Template Class NDArray

Class Documentation

template<typename T = float>
class NDArray

An array container with N dimensions.

Template Parameters
  • T – Type of values stored by the container.

  • Allocator – Allocator class. std::allocator<T> for CPU NDArrays and CudaManagedAllocator<T> for GPU NDArrays.

Public Functions

inline NDArray(const std::initializer_list<unsigned int> &dimensions)

Constructs an uninitialized array with the given dimensions.

Parameters

dimensionsInitializer list containing the dimensions of the array.

inline NDArray(const std::initializer_list<unsigned int> &dimensions, Initializer &fct)

Constructs an array with the given dimensions and initializes it with the given initializer

Parameters
  • dimensionsInitializer list containing the dimensions of the array.

  • fctInitializer that initializes the values of the array.

inline NDArray(const std::initializer_list<unsigned int> &dimensions, Initializer &&fct)

Constructs an array with the given dimensions and initializes it with the given initializer

Parameters
  • dimensionsInitializer list containing the dimensions of the array.

  • fctInitializer that initializes the values of the array.

inline NDArray(const std::initializer_list<unsigned int> &dimensions, std::shared_ptr<Initializer> &fct)

Constructs an array with the given dimensions and initializes it with the given initializer

Parameters
  • dimensionsInitializer list containing the dimensions of the array.

  • fctInitializer that initializes the values of the array.

inline unsigned int get_n_dims() const

Gets the number of dimensions of the array.

Returns

The number of dimensions of the array.

inline std::vector<unsigned int> get_dims() const

Gets the dimensions of the array.

Returns

A vector containing the size of each axis in the array.

inline std::size_t size() const

Gets the total number of elements in the array.

Returns

The total number of elements in the array.

inline EvSpikeSim::vector<T> &get_values()

Gets the vector containing the values of the array.

Returns

The vector containing the values of the array.

template<class IteratorType>
inline void set_values(const IteratorType &begin, const IteratorType &end)

Set new values using the given iterators. The iterators should contain the right number of elements.

Template Parameters

IteratorType – Type of iterators.

Parameters
  • begin – Iterator on the first new element.

  • end – Iterator on the end of the new elements.

template<class ContainerType>
inline void set_values(const ContainerType &other)

Set new values using another container. Values are copied. The other container should contain the right number of elements.

Template Parameters

ContainerType – Type of the other container.

Parameters

other – The other container used to set new values.

template<typename U, typename ...Args>
inline T &get(U first_idx, Args... indices)

Gets the value at the specified indices. Usage: arr.get(3, 2, 4) for a 3D array.

Template Parameters
  • U – Type of the first index.

  • Args – Types of the remaining indices.

Parameters
  • first_idx – The first index.

  • indices – The remaining indices.

Returns

A reference on the value stored at the given indices.

template<typename U, typename ...Args>
inline const T &get(U first_idx, Args... indices) const

Gets the constant value at the specified indices. Usage: arr.get(3, 2, 4) for a 3D array.

Template Parameters
  • U – Type of the first index.

  • Args – Types of the remaining indices.

Parameters
  • first_idx – The first index.

  • indices – The remaining indices.

Returns

A const reference on the value stored at the given indices.

template<typename U, typename ...Args>
inline void set(T value, U first_idx, Args... indices)

Set a new value at the specified index. Usage: arr.get(-4, 3, 2, 4) sets the new value -4 in a 3D array.

Template Parameters
  • U – Type of the first index.

  • Args – Types of the remaining indices.

Parameters
  • value – The new value to set.

  • first_idx – The first index.

  • indices – The remaining indices.

inline T *get_c_ptr()

Gets the raw pointer on the data.

Returns

The raw pointer on the data.

template<class ContainerType>
inline NDArray<T> &operator=(const ContainerType &other)

Set new values using another container. Values are copied. The other container should contain the right number of elements.

Template Parameters

ContainerType – Type of the other container.

Parameters

other – The other container used to set new values.

Returns

Reference on the self NDArray.