swig icon indicating copy to clipboard operation
swig copied to clipboard

How to convert mex array to/from carray?

Open jkfindeisen opened this issue 9 years ago • 3 comments

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<size_t> 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 avatar Jun 09 '15 09:06 jkfindeisen

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.

jkfindeisen avatar Jun 10 '15 07:06 jkfindeisen

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.

jaeandersson avatar Jun 10 '15 08:06 jaeandersson

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

jkfindeisen avatar Jun 10 '15 11:06 jkfindeisen