39 {
40 for (uint32_t n = 0; n < ctx.
size(); ++n)
41 {
43
44
45 auto fn = [
this](
const TensorContext &ctx, uint32_t n,
const Reader<float> &t) {
46 const auto name = ctx.
name(n);
47 const auto shape = ctx.
shape(n);
48
49 const auto rank = shape.
rank();
50
52
53 for (uint32_t axis = 0; axis < rank; ++axis)
54 {
55 dims[axis] = shape.dim(axis);
56 }
57
58 H5::DataSpace dataspace(rank, dims);
59
60 auto dataset =
61 _value_grp.createDataSet(
value_filename(n), H5::PredType::IEEE_F32BE, dataspace);
62
64
68
69 LexicalLayout layout{};
70
71 for (IndexEnumerator e{shape}; e.valid(); e.advance())
72 {
73 auto i = e.current();
74 data[layout.offset(shape, i)] = t.at(i);
75 }
76
77 dataset.write(data, H5::PredType::NATIVE_FLOAT);
78
80
81
82 {
83 H5::DataSpace name_dataspace(H5S_SCALAR);
84 H5::StrType name_datatype(H5::PredType::C_S1, name.size());
85
86 auto name_attr =
87 _name_grp.createAttribute(
value_filename(n), name_datatype, name_dataspace);
88
89 name_attr.write(name_datatype, name);
90 }
91 };
92
94 }
95 }
uint32_t rank(void) const
std::vector< int > dims(const std::string &src)
uint64_t num_elements(const Shape &)
std::string value_filename(uint32_t n)
Return the name of n-th tensor dataset.
virtual nncc::core::ADT::tensor::Shape shape(uint32_t n) const =0
virtual std::string name(uint32_t n) const =0
virtual void getConstFloatTensor(uint32_t n, const TypedReader< float > &cb) const
virtual uint32_t size(void) const =0