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

Writting documentation on MultidiagonalMatrix.

parent 60958e9a
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@ template< typename Matrix >
struct MatrixInfo
{};

/// This is to prevent from appearing in Doxygen documentation.
/// \cond HIDDEN_CLASS
template< typename Real,
          typename Device,
          typename Index,
@@ -151,5 +153,6 @@ struct MatrixInfo< Legacy::SlicedEllpack< Real, Device, Index, SliceSize> >
   static String getFormat() { return "SlicedEllpack Legacy"; };
};

/// \endcond
} //namespace Matrices
} //namespace TNL
+3 −0
Original line number Diff line number Diff line
@@ -17,9 +17,12 @@
namespace TNL {
namespace Matrices {

/// This is to prevent from appearing in Doxygen documentation.
/// \cond HIDDEN_CLASS
template< typename Device >
class MatrixReaderDeviceDependentCode
{};
/// \endcond

template< typename Matrix >
class MatrixReader
+3 −0
Original line number Diff line number Diff line
@@ -357,6 +357,8 @@ void MatrixReader< Matrix >::parseMtxLineWithElement( const String& line,
   value = ( RealType ) atof( parsedLine[ 2 ].getString() );
}

/// This is to prevent from appearing in Doxygen documentation.
/// \cond HIDDEN_CLASS
template<>
class MatrixReaderDeviceDependentCode< Devices::Host >
{
@@ -392,6 +394,7 @@ class MatrixReaderDeviceDependentCode< Devices::Cuda >
      MatrixReader< Matrix >::readMtxFileHostMatrix( file, matrix, rowLengths, verbose, symReader );
   }
};
/// \endcond

} // namespace Matrices
} // namespace TNL
+194 −40
Original line number Diff line number Diff line
@@ -20,62 +20,214 @@
namespace TNL {
namespace Matrices {

/**
 * \brief Implementation of sparse multi-diagonal matrix.
 * 
 * Use this matrix type for storing of matrices where the offsets of non-zero elements
 * from the diagonal are the same in each row. Typically such matrices arise from
 * discretization of partial differential equations on regular numerical grids.
 * 
 * \tparam Real is a type of matrix elements.
 * \tparam Device is a device where the matrix is allocated.
 * \tparam Index is a type for indexing of the matrix elements.
 * \tparam Organization tells the ordering of matrix elements. It is either RowMajorOrder
 *         or ColumnMajorOrder.
 * \tparam RealAllocator is allocator for the matrix elements.
 * \tparam IndexAllocator is allocator for the matrix elements offsets.
 */
template< typename Real = double,
          typename Device = Devices::Host,
          typename Index = int,
          ElementsOrganization Organization = Containers::Segments::DefaultElementsOrganization< Device >::getOrganization(),
          typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >,
          typename IndexAllocator = typename Allocators::Default< Device >::template Allocator< Index > >
class Multidiagonal : public Matrix< Real, Device, Index, RealAllocator >
class MultidiagonalMatrix : public Matrix< Real, Device, Index, RealAllocator >
{
   public:

      // Supporting types - they are not important for the user
      using BaseType = 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;

      /**
       * \brief The type of matrix elements.
       */
      using RealType = Real;

      /**
       * \brief The device where the matrix is allocated.
       */
      using DeviceType = Device;

      /**
       * \brief The type used for matrix elements indexing.
       */
      using IndexType = Index;

      /**
       * \brief The allocator for matrix elements values.
       */
      using RealAllocatorType = RealAllocator;

      /**
       * \brief The allocator for matrix elements offsets from the diagonal.
       */
      using IndexAllocatorType = IndexAllocator;
      using BaseType = Matrix< Real, Device, Index, RealAllocator >;
      using ValuesVectorType = typename BaseType::ValuesVectorType;
      using ValuesViewType = typename ValuesVectorType::ViewType;
      using IndexerType = details::MultidiagonalMatrixIndexer< IndexType, Organization >;
      using DiagonalsShiftsType = Containers::Vector< IndexType, DeviceType, IndexType, IndexAllocatorType >;
      using DiagonalsShiftsView = typename DiagonalsShiftsType::ViewType;
      using RowView = MultidiagonalMatrixRowView< ValuesViewType, IndexerType, DiagonalsShiftsView >;

      /**
       * \brief Type of related matrix view. 
       * 
       * See \ref MultidiagonalMatrixView.
       */
      using ViewType = MultidiagonalMatrixView< Real, Device, Index, Organization >;
      using ConstViewType = MultidiagonalMatrixView< typename std::add_const< Real >::type, Device, Index, Organization >;

