Commit 4309f3f6 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Added forRows to MultidiagonalMatrix.

parent 1bcdc892
Loading
Loading
Loading
Loading
+104 −4
Original line number Diff line number Diff line
@@ -134,12 +134,12 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator >
      /**
       * \brief Type for accessing matrix rows.
       */
      using RowView = MultidiagonalMatrixRowView< ValuesViewType, IndexerType, DiagonalsOffsetsView >;
      using RowViewType = typename ViewType::RowViewType;

      /**
       * \brief Type for accessing constant matrix rows.
       */
      using ConstRowView = typename RowView::ConstViewType;
      using ConstRowViewType = typename ViewType::ConstViewType;

      /**
       * \brief Helper type for getting self type or its modifications.
@@ -492,7 +492,7 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator >
       * See \ref MultidiagonalMatrixRowView.
       */
      __cuda_callable__
      RowView getRow( const IndexType& rowIdx );
      RowViewType getRow( const IndexType& rowIdx );

      /**
       * \brief Constant getter of simple structure for accessing given matrix row.
@@ -509,7 +509,7 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator >
       * See \ref MultidiagonalMatrixRowView.
       */
      __cuda_callable__
      const RowView getRow( const IndexType& rowIdx ) const;
      const ConstRowViewType getRow( const IndexType& rowIdx ) const;

      /**
       * \brief Set all matrix elements to given value.
@@ -801,6 +801,106 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator >
      template< typename Function >
      void forAllElements( Function& function );

      /**
       * \brief Method for parallel iteration over matrix rows from interval [ \e begin, \e end).
       *
       * In each row, given lambda function is performed. Each row is processed by at most one thread unlike the method
       * \ref MultidiagonalMatrix::forElements where more than one thread can be mapped to each row.
       *
       * \tparam Function is type of the lambda function.
       *
       * \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 each row.
       *
       * ```
       * auto function = [] __cuda_callable__ ( RowViewType& row ) mutable { ... };
       * ```
       *
       * \e RowViewType represents matrix row - see \ref TNL::Matrices::MultidiagonalMatrix::RowViewType.
       *
       * \par Example
       * \include Matrices/MultidiagonalMatrix/MultidiagonalMatrixExample_forRows.cpp
       * \par Output
       * \include MultidiagonalMatrixExample_forRows.out
       */
      template< typename Function >
      void forRows( IndexType begin, IndexType end, Function&& function );

      /**
       * \brief Method for parallel iteration over matrix rows from interval [ \e begin, \e end) for constant instances.
       *
       * In each row, given lambda function is performed. Each row is processed by at most one thread unlike the method
       * \ref MultidiagonalMatrix::forElements where more than one thread can be mapped to each row.
       *
       * \tparam Function is type of the lambda function.
       *
       * \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 each row.
       *
       * ```
       * auto function = [] __cuda_callable__ ( RowViewType& row ) { ... };
       * ```
       *
       * \e RowViewType represents matrix row - see \ref TNL::Matrices::MultidiagonalMatrix::RowViewType.
       *
       * \par Example
       * \include Matrices/MultidiagonalMatrix/MultidiagonalMatrixExample_forRows.cpp
       * \par Output
       * \include MultidiagonalMatrixExample_forRows.out
       */
      template< typename Function >
      void forRows( IndexType begin, IndexType end, Function&& function ) const;

      /**
       * \brief Method for parallel iteration over all matrix rows.
       *
       * In each row, given lambda function is performed. Each row is processed by at most one thread unlike the method
       * \ref MultidiagonalMatrix::forAllElements where more than one thread can be mapped to each row.
       *
       * \tparam Function is type of the lambda function.
       *
       * \param function is an instance of the lambda function to be called for each row.
       *
       * ```
       * auto function = [] __cuda_callable__ ( RowViewType& row ) mutable { ... };
       * ```
       *
       * \e RowViewType represents matrix row - see \ref TNL::Matrices::MultidiagonalMatrix::RowViewType.
       *
       * \par Example
       * \include Matrices/MultidiagonalMatrix/MultidiagonalMatrixExample_forRows.cpp
       * \par Output
       * \include MultidiagonalMatrixExample_forRows.out
       */
      template< typename Function >
      void forAllRows( Function&& function );

      /**
       * \brief Method for parallel iteration over all matrix rows for constant instances.
       *
       * In each row, given lambda function is performed. Each row is processed by at most one thread unlike the method
       * \ref MultidiagonalMatrix::forAllElements where more than one thread can be mapped to each row.
       *
       * \tparam Function is type of the lambda function.
       *
       * \param function is an instance of the lambda function to be called for each row.
       *
       * ```
       * auto function = [] __cuda_callable__ ( RowViewType& row ) { ... };
       * ```
       *
       * \e RowViewType represents matrix row - see \ref TNL::Matrices::MultidiagonalMatrix::RowViewType.
       *
       * \par Example
       * \include Matrices/MultidiagonalMatrix/MultidiagonalMatrixExample_forRows.cpp
       * \par Output
       * \include MultidiagonalMatrixExample_forRows.out
       */
      template< typename Function >
      void forAllRows( Function&& function ) const;

      /**
       * \brief Method for sequential iteration over all matrix rows for constant instances.
       *
+58 −2
Original line number Diff line number Diff line
@@ -404,7 +404,7 @@ template< typename Real,
__cuda_callable__
auto
MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::
getRow( const IndexType& rowIdx ) const -> const RowView
getRow( const IndexType& rowIdx ) const -> const ConstRowViewType
{
   return this->view.getRow( rowIdx );
}
@@ -418,7 +418,7 @@ template< typename Real,
__cuda_callable__
auto
MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::
getRow( const IndexType& rowIdx ) -> RowView
getRow( const IndexType& rowIdx ) -> RowViewType
{
   return this->view.getRow( rowIdx );
}
@@ -580,6 +580,62 @@ forAllElements( Function& function )
   this->view.forElements( 0, this->getRows(), function );
}

template< typename Real,
          typename Device,
          typename Index,
          ElementsOrganization Organization,
          typename RealAllocator,
          typename IndexAllocator >
   template< typename Function >
void
MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::
forRows( IndexType begin, IndexType end, Function&& function )
{
   this->getView().forRows( begin, end, function );
}

template< typename Real,
          typename Device,
          typename Index,
          ElementsOrganization Organization,
          typename RealAllocator,
          typename IndexAllocator >
   template< typename Function >
void
MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::
forRows( IndexType begin, IndexType end, Function&& function ) const
{
   this->getConstView().forRows( begin, end, function );
}

template< typename Real,
          typename Device,
          typename Index,
          ElementsOrganization Organization,
          typename RealAllocator,
          typename IndexAllocator >
   template< typename Function >
void
MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::
forAllRows( Function&& function )
{
   this->getView().forAllRows( function );
}

template< typename Real,
          typename Device,
          typename Index,
          ElementsOrganization Organization,
          typename RealAllocator,
          typename IndexAllocator >
   template< typename Function >
void
MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::
forAllRows( Function&& function ) const
{
   this->getConsView().forAllRows( function );
}

template< typename Real,
          typename Device,
          typename Index,
+22 −14
Original line number Diff line number Diff line
@@ -110,6 +110,14 @@ class MultidiagonalMatrixRowView
      __cuda_callable__
      IndexType getSize() const;

      /**
       * \brief Returns the matrix row index.
       *
       * \return matrix row index.
       */
      __cuda_callable__
      const IndexType& getRowIndex() const;

      /**
       * \brief Computes column index of matrix element on given subdiagonal.
       *
+11 −1
Original line number Diff line number Diff line
@@ -33,6 +33,16 @@ getSize() const -> IndexType
   return diagonalsOffsets.getSize();//indexer.getRowSize( rowIdx );
}


template< typename ValuesView, typename Indexer, typename DiagonalsOffsetsView >
__cuda_callable__
auto
MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsOffsetsView >::
getRowIndex() const -> const IndexType&
{
   return this->rowIdx;
}

template< typename ValuesView, typename Indexer, typename DiagonalsOffsetsView >
__cuda_callable__
auto
+109 −3
Original line number Diff line number Diff line
@@ -76,7 +76,12 @@ class MultidiagonalMatrixView : public MatrixView< Real, Device, Index >
      /**
       * \brief Type for accessing matrix rows.
       */
      using RowView = MultidiagonalMatrixRowView< ValuesViewType, IndexerType, DiagonalsOffsetsView >;
      using RowViewType = MultidiagonalMatrixRowView< ValuesViewType, IndexerType, DiagonalsOffsetsView >;

      /**
       * \brief Type for accessing constant matrix rows.
       */
      using ConstRowViewType = typename RowViewType::ConstViewType;

      /**
       * \brief Helper type for getting self type or its modifications.
@@ -251,7 +256,7 @@ class MultidiagonalMatrixView : public MatrixView< Real, Device, Index >
       * See \ref MultidiagonalMatrixRowView.
       */
      __cuda_callable__
      RowView getRow( const IndexType& rowIdx );
      RowViewType getRow( const IndexType& rowIdx );

      /**
       * \brief Constant getter of simple structure for accessing given matrix row.
@@ -268,7 +273,7 @@ class MultidiagonalMatrixView : public MatrixView< Real, Device, Index >
       * See \ref MultidiagonalMatrixRowView.
       */
      __cuda_callable__
      const RowView getRow( const IndexType& rowIdx ) const;
      const ConstRowViewType getRow( const IndexType& rowIdx ) const;

      /**
       * \brief Set all matrix elements to given value.
@@ -558,6 +563,107 @@ class MultidiagonalMatrixView : public MatrixView< Real, Device, Index >
      template< typename Function >
      void forAllElements( Function& function );

      /**
       * \brief Method for parallel iteration over matrix rows from interval [ \e begin, \e end).
       *
       * In each row, given lambda function is performed. Each row is processed by at most one thread unlike the method
       * \ref MultidiagonalMatrixView::forElements where more than one thread can be mapped to each row.

       *
       * \tparam Function is type of the lambda function.
       *
       * \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 each row.
       *
       * ```
       * auto function = [] __cuda_callable__ ( RowViewType& row ) mutable { ... };
       * ```
       *
       * \e RowViewType represents matrix row - see \ref TNL::Matrices::MultidiagonalMatrixView::RowViewType.
       *
       * \par Example
       * \include Matrices/MultidiagonalMatrix/MultidiagonalMatrixViewExample_forRows.cpp
       * \par Output
       * \include MultidiagonalMatrixViewExample_forRows.out
       */
      template< typename Function >
      void forRows( IndexType begin, IndexType end, Function&& function );

      /**
       * \brief Method for parallel iteration over matrix rows from interval [ \e begin, \e end) for constant instances.
       *
       * In each row, given lambda function is performed. Each row is processed by at most one thread unlike the method
       * \ref MultidiagonalMatrixView::forElements where more than one thread can be mapped to each row.
       *
       * \tparam Function is type of the lambda function.
       *
       * \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 each row.
       *
       * ```
       * auto function = [] __cuda_callable__ ( RowViewType& row ) { ... };
       * ```
       *
       * \e RowViewType represents matrix row - see \ref TNL::Matrices::MultidiagonalMatrixView::RowViewType.
       *
       * \par Example
       * \include Matrices/MultidiagonalMatrix/MultidiagonalMatrixViewExample_forRows.cpp
       * \par Output
       * \include MultidiagonalMatrixViewExample_forRows.out
       */
      template< typename Function >
      void forRows( IndexType begin, IndexType end, Function&& function ) const;

      /**
       * \brief Method for parallel iteration over all matrix rows.
       *
       * In each row, given lambda function is performed. Each row is processed by at most one thread unlike the method
       * \ref MultidiagonalMatrixView::forAllElements where more than one thread can be mapped to each row.
       *
       * \tparam Function is type of the lambda function.
       *
       * \param function is an instance of the lambda function to be called for each row.
       *
       * ```
       * auto function = [] __cuda_callable__ ( RowViewType& row ) mutable { ... };
       * ```
       *
       * \e RowViewType represents matrix row - see \ref TNL::Matrices::MultidiagonalMatrixView::RowViewType.
       *
       * \par Example
       * \include Matrices/MultidiagonalMatrix/MultidiagonalMatrixViewExample_forRows.cpp
       * \par Output
       * \include MultidiagonalMatrixViewExample_forRows.out
       */
      template< typename Function >
      void forAllRows( Function&& function );

      /**
       * \brief Method for parallel iteration over all matrix rows for constant instances.
       *
       * In each row, given lambda function is performed. Each row is processed by at most one thread unlike the method
       * \ref MultidiagonalMatrixView::forAllElements where more than one thread can be mapped to each row.
       *
       * \tparam Function is type of the lambda function.
       *
       * \param function is an instance of the lambda function to be called for each row.
       *
       * ```
       * auto function = [] __cuda_callable__ ( RowViewType& row ) { ... };
       * ```
       *
       * \e RowViewType represents matrix row - see \ref TNL::Matrices::MultidiagonalMatrixView::RowViewType.
       *
       * \par Example
       * \include Matrices/MultidiagonalMatrix/MultidiagonalMatrixViewExample_forRows.cpp
       * \par Output
       * \include MultidiagonalMatrixViewExample_forRows.out
       */
      template< typename Function >
      void forAllRows( Function&& function ) const;

      /**
       * \brief Method for sequential iteration over all matrix rows for constant instances.
       *
Loading