@@ -20,24 +20,67 @@ This tutorial introduces vectors in TNL. `Vector`, in addition to `Array`, offer
By *horizontal* operations we mean vector expressions where we have one or more vectors as an input and a vector as an output. In TNL, this kind of operations is performed by the [Expression Templates](https://en.wikipedia.org/wiki/Expression_templates). It makes algebraic operations with vectors easy to do and very efficient at the same time. In some cases, one get even more efficient code compared to [Blas](https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms) and [cuBlas](https://developer.nvidia.com/cublas). See the following example.
\include Expressions.cpp
\includelineno Expressions.cpp
Output is:
\include Expressions.out
Vector expressions work only with `VectorView` not with `Vector`. The expression is evaluated on the same device where the vectors are allocated, this is done automatically. One cannot, however, mix vectors from different devices in one expression. Vector expression may contain any common function like `min`, `max`, `abs`, `sin`, `cos`, `exp`, `log`, `sqrt`, `pow` etc.
Vector expressions work only with `VectorView` not with `Vector`. The expression is evaluated on the same device where the vectors are allocated, this is done automatically. One cannot, however, mix vectors from different devices in one expression. Vector expression may contain any common function like the following:
| \ref TNL::min | Minimas of input vector expressions elements. |
| \ref TNL::sign | Signum of input vector expression elements. |
### Vertical operations
By *vertical operations* we mean (parallel) reduction based operations where we have one vector expressions as an input and one value as an output. For example computing scalar product, vector norm or finding minimum or maximum of vector elements is based on reduction. See the following example.
\include Reduction.cpp
\includelineno Reduction.cpp
Output is:
\include Reduction.out
The following table shows vertical operations that can be used on vector expressions:
| \ref TNL::min | Minimum of vector expression elements. |
| \ref TNL::argMin | Minimum of vector expression elements with index of the smallest element. |
| \ref TNL::max | Maximum of vector expression elements. |
| \ref TNL::argMax | Minimum of vector expression elements with index of the smallest element. |
| \ref TNL::sum | Sum of vector expression elements. |
| \ref TNL::lpNorm | lp norm of vector expression elements. `p` is given as second argument. |
| \ref TNL::product | Product of vector expression elements. |
| \ref TNL::logicalAnd | Logical AND of vector expression elements. |
| \ref TNL::logicalOr | Logical OR of vector expression elements. |
| \ref TNL::binaryAnd | Binary AND of vector expression elements. |
| \ref TNL::binaryOr | Binary OR of vector expression elements. |
## Static vectors
Static vectors are derived from static arrays and so they are allocated on the stack and can be created in CUDA kernels as well. Their size is fixed as well and it is given by a template parameter. Static vector is a templated class defined in namespace `TNL::Containers` having two template parameters: