From 5192b0b0c52f4e2ded7a5f28522d02e6d0baaac7 Mon Sep 17 00:00:00 2001 From: zhuwenhao Date: Fri, 6 Jun 2025 11:08:08 +0800 Subject: [PATCH 1/6] Support saving AbstractArray as mat file --- src/MAT_HDF5.jl | 16 ++++++++++++++-- test/write.jl | 4 ++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/MAT_HDF5.jl b/src/MAT_HDF5.jl index 00d2f54..b0d36d6 100644 --- a/src/MAT_HDF5.jl +++ b/src/MAT_HDF5.jl @@ -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 @@ -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 diff --git a/test/write.jl b/test/write.jl index 3a1d820..97275d5 100644 --- a/test/write.jl +++ b/test/write.jl @@ -129,3 +129,7 @@ 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("aa"=>[1 2 3;4 5 6;7 8 9]')) +test_write(Dict("aa"=>reshape([1 2 3;4 5 6;7 8 9]',1,9))) \ No newline at end of file From d919989d067181a47beec278bab50b2c936199ac Mon Sep 17 00:00:00 2001 From: zhuwenhao Date: Fri, 6 Jun 2025 11:15:52 +0800 Subject: [PATCH 2/6] Improve the test case --- test/write.jl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/write.jl b/test/write.jl index 97275d5..ae4a2eb 100644 --- a/test/write.jl +++ b/test/write.jl @@ -131,5 +131,8 @@ test_write(sd) test_compression_effective(Dict("data" => fill(1.0, 1000))) # test adjoint/reshape array -test_write(Dict("aa"=>[1 2 3;4 5 6;7 8 9]')) -test_write(Dict("aa"=>reshape([1 2 3;4 5 6;7 8 9]',1,9))) \ No newline at end of file +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))) \ No newline at end of file From ffa72728195305eeada81e01aaf4b8f00be6681f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E5=AE=B6=E8=B1=AA?= Date: Mon, 9 Jun 2025 11:10:54 +0800 Subject: [PATCH 3/6] add gitlab ci --- .tongyuan/.gitlab-ci.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .tongyuan/.gitlab-ci.yml diff --git a/.tongyuan/.gitlab-ci.yml b/.tongyuan/.gitlab-ci.yml new file mode 100644 index 0000000..c8d4ecd --- /dev/null +++ b/.tongyuan/.gitlab-ci.yml @@ -0,0 +1,20 @@ +include: + - 'https://git.tongyuan.cc/syslab/ci/julia-ci-templates/raw/main/v3.yml' + +# 执行 Julia 标准单元测试 pkg> test +# 进阶配置参考阅读: https://git.tongyuan.cc/syslab/ci/julia-ci-templates#Linux单元测试 +单元测试(Ubuntu): + parallel: + matrix: + - julia_version: ["1.7", "1.9", "1.10"] + # variables: + # python_version: "3.7" + extends: + - .ubuntu_x86_64 + - .setup_julia + - .test_linux + +注册: + needs: [] + extends: + - .register_fork From 3192f977ffe312cdf4db193576c71e92163de4cd Mon Sep 17 00:00:00 2001 From: zhuwenhao Date: Fri, 6 Jun 2025 11:08:08 +0800 Subject: [PATCH 4/6] Support saving AbstractArray as mat file --- src/MAT_HDF5.jl | 16 ++++++++++++++-- test/write.jl | 4 ++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/MAT_HDF5.jl b/src/MAT_HDF5.jl index 00d2f54..b0d36d6 100644 --- a/src/MAT_HDF5.jl +++ b/src/MAT_HDF5.jl @@ -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 @@ -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 diff --git a/test/write.jl b/test/write.jl index 3a1d820..97275d5 100644 --- a/test/write.jl +++ b/test/write.jl @@ -129,3 +129,7 @@ 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("aa"=>[1 2 3;4 5 6;7 8 9]')) +test_write(Dict("aa"=>reshape([1 2 3;4 5 6;7 8 9]',1,9))) \ No newline at end of file From b7458f32c798917ba17c53b79b7668b5f51d20f8 Mon Sep 17 00:00:00 2001 From: zhuwenhao Date: Fri, 6 Jun 2025 11:15:52 +0800 Subject: [PATCH 5/6] Improve the test case --- test/write.jl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/write.jl b/test/write.jl index 97275d5..ae4a2eb 100644 --- a/test/write.jl +++ b/test/write.jl @@ -131,5 +131,8 @@ test_write(sd) test_compression_effective(Dict("data" => fill(1.0, 1000))) # test adjoint/reshape array -test_write(Dict("aa"=>[1 2 3;4 5 6;7 8 9]')) -test_write(Dict("aa"=>reshape([1 2 3;4 5 6;7 8 9]',1,9))) \ No newline at end of file +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))) \ No newline at end of file From b3031bc51beb7107385ee854ead79c681228000b Mon Sep 17 00:00:00 2001 From: zhuwenhao Date: Mon, 9 Jun 2025 14:51:36 +0800 Subject: [PATCH 6/6] remove unexpected file --- .tongyuan/.gitlab-ci.yml | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 .tongyuan/.gitlab-ci.yml diff --git a/.tongyuan/.gitlab-ci.yml b/.tongyuan/.gitlab-ci.yml deleted file mode 100644 index c8d4ecd..0000000 --- a/.tongyuan/.gitlab-ci.yml +++ /dev/null @@ -1,20 +0,0 @@ -include: - - 'https://git.tongyuan.cc/syslab/ci/julia-ci-templates/raw/main/v3.yml' - -# 执行 Julia 标准单元测试 pkg> test -# 进阶配置参考阅读: https://git.tongyuan.cc/syslab/ci/julia-ci-templates#Linux单元测试 -单元测试(Ubuntu): - parallel: - matrix: - - julia_version: ["1.7", "1.9", "1.10"] - # variables: - # python_version: "3.7" - extends: - - .ubuntu_x86_64 - - .setup_julia - - .test_linux - -注册: - needs: [] - extends: - - .register_fork