bastibe / transplant

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

cell2mat fails for the shape due to different data types when using msgpack #17

Closed dlaidig closed 8 years ago

dlaidig commented 8 years ago

When using transplant, I got an error "All contents of the input cell array must be of the same data type. (MATLAB:cell2mat:MixedDataTypes)". It turns out that this happens in the function decode_matrix() of transplant_remote.m when trying to convert the shape to a matrix. The different entries of the shape are stored as the smallest fitting integer type which causes cell2mat to fail.

In decode_matrix():

disp(value{3});
    [7479]    [3]
disp(class(value{3}));
    cell
disp(class(value{3}{1}));
    uint16
disp(class(value{3}{2}));
    uint8

As a quick fix, I changed the python side to transmit the shape as floats, but I don't know transplant and msgpack good enough to suggest an elegant solution.

bastibe commented 8 years ago

What data were you trying to send?

dlaidig commented 8 years ago

A two-dimensional numpy array.

This fails on my system (Matlab R2015b, python3-msgpack 0.4.8, current transplant from master):

import numpy as np
from transplant import Matlab
m = Matlab()
print(m.sqrt(np.ones((1, 256))))

With (1, 255) it still works as both shape entires are uint8.

bastibe commented 8 years ago

Should be fixed in 993a81392454bd65e57c6449d38032fc78116c4d. Can you confirm this?

dlaidig commented 8 years ago

Yes, works for me. :) I noticed in the code that the same is done for sparse matrices (which I don't use). Shouldn't the same be done there?

bastibe commented 8 years ago

Great find! Thank you! I'll fix it right away.

bastibe commented 8 years ago

OK, should be fixed now.