Skip to content

Commit

Permalink
Clean up Dataspaces
Browse files Browse the repository at this point in the history
- define HDF5.UNLIMITED constant for unlimited values
- improve printing of Dataspace objects
- define Dataspace contructors, deprecate methods for dataspace functions
  • Loading branch information
simonbyrne committed Sep 5, 2023
1 parent 72f39f3 commit 762c8fe
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 210 deletions.
1 change: 1 addition & 0 deletions src/HDF5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export @read,
create_property,
group_info,
object_info,
Dataspace,
dataspace,
datatype,
Filters,
Expand Down
35 changes: 0 additions & 35 deletions src/api_midlevel.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# This file defines midlevel api wrappers. We include name normalization for methods that are
# applicable to different hdf5 api-layers. We still try to adhere close proximity to the underlying
# method name in the hdf5-library.

"""
HDF5.set_extent_dims(dset::HDF5.Dataset, new_dims::Dims)
Expand All @@ -13,40 +12,6 @@ function set_extent_dims(dset::Dataset, size::Dims)
API.h5d_set_extent(dset, API.hsize_t[reverse(size)...])
end

"""
HDF5.set_extent_dims(dspace::HDF5.Dataspace, new_dims::Dims, max_dims::Union{Dims,Nothing} = nothing)
Change the dimensions of a dataspace `dspace` to `new_dims`, optionally with the maximum possible
dimensions `max_dims` different from the active size `new_dims`. If not given, `max_dims` is set equal
to `new_dims`.
"""
function set_extent_dims(
dspace::Dataspace, size::Dims, max_dims::Union{Dims,Nothing}=nothing
)
checkvalid(dspace)
rank = length(size)
current_size = API.hsize_t[reverse(size)...]
maximum_size = isnothing(max_dims) ? C_NULL : [reverse(max_dims .% API.hsize_t)...]
API.h5s_set_extent_simple(dspace, rank, current_size, maximum_size)
return nothing
end

"""
HDF5.get_extent_dims(obj::Union{HDF5.Dataspace, HDF5.Dataset, HDF5.Attribute}) -> dims, maxdims
Get the array dimensions from a dataspace, dataset, or attribute and return a tuple of `dims` and `maxdims`.
"""
function get_extent_dims(obj::Union{Dataspace,Dataset,Attribute})
dspace = obj isa Dataspace ? checkvalid(obj) : dataspace(obj)
h5_dims, h5_maxdims = API.h5s_get_simple_extent_dims(dspace)
# reverse dimensions since hdf5 uses C-style order
N = length(h5_dims)
dims = ntuple(i -> @inbounds(Int(h5_dims[N - i + 1])), N)
maxdims = ntuple(i -> @inbounds(h5_maxdims[N - i + 1]) % Int, N) # allows max_dims to be specified as -1 without triggering an overflow
obj isa Dataspace || close(dspace)
return dims, maxdims
end

"""
HDF5.get_chunk_offset(dataset_id, index)
Expand Down
Loading

0 comments on commit 762c8fe

Please sign in to comment.