Skip to content

Commit b2e1c7f

Browse files
committed
Use new runtime ability to define Float16 type
1 parent 5243ccc commit b2e1c7f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/HDF5.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,14 @@ hdf5_type_id(::Type{Int32}) = H5T.NATIVE_INT32
8686
hdf5_type_id(::Type{UInt32}) = H5T.NATIVE_UINT32
8787
hdf5_type_id(::Type{Int64}) = H5T.NATIVE_INT64
8888
hdf5_type_id(::Type{UInt64}) = H5T.NATIVE_UINT64
89+
hdf5_type_id(::Type{Float16}) = H5T.NATIVE_FLOAT16
8990
hdf5_type_id(::Type{Float32}) = H5T.NATIVE_FLOAT
9091
hdf5_type_id(::Type{Float64}) = H5T.NATIVE_DOUBLE
9192
hdf5_type_id(::Type{Reference}) = H5T.STD_REF_OBJ
9293

9394
hdf5_type_id(::Type{S}) where {S<:AbstractString} = H5T.C_S1
9495

95-
const BitsType = Union{Bool,Int8,UInt8,Int16,UInt16,Int32,UInt32,Int64,UInt64,Float32,Float64}
96+
const BitsType = Union{Bool,Int8,UInt8,Int16,UInt16,Int32,UInt32,Int64,UInt64,Float16,Float32,Float64}
9697
const ScalarType = Union{BitsType,Reference}
9798

9899
# It's not safe to use particular id codes because these can change, so we use characteristics of the type.
@@ -112,7 +113,8 @@ function _hdf5_type_map(class_id, is_signed, native_size)
112113
throw(KeyError(class_id, is_signed, native_size))
113114
end
114115
else
115-
return native_size === Csize_t(4) ? Float32 :
116+
return native_size === Csize_t(2) ? Float16 :
117+
native_size === Csize_t(4) ? Float32 :
116118
native_size === Csize_t(8) ? Float64 :
117119
throw(KeyError(class_id, is_signed, native_size))
118120
end
@@ -1934,6 +1936,14 @@ function __init__()
19341936
__init_globals__()
19351937
register_blosc()
19361938

1939+
# Generate the Float16 datatype:
1940+
float16 = h5t_copy(H5T.NATIVE_FLOAT)
1941+
h5t_set_fields(float16, 15, 10, 5, 0, 10)
1942+
h5t_set_size(float16, 2)
1943+
h5t_set_ebias(float16, 15)
1944+
h5t_lock(float16)
1945+
H5T.NATIVE_FLOAT16 = float16
1946+
19371947
# Turn off automatic error printing
19381948
# h5e_set_auto(H5E.DEFAULT, C_NULL, C_NULL)
19391949

src/api_types.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ end
341341
NATIVE_UINT64::hid_t
342342
NATIVE_FLOAT::hid_t
343343
NATIVE_DOUBLE::hid_t
344+
NATIVE_FLOAT16::hid_t
344345
end
345346

346347
# Filter constants

0 commit comments

Comments
 (0)