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")
- (progn
- (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)))
- (declare
- (type (simple-array double-float) elements-m1 elements-m2 elements-m)
- (type fixnum n-rows n-cols n)
- (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 (aref elements-m (+ j (* i n-cols))) (loop for k fixnum from 0 below n
- sum (* (aref elements-m1 (+ k (* i n))) (aref elements-m2 (+ j (* k n))))))))
- m))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement