Skip to content

Commit

Permalink
Fix #1084, create_dataset with Type and Dataspace
Browse files Browse the repository at this point in the history
Also expand definitions for dataspace with two positional arguments.
Pin Blosc_jll to 1.21.2 if AVX2 is not detected. See Blosc/c-blosc#371
  • Loading branch information
mkitti committed Jun 29, 2023
1 parent 1b67f35 commit bc0dc44
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/datasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ create_dataset(
dspace_dims::Int...;
pv...
) = create_dataset(checkvalid(parent), path, datatype(dtype), dataspace(dspace_dims); pv...)
create_dataset(
parent::Union{File,Group},
path::Union{AbstractString,Nothing},
dtype::Type,
dspace::Dataspace;
pv...
) = create_dataset(checkvalid(parent), path, datatype(dtype), dspace; pv...)

# Get the datatype of a dataset
datatype(dset::Dataset) = Datatype(API.h5d_get_type(checkvalid(dset)), file(dset))
Expand Down
4 changes: 4 additions & 0 deletions src/dataspaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,17 @@ dataspace(n::Nothing) = Dataspace(API.h5s_create(API.H5S_NULL))
# for giving sizes explicitly
"""
dataspace(dims::Tuple; max_dims::Tuple=dims)
dataspace(dims::Tuple, max_dims::Tuple)
Construct a simple `Dataspace` for the given dimensions `dims`. The maximum
dimensions `maxdims` specifies the maximum possible size: `-1` can be used to
indicate unlimited dimensions.
"""
dataspace(sz::Dims{N}; max_dims::Union{Dims{N},Tuple{}}=()) where {N} =
_dataspace(sz, max_dims)
dataspace(sz::Dims{N}, max_dims::Union{Dims{N},Tuple{}}) where {N} =
_dataspace(sz, max_dims)
dataspace(dims::Tuple{Dims{N},Dims{N}}) where {N} = _dataspace(first(dims), last(dims))
dataspace(sz1::Int, sz2::Int, sz3::Int...; max_dims::Union{Dims,Tuple{}}=()) =
_dataspace(tuple(sz1, sz2, sz3...), max_dims)

Expand Down
61 changes: 61 additions & 0 deletions test/create_dataset.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using HDF5
using Test

"""
Test Set create_dataset
Test the combination of arguments to create_dataset.
"""

@testset "create_dataset" begin
mktemp() do fn, io
h5open(fn, "w") do h5f
h5g = create_group(h5f, "test_group")

# Arguments
# Test file and group
parents = (h5f, h5g)
# Test anonymous dattaset, String, and SubString
names = (nothing, "test_dataset", @view("test_dataset"[1:4]))
# Test primitive, HDF5.Datatype, non-primitive, non-primitive HDF5.Datatype
types = (UInt8, datatype(UInt8), Complex{Float32}, datatype(Complex{Float32}))
# Test Tuple, HDF5.Dataspace, two tuples (extendible), extendible HDF5.Dataspace
spaces = (
(3, 4),
dataspace((16, 16)),
((4, 4), (8, 8)),
dataspace((16, 16); max_dims=(32, 32))
)
# TODO: test keywords

# Create argument cross product
p = Iterators.product(parents, names, types, spaces)

for (parent, name, type, space) in p
try
# create a chunked dataset since contiguous datasets are not extendible
ds = create_dataset(parent, name, type, space; chunk=(2, 2))
@test datatype(ds) == datatype(type)
@test dataspace(ds) == dataspace(space)
@test isvalid(ds)
close(ds)
if !isnothing(name)
# if it is not an anonymous dataset, try to open it
ds2 = open_dataset(parent, name)
@test isvalid(ds2)
close(ds2)
delete_object(parent, name)
end
catch err
throw(ArgumentError("""
Error occured with (
$parent :: $(typeof(parent)),
$name :: $(typeof(name)),
$type :: $(typeof(type)),
$space :: $(typeof(space)))
"""))
end
end
end
end
end
4 changes: 4 additions & 0 deletions test/dataspace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ using Test
@test dataspace((5,)) == ds_vector
@test dataspace((5, 7)) == ds_matrix != ds_maxdim
@test dataspace((5, 7); max_dims=(20, 20)) == ds_maxdim != ds_matrix
@test dataspace((5, 7), (20, 20)) == ds_maxdim
@test dataspace(((5, 7), (20, 20))) == ds_maxdim
@test dataspace((1,); max_dims=(-1,)) == ds_unlim
@test dataspace((1,), (-1,)) == ds_unlim
@test dataspace(((1,), (-1,))) == ds_unlim
# for ≥ 2 numbers, same as single tuple argument
@test dataspace(5, 7) == ds_matrix
@test dataspace(5, 7, 1) == dataspace((5, 7, 1))
Expand Down
15 changes: 11 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ using HDF5
using Test
using Pkg
filter_path = joinpath(dirname(pathof(HDF5)), "..", "filters")
Pkg.develop(PackageSpec(; path=joinpath(filter_path, "H5Zblosc")))
Pkg.develop(PackageSpec(; path=joinpath(filter_path, "H5Zbzip2")))
Pkg.develop(PackageSpec(; path=joinpath(filter_path, "H5Zlz4")))
Pkg.develop(PackageSpec(; path=joinpath(filter_path, "H5Zzstd")))
if !Base.BinaryPlatforms.CPUID.test_cpu_feature(Base.BinaryPlatforms.CPUID.JL_X86_avx2)
Pkg.add(PackageSpec(name="Blosc_jll", version=v"1.21.2+0"))
end
Pkg.develop([
PackageSpec(; path=joinpath(filter_path, "H5Zblosc")),
PackageSpec(; path=joinpath(filter_path, "H5Zbzip2")),
PackageSpec(; path=joinpath(filter_path, "H5Zlz4")),
PackageSpec(; path=joinpath(filter_path, "H5Zzstd")),
])
@static if VERSION >= v"1.6"
Pkg.develop(PackageSpec(; path=joinpath(filter_path, "H5Zbitshuffle")))
end
Expand All @@ -29,6 +34,8 @@ end
@testset "HDF5.jl" begin
@debug "plain"
include("plain.jl")
@debug "create_dataset"
include("create_dataset.jl")
@debug "strings"
include("strings.jl")
@debug "api"
Expand Down

0 comments on commit bc0dc44

Please sign in to comment.