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

◆ from_variant()

std::optional< TensorData > MayaFlux::Kakshya::TensorData::from_variant ( const DataVariant & variant,
std::vector< uint64_t > shape = {},
std::string name = {} )
staticnodiscard

Tensor holding a copy of a DataVariant.

Parameters
variantSource data. glm vectors become [N, components] float tensors and glm::mat4 becomes [N, 4, 4].
shapeDimension sizes; empty keeps the shape implied above.
nameOptional tensor name.
Returns
Tensor, or std::nullopt when the shape does not match the data.

Definition at line 109 of file Tensor.cpp.

111{
112 return std::visit(
113 [&](const auto& values) -> std::optional<TensorData> {
114 using V = typename std::decay_t<decltype(values)>::value_type;
115 if constexpr (TensorElement<V>) {
116 return from_values<V>(std::span<const V>(values), std::move(shape), std::move(name));
117 } else if constexpr (std::same_as<V, glm::mat4>) {
118 return from_vector_shaped(values, 16, true, std::move(shape), std::move(name));
119 } else {
120 return from_vector_shaped(values, sizeof(V) / sizeof(float), false, std::move(shape), std::move(name));
121 }
122 },
123 variant);
124}
static std::optional< TensorData > from_values(std::span< const T > values, std::vector< uint64_t > shape={}, std::string name={})
Contiguous tensor holding a copy of typed values.
Definition Tensor.hpp:75

References from_values().

Here is the call graph for this function: