Template Class Array

Class Documentation

template<class T>
class brille::Array

A multidimensional shared data array with operator overloads.

The Array<T>` object holds a multidimensional shared data object plus information necessary to index into that array with an offset, different shape, and/or different stride than the underlying data contains.

The Array<T> object provides overloads for basic operations, a number of utility methods, and methods to create offset and/or reduced-range mutable or immutable views into the shared array.

Public Types

using ref_t = std::shared_ptr<void>
using shape_t = brille::shape_t
using bItr = BroadcastIt<ind_t>
using sItr = SubIt<ind_t>
using aItr = ArrayIt<T>

Public Functions

T *data()

The stride of our multidimensional view.

T *data(const ind_t &idx)
T *data(const shape_t &idx)
const T *data() const
const T *data(const ind_t &idx) const
const T *data(const shape_t &idx) const
ind_t raw_size() const
ind_t raw_shift() const
bool own() const
ref_t ref() const
bool ismutable(void) const
bool isconst(void) const
ind_t ndim(void) const
ind_t numel(void) const
ind_t size(const ind_t dim) const
shape_t shape(void) const
shape_t stride(void) const
shape_t cstride() const
sItr subItr() const
sItr subItr(const shape_t &fix) const
aItr valItr() const
bItr broadcastItr(const shape_t &other) const
template<class R>
bItr broadcastItr(const Array<R> &other) const
bool is_column_ordered() const
bool is_row_ordered() const
bool is_contiguous() const
Array()
Array(T *data, const ind_t num, const bool own, const bool mut = true)
Array(T *data, const ind_t num, const bool own, const shape_t &shape, const shape_t &stride, const bool mut = true)
template<class P>
Array(T *data, const ind_t num, const bool own, std::shared_ptr<P> ref, const shape_t &shape, const shape_t &stride, const bool mut = true)
template<class P>
Array(T *data, const ind_t num, const ind_t shift, const bool own, const std::shared_ptr<P> &ref, const shape_t &shape, const shape_t &stride, const bool mut = true)
Array(const ind_t s0, const ind_t s1)
Array(const ind_t s0, const ind_t s1, const T init)
Array(const shape_t &shape)
Array(const shape_t &shape, const T init)
Array(const shape_t &shape, const shape_t &stride)
Array(const shape_t &shape, const shape_t &stride, const T init)
Array(const Array2<T> &twod, const shape_t &shape)
Array(const Array<T> &o)
~Array()
Array<T> &operator=(const Array<T> &other)
template<class R>
Array(const Array<R> &other)
template<class R>
Array<T> &operator=(const Array<R> &other)
bool make_mutable()
bool make_immutable()
Array<T> decouple() const
T &operator[](ind_t lin)
const T &operator[](ind_t lin) const
T &operator[](shape_t &sub)
const T &operator[](shape_t &sub) const
Array<T> view() const
Array<T> view(ind_t i) const

View a single sub-array at index i or an offset-smaller array if single=false;.

Array<T> view(ind_t i, ind_t j) const

View the sub-arrays from i to j-1

Array<T> view(const shape_t&) const
Array<T> extract(ind_t i) const
template<class I>
std::enable_if_t<std::is_integral_v<I>, Array<T>> extract(const Array<I> &i) const
template<class I>
std::enable_if_t<std::is_integral_v<I>, Array<T>> extract(const std::vector<I> &i) const
template<class I, size_t Nel>
std::enable_if_t<std::is_integral_v<I>, Array<T>> extract(const std::array<I, Nel> &i) const
template<class I, size_t Nel>
std::enable_if_t<std::is_integral_v<I>, Array<T>> extract(const std::vector<std::array<I, Nel>> &i) const
Array<T> extract(const Array<bool> &i) const
Array<T> extract(const std::vector<bool> &i) const
bool set(const ind_t i, const Array<T> &in)
template<class R>
bool set(const ind_t i, const Array<R> &in)
bool set(const ind_t i, const std::vector<T> &in)
template<size_t Nel>
bool set(const ind_t i, const std::array<T, Nel> &in)
T set(const shape_t &sub, T in)
Array<T> &append(const ind_t, const Array<T>&)
std::string to_string() const
std::string to_string(const ind_t) const
Array<T> &reshape(const shape_t &ns)
Array<T> &resize(const shape_t&, T init = T(0))

Modify the number of arrays.

Allocate a new T* and copy the overlapping region. The new shape must* have the same number of dimensions as the old shape.

Resizing an array will decouple it from any other arrays sharing their underlying data. Such an operation should not be taken lightly.

Parameters
  • ns: the new shape

  • init: an optional initialization value for any non-overlapping region

template<class I>
Array<T> &resize(const I, T init = T(0))
bool all(ind_t n = 0) const
bool any(ind_t n = 0) const
ind_t count(ind_t n = 0) const
ind_t first(ind_t n = 0) const
ind_t last(ind_t n = 0) const
bool all(T val, ind_t n = 0) const
bool any(T val, ind_t n = 0) const
ind_t count(T val, ind_t n = 0) const
ind_t first(T val, ind_t n = 0) const
ind_t last(T val, ind_t n = 0) const
Array<int> round() const
Array<int> floor() const
Array<int> ceil() const
Array<T> sum(ind_t dim = 0) const
Array<T> prod(ind_t dim = 0) const
Array<T> min(ind_t dim = 0) const
Array<T> max(ind_t dim = 0) const
T sum() const
T prod() const
template<class R, size_t Nel>
bool match(ind_t i, ind_t j, const std::array<R, Nel> &rot, int order = 1) const
bool match(ind_t i, ind_t j, ops op = ops::plus, T val = T{0}) const
bool all(cmp expr, T val) const
bool any(cmp expr, T val) const
ind_t first(cmp expr, T val) const
ind_t last(cmp expr, T val) const
ind_t count(cmp expr, T val) const
Array<bool> is(cmp expr, T val) const
std::vector<ind_t> find(cmp expr, T val) const
template<class R>
Array<bool> is(cmp expr, const Array<R> &that) const
template<class R>
std::vector<bool> is(cmp expr, const std::vector<R> &val) const
template<class R>
bool is(const Array<R> &that) const
std::vector<bool> is_unique() const
std::vector<ind_t> unique_idx() const
Array<T> unique() const
Array<T> operator-() const
Array<T> &operator+=(const T&)
Array<T> &operator-=(const T&)
Array<T> &operator*=(const T&)
Array<T> &operator/=(const T&)
template<class R>
Array<T> &operator+=(const Array<R>&)
template<class R>
Array<T> &operator-=(const Array<R>&)
template<class R>
Array<T> &operator*=(const Array<R>&)
template<class R>
Array<T> &operator/=(const Array<R>&)
T dot(ind_t i, ind_t j) const
T norm(ind_t i) const
template<typename I, typename = std::enable_if_t<std::is_integral<I>::value>>
void permute(std::vector<I> &p)
bool swap(ind_t a, ind_t b)
bool swap(ind_t i, ind_t a, ind_t b)
std::vector<T> to_std() const
T *ptr()
T *ptr(const ind_t i0)
template<class ...Subs, class = std::enable_if_t<brille::utils::are_same<ind_t, Subs...>::value, void>>
T *ptr(const ind_t i0, Subs... subscripts)
T *ptr(const shape_t &partial_subscript)
const T *ptr() const
const T *ptr(const ind_t i0) const
template<class ...Subs, class = std::enable_if_t<brille::utils::are_same<ind_t, Subs...>::value, void>>
const T *ptr(const ind_t i0, Subs... subscripts) const
const T *ptr(const shape_t &partial_subscript) const
T &val(const ind_t i0)
template<class ...Subs, class = std::enable_if_t<brille::utils::are_same<ind_t, Subs...>::value, void>>
T &val(const ind_t i0, Subs... subscripts)
T &val(const shape_t &partial_subscript)
template<typename I>
T &val(std::initializer_list<I> l)
const T &val(const ind_t i0) const
template<class ...Subs, class = std::enable_if_t<brille::utils::are_same<ind_t, Subs...>::value, void>>
const T &val(const ind_t i0, Subs... subscripts) const
const T &val(const shape_t &partial_subscript) const
template<typename I>
const T &val(std::initializer_list<I> l) const
Array<T> contiguous_copy() const
Array<T> contiguous_row_ordered_copy() const
Array<T> squeeze() const
Array<T> squeeze(const ind_t dim) const
Array<T> slice(const ind_t i0) const
bool shares_with(const Array<T> &other) const

Public Static Functions

Array<T> from_std(const std::vector<T> &data)
template<class R, size_t Nel>
Array<T> from_std(const std::vector<std::array<R, Nel>> &data)

Protected Functions

ind_t l2l_d(const ind_t l) const
ind_t s2l_d(const shape_t &s) const

Protected Attributes

T *_data
ind_t _num

A (possilby shared) raw pointer.

ind_t _shift

The number of elements stored under the raw pointer.

bool _own

A linear shift to where our subscript indexing begins (_data+shift)[subscript].

ref_t _ref

Whether we need to worry about memory management of the pointer.

bool _mutable

A shared_ptr for reference counting an owned raw pointer.

shape_t _shape

Whether we are allowed to modify the memory under the pointer.

shape_t _stride

The multidimensional shape of this view, prod(_shape) ≤ _num.