array type declaration problems
james anderson <[email protected]> Sun, 21 Sep 2003 11:40:09 +0200
| Newsgroups | gmane.lisp.openmcl.bugs |
|---|---|
| Message-ID | <[email protected]> |
hello;
you may recall my queries over the last days wrt floating-point
efficiency.
one aspect of the work is an api-independant 3-d modeling package. so
far i have preliminary interfaces to opengl, core-graphics, and
quickdraw. x is next. thus my query last week about clx for openmcl.
i've managed to build 0.14 and clx mostly works, but i've stumbled over
something quite peculiar in float array access.
this function
(defun matrix-identity (&optional (nm (matrix) result-p))
"initialize an optional argument matrix to the diagonal = 1.0d0.
if no result matrix is provided a new matrix is constructed."
#|(declare (optimize (speed 3) (safety 0)) (type double-matrix nm))|#
(when result-p (assert-type nm double-matrix))
(let ((i-max (array-dimension nm 0))
(j-max (array-dimension nm 1)))
(declare (type fixnum i-max j-max))
(dotimes (i i-max)
(dotimes (j j-max)
(if (= i j)
(setf (aref nm i j) 1.0d0)
(when result-p ; a defaulted result is
already initialized
(setf (aref nm i j) 0.0d0))))))
nm)
produces incorrect result if the type declaration is included.
independent of the optimize declaration.
that is
(matrix-identity (transform-matrix))
#<ARRAY 4x4 type DOUBLE-FLOAT, simple>
? (print-matrix *)
#2a((0.0D0 0.0D0 0.0D0 0.0D0) (0.0D0 0.0D0 0.0D0 0.0D0) (0.0D0 0.0D0
0.0D0 0.0D0) (0.0D0 0.0D0 0.0D0 0.0D0))
#<ARRAY 4x4 type DOUBLE-FLOAT, simple>
it does not set the diagonal. if i change it to something like
...
(print (setf (aref nm i j) 1.0d0))
...
it does. it also makes no difference if i include the type definition
for double-matrix literally.
...