[cffi-devel] Re: creating two-dimensional arrays
hbabcockos1 at mac.com
hbabcockos1 at mac.com
Thu Mar 16 02:56:26 UTC 2006
On Mar 15, 2006, at 6:46 AM, Luís Oliveira wrote:
> hbabcockos1 at mac.com writes:
>> What is the right way to create a 2D array to pass to a c-function
>> that expects **arr?
>
> In message ID <BAY17-DAV41D78728D384B9C2D15ADD9300 at phx.gbl>, Vasilis
> sent some functions macros to manipulate and create arrays of
> arbitrary
> ranks: http://common-lisp.net/pipermail/cffi-devel/2005-December/
> 000281.html
I was able to get this to work. I was using the wrong index variable
(y instead of x) in the inner loop.
(defun make-matrix (lisp-mat)
"Creates a two-dimensional c array, initializes with lisp matrix"
(let* ((x-dim (array-dimension lisp-mat 0))
(y-dim (array-dimension lisp-mat 1))
(c-mat (foreign-alloc :pointer :count y-dim)))
(dotimes (y y-dim)
(let ((cur (foreign-alloc :double :count x-dim)))
(setf (mem-aref c-mat :pointer y) cur)
(dotimes (x x-dim)
(setf (mem-aref cur :double x) (coerce (aref lisp-mat x y)
'double-float)))))
c-mat)) ^^^
Thanks for the suggestion though, it looks like a nice generalization
of the specific case I am trying to handle.
-Hazen
More information about the cffi-devel
mailing list