Menu

#25 Wrong access to data in sparse logical arrays in v4, v6 and v7 files.

1.5.3
closed-fixed
cch
5
2016-01-11
2014-05-15
No

If I execute the following code in MATLAB:

x = mod(1:16,2) == 0; sx = sparse(x)

I get a sparse boolean matrix with the entries

(1, 2) -> 1
(1, 4) -> 1
(1, 6) -> 1
(1, 8) -> 1
(1, 10) -> 1
(1, 12) -> 1
(1, 14) -> 1
(1, 16) -> 1

Now I save this matrix with different mat-versions like this:

save('v4.mat', 'sx', '-v4')
save('v6.mat', 'sx', '-v6')
save('v7.mat', 'sx', '-v7')
save('v73.mat', 'sx', '-v7.3')

If I try accessing the content using the matdump tool, it only works with the v73.mat file. The others seem to get the data type wrong.

matdump.exe -d v4.mat
MAT V4 data type error
Name: sx
Rank: 2
Dimensions: 9 x 3
Class Type: Sparse Array
Data Type: IEEE 754 double-precision

matdump.exe -d v6.mat
Name: sx
Rank: 2
Dimensions: 1 x 16
Class Type: Sparse Array (logical)
Data Type: IEEE 754 double-precision
{
(1,2) 7.7486e-304
}

matdump.exe -d v7.mat
Name: sx
Rank: 2
Dimensions: 1 x 16
Class Type: Sparse Array (logical)
Data Type: IEEE 754 double-precision
{
(1,2) 7.7486e-304
}

matdump.exe -d v73.mat
Name: sx
Rank: 2
Dimensions: 1 x 16
Class Type: Sparse Array (logical)
Data Type: 8-bit, unsigned integer
{
(1,2) 1
(1,4) 1
(1,6) 1
(1,8) 1
(1,10) 1
(1,12) 1
(1,14) 1
(1,16) 1
}

Discussion

  • cch

    cch - 2014-05-16

    I do not support sparse arrays in version 4 MAT files.

    I want to write a test case for the sparse logical variables, but I have attached a patch that fixes the issue. I will actually blame this one on MATLAB. In the MAT file it says the data is written as double values, but they are actually 8-bit ints. I used R2014a to generate my data file. Can you tell me what version you are using? At least for now, I assume if the sparse array is logical, the data is written as int8. Would you please test on your end and let me know if there are any issues? I will commit this once I get a test case written for it.

     
  • cch

    cch - 2014-05-16
    • status: open --> accepted
    • assigned_to: cch
     
  • schlumpfuffzn

    schlumpfuffzn - 2014-05-16

    I am using MATLAB R2014a as well.
    Applying the patch fixed the problem, so thank you for the quick help.

     
  • cch

    cch - 2014-05-20
    • status: accepted --> closed-fixed
     
  • cch

    cch - 2014-05-20

    Should be fixed by commit [7af9e7].

     

    Related

    Commit: [7af9e7]

  • tbeu

    tbeu - 2016-01-11
    • Group: master --> 1.5.3
     

Log in to post a comment.