Skip to content

Commit

Permalink
Fix JuliaIO#863, support mmapping complex arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
jmert committed Aug 20, 2021
1 parent d8287f2 commit f296435
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/HDF5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
22 changes: 21 additions & 1 deletion test/mmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f296435

Please sign in to comment.