Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defmethod mult ((m1 matrix-r) (m2 matrix-r))
- (if (not (= (number-of-cols m1) (number-of-rows m2)))
- (error "Can't perform matrix multiplication")
- (let* ((elements-m1 (elements m1)) (elements-m2 (elements m2))
- (n (number-of-cols m1))
- (n-rows (number-of-rows m1))
- (n-cols (number-of-cols m2))
- (m (make-instance 'matrix-r :number-of-rows n-rows :number-of-cols n-cols))
- (elements-m (elements m))
- (width (lane-width m1))
- (r-lane (make-array width :element-type 'double-float))
- (c-lane (make-array width :element-type 'double-float))
- (sum 0.0d0))
- (declare
- (type fixnum n-rows n-cols n width)
- (type (simple-vector) elements-m1 elements-m2 elements-m)
- (type (simple-array double-float (4)) r-lane c-lane)
- (type double-float sum)
- (optimize (debug 0) (safety 0) (speed 3)))
- (loop for i fixnum from 0 below n-rows do
- (loop for j fixnum from 0 below n-cols do
- (setf sum 0.0d0)
- (loop for k fixnum from 0 below (number-of-lanes m1) do
- (setf r-lane (aref elements-m1 k))
- (setf c-lane (aref elements-m2 k))
- (loop for l fixnum below 4 do
- ;;(incf sum (* (aref elements-m1 (+ k (the fixnum (* i n))))
- ;;(aref elements-m2 (+ j (the fixnum (* k n)))))))
- (incf sum (* (aref r-lane l) (aref c-lane l)))))
- (setf (aref (aref elements-m 0) 0) sum)))
- m)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement