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
16 changes: 14 additions & 2 deletions src/MAT_HDF5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,19 @@ function m_writearray(parent::HDF5Parent, name::String, adata::AbstractArray{Com
end
end

function _normalize_arr(x)
if x isa Array
x
elseif x isa AbstractArray
collect(x)
else
x
end
end

# Write a scalar or array
function m_write(mfile::MatlabHDF5File, parent::HDF5Parent, name::String, data::Union{T, Complex{T}, Array{T}, Array{Complex{T}}}) where {T<:HDF5BitsOrBool}
function m_write(mfile::MatlabHDF5File, parent::HDF5Parent, name::String, data::Union{T, Complex{T}, AbstractArray{T}, AbstractArray{Complex{T}}}) where {T<:HDF5BitsOrBool}
data = _normalize_arr(data)
if isempty(data)
m_writeempty(parent, name, data)
return
Expand Down Expand Up @@ -443,7 +454,8 @@ function m_write(mfile::MatlabHDF5File, parent::HDF5Parent, name::String, str::A
end

# Write cell arrays
function m_write(mfile::MatlabHDF5File, parent::HDF5Parent, name::String, data::Array{T}) where T
function m_write(mfile::MatlabHDF5File, parent::HDF5Parent, name::String, data::AbstractArray{T}) where T
data = _normalize_arr(data)
pathrefs = "/#refs#"
fid = HDF5.file(parent)
local g
Expand Down
7 changes: 7 additions & 0 deletions test/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,10 @@ test_write(sd)
# note: compression is NOT effective when the dict contains many duplicate entries
# which are not compressible by themselves!
test_compression_effective(Dict("data" => fill(1.0, 1000)))

# test adjoint/reshape array
test_write(Dict("adjoint_arr"=>[1 2 3;4 5 6;7 8 9]'))
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)))
Loading