      using HostDiagonalsShiftsType = Containers::Vector< IndexType, Devices::Host, IndexType >;
      using HostDiagonalsShiftsView = typename HostDiagonalsShiftsType::ViewType;
      /**
       * \brief Matrix view type for constant instances.
       * 
       * See \ref MutlidiagonlMatrixView.
       */
      using ConstViewType = MultidiagonalMatrixView< typename std::add_const< Real >::type, Device, Index, Organization >;

      /**
       * \brief Type for accessing matrix rows.
       */
      using RowView = MultidiagonalMatrixRowView< ValuesViewType, IndexerType, DiagonalsShiftsView >;

      // TODO: remove this - it is here only for compatibility with original matrix implementation
      typedef Containers::Vector< IndexType, DeviceType, IndexType > CompressedRowLengthsVector;
      typedef Containers::VectorView< IndexType, DeviceType, IndexType > CompressedRowLengthsVectorView;
      typedef typename CompressedRowLengthsVectorView::ConstViewType ConstCompressedRowLengthsVectorView;
      /**
       * \brief Type for accessing constant matrix rows.
       */
      using ConstRowView = typename RowView::ConstViewType;

      /**
       * \brief Helper type for getting self type or its modifications.
       */
      template< typename _Real = Real,
                typename _Device = Device,
                typename _Index = Index >
      using Self = Multidiagonal< _Real, _Device, _Index >;

                typename _Index = Index,
                ElementsOrganization _Organization = Organization,
                typename _RealAllocator = RealAllocator,
                typename _IndexAllocator = IndexAllocator >
      using Self = MultidiagonalMatrix< _Real, _Device, _Index, _Organization, _RealAllocator, _IndexAllocator >;

      /**
       * \brief Elements organization getter.
       */
      static constexpr ElementsOrganization getOrganization() { return Organization; };

      Multidiagonal();

      Multidiagonal( const IndexType rows,
      /**
       * \brief Constructor with no parameters.
       */
      MultidiagonalMatrix();

      /**
       * \brief Constructor with matrix dimensions.
       * 
       * \param rows is number of matrix rows.
       * \param columns is number of matrix columns.
       */
      MultidiagonalMatrix( const IndexType rows,
                           const IndexType columns );

      /**
       * \brief Constructor with matrix dimensions and matrix elements offsets.
       * 
       * \param rows is number of matrix rows.
       * \param columns is number of matrix columns.
       * \param diagonalsShifts are shifts of subdiagonals from the main diagonal.
       * 
       * \par Example
       * \include Matrices/MultidiagonalMatrix/MultidiagonalMatrixExample_Constructor.cpp
       * \par Output
       * \include MultidiagonalMatrixExample_Constructor.out
       * 
       */
      template< typename Vector >
      Multidiagonal( const IndexType rows,
      MultidiagonalMatrix( const IndexType rows,
                           const IndexType columns,
                           const Vector& diagonalsShifts );

      /**
       * \brief Constructor with matrix dimensions and diagonals shifts.
       * 
       * \param rows
       * \param columns
       * \param diagonalsShifts
       */
      template< typename ListIndex >
      MultidiagonalMatrix( const IndexType rows,
                           const IndexType columns,
                           const std::initializer_list< ListIndex > diagonalsShifts );

      template< typename ListIndex, typename ListReal >
      MultidiagonalMatrix( const IndexType columns,
                           const std::initializer_list< ListIndex > diagonalsShifts,
                           const std::initializer_list< std::initializer_list< ListReal > >& data )
      

      /**
       * \brief Copy constructor.
       * 
       * \param matrix is an input matrix.
       */
      MultidiagonalMatrix( const MultidiagonalMatrix& matrix ) = default;

      /**
       * \brief Move constructor.
       * 
       * \param matrix is an input matrix.
       */
      MultidiagonalMatrix( MultidiagonalMatrix&& matrix ) = default;

      /**
       * \brief Returns a modifiable view of the mutlidiagonal matrix.
       * 
       * See \ref MultidiagonalMatrixView.
       * 
       * \return multidiagonal matrix view.
       */
      ViewType getView() const; // TODO: remove const

      //ConstViewType getConstView() const;

      /**
       * \brief Returns a non-modifiable view of the multidiagonal matrix.
       * 
       * See \ref MultidiagonalMatrixView.
       * 
       * \return multidiagonal matrix view.
       */
      ConstViewType getConstView() const;

      /**
       * \brief Returns string with serialization type.
       * 
       * The string has a form `Matrices::MultidiagonalMatrix< RealType,  [any_device], IndexType, ElementsOrganization, [any_allocator], [any_allocator] >`.
       * 
       * \return \ref String with the serialization type.
       * 
       * \par Example
       * \include Matrices/SparseMatrix/SparseMatrixExample_getSerializationType.cpp
       * \par Output
       * \include SparseMatrixExample_getSerializationType.out
       */
      static String getSerializationType();

      /**
       * \brief Returns string with serialization type.
       * 
       * See \ref SparseMatrix::getSerializationType.
       * 
       * \return \e String with the serialization type.
       * 
       * \par Example
       * \include Matrices/SparseMatrix/SparseMatrixExample_getSerializationType.cpp
       * \par Output
       * \include SparseMatrixExample_getSerializationType.out
       */
      virtual String getSerializationTypeVirtual() const;

      template< typename Vector >
@@ -83,8 +235,10 @@ class Multidiagonal : public Matrix< Real, Device, Index, RealAllocator >
                          const IndexType columns,
                          const Vector& diagonalsShifts );

      //template< typename Vector >
      void setCompressedRowLengths( const ConstCompressedRowLengthsVectorView rowCapacities );
      template< typename RowLengthsVector >
      void setCompressedRowLengths( const RowLengthsVector& rowCapacities );

      void setElements( const std::initializer_list< std::initializer_list< ListReal > >& data )

      const IndexType& getDiagonalsCount() const;

@@ -101,17 +255,17 @@ class Multidiagonal : public Matrix< Real, Device, Index, RealAllocator >
      IndexType getMaxRowLength() const;

      template< typename Real_, typename Device_, typename Index_, ElementsOrganization Organization_, typename RealAllocator_ >
      void setLike( const Multidiagonal< Real_, Device_, Index_, Organization_, RealAllocator_ >& m );
      void setLike( const MultidiagonalMatrix< Real_, Device_, Index_, Organization_, RealAllocator_ >& m );

      IndexType getNumberOfNonzeroMatrixElements() const;

      void reset();

      template< typename Real_, typename Device_, typename Index_, ElementsOrganization Organization_, typename RealAllocator_ >
      bool operator == ( const Multidiagonal< Real_, Device_, Index_, Organization_, RealAllocator_ >& matrix ) const;
      bool operator == ( const MultidiagonalMatrix< Real_, Device_, Index_, Organization_, RealAllocator_ >& matrix ) const;

      template< typename Real_, typename Device_, typename Index_, ElementsOrganization Organization_, typename RealAllocator_ >
      bool operator != ( const Multidiagonal< Real_, Device_, Index_, Organization_, RealAllocator_ >& matrix ) const;
      bool operator != ( const MultidiagonalMatrix< Real_, Device_, Index_, Organization_, RealAllocator_ >& matrix ) const;

      __cuda_callable__
      RowView getRow( const IndexType& rowIdx );
@@ -162,12 +316,12 @@ class Multidiagonal : public Matrix< Real, Device, Index, RealAllocator >
                          OutVector& outVector ) const;

