NDArray is a class that can be used in both host and device code. NDArray is automatically divided into multiple NDArrayViews for each task.
More...
#include "mu/ndarray/ndarray.hpp"
|
| static constexpr std::int64_t | MAX_DIMS = 10 |
| |
template<typename T>
class mu::NDArray< T >
NDArray is a class that can be used in both host and device code. NDArray is automatically divided into multiple NDArrayViews for each task.
Definition at line 22 of file ndarray.hpp.
◆ ShapeArray
◆ StridesArray
◆ NDArray() [1/5]
◆ NDArray() [2/5]
Definition at line 30 of file ndarray.hpp.
31 : data_(
const_cast<void*
>(
reinterpret_cast<const void*
>(
data))),
32 dims_(std::min<std::int64_t>(
static_cast<std::int64_t
>(
shape.size()),
MAX_DIMS)),
35 std::fill(shape_.begin(), shape_.end(), 0);
36 std::fill(strides_.begin(), strides_.end(), 0);
39 std::copy(
shape.begin(), last, shape_.begin());
40 calculateSizeAndStrides();
const ShapeArray & shape() const
static constexpr std::int64_t MAX_DIMS
◆ NDArray() [3/5]
◆ NDArray() [4/5]
Definition at line 52 of file ndarray.hpp.
std::int64_t elemSize() const
◆ NDArray() [5/5]
Definition at line 60 of file ndarray.hpp.
65 std::fill(shape_.begin(), shape_.end(), 0);
66 std::fill(strides_.begin(), strides_.end(), 0);
67 std::copy(
shape.begin(),
shape.begin() + dims_, shape_.begin());
68 calculateSizeAndStrides();
std::int64_t dims() const
◆ ~NDArray()
◆ at() [1/2]
template<typename T >
template<typename... Idxs>
Definition at line 190 of file ndarray.hpp.
192 return const_cast<T&
>(
static_cast<const NDArray&
>(*this).at(idxs...));
◆ at() [2/2]
template<typename T >
template<typename... Idxs>
Definition at line 196 of file ndarray.hpp.
198 std::array<std::int64_t, MAX_DIMS> indices = {idxs...};
199 if (
sizeof...(Idxs) !=
static_cast<std::size_t
>(dims_))
202 return *
reinterpret_cast<const T*
>(data_);
204 for (std::size_t i = 0; i < indices.size(); ++i)
206 if (indices[i] < 0 || indices[i] >= shape_[i])
209 return *
reinterpret_cast<const T*
>(data_);
T & operator()(Idxs... idxs)
◆ data() [1/2]
Definition at line 73 of file ndarray.hpp.
75 return reinterpret_cast<T*
>(data_);
◆ data() [2/2]
Definition at line 77 of file ndarray.hpp.
79 return reinterpret_cast<const T*
>(data_);
◆ dims()
◆ elemSize()
◆ numElements()
◆ operator const T &()
Definition at line 162 of file ndarray.hpp.
167 return *
reinterpret_cast<const T*
>(data_);
169 return *
reinterpret_cast<const T*
>(data_);
◆ operator typename std::enable_if_t< std::is_same_v< U, std::remove_const_t< T >>, T & >()
template<typename T >
template<typename U = T>
| mu::NDArray< T >::operator typename std::enable_if_t< std::is_same_v< U, std::remove_const_t< T >>, T & > |
( |
| ) |
|
|
inline |
Definition at line 152 of file ndarray.hpp.
157 return *
reinterpret_cast<T*
>(data_);
159 return *
reinterpret_cast<T*
>(data_);
◆ operator()() [1/2]
template<typename T >
template<typename... Idxs>
Definition at line 113 of file ndarray.hpp.
115 return const_cast<T&
>(
static_cast<const NDArray&
>(*this)(idxs...));
◆ operator()() [2/2]
template<typename T >
template<typename... Idxs>
| const T& mu::NDArray< T >::operator() |
( |
Idxs... |
idxs | ) |
const |
|
inline |
Definition at line 119 of file ndarray.hpp.
121 return reinterpret_cast<const T*
>(data_)[computeOffset({idxs...})];
◆ operator[]() [1/2]
Definition at line 126 of file ndarray.hpp.
128 auto const_result =
static_cast<const NDArray&
>(*this)[idx];
130 const_cast<void*
>(
static_cast<const void*
>(const_result.data())),
131 const_result.shape(),
132 const_result.elemSize(),
133 const_result.dims());
◆ operator[]() [2/2]
Definition at line 136 of file ndarray.hpp.
139 std::fill(new_shape.begin(), new_shape.end(), 0);
140 std::copy(shape_.begin() + 1, shape_.end(), new_shape.begin());
142 const T* subData =
reinterpret_cast<const T*
>(data_) + idx * strides_[0];
143 return NDArray<const T>(
144 const_cast<void*
>(
static_cast<const void*
>(subData)),
147 dims_ > 0 ? dims_ - 1 : 0);
std::array< std::int64_t, MAX_DIMS > ShapeArray
◆ scalar() [1/2]
Definition at line 173 of file ndarray.hpp.
175 return const_cast<T&
>(
static_cast<const NDArray&
>(*this).scalar());
◆ scalar() [2/2]
Definition at line 178 of file ndarray.hpp.
183 return *
reinterpret_cast<const T*
>(data_);
185 return *
reinterpret_cast<const T*
>(data_);
◆ setData()
◆ shape()
◆ size()
◆ strides()
◆ MAX_DIMS
The documentation for this class was generated from the following files: