diff --git a/src/TNL/Matrices/DenseMatrix.h b/src/TNL/Matrices/DenseMatrix.h index 0036ba240d88ed0e9ac9458d3ae3ed149e3775e6..faf0d96492e2cbaf3cf6b92676b32a5862fda80e 100644 --- a/src/TNL/Matrices/DenseMatrix.h +++ b/src/TNL/Matrices/DenseMatrix.h @@ -457,7 +457,11 @@ class DenseMatrix : public Matrix< Real, Device, Index, RealAllocator > * * \tparam Function is type of lambda function that will operate on matrix elements. * It is should have form like - * `function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, const RealType& value )`. + * + * ``` + * auto function = [=] __cuda_callable__ ( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, const RealType& value ) { ... }; + * ``` + * * The column index repeats twice only for compatibility with sparse matrices. * * \param begin defines beginning of the range [begin,end) of rows to be processed. @@ -477,7 +481,11 @@ class DenseMatrix : public Matrix< Real, Device, Index, RealAllocator > * * \tparam Function is type of lambda function that will operate on matrix elements. * It is should have form like - * `function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, RealType& value )`. + * + * ``` + * auto function = [=] __cuda_callable__ ( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, RealType& value ) { ... }; + * ``` + * * The column index repeats twice only for compatibility with sparse matrices. * * \param begin defines beginning of the range [begin,end) of rows to be processed. @@ -537,10 +545,10 @@ class DenseMatrix : public Matrix< Real, Device, Index, RealAllocator > * \param function is an instance of the lambda function to be called for each row. * * ``` - * auto function = [] __cuda_callable__ ( RowViewType& row ) mutable { ... }; + * auto function = [] __cuda_callable__ ( RowView& row ) mutable { ... }; * ``` * - * \e RowViewType represents matrix row - see \ref TNL::Matrices::DenseMatrix::RowViewType. + * \e RowView represents matrix row - see \ref TNL::Matrices::DenseMatrix::RowView. * * \par Example * \include Matrices/DenseMatrix/DenseMatrixExample_forRows.cpp @@ -563,10 +571,10 @@ class DenseMatrix : public Matrix< Real, Device, Index, RealAllocator > * \param function is an instance of the lambda function to be called for each row. * * ``` - * auto function = [] __cuda_callable__ ( RowViewType& row ) { ... }; + * auto function = [] __cuda_callable__ ( RowView& row ) { ... }; * ``` * - * \e RowViewType represents matrix row - see \ref TNL::Matrices::DenseMatrix::RowViewType. + * \e RowView represents matrix row - see \ref TNL::Matrices::DenseMatrix::RowView. * * \par Example * \include Matrices/DenseMatrix/DenseMatrixExample_forRows.cpp @@ -587,10 +595,10 @@ class DenseMatrix : public Matrix< Real, Device, Index, RealAllocator > * \param function is an instance of the lambda function to be called for each row. * * ``` - * auto function = [] __cuda_callable__ ( RowViewType& row ) mutable { ... }; + * auto function = [] __cuda_callable__ ( RowView& row ) mutable { ... }; * ``` * - * \e RowViewType represents matrix row - see \ref TNL::Matrices::DenseMatrix::RowViewType. + * \e RowView represents matrix row - see \ref TNL::Matrices::DenseMatrix::RowView. * * \par Example * \include Matrices/DenseMatrix/DenseMatrixExample_forRows.cpp @@ -611,10 +619,10 @@ class DenseMatrix : public Matrix< Real, Device, Index, RealAllocator > * \param function is an instance of the lambda function to be called for each row. * * ``` - * auto function = [] __cuda_callable__ ( RowViewType& row ) { ... }; + * auto function = [] __cuda_callable__ ( RowView& row ) { ... }; * ``` * - * \e RowViewType represents matrix row - see \ref TNL::Matrices::DenseMatrix::RowViewType. + * \e RowView represents matrix row - see \ref TNL::Matrices::DenseMatrix::RowView. * * \par Example * \include Matrices/DenseMatrix/DenseMatrixExample_forRows.cpp @@ -629,8 +637,12 @@ class DenseMatrix : public Matrix< Real, Device, Index, RealAllocator > * * \tparam Function is type of lambda function that will operate on matrix elements. * It is should have form like - * `function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, const RealType& value )`. - * The column index repeats twice only for compatibility with sparse matrices. + * + * ``` + * auto function = [] __cuda_callable__ ( RowView& row ) { ... }; + * ``` + * + * \e RowView represents matrix row - see \ref TNL::Matrices::DenseMatrix::RowView. * * \param begin defines beginning of the range [begin,end) of rows to be processed. * \param end defines ending of the range [begin,end) of rows to be processed. @@ -644,8 +656,12 @@ class DenseMatrix : public Matrix< Real, Device, Index, RealAllocator > * * \tparam Function is type of lambda function that will operate on matrix elements. * It is should have form like - * `function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, RealType& value )`. - * The column index repeats twice only for compatibility with sparse matrices. + * + * ``` + * auto function = [] __cuda_callable__ ( RowView& row ) { ... }; + * ``` + * + * \e RowView represents matrix row - see \ref TNL::Matrices::DenseMatrix::RowView. * * \param begin defines beginning of the range [begin,end) of rows to be processed. * \param end defines ending of the range [begin,end) of rows to be processed. @@ -680,12 +696,25 @@ class DenseMatrix : public Matrix< Real, Device, Index, RealAllocator > * \brief Method for performing general reduction on matrix rows. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType columnIdx, RealType elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType columnIdx, RealType elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * * \param begin defines beginning of the range [begin,end) of rows to be processed. @@ -709,12 +738,25 @@ class DenseMatrix : public Matrix< Real, Device, Index, RealAllocator > * \brief Method for performing general reduction on matrix rows for constant instances. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType columnIdx, RealType elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType columnIdx, RealType elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * It is declared as + * + * ```` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * * \param begin defines beginning of the range [begin,end) of rows to be processed. @@ -738,12 +780,24 @@ class DenseMatrix : public Matrix< Real, Device, Index, RealAllocator > * \brief Method for performing general reduction on ALL matrix rows. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType columnIdx, RealType elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType columnIdx, RealType elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. + * + * ```` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * It is declared as + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * * \param fetch is an instance of lambda function for data fetch. @@ -765,12 +819,25 @@ class DenseMatrix : public Matrix< Real, Device, Index, RealAllocator > * \brief Method for performing general reduction on ALL matrix rows for constant instances. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType columnIdx, RealType elementValue ) -> FetchValue`. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType columnIdx, RealType elementValue ) -> FetchValue { ... }; + * ``` + * * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * * \param fetch is an instance of lambda function for data fetch. @@ -793,7 +860,9 @@ class DenseMatrix : public Matrix< Real, Device, Index, RealAllocator > * * More precisely, it computes: * - * `outVector = matrixMultiplicator * ( *this ) * inVector + outVectorMultiplicator * outVector` + * ``` + * outVector = matrixMultiplicator * ( *this ) * inVector + outVectorMultiplicator * outVector + * ``` * * \tparam InVector is type of input vector. It can be \ref Vector, * \ref VectorView, \ref Array, \ref ArraView or similar container. diff --git a/src/TNL/Matrices/DenseMatrixElement.h b/src/TNL/Matrices/DenseMatrixElement.h index e35235fd9ed6cbb8a752dec1d024d26cda938790..c9dcc3c86ea699607621b8f31a685fc989281e70 100644 --- a/src/TNL/Matrices/DenseMatrixElement.h +++ b/src/TNL/Matrices/DenseMatrixElement.h @@ -17,17 +17,36 @@ namespace TNL { namespace Matrices { - +/** + * \brief Accessor for dense matrix elements. + * + * \tparam Real is a type of matrix elements values. + * \tparam Index is a type of matrix elements column indexes. + */ template< typename Real, typename Index > class DenseMatrixElement { public: + /** + * \brief Type of matrix elements values. + */ using RealType = Real; + /** + * \brief Type of matrix elements column indexes. + */ using IndexType = Index; + /** + * \brief Constructor. + * + * \param value is matrix element value. + * \param rowIdx is row index of the matrix element. + * \param columnIdx is a column index of the matrix element. + * \param localIdx is the column index of the matrix element as well. + */ __cuda_callable__ DenseMatrixElement( RealType& value, const IndexType& rowIdx, @@ -35,18 +54,43 @@ class DenseMatrixElement const IndexType& localIdx ) // localIdx is here only for compatibility with SparseMatrixElement : value_( value ), rowIdx( rowIdx ), columnIdx( columnIdx ) {}; + /** + * \brief Returns reference on matrix element value. + * + * \return reference on matrix element value. + */ __cuda_callable__ RealType& value() { return value_; }; + /** + * \brief Returns constant reference on matrix element value. + * + * \return constant reference on matrix element value. + */ __cuda_callable__ const RealType& value() const { return value_; }; + /** + * \brief Returns constant reference on matrix element row index. + * + * \return constant reference on matrix element row index. + */ __cuda_callable__ const IndexType& rowIndex() const { return rowIdx; }; + /** + * \brief Returns constant reference on matrix element column index. + * + * \return constant reference on matrix element column index. + */ __cuda_callable__ const IndexType& columnIndex() const { return columnIdx; }; + /** + * \brief Returns constant reference on matrix element column index. + * + * \return constant reference on matrix element column index. + */ __cuda_callable__ const IndexType& localIndex() const { return columnIdx; }; diff --git a/src/TNL/Matrices/DenseMatrixView.h b/src/TNL/Matrices/DenseMatrixView.h index 5fd6cda8e34ab9414afe76139ddc082c1e87361a..6e181d698a52a70983af661c488952ba44d8dddb 100644 --- a/src/TNL/Matrices/DenseMatrixView.h +++ b/src/TNL/Matrices/DenseMatrixView.h @@ -405,12 +405,25 @@ class DenseMatrixView : public MatrixView< Real, Device, Index > * \brief Method for performing general reduction on matrix rows. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType columnIdx, RealType elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType columnIdx, RealType elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * * \param begin defines beginning of the range [begin,end) of rows to be processed. @@ -434,12 +447,25 @@ class DenseMatrixView : public MatrixView< Real, Device, Index > * \brief Method for performing general reduction on matrix rows for constant instances. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType columnIdx, RealType elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType columnIdx, RealType elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * * \param begin defines beginning of the range [begin,end) of rows to be processed. @@ -463,12 +489,25 @@ class DenseMatrixView : public MatrixView< Real, Device, Index > * \brief Method for performing general reduction on ALL matrix rows. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType columnIdx, RealType elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType columnIdx, RealType elementValue ) -> FetchValue + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * * \param fetch is an instance of lambda function for data fetch. @@ -490,12 +529,25 @@ class DenseMatrixView : public MatrixView< Real, Device, Index > * \brief Method for performing general reduction on ALL matrix rows for constant instances. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType columnIdx, RealType elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType columnIdx, RealType elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * * \param fetch is an instance of lambda function for data fetch. @@ -518,10 +570,12 @@ class DenseMatrixView : public MatrixView< Real, Device, Index > * * \tparam Function is type of lambda function that will operate on matrix elements. * It is should have form like - * `function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx, const RealType& value )`. + * + * ``` + * auto function = [=] __cuda_callable__ ( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx, const RealType& value ) { ... }; + * ``` + * * The column index repeats twice only for compatibility with sparse matrices. - * If the 'compute' variable is set to false the iteration over the row can - * be interrupted. * * \param begin defines beginning of the range [begin,end) of rows to be processed. * \param end defines ending of the range [begin,end) of rows to be processed. @@ -540,10 +594,12 @@ class DenseMatrixView : public MatrixView< Real, Device, Index > * * \tparam Function is type of lambda function that will operate on matrix elements. * It is should have form like - * `function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx, RealType& value )`. + * + * ``` + * auto function = [=] __cuda_callable__ ( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx, RealType& value ) { ... }; + * ``` + * * The column index repeats twice only for compatibility with sparse matrices. - * If the 'compute' variable is set to false the iteration over the row can - * be interrupted. * * \param begin defines beginning of the range [begin,end) of rows to be processed. * \param end defines ending of the range [begin,end) of rows to be processed. @@ -602,10 +658,10 @@ class DenseMatrixView : public MatrixView< Real, Device, Index > * \param function is an instance of the lambda function to be called for each row. * * ``` - * auto function = [] __cuda_callable__ ( RowViewType& row ) mutable { ... }; + * auto function = [] __cuda_callable__ ( RowView& row ) mutable { ... }; * ``` * - * \e RowViewType represents matrix row - see \ref TNL::Matrices::DenseMatrix::RowViewType. + * \e RowView represents matrix row - see \ref TNL::Matrices::DenseMatrix::RowView. * * \par Example * \include Matrices/DenseMatrix/DenseMatrixExample_forRows.cpp @@ -628,10 +684,10 @@ class DenseMatrixView : public MatrixView< Real, Device, Index > * \param function is an instance of the lambda function to be called for each row. * * ``` - * auto function = [] __cuda_callable__ ( RowViewType& row ) { ... }; + * auto function = [] __cuda_callable__ ( RowView& row ) { ... }; * ``` * - * \e RowViewType represents matrix row - see \ref TNL::Matrices::DenseMatrixView::RowViewType. + * \e RowView represents matrix row - see \ref TNL::Matrices::DenseMatrixView::RowView. * * \par Example * \include Matrices/DenseMatrix/DenseMatrixViewExample_forRows.cpp @@ -652,10 +708,10 @@ class DenseMatrixView : public MatrixView< Real, Device, Index > * \param function is an instance of the lambda function to be called for each row. * * ``` - * auto function = [] __cuda_callable__ ( RowViewType& row ) mutable { ... }; + * auto function = [] __cuda_callable__ ( RowView& row ) mutable { ... }; * ``` * - * \e RowViewType represents matrix row - see \ref TNL::Matrices::DenseMatrixView::RowViewType. + * \e RowView represents matrix row - see \ref TNL::Matrices::DenseMatrixView::RowView. * * \par Example * \include Matrices/DenseMatrix/DenseMatrixViewExample_forRows.cpp @@ -676,10 +732,10 @@ class DenseMatrixView : public MatrixView< Real, Device, Index > * \param function is an instance of the lambda function to be called for each row. * * ``` - * auto function = [] __cuda_callable__ ( RowViewType& row ) { ... }; + * auto function = [] __cuda_callable__ ( RowView& row ) { ... }; * ``` * - * \e RowViewType represents matrix row - see \ref TNL::Matrices::DenseMatrixView::RowViewType. + * \e RowView represents matrix row - see \ref TNL::Matrices::DenseMatrixView::RowView. * * \par Example * \include Matrices/DenseMatrix/DenseMatrixViewExample_forRows.cpp @@ -694,10 +750,12 @@ class DenseMatrixView : public MatrixView< Real, Device, Index > * * \tparam Function is type of lambda function that will operate on matrix elements. * It is should have form like - * `function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, const RealType& value )`. - * The column index repeats twice only for compatibility with sparse matrices. - * If the 'compute' variable is set to false the iteration over the row can - * be interrupted. + * + * ``` + * auto function = [] __cuda_callable__ ( RowView& row ) { ... }; + * ``` + * + * \e RowView represents matrix row - see \ref TNL::Matrices::DenseMatrixView::RowView. * * \param begin defines beginning of the range [begin,end) of rows to be processed. * \param end defines ending of the range [begin,end) of rows to be processed. @@ -711,10 +769,12 @@ class DenseMatrixView : public MatrixView< Real, Device, Index > * * \tparam Function is type of lambda function that will operate on matrix elements. * It is should have form like - * `function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, RealType& value )`. - * The column index repeats twice only for compatibility with sparse matrices. - * If the 'compute' variable is set to false the iteration over the row can - * be interrupted. + * + * ``` + * auto function = [] __cuda_callable__ ( RowView& row ) { ... }; + * ``` + * + * \e RowView represents matrix row - see \ref TNL::Matrices::DenseMatrixView::RowView. * * \param begin defines beginning of the range [begin,end) of rows to be processed. * \param end defines ending of the range [begin,end) of rows to be processed. @@ -750,7 +810,9 @@ class DenseMatrixView : public MatrixView< Real, Device, Index > * * More precisely, it computes: * - * `outVector = matrixMultiplicator * ( *this ) * inVector + outVectorMultiplicator * outVector` + * ``` + * outVector = matrixMultiplicator * ( *this ) * inVector + outVectorMultiplicator * outVector + * ``` * * \tparam InVector is type of input vector. It can be \ref Vector, * \ref VectorView, \ref Array, \ref ArraView or similar container. diff --git a/src/TNL/Matrices/LambdaMatrix.h b/src/TNL/Matrices/LambdaMatrix.h index cfdd77d2e3d19c24f5758cd9d7f9c995ef6adabd..2b788ed5270540a58582153b8c37e87dd346c2a4 100644 --- a/src/TNL/Matrices/LambdaMatrix.h +++ b/src/TNL/Matrices/LambdaMatrix.h @@ -260,7 +260,11 @@ class LambdaMatrix * * \tparam Function is type of lambda function that will operate on matrix elements. * It is should have form like - * `function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, const RealType& value )`. + * + * ``` + * auto function = [=] __cuda_callable__ ( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, const RealType& value ) { ... }; + * ``` + * * The column index repeats twice only for compatibility with sparse matrices. * * \param begin defines beginning of the range [begin,end) of rows to be processed. @@ -273,7 +277,7 @@ class LambdaMatrix * \include LambdaMatrixExample_forRows.out */ template< typename Function > - void forElements( IndexType first, IndexType last, Function& function ) const; + void forElements( IndexType begin, IndexType end, Function& function ) const; /** * \brief This method calls \e forElements for all matrix rows (for constant instances). @@ -346,10 +350,12 @@ class LambdaMatrix * * \tparam Function is type of lambda function that will operate on matrix elements. * It is should have form like - * `function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, const RealType& value )`. - * The column index repeats twice only for compatibility with sparse matrices. - * If the 'compute' variable is set to false the iteration over the row can - * be interrupted. + * + * ``` + * auto function = [] __cuda_callable__ ( RowView& row ) { ... }; + * ``` + * + * \e RowView represents matrix row - see \ref TNL::Matrices::LambdaMatrix::RowView. * * \param begin defines beginning of the range [begin,end) of rows to be processed. * \param end defines ending of the range [begin,end) of rows to be processed. @@ -373,16 +379,29 @@ class LambdaMatrix * \brief Method for performing general reduction on matrix rows. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType columnIdx, RealType elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType columnIdx, RealType elementValue ) -> FetchValue + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. + * + * ``` + * auto reduce = [=] __cuda_callbale__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue + * ``` + * * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [\e begin, \e end) of rows to be processed. + * \param end defines ending of the range [\e begin,\e end) of rows to be processed. * \param fetch is an instance of lambda function for data fetch. * \param reduce is an instance of lambda function for reduction. * \param keep in an instance of lambda function for storing results. @@ -396,18 +415,31 @@ class LambdaMatrix * \include LambdaMatrixExample_reduceRows.out */ template< typename Fetch, typename Reduce, typename Keep, typename FetchReal > - void reduceRows( IndexType first, IndexType last, Fetch& fetch, const Reduce& reduce, Keep& keep, const FetchReal& identity ) const; + void reduceRows( IndexType begin, IndexType end, Fetch& fetch, const Reduce& reduce, Keep& keep, const FetchReal& zero ) const; /** * \brief Method for performing general reduction on ALL matrix rows. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType columnIdx, RealType elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType columnIdx, RealType elementValue ) -> FetchValue + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue + * ``` + * * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * * \param fetch is an instance of lambda function for data fetch. @@ -430,7 +462,9 @@ class LambdaMatrix * * More precisely, it computes: * - * `outVector = matrixMultiplicator * ( *this ) * inVector + outVectorMultiplicator * outVector` + * ``` + * outVector = matrixMultiplicator * ( *this ) * inVector + outVectorMultiplicator * outVector + * ``` * * \tparam InVector is type of input vector. It can be \ref Vector, * \ref VectorView, \ref Array, \ref ArraView or similar container. diff --git a/src/TNL/Matrices/LambdaMatrixElement.h b/src/TNL/Matrices/LambdaMatrixElement.h index 57ba698f3674dada2aadd9fa7d5c62d83eb138dd..b094eb004f7110d963417b5413dcf44c9ad76b9e 100644 --- a/src/TNL/Matrices/LambdaMatrixElement.h +++ b/src/TNL/Matrices/LambdaMatrixElement.h @@ -17,17 +17,36 @@ namespace TNL { namespace Matrices { - +/** + * \brief Accessor for elements of lambda matrix. + * + * \tparam Real is type of matrix elements values. + * \tparam Index is a type of matrix elements column indexes. + */ template< typename Real, typename Index > class LambdaMatrixElement { public: + /** + * \brief Type of matrix elements values. + */ using RealType = Real; + /** + * \brief Type of matrix elements column indexes. + */ using IndexType = Index; + /** + * \brief Constructor. + * + * \param value is matrix element value. + * \param rowIdx is row index of the matrix element. + * \param columnIdx is a column index of the matrix element. + * \param localIdx is the rank of the non-zero elements in the matrix row. + */ __cuda_callable__ LambdaMatrixElement( const RealType& value, const IndexType& rowIdx, @@ -35,18 +54,43 @@ class LambdaMatrixElement const IndexType& localIdx ) : value_( value ), rowIdx( rowIdx ), columnIdx( columnIdx ), localIdx( localIdx ) {}; + /** + * \brief Copy constructor. + * + * \param el is the source matrix element. + */ __cuda_callable__ LambdaMatrixElement( const LambdaMatrixElement& el ) = default; + /** + * \brief Returns constant reference on matrix element value. + * + * \return constant reference on matrix element value. + */ __cuda_callable__ const RealType& value() const { return value_; }; + /** + * \brief Returns constant reference on matrix element row index. + * + * \return constant reference on matrix element row index. + */ __cuda_callable__ const IndexType& rowIndex() const { return rowIdx; }; + /** + * \brief Returns constant reference on matrix element column index. + * + * \return constant reference on matrix element column index. + */ __cuda_callable__ const IndexType& columnIndex() const { return columnIdx; }; + /** + * \brief Returns constant reference on the rank of the non-zero matrix element in the row. + * + * \return constant reference on the rank of the non-zero matrix element in the row. + */ __cuda_callable__ const IndexType& localIndex() const { return localIdx; }; diff --git a/src/TNL/Matrices/MatrixRowViewIterator.h b/src/TNL/Matrices/MatrixRowViewIterator.h index cf99bea295f56948226ace980ba1e0019bf90756..463ac3ca516f150192b5e70a22f9d96aff8816ca 100644 --- a/src/TNL/Matrices/MatrixRowViewIterator.h +++ b/src/TNL/Matrices/MatrixRowViewIterator.h @@ -72,15 +72,27 @@ class MatrixRowViewIterator __cuda_callable__ bool operator!=( const MatrixRowViewIterator& other ) const; + /** + * \brief Increment operator. + */ __cuda_callable__ MatrixRowViewIterator& operator++(); + /** + * \brief Decrement operetor. + */ __cuda_callable__ MatrixRowViewIterator& operator--(); + /** + * \brief Dereference operator. + */ __cuda_callable__ MatrixElementType operator*(); + /** + * \brief Dereference operator for constant instances. + */ __cuda_callable__ const MatrixElementType operator*() const; diff --git a/src/TNL/Matrices/MultidiagonalMatrix.h b/src/TNL/Matrices/MultidiagonalMatrix.h index 622b79da4f03e745e7bcdc1222ca1027da092a6e..3a74b0b44ff0d0b5529e87416b36790113a02f6f 100644 --- a/src/TNL/Matrices/MultidiagonalMatrix.h +++ b/src/TNL/Matrices/MultidiagonalMatrix.h @@ -245,7 +245,7 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator > MultidiagonalMatrix( MultidiagonalMatrix&& matrix ) = default; /** - * \brief Returns a modifiable view of the mutlidiagonal matrix. + * \brief Returns a modifiable view of the multidiagonal matrix. * * See \ref MultidiagonalMatrixView. * @@ -601,12 +601,24 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator > * \brief Method for performing general reduction on matrix rows. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * * \param begin defines beginning of the range [begin,end) of rows to be processed. @@ -624,22 +636,34 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator > * \include MultidiagonalMatrixExample_reduceRows.out */ template< typename Fetch, typename Reduce, typename Keep, typename FetchReal > - void reduceRows( IndexType first, IndexType last, Fetch& fetch, Reduce& reduce, Keep& keep, const FetchReal& identity ); + void reduceRows( IndexType begin, IndexType end, Fetch& fetch, Reduce& reduce, Keep& keep, const FetchReal& zero ); /** * \brief Method for performing general reduction on matrix rows for constant instances. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce = [=] __cuda_callbale__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep =[=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [\e begin,\e end) of rows to be processed. + * \param end defines ending of the range [\e begin,\e end) of rows to be processed. * \param fetch is an instance of lambda function for data fetch. * \param reduce is an instance of lambda function for reduction. * \param keep in an instance of lambda function for storing results. @@ -653,18 +677,30 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator > * \include MultidiagonalMatrixExample_reduceRows.out */ template< typename Fetch, typename Reduce, typename Keep, typename FetchReal > - void reduceRows( IndexType first, IndexType last, Fetch& fetch, Reduce& reduce, Keep& keep, const FetchReal& identity ) const; + void reduceRows( IndexType begin, IndexType end, Fetch& fetch, Reduce& reduce, Keep& keep, const FetchReal& zero ) const; /** * \brief Method for performing general reduction on all matrix rows. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * * \param fetch is an instance of lambda function for data fetch. @@ -686,12 +722,24 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator > * \brief Method for performing general reduction on all matrix rows for constant instances. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * * \param fetch is an instance of lambda function for data fetch. @@ -712,10 +760,11 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator > /** * \brief Method for iteration over matrix rows for constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like * - * `function( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value )`, + * ``` + * auto function = [=] __cuda_callble__ ( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value ) { ... }; + * ``` * * where * @@ -724,7 +773,7 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator > * \e localIdx parameter is a rank of the non-zero element in given row. It is also, in fact, * index of the matrix subdiagonal. * - * \e columnIdx is a column index of the matrx element. + * \e columnIdx is a column index of the matrix element. * * \e value is the matrix element value. * @@ -743,10 +792,11 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator > /** * \brief Method for iteration over matrix rows for non-constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like * - * `function( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value )`, + * ``` + * auto function = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value ) { ... }; + * ``` * * where * @@ -906,9 +956,12 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator > /** * \brief Method for sequential iteration over all matrix rows for constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like - * `function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, const RealType& value )`. + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like + * + * ``` + * auto function = [=] ( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, const RealType& value ) { ... }; + * ``` + * * The column index repeats twice only for compatibility with sparse matrices. * * \param begin defines beginning of the range [begin,end) of rows to be processed. @@ -921,13 +974,16 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator > /** * \brief Method for sequential iteration over all matrix rows for non-constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like - * `function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, RealType& value )`. + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like + * + * ``` + * auto function = [=] __cuda_callable__ ( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, RealType& value ) { ... }; + * ``` + * * The column index repeats twice only for compatibility with sparse matrices. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [\e begin,\e end) of rows to be processed. + * \param end defines ending of the range [\e begin,\e end) of rows to be processed. * \param function is an instance of the lambda function to be called in each row. */ template< typename Function > @@ -960,7 +1016,9 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator > * * More precisely, it computes: * - * `outVector = matrixMultiplicator * ( * this ) * inVector + outVectorMultiplicator * outVector` + * ``` + * outVector = matrixMultiplicator * ( * this ) * inVector + outVectorMultiplicator * outVector + * ``` * * \tparam InVector is type of input vector. It can be \ref Vector, * \ref VectorView, \ref Array, \ref ArraView or similar container. diff --git a/src/TNL/Matrices/MultidiagonalMatrixElement.h b/src/TNL/Matrices/MultidiagonalMatrixElement.h index 3672526eabd584f7622f2743175d45068e1d7f9d..2c8c370276c802450e44fa40a3000f479dccdbec 100644 --- a/src/TNL/Matrices/MultidiagonalMatrixElement.h +++ b/src/TNL/Matrices/MultidiagonalMatrixElement.h @@ -18,16 +18,36 @@ namespace TNL { namespace Matrices { +/** + * \brief Accessor for multidiagonal matrix elements. + * + * \tparam Real is a type of matrix elements values. + * \tparam Index is a type of matrix elements column indexes. + */ template< typename Real, typename Index > class MultidiagonalMatrixElement { public: + /** + * \brief Type of matrix elements values. + */ using RealType = Real; + /** + * \brief Type of matrix elements column indexes. + */ using IndexType = Index; + /** + * \brief Constructor. + * + * \param value is matrix element value. + * \param rowIdx is row index of the matrix element. + * \param columnIdx is a column index of the matrix element. + * \param localIdx is the rank of the non-zero elements in the matrix row. + */ __cuda_callable__ MultidiagonalMatrixElement( RealType& value, const IndexType& rowIdx, @@ -35,21 +55,51 @@ class MultidiagonalMatrixElement const IndexType& localIdx ) : value_( value ), rowIdx( rowIdx ), columnIdx( columnIdx ), localIdx( localIdx ) {}; + /** + * \brief Returns reference on matrix element value. + * + * \return reference on matrix element value. + */ __cuda_callable__ RealType& value() { return value_; }; + /** + * \brief Returns constant reference on matrix element value. + * + * \return constant reference on matrix element value. + */ __cuda_callable__ const RealType& value() const { return value_; }; + /** + * \brief Returns constant reference on matrix element column index. + * + * \return constant reference on matrix element column index. + */ __cuda_callable__ const IndexType& rowIndex() const { return rowIdx; }; + /** + * \brief Returns reference on matrix element column index. + * + * \return reference on matrix element column index. + */ __cuda_callable__ IndexType& columnIndex() { return columnIdx; }; + /** + * \brief Returns constant reference on matrix element column index. + * + * \return constant reference on matrix element column index. + */ __cuda_callable__ const IndexType& columnIndex() const { return columnIdx; }; + /** + * \brief Returns constant reference on the rank of the non-zero matrix element in the row. + * + * \return constant reference on the rank of the non-zero matrix element in the row. + */ __cuda_callable__ const IndexType& localIndex() const { return localIdx; }; diff --git a/src/TNL/Matrices/MultidiagonalMatrixView.h b/src/TNL/Matrices/MultidiagonalMatrixView.h index fc5799fa68b23cdd25a501d899b2fcdcf34c0356..869ddb9732e8541fecf9847c1ed648f189012335 100644 --- a/src/TNL/Matrices/MultidiagonalMatrixView.h +++ b/src/TNL/Matrices/MultidiagonalMatrixView.h @@ -363,16 +363,28 @@ class MultidiagonalMatrixView : public MatrixView< Real, Device, Index > * \brief Method for performing general reduction on matrix rows for constant instances. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param fetch is an instance of lambda function for data fetch. * \param reduce is an instance of lambda function for reduction. * \param keep in an instance of lambda function for storing results. @@ -386,22 +398,34 @@ class MultidiagonalMatrixView : public MatrixView< Real, Device, Index > * \include MultidiagonalMatrixViewExample_reduceRows.out */ template< typename Fetch, typename Reduce, typename Keep, typename FetchReal > - void reduceRows( IndexType first, IndexType last, Fetch& fetch, Reduce& reduce, Keep& keep, const FetchReal& identity ) const; + void reduceRows( IndexType begin, IndexType end, Fetch& fetch, Reduce& reduce, Keep& keep, const FetchReal& zero ) const; /** * \brief Method for performing general reduction on matrix rows. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param fetch is an instance of lambda function for data fetch. * \param reduce is an instance of lambda function for reduction. * \param keep in an instance of lambda function for storing results. @@ -415,18 +439,30 @@ class MultidiagonalMatrixView : public MatrixView< Real, Device, Index > * \include MultidiagonalMatrixViewExample_reduceRows.out */ template< typename Fetch, typename Reduce, typename Keep, typename FetchReal > - void reduceRows( IndexType first, IndexType last, Fetch& fetch, Reduce& reduce, Keep& keep, const FetchReal& identity ); + void reduceRows( IndexType begin, IndexType end, Fetch& fetch, Reduce& reduce, Keep& keep, const FetchReal& zero ); /** * \brief Method for performing general reduction on all matrix rows for constant instances. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * * \param fetch is an instance of lambda function for data fetch. @@ -448,10 +484,18 @@ class MultidiagonalMatrixView : public MatrixView< Real, Device, Index > * \brief Method for performing general reduction on all matrix rows. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * * \tparam Keep is a type of lambda function for storing results of reduction in each row. * It is declared as `keep( const IndexType rowIdx, const double& value )`. * \tparam FetchValue is type returned by the Fetch lambda function. @@ -474,10 +518,11 @@ class MultidiagonalMatrixView : public MatrixView< Real, Device, Index > /** * \brief Method for iteration over all matrix rows for constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like * - * `function( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value )`, + * ``` + * auto function = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value ) { ... }; + * ``` * * where * @@ -486,12 +531,12 @@ class MultidiagonalMatrixView : public MatrixView< Real, Device, Index > * \e localIdx parameter is a rank of the non-zero element in given row. It is also, in fact, * index of the matrix subdiagonal. * - * \e columnIdx is a column index of the matrx element. + * \e columnIdx is a column index of the matrix element. * * \e value is the matrix element value. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param function is an instance of the lambda function to be called in each row. * * \par Example @@ -500,15 +545,16 @@ class MultidiagonalMatrixView : public MatrixView< Real, Device, Index > * \include MultidiagonalMatrixViewExample_forRows.out */ template< typename Function > - void forElements( IndexType first, IndexType last, Function& function ) const; + void forElements( IndexType begin, IndexType end, Function& function ) const; /** * \brief Method for iteration over all matrix rows for non-constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like * - * `function( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value )`, + * ``` + * auto function = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value ) { ... }; + * ``` * * where * @@ -517,12 +563,12 @@ class MultidiagonalMatrixView : public MatrixView< Real, Device, Index > * \e localIdx parameter is a rank of the non-zero element in given row. It is also, in fact, * index of the matrix subdiagonal. * - * \e columnIdx is a column index of the matrx element. + * \e columnIdx is a column index of the matrix element. * * \e value is a reference to the matrix element value. It can be used even for changing the matrix element value. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param function is an instance of the lambda function to be called in each row. * * \par Example @@ -531,7 +577,7 @@ class MultidiagonalMatrixView : public MatrixView< Real, Device, Index > * \include MultidiagonalMatrixViewExample_forRows.out */ template< typename Function > - void forElements( IndexType first, IndexType last, Function& function ); + void forElements( IndexType begin, IndexType end, Function& function ); /** * \brief This method calls \e forElements for all matrix rows (for constant instances). @@ -668,13 +714,16 @@ class MultidiagonalMatrixView : public MatrixView< Real, Device, Index > /** * \brief Method for sequential iteration over all matrix rows for constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like - * `function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, const RealType& value )`. - * The column index repeats twice only for compatibility with sparse matrices. + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * ``` + * auto function = [] __cuda_callable__ ( const RowView& row ) { ... }; + * ``` + * + * \e RowView represents matrix row - see \ref TNL::Matrices::MultidiagonalMatrixView::RowView. + * + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param function is an instance of the lambda function to be called in each row. */ template< typename Function > @@ -683,13 +732,16 @@ class MultidiagonalMatrixView : public MatrixView< Real, Device, Index > /** * \brief Method for sequential iteration over all matrix rows for non-constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like - * `function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, RealType& value )`. - * The column index repeats twice only for compatibility with sparse matrices. + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * ``` + * auto function = [] __cuda_callable__ ( RowView& row ) { ... }; + * ``` + * + * \e RowView represents matrix row - see \ref TNL::Matrices::MultidiagonalMatrixView::RowView. + * + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param function is an instance of the lambda function to be called in each row. */ template< typename Function > @@ -722,7 +774,9 @@ class MultidiagonalMatrixView : public MatrixView< Real, Device, Index > * * More precisely, it computes: * - * `outVector = matrixMultiplicator * ( * this ) * inVector + outVectorMultiplicator * outVector` + * ``` + * outVector = matrixMultiplicator * ( * this ) * inVector + outVectorMultiplicator * outVector + * ``` * * \tparam InVector is type of input vector. It can be \ref Vector, * \ref VectorView, \ref Array, \ref ArraView or similar container. @@ -745,8 +799,8 @@ class MultidiagonalMatrixView : public MatrixView< Real, Device, Index > OutVector& outVector, const RealType matrixMultiplicator = 1.0, const RealType outVectorMultiplicator = 0.0, - const IndexType firstRow = 0, - IndexType lastRow = 0 ) const; + const IndexType begin = 0, + IndexType end = 0 ) const; template< typename Real_, typename Device_, typename Index_, ElementsOrganization Organization_ > void addMatrix( const MultidiagonalMatrixView< Real_, Device_, Index_, Organization_ >& matrix, diff --git a/src/TNL/Matrices/SparseMatrix.h b/src/TNL/Matrices/SparseMatrix.h index ef7fe058039ee96606d38c921e42477368e035ec..3b139d941194759192c6579f2beec2f9c1489863 100644 --- a/src/TNL/Matrices/SparseMatrix.h +++ b/src/TNL/Matrices/SparseMatrix.h @@ -604,16 +604,28 @@ class SparseMatrix : public Matrix< Real, Device, Index, RealAllocator > * \brief Method for performing general reduction on matrix rows. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param fetch is an instance of lambda function for data fetch. * \param reduce is an instance of lambda function for reduction. * \param keep in an instance of lambda function for storing results. @@ -633,16 +645,28 @@ class SparseMatrix : public Matrix< Real, Device, Index, RealAllocator > * \brief Method for performing general reduction on matrix rows for constant instances. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... } + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param fetch is an instance of lambda function for data fetch. * \param reduce is an instance of lambda function for reduction. * \param keep in an instance of lambda function for storing results. @@ -662,12 +686,24 @@ class SparseMatrix : public Matrix< Real, Device, Index, RealAllocator > * \brief Method for performing general reduction on all matrix rows. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValu { ... }; + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * * \param fetch is an instance of lambda function for data fetch. @@ -689,12 +725,24 @@ class SparseMatrix : public Matrix< Real, Device, Index, RealAllocator > * \brief Method for performing general reduction on all matrix rows for constant instances. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * * \param fetch is an instance of lambda function for data fetch. @@ -717,7 +765,7 @@ class SparseMatrix : public Matrix< Real, Device, Index, RealAllocator > * * \tparam Function is type of lambda function that will operate on matrix elements. * - * \param begin defines beginning of the range [ \e begin,\e end ) of rows to be processed. + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param function is an instance of the lambda function to be called for element of given rows. * @@ -897,13 +945,16 @@ class SparseMatrix : public Matrix< Real, Device, Index, RealAllocator > /** * \brief Method for sequential iteration over all matrix rows for constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like - * `function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, const RealType& value )`. - * The column index repeats twice only for compatibility with sparse matrices. + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * ``` + * auto function = [] __cuda_callable__ ( RowView& row ) { ... }; + * ``` + * + * \e RowView represents matrix row - see \ref TNL::Matrices::SparseMatrix::RowView. + * + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param function is an instance of the lambda function to be called in each row. */ template< typename Function > @@ -912,13 +963,16 @@ class SparseMatrix : public Matrix< Real, Device, Index, RealAllocator > /** * \brief Method for sequential iteration over all matrix rows for non-constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like - * `function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, RealType& value )`. - * The column index repeats twice only for compatibility with sparse matrices. + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * ``` + * auto function = [] __cuda_callable__ ( RowView& row ) { ... }; + * ``` + * + * \e RowView represents matrix row - see \ref TNL::Matrices::SparseMatrix::RowView. + * + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param function is an instance of the lambda function to be called in each row. */ template< typename Function > @@ -951,7 +1005,9 @@ class SparseMatrix : public Matrix< Real, Device, Index, RealAllocator > * * More precisely, it computes: * - * `outVector = matrixMultiplicator * ( * this ) * inVector + outVectorMultiplicator * outVector` + * ``` + * outVector = matrixMultiplicator * ( * this ) * inVector + outVectorMultiplicator * outVector + * ``` * * \tparam InVector is type of input vector. It can be \ref Vector, * \ref VectorView, \ref Array, \ref ArraView or similar container. @@ -974,8 +1030,8 @@ class SparseMatrix : public Matrix< Real, Device, Index, RealAllocator > OutVector& outVector, const ComputeRealType& matrixMultiplicator = 1.0, const ComputeRealType& outVectorMultiplicator = 0.0, - const IndexType firstRow = 0, - const IndexType lastRow = 0 ) const; + const IndexType begin = 0, + const IndexType end = 0 ) const; /*template< typename Real2, typename Index2 > void addMatrix( const SparseMatrix< Real2, Segments, Device, Index2 >& matrix, diff --git a/src/TNL/Matrices/SparseMatrixElement.h b/src/TNL/Matrices/SparseMatrixElement.h index 485fb919b95a0938dc9d4b3b67093be31008f0a6..39c7b61b4953289a7adc8bb1cb2452485259994a 100644 --- a/src/TNL/Matrices/SparseMatrixElement.h +++ b/src/TNL/Matrices/SparseMatrixElement.h @@ -18,6 +18,12 @@ namespace TNL { namespace Matrices { +/** + * \brief Accessor for sparse matrix elements. + * + * \tparam Real is a type of matrix elements values. + * \tparam Index is a type of matrix elements column indexes. + */ template< typename Real, typename Index, bool isBinary_ = false > @@ -25,10 +31,24 @@ class SparseMatrixElement { public: + /** + * \brief Type of matrix elements values. + */ using RealType = Real; + /** + * \brief Type of matrix elements column indexes. + */ using IndexType = Index; + /** + * \brief Constructor. + * + * \param value is matrix element value. + * \param rowIdx is row index of the matrix element. + * \param columnIdx is a column index of the matrix element. + * \param localIdx is the rank of the non-zero elements in the matrix row. + */ __cuda_callable__ SparseMatrixElement( RealType& value, const IndexType& rowIdx, @@ -36,21 +56,51 @@ class SparseMatrixElement const IndexType& localIdx ) : value_( value ), rowIdx( rowIdx ), columnIdx( columnIdx ), localIdx( localIdx ) {}; + /** + * \brief Returns reference on matrix element value. + * + * \return reference on matrix element value. + */ __cuda_callable__ RealType& value() { return value_; }; + /** + * \brief Returns constant reference on matrix element value. + * + * \return constant reference on matrix element value. + */ __cuda_callable__ const RealType& value() const { return value_; }; + /** + * \brief Returns constant reference on matrix element column index. + * + * \return constant reference on matrix element column index. + */ __cuda_callable__ const IndexType& rowIndex() const { return rowIdx; }; + /** + * \brief Returns reference on matrix element column index. + * + * \return reference on matrix element column index. + */ __cuda_callable__ IndexType& columnIndex() { return columnIdx; }; + /** + * \brief Returns constant reference on matrix element column index. + * + * \return constant reference on matrix element column index. + */ __cuda_callable__ const IndexType& columnIndex() const { return columnIdx; }; + /** + * \brief Returns constant reference on the rank of the non-zero matrix element in the row. + * + * \return constant reference on the rank of the non-zero matrix element in the row. + */ __cuda_callable__ const IndexType& localIndex() const { return localIdx; }; diff --git a/src/TNL/Matrices/SparseMatrixView.h b/src/TNL/Matrices/SparseMatrixView.h index 10310d8023ea5c2aea035c79022e49782be6ae74..ba73ea651f5fd36fdf72a524139043d9ad3cbef5 100644 --- a/src/TNL/Matrices/SparseMatrixView.h +++ b/src/TNL/Matrices/SparseMatrixView.h @@ -395,16 +395,28 @@ class SparseMatrixView : public MatrixView< Real, Device, Index > * \brief Method for performing general reduction on matrix rows. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param fetch is an instance of lambda function for data fetch. * \param reduce is an instance of lambda function for reduction. * \param keep in an instance of lambda function for storing results. @@ -424,16 +436,28 @@ class SparseMatrixView : public MatrixView< Real, Device, Index > * \brief Method for performing general reduction on matrix rows for constant instances. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param fetch is an instance of lambda function for data fetch. * \param reduce is an instance of lambda function for reduction. * \param keep in an instance of lambda function for storing results. @@ -453,12 +477,24 @@ class SparseMatrixView : public MatrixView< Real, Device, Index > * \brief Method for performing general reduction on all matrix rows. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * * \param fetch is an instance of lambda function for data fetch. @@ -480,12 +516,24 @@ class SparseMatrixView : public MatrixView< Real, Device, Index > * \brief Method for performing general reduction on all matrix rows for constant instances. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * * \param fetch is an instance of lambda function for data fetch. @@ -506,13 +554,16 @@ class SparseMatrixView : public MatrixView< Real, Device, Index > /** * \brief Method for iteration over all matrix rows for constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like - * `function( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value )`. + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like + * + * ``` + * auto function = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value ) { ... }; + * ``` + * * The \e localIdx parameter is a rank of the non-zero element in given row. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin,\e end ) of rows to be processed. * \param function is an instance of the lambda function to be called in each row. * * \par Example @@ -526,13 +577,16 @@ class SparseMatrixView : public MatrixView< Real, Device, Index > /** * \brief Method for iteration over all matrix rows for non-constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like - * `function( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value )`. + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like + * + * ``` + * auto function = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value ) { ... }; + * ``` + * * The \e localIdx parameter is a rank of the non-zero element in given row. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param function is an instance of the lambda function to be called in each row. * * \par Example @@ -679,13 +733,16 @@ class SparseMatrixView : public MatrixView< Real, Device, Index > /** * \brief Method for sequential iteration over all matrix rows for constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like - * `function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, const RealType& value )`. - * The column index repeats twice only for compatibility with sparse matrices. + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * ``` + * auto function = [] __cuda_callable__ ( RowView& row ) { ... }; + * ``` + * + * \e RowView represents matrix row - see \ref TNL::Matrices::SparseMatrixView::RowView. + * + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param function is an instance of the lambda function to be called in each row. */ template< typename Function > @@ -694,13 +751,16 @@ class SparseMatrixView : public MatrixView< Real, Device, Index > /** * \brief Method for sequential iteration over all matrix rows for non-constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like - * `function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, RealType& value )`. - * The column index repeats twice only for compatibility with sparse matrices. + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * ``` + * auto function = [] __cuda_callable__ ( RowView& row ) { ... }; + * ``` + * + * \e RowView represents matrix row - see \ref TNL::Matrices::SparseMatrixView::RowView. + * + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param function is an instance of the lambda function to be called in each row. */ template< typename Function > @@ -733,7 +793,9 @@ class SparseMatrixView : public MatrixView< Real, Device, Index > * * More precisely, it computes: * - * `outVector = matrixMultiplicator * ( * this ) * inVector + outVectorMultiplicator * outVector` + * ``` + * outVector = matrixMultiplicator * ( * this ) * inVector + outVectorMultiplicator * outVector + * ``` * * \tparam InVector is type of input vector. It can be \ref Vector, * \ref VectorView, \ref Array, \ref ArraView or similar container. diff --git a/src/TNL/Matrices/TridiagonalMatrix.h b/src/TNL/Matrices/TridiagonalMatrix.h index 4789a079f0dc469a656b5eb7e371bf024d2ff4f7..45e6d132fecd289df3ba1ccf608eebf39a1342d7 100644 --- a/src/TNL/Matrices/TridiagonalMatrix.h +++ b/src/TNL/Matrices/TridiagonalMatrix.h @@ -493,16 +493,28 @@ class TridiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator > * \brief Method for performing general reduction on matrix rows. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param fetch is an instance of lambda function for data fetch. * \param reduce is an instance of lambda function for reduction. * \param keep in an instance of lambda function for storing results. @@ -522,16 +534,28 @@ class TridiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator > * \brief Method for performing general reduction on matrix rows of constant matrix instances. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param fetch is an instance of lambda function for data fetch. * \param reduce is an instance of lambda function for reduction. * \param keep in an instance of lambda function for storing results. @@ -551,16 +575,28 @@ class TridiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator > * \brief Method for performing general reduction on all matrix rows. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param fetch is an instance of lambda function for data fetch. * \param reduce is an instance of lambda function for reduction. * \param keep in an instance of lambda function for storing results. @@ -580,16 +616,28 @@ class TridiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator > * \brief Method for performing general reduction on all matrix rows of constant matrix instances. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param fetch is an instance of lambda function for data fetch. * \param reduce is an instance of lambda function for reduction. * \param keep in an instance of lambda function for storing results. @@ -608,13 +656,16 @@ class TridiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator > /** * \brief Method for iteration over matrix rows for constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like - * `function( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value )`. + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like + * + * ``` + * auto function = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value ) { ... }; + * ``` + * * The \e localIdx parameter is a rank of the non-zero element in given row. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param function is an instance of the lambda function to be called in each row. * * \par Example @@ -628,9 +679,12 @@ class TridiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator > /** * \brief Method for iteration over matrix rows for non-constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like - * `function( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value )`. + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like + * + * ``` + * auto function = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value ) { ... }; + * ``` + * * The \e localIdx parameter is a rank of the non-zero element in given row. * * \param begin defines beginning of the range [begin,end) of rows to be processed. @@ -648,13 +702,16 @@ class TridiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator > /** * \brief Method for iteration over all matrix rows for constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like - * `function( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value )`. + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like + * + * ``` + * auto function = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value ) { ... }; + * ``` + * * The \e localIdx parameter is a rank of the non-zero element in given row. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param function is an instance of the lambda function to be called in each row. * * \par Example @@ -668,9 +725,12 @@ class TridiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator > /** * \brief Method for iteration over all matrix rows for non-constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like - * `function( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value )`. + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like + * + * ``` + * auto function = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value ) { ... }; + * ``` + * * The \e localIdx parameter is a rank of the non-zero element in given row. * * \param begin defines beginning of the range [begin,end) of rows to be processed. @@ -788,10 +848,13 @@ class TridiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator > /** * \brief Method for sequential iteration over all matrix rows for constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like - * `function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, const RealType& value )`. - * The column index repeats twice only for compatibility with sparse matrices. + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like + * + * ``` + * auto function = [] __cuda_callable__ ( RowView& row ) { ... }; + * ``` + * + * \e RowView represents matrix row - see \ref TNL::Matrices::TridiagonalMatrix::RowView. * * \param begin defines beginning of the range [begin,end) of rows to be processed. * \param end defines ending of the range [begin,end) of rows to be processed. @@ -803,10 +866,13 @@ class TridiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator > /** * \brief Method for sequential iteration over all matrix rows for non-constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like - * `function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, RealType& value )`. - * The column index repeats twice only for compatibility with sparse matrices. + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like + * + * ``` + * auto function = [] __cuda_callable__ ( RowView& row ) { ... }; + * ``` + * + * \e RowView represents matrix row - see \ref TNL::Matrices::TridiagonalMatrix::RowView. * * \param begin defines beginning of the range [begin,end) of rows to be processed. * \param end defines ending of the range [begin,end) of rows to be processed. @@ -842,7 +908,9 @@ class TridiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator > * * More precisely, it computes: * - * `outVector = matrixTriplicator * ( * this ) * inVector + outVectorTriplicator * outVector` + * ``` + * outVector = matrixTriplicator * ( * this ) * inVector + outVectorTriplicator * outVector + * ``` * * \tparam InVector is type of input vector. It can be \ref Vector, * \ref VectorView, \ref Array, \ref ArraView or similar container. diff --git a/src/TNL/Matrices/TridiagonalMatrixView.h b/src/TNL/Matrices/TridiagonalMatrixView.h index 6b68f419783328208caa9a07ed49e50c5a99eabd..c8e0ecdcad2e6f9b4fc45f2b56e09a0070866c5a 100644 --- a/src/TNL/Matrices/TridiagonalMatrixView.h +++ b/src/TNL/Matrices/TridiagonalMatrixView.h @@ -179,11 +179,6 @@ class TridiagonalMatrixView : public MatrixView< Real, Device, Index > template< typename Vector > void getCompressedRowLengths( Vector& rowLengths ) const; - //[[deprecated]] - //IndexType getRowLength( const IndexType row ) const; - - //IndexType getMaxRowLength() const; - /** * \brief Returns number of non-zero matrix elements. * @@ -350,16 +345,28 @@ class TridiagonalMatrixView : public MatrixView< Real, Device, Index > * \brief Method for performing general reduction on matrix rows for constant instances. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param fetch is an instance of lambda function for data fetch. * \param reduce is an instance of lambda function for reduction. * \param keep in an instance of lambda function for storing results. @@ -373,22 +380,34 @@ class TridiagonalMatrixView : public MatrixView< Real, Device, Index > * \include TridiagonalMatrixViewExample_reduceRows.out */ template< typename Fetch, typename Reduce, typename Keep, typename FetchReal > - void reduceRows( IndexType first, IndexType last, Fetch& fetch, Reduce& reduce, Keep& keep, const FetchReal& identity ) const; + void reduceRows( IndexType begin, IndexType end, Fetch& fetch, Reduce& reduce, Keep& keep, const FetchReal& zero ) const; /** * \brief Method for performing general reduction on matrix rows. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param fetch is an instance of lambda function for data fetch. * \param reduce is an instance of lambda function for reduction. * \param keep in an instance of lambda function for storing results. @@ -402,18 +421,30 @@ class TridiagonalMatrixView : public MatrixView< Real, Device, Index > * \include TridiagonalMatrixViewExample_reduceRows.out */ template< typename Fetch, typename Reduce, typename Keep, typename FetchReal > - void reduceRows( IndexType first, IndexType last, Fetch& fetch, Reduce& reduce, Keep& keep, const FetchReal& identity ); + void reduceRows( IndexType begin, IndexType end, Fetch& fetch, Reduce& reduce, Keep& keep, const FetchReal& zero ); /** * \brief Method for performing general reduction on all matrix rows for constant instances. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * * \param fetch is an instance of lambda function for data fetch. @@ -435,12 +466,24 @@ class TridiagonalMatrixView : public MatrixView< Real, Device, Index > * \brief Method for performing general reduction on all matrix rows. * * \tparam Fetch is a type of lambda function for data fetch declared as - * `fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue`. - * The return type of this lambda can be any non void. + * + * ``` + * auto fetch = [=] __cuda_callable__ ( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue { ... }; + * ``` + * + * The return type of this lambda can be any non void. * \tparam Reduce is a type of lambda function for reduction declared as - * `reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue`. - * \tparam Keep is a type of lambda function for storing results of reduction in each row. - * It is declared as `keep( const IndexType rowIdx, const double& value )`. + * + * ``` + * auto reduce = [=] __cuda_callable__ ( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue { ... }; + * ``` + * + * \tparam Keep is a type of lambda function for storing results of reduction in each row. It is declared as + * + * ``` + * auto keep = [=] __cuda_callable__ ( const IndexType rowIdx, const double& value ) { ... }; + * ``` + * * \tparam FetchValue is type returned by the Fetch lambda function. * * \param fetch is an instance of lambda function for data fetch. @@ -461,13 +504,16 @@ class TridiagonalMatrixView : public MatrixView< Real, Device, Index > /** * \brief Method for iteration over all matrix rows for constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like - * `function( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value )`. - * The \e localIdx parameter is a rank of the non-zero element in given row. + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like + * + * ``` + * auto function = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value ) { ... }; + * ``` + * + * The \e localIdx parameter is a rank of the non-zero element in given row. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin,\e end ) of rows to be processed. * \param function is an instance of the lambda function to be called in each row. * * \par Example @@ -476,18 +522,21 @@ class TridiagonalMatrixView : public MatrixView< Real, Device, Index > * \include TridiagonalMatrixViewExample_forRows.out */ template< typename Function > - void forElements( IndexType first, IndexType last, Function& function ) const; + void forElements( IndexType begin, IndexType end, Function& function ) const; /** * \brief Method for iteration over all matrix rows for non-constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like - * `function( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value )`. + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like + * + * ``` + * auto function = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value ) { ... }; + * ``` + * * The \e localIdx parameter is a rank of the non-zero element in given row. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param function is an instance of the lambda function to be called in each row. * * \par Example @@ -496,7 +545,7 @@ class TridiagonalMatrixView : public MatrixView< Real, Device, Index > * \include TridiagonalMatrixViewExample_forRows.out */ template< typename Function > - void forElements( IndexType first, IndexType last, Function& function ); + void forElements( IndexType begin, IndexType end, Function& function ); /** * \brief This method calls \e forElements for all matrix rows (for constant instances). @@ -633,15 +682,16 @@ class TridiagonalMatrixView : public MatrixView< Real, Device, Index > /** * \brief Method for sequential iteration over all matrix rows for constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like - * `function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, const RealType& value )`. - * The column index repeats twice only for compatibility with sparse matrices. - * If the 'compute' variable is set to false the iteration over the row can - * be interrupted. + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like + * + * ``` + * auto function = [] __cuda_callable__ ( RowView& row ) { ... }; + * ``` + * + * \e RowView represents matrix row - see \ref TNL::Matrices::TridiagonalMatrixView::RowView. * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param function is an instance of the lambda function to be called in each row. */ template< typename Function > @@ -650,15 +700,16 @@ class TridiagonalMatrixView : public MatrixView< Real, Device, Index > /** * \brief Method for sequential iteration over all matrix rows for non-constant instances. * - * \tparam Function is type of lambda function that will operate on matrix elements. - * It is should have form like - * `function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, RealType& value )`. - * The column index repeats twice only for compatibility with sparse matrices. - * If the 'compute' variable is set to false the iteration over the row can - * be interrupted. + * \tparam Function is type of lambda function that will operate on matrix elements. It is should have form like * - * \param begin defines beginning of the range [begin,end) of rows to be processed. - * \param end defines ending of the range [begin,end) of rows to be processed. + * ``` + * auto function = [] __cuda_callable__ ( RowView& row ) { ... }; + * ``` + * + * \e RowView represents matrix row - see \ref TNL::Matrices::TridiagonalMatrixView::RowView. + * + * \param begin defines beginning of the range [ \e begin, \e end ) of rows to be processed. + * \param end defines ending of the range [ \e begin, \e end ) of rows to be processed. * \param function is an instance of the lambda function to be called in each row. */ template< typename Function > @@ -691,7 +742,9 @@ class TridiagonalMatrixView : public MatrixView< Real, Device, Index > * * More precisely, it computes: * - * `outVector = matrixMultiplicator * ( * this ) * inVector + outVectorMultiplicator * outVector` + * ``` + * outVector = matrixMultiplicator * ( * this ) * inVector + outVectorMultiplicator * outVector + * ``` * * \tparam InVector is type of input vector. It can be \ref Vector, * \ref VectorView, \ref Array, \ref ArraView or similar container.