Commit 10d646e6 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Added documenation of some vector functions plus reduction tutorial fixes.

parent 330361cc
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -41,17 +41,17 @@ Putting everything together gives the following example:

\include SumExample.cpp

Since TNL vectors cannot be pass to CUDA kernels and so they cannot be captured by CUDA lambdas, we must first get vector view from the vector using a method `getView()`.
Since TNL vectors cannot be pass to CUDA kernels and so they cannot be captured by CUDA lambdas, we must first get vector view from the vector using a method `getConstView()`.

Note tha we pass `0.0` as the last argument of the method `Reduction< Device >::reduce`. It is an *idempotent element* (see [Idempotence](https://cs.wikipedia.org/wiki/Idempotence)). It is an element which, for given operation, does not change the result. For addition, it is zero. The result looks as follows.

\include SumExample.out

Sum of vector elements can be also obtained as `sum(v)`.
Sum of vector elements can be also obtained as [`sum(v)`](../html/namespaceTNL.html#a41cea4796188f0877dbb6e72e2d3559e).

### Product<a name="flexible_parallel_reduction_product"></a>

To demonstrate the effect of the *idempotent element*, we will now compute product of all elements of the vector. The *idempotent element* is one for multiplication and we also need to replace `a+=b` with `a*=b` in the definition of `reduce`. We get the following code:
To demonstrate the effect of the *idempotent element*, we will now compute product of all elements of the vector. The *idempotent element* is one for multiplication and we also need to replace `a+b` with `a*b` in the definition of `reduce`. We get the following code:

\include ProductExample.cpp

@@ -59,7 +59,7 @@ leading to output like this:

\include ProductExample.out

Product of vector elements can be computed using fuction `product(v)`.
Product of vector elements can be computed using fuction [`product(v)`](../html/namespaceTNL.html#ac11e1901681d36b19a0ad3c6f167a718).

### Scalar product<a name="flexible_parallel_reduction_scalar_product"></a>

@@ -71,7 +71,7 @@ The result is:

\include ScalarProductExample.out

Scalar product of vectors `u` and `v` can be in TNL computed by `dot(u,v)` or simply as `(u,v)`.
Scalar product of vectors `u` and `v` can be in TNL computed by [`dot(u,v)`](../html/namespaceTNL.html#ab49c6303cbe48c65ca350389460c2e40) or simply as [`(u,v)`](../html/namespaceTNL_1_1Containers.html#a6453777fc16ef91a3c309338cd18dd0c).

### Maxium norm<a name="flexible_parallel_reduction_maximum_norm"></a>

@@ -83,7 +83,7 @@ The output is:

\include MaximumNormExample.out

Maximum norm in TNL computes function `maxNorm(v)`.
Maximum norm in TNL computes function [`maxNorm(v)`](../html/namespaceTNL.html#acea36b20e471c597fb21bc2b996bbb04).

### Vectors comparison<a name="flexible_parallel_reduction_vector_comparison"></a>

+37 −2
Original line number Diff line number Diff line
@@ -17,8 +17,12 @@
namespace TNL {
namespace Containers {

////
// Addition
/**
 * \brief Addition of vector and vector expression.
 * @param a
 * @param b
 * @return 
 */
template< typename Real, typename Device, typename Index, typename Allocator, typename ET,
          typename..., typename = std::enable_if_t< Expressions::IsNumericExpression<ET>::value > >
auto
@@ -493,6 +497,13 @@ operator-( const Vector< Real, Device, Index, Allocator >& a )

////
// Scalar product
/**
 * \brief Computes scalar product of vector and vector expression.
 * 
 * @param a input vector
 * @param b input vector expression
 * @return scalar product of vector and vector expression
 */
template< typename Real, typename Device, typename Index, typename Allocator, typename ET,
          typename..., typename = std::enable_if_t< Expressions::IsNumericExpression<ET>::value > >
Real
@@ -631,6 +642,13 @@ max( const Containers::Vector< Real1, Device, Index, Allocator >& a, const Conta

////
// Dot product - the same as scalar product, just for convenience
/**
 * \brief Computes scalar product of vector and vector expression.
 * 
 * @param a input vector
 * @param b input vector expression
 * @return scalar product of vector and vector expression
 */
template< typename Real, typename Device, typename Index, typename Allocator, typename ET,
          typename..., typename = std::enable_if_t< Containers::Expressions::IsNumericExpression<ET>::value > >
auto
@@ -948,6 +966,12 @@ argMax( const Containers::Vector< Real, Device, Index, Allocator >& a )
   return Containers::Expressions::ExpressionArgMax( a.getConstView() );
}

/**
 * \brief Computes sum of all vector elements.
 * 
 * @param a input vector
 * @return sum of all vector elements
 */
template< typename Real,
          typename Device,
          typename Index, typename Allocator >
@@ -957,6 +981,12 @@ sum( const Containers::Vector< Real, Device, Index, Allocator >& a )
   return Containers::Expressions::ExpressionSum( a.getConstView() );
}

/**
 * \brief Computes maximum norm of a vector.
 * 
 * @param a input vector
 * @return  maximum norm
 */
template< typename Real,
          typename Device,
          typename Index, typename Allocator >
@@ -1000,6 +1030,11 @@ lpNorm( const Containers::Vector< Real, Device, Index, Allocator >& a, const Rea
   return TNL::pow( Containers::Expressions::ExpressionLpNorm( a.getConstView(), p ), 1.0 / p );
}

/**
 * \brief Computes product of all vector elements.
 * @param a
 * @return 
 */
template< typename Real,
          typename Device,
          typename Index, typename Allocator >