bastibe / transplant

Transplant is an easy way of calling Matlab from Python
https://transplant.readthedocs.io
Other
110 stars 26 forks source link

Sparse Matrixes #11

Closed ASpeiser closed 8 years ago

ASpeiser commented 8 years ago

Hey,

I really like the package. Unfortunately it seems like it doesn't support sparse matrices. Doing matlab.sparse(3,3) already fails.

Is there a quick fix possible?

bastibe commented 8 years ago

Hi,

I can't think of a very quick fix. But it should be relatively straight-forward to add an encoder/decoder in _encode_values and _decode_values in _transplantmaster.py and in encode_values and decode_values in _transplantremote.m. If you want to take a stab at it, I'd be happy to merge your code.

Otherwise, I'll try to do it myself next week.

ASpeiser commented 8 years ago

Sorry, I don't think I got the know how. But a fix would help me very much.

bastibe commented 8 years ago

The latest version has support for sparse matrices. Of course you will need scipy for this to work, since numpy does not include sparse matrices.

I currently transfer sparse matrices in COO format, which might be slow for large numbers of values. More importantly, I reconstruct Matlab's matrices in COO format in Python, which, again, might by slow for some workloads. You might need to convert them to CSC or CSR to get your work done. If you have any insights into which one of these formats is more valuable than any other, I'd be very interested in that.

Please let me know if this solves your problem.