Skip to content

Commit

Permalink
Fix hyperslab support for complex datasets (#591)
Browse files Browse the repository at this point in the history
* fix hyperslab support for complex datasets

* add tests for hyperslab support for complex datasets
  • Loading branch information
kleinhenz authored and musm committed Oct 31, 2019
1 parent 39c04c4 commit 49b3339
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/HDF5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand All @@ -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))
Expand Down
12 changes: 12 additions & 0 deletions test/plain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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})
Expand Down

0 comments on commit 49b3339

Please sign in to comment.