JuliaIO / MAT.jl

Julia module for reading MATLAB files
MIT License
278 stars 71 forks source link

Method ambiguities when using matread #111

Closed galenlynch closed 5 years ago

galenlynch commented 5 years ago

I am unable to load some mat files using MAT 0.4.0 and Julia 1.1.0, due to method ambiguities:

julia> using MAT
julia> resfile = "times_12.mat"
"times_12.mat"
julia> vars = matread(resfile)
ERROR: MethodError: read(::HDF5.HDF5Dataset, ::Type{Array{Bool,N} where N}) is ambiguous. Candidates:
  read(obj::Union{HDF5Attribute, HDF5Dataset}, ::Type{Array{T,N} where N}) where T<:Union{Bool, Float32, Float64, Int16, Int32, Int64, Int8, UInt16, UInt32, UInt64, UInt8, HDF5ReferenceObj} in HDF5 at /home/glynch/.julia/packages/HDF5/H0XJB/src/HDF5.jl:1309
  read(obj::Union{HDF5Dataset, HDF5Datatype, HDF5Group}, ::Type{Array{Bool,N} where N}) in MAT.MAT_HDF5 at /home/glynch/.julia/packages/MAT/1a6rY/src/MAT_HDF5.jl:611
Possible fix, define
  read(::HDF5.HDF5Dataset, ::Type{Array{Bool,N} where N})
Stacktrace:
 [1] m_read(::HDF5.HDF5Dataset) at /home/glynch/.julia/packages/MAT/1a6rY/src/MAT_HDF5.jl:183
 [2] read(::MAT.MAT_HDF5.MatlabHDF5File, ::String) at /home/glynch/.julia/packages/MAT/1a6rY/src/MAT_HDF5.jl:262
 [3] read(::MAT.MAT_HDF5.MatlabHDF5File) at /home/glynch/.julia/packages/HDF5/H0XJB/src/datafile.jl:45
 [4] matread(::String) at /home/glynch/.julia/packages/MAT/1a6rY/src/MAT.jl:130
 [5] top-level scope at none:0

This just started happening, and I'm not sure what changed.

galenlynch commented 5 years ago

Perhaps the sudden ambiguity stems from JuliaLang/julia#30114?

The problem seems to involve reading a Matlab logical array, but I'm having trouble creating a simple demonstration of the problem due to other, unrelated, issues with creating logical arrays:

julia> foo = BitArray{1}(undef, 3)
3-element BitArray{1}:
 false
 false
 false

julia> file = matopen("foo.mat", "w")
MAT.MAT_HDF5.MatlabHDF5File(HDF5 data file: foo.mat, true, true, 0)

julia> write(file, "foo", foo)
ERROR: This is the write function for CompositeKind, but the input doesn't fit
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] m_write(::MAT.MAT_HDF5.MatlabHDF5File, ::HDF5.HDF5Group, ::String, ::Tuple{Int64}) at /home/glynch/.julia/packages/MAT/1a6rY/src/MAT_HDF5.jl:518
 [3] m_write(::MAT.MAT_HDF5.MatlabHDF5File, ::HDF5.HDF5File, ::String, ::Array{String,1}, ::Array{Any,1}) at /home/glynch/.julia/packages/MAT/1a6rY/src/MAT_HDF5.jl:506
 [4] m_write(::MAT.MAT_HDF5.MatlabHDF5File, ::HDF5.HDF5File, ::String, ::BitArray{1}) at /home/glynch/.julia/packages/MAT/1a6rY/src/MAT_HDF5.jl:521
 [5] write(::MAT.MAT_HDF5.MatlabHDF5File, ::String, ::BitArray{1}) at /home/glynch/.julia/packages/MAT/1a6rY/src/MAT_HDF5.jl:534
 [6] top-level scope at none:0

julia> foo = Vector{Bool}(undef, 3)
3-element Array{Bool,1}:
  true
 false
 false

julia> write(file, "foo", foo)
ERROR: MethodError: no method matching m_writearray(::HDF5.HDF5File, ::String, ::Base.ReinterpretArray{UInt8,1,Bool,Array{Bool,1}})
Closest candidates are:
  m_writearray(::Union{HDF5File, HDF5Group}, ::String, ::Array{T<:Union{Bool, Float32, Float64, Int16, Int32, Int64, Int8, UInt16, UInt32, UInt64, UInt8},N} where N) where T<:Union{Bool, Float32, Float64, Int16, Int32, Int64, Int8, UInt16, UInt32, UInt64, UInt8} at /home/glynch/.julia/dev/MAT/src/MAT_HDF5.jl:334
  m_writearray(::Union{HDF5File, HDF5Group}, ::String, ::Array{Complex{T<:Union{Bool, Float32, Float64, Int16, Int32, Int64, Int8, UInt16, UInt32, UInt64, UInt8}},N} where N) where T<:Union{Bool, Float32, Float64, Int16, Int32, Int64, Int8, UInt16, UInt32, UInt64, UInt8} at /home/glynch/.julia/dev/MAT/src/MAT_HDF5.jl:346
Stacktrace:
 [1] m_write(::MAT.MAT_HDF5.MatlabHDF5File, ::HDF5.HDF5File, ::String, ::Array{Bool,1}) at /home/glynch/.julia/packages/MAT/1a6rY/src/MAT_HDF5.jl:370
 [2] write(::MAT.MAT_HDF5.MatlabHDF5File, ::String, ::Array{Bool,1}) at /home/glynch/.julia/packages/MAT/1a6rY/src/MAT_HDF5.jl:534
 [3] top-level scope at none:0
galenlynch commented 5 years ago

Whoops, I just remembered that I'm using https://github.com/halleysfifthinc/MAT.jl#v0.7-update instead of a tagged version, so this issue is maybe not relevant.

jaakkor2 commented 5 years ago

I guess you upgraded HDF5 . Try pinning it to v0.10.4. PR #110 requires HDF5 v0.11.