Closed tamasgal closed 1 year ago
OK, I found that datatype()
is the culprit, see below. I am able to create the dataset by passing an instance of Foo
instead of the type itself:
julia> d = create_dataset(f, "foo", foos[1])
(HDF5.Dataset: /foo (file: test.h5 xfer_mode: 0), HDF5.Datatype: H5T_COMPOUND {
H5T_STD_I32LE "x" : 0;
H5T_IEEE_F32LE "y" : 4;
})
julia> datatype(Int)
HDF5.Datatype: H5T_STD_I64LE
julia> datatype(Foo)
ERROR: Type Symbol does not have a definite size.
Stacktrace:
[1] sizeof(x::Type)
@ Base ./essentials.jl:559
[2] hdf5_type_id(#unused#::Type{Symbol}, isstruct::Val{true})
@ HDF5 ~/.julia/packages/HDF5/HtnQZ/src/typeconversions.jl:71
[3] hdf5_type_id(#unused#::Type{Symbol})
@ HDF5 ~/.julia/packages/HDF5/HtnQZ/src/typeconversions.jl:69
[4] hdf5_type_id(#unused#::Type{Core.TypeName}, isstruct::Val{true})
@ HDF5 ~/.julia/packages/HDF5/HtnQZ/src/typeconversions.jl:74
[5] hdf5_type_id(#unused#::Type{Core.TypeName})
@ HDF5 ~/.julia/packages/HDF5/HtnQZ/src/typeconversions.jl:69
[6] hdf5_type_id(#unused#::Type{DataType}, isstruct::Val{true})
@ HDF5 ~/.julia/packages/HDF5/HtnQZ/src/typeconversions.jl:74
[7] hdf5_type_id(#unused#::Type{DataType})
@ HDF5 ~/.julia/packages/HDF5/HtnQZ/src/typeconversions.jl:69
[8] datatype(#unused#::Type{Foo})
@ HDF5 ~/.julia/packages/HDF5/HtnQZ/src/typeconversions.jl:66
[9] top-level scope
@ REPL[38]:1
julia> datatype(foos[1]) # foos is an array of Foo instances
HDF5.Datatype: H5T_COMPOUND {
H5T_STD_I32LE "x" : 0;
H5T_IEEE_F32LE "y" : 4;
}
julia> HDF5.Datatype(HDF5.hdf5_type_id(Foo))
HDF5.Datatype: H5T_COMPOUND {
H5T_STD_I32LE "x" : 0;
H5T_IEEE_F32LE "y" : 4;
}
I am scratching my head right now. We have this line
and this errors:
julia> datatype(Foo)
ERROR: Type Symbol does not have a definite size.
but when calling the right hand side manuall, it works:
julia> HDF5.Datatype(HDF5.hdf5_type_id(Foo), true)
HDF5.Datatype: H5T_COMPOUND {
H5T_STD_I32LE "x" : 0;
H5T_IEEE_F32LE "y" : 4;
}
I am probably overlooking something simple π
I think we're missing a method definition.
julia> HDF5.datatype(::Type{T}) where T = HDF5.Datatype(HDF5.hdf5_type_id(T), isstructtype(T))
julia> datatype(Foo)
HDF5.Datatype: H5T_COMPOUND {
H5T_STD_I32LE "x" : 0;
H5T_IEEE_F32LE "y" : 4;
}
Yes you're right. I'll prepare a PR with tests.
I am happily using
write_dataset()
to dump compound structures using arrays of structs, but while I was writing an expandable cached write-out wrapper, I discovered that creating datasets is not working. Something is not propagated correctly because it complains thatType Symbol has not have a definite size
.Let me dump this issue (I'll also try to figure out what's wrong).
Probably related to https://github.com/JuliaIO/HDF5.jl/pull/1013 and see also the recent post on the Julia Discourse: https://discourse.julialang.org/t/hdf5-jl-variable-length-string/98808