lisp - Blocked Matrix Multiplication -
i trying create function performs blocked matrix multiplication in allegrocl, keep getting array-index errors. believe due indicies being 0-19 side of 20 x 20 block matrix, i'm unsure of how fix it.
error: array index 20 big dimension 20 while accessing #. [condition type: type-error]
any or direction appreciated. below code far.
(defun bmmul (a b) (let* ((m (car (array-dimensions a))) (n (cadr (array-dimensions a))) (l (cadr (array-dimensions b))) (u 0) (c (make-array `(,m ,l) :initial-element 0))) (loop p 0 (- m n) (loop (+ 0 1) n (setf u (aref c 0)) (loop k p (- (+ p n) 1) (setf u (* (aref k) (aref b k 0)))) (setf (aref c 0) u))) c))
in general, when looping on array index, go :from 0 :below n
, n
array dimension, when dimension 20, index goes 0 , including 19.
another problem seems in innermost loop, want incf
, not setf
. not need temporary variable (u
) there, incf
array cell directly.
finally, not feel structured loops correctly, not expect see hardcoded 0
index there. innermost loop body should (incf (aref c j) (* (aref k) (aref b k j)))
, regardless of whether ordinary or blocked multiplication.
Comments
Post a Comment