diff --git a/src/HDF5.jl b/src/HDF5.jl index 569527c75..f1b3260bd 100644 --- a/src/HDF5.jl +++ b/src/HDF5.jl @@ -1431,6 +1431,7 @@ end # Reading with mmap ismmappable(::Type{<:ScalarType}) = true +ismmappable(::Type{Complex{T}}) where {T<:BitsType} = true ismmappable(::Type) = false ismmappable(obj::Dataset, ::Type{T}) where {T} = ismmappable(T) && iscontiguous(obj) ismmappable(obj::Dataset) = ismmappable(obj, get_jl_type(obj)) diff --git a/test/mmap.jl b/test/mmap.jl index 96402673f..60f77f9d6 100644 --- a/test/mmap.jl +++ b/test/mmap.jl @@ -35,4 +35,24 @@ A_mmaped = HDF5.readmmap(f["A"]) A_mmaped[1,1] = 33 close(f) -end +# issue #863 - fix mmapping complex arrays +f = h5open(fn, "w") +A = rand(ComplexF32, 5, 5) +f["A"] = A +close(f) +f = h5open(fn, "r+") +complex_support = HDF5.COMPLEX_SUPPORT[] +# Complex arrays can be mmapped when complex support is enabled +complex_support || HDF5.enable_complex_support() +@test A == read(f["A"]) +@test A == HDF5.readmmap(f["A"]) +# But mmapping should throw an error when support is disabled +HDF5.disable_complex_support() +At = [(r = real(c), i = imag(c)) for c in A] +@test read(f["A"]) == At # readable as array of NamedTuples +@test_throws ErrorException("Cannot mmap datasets of type $(eltype(At))") HDF5.readmmap(f["A"]) +close(f) +# Restore complex support state +complex_support && HDF5.enable_complex_support() + +end # testset