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

empty cell not correctly managed #104

Open
Nelson-numerical-software opened this issue Feb 20, 2019 · 6 comments
Open

empty cell not correctly managed #104

Nelson-numerical-software opened this issue Feb 20, 2019 · 6 comments

Comments

@Nelson-numerical-software
Copy link

Nelson-numerical-software commented Feb 20, 2019

Tested with 1.5.13:

A = cell(1); 
save('empty_cell.mat', 'A', '-v7.3')

load with matio:

matvar_t * elementMatVar = Mat_VarGetCell(matVariable, (int)k);

elementMatVar->class_type with k = 0 returns: MAT_C_EMPTY and not MAT_C_DOUBLE (expected)
elementMatVar->data_type MAT_T_UNKNOWN

same code with a value works:

A = {1} // or  A = {[]}
save('cell.mat', 'A', '-v7.3')
@tbeu
Copy link
Owner

tbeu commented Feb 21, 2019

Is this only the case for v7.3 MAT-files or can you also reproduce when saved with -v6 or -v7?

@Nelson-numerical-software
Copy link
Author

same problem with v6 or v7

@Nelson-numerical-software
Copy link
Author

save using matio works but not an original .mat file

@tbeu
Copy link
Owner

tbeu commented Feb 21, 2019

Can you please attach all three file here. Thanks.

@tbeu
Copy link
Owner

tbeu commented Feb 21, 2019

>> A = cell(1);
>> B = {[]};
>> isequal(A, B)

ans =

     1
>> whos
  Name      Size                    Bytes  Class

  A         1x1                         4  cell array
  B         1x1                        60  cell array
  ans       1x1                         1  logical array

Though the two variable are equal, they are not. The difference is in the size. Variable A is en empty cell, variable B is a cell containing an empty array (of type double). This is also what matdump reports:

$ matdump -f whos -d empty_cell.mat
Name                       Size           Bytes          Class

A                          1x1                   4  mxCELL_CLASS
B                          1x1                  60  mxCELL_CLASS

$ matdump -d empty_cell.mat A
      Name: A
      Rank: 2
Class Type: Cell Array
{
    Empty
}

$ matdump -d empty_cell.mat B
      Name: B
      Rank: 2
Class Type: Cell Array
{
}

For variable A there simply is no data type information available. That is why you get MAT_T_UNKNOWN. Changing it to MAT_T_DOUBLE by default does not seem straight.

@tbeu
Copy link
Owner

tbeu commented Feb 21, 2019

But I have to admit that this kind of empty variable is not yet covered by the test. In matio_test_cases.m we have the following cases for empty cells

%% Cell-Array Variables
var51 = {}; % or var51 = cell(0);
var52 = {[] single([]) int64([]) uint64([]) int32([]) uint32([]) int16([]) uint16([]) int8([]) uint8([])};

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