Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when importing empty cell array #149

Open
MaxandreJ opened this issue Nov 17, 2018 · 3 comments
Open

Error when importing empty cell array #149

MaxandreJ opened this issue Nov 17, 2018 · 3 comments

Comments

@MaxandreJ
Copy link

MaxandreJ commented Nov 17, 2018

Hi,

See first answer below, I have provided a minimal working example now. The problem is with a cell array of any size containing uninitialised values.

On Julia 1.0.2 and MATLAB.jl v"0.7.0", with a 4x4 cell array MATLAB variable containing 1200001 x 1 double (4 of them, on the first row) and [] (on the other rows),

I run

file = read_matfile(filepath)
my_variable_MxArray = file[variable_name]
my_variable_julia = jvalue(my_variable_MxArray)

and get the error

ERROR: NULL pointer for MxArray.

with the stacktrace

Stacktrace:
 [1] Type at /Users/maxandrejacqueline/.julia/packages/MATLAB/ZuG4g/src/mxarray.jl:8 [inlined]
 [2] get_cell at /Users/maxandrejacqueline/.julia/packages/MATLAB/ZuG4g/src/mxarray.jl:359 [inlined]
 [3] _jarrayx(::String, ::MATLAB.MxArray, ::Tuple{Int64,Int64}) at /Users/maxandrejacqueline/.julia/packages/MATLAB/ZuG4g/src/mxarray.jl:506
 [4] jmatrix(::MATLAB.MxArray) at /Users/maxandrejacqueline/.julia/packages/MATLAB/ZuG4g/src/mxarray.jl:521
 [5] jvalue(::MATLAB.MxArray) at /Users/maxandrejacqueline/.julia/packages/MATLAB/ZuG4g/src/mxarray.jl:605

I do not have time to provide a minimal working example (MWE) at the moment. I have provided an MWE now.

Best,
Max

@MaxandreJ MaxandreJ changed the title Error when importing 4x4 cell array Error when importing empty cell array Nov 17, 2018
@MaxandreJ
Copy link
Author

MaxandreJ commented Nov 18, 2018

Minimal working example

Creating a variable in MATLAB using

my_test = cell(1);

which displays as

my_test =

  1×1 cell array

    {0×0 double}

and saving it

save("../../../Data/test/test.mat",'my_test')

I try to import it in Julia using

my_matfile_contents = read_matfile("../../Data/test/test.mat")

my_variable_MxArray = my_matfile_contents["my_test"]

my_variable_julia = jvalue(my_struct_MxArray)

I get the error and stacktrace

ERROR: NULL pointer for MxArray.
Stacktrace:
 [1] Type at /Users/maxandrejacqueline/.julia/packages/MATLAB/ZuG4g/src/mxarray.jl:8 [inlined]
 [2] get_cell at /Users/maxandrejacqueline/.julia/packages/MATLAB/ZuG4g/src/mxarray.jl:359 [inlined]
 [3] _jarrayx(::String, ::MxArray, ::Tuple{Int64}) at /Users/maxandrejacqueline/.julia/packages/MATLAB/ZuG4g/src/mxarray.jl:506
 [4] jvector(::MxArray) at /Users/maxandrejacqueline/.julia/packages/MATLAB/ZuG4g/src/mxarray.jl:515
 [5] jvalue(::MxArray) at /Users/maxandrejacqueline/.julia/packages/MATLAB/ZuG4g/src/mxarray.jl:605
 [6] top-level scope at none:0

.

However, if I manually initialise the values of my cell array in MATLAB, as such

my_test = cell(1);
my_test{1} = [];
save("../../../Data/test/test.mat",'my_test')

my variable still displays as

my_test =

  1×1 cell array

    {0×0 double}

but this time when I run in Julia

my_matfile_contents = read_matfile("../../Data/test/test.mat")

my_variable_MxArray = my_matfile_contents["my_test"]

my_variable_julia = jvalue(my_struct_MxArray)

I get the correct behaviour

1-element Array{Any,1}:
 Array{Float64}(0,0)

This may mean that the initialisation of cells in a cell array by the command cell(dimensions) in MATLAB is actually different from initialising the cells manually (eg. my_test{1} = [];), even if it is not shown to the user. scipy.io works with both initialisation methods and doesn't return any MatlabOpaque object so I don't think this is to do with the MATLAB C API vs MATLAB C++ API.

@MaxandreJ
Copy link
Author

I think I've got to the root of the problem... Using scipy.io in Julia (through PyCall) to import the variables, I've managed to find a difference between the two ways of initialising the cell array.

If I do

my_test = cell(1);

to create the cell array, I import it in Julia using scipy.io, and I inspect the variable, I get

PyObject array([], shape=(1, 0), dtype=float64)

whereas if I initialise the cell array with

my_test = cell(1);
my_test{1} = [];

I import it in Julia using scipy.io, and I inspect the variable, I get

PyObject array([], shape=(0, 0), dtype=uint8)

Notice the difference in shape and variable type! This should prove useful when debugging this issue.

Best,
Max

@musm
Copy link
Collaborator

musm commented Nov 20, 2018

Thanks for the detailed bug report and MWE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants