Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/MAT_HDF5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,16 @@ function m_write(mfile::MatlabHDF5File, parent::HDF5Parent, name::String, c::Abs
m_write(mfile, parent, name, string(c))
end

# Tuple
function m_write(mfile::MatlabHDF5File, parent::HDF5Parent, name::String, t::Tuple)
m_write(mfile, parent, name, [x for x in t])
end

# Symbol
function m_write(mfile::MatlabHDF5File, parent::HDF5Parent, name::String, s::Symbol)
m_write(mfile, parent, name, string(s))
end

# Write cell arrays
function m_write(mfile::MatlabHDF5File, parent::HDF5Parent, name::String, data::AbstractArray{T}, object_decode::UInt32=UInt32(0)) where T
data = _normalize_arr(data)
Expand Down
34 changes: 28 additions & 6 deletions test/write.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MAT, Test, Dates
using SparseArrays, LinearAlgebra

tmpfile = string(tempname(), ".mat")

Expand Down Expand Up @@ -150,12 +151,33 @@ test_write(Dict("reshape_arr"=>reshape([1 2 3;4 5 6;7 8 9]',1,9)))
test_write(Dict("adjoint_arr"=>Any[1 2 3;4 5 6;7 8 9]'))
test_write(Dict("reshape_arr"=>reshape(Any[1 2 3;4 5 6;7 8 9]',1,9)))

# named tuple
nt = (x = 5, y = Any[6, "string"])
matwrite(tmpfile, Dict("nt" => nt))
nt_read = matread(tmpfile)["nt"]
@test nt_read["x"] == 5
@test nt_read["y"] == nt.y
@testset "named tuple" begin
nt = (x = 5, y = Any[6, "string"])
matwrite(tmpfile, Dict("nt" => nt))
nt_read = matread(tmpfile)["nt"]
@test nt_read["x"] == 5
@test nt_read["y"] == nt.y
end

@testset "tuple" begin
# NTuple{T}
t = (5, 6)
matwrite(tmpfile, Dict("t" => (5, 6)))
r = matread(tmpfile)["t"]
@test r == [x for x in t]

# otherwise cell array
t = (5, "string")
matwrite(tmpfile, Dict("t" => t))
r = matread(tmpfile)["t"]
@test r == [x for x in t]
end

@testset "symbol" begin
matwrite(tmpfile, Dict("s" => :symbol))
r = matread(tmpfile)["s"]
@test r == "symbol"
end

# test nested struct array - interface via Dict array
@testset "MatlabStructArray writing" begin
Expand Down
Loading