Read a selection of tensors together with the file's metadata.
6{
8 fail(
"no file is open");
9 return std::nullopt;
10 }
11
12 std::vector<std::string> names = options.names;
13 if (names.empty()) {
15 names.push_back(spec.name);
16 }
17
18 Kakshya::TensorSet set;
20 set.tensors.reserve(names.size());
21 for (const auto& name : names) {
22 auto tensor =
read(name);
23 if (!tensor)
24 return std::nullopt;
25 set.tensors.push_back(std::move(*tensor));
26 }
27 return set;
28}
virtual bool is_open() const =0
Check if a file is currently open.
virtual std::map< std::string, std::string > tensor_metadata() const
Free-form string metadata stored in the file, empty if the format has none.
virtual std::vector< Kakshya::TensorSpec > describe() const =0
Specs of every tensor in the open file, in file order, without reading data.
bool fail(std::string reason)
Record a failure reason and return false.
virtual std::optional< Kakshya::TensorData > read(std::string_view name)=0
Read one tensor by name.