Template Class Array#

Inheritance Relationships#

Derived Type#

Class Documentation#

template<typename dtype>
class Array#

An Array class which acts in many ways like a numpy array.

This copy constructor and assignment operator act to wrap existing memory rather than copy the memory.

Subclassed by pele::MatrixAdapter< dtype >

Public Types

typedef dtype *iterator#

return iterators over data

typedef dtype const *const_iterator#

Public Functions

inline Array()#

create an array of size 0

inline Array(size_t size)#

construct an array with a given size

inline Array(size_t size, dtype const &val)#

construct an array with a given size, each element is a copy of val

inline Array(std::initializer_list<dtype> data)#

construct an array from an initializer list

inline Array(dtype *data, size_t size)#

wrap some data that is passed.

Do not take ownership of the data.

inline Array(dtype *data_begin, dtype *data_end)#

wrap the data between iterators.

This memory should never be deleted.

inline Array(std::vector<dtype> &x)#

wrap the data in a vector.

This memory should never be deleted.

inline void wrap(Array<dtype> x)#

wrap another array is implemented by shared_ptr parent class

Note, the input here is a const array, but this constructs a modifiable array. This is a loophole around the const declaration, but i’m not sure there is any way around it. The compiler complains if this is not here. e.g. for constructions like Array(x.copy())

This is commented because it just duplicates the default copy constructor

Array(Array<dtype> const & x) : _memory(x._memory) _data(x._data), _size(x._size) {} wrap another array

inline dtype *data()#

return pointer to data

inline dtype const *data() const#
inline size_t size() const#

return the size of the array

inline dtype &operator[](const size_t i)#

access an element in the array

inline dtype const &operator[](const size_t i) const#
inline iterator begin()#
inline iterator end()#
inline const_iterator begin() const#
inline const_iterator end() const#
inline bool operator==(Array<dtype> const rhs) const#

return true if the two arrays wrap the same data

inline bool operator!=(Array<dtype> const rhs) const#
inline Array<dtype> &assign(const Array<dtype> &rhs)#

Assignment function: copy the data into the existing array.

arrays must be of same size

inline Array<dtype> &assign(dtype const &d)#

assign each element of the array to be d

inline Array<dtype> copy() const#

return a copy of the array.

inline void free()#

wrap a new empty array.

inline bool empty() const#

Returns whether the array is empty (whether its size is 0).

inline long int reference_count() const#
inline Array<dtype> operator+(const Array<dtype> &rhs)#

Array addition(+) , subtraction (-).

inline Array<dtype> operator-(const Array<dtype> &rhs)#
inline Array<dtype> operator-()#
inline Array<dtype> &operator+=(const Array<dtype> &rhs)#

Compound Assignment Operators += -= *=.

inline Array<dtype> &operator+=(const dtype &rhs)#
inline Array<dtype> &operator-=(const Array<dtype> &rhs)#
inline Array<dtype> &operator-=(const dtype &rhs)#
inline Array<dtype> &operator*=(const Array<dtype> &rhs)#
inline Array<dtype> &operator*=(const dtype &rhs)#
inline Array<dtype> operator*(const dtype rhs)#
inline Array<dtype> &operator/=(const Array<dtype> &rhs)#
inline Array<dtype> &operator/=(const dtype &rhs)#
inline dtype sum() const#

returns the sum of all elements (reduces the array)

inline dtype prod() const#

returns the product of all elements (reduces the array)

References: http://www.cplusplus.com/reference/functional/multiplies/ http://en.cppreference.com/w/cpp/algorithm/accumulate http://rosettacode.org/wiki/Sum_and_product_of_an_array

inline std::vector<dtype> to_std_vector_copy() const#
inline Array<dtype> view(size_t ibegin, size_t iend) const#

return an array that wraps the data from index ibegin to index iend-1.

inline dtype get_max() const#

Get maximum and minimum elements of array.

inline dtype get_min() const#