Skip to content

Commit

Permalink
move read_chunk/write_chunk to midlevel
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne committed Jun 23, 2021
1 parent cf63655 commit dd19d33
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 75 deletions.
8 changes: 4 additions & 4 deletions src/HDF5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,7 @@ Write a raw chunk at a given offset.
function do_write_chunk(dataset::Dataset, offset, chunk_bytes::Vector{UInt8}, filter_mask=0)
checkvalid(dataset)
offs = collect(API.hsize_t, reverse(offset)) .- 1
API.h5d_write_chunk(dataset, API.H5P_DEFAULT, UInt32(filter_mask), offs, length(chunk_bytes), chunk_bytes)
write_chunk(dataset, offs, chunk_bytes; filter_mask=UInt32(filter_mask))
end

"""
Expand All @@ -1724,7 +1724,7 @@ Write a raw chunk at a given linear index.
function do_write_chunk(dataset::Dataset, index::Integer, chunk_bytes::Vector{UInt8}, filter_mask=0)
checkvalid(dataset)
index -= 1
API.h5d_write_chunk(dataset, API.H5P_DEFAULT, UInt32(filter_mask), index, chunk_bytes)
write_chunk(dataset, index, chunk_bytes; filter_mask=UInt32(filter_mask))
end

"""
Expand All @@ -1737,7 +1737,7 @@ function do_read_chunk(dataset::Dataset, offset)
checkvalid(dataset)
offs = collect(API.hsize_t, reverse(offset)) .- 1
filters = Ref{UInt32}()
buf = API.h5d_read_chunk(dataset, offs; filters = filters)
buf = read_chunk(dataset, offs; filters = filters)
return (filters[], buf)
end

Expand All @@ -1751,7 +1751,7 @@ function do_read_chunk(dataset::Dataset, index::Integer)
checkvalid(dataset)
index -= 1
filters = Ref{UInt32}()
buf = API.h5d_read_chunk(dataset, index; filters = filters)
buf = read_chunk(dataset, index; filters = filters)
return (filters[], buf)
end

Expand Down
72 changes: 2 additions & 70 deletions src/api/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ end
"""
h5d_get_num_chunks(dataset_id, fspace_id = H5S_ALL)
Helper method to retrieve the number of chunks. Returns an integer of type `HDF5.hsize_t`.
Helper method to retrieve the number of chunks. Returns an integer of type `HDF5.API.hsize_t`.
"""
function h5d_get_num_chunks(dataset_id, fspace_id = H5S_ALL)
@static if v"1.10.5" > _libhdf5_build_ver
Expand All @@ -149,82 +149,14 @@ end
h5d_get_space_status(dataset_id)
Helper method to retrieve the status of the dataset space.
Returns a `HDF5.H5D_space_status_t` (`Cint`) indicating the status, see `HDF5.H5D_SPACE_STATUS_`* constants.
Returns a `HDF5.API.H5D_space_status_t` (`Cint`) indicating the status, see `HDF5.API.H5D_SPACE_STATUS_`* constants.
"""
function h5d_get_space_status(dataset_id)
r = Ref{H5D_space_status_t}()
h5d_get_space_status(dataset_id, r)
return r[]
end

"""
h5d_read_chunk(dataset_id, offset, [buf]; dxpl_id = HDF5.H5P_DEFAULT, filters = Ref{UInt32}())
Helper method to read chunks via 0-based offsets in a `Tuple`.
Argument `buf` is optional and defaults to a `Vector{UInt8}` of length determined by `HDF5.get_chunk_length`.
Argument `dxpl_id` can be supplied a keyword and defaults to `HDF5.H5P_DEFAULT`.
Argument `filters` can be retrieved by supplying a `Ref{UInt32}` value via a keyword argument.
This method returns `Vector{UInt8}`.
"""
function h5d_read_chunk(dataset_id, offset,
buf::Vector{UInt8} = Vector{UInt8}(undef, get_chunk_length(dataset_id));
dxpl_id = H5P_DEFAULT,
filters = Ref{UInt32}()
)
h5d_read_chunk(dataset_id, dxpl_id, offset, filters, buf)
return buf
end
h5d_read_chunk(dataset_id, dxpl_id, offset) = h5d_read_chunk(dataset_id, offset; dxpl_id = dxpl_id)
h5d_read_chunk(dataset_id, dxpl_id, offset, buf::Vector{UInt8}) = h5d_read_chunk(dataset_id, offset, buf; dxpl_id = dxpl_id)

"""
h5d_read_chunk(dataset_id, index::Integer, [buf]; dxpl_id = HDF5.H5P_DEFAULT, filters = Ref{UInt32}())
Helper method to read chunks via 0-based integer `index`.
Argument `buf` is optional and defaults to a `Vector{UInt8}` of length determined by `HDF5.h5d_get_chunk_info`.
Argument `dxpl_id` can be supplied a keyword and defaults to `HDF5.H5P_DEFAULT`.
Argument `filters` can be retrieved by supplying a `Ref{UInt32}` value via a keyword argument.
This method returns `Vector{UInt8}`.
"""
function h5d_read_chunk(dataset_id, index::Integer,
buf::Vector{UInt8} = Vector{UInt8}(undef, get_chunk_length(dataset_id));
dxpl_id = H5P_DEFAULT,
filters = Ref{UInt32}()
)
offset = [reverse(get_chunk_offset(dataset_id, index))...]
h5d_read_chunk(dataset_id, offset, buf; dxpl_id = dxpl_id, filters = filters)
end
h5d_read_chunk(dataset_id, dxpl_id, index::Integer) = h5d_read_chunk(dataset_id, index; dxpl_id = dxpl_id)
h5d_read_chunk(dataset_id, dxpl_id, index::Integer, buf::Vector{UInt8}) = h5d_read_chunk(dataset_id, index, buf; dxpl_id = dxpl_id)

"""
h5d_write_chunk(dataset_id, offset, buf::Vector{UInt8}; dxpl_id = HDF5.H5P_DEFAULT, filter_mask = 0)
Helper method to write chunks via 0-based offsets `offset` as a `Tuple`.
"""
function h5d_write_chunk(dataset_id, offset, buf::Vector{UInt8}; dxpl_id = H5P_DEFAULT, filter_mask=0)
h5d_write_chunk(dataset_id, dxpl_id, filter_mask, offset, length(buf), buf)
end
h5d_write_chunk(dataset_id, dxpl_id, filter_mask, offset, buf::Vector{UInt8}) =
h5d_write_chunk(dataset_id, offset, buf; dxpl_id = dxpl_id, filter_mask = filter_mask)

"""
h5d_write_chunk(dataset_id, index::Integer, buf::Vector{UInt8}; dxpl_id = H5P_DEFAULT, filter_mask = 0)
Helper method to write chunks via 0-based integer `index`.
"""
function h5d_write_chunk(dataset_id, index::Integer, buf::Vector{UInt8}; dxpl_id = H5P_DEFAULT, filter_mask = 0)
offset = [reverse(get_chunk_offset(dataset_id, index))...]
h5d_write_chunk(dataset_id, offset, buf; dxpl_id = dxpl_id, filter_mask = filter_mask)
end
h5d_write_chunk(dataset_id, dxpl_id, filter_mask, index::Integer, buf::Vector{UInt8}) =
h5d_write_chunk(dataset_id, index, buf; dxpl_id = dxpl_id, filter_mask = filter_mask)



###
### Error Interface
Expand Down
61 changes: 61 additions & 0 deletions src/api_midlevel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,64 @@ function vlen_get_buf_size(dataset_id)
space = API.h5d_get_space(dataset_id)
API.h5d_vlen_get_buf_size(dataset_id, type, space)
end



"""
HDF5.read_chunk(dataset_id, offset, [buf]; dxpl_id = HDF5.H5P_DEFAULT, filters = Ref{UInt32}())
Helper method to read chunks via 0-based offsets in a `Tuple`.
Argument `buf` is optional and defaults to a `Vector{UInt8}` of length determined by `HDF5.get_chunk_length`.
Argument `dxpl_id` can be supplied a keyword and defaults to `HDF5.H5P_DEFAULT`.
Argument `filters` can be retrieved by supplying a `Ref{UInt32}` value via a keyword argument.
This method returns `Vector{UInt8}`.
"""
function read_chunk(dataset_id, offset,
buf::Vector{UInt8} = Vector{UInt8}(undef, get_chunk_length(dataset_id));
dxpl_id = H5P_DEFAULT,
filters = Ref{UInt32}()
)
API.h5d_read_chunk(dataset_id, dxpl_id, offset, filters, buf)
return buf
end

"""
HDF5.read_chunk(dataset_id, index::Integer, [buf]; dxpl_id = HDF5.H5P_DEFAULT, filters = Ref{UInt32}())
Helper method to read chunks via 0-based integer `index`.
Argument `buf` is optional and defaults to a `Vector{UInt8}` of length determined by `HDF5.h5d_get_chunk_info`.
Argument `dxpl_id` can be supplied a keyword and defaults to `HDF5.H5P_DEFAULT`.
Argument `filters` can be retrieved by supplying a `Ref{UInt32}` value via a keyword argument.
This method returns `Vector{UInt8}`.
"""
function read_chunk(dataset_id, index::Integer,
buf::Vector{UInt8} = Vector{UInt8}(undef, get_chunk_length(dataset_id));
dxpl_id = H5P_DEFAULT,
filters = Ref{UInt32}()
)
offset = [reverse(get_chunk_offset(dataset_id, index))...]
read_chunk(dataset_id, offset, buf; dxpl_id = dxpl_id, filters = filters)
end

"""
HDF5.write_chunk(dataset_id, offset, buf::Vector{UInt8}; dxpl_id = HDF5.H5P_DEFAULT, filter_mask = 0)
Helper method to write chunks via 0-based offsets `offset` as a `Tuple`.
"""
function write_chunk(dataset_id, offset, buf::Vector{UInt8}; dxpl_id = H5P_DEFAULT, filter_mask=0)
h5d_write_chunk(dataset_id, dxpl_id, filter_mask, offset, length(buf), buf)
end

"""
HDF5.write_chunk(dataset_id, index::Integer, buf::Vector{UInt8}; dxpl_id = H5P_DEFAULT, filter_mask = 0)
Helper method to write chunks via 0-based integer `index`.
"""
function write_chunk(dataset_id, index::Integer, buf::Vector{UInt8}; dxpl_id = H5P_DEFAULT, filter_mask = 0)
offset = [reverse(get_chunk_offset(dataset_id, index))...]
write_chunk(dataset_id, offset, buf; dxpl_id = dxpl_id, filter_mask = filter_mask)
end
18 changes: 17 additions & 1 deletion src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,27 @@ function exists end
@deprecate get_dims(dspace::Union{Dataspace,Dataset,Attribute}) get_extent_dims(dspace) false
@deprecate set_dims!(dset::Dataspace) set_extent_dims(dset) false

### Changed in PR #844
@deprecate silence_errors(f::Function) f()

### Changed in PR #845
@deprecate h5d_read_chunk(dataset_id, offset, buf::Vector{UInt8} = Vector{UInt8}(undef, get_chunk_length(dataset_id)); kwargs...) read_chunk(dataset_id, offset, buf; kwargs...) false
@deprecate h5d_read_chunk(dataset_id, dxpl_id, offset) read_chunk(dataset_id, offset; dxpl_id = dxpl_id) false
@deprecate h5d_read_chunk(dataset_id, dxpl_id, offset, buf::Vector{UInt8}) read_chunk(dataset_id, offset, buf; dxpl_id = dxpl_id) false

@deprecate h5d_read_chunk(dataset_id, index::Integer, buf::Vector{UInt8} = Vector{UInt8}(undef, get_chunk_length(dataset_id)); kwargs...) read_chunk(dataset_id, index, buf; kwargs...) false
@deprecate h5d_read_chunk(dataset_id, dxpl_id, index::Integer) read_chunk(dataset_id, index; dxpl_id = dxpl_id) false
@deprecate h5d_read_chunk(dataset_id, dxpl_id, index::Integer, buf::Vector{UInt8}) read_chunk(dataset_id, index, buf; dxpl_id = dxpl_id) false

@deprecate h5d_write_chunk(dataset_id, offset, buf::Vector{UInt8}; kwargs...) write_chunk(dataset_id, offset, buf; kwargs...) false
@deprecate h5d_write_chunk(dataset_id, dxpl_id, filter_mask, offset, buf::Vector{UInt8}) write_chunk(dataset_id, offset, buf; dxpl_id = dxpl_id, filter_mask = filter_mask) false

@deprecate h5d_write_chunk(dataset_id, index::Integer, buf::Vector{UInt8}; kwargs...) write_chunk(dataset_id, index, buf; kwargs...) false
@deprecate h5d_write_chunk(dataset_id, dxpl_id, filter_mask, index::Integer, buf::Vector{UInt8}) write_chunk(dataset_id, index, buf; dxpl_id = dxpl_id, filter_mask = filter_mask) false

for name in names(API; all=true)
if name names(HDF5; all=true) && startswith(uppercase(String(name)), "H")
depmsg = ", use HDF5.API.$name instead."
@eval Base.@deprecate_binding $name API.$name false $depmsg
end
end
end

0 comments on commit dd19d33

Please sign in to comment.