rsmenon / MATLink

Communicate with MATLAB from Mathematica
matlink.org
67 stars 14 forks source link

Allow explicitly casting arrays to logicals #82

Open szhorvat opened 8 years ago

szhorvat commented 8 years ago

MCell can be used to explicitly cast an expression to a cell, i.e. force interpretation as a cell.

MFunction["class"][Range[5]]
"double"

MFunction["class"][MCell@Range[5]]
"cell"

It would be useful to add support to cast to logical arrays explicitly, i.e. MFunction["class"][MLogical@UnitStep@Range[-5,5]] should return "logical".

This is because some functions only take logical arrays. An example is bwdistgeodesic. Large logical arrays, e.g. ones that represent binary images, are just not practical to be represented as arrays of True and False. A packed integer array is much better.

It's been a long time. What do you think?

rsmenon commented 8 years ago

Yeah, this is definitely a good idea. Heh, we put it down as a todo but forgot :) (and seems like it wasn't missed much).

Since we're talking about large multidimensional arrays, perhaps we should avoid having to do ArrayQ[arr, testIfZeroOneIntegers] in the definition? I'm not sure if this would unpack. Perhaps something like MLogical[..., "Integer" -> True] and then we don't do Boole@ on it?

Either way, definitely a +1.