swig
swig copied to clipboard
Implement cast
http://es.mathworks.com/help/matlab/ref/cast.html
Probably a tricky thing to implement...
Yes, I agree that casting is tricky on the Matlab side. But it can be supported on the c++ side using cast operators. Here is an example from our source for double():
%rename("double") class::operator const double;
Then in Matlab you can simply call double(class). You could also add additional conversion operators for other primitive data types if desired.
double(A)
is supposed to mean "convert to double storage", not "convert to a double scalar", so %rename("double") class::operator double
is not necessarily the answer. Anyway, in many cases, %rename("double")
will probably do the trick.
In CasADi, we use full(A)
and sparse(A)
to convert CasADi matrices to dense and sparse MATLAB matrices respectively.