NDArray¶
-
template<typename T, ssize_t Ndim = 2>
class NDArray : public aare::ArrayExpr<NDArray<T, 2>, 2>¶ -
Public Functions
-
inline explicit NDArray(std::array<ssize_t, Ndim> shape)¶
Construct a new NDArray object with a given shape.
Note
The data is uninitialized.
- Parameters:
shape – shape of the new NDArray
-
inline NDArray(std::array<ssize_t, Ndim> shape, T value)¶
Construct a new NDArray object with a shape and value.
- Parameters:
shape – shape of the new array
value – value to initialize the array with
-
inline explicit NDArray(const NDView<T, Ndim> v)¶
Construct a new NDArray object from a NDView.
Note
The data is copied from the view to the NDArray.
- Parameters:
v – view of data to initialize the NDArray with
-
template<size_t Size>
inline NDArray(const std::array<T, Size> &arr)¶ Construct a new NDArray object from an std::array.
-
inline NDArray(NDArray &&other) noexcept¶
Move construct a new NDArray object. Cheap since it just reassigns the pointer and copy size/strides.
- Parameters:
other –
-
template<ssize_t M, typename = std::enable_if_t<(M == Ndim + 1)>>
inline NDArray(NDArray<T, M> &&other)¶ Move construct a new NDArray object from an array with Ndim + 1. Can be used to drop a dimension cheaply.
- Parameters:
other –
-
inline NDArray(const NDArray &other)¶
Copy construct a new NDArray object from another NDArray.
- Parameters:
other –
-
template<typename E>
inline NDArray(ArrayExpr<E, Ndim> &&expr)¶ Conversion from a ArrayExpr to an actual NDArray. Used when the expression is evaluated and data needed.
- Template Parameters:
E –
- Parameters:
expr –
-
inline auto *begin()¶
-
inline const auto *begin() const¶
-
inline auto *end()¶
-
inline const auto *end() const¶
-
template<typename ...Ix>
inline std::enable_if_t<sizeof...(Ix) == Ndim, const T&> operator()(Ix... index) const¶
-
inline std::byte *buffer()¶
-
inline ssize_t size() const¶
Return the total number of elements in the array as a signed integer.
-
inline size_t total_bytes() const¶
Return the total number of bytes in the array.
-
inline ssize_t shape(ssize_t i) const noexcept¶
Return the size of dimension i.
-
inline size_t bitdepth() const noexcept¶
Return the bitdepth of the array. Useful for checking that detector data can fit in the array type.
-
inline std::array<ssize_t, Ndim> byte_strides() const noexcept¶
Return the number of bytes to step in each dimension when traversing the array.
-
template<size_t Size>
inline NDArray<T, 1> &operator=(const std::array<T, Size> &other)¶ Copy to the NDArray from an std::array. If the size of the array is different we reallocate the data.
-
template<typename V>
inline NDArray &operator/=(const NDArray<V, Ndim> &other)¶ Divide elementwise by another NDArray. Templated to allow division with different types.
TODO! Why is this templated when the others are not?
-
inline NDArray &operator*=(const T &value)¶
Multiply all elements in the NDArray with a scalar value.
-
inline NDArray &operator&=(const T &mask)¶
Bitwise AND all elements in the NDArray with a scalar mask. Used for example to mask out gain bits for Jungfrau detectors.
-
inline NDArray operator+(const T &value)¶
Operator + with a scalar value. Returns a new NDArray.
TODO! Expression template version of this?
-
inline NDArray operator-(const T &value)¶
Operator - with a scalar value. Returns a new NDArray.
TODO! Expression template version of this?
-
inline NDArray operator*(const T &value)¶
Operator * with a scalar value. Returns a new NDArray.
TODO! Expression template version of this?
-
inline NDArray operator/(const T &value)¶
Operator / with a scalar value. Returns a new NDArray.
TODO! Expression template version of this?
Friends
- friend class NDArray
-
inline explicit NDArray(std::array<ssize_t, Ndim> shape)¶