MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
TensorConverter.cpp
Go to the documentation of this file.
1#include "TensorConverter.hpp"
2
4
5namespace MayaFlux::Yantra {
6
8{
9 if (!input.data)
10 return false;
11
12 const auto view = input.data->view();
13 if (!view)
14 return false;
15
16 const auto& cfg = config<TensorConversionConfig>();
17 return Kakshya::diagnose_conversion(view->spec(), cfg.target, cfg.quantization).empty();
18}
19
21{
22 if (!input.data) {
24 std::source_location::current(), "TensorConverter: the input holds no tensor container");
25 }
26
27 const auto view = input.data->view();
28 if (!view) {
30 std::source_location::current(), "TensorConverter: the tensor container holds no valid tensor");
31 }
32
33 const auto& cfg = config<TensorConversionConfig>();
34 auto converted = Kakshya::convert_tensor(*view, cfg.target, cfg.quantization);
35 if (!converted) {
37 std::source_location::current(), "TensorConverter: {}", converted.error());
38 }
39
40 output_type output(std::make_shared<Kakshya::TensorContainer>(std::move(*converted)));
41 output.metadata = input.metadata;
42 output.facets = input.facets;
43 return output;
44}
45
46}
bool validate_input(const input_type &input) const override
True when the input holds a valid tensor the configured conversion accepts.
output_type operation_function(const input_type &input) override
@ ComputeMatrix
Compute operations (Yantra - algorithms, matrices, DSP).
@ Yantra
DSP algorithms, computational units, matrix operations, Grammar.
std::string diagnose_conversion(const TensorSpec &source, TensorDType target, const std::optional< TensorQuantization > &quantization)
Empty when a tensor can be converted to a type, otherwise the reason it cannot.
std::expected< TensorData, std::string > convert_tensor(const TensorAccess &source, TensorDType target, const std::optional< TensorQuantization > &quantization)
Convert the elements of a tensor to another element type.
T data
The actual computation data.
Definition DataIO.hpp:64
Facets facets
Typed results that travel with the data, read by type.
Definition DataIO.hpp:68
std::unordered_map< std::string, std::any > metadata
Associated metadata.
Definition DataIO.hpp:67