How to define a pointer to a 2d array in cffi

Discussion of Common Lisp

How to define a pointer to a 2d array in cffi

Postby joeish80829 » Fri Nov 22, 2013 6:11 pm

I have a function that accepts a void* as a parameter

Im trying to convert this to use as the void*

Code: Select all
float trainingData[4][2] = { {501, 10}, {255, 10}, {501, 255}, {10, 501} };


this is how i do a void* 1d array

Code: Select all
  float labels[4] = {1.0, -1.0, -1.0, -1.0};

(labels (foreign-alloc :float :initial-contents '(1.0 -1.0 -1.0 -1.0)))


so how do i do the 2d array
joeish80829
 
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

Re: How to define a pointer to a 2d array in cffi

Postby pjstirling » Mon Nov 25, 2013 10:02 am

It looks like cffi doesn't support multi-dimensional arrays. C stores multi-dimension arrays in row-major order, and the wikipedia page gives quite a good write-up of how to map between linear arrays (that you can allocate with cffi) and what the foreign code expects.
pjstirling
 
Posts: 78
Joined: Sun Nov 28, 2010 4:21 pm

Re: How to define a pointer to a 2d array in cffi

Postby joeish80829 » Sat Dec 07, 2013 6:53 pm

where is this wiki page you speak of.....thx 4 the reply btw....Id reall like to learn to convert this array?
joeish80829
 
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

Re: How to define a pointer to a 2d array in cffi

Postby pjstirling » Sun Dec 08, 2013 9:19 am

The row-major order link in my post was a link to the wikipedia page http://en.wikipedia.org/wiki/Row-major.
pjstirling
 
Posts: 78
Joined: Sun Nov 28, 2010 4:21 pm


Return to Common Lisp

Who is online

Users browsing this forum: hill0093 and 1 guest