jaeandersson / swig

SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages.
http://www.swig.org
Other
23 stars 19 forks source link

How to convert mex array to/from carray? #20

Open jkfindeisen opened 9 years ago

jkfindeisen commented 9 years ago

I do image processing and want to use this SWIG to exchange multidimensional mex arrays (matrices) to carrays or something similar. I want to either process them in-place (without copying) or create a new mex array as output (dimensions would be known in advance).

On the C/C++ side I would like to have the mex arrays wrapped as

T * data, size_t * dimenions, int number_dimensions or T * data, std::vector dimensions T = int, double, ...

Important is that no additional copying takes place (my matrices are big) and that multidimensional arrays are supported.

I looked at matlab/carray.i but couldn't find anything useful. Is this already possible with the currents means?

If not, I could volunteer in writing such bindings, because I need them either way. Also I think that this would probably be a very often used task with Malab being centered so much on matrices...

jkfindeisen commented 9 years ago

I should add that I'm already doing it with Python/Numpy arrays (using numpy.i) but in Matlab there seems to be some difficulty with copyonwrite, so changing matrices in-place does not seem to be possible easily. Having them read-only would be enough in my case.

To summarize: So all I want is to know whether there is already a solution for input/output of multidimensional matlab matrices to/from carrays plus dimensions.

jaeandersson commented 9 years ago

Hi! I did not look into matlab/carray.i, so if you are willing to do that, go ahead. So far, I think there are only typemaps for e.g. scalars and vectors. When you're done, just make a pull request. I guess there should be no fundamental problem, just add the appropriate typemap.

jkfindeisen commented 9 years ago

Ok, will do that. It might take awhile but I will come back to you.