Elements of a tensor as dense C-order bytes.
- Parameters
-
| tensor | Source tensor. |
| dense | Receives 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
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.
std::optional< TensorAccess > access() const
Borrow the tensor, or std::nullopt when it holds nothing valid.
References MayaFlux::Kakshya::TensorData::access(), and MayaFlux::Kakshya::TensorData::copy_of().
Referenced by encode_npy(), and MayaFlux::IO::SafetensorsWriter::write().