Tensors

Tensor

template<typename T, std::size_t Dim, std::size_t Rank>
class tensor : public tmech::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.

In-place arithmetic operators

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

In-place tensor single contraction.

Parameters
  • rhs: Right hand side tensor expression of single contraction.

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

In-place tensor element-wise scalar multiplication.

Parameters
  • value: Value of element-wise scalar multiplication.

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>
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>
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.

constexpr auto begin() noexcept

Returns an iterator to the first element of the tensor.

constexpr auto end() noexcept

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

constexpr auto begin() const noexcept

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

constexpr auto end() const noexcept

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

constexpr T *raw_data() noexcept

Returns a pointer to the memory of the array.

constexpr T const *raw_data() const noexcept

Returns a constant pointer to the memory of the array.

Dimension and rank

constexpr auto rank() noexcept

Returns the rank of the tensor.

constexpr auto dimension() noexcept

Returns the dimension of the tensor.

constexpr auto size() noexcept

Returns the size of the underlying array.

Deconstructor

~tensor()

Deallocates a Dim-dimensional Rank-tensor.

Constructors

tensor()

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

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

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

Parameters
  • _tensor: Tensor to be copyed.

Constructors from initializer list

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

Allocates a Dim-dimensional Rank-tensor.

Parameters
  • l: The elements of the tensor.

Extended copy semantic

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

The extended copy constructor.

constexpr std::ostream &print(std::ostream &os) const
constexpr auto fill(value_type const value) noexcept
auto const &randu() noexcept
auto const &randn() noexcept
template<typename _Sequence>
constexpr auto change_basis_view() noexcept

Public Types

using value_data_type = typename detail::get_tensor_array_type<T, Size, dynamic_memory>::data_type
using data_type = tensor<T, Dim, Rank>
using entry_type = typename detail::get_complex_entry_type<T>::type
using value_type = T
using size_type = std::size_t

Public Functions

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 Derived>
constexpr auto const &operator=(tensor_base<Derived> const &tensor_base) noexcept
template<typename _Tensor, std::enable_if_t<is_tensor_type<typename std::decay<_Tensor>::type>::value>* = nullptr>
constexpr auto const &operator=(_Tensor &&__tensor) noexcept
constexpr auto direct_access(std::size_t __idx) const noexcept

Public Static Functions

constexpr auto simple_evaluation()

Public Static Attributes

constexpr std::size_t Size = {detail::get_tensor_size<Dim, Rank>::size}
constexpr bool dynamic_memory = {((Size <= TMECH_MAX_STATIC_SIZE) ? false : true)}

Private Types

using basetype = tensor_base<tensor<T, Dim, Rank>>

Private Functions

template<bool DynamicMemory = dynamic_memory, typename std::enable_if_t<!DynamicMemory>* = nullptr>
constexpr auto check_size()
template<bool DynamicMemory = dynamic_memory, typename std::enable_if_t<DynamicMemory>* = nullptr>
constexpr auto check_size()
template<bool DynamicMemory = dynamic_memory, typename std::enable_if_t<!DynamicMemory>* = nullptr>
constexpr auto check_size_fill_zeros()
template<bool DynamicMemory = dynamic_memory, typename std::enable_if_t<DynamicMemory>* = nullptr>
constexpr auto check_size_fill_zeros()
template<bool DynamicMemory = dynamic_memory, typename std::enable_if_t<!DynamicMemory>* = nullptr>
constexpr auto delete_data()
template<bool DynamicMemory = dynamic_memory, typename std::enable_if_t<DynamicMemory>* = nullptr>
constexpr auto delete_data()

Private Members

value_data_type _data

Friends

friend class tensor
template<typename _TensorLHS, typename _TensorRHS, typename, typename>
friend constexpr auto operator==(_TensorLHS &&__lhs, _TensorRHS &&__rhs) noexcept
template<typename _TensorLHS, typename _TensorRHS, typename, typename>
friend constexpr auto operator!=(_TensorLHS &&__lhs, _TensorRHS &&__rhs) noexcept

Adaptor

Warning

doxygenclass: Cannot find class “adaptor_wrapper” in doxygen xml output for project “tmech” from directory: _build/xml

Identity

template<typename T, std::size_t Dim, std::size_t Rank>
class eye : public tmech::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>
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

constexpr auto rank() noexcept

Returns the rank.

constexpr auto dimension() noexcept

Returns the dimension.

Private functions

template<typename ...Indicies>
constexpr auto value(size_type const i, size_type const j, Indicies const... indices) noexcept

Recursive function to determine the element at the specified position.

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.

constexpr auto value(size_type const i, size_type const j) noexcept

Determines the element at the specified position.

Parameters
  • i: First index specifying the position in the tensor expression.

  • j: Second index 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.

Public Types

using value_type = T
using size_type = std::size_t

Public Functions

~eye() noexcept

Public Static Functions

constexpr auto simple_evaluation() noexcept

Zeros

template<typename T, std::size_t Dim, std::size_t Rank>
class zeros : public tmech::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>
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

constexpr auto rank() noexcept

Returns the rank.

constexpr auto dimension() noexcept

Returns the dimension.

Public Types

using value_type = T
using size_type = std::size_t

Random normal

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

Constructors

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

Default constructor

randn(randn const &data) noexcept

Copy constructor

Public Types

using value_type = _T
using el_type = typename detail::element_type<_T>::value_type

Public Functions

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

Public Static Functions

constexpr auto rank() noexcept
constexpr auto dimension() noexcept

Random uniform

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

Constructors

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

Default constructor

randu(randu const &data) noexcept

Copy constructor

Public Types

using value_type = _T
using el_type = typename detail::element_type<_T>::value_type

Public Functions

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

Public Static Functions

constexpr auto rank() noexcept
constexpr auto dimension() noexcept

Private Types

using basetype = tensor_base<randu<_T, _Dim, _Rank>>
using uniform_distribution = typename detail::uniform_distribution<_T, std::is_floating_point<_T>::value>::type

Private Members

std::random_device dev
std::mt19937 rng
uniform_distribution dist
tensor<value_type, _Dim, _Rank> _data

Wrapper