-
Notifications
You must be signed in to change notification settings - Fork 146
Add support for Float16 #1229
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
Add support for Float16 #1229
Changes from 1 commit
d2d4386
ca677b0
1f97e35
e545374
1a38a1b
82ee49b
b089094
54ae520
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -523,17 +523,18 @@ const H5T_C_S1 = _read_const(:H5T_C_S1_g) | |||||
| const H5T_STD_REF_OBJ = _read_const(:H5T_STD_REF_OBJ_g) | ||||||
| const H5T_STD_REF_DSETREG = _read_const(:H5T_STD_REF_DSETREG_g) | ||||||
| # Native types | ||||||
| const H5T_NATIVE_B8 = _read_const(:H5T_NATIVE_B8_g) | ||||||
| const H5T_NATIVE_INT8 = _read_const(:H5T_NATIVE_INT8_g) | ||||||
| const H5T_NATIVE_UINT8 = _read_const(:H5T_NATIVE_UINT8_g) | ||||||
| const H5T_NATIVE_INT16 = _read_const(:H5T_NATIVE_INT16_g) | ||||||
| const H5T_NATIVE_UINT16 = _read_const(:H5T_NATIVE_UINT16_g) | ||||||
| const H5T_NATIVE_INT32 = _read_const(:H5T_NATIVE_INT32_g) | ||||||
| const H5T_NATIVE_UINT32 = _read_const(:H5T_NATIVE_UINT32_g) | ||||||
| const H5T_NATIVE_INT64 = _read_const(:H5T_NATIVE_INT64_g) | ||||||
| const H5T_NATIVE_UINT64 = _read_const(:H5T_NATIVE_UINT64_g) | ||||||
| const H5T_NATIVE_FLOAT = _read_const(:H5T_NATIVE_FLOAT_g) | ||||||
| const H5T_NATIVE_DOUBLE = _read_const(:H5T_NATIVE_DOUBLE_g) | ||||||
| const H5T_NATIVE_B8 = _read_const(:H5T_NATIVE_B8_g) | ||||||
| const H5T_NATIVE_INT8 = _read_const(:H5T_NATIVE_INT8_g) | ||||||
| const H5T_NATIVE_UINT8 = _read_const(:H5T_NATIVE_UINT8_g) | ||||||
| const H5T_NATIVE_INT16 = _read_const(:H5T_NATIVE_INT16_g) | ||||||
| const H5T_NATIVE_UINT16 = _read_const(:H5T_NATIVE_UINT16_g) | ||||||
| const H5T_NATIVE_INT32 = _read_const(:H5T_NATIVE_INT32_g) | ||||||
| const H5T_NATIVE_UINT32 = _read_const(:H5T_NATIVE_UINT32_g) | ||||||
| const H5T_NATIVE_INT64 = _read_const(:H5T_NATIVE_INT64_g) | ||||||
| const H5T_NATIVE_UINT64 = _read_const(:H5T_NATIVE_UINT64_g) | ||||||
| const H5T_NATIVE_FLOAT16 = _read_const(:H5T_NATIVE_FLOAT16_g) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need something for earlier versions of HDF5 here (pre 2.0).
|
||||||
| const H5T_NATIVE_FLOAT16 = _read_const(:H5T_NATIVE_FLOAT16_g) | |
| const H5T_NATIVE_FLOAT16 = _has_symbol(:H5T_NATIVE_FLOAT16_g) ? _read_const(:H5T_NATIVE_FLOAT16_g) : hid_t(-1) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -142,6 +142,7 @@ hdf5_type_id(::Type{Int32}) = API.H5T_NATIVE_INT32 | |||||||||||||||
| hdf5_type_id(::Type{UInt32}) = API.H5T_NATIVE_UINT32 | ||||||||||||||||
| hdf5_type_id(::Type{Int64}) = API.H5T_NATIVE_INT64 | ||||||||||||||||
| hdf5_type_id(::Type{UInt64}) = API.H5T_NATIVE_UINT64 | ||||||||||||||||
| hdf5_type_id(::Type{Float16}) = API.H5T_NATIVE_FLOAT16 | ||||||||||||||||
|
||||||||||||||||
| hdf5_type_id(::Type{Float16}) = API.H5T_NATIVE_FLOAT16 | |
| function hdf5_type_id(::Type{Float16}) | |
| if API._has_symbol(:H5T_NATIVE_FLOAT16_g) | |
| return API.H5T_NATIVE_FLOAT16 | |
| end | |
| throw(ArgumentError("Float16 HDF5 datatypes are not supported by the linked HDF5 library")) | |
| end |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -41,6 +41,7 @@ end | |||||||||||||||||
| A = randn(3, 5) | ||||||||||||||||||
| write(f, "Afloat64", convert(Matrix{Float64}, A)) | ||||||||||||||||||
| write(f, "Afloat32", convert(Matrix{Float32}, A)) | ||||||||||||||||||
| write(f, "Afloat16", convert(Matrix{Float16}, A)) | ||||||||||||||||||
| Ai = rand(1:20, 2, 4) | ||||||||||||||||||
| write(f, "Aint8", convert(Matrix{Int8}, Ai)) | ||||||||||||||||||
| f["Aint16"] = convert(Matrix{Int16}, Ai) | ||||||||||||||||||
|
|
@@ -176,6 +177,9 @@ end | |||||||||||||||||
| @test zerodim == 42 && isa(zerodim, Int32) | ||||||||||||||||||
| bloscempty = read(fr, "bloscempty") | ||||||||||||||||||
| @test bloscempty == Int64[] && isa(bloscempty, Vector{Int64}) | ||||||||||||||||||
| Af16 = read(fr, "Afloat16") | ||||||||||||||||||
| @test convert(Matrix{Float16}, A) == Af16 | ||||||||||||||||||
| @test eltype(Af16) == Float16 | ||||||||||||||||||
|
||||||||||||||||||
| Af16 = read(fr, "Afloat16") | |
| @test convert(Matrix{Float16}, A) == Af16 | |
| @test eltype(Af16) == Float16 | |
| if HDF5.API._has_symbol(:H5T_NATIVE_FLOAT16_g) | |
| Af16 = read(fr, "Afloat16") | |
| @test convert(Matrix{Float16}, A) == Af16 | |
| @test eltype(Af16) == Float16 | |
| end |
Copilot
AI
Apr 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ComplexF16 datasets are now written/read unconditionally. This will break on HDF5 builds that don’t support Float16 type IDs (since complex compound type creation relies on hdf5_type_id(Float16)). Please make these tests conditional on Float16 datatype support (or update the minimum supported HDF5 version) to avoid failures on older libhdf5 installations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is probably unrelated.