NDArray is a class that can be used in both host and device code. NDArray is automatically divided into multiple NDArray slices for each task.
More...
|
| static constexpr std::int64_t | MAX_DIMS = 10 |
| |
template<typename T>
class pxl::NDArray< T >
NDArray is a class that can be used in both host and device code. NDArray is automatically divided into multiple NDArray slices for each task.
Definition at line 24 of file ndarray.hpp.
◆ ShapeArray
◆ StridesArray
◆ NDArray() [1/4]
◆ NDArray() [2/4]
template<typename T >
template<typename U >
Definition at line 33 of file ndarray.hpp.
34 : data_(
const_cast<void*
>(
static_cast<const void*
>(
data))),
35 dims_(
static_cast<std::int64_t
>(
shape.size())),
38 std::fill(shape_.begin(), shape_.end(), 0);
39 std::fill(strides_.begin(), strides_.end(), 0);
40 for (
size_t i = 0; i <
shape.size(); ++i)
42 shape_[i] =
static_cast<std::int64_t
>(*(
shape.begin() + i));
44 calculateSizeAndStrides();
const ShapeArray & shape() const
◆ NDArray() [3/4]
Definition at line 46 of file ndarray.hpp.
47 : data_(
const_cast<void*
>(
reinterpret_cast<const void*
>(
data))),
51 std::fill(shape_.begin(), shape_.end(), 0);
52 std::fill(strides_.begin(), strides_.end(), 0);
53 for (
size_t i = 0; i <
MAX_DIMS; ++i)
61 calculateSizeAndStrides();
static constexpr std::int64_t MAX_DIMS
◆ NDArray() [4/4]
Definition at line 64 of file ndarray.hpp.
69 std::fill(shape_.begin(), shape_.end(), 0);
70 std::fill(strides_.begin(), strides_.end(), 0);
71 for (
size_t i = 0; i <
MAX_DIMS; ++i)
79 calculateSizeAndStrides();
std::int64_t elemSize() const
◆ ~NDArray()
◆ at() [1/2]
template<typename T >
template<typename... Idxs>
Definition at line 214 of file ndarray.hpp.
216 return const_cast<T&
>(
static_cast<const NDArray&
>(*this).at(idxs...));
◆ at() [2/2]
template<typename T >
template<typename... Idxs>
Definition at line 220 of file ndarray.hpp.
222 std::vector<std::int64_t> indices = {idxs...};
223 if (indices.size() !=
static_cast<size_t>(dims_))
225 throw std::out_of_range(
"Number of indices does not match ndarray dimensions");
227 for (
size_t i = 0; i < indices.size(); ++i)
229 if (indices[i] < 0 || indices[i] >= shape_[i])
231 throw std::out_of_range(
"Index out of bounds");
T & operator()(Idxs... idxs)
◆ data() [1/2]
Definition at line 84 of file ndarray.hpp.
86 return reinterpret_cast<T*
>(data_);
◆ data() [2/2]
Definition at line 88 of file ndarray.hpp.
90 return reinterpret_cast<const T*
>(data_);
◆ dims()
◆ elemSize()
◆ numElements()
◆ operator const T &()
Definition at line 188 of file ndarray.hpp.
192 throw std::logic_error(
"Scalar conversion only available for 0-dimensional ndarrays");
194 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>
| pxl::NDArray< T >::operator typename std::enable_if_t< std::is_same_v< U, std::remove_const_t< T >>, T & > |
( |
| ) |
|
|
inline |
Definition at line 179 of file ndarray.hpp.
183 throw std::logic_error(
"Scalar conversion only available for 0-dimensional ndarrays");
185 return *
reinterpret_cast<T*
>(data_);
◆ operator()() [1/2]
template<typename T >
template<typename... Idxs>
Definition at line 124 of file ndarray.hpp.
126 return const_cast<T&
>(
static_cast<const NDArray&
>(*this)(idxs...));
◆ operator()() [2/2]
template<typename T >
template<typename... Idxs>
| const T& pxl::NDArray< T >::operator() |
( |
Idxs... |
idxs | ) |
const |
|
inline |
Definition at line 130 of file ndarray.hpp.
134 std::vector<std::int64_t> indices = {idxs...};
135 if (indices.size() !=
static_cast<size_t>(dims_))
137 throw std::out_of_range(
"Number of indices does not match ndarray dimensions");
139 for (
size_t i = 0; i < indices.size(); ++i)
141 if (indices[i] < 0 || indices[i] >= shape_[i])
143 throw std::out_of_range(
"Index out of bounds");
147 return reinterpret_cast<const T*
>(data_)[computeOffset({idxs...})];
◆ operator[]() [1/2]
Definition at line 151 of file ndarray.hpp.
153 auto const_result =
static_cast<const NDArray&
>(*this)[idx];
155 const_cast<T*
>(const_result.data()),
156 const_result.shape());
◆ operator[]() [2/2]
Definition at line 159 of file ndarray.hpp.
163 if (idx < 0 || idx >= shape_[0])
165 throw std::out_of_range(
"Index out of bounds for first dimension");
169 std::fill(new_shape.begin(), new_shape.end(), 0);
170 std::copy(shape_.begin() + 1, shape_.end(), new_shape.begin());
172 return NDArray<const T>(
173 reinterpret_cast<const T*
>(data_) + idx * strides_[0],
std::array< std::int64_t, MAX_DIMS > ShapeArray
◆ scalar() [1/2]
Definition at line 198 of file ndarray.hpp.
200 return const_cast<T&
>(
static_cast<const NDArray&
>(*this).scalar());
◆ scalar() [2/2]
Definition at line 203 of file ndarray.hpp.
207 throw std::logic_error(
"scalar() only available for 0-dimensional ndarrays");
209 return *
reinterpret_cast<const T*
>(data_);
◆ setData()
◆ shape()
◆ size()
◆ strides()
◆ MAX_DIMS
The documentation for this class was generated from the following files: