@@ -226,6 +226,16 @@ const H5T_NATIVE_DOUBLE = read_const(:H5T_NATIVE_DOUBLE_g)
226
226
# Library versions
227
227
const H5F_LIBVER_EARLIEST = 0
228
228
const H5F_LIBVER_LATEST = 1
229
+ # Constructed types (occurs at runtime)
230
+ function make_float16 ()
231
+ FLOAT16 = h5t_copy (H5T_NATIVE_FLOAT)
232
+ h5t_set_fields (FLOAT16, 15 , 10 , 5 , 0 , 10 )
233
+ h5t_set_size (FLOAT16, 2 )
234
+ h5t_set_ebias (FLOAT16, 15 )
235
+ h5t_lock (FLOAT16)
236
+ return FLOAT16
237
+ end
238
+ # const H5T_FLOAT16 = make_float16() (in `__init__()`)
229
239
230
240
# # Conversion between Julia types and HDF5 atomic types
231
241
hdf5_type_id (:: Type{Int8} ) = H5T_NATIVE_INT8
@@ -236,10 +246,11 @@ hdf5_type_id(::Type{Int32}) = H5T_NATIVE_INT32
236
246
hdf5_type_id (:: Type{UInt32} ) = H5T_NATIVE_UINT32
237
247
hdf5_type_id (:: Type{Int64} ) = H5T_NATIVE_INT64
238
248
hdf5_type_id (:: Type{UInt64} ) = H5T_NATIVE_UINT64
249
+ # hdf5_type_id(::Type{Float16}) = H5T_FLOAT16 (in `__init__()`)
239
250
hdf5_type_id (:: Type{Float32} ) = H5T_NATIVE_FLOAT
240
251
hdf5_type_id (:: Type{Float64} ) = H5T_NATIVE_DOUBLE
241
252
242
- @compat typealias HDF5BitsKind Union{Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Float32, Float64}
253
+ @compat typealias HDF5BitsKind Union{Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Float16, Float32, Float64}
243
254
@compat typealias BitsKindOrString Union{HDF5BitsKind, String}
244
255
245
256
# It's not safe to use particular id codes because these can change, so we use characteristics of the type.
@@ -252,6 +263,7 @@ const hdf5_type_map = @compat Dict(
252
263
(H5T_INTEGER, H5T_SGN_NONE, convert (Csize_t, 2 )) => UInt16,
253
264
(H5T_INTEGER, H5T_SGN_NONE, convert (Csize_t, 4 )) => UInt32,
254
265
(H5T_INTEGER, H5T_SGN_NONE, convert (Csize_t, 8 )) => UInt64,
266
+ (H5T_FLOAT, nothing , convert (Csize_t, 2 )) => Float16,
255
267
(H5T_FLOAT, nothing , convert (Csize_t, 4 )) => Float32,
256
268
(H5T_FLOAT, nothing , convert (Csize_t, 8 )) => Float64,
257
269
)
@@ -1801,17 +1813,30 @@ function hdf5_to_julia_eltype(objtype)
1801
1813
error (" character set " , cset, " not recognized" )
1802
1814
end
1803
1815
elseif class_id == H5T_INTEGER || class_id == H5T_FLOAT
1804
- native_type = h5t_get_native_type (objtype. id)
1805
- try
1806
- native_size = h5t_get_size (native_type)
1807
- if class_id == H5T_INTEGER
1808
- is_signed = h5t_get_sign (native_type)
1809
- else
1810
- is_signed = nothing
1816
+ # First look in the type last for a match
1817
+ # otherwise fall back to a native datatype
1818
+ # Allows for users to dynamically add types to the typemap
1819
+ t_size = h5t_get_size (objtype)
1820
+ if class_id == H5T_INTEGER
1821
+ is_signed = h5t_get_sign (objtype)
1822
+ else
1823
+ is_signed = nothing # probably should include the mantissa size, etc...
1824
+ end
1825
+ if haskey (hdf5_type_map, (class_id, is_signed, t_size))
1826
+ T = hdf5_type_map[(class_id, is_signed, t_size)]
1827
+ else
1828
+ native_type = h5t_get_native_type (objtype. id)
1829
+ try
1830
+ native_size = h5t_get_size (native_type)
1831
+ if class_id == H5T_INTEGER
1832
+ is_signed = h5t_get_sign (native_type)
1833
+ else
1834
+ is_signed = nothing
1835
+ end
1836
+ T = hdf5_type_map[(class_id, is_signed, native_size)]
1837
+ finally
1838
+ h5t_close (native_type)
1811
1839
end
1812
- T = hdf5_type_map[(class_id, is_signed, native_size)]
1813
- finally
1814
- h5t_close (native_type)
1815
1840
end
1816
1841
elseif class_id == H5T_ENUM
1817
1842
super_type = h5t_get_super (objtype. id)
@@ -1994,7 +2019,10 @@ for (jlname, h5name, outtype, argtypes, argsyms, msg) in
1994
2019
(:h5s_select_hyperslab , :H5Sselect_hyperslab , Herr, (Hid, Cint, Ptr{Hsize}, Ptr{Hsize}, Ptr{Hsize}, Ptr{Hsize}), (:dspace_id , :seloper , :start , :stride , :count , :block ), " Error selecting hyperslab" ),
1995
2020
(:h5t_commit , :H5Tcommit2 , Herr, (Hid, Ptr{UInt8}, Hid, Hid, Hid, Hid), (:loc_id , :name , :dtype_id , :lcpl_id , :tcpl_id , :tapl_id ), " Error committing type" ),
1996
2021
(:h5t_close , :H5Tclose , Herr, (Hid,), (:dtype_id ,), " Error closing datatype" ),
2022
+ (:h5t_lock , :H5Tlock , Herr, (Hid,), (:dtype_id ,), " Error locking datatype" ),
1997
2023
(:h5t_set_cset , :H5Tset_cset , Herr, (Hid, Cint), (:dtype_id , :cset ), " Error setting character set in datatype" ),
2024
+ (:h5t_set_ebias , :H5Tset_ebias , Herr, (Hid, Csize_t), (:dtype_id , :ebias ), " Error setting exponential bias of floating-point type" ),
2025
+ (:h5t_set_fields , :H5Tset_fields , Herr, (Hid, Csize_t, Csize_t, Csize_t, Csize_t, Csize_t), (:dtype_id , :spos , :epos , :esize , :mpos , :msize ), " Error setting floating-point type fields" ),
1998
2026
(:h5t_set_size , :H5Tset_size , Herr, (Hid, Csize_t), (:dtype_id , :sz ), " Error setting size of datatype" ),
1999
2027
)
2000
2028
@@ -2080,6 +2108,7 @@ for (jlname, h5name, outtype, argtypes, argsyms, ex_error) in
2080
2108
(:h5t_get_array_ndims , :H5Tget_array_ndims , Cint, (Hid,), (:dtype_id ,), :(error (" Error getting ndims of array" ))),
2081
2109
(:h5t_get_class , :H5Tget_class , Cint, (Hid,), (:dtype_id ,), :(error (" Error getting class" ))),
2082
2110
(:h5t_get_cset , :H5Tget_cset , Cint, (Hid,), (:dtype_id ,), :(error (" Error getting character set encoding" ))),
2111
+ (:h5t_get_ebias , :H5Tget_ebias , Csize_t, (Hid,), (:dtype_id ,), :(error (" Error getting exponential bias" ))),
2083
2112
(:h5t_get_member_class , :H5Tget_member_class , Cint, (Hid, Cuint), (:dtype_id , :index ), :(error (" Error getting class of compound datatype member #" , index))),
2084
2113
(:h5t_get_member_index , :H5Tget_member_index , Cint, (Hid, Ptr{UInt8}), (:dtype_id , :membername ), :(error (" Error getting index of compound datatype member \" " , membername, " \" " ))),
2085
2114
(:h5t_get_member_offset , :H5Tget_member_offset , Csize_t, (Hid, Cuint), (:dtype_id , :index ), :(error (" Error getting offset of compound datatype member #" , index))),
@@ -2170,6 +2199,21 @@ function h5s_get_simple_extent_dims(space_id::Hid)
2170
2199
h5s_get_simple_extent_dims (space_id, dims, maxdims)
2171
2200
return tuple (reverse! (dims)... ), tuple (reverse! (maxdims)... )
2172
2201
end
2202
+ function h5t_get_fields (type_id:: Hid )
2203
+ spos = Ref {Csize_t} ()
2204
+ epos = Ref {Csize_t} ()
2205
+ esize = Ref {Csize_t} ()
2206
+ mpos = Ref {Csize_t} ()
2207
+ msize = Ref {Csize_t} ()
2208
+ herr = ccall ((:H5Tget_fields , libhdf5),
2209
+ Herr,
2210
+ (Hid, Ptr{Csize_t}, Ptr{Csize_t}, Ptr{Csize_t}, Ptr{Csize_t}, Ptr{Csize_t}),
2211
+ type_id, spos, epos, esize, mpos, msize)
2212
+ if herr < 0
2213
+ error (" Error getting fields of floating-point datatype" )
2214
+ end
2215
+ return (spos[], epos[], esize[], mpos[], msize[])
2216
+ end
2173
2217
function h5t_get_member_name (type_id:: Hid , index:: Integer )
2174
2218
pn = ccall ((:H5Tget_member_name , libhdf5),
2175
2219
Ptr{UInt8},
@@ -2403,6 +2447,10 @@ function __init__()
2403
2447
UTF8_ATTRIBUTE_PROPERTIES[] = p_create (H5P_ATTRIBUTE_CREATE)
2404
2448
h5p_set_char_encoding (UTF8_ATTRIBUTE_PROPERTIES[]. id, cset (Compat. UTF8String))
2405
2449
2450
+ # Set up Float16 (must occur at runtime)
2451
+ eval (:(const H5T_FLOAT16 = make_float16 ()))
2452
+ eval (:(hdf5_type_id (:: Type{Float16} ) = H5T_FLOAT16))
2453
+
2406
2454
rehash! (hdf5_type_map, length (hdf5_type_map. keys))
2407
2455
rehash! (hdf5_prop_get_set, length (hdf5_prop_get_set. keys))
2408
2456
0 commit comments