Back to Arangodb

Tensor

3rdParty/boost/1.78.0/libs/numeric/ublas/doc/tensor.html

3.12.9.110.1 KB
Original Source

Tensor

Tensor

Description

The templated class tensor<value_t,format_t,storage_t> is the base container adaptor for dense tensors. Every element $t_{i_1,i_2,\dots,i_p}$ of a $p$-order $(n_1 \times n_2 \times \cdots \times n_p)$-dimensional tensor $T$ is mapped to $j$-th element of a one-dimensional container where $j = \sum_{r=1}^p i_r \cdot w_r$ with $1 \leq i_r \leq n_r $ for $1 \leq r \leq p$. For the first-order orientation $w_1 = 1$ and $w_k = n_{k-1} \cdot w_{k-1}$ for $k > 1$. For last-order orientation $w_p = 1$ and $ w_k = n_{k+1} \cdot w_{k+1}$ for $k < p$.

Example

**#include** <boost/numeric/ublas/tensor.hpp> **int** main () { **using namespace** boost::numeric::ublas;
  tensor< **double** > t{4,2,3}; **for** ( **auto** k = 0ul; k < t.size (2); ++ k) **for** ( **auto** j = 0ul; j < t.size (1); ++ j) **for** ( **auto** i = 0ul; i < t.size (0); ++ i)
        t.at(i,j,k) = 3*i + 2*j + 5*k;

  std::cout << t << std::endl;
}

Definition

Defined in the header file tensor/tensor.hpp.

Model of

Tensor

Type requirements

None, except for those imposed by the requirements of Tensor .

Public base classes

tensor_container<tensor<value_t,format_t,storage_t> >

Template parameters

ParameterDescriptionDefault
value_tThe type of object stored in the tensor.
format_tStorage organization. [1]first_order
storage_tThe type of the Storage array. [2]std::vector<value_t>

Member types

Member typeDescription
value_typeType value_t of the tensor elements.
layout_typeFormat of the tensor which is either first_order or last_order.
array_typeSequence container type that stores all tensor elements and is accessible with a single index.
strides_typeType of the strides vector basic_strides<std::size_t,layout_type> that stores all tensor elements and is accessible with a single index.
extents_typeType of the dimension extents vector shape that stores all tensor elements and is accessible with a single index.
size_typeUnsigned integer which is usually std::size_t.
difference_typeUnsigned integer which is usually std::ptrdiff_t.
referenceReference type storage_type::reference which is in most cases value_type&.
const_referenceConstant reference type storage_type::const_reference which is in most cases const value_type&.
pointerPointer type storage_type::pointer which is in most cases value_type*.
const_pointerConstant reference type storage_type::const_reference which is in most cases const value_type*.
iteratorRandomAccessIterator storage_type::iterator.
const_iteratorConstant RandomAccessIterator storage_type::const_iterator.
reverse_iteratorReverse RandomAccessIterator storage_type::reverse_iterator.
const_reverse_iteratorReverse RandomAccessIterator storage_type::const_reverse_iterator.
matrix_typeType of the matrix matrix<value_type,layout_type,array_type> with which the tensor type interacts.
vector_typeType of the vector matrix<value_type,layout_type,array_type> with which the tensor type interacts.

Alias templates

Alias templateDescription
template<class derived_type> using tensor_expression_type = detail::tensor_expression<self_type,derived_type>Type of tensor_expression where self_type is the tensor type.
template<class derived_type> using matrix_expression_type = matrix_expression<derived_type>Type of matrix_expression.
template<class derived_type> using vector_expression_type = vector_expression<derived_type>Type of vector_expression.

Member Functions

Construction

Member functionDescription
tensor ()Constructs an uninitialized tensor that holds zero elements.
tensor (std::initializer_list<size_type> list)Constructs an uninitialized tensor where list specifies the dimension extents.
tensor (extents_type const& s)Constructs an uninitialized tensor where s specifies the dimension extents.
tensor (extents_type const& e, array_type const& a)Constructs an uninitialized tensor where e specifies the dimension extents and a the data elements of the tensor.
tensor (tensor<value_type,other_layout&rt; const& other)Constructs tensor by copying elements from other where the layout is different from this layout type.
tensor (tensor const& other)Constructs tensor by copying elements from other.
tensor (tensor && other)Constructs tensor by moving elements from other.
tensor (matrix_type const& other)Constructs tensor by copying elements from other matrix. The tensor will have the order 2.
tensor (matrix_type && other)Constructs tensor by moving elements from other matrix. The tensor will have the order 2.
tensor (vector_type const& other)Constructs tensor by copying elements from other vector. The tensor will have the order 1.
tensor (vector_type && other)Constructs tensor by moving elements from other vector. The tensor will have the order 1.
tensor (tensor_expression_type<derived_type> const& expr)Constructs tensor by evaluating the tensor expression expr and copying all elements of the result.
tensor (matrix_expression_type<derived_type> const& expr)Constructs tensor by evaluating the matrix expression expr and copying all elements of the result.
tensor (vector_expression_type<derived_type> const& expr)Constructs tensor by evaluating the vector expression expr and copying all elements of the result.

Assignment

Member functionDescription
tensor& operator=(tensor_expression_type<derived_type> const& expr)Evaluates the tensor expression expr and copyies all elements of the result.
tensor& operator=(tensor other)Copies or moves elements of other.
tensor& operator=(const_reference v)Initialiates all elements of a tensor with v.

Capacity

Member functionDescription
bool empty() constReturns true if a tensor has zero elements.
size_type size() constReturns the number of elements of the tensor.
size_type rank() constReturns the number of dimensions of the tensor.
size_type order() constReturns the number of dimensions of the tensor.
strides_type const& strides() constReturns a constant reference to the strides of the tensor.
extents_type const& extents() constReturns a constant reference to the extents of the tensor.

Element access

Member functionDescription
pointer data()Returns a pointer the first element of the tensor.
const_pointer data() constReturns a const_pointer the first element of the tensor.
reference operator[](size_type j)Returns a reference to the j-th element of the storage array of the tensor. Corresponds to the function call tensor::data()+j
const_reference operator[](size_type j) constReturns a const_reference to the j-th element of the storage array of the tensor. Corresponds to the function call tensor::data()+j.
template<class ... size_types> reference at(size_type i, size_types ... is)Returns a reference to the (i,is...)-th element of the tensor where (i,is...) denotes a multi-index with tensor::order() elements. If sizeof...(is)==0, tensor::operator[i] is called.
template<class ... size_types> const_reference at(size_type i, size_types ... is)Returns a const_reference to the (i,is...)-th element of the tensor where (i,is...) denotes a multi-index with tensor::order() elements. If sizeof...(is)==0, tensor::operator[i] is called.

Proxy Generation

Member functionDescription
template<std::size_t I, class ... index_types> tensor_index operator()(indices::Index<I> p, index_types ... ps)Returns a tensor index instance with index objects (p,ps...) for a tensor contraction where sizeof...(ps)+1 must be equal to tensor::order().

Iterators

Member functionDescription
const_iterator begin() constReturns a const_iterator pointing to the first element of the tensor.
const_iterator cbegin() constReturns a const_iterator pointing to the first element of the tensor.
iterator begin()Returns an iterator pointing to the first element of the tensor.
const_iterator end() constReturns a const_iterator pointing to the position after the last element of the tensor.
const_iterator cend() constReturns a const_iterator pointing to the position after the last element of the tensor.
iterator begin()Returns an iterator pointing to the position after the last element of the tensor.

Modifiers

Member functionDescription
void reshape(extents_type const& e, value_type v = value_type{})Reshapes the tensor according to the extents e. If e.product() is greater than tensor::size(), the tensor is resized with v.

Notes

[1] Supported parameters for the storage organization are first_order and last_order.

[2] Common parameters for the storage array are std::array<N,T> and std::vector<T>.


Copyright (©) 2018 Cem Bassoy
Use, modification and distribution are subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).