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

◆ from_bytes()

std::optional< TensorData > MayaFlux::Kakshya::TensorData::from_bytes ( TensorSpec spec,
std::span< const std::byte > bytes )
staticnodiscard

Tensor holding a copy of bytes.

Parameters
specLayout of the bytes.
bytesExactly the storage the spec addresses.
Returns
Tensor, or std::nullopt for an inconsistent spec or a size mismatch.

Definition at line 93 of file Tensor.cpp.

94{
95 auto result = allocate(std::move(spec));
96 if (!result)
97 return std::nullopt;
98 if (result->m_size != bytes.size()) {
100 "TensorData::from_bytes: tensor '{}' needs {} bytes, received {}",
101 result->m_spec.name, result->m_size, bytes.size());
102 return std::nullopt;
103 }
104 if (!bytes.empty())
105 std::memcpy(result->m_data.get(), bytes.data(), bytes.size());
106 return result;
107}
#define MF_ERROR(comp, ctx,...)
const TensorSpec & spec() const noexcept
Layout of the stored bytes.
Definition Tensor.hpp:105
static std::optional< TensorData > allocate(TensorSpec spec)
Zero-filled tensor for a spec.
Definition Tensor.cpp:72
@ Runtime
General runtime operations (default fallback).
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.

References allocate(), MayaFlux::Journal::Kakshya, MF_ERROR, MayaFlux::Journal::Runtime, and spec().

Referenced by ~TensorData().

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