MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ read_tensors()

std::optional< Kakshya::TensorSet > MayaFlux::IO::TensorReader::read_tensors ( const TensorReadOptions & options = {})
nodiscard

Read a selection of tensors together with the file's metadata.

Returns
The set, or std::nullopt if any requested tensor is missing or unreadable.

Definition at line 5 of file TensorReader.cpp.

6{
7 if (!is_open()) {
8 fail("no file is open");
9 return std::nullopt;
10 }
11
12 std::vector<std::string> names = options.names;
13 if (names.empty()) {
14 for (const auto& spec : describe())
15 names.push_back(spec.name);
16 }
17
18 Kakshya::TensorSet set;
19 set.metadata = tensor_metadata();
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.

References describe(), fail(), MayaFlux::IO::FileReader::is_open(), MayaFlux::Kakshya::TensorSet::metadata, MayaFlux::IO::TensorReadOptions::names, read(), tensor_metadata(), and MayaFlux::Kakshya::TensorSet::tensors.

Referenced by read().

Here is the call graph for this function:
Here is the caller graph for this function: