From 49b33393ddaf2096438e23aa8de3ec833923bb0b Mon Sep 17 00:00:00 2001 From: Joseph Kleinhenz Date: Wed, 30 Oct 2019 23:30:42 -0400 Subject: [PATCH] Fix hyperslab support for complex datasets (#591) * fix hyperslab support for complex datasets * add tests for hyperslab support for complex datasets --- src/HDF5.jl | 4 ++-- test/plain.jl | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/HDF5.jl b/src/HDF5.jl index 20ab22b15..b78de97cc 100644 --- a/src/HDF5.jl +++ b/src/HDF5.jl @@ -1764,7 +1764,7 @@ function getindex(dset::HDF5Dataset, indices::Union{AbstractRange{Int},Int}...) _getindex(dset,T, indices...) end function _getindex(dset::HDF5Dataset, T::Type, indices::Union{AbstractRange{Int},Int}...) - if !(T <: HDF5Scalar) + if !(T <: Union{HDF5Scalar, Complex{<:HDF5Scalar}}) error("Dataset indexing (hyperslab) is available only for bits types") end dsel_id = hyperslab(dset, indices...) @@ -1791,7 +1791,7 @@ function _setindex!(dset::HDF5Dataset,T::Type, X::Array, indices::Union{Abstract error("Dataset indexing (hyperslab) is available only for arrays") end ET = eltype(T) - if !(ET <: HDF5Scalar) + if !(ET <: Union{HDF5Scalar, Complex{<:HDF5Scalar}}) error("Dataset indexing (hyperslab) is available only for bits types") end if length(X) != prod(map(length, indices)) diff --git a/test/plain.jl b/test/plain.jl index d53f13290..26636f4a8 100644 --- a/test/plain.jl +++ b/test/plain.jl @@ -415,6 +415,11 @@ end # testset plain write(f, "Acmplx64", convert(Matrix{ComplexF64}, Acmplx)) write(f, "Acmplx32", convert(Matrix{ComplexF32}, Acmplx)) + dset = d_create(f, "Acmplx64_hyperslab", datatype(Complex{Float64}), dataspace(Acmplx)) + for i in 1:size(Acmplx, 2) + dset[:, i] = Acmplx[:,i] + end + HDF5.disable_complex_support() @test_throws ErrorException f["_ComplexF64"] = 1.0 + 2.0im @test_throws ErrorException write(f, "_Acmplx64", convert(Matrix{ComplexF64}, Acmplx)) @@ -436,6 +441,13 @@ end # testset plain @test convert(Matrix{ComplexF64}, Acmplx) == Acmplx64 @test eltype(Acmplx64) == ComplexF64 + dset = fr["Acmplx64_hyperslab"] + Acmplx64_hyperslab = zeros(eltype(dset), size(dset)) + for i in 1:size(dset, 2) + Acmplx64_hyperslab[:,i] = dset[:,i] + end + @test convert(Matrix{ComplexF64}, Acmplx) == Acmplx64_hyperslab + HDF5.disable_complex_support() z = read(fr, "ComplexF64") @test isa(z, HDF5.HDF5Compound{2})