A multidimensional shared data array with operator overloads.
The Array2<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 Array2<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.
Subclassed by brille::LDVec< T >, brille::LQVec< T >
Public Functions
-
T *
data()
The stride of our view.
-
T *
data(const ind_t &idx)
-
T *
data(const ind_t &i0, const ind_t &i1)
-
T *
data(const shape_t &idx)
-
const T *
data() const
-
const T *
data(const ind_t &idx) const
-
const T *
data(const ind_t &i0, const ind_t &i1) 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 Array2<R> &other) const
-
bool
is_column_ordered() const
-
bool
is_row_ordered() const
-
bool
is_contiguous() const
-
Array2()
-
Array2(T *data, const ind_t num, const bool own, const bool mut = true)
-
Array2(T *data, const ind_t num, const bool own, const shape_t &shape, const shape_t &stride, const bool mut = true)
-
template<class
P>
Array2(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>
Array2(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)
-
Array2(const ind_t s0, const ind_t s1)
-
Array2(const ind_t s0, const ind_t s1, const T init)
-
Array2(const shape_t &shape)
-
Array2(const shape_t &shape, const T init)
-
Array2(const shape_t &shape, const shape_t &stride)
-
Array2(const shape_t &shape, const shape_t &stride, const T init)
-
Array2(const Array<T> &nd)
-
Array2(const Array2<T> &o)
-
~Array2()
-
Array2<T> &
operator=(const Array2<T> &other)
-
template<class
R>
Array2(const Array2<R> &other)
-
template<class
R>
Array2<T> &operator=(const Array2<R> &other)
-
bool
make_mutable()
-
bool
make_immutable()
-
Array2<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
-
Array2<T>
view() const
-
Array2<T>
view(ind_t i) const
View a single sub-array at index i or an offset-smaller array if single=false;.
-
Array2<T>
view(ind_t i, ind_t j) const
View the sub-arrays from i to j-1
-
Array2<T>
view(const shape_t&) const
-
bool
set(const ind_t i, const Array2<T> &in)
-
template<class
R>
bool set(const ind_t i, const Array2<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)
-
Array2<T> &
append(const ind_t, const Array2<T>&)
-
std::string
to_string() const
-
std::string
to_string(const ind_t) const
-
Array2<T> &
reshape(const shape_t &ns)
-
Array2<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
-
-
template<class
I>
Array2<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
-
Array2<int>
round() const
-
Array2<int>
floor() const
-
Array2<int>
ceil() const
-
Array2<T>
sum(ind_t dim = 0) const
-
Array2<T>
prod(ind_t dim = 0) const
-
Array2<T>
min(ind_t dim = 0) const
-
Array2<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
-
Array2<bool>
is(cmp expr, T val) const
-
std::vector<ind_t>
find(cmp expr, T val) const
-
template<class
R>
Array2<bool> is(cmp expr, const Array2<R> &that) const
-
template<class
R>
std::vector<bool> is(cmp expr, const std::vector<R> &val) const
-
template<class
R>
bool is(const Array2<R> &that) const
-
std::vector<bool>
is_unique() const
-
std::vector<ind_t>
unique_idx() const
-
Array2<T>
unique() const
-
Array2<T>
operator-() const
-
Array2<T> &
operator+=(const T&)
-
Array2<T> &
operator-=(const T&)
-
Array2<T> &
operator*=(const T&)
-
Array2<T> &
operator/=(const T&)
-
template<class
R>
Array2<T> &operator+=(const Array2<R>&)
-
template<class
R>
Array2<T> &operator-=(const Array2<R>&)
-
template<class
R>
Array2<T> &operator*=(const Array2<R>&)
-
template<class
R>
Array2<T> &operator/=(const Array2<R>&)
-
T
dot(ind_t i, ind_t j) const
-
T
norm(ind_t i) const
-
template<class
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(const ind_t i0)
-
T *
ptr(const ind_t i0, const ind_t j0)
-
T *
ptr(const shape_t &partial_subscript)
-
const T *
ptr(const ind_t i0) const
-
const T *
ptr(const ind_t i0, const ind_t j0) const
-
const T *
ptr(const shape_t &partial_subscript) const
-
T &
val(const ind_t i0)
-
T &
val(const ind_t i0, const ind_t j0)
-
T &
val(const shape_t &partial_subscript)
-
template<class
I>
T &val(std::initializer_list<I> l)
-
const T &
val(const ind_t i0) const
-
const T &
val(const ind_t i0, const ind_t j0) const
-
const T &
val(const shape_t &partial_subscript) const
-
template<class
I>
const T &val(std::initializer_list<I> l) const
-
Array2<T>
contiguous_copy() const
-
Array2<T>
contiguous_row_ordered_copy() const
Public Static Functions
-
Array2<T>
from_std(const std::vector<T> &data)
-
template<class
R, size_t Nel>
Array2<T> from_std(const std::vector<std::array<R, Nel>> &data)
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 shape of this view, prod(_shape) ≤ _num.