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

◆ dense_bytes()

std::optional< std::span< const std::byte > > MayaFlux::IO::Detail::dense_bytes ( const Kakshya::TensorData & tensor,
std::optional< Kakshya::TensorData > & dense )
nodiscard

Elements of a tensor as dense C-order bytes.

Parameters
tensorSource tensor.
denseReceives a gathered copy only when the tensor is strided; the returned span then points into it, so keep it alive while the span is used.
Returns
The bytes, or std::nullopt when the tensor is invalid.

Definition at line 210 of file TensorCodec.cpp.

212{
213 const auto view = tensor.access();
214 if (!view)
215 return std::nullopt;
216
217 const auto raw = view->bytes();
218 if (!raw.empty() || view->element_count() == 0)
219 return raw;
220
221 dense = Kakshya::TensorData::copy_of(*view);
222 if (!dense)
223 return std::nullopt;
224 const auto gathered = dense->access();
225 if (!gathered)
226 return std::nullopt;
227 return gathered->bytes();
228}
static std::optional< TensorData > copy_of(const TensorAccess &view)
Dense C-ordered copy of any tensor view.
Definition Tensor.cpp:126
std::optional< TensorAccess > access() const
Borrow the tensor, or std::nullopt when it holds nothing valid.
Definition Tensor.cpp:150

References MayaFlux::Kakshya::TensorData::access(), and MayaFlux::Kakshya::TensorData::copy_of().

Referenced by encode_npy(), and MayaFlux::IO::SafetensorsWriter::write().

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