From 1b67f35cdc7478ce4cbea865a03ea4978f82f958 Mon Sep 17 00:00:00 2001 From: Mark Kittisopikul Date: Wed, 28 Jun 2023 23:50:26 -0400 Subject: [PATCH 1/3] Fix #1083 maxdims -> max_dims in dataspace documentation --- src/dataspaces.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dataspaces.jl b/src/dataspaces.jl index cea2773ee..a668bf614 100644 --- a/src/dataspaces.jl +++ b/src/dataspaces.jl @@ -77,7 +77,7 @@ dataspace(n::Nothing) = Dataspace(API.h5s_create(API.H5S_NULL)) # for giving sizes explicitly """ - dataspace(dims::Tuple; maxdims::Tuple=dims) + dataspace(dims::Tuple; max_dims::Tuple=dims) Construct a simple `Dataspace` for the given dimensions `dims`. The maximum dimensions `maxdims` specifies the maximum possible size: `-1` can be used to From bc0dc44b340b419f5569f183807e4123f438b2a4 Mon Sep 17 00:00:00 2001 From: Mark Kittisopikul Date: Thu, 29 Jun 2023 02:40:53 -0400 Subject: [PATCH 2/3] Fix #1084, create_dataset with Type and Dataspace Also expand definitions for dataspace with two positional arguments. Pin Blosc_jll to 1.21.2 if AVX2 is not detected. See https://github.com/Blosc/c-blosc/issues/371 --- src/datasets.jl | 7 +++++ src/dataspaces.jl | 4 +++ test/create_dataset.jl | 61 ++++++++++++++++++++++++++++++++++++++++++ test/dataspace.jl | 4 +++ test/runtests.jl | 15 ++++++++--- 5 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 test/create_dataset.jl diff --git a/src/datasets.jl b/src/datasets.jl index 6d6c88ea5..8324d4836 100644 --- a/src/datasets.jl +++ b/src/datasets.jl @@ -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)) diff --git a/src/dataspaces.jl b/src/dataspaces.jl index a668bf614..c6a1c768d 100644 --- a/src/dataspaces.jl +++ b/src/dataspaces.jl @@ -78,6 +78,7 @@ 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 @@ -85,6 +86,9 @@ 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) diff --git a/test/create_dataset.jl b/test/create_dataset.jl new file mode 100644 index 000000000..6a2e7407d --- /dev/null +++ b/test/create_dataset.jl @@ -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 diff --git a/test/dataspace.jl b/test/dataspace.jl index 75c31d16e..46d1a0f4b 100644 --- a/test/dataspace.jl +++ b/test/dataspace.jl @@ -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)) diff --git a/test/runtests.jl b/test/runtests.jl index b9b209488..d8fb3b145 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 @@ -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" From 311ec976b1cb59b0e2f3b700c24aa583a21a62de Mon Sep 17 00:00:00 2001 From: Mark Kittisopikul Date: Thu, 29 Jun 2023 02:49:07 -0400 Subject: [PATCH 3/3] Formatter --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index d8fb3b145..de9021459 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -14,7 +14,7 @@ using Test using Pkg filter_path = joinpath(dirname(pathof(HDF5)), "..", "filters") 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")) + Pkg.add(PackageSpec(; name="Blosc_jll", version=v"1.21.2+0")) end Pkg.develop([ PackageSpec(; path=joinpath(filter_path, "H5Zblosc")),