Copy into a vector of T.
Scalar and complex T need a dense tensor of that dtype. glm vector and matrix T need a dense f32 tensor whose bytes divide into whole elements.
Definition at line 132 of file Tensor.hpp.
133 {
134 const auto view =
access();
135 if (!view)
136 return std::nullopt;
137 const auto raw = view->bytes();
138 if constexpr (TensorElement<T>) {
139 if (!
m_spec.dtype.is<T>())
140 return std::nullopt;
141 } else {
142 if (!
m_spec.dtype.is<
float>() || raw.size() %
sizeof(T) != 0)
143 return std::nullopt;
144 }
145 if (raw.empty())
146 return view->element_count() == 0 ? std::optional<std::vector<T>>(std::vector<T> {}) : std::nullopt;
147 std::vector<T> result(raw.size() / sizeof(T));
148 std::memcpy(result.data(), raw.data(), result.size() * sizeof(T));
149 return result;
150 }
std::optional< TensorAccess > access() const
Borrow the tensor, or std::nullopt when it holds nothing valid.
References access(), and m_spec.
Referenced by to_variant().