8 fail(
"no file is open");
12 std::vector<std::string> names = options.
names;
15 names.push_back(spec.name);
20 set.
tensors.reserve(names.size());
21 for (
const auto& name : names) {
22 auto tensor =
read(name);
25 set.
tensors.push_back(std::move(*tensor));
33 if (spec.name == name)
34 return std::move(spec);
46 std::error_code error;
47 const auto size = std::filesystem::file_size(
m_path, error);
54 m_last_error =
"Tensor data requires read() or read_tensors()";
60 m_last_error =
"Tensor data requires read() or read_tensors()";
66 m_last_error =
"Tensor data does not use a SignalSourceContainer";
72 return fail(
"Tensor data cannot load into a SignalSourceContainer");
virtual bool is_open() const =0
Check if a file is currently open.
std::type_index get_data_type() const override
Get the data type this reader produces.
std::vector< Kakshya::DataVariant > read_all() override
Read all data from the file into memory.
virtual std::map< std::string, std::string > tensor_metadata() const
Free-form string metadata stored in the file, empty if the format has none.
std::optional< FileMetadata > get_metadata() const override
Get metadata from the open file.
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.
bool load_into_container(std::shared_ptr< Kakshya::SignalSourceContainer >) override
Load file data into an existing container.
std::vector< Kakshya::DataVariant > read_region(const FileRegion &) override
Read a specific region of data.
std::type_index get_container_type() const override
Get the container type this reader creates.
std::optional< Kakshya::TensorSpec > find_spec(std::string_view name) const
Spec of one tensor by name, without reading data.
std::shared_ptr< Kakshya::SignalSourceContainer > create_container() override
Create and initialize a container from the file.
virtual std::string format_name() const =0
Format identifier such as safetensors or npy.
std::optional< Kakshya::TensorSet > read_tensors(const TensorReadOptions &options={})
Read a selection of tensors together with the file's metadata.
Generic region descriptor for any file type.
std::vector< std::string > names
Tensors to read, in this order.
Selection for TensorReader::read_tensors().
std::vector< TensorData > tensors
std::map< std::string, std::string > metadata
Named tensors that belong together, such as a model's weights or I/O.