1 ;;; -*- Mode: lisp; outline-regexp: ";;;;;*"; indent-tabs-mode: nil -*-;;;
4 ;;; author: cyrus harmon
7 ;;; macros for looping over matrices and doing operations with the benefit
8 ;;; of type declarations
12 (defun parse-mloop-vars (vars)
13 (apply #'mapcar
(cons #'list vars
)))
15 (defmacro mloop
((mspecs m n i j
) &body body
)
16 (destructuring-bind (matrices types vars
)
17 (parse-mloop-vars mspecs
)
18 `(destructuring-bind (,m
,n
) (clem:dim
,(car matrices
))
19 (declare (type fixnum
,m
,n
))
20 (let (,@(loop for var in vars and matrix in matrices
22 `(,var
(clem::matrix-vals
,matrix
))))
23 ,@(loop for type in types and var in vars
25 `(declare (type (simple-array ,type
*) ,var
)))
27 (declare (type fixnum
,i
))
29 (declare (type fixnum
,j
))
32 (defmacro mloop-range
((mspecs startr endr startc endc i j
) &body body
)
33 (destructuring-bind (matrices types vars
)
34 (parse-mloop-vars mspecs
)
35 `(let (,@(loop for var in vars and matrix in matrices
37 `(,var
(clem::matrix-vals
,matrix
))))
38 ,@(loop for type in types and var in vars
40 `(declare (type (simple-array ,type
*) ,var
)))
41 (do ((,i
,startr
(1+ ,i
)))
43 (declare (type fixnum
,i
))
44 (do ((,j
,startc
(1+ ,j
)))
46 (declare (type fixnum
,j
))