Commit 205a15db authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Renaming diagonals shifts to offsets in MultidiagonalMatrix.

parent f02dfdd9
Loading
Loading
Loading
Loading
+23 −19
Original line number Diff line number Diff line
@@ -50,10 +50,10 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator >
      using ValuesVectorType = typename BaseType::ValuesVectorType;
      using ValuesViewType = typename ValuesVectorType::ViewType;
      using IndexerType = details::MultidiagonalMatrixIndexer< Index, Organization >;
      using DiagonalsShiftsType = Containers::Vector< Index, Device, Index, IndexAllocator >;
      using DiagonalsShiftsView = typename DiagonalsShiftsType::ViewType;
      using HostDiagonalsShiftsType = Containers::Vector< Index, Devices::Host, Index >;
      using HostDiagonalsShiftsView = typename HostDiagonalsShiftsType::ViewType;
      using DiagonalsOffsetsType = Containers::Vector< Index, Device, Index, IndexAllocator >;
      using DiagonalsOffsetsView = typename DiagonalsOffsetsType::ViewType;
      using HostDiagonalsOffsetsType = Containers::Vector< Index, Devices::Host, Index >;
      using HostDiagonalsOffsetsView = typename HostDiagonalsOffsetsType::ViewType;

      /**
       * \brief The type of matrix elements.
@@ -97,7 +97,7 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator >
      /**
       * \brief Type for accessing matrix rows.
       */
      using RowView = MultidiagonalMatrixRowView< ValuesViewType, IndexerType, DiagonalsShiftsView >;
      using RowView = MultidiagonalMatrixRowView< ValuesViewType, IndexerType, DiagonalsOffsetsView >;

      /**
       * \brief Type for accessing constant matrix rows.
@@ -139,7 +139,7 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator >
       * 
       * \param rows is number of matrix rows.
       * \param columns is number of matrix columns.
       * \param diagonalsShifts are shifts of subdiagonals from the main diagonal.
       * \param diagonalsOffsets are offsets of subdiagonals from the main diagonal.
       * 
       * \par Example
       * \include Matrices/MultidiagonalMatrix/MultidiagonalMatrixExample_Constructor.cpp
@@ -149,14 +149,14 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator >
      template< typename Vector >
      MultidiagonalMatrix( const IndexType rows,
                           const IndexType columns,
                           const Vector& diagonalsShifts );
                           const Vector& diagonalsOffsets );

      /**
       * \brief Constructor with matrix dimensions and diagonals shifts.
       * \brief Constructor with matrix dimensions and diagonals offsets.
       * 
       * \param rows is number of matrix rows.
       * \param columns is number of matrix columns.
       * \param diagonalsShifts are shifts of sub-diagonals from the main diagonal.
       * \param diagonalsOffsets are offsets of sub-diagonals from the main diagonal.
       * 
       * \par Example
       * \include Matrices/MultidiagonalMatrix/MultidiagonalMatrixExample_Constructor_init_list_1.cpp
@@ -166,18 +166,19 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator >
      template< typename ListIndex >
      MultidiagonalMatrix( const IndexType rows,
                           const IndexType columns,
                           const std::initializer_list< ListIndex > diagonalsShifts );
                           const std::initializer_list< ListIndex > diagonalsOffsets );

      /**
       * \brief Constructor with matrix dimensions, diagonals shifts and matrix elements.
       * \brief Constructor with matrix dimensions, diagonals offsets and matrix elements.
       * 
       * The number of matrix rows is given by the size of the initializer list \e data.
       * 
       * \param columns is number of matrix columns.
       * \param diagonalShifts are shifts of sub-diagonals from the main diagonal.
       * \param diagonalOffsets are offsets of sub-diagonals from the main diagonal.
       * \param data is initializer list holding matrix elements. The size of the outer list
       *    defines the number of matrix rows. Each inner list defines non-zero elements in each row
       *    and so its size must be lower or equal to the size of \e diagonalsShifts.
       *    defines the number of matrix rows. Each inner list defines values of each sub-diagonal
       *    and so its size must be lower or equal to the size of \e diagonalsOffsets. Values
       *    of sub-diagonals which do not fit to given row are omitted.
       * 
       * \par Example
       * \include Matrices/MultidiagonalMatrix/MultidiagonalMatrixExample_Constructor_init_list_2.cpp
@@ -186,7 +187,7 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator >
       */
      template< typename ListIndex, typename ListReal >
      MultidiagonalMatrix( const IndexType columns,
                           const std::initializer_list< ListIndex > diagonalsShifts,
                           const std::initializer_list< ListIndex > diagonalsOffsets,
                           const std::initializer_list< std::initializer_list< ListReal > >& data );

      /**
@@ -249,10 +250,13 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator >
       */
      virtual String getSerializationTypeVirtual() const;

      /**
       * \brief Set matrix dimensions and 
       */
      template< typename Vector >
      void setDimensions( const IndexType rows,
                          const IndexType columns,
                          const Vector& diagonalsShifts );
                          const Vector& diagonalsOffsets );

      template< typename RowLengthsVector >
      void setCompressedRowLengths( const RowLengthsVector& rowCapacities );
@@ -262,7 +266,7 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator >

      const IndexType& getDiagonalsCount() const;

      const DiagonalsShiftsType& getDiagonalsShifts() const;
      const DiagonalsOffsetsType& getDiagonalsOffsets() const;

      template< typename Vector >
      void getCompressedRowLengths( Vector& rowLengths ) const;
@@ -386,9 +390,9 @@ class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator >
      IndexType getElementIndex( const IndexType row,
                                 const IndexType localIdx ) const;

      DiagonalsShiftsType diagonalsShifts;
      DiagonalsOffsetsType diagonalsOffsets;

      HostDiagonalsShiftsType hostDiagonalsShifts;
      HostDiagonalsOffsetsType hostDiagonalsOffsets;

      IndexerType indexer;

+28 −28
Original line number Diff line number Diff line
@@ -42,10 +42,10 @@ template< typename Real,
MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::
MultidiagonalMatrix( const IndexType rows,
               const IndexType columns,
               const Vector& diagonalsShifts )
               const Vector& diagonalsOffsets )
{
   TNL_ASSERT_GT( diagonalsShifts.getSize(), 0, "Cannot construct mutltidiagonal matrix with no diagonals shifts." );
   this->setDimensions( rows, columns, diagonalsShifts );
   TNL_ASSERT_GT( diagonalsOffsets.getSize(), 0, "Cannot construct mutltidiagonal matrix with no diagonals shifts." );
   this->setDimensions( rows, columns, diagonalsOffsets );
}

template< typename Real,
@@ -58,9 +58,9 @@ template< typename Real,
MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::
MultidiagonalMatrix( const IndexType rows,
                     const IndexType columns,
                     const std::initializer_list< ListIndex > diagonalsShifts )
                     const std::initializer_list< ListIndex > diagonalsOffsets )
{
   Containers::Vector< IndexType, DeviceType, IndexType > shifts( diagonalsShifts );
   Containers::Vector< IndexType, DeviceType, IndexType > shifts( diagonalsOffsets );
   TNL_ASSERT_GT( shifts.getSize(), 0, "Cannot construct multidiagonal matrix with no diagonals shifts." );
   this->setDimensions( rows, columns, shifts );
}
@@ -74,10 +74,10 @@ template< typename Real,
   template< typename ListIndex, typename ListReal >
MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::
MultidiagonalMatrix( const IndexType columns,
                     const std::initializer_list< ListIndex > diagonalsShifts,
                     const std::initializer_list< ListIndex > diagonalsOffsets,
                     const std::initializer_list< std::initializer_list< ListReal > >& data )
{
   Containers::Vector< IndexType, DeviceType, IndexType > shifts( diagonalsShifts );
   Containers::Vector< IndexType, DeviceType, IndexType > shifts( diagonalsOffsets );
   TNL_ASSERT_GT( shifts.getSize(), 0, "Cannot construct multidiagonal matrix with no diagonals shifts." );
   this->setDimensions( data.size(), columns, shifts );
   this->setElements( data );
@@ -95,8 +95,8 @@ getView() const -> ViewType
{
   // TODO: fix when getConstView works
   return ViewType( const_cast< MultidiagonalMatrix* >( this )->values.getView(),
                    const_cast< MultidiagonalMatrix* >( this )->diagonalsShifts.getView(),
                    const_cast< MultidiagonalMatrix* >( this )->hostDiagonalsShifts.getView(),
                    const_cast< MultidiagonalMatrix* >( this )->diagonalsOffsets.getView(),
                    const_cast< MultidiagonalMatrix* >( this )->hostDiagonalsOffsets.getView(),
                    indexer );
}

@@ -153,16 +153,16 @@ void
MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::
setDimensions( const IndexType rows,
               const IndexType columns,
               const Vector& diagonalsShifts )
               const Vector& diagonalsOffsets )
{
   Matrix< Real, Device, Index >::setDimensions( rows, columns );
   this->diagonalsShifts = diagonalsShifts;
   this->hostDiagonalsShifts = diagonalsShifts;
   const IndexType minShift = min( diagonalsShifts );
   this->diagonalsOffsets = diagonalsOffsets;
   this->hostDiagonalsOffsets = diagonalsOffsets;
   const IndexType minOffset = min( diagonalsOffsets );
   IndexType nonemptyRows = min( rows, columns );
   if( rows > columns && minShift < 0 )
      nonemptyRows = min( rows, nonemptyRows - minShift );
   this->indexer.set( rows, columns, diagonalsShifts.getSize(), nonemptyRows );
   if( rows > columns && minOffset < 0 )
      nonemptyRows = min( rows, nonemptyRows - minOffset );
   this->indexer.set( rows, columns, diagonalsOffsets.getSize(), nonemptyRows );
   this->values.setSize( this->indexer.getStorageSize() );
   this->values = 0.0;
   this->view = this->getView();
@@ -224,7 +224,7 @@ setElements( const std::initializer_list< std::initializer_list< ListReal > >& d
      MultidiagonalMatrix< Real, Devices::Host, Index, Organization > hostMatrix(
         this->getRows(),
         this->getColumns(),
         this->getDiagonalsShifts() );
         this->getDiagonalsOffsets() );
      hostMatrix.setElements( data );
      *this = hostMatrix;
   }
@@ -251,9 +251,9 @@ template< typename Real,
          typename IndexAllocator >
auto
MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::
getDiagonalsShifts() const -> const DiagonalsShiftsType&
getDiagonalsOffsets() const -> const DiagonalsOffsetsType&
{
   return this->diagonalsShifts;
   return this->diagonalsOffsets;
}

template< typename Real,
@@ -320,7 +320,7 @@ void
MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::
setLike( const MultidiagonalMatrix< Real_, Device_, Index_, Organization_, RealAllocator_ >& m )
{
   this->setDimensions( m.getRows(), m.getColumns(), m.getDiagonalsShifts() );
   this->setDimensions( m.getRows(), m.getColumns(), m.getDiagonalsOffsets() );
}

template< typename Real,
@@ -744,7 +744,7 @@ operator=( const MultidiagonalMatrix< Real_, Device_, Index_, Organization_, Rea
      }
      else
      {
         const IndexType maxRowLength = this->diagonalsShifts.getSize();
         const IndexType maxRowLength = this->diagonalsOffsets.getSize();
         const IndexType bufferRowsCount( 128 );
         const size_t bufferSize = bufferRowsCount * maxRowLength;
         Containers::Vector< RHSRealType, RHSDeviceType, RHSIndexType, RHSRealAllocatorType > matrixValuesBuffer( bufferSize );
@@ -795,7 +795,7 @@ template< typename Real,
void MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::save( File& file ) const
{
   Matrix< Real, Device, Index >::save( file );
   file << diagonalsShifts;
   file << diagonalsOffsets;
}

template< typename Real,
@@ -807,13 +807,13 @@ template< typename Real,
void MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::load( File& file )
{
   Matrix< Real, Device, Index >::load( file );
   file >> this->diagonalsShifts;
   this->hostDiagonalsShifts = this->diagonalsShifts;
   const IndexType minShift = min( diagonalsShifts );
   file >> this->diagonalsOffsets;
   this->hostDiagonalsOffsets = this->diagonalsOffsets;
   const IndexType minOffset = min( diagonalsOffsets );
   IndexType nonemptyRows = min( this->getRows(), this->getColumns() );
   if( this->getRows() > this->getColumns() && minShift < 0 )
      nonemptyRows = min( this->getRows(), nonemptyRows - minShift );
   this->indexer.set( this->getRows(), this->getColumns(), diagonalsShifts.getSize(), nonemptyRows );
   if( this->getRows() > this->getColumns() && minOffset < 0 )
      nonemptyRows = min( this->getRows(), nonemptyRows - minOffset );
   this->indexer.set( this->getRows(), this->getColumns(), diagonalsOffsets.getSize(), nonemptyRows );
   this->view = this->getView();
}

+6 −6
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ namespace Matrices {

template< typename ValuesView,
          typename Indexer,
          typename DiagonalsShiftsView_ >
          typename DiagonalsOffsetsView_ >
class MultidiagonalMatrixRowView
{
   public:
@@ -24,7 +24,7 @@ class MultidiagonalMatrixRowView
      using IndexType = typename ValuesView::IndexType;
      using ValuesViewType = ValuesView;
      using IndexerType = Indexer;
      using DiagonalsShiftsView = DiagonalsShiftsView_;
      using DiagonalsOffsetsView = DiagonalsOffsetsView_;
      
      /**
       * \brief Type of constant container view used for storing the matrix elements values.
@@ -34,7 +34,7 @@ class MultidiagonalMatrixRowView
      /**
       * \brief Type of constant container view used for storing the column indexes of the matrix elements.
       */
      using ConstDiagonalsShiftsViewType = typename DiagonalsShiftsView::ConstViewType;
      using ConstDiagonalsOffsetsViewType = typename DiagonalsOffsetsView::ConstViewType;

      /**
       * \brief Type of constant indexer view.
@@ -44,11 +44,11 @@ class MultidiagonalMatrixRowView
      /**
       * \brief Type of constant sparse matrix row view.
       */
      using ConstViewType = MultidiagonalMatrixRowView< ConstValuesViewType, ConstIndexerViewType, ConstDiagonalsShiftsViewType >;
      using ConstViewType = MultidiagonalMatrixRowView< ConstValuesViewType, ConstIndexerViewType, ConstDiagonalsOffsetsViewType >;

      __cuda_callable__
      MultidiagonalMatrixRowView( const IndexType rowIdx,
                                  const DiagonalsShiftsView& diagonalsShifts,
                                  const DiagonalsOffsetsView& diagonalsOffsets,
                                  const ValuesViewType& values,
                                  const IndexerType& indexer);

@@ -71,7 +71,7 @@ class MultidiagonalMatrixRowView

      IndexType rowIdx;

      DiagonalsShiftsView diagonalsShifts;
      DiagonalsOffsetsView diagonalsOffsets;

      ValuesViewType values;

+16 −16
Original line number Diff line number Diff line
@@ -13,59 +13,59 @@
namespace TNL {
namespace Matrices {   

template< typename ValuesView, typename Indexer, typename DiagonalsShiftsView >
template< typename ValuesView, typename Indexer, typename DiagonalsOffsetsView >
__cuda_callable__
MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsShiftsView >::
MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsOffsetsView >::
MultidiagonalMatrixRowView( const IndexType rowIdx,
                            const DiagonalsShiftsView& diagonalsShifts,
                            const DiagonalsOffsetsView& diagonalsOffsets,
                            const ValuesViewType& values,
                            const IndexerType& indexer )
: rowIdx( rowIdx ), diagonalsShifts( diagonalsShifts ), values( values ), indexer( indexer )
: rowIdx( rowIdx ), diagonalsOffsets( diagonalsOffsets ), values( values ), indexer( indexer )
{
}

template< typename ValuesView, typename Indexer, typename DiagonalsShiftsView >
template< typename ValuesView, typename Indexer, typename DiagonalsOffsetsView >
__cuda_callable__
auto
MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsShiftsView >::
MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsOffsetsView >::
getSize() const -> IndexType
{
   return diagonalsShifts.getSize();//indexer.getRowSize( rowIdx );
   return diagonalsOffsets.getSize();//indexer.getRowSize( rowIdx );
}

template< typename ValuesView, typename Indexer, typename DiagonalsShiftsView >
template< typename ValuesView, typename Indexer, typename DiagonalsOffsetsView >
__cuda_callable__
auto
MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsShiftsView >::
MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsOffsetsView >::
getColumnIndex( const IndexType localIdx ) const -> const IndexType
{
   TNL_ASSERT_GE( localIdx, 0, "" );
   TNL_ASSERT_LT( localIdx, indexer.getDiagonals(), "" );
   return rowIdx + diagonalsShifts[ localIdx ];
   return rowIdx + diagonalsOffsets[ localIdx ];
}

template< typename ValuesView, typename Indexer, typename DiagonalsShiftsView >
template< typename ValuesView, typename Indexer, typename DiagonalsOffsetsView >
__cuda_callable__
auto
MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsShiftsView >::
MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsOffsetsView >::
getValue( const IndexType localIdx ) const -> const RealType&
{
   return this->values[ this->indexer.getGlobalIndex( rowIdx, localIdx ) ];
}

template< typename ValuesView, typename Indexer, typename DiagonalsShiftsView >
template< typename ValuesView, typename Indexer, typename DiagonalsOffsetsView >
__cuda_callable__
auto
MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsShiftsView >::
MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsOffsetsView >::
getValue( const IndexType localIdx ) -> RealType&
{
   return this->values[ this->indexer.getGlobalIndex( rowIdx, localIdx ) ];
}

template< typename ValuesView, typename Indexer, typename DiagonalsShiftsView >
template< typename ValuesView, typename Indexer, typename DiagonalsOffsetsView >
__cuda_callable__
void 
MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsShiftsView >::
MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsOffsetsView >::
setElement( const IndexType localIdx,
            const RealType& value )
{
+9 −9
Original line number Diff line number Diff line
@@ -30,15 +30,15 @@ class MultidiagonalMatrixView : public MatrixView< Real, Device, Index >
      using DeviceType = Device;
      using IndexType = Index;
      using BaseType = MatrixView< Real, Device, Index >;
      //using DiagonalsShiftsType = Containers::Vector< IndexType, DeviceType, IndexType >;
      using DiagonalsShiftsView = Containers::VectorView< IndexType, DeviceType, IndexType >;
      //using HostDiagonalsShiftsType = Containers::Vector< IndexType, Devices::Host, IndexType >;
      using HostDiagonalsShiftsView = Containers::VectorView< IndexType, Devices::Host, IndexType >;
      //using DiagonalsOffsetsType = Containers::Vector< IndexType, DeviceType, IndexType >;
      using DiagonalsOffsetsView = Containers::VectorView< IndexType, DeviceType, IndexType >;
      //using HostDiagonalsOffsetsType = Containers::Vector< IndexType, Devices::Host, IndexType >;
      using HostDiagonalsOffsetsView = Containers::VectorView< IndexType, Devices::Host, IndexType >;
      using IndexerType = details::MultidiagonalMatrixIndexer< IndexType, Organization >;
      using ValuesViewType = typename BaseType::ValuesView;
      using ViewType = MultidiagonalMatrixView< Real, Device, Index, Organization >;
      using ConstViewType = MultidiagonalMatrixView< typename std::add_const< Real >::type, Device, Index, Organization >;
      using RowView = MultidiagonalMatrixRowView< ValuesViewType, IndexerType, DiagonalsShiftsView >;
      using RowView = MultidiagonalMatrixRowView< ValuesViewType, IndexerType, DiagonalsOffsetsView >;

      // TODO: remove this - it is here only for compatibility with original matrix implementation
      typedef Containers::Vector< IndexType, DeviceType, IndexType > CompressedRowLengthsVector;
@@ -54,8 +54,8 @@ class MultidiagonalMatrixView : public MatrixView< Real, Device, Index >
      MultidiagonalMatrixView();

      MultidiagonalMatrixView( const ValuesViewType& values,
                               const DiagonalsShiftsView& diagonalsShifts,
                               const HostDiagonalsShiftsView& hostDiagonalsShifts,
                               const DiagonalsOffsetsView& diagonalsOffsets,
                               const HostDiagonalsOffsetsView& hostDiagonalsOffsets,
                               const IndexerType& indexer );

      ViewType getView();
@@ -174,9 +174,9 @@ class MultidiagonalMatrixView : public MatrixView< Real, Device, Index >
      IndexType getElementIndex( const IndexType row,
                                 const IndexType localIdx ) const;

      DiagonalsShiftsView diagonalsShifts;
      DiagonalsOffsetsView diagonalsOffsets;

      HostDiagonalsShiftsView hostDiagonalsShifts;
      HostDiagonalsOffsetsView hostDiagonalsOffsets;

      IndexerType indexer;
};
Loading