Page 1 of 1

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

Posted: Fri Nov 22, 2013 6:11 pm
by joeish80829
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

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

Posted: Mon Nov 25, 2013 10:02 am
by pjstirling
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.

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

Posted: Sat Dec 07, 2013 6:53 pm
by joeish80829
where is this wiki page you speak of.....thx 4 the reply btw....Id reall like to learn to convert this array?

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

Posted: Sun Dec 08, 2013 9:19 am
by pjstirling
The row-major order link in my post was a link to the wikipedia page http://en.wikipedia.org/wiki/Row-major.