Elements as a typed span.
- Template Parameters
-
| T | Element type that equals the tensor dtype exactly. |
- Returns
- Span over the elements, or empty on a dtype mismatch, a strided layout or a misaligned address.
Definition at line 73 of file TensorAccess.hpp.
74 {
76 return {};
77 const auto raw =
bytes();
78 if (raw.empty() || reinterpret_cast<uintptr_t>(raw.data()) % alignof(T) != 0)
79 return {};
80 return {
reinterpret_cast<const T*
>(raw.data()), raw.size() /
sizeof(
T) };
81 }
std::span< const std::byte > bytes() const noexcept
Bytes of the elements when they are dense in C order.
References as(), bytes(), and m_spec.
Referenced by as().