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

matwrite fails for a basic dictionary on an isbits test #162

Open
BambOoxX opened this issue Jul 9, 2021 · 4 comments
Open

matwrite fails for a basic dictionary on an isbits test #162

BambOoxX opened this issue Jul 9, 2021 · 4 comments

Comments

@BambOoxX
Copy link

BambOoxX commented Jul 9, 2021

MAT.jl v0.10.1 seems to fail with this call

D = Dict("num" => rand(),
              "vec" => rand(2),
              "mat" => rand(3, 3),
              "str" => "abc",
              "chr" => 'A',
               )
fname = tempname()*".mat"
matwrite(fname,D

is there something brroken, or I am using this incorrectly ?

@inkydragon
Copy link

It looks like MAT.jl doesn't support writing char to mat files yet.

julia> matwrite("char.mat", Dict("chr" => 'a'))
ERROR: This is the write function for CompositeKind, but the input doesn't fit
Stacktrace:
 [1] error(s::String)
   @ Base .\error.jl:33
 [2] m_write(mfile::MAT.MAT_HDF5.MatlabHDF5File, parent::HDF5.File, name::String, s::Char)
   @ MAT.MAT_HDF5 C:\Users\woclass\.julia\packages\MAT\f523T\src\MAT_HDF5.jl:530
 [3] write(parent::MAT.MAT_HDF5.MatlabHDF5File, name::String, thing::Char)
   @ MAT.MAT_HDF5 C:\Users\woclass\.julia\packages\MAT\f523T\src\MAT_HDF5.jl:546
 [4] matwrite(filename::String, dict::Dict{String, Char}; compress::Bool)
   @ MAT C:\Users\woclass\.julia\packages\MAT\f523T\src\MAT.jl:157
 [5] matwrite(filename::String, dict::Dict{String, Char})
   @ MAT C:\Users\woclass\.julia\packages\MAT\f523T\src\MAT.jl:148
 [6] top-level scope
   @ REPL[43]:1

@BambOoxX
Copy link
Author

BambOoxX commented Nov 17, 2021

Coming back to this again, the surprising part of it is that when reading a single character string, MAT automatically parses this as a Char...

julia>D = Dict("num" => rand(),
              "vec" => rand(2),
              "mat" => rand(3, 3),
              "str" => "abc",
              "chr" => "A",
             )
Dict{String, Any} with 5 entries:
  "mat" => [0.183045 0.573825 0.506827; 0.27681 0.500612 0.790263; 0.833868 0.144452 0.111698]
  "str" => "abc"
  "vec" => [0.0367621, 0.740946]
  "chr" => "A"
  "num" => 0.0702267

julia> matwrite(fname,D)

julia> matread(fname)
Dict{String, Any} with 5 entries:
  "mat" => [0.183045 0.573825 0.506827; 0.27681 0.500612 0.790263; 0.833868 0.144452 0.111698]
  "str" => "abc"
  "vec" => [0.0367621, 0.740946]
  "chr" => 'A'
  "num" => 0.0702267

julia> typeof(ans["chr"])
Char

@BambOoxX
Copy link
Author

BambOoxX commented Nov 17, 2021

I know this is far from being good, but whouldn't it be relevant to avoid this error with Char variables by simply doing e.g.

MAT.MAT_HDF5.m_write(mfile::MAT.MAT_HDF5.MatlabHDF5File, parent::MAT.MAT_HDF5.HDF5Parent, name::String, char::AbstractChar) = MAT.MAT_HDF5.m_write(mfile, parent, name, string(char))

This now results in a correct roundtrip from/to .mat files

This would allow to close #143 as well.

@simonster, what do you make of this ?

@BambOoxX
Copy link
Author

Bump ?

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