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

◆ copy_of()

std::optional< TensorData > MayaFlux::Kakshya::TensorData::copy_of ( const TensorAccess & view)
staticnodiscard

Dense C-ordered copy of any tensor view.

Gathers through strides, so transposed, Fortran-ordered, offset and broadcast views all become ordinary contiguous tensors.

Definition at line 126 of file Tensor.cpp.

127{
128 TensorSpec spec = view.spec();
129 spec.strides.clear();
130 spec.byte_offset = 0;
131 spec.device = {};
132
133 auto result = allocate(spec);
134 if (!result)
135 return std::nullopt;
136 if (result->m_size == 0)
137 return result;
138
139 if (view.spec().dtype.is_sub_byte() || view.spec().is_contiguous()) {
140 std::memcpy(result->m_data.get(), view.element_data(), result->m_size);
141 return result;
142 }
143
144 std::byte* cursor = result->m_data.get();
145 gather(view.element_data(), cursor, view.spec().dtype.element_bytes(),
146 view.spec().shape, view.spec().resolved_strides(), 0);
147 return result;
148}
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

References allocate(), MayaFlux::Kakshya::TensorSpec::dtype, MayaFlux::Kakshya::TensorDType::element_bytes(), MayaFlux::Kakshya::TensorAccess::element_data(), MayaFlux::Kakshya::TensorSpec::is_contiguous(), MayaFlux::Kakshya::TensorDType::is_sub_byte(), MayaFlux::Kakshya::TensorSpec::resolved_strides(), MayaFlux::Kakshya::TensorSpec::shape, MayaFlux::Kakshya::TensorAccess::spec(), and spec().

Referenced by MayaFlux::Kakshya::TensorInsertion::assign(), MayaFlux::Kakshya::TensorInsertion::assign_window(), MayaFlux::Kakshya::convert_tensor(), MayaFlux::Kakshya::TensorImport::copy(), MayaFlux::IO::Detail::dense_bytes(), MayaFlux::Kakshya::TensorContainer::get_region_data(), and MayaFlux::Kakshya::TensorInsertion::resize().

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