Tensors

Tensor

template<typename T, std::size_t Dim, std::size_t Rank>
class tensor : public tensor_base<tensor<T, Dim, Rank>>

Dense multidimensional tensor.

Template Parameters:
  • T – The type of the tensor holding the elements.

  • Dim – Dimension of the underlying physical problem.

  • Rank – Rank of the tensor.

Constructors

tensor() noexcept

Allocates a Dim-dimensional Rank-tensor. All elements are set to zero.

tensor(tensor<T, Dim, Rank> const &_tensor) noexcept

Allocates a Dim-dimensional Rank-tensor. Elements are copyed from _tensor

Parameters:

_tensor – Tensor to be copyed.

Extended copy semantic

template<typename _Tensor, std::enable_if_t<is_tensor_type<_Tensor>::value>* = nullptr>
tensor(_Tensor const &tensor_base) noexcept

The extended copy constructor.

Constructors from initializer list

tensor(std::initializer_list<value_type> const &data) noexcept

Allocates a Dim-dimensional Rank-tensor.

Parameters:

l – The elements of the tensor.

Deconstructor

~tensor() noexcept

Deallocates a Dim-dimensional Rank-tensor.

In-place arithmetic operators

inline constexpr auto const &operator=(tensor const &tensor) noexcept

Assigns tensors to each other.

Note

This is a special case of the templated operator=. Its purpose is to prevent a default operator= from hiding the templated operator=.

template<typename _Tensor, std::enable_if_t<is_tensor_type<typename std::decay<_Tensor>::type>::value>* = nullptr>
inline constexpr auto const &operator+=(_Tensor &&__rhs) noexcept

In-place tensor subtraction.

Parameters:

rhs – Right hand side tensor expression of subtraction.

template<typename _Tensor, std::enable_if_t<is_tensor_type<typename std::decay<_Tensor>::type>::value>* = nullptr>
inline constexpr auto const &operator-=(_Tensor &&__rhs) noexcept

In-place tensor addition.

Parameters:

rhs – Right hand side tensor expression of addtion.

template<typename _Tensor, std::enable_if_t<is_tensor_type<typename std::decay<_Tensor>::type>::value>* = nullptr>
inline constexpr auto const &operator*=(_Tensor &&__rhs) noexcept

In-place tensor single contraction.

Parameters:

rhs – Right hand side tensor expression of single contraction.

inline constexpr auto const &operator*=(value_type const value) noexcept

In-place tensor element-wise scalar multiplication.

Parameters:

value – Value of element-wise scalar multiplication.

inline constexpr auto const &operator/=(value_type const value) noexcept

In-place tensor element-wise scalar division.

Parameters:

value – Value of element-wise scalar division.

Data

template<typename ...Indicies>
inline constexpr auto const &operator()(Indicies const... indices) const noexcept

Returns a constant reference of the element at the specified position in the tensor.

Parameters:

indicies – a list of indices specifying the position in the tensor. Indices must be unsigned integers, the number of indices must be equal to the rank of the expression.

template<typename ...Indicies>
inline constexpr auto &operator()(Indicies const... indices) noexcept

Returns a reference of the element at the specified position in the tensor.

Parameters:

indicies – a list of indices specifying the position in the tensor. Indices must be unsigned integers, the number of indices must be equal to the rank of the expression.

inline constexpr auto begin() noexcept

Returns an iterator to the first element of the tensor.

inline constexpr auto end() noexcept

Returns an iterator to the element following the last element of the tensor.

inline constexpr auto begin() const noexcept

Returns a constant iterator to the first element of the tensor.

inline constexpr auto end() const noexcept

Returns a constant iterator to the element following the last element of the tensor.

inline constexpr T *raw_data() noexcept

Returns a pointer to the memory of the array.

inline constexpr T const *raw_data() const noexcept

Returns a constant pointer to the memory of the array.

Dimension and rank

static inline constexpr auto rank() noexcept

Returns the rank of the tensor.

static inline constexpr auto dimension() noexcept

Returns the dimension of the tensor.

static inline constexpr auto size() noexcept

Returns the size of the underlying array.

Adaptor

template<typename _T, std::size_t _Dim, std::size_t _Rank, typename _Type>
class adaptor : public tensor_base<adaptor<_T, _Dim, _Rank, _Type>>

Constructors

constexpr adaptor(_T *__data) noexcept

Default constructor

constexpr adaptor(adaptor const &__data) noexcept

Copy constructor

Extended copy semantic

template<typename _Derived>
inline constexpr auto const &operator=(tensor_base<_Derived> const &tensor_base) noexcept

The extended assignment operator.

Data

template<typename ...Indices>
inline constexpr auto operator()(Indices... indices) const noexcept

Returns the element at the specified position in the expression.

Parameters:

indicies – A list of indices specifying the position in the tensor expression. Indices must be unsigned integers, the number of indices must be equal to the rank of the expression.

Dimension and rank

static inline constexpr auto rank() noexcept

Returns the rank of the expression.

static inline constexpr auto dimension() noexcept

Returns the dimension of the expression.

Identity

template<typename T, std::size_t Dim, std::size_t Rank>
class eye : public tensor_base<eye<T, Dim, Rank>>

Identity tensor. Only for a Rank which is a multiplier of two.

Template Parameters:
  • T – The type of the tensor holding the elements.

  • Dim – Dimension of the underlying physical problem.

  • Rank – Rank of the tensor. Rank needs to be a multiplier of two.

Constructors

constexpr eye() noexcept

Default constructor.

Data

template<typename ...Indices>
inline constexpr auto operator()(const Indices... indices) const noexcept

Returns the element at the specified position in the expression.

Parameters:

indicies – a list of indices specifying the position in the tensor expression. Indices must be unsigned integers, the number of indices must be equal to the rank of the expression.

Dimension and rank

static inline constexpr auto rank() noexcept

Returns the rank.

static inline constexpr auto dimension() noexcept

Returns the dimension.

Zeros

template<typename T, std::size_t Dim, std::size_t Rank>
class zeros : public tensor_base<zeros<T, Dim, Rank>>

Wrapper for a tensor, which contains only zeros. No memory is initialised.

Template Parameters:
  • T – The type of the tensor holding the elements.

  • Dim – Dimension of the underlying physical problem.

  • Rank – Rank of the tensor.

Constructors

constexpr zeros() noexcept

Default constructor

Data

template<typename ...Indices>
inline constexpr auto operator()(const Indices...) const noexcept

Returns a zeros.

Parameters:

indicies – A list of indices specifying the position in the tensor expression. Indices must be unsigned integers, the number of indices must be equal to the rank of the expression.

Dimension and rank

static inline constexpr auto rank() noexcept

Returns the rank.

static inline constexpr auto dimension() noexcept

Returns the dimension.

Random normal

template<typename _T, std::size_t _Dim, std::size_t _Rank>
class randn : public tensor_base<randn<_T, _Dim, _Rank>>

Wrapper for a tensor whose elements are drawn from a normal (Gaussian) distribution with the given mean and standard deviation.

Template Parameters:
  • _T – The type of the tensor holding the elements.

  • _Dim – Dimension of the underlying physical problem.

  • _Rank – Rank of the tensor.

Constructors

randn(el_type mean = 0, el_type stddev = 1) noexcept

Default constructor

randn(randn const &data) noexcept

Copy constructor

Random uniform

template<typename _T, std::size_t _Dim, std::size_t _Rank>
class randu : public tensor_base<randu<_T, _Dim, _Rank>>

Wrapper for a tensor whose elements are drawn from a uniform distribution (real or integer, depending on the value type).

Template Parameters:
  • _T – The type of the tensor holding the elements.

  • _Dim – Dimension of the underlying physical problem.

  • _Rank – Rank of the tensor.

Constructors

randu(el_type __a = el_type(0), el_type __b = el_type(1)) noexcept

Default constructor

randu(randu const &data) noexcept

Copy constructor

Wrapper