NDArray

template<typename T, ssize_t Ndim = 2>
class NDArray : public aare::ArrayExpr<NDArray<T, 2>, 2>

Public Types

using value_type = T

Public Functions

inline NDArray()

Default constructor. Constructs an empty NDArray.

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 ~NDArray()

Destroy the NDArray object. Frees the allocated memory.

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, T&> operator()(Ix... index)
template<typename ...Ix>
inline std::enable_if_t<sizeof...(Ix) == Ndim, const T&> operator()(Ix... index) const
inline T &operator()(ssize_t i)
inline const T &operator()(ssize_t i) const
inline T &operator[](ssize_t i)
inline const T &operator[](ssize_t i) const
inline T *data()
inline const T *data() 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 Shape<Ndim> shape() const noexcept

Return the shape of the array.

inline ssize_t shape(ssize_t i) const noexcept

Return the size of dimension i.

inline std::array<ssize_t, Ndim> strides() const noexcept

Return the strides of the array.

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.

inline NDArray &operator=(NDArray &&other) noexcept

Move assignment operator.

inline NDArray &operator=(const NDArray &other)

Copy assignment operator.

inline NDArray &operator+=(const NDArray &other)

Add elementwise from another NDArray.

inline NDArray &operator-=(const NDArray &other)

Subtract elementwise with another NDArray.

inline NDArray &operator*=(const NDArray &other)

Multiply elementwise with another NDArray.

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)

Assign a scalar value to all elements in the NDArray.

inline NDArray &operator+=(const T &value)

Add a scalar value to all elements in the NDArray.

inline NDArray &operator-=(const T &value)

Subtract a scalar value to all elements in the NDArray.

inline NDArray &operator*=(const T &value)

Multiply all elements in the NDArray with a scalar value.

inline NDArray &operator/=(const T &value)

Divide 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?

inline bool operator==(const NDArray &other) const

Compare two NDArrays elementwise for equality.

inline bool operator!=(const NDArray &other) const

Compare two NDArrays elementwise for non-equality.

inline void sqrt()

Compute the square root of all elements in the NDArray.

inline NDArray &operator++()
inline NDView<T, Ndim> view() const

Create a view of the NDArray.

Returns:

NDView<T, Ndim>

Friends

friend class NDArray