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)}

Friends

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