Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix hyperslab support for complex datasets #591

Merged
merged 2 commits into from
Oct 31, 2019
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
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