Template Class ArrayView#

Class Documentation#

template<typename T>
class ArrayView#

An intermediate type to represent a slice or view of an array.

Template Parameters

T – The type of the array.

Public Types

using BaseType = typename std::decay_t<T>#
using Scalar = typename typetraits::TypeInfo<BaseType>::Scalar#
using Reference = BaseType&#
using ConstReference = const BaseType&#
using Backend = typename typetraits::TypeInfo<BaseType>::Backend#
using ArrayType = Array<Scalar, Backend>#
using StrideType = typename ArrayType::StrideType#
using ShapeType = typename ArrayType::ShapeType#
using Iterator = detail::ArrayIterator<ArrayView>#

Public Functions

ArrayView() = delete#

Default constructor should never be used.

explicit ArrayView(T &array)#

Copy an ArrayView object

Parameters

array – The array to copy

explicit ArrayView(T &&array) = delete#

Copy an ArrayView object (not const)

Parameters

array – The array to copy

ArrayView(const ArrayView &other) = default#

Copy an ArrayView object (const)

Parameters

other – The array to copy

ArrayView(ArrayView &&other) = default#

Constructs an ArrayView from a temporary instance

Parameters

other – The ArrayView to move

ArrayView &operator=(const ArrayView &other) = default#

Assigns another ArrayView object to this ArrayView.

Parameters

other – The ArrayView to assign.

Returns

A reference to this

ArrayView &operator=(const Scalar &scalar)#

Assigns a temporary ArrayView to this ArrayView.

Parameters
  • other – The ArrayView to move.

  • scalar – The scalar value to assign

Returns

A reference to this ArrayView. Assign a scalar value to this ArrayView. This function should only be used to assign to a zero-dimensional “scalar” ArrayView, and will throw an error if used incorrectly.

Returns

A reference to this

template<typename RefType>
ArrayView &operator=(const ArrayRef<RefType> &other)#
const ArrayView<T> operator[](int64_t index) const#

Access a sub-array of this ArrayView.

Parameters

index – The index of the sub-array.

Returns

An ArrayView from this

ArrayView<T> operator[](int64_t index)#
template<typename CAST = Scalar>
CAST get() const#

Since even scalars are represented as an ArrayView object, it can be difficult to operate on them directly. This allows you to extract the scalar value stored by a zero-dimensional ArrayView object

Template Parameters

CAST – Type to cast to

Returns

The scalar represented by the ArrayView object

template<typename CAST>
explicit operator CAST() const#

Same functionality as “get”, except slightly less robust for user-defined types.

Template Parameters

CAST – Type to cast to

Returns

The scalar represented by the ArrayView object

ShapeType shape() const#

Access the underlying shape of this ArrayView

Returns

Shape object

StrideType stride() const#

Access the stride of this ArrayView

Returns

Stride object

int64_t offset() const#

Access the offset of this ArrayView. This is the offset, in elements, from the referenced Array’s first element.

Returns

Offset

void setShape(const ShapeType &shape)#

Set the Shape of this ArrayView to something else. Intended for internal use only.

Parameters

shape – The new shape of this ArrayView

void setStride(const StrideType &stride)#

Set the Stride of this ArrayView to something else. Intended for internal use only.

Parameters

stride – The new stride of this ArrayView

void setOffset(const int64_t &offset)#

Set the offset of this ArrayView object. Intended for internal use only.

Parameters

offset – The new offset of this ArrayView

int64_t ndim() const#

Returns the number of dimensions of this ArrayView

Returns

Number of dimensions

auto scalar(int64_t index) const#

Return the Scalar at a given index in this ArrayView. This is intended for use internally, but can be used externally too.

Parameters

index – The index of the Scalar to return

Returns

Scalar at the given index

ArrayType eval() const#

Evaluate the contents of this ArrayView object and return an Array instance from it. Depending on your use case, this may result in more performant code, but the new Array will not reference the original data in the ArrayView.

Returns

A new Array instance

Iterator begin() const#
Iterator end() const#
std::string str(const std::string &format = "{}") const#

Cast an ArrayView to a std::string, aligning items down the columns. A format string can also be specified, which will be used to format the items to strings

Parameters

format – The format string

Returns

A std::string representation of this ArrayView

template<typename RefType>
ArrayView<T> &operator=(const ArrayRef<RefType> &other)#