Skip to content

Commit 49b3339

Browse files
kleinhenzmusm
authored andcommitted
Fix hyperslab support for complex datasets (#591)
* fix hyperslab support for complex datasets * add tests for hyperslab support for complex datasets
1 parent 39c04c4 commit 49b3339

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/HDF5.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,7 @@ function getindex(dset::HDF5Dataset, indices::Union{AbstractRange{Int},Int}...)
17641764
_getindex(dset,T, indices...)
17651765
end
17661766
function _getindex(dset::HDF5Dataset, T::Type, indices::Union{AbstractRange{Int},Int}...)
1767-
if !(T <: HDF5Scalar)
1767+
if !(T <: Union{HDF5Scalar, Complex{<:HDF5Scalar}})
17681768
error("Dataset indexing (hyperslab) is available only for bits types")
17691769
end
17701770
dsel_id = hyperslab(dset, indices...)
@@ -1791,7 +1791,7 @@ function _setindex!(dset::HDF5Dataset,T::Type, X::Array, indices::Union{Abstract
17911791
error("Dataset indexing (hyperslab) is available only for arrays")
17921792
end
17931793
ET = eltype(T)
1794-
if !(ET <: HDF5Scalar)
1794+
if !(ET <: Union{HDF5Scalar, Complex{<:HDF5Scalar}})
17951795
error("Dataset indexing (hyperslab) is available only for bits types")
17961796
end
17971797
if length(X) != prod(map(length, indices))

test/plain.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,11 @@ end # testset plain
415415
write(f, "Acmplx64", convert(Matrix{ComplexF64}, Acmplx))
416416
write(f, "Acmplx32", convert(Matrix{ComplexF32}, Acmplx))
417417

418+
dset = d_create(f, "Acmplx64_hyperslab", datatype(Complex{Float64}), dataspace(Acmplx))
419+
for i in 1:size(Acmplx, 2)
420+
dset[:, i] = Acmplx[:,i]
421+
end
422+
418423
HDF5.disable_complex_support()
419424
@test_throws ErrorException f["_ComplexF64"] = 1.0 + 2.0im
420425
@test_throws ErrorException write(f, "_Acmplx64", convert(Matrix{ComplexF64}, Acmplx))
@@ -436,6 +441,13 @@ end # testset plain
436441
@test convert(Matrix{ComplexF64}, Acmplx) == Acmplx64
437442
@test eltype(Acmplx64) == ComplexF64
438443

444+
dset = fr["Acmplx64_hyperslab"]
445+
Acmplx64_hyperslab = zeros(eltype(dset), size(dset))
446+
for i in 1:size(dset, 2)
447+
Acmplx64_hyperslab[:,i] = dset[:,i]
448+
end
449+
@test convert(Matrix{ComplexF64}, Acmplx) == Acmplx64_hyperslab
450+
439451
HDF5.disable_complex_support()
440452
z = read(fr, "ComplexF64")
441453
@test isa(z, HDF5.HDF5Compound{2})

0 commit comments

Comments
 (0)