Commit 6dac0736 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Added forRows to tridiagonal matrix.

parent 3a919ad2
Loading
Loading
Loading
Loading
+107 −3
Original line number Diff line number Diff line
@@ -117,8 +117,12 @@ class TridiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator >
      /**
       * \brief Type for accessing matrix rows.
       */
      using RowView = TridiagonalMatrixRowView< ValuesViewType, IndexerType >;
      using RowViewType = typename ViewType::RowViewType;

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

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

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

      /**
       * \brief Set all matrix elements to given value.
@@ -681,6 +685,106 @@ class TridiagonalMatrix : 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 TridiagonalMatrix::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::TridiagonalMatrix::RowViewType.
       *
       * \par Example
       * \include Matrices/TridiagonalMatrix/TridiagonalMatrixExample_forRows.cpp
       * \par Output
       * \include TridiagonalMatrixExample_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 TridiagonalMatrix::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::TridiagonalMatrix::RowViewType.
       *
       * \par Example
       * \include Matrices/TridiagonalMatrix/TridiagonalMatrixExample_forRows.cpp
       * \par Output
       * \include TridiagonalMatrixExample_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 TridiagonalMatrix::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::TridiagonalMatrix::RowViewType.
       *
       * \par Example
       * \include Matrices/TridiagonalMatrix/TridiagonalMatrixExample_forRows.cpp
       * \par Output
       * \include TridiagonalMatrixExample_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 TridiagonalMatrix::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::TridiagonalMatrix::RowViewType.
       *
       * \par Example
       * \include Matrices/TridiagonalMatrix/TridiagonalMatrixExample_forRows.cpp
       * \par Output
       * \include TridiagonalMatrixExample_forRows.out
       */
      template< typename Function >
      void forAllRows( Function&& function ) const;

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

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

template< typename Real,
          typename Device,
          typename Index,
          ElementsOrganization Organization,
          typename RealAllocator >
   template< typename Function >
void
TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator >::
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 >
   template< typename Function >
void
TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator >::
forAllRows( Function&& function )
{
   this->getView().forAllRows( function );
}

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

template< typename Real,
          typename Device,
          typename Index,
+37 −14
Original line number Diff line number Diff line
@@ -59,6 +59,21 @@ class TridiagonalMatrixRowView
       */
      using IndexerType = Indexer;

      /**
       * \brief Type of constant container view used for storing the matrix elements values.
       */
      using ConstValuesViewType = typename ValuesViewType::ConstViewType;

      /**
       * \brief Type of constant indexer view.
       */
      using ConstIndexerViewType = typename Indexer::ConstType;

      /**
       * \brief Type of constant sparse matrix row view.
       */
      using ConstViewType = TridiagonalMatrixRowView< ConstValuesViewType, ConstIndexerViewType >;

      /**
       * \brief Constructor with all necessary data.
       *
@@ -79,6 +94,14 @@ class TridiagonalMatrixRowView
      __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.
       *
+10 −1
Original line number Diff line number Diff line
@@ -32,6 +32,15 @@ getSize() const -> IndexType
   return indexer.getRowSize( rowIdx );
}

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

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

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

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

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

      /**
       * \brief Set all matrix elements to given value.
@@ -521,6 +526,106 @@ class TridiagonalMatrixView : 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 TridiagonalMatrixView::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::TridiagonalMatrixView::RowViewType.
       *
       * \par Example
       * \include Matrices/TridiagonalMatrix/TridiagonalMatrixViewExample_forRows.cpp
       * \par Output
       * \include TridiagonalMatrixViewExample_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 TridiagonalMatrixView::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::TridiagonalMatrixView::RowViewType.
       *
       * \par Example
       * \include Matrices/TridiagonalMatrix/TridiagonalMatrixViewExample_forRows.cpp
       * \par Output
       * \include TridiagonalMatrixViewExample_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 TridiagonalMatrixView::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::TridiagonalMatrixView::RowViewType.
       *
       * \par Example
       * \include Matrices/TridiagonalMatrix/TridiagonalMatrixViewExample_forRows.cpp
       * \par Output
       * \include TridiagonalMatrixViewExample_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 TridiagonalMatrixView::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::TridiagonalMatrixView::RowViewType.
       *
       * \par Example
       * \include Matrices/TridiagonalMatrix/TridiagonalMatrixViewExample_forRows.cpp
       * \par Output
       * \include TridiagonalMatrixViewExample_forRows.out
       */
      template< typename Function >
      void forAllRows( Function&& function ) const;

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