Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support BITSHUFFLE option of Blosc >= v0.7.3 #899

Merged
merged 1 commit into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion filters/H5Zblosc/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"

[compat]
HDF5 = "0.16"
Blosc = "0.7.1"
Blosc = "0.7.3"
julia = "1.3"
13 changes: 10 additions & 3 deletions filters/H5Zblosc/src/H5Zblosc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import HDF5.Filters: filterid, register_filter, filtername, filter_func, filter_

export H5Z_FILTER_BLOSC, blosc_filter, BloscFilter

# Import Blosc shuffle constants
import Blosc: NOSHUFFLE, SHUFFLE, BITSHUFFLE

const H5Z_FILTER_BLOSC = API.H5Z_filter_t(32001) # Filter ID registered with the HDF Group for Blosc
const FILTER_BLOSC_VERSION = 2
Expand Down Expand Up @@ -65,7 +67,7 @@ function blosc_filter(flags::Cuint, cd_nelmts::Csize_t,
# Compression level:
clevel = cd_nelmts >= 5 ? unsafe_load(cd_values, 5) : Cuint(5)
# Do shuffle:
doshuffle = cd_nelmts >= 6 ? unsafe_load(cd_values, 6) != 0 : true
doshuffle = cd_nelmts >= 6 ? unsafe_load(cd_values, 6) : SHUFFLE

if (flags & API.H5Z_FLAG_REVERSE) == 0 # compressing
# Allocate an output buffer exactly as long as the input data; if
Expand Down Expand Up @@ -134,7 +136,8 @@ struct BloscFilter <: Filter
compcode::Cuint
end

function BloscFilter(;level=5, shuffle=true, compressor="blosclz")
function BloscFilter(;level=5, shuffle=SHUFFLE, compressor="blosclz")
Blosc.isvalidshuffle(shuffle) || throw(ArgumentError("invalid blosc shuffle $shuffle"))
compcode = Blosc.compcode(compressor)
BloscFilter(0,0,0,0,level,shuffle,compcode)
end
Expand All @@ -151,13 +154,17 @@ filter_cfunc(::Type{BloscFilter}) = @cfunction(blosc_filter, Csize_t,
function Base.show(io::IO, blosc::BloscFilter)
print(io, BloscFilter,
"(level=", Int(blosc.level),
",shuffle=", blosc.shuffle!=0,
",shuffle=", blosc.shuffle==NOSHUFFLE ? "NOSHUFFLE" :
blosc.shuffle==SHUFFLE ? "SHUFFLE" :
blosc.shuffle==BITSHUFFLE ? "BITSHUFFLE" :
"UNKNOWN",
",compressor=", Blosc.compname(blosc.compcode),
")")
end

function Base.push!(f::FilterPipeline, blosc::BloscFilter)
0 <= blosc.level <= 9 || throw(ArgumentError("blosc compression $(blosc.level) not in [0,9]"))
Blosc.isvalidshuffle(blosc.shuffle) || throw(ArgumentError("invalid blosc shuffle $(blosc.shuffle)"))
ref = Ref(blosc)
GC.@preserve ref begin
API.h5p_set_filter(f.plist, filterid(BloscFilter), API.H5Z_FLAG_OPTIONAL, div(sizeof(BloscFilter), sizeof(Cuint)), pointer_from_objref(ref))
Expand Down
8 changes: 7 additions & 1 deletion test/filter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ for (name, filter) in compressionFilters

end

ds = create_dataset(
f, "blosc_bitshuffle", datatype(data), dataspace(data),
chunk=(100,100), filters=BloscFilter(shuffle=H5Zblosc.BITSHUFFLE)
)
write(ds, data)

# Close and re-open file for reading
close(f)
Expand All @@ -74,7 +79,8 @@ for name in keys(f)
if startswith(name, "shuffle+")
@test filters[1] isa Shuffle
@test filters[2] isa compressionFilters[name[9:end]]
elseif haskey(compressionFilters, name)
elseif haskey(compressionFilters, name) || name == "blosc_bitshuffle"
name = replace(name, r"_.*"=>"")
@test filters[1] isa compressionFilters[name]
end
end
Expand Down