Tensor
-
Tensor
a. 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$.
b. 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;
}
c. Definition
Defined in the header file tensor/tensor.hpp
.
d. Model of
e. Type requirements
None, except for those imposed by the requirements of Tensor .
f. Public base classes
tensor_container<tensor<value_t,format_t,storage_t> >
g. Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of object stored in the tensor. |
|
|
Storage organization. [1] |
|
|
The type of the Storage array. [2] |
|
h. Member types
Member type | Description |
---|---|
|
Type |
|
Format of the tensor which is either |
|
Sequence container type that stores all tensor elements and is accessible with a single index. |
|
Type of the strides vector
|
|
Type of the dimension extents vector |
|
Unsigned integer which is usually |
|
Unsigned integer which is usually |
|
Reference type |
|
Constant reference type
|
|
Pointer type |
|
Constant reference type
|
|
RandomAccessIterator |
|
Constant RandomAccessIterator
|
|
Reverse RandomAccessIterator
|
|
Reverse RandomAccessIterator
|
|
Type of the matrix
|
|
Type of the vector
|
i. Alias templates
Alias template | Description |
---|---|
|
Type of tensor_expression where |
|
Type of matrix_expression. |
|
Type of vector_expression. |
j. Member Functions
i. Construction
Member function | Description |
---|---|
|
Constructs an uninitialized |
|
Constructs an
uninitialized |
|
Constructs an uninitialized
|
|
Constructs an
uninitialized |
|
Constructs
tensor by copying elements from |
|
Constructs tensor by copying elements
from |
|
Constructs tensor by moving elements from
|
|
Constructs tensor by copying
elements from |
|
Constructs tensor by moving elements
from |
|
Constructs tensor by copying
elements from |
|
Constructs tensor by moving elements
from |
|
Constructs
tensor by evaluating the tensor
expression |
|
Constructs
tensor by evaluating the matrix expression
|
|
Constructs
tensor by evaluating the vector expression
|
ii. Assignment
Member function | Description |
---|---|
|
Evaluates the tensor expression
|
|
Copies or moves elements of |
|
Initialiates all elements of a
tensor with |
iii. Capacity
Member function | Description |
---|---|
|
Returns true if a tensor has zero elements. |
|
Returns the number of elements of the tensor. |
|
Returns the number of dimensions of the tensor. |
|
Returns the number of dimensions of the tensor. |
|
Returns a constant reference to the strides of the tensor. |
|
Returns a constant reference to the extents of the tensor. |
iv. Element access
Member function | Description |
---|---|
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a |
|
Returns a |
v. Proxy Generation
Member function | Description |
---|---|
|
Returns a tensor index instance with
index objects |
vi. Iterators
Member function | Description |
---|---|
|
Returns a const_iterator pointing to the first element of the tensor. |
|
Returns a const_iterator pointing to the first element of the tensor. |
|
Returns an iterator pointing to the first element of the tensor. |
|
Returns a const_iterator pointing to the position after the last element of the tensor. |
|
Returns a const_iterator pointing to the position after the last element of the tensor. |
|
Returns an iterator pointing to the position after the last element of the tensor. |
vii. Modifiers
Member function | Description |
---|---|
|
Reshapes the tensor according to the extents |
viii. 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
Copyright (©) 2021 Shikhar Vashistha
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 ).