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

◆ take() [1/2]

std::optional< TensorImport > MayaFlux::Kakshya::TensorImport::take ( DLManagedTensor * managed)
staticnodiscard

Take ownership of a legacy, unversioned DLPack tensor.

Definition at line 252 of file TensorDLPack.cpp.

253{
254 if (!managed)
255 return std::nullopt;
256
257 const std::function<void()> release = [managed] {
258 if (managed->deleter)
259 managed->deleter(managed);
260 };
261
262 TensorSpec spec;
263 if (const auto why = spec_from(managed->dl_tensor, spec); !why.empty())
264 return reject(release, why);
265
266 const bool empty = spec.element_count().value_or(0) == 0;
267 if (empty)
268 spec.byte_offset = 0;
269 const auto range = spec.byte_range();
270 if (!range)
271 return reject(release, spec.diagnose());
272
273 const auto* data = static_cast<const std::byte*>(managed->dl_tensor.data);
274 const size_t size = empty ? 0 : static_cast<size_t>(range->second);
275 if (!empty && !data)
276 return reject(release, "null data pointer for a non-empty tensor");
277
278 TensorImport imported(std::move(spec), data, size, false, release);
279 if (!imported.access()) {
280 imported.m_release = nullptr;
281 return reject(release, "tensor layout is not valid host memory");
282 }
283 return imported;
284}
const TensorSpec & spec() const noexcept
Layout described by the producer.
TensorImport(TensorImport &&other) noexcept
std::vector< double > range(std::span< const double > data, size_t n_windows, uint32_t hop_size, uint32_t window_size)
Value range (max - min) per window.
Definition Analysis.cpp:473

References access(), m_release, spec(), and TensorImport().

Here is the call graph for this function: