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.
Extended copy semantic
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.
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
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.
-
template<typename _Derived>
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.
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.
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.
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.