-
Notifications
You must be signed in to change notification settings - Fork 1
Documentation
Following the documentation style of Boost.uBLAS, the HTML documentation is in the doc and doc/tensor directories. Additionally, most functions and data structures are doxygen documented. This page shall provide an overview and demonstrate how uBLAS was extended with tensors. Note that complete examples are found in examples/tensor directory.
Entrywise tensor operations perform a binary or unary operations on tensor, matrix and vector elements with the same multi-index. The operators are overloaded and implemented in operators_arithmetic.hpp. Consequently all objects must have the same shape. Note that none of the operators evaluate the expression but rather construct an expression template with respect to the operation. Expression templates are evaluated when the assignment operator of the tensor is encountered.
Operations | Operators | Example |
---|---|---|
Binary Operations with Tensors | +,-,/,* |
Z = X*Y; |
Binary Operations with Tensor Expressions | +,-,/,* |
Z = X*Y + X/Y; |
Binary Operations with Matrices | +,-,/,* |
Z = X*A; |
Binary Operations with Tensor/Matrix Expressions | +,-,/,* |
Z = B*Y + A/Y; |
Binary Operations with Vectors | +,-,/,* |
Z = X*v; |
Binary Operations with Tensor/Vector Expressions | +,-,/,* |
Z = X*u + v/Y; |
Binary Operations with Scalars | +,-,/,* |
Z = 4*X; |
Unary Operations | +,- |
Z = -X; |
Tensor assignments perform a binary or unary operations on tensor, matrix and vector elements with the same multi-index. The operators are overloaded and implemented in operators_arithmetic.hpp. Note that the implementation evaluates the expression.
Operations | Operators | Example |
---|---|---|
Operations with Tensors | +=,-=,/=,*= |
Z += X; , Z *= Y;
|
Operations with Tensor Expressions | +=,-=,/=,*= |
Z += X*Z + 3; |
Operations with Scalars | +=,-=,/=,*= |
Z += 4; |
Comparison operations compare tensor elements with the same multi-index. The operators are overloaded and implemented in operators_comparison.hpp. Consequently all objects must have the same shape. Note that all comparisons are evaluated when the compare operator is encountered and expression objects are not generated.
Operations | Operators | Example |
---|---|---|
Tensors | ==,!=,<,>,<=,>= |
X==Y && Y!=Z; |
Tensor Expressions | ==,!=,<,>,<=,>= |
X*Y <= Y/Z; |
Tensors with Scalars | ==,!=,<,>,<=,>= |
X==Y && 3*Z<=4; |
The following free tensor functions are implemented in functions.hpp. Internally they call generic functions, defined in multiplication.hpp and algorithms.hpp, that are implemented in terms of pointers, strides and offsets. Note that the functions are evaluated immediately and no expression object is generated. Note that you can combine entrywise and compare operations as well as computed assignments with these free functions.
Operations | Operators | Example |
---|---|---|
Tensor Transposition | trans() |
auto Z = trans(X,{4,3,2}) |
k-mode Tensor-Times-Vector | prod() |
auto Z = prod(X,v,2); |
k-mode Tensor-Times-Matrix | prod() |
auto Z = prod(X,A,2); |
Tensor-Times-Tensor | prod() |
auto Z = prod(X,Y,{1,3}); , auto Z = prod(X,Y,{1,3},{4,2});
|
Inner Product | inner_prod() |
auto a = inner_prod(X,Y); |
Outer Product | outer_prod() |
auto Z = outer_prod(X,Y); |