      template< typename Real_, typename Device_, typename Index_, ElementsOrganization Organization_, typename RealAllocator_ >
      void addMatrix( const Multidiagonal< Real_, Device_, Index_, Organization_, RealAllocator_ >& matrix,
      void addMatrix( const MultidiagonalMatrix< Real_, Device_, Index_, Organization_, RealAllocator_ >& matrix,
                      const RealType& matrixMultiplicator = 1.0,
                      const RealType& thisMatrixMultiplicator = 1.0 );

      template< typename Real2, typename Index2 >
      void getTransposition( const Multidiagonal< Real2, Device, Index2 >& matrix,
      void getTransposition( const MultidiagonalMatrix< Real2, Device, Index2 >& matrix,
                             const RealType& matrixMultiplicator = 1.0 );

      template< typename Vector1, typename Vector2 >
@@ -178,7 +332,7 @@ class Multidiagonal : public Matrix< Real, Device, Index, RealAllocator >
                                const RealType& omega = 1.0 ) const;

      // copy assignment
      Multidiagonal& operator=( const Multidiagonal& matrix );
      MultidiagonalMatrix& operator=( const MultidiagonalMatrix& matrix );

      // cross-device copy assignment
      template< typename Real_,
@@ -187,7 +341,7 @@ class Multidiagonal : public Matrix< Real, Device, Index, RealAllocator >
                ElementsOrganization Organization_,
                typename RealAllocator_,
                typename IndexAllocator_ >
      Multidiagonal& operator=( const Multidiagonal< Real_, Device_, Index_, Organization_, RealAllocator_, IndexAllocator_ >& matrix );
      MultidiagonalMatrix& operator=( const MultidiagonalMatrix< Real_, Device_, Index_, Organization_, RealAllocator_, IndexAllocator_ >& matrix );

      void save( File& file ) const;

@@ -224,4 +378,4 @@ class Multidiagonal : public Matrix< Real, Device, Index, RealAllocator >
} // namespace Matrices
} // namespace TNL

#include <TNL/Matrices/Multidiagonal.hpp>
#include <TNL/Matrices/MultidiagonalMatrix.hpp>
+93 −75

File changed and moved.

Preview size limit exceeded, changes collapsed.

Loading