Loading src/TNL/Matrices/MatrixType.h +36 −0 Original line number Diff line number Diff line Loading @@ -13,15 +13,51 @@ namespace TNL { namespace Matrices { template< bool Symmetric, bool Binary > struct MatrixType { static constexpr bool isSymmetric() { return Symmetric; } static constexpr bool isBinary() { return Binary; } }; struct GeneralMatrix { static constexpr bool isSymmetric() { return false; } static constexpr bool isBinary() { return false; } }; struct SymmetricMatrix { static constexpr bool isSymmetric() { return true; } static constexpr bool isBinary() { return false; } }; struct BinaryMatrix { static constexpr bool isSymmetric() { return false; } static constexpr bool isBinary() { return true; } }; struct BinarySymmetricMatrix { static constexpr bool isSymmetric() { return false; } static constexpr bool isBinary() { return true; } }; struct SymmetricBinaryMatrix { static constexpr bool isSymmetric() { return false; } static constexpr bool isBinary() { return true; } }; } //namespace Matrices } //namespace TNL No newline at end of file src/TNL/Matrices/SparseMatrix.h +1 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ class SparseMatrix : public Matrix< Real, Device, Index, RealAllocator > { public: static constexpr bool isSymmetric() { return MatrixType::isSymmetric(); }; static constexpr bool isBinary() { return std::is_same< Real, bool >::value; }; static constexpr bool isBinary() { return MatrixType::isBinary(); }; using RealType = Real; template< typename Device_, typename Index_, typename IndexAllocator_ > Loading src/TNL/Matrices/SparseMatrixRowView.hpp +2 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,7 @@ SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView, isBinary_ >:: getValue( const IndexType localIdx ) const -> const RealType& { TNL_ASSERT_LT( localIdx, this->getSize(), "Local index exceeds matrix row capacity." ); TNL_ASSERT_FALSE( isBinary(), "Cannot call this method for binary matrix row." ); return values[ segmentView.getGlobalIndex( localIdx ) ]; } Loading @@ -84,6 +85,7 @@ SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView, isBinary_ >:: getValue( const IndexType localIdx ) -> RealType& { TNL_ASSERT_LT( localIdx, this->getSize(), "Local index exceeds matrix row capacity." ); TNL_ASSERT_FALSE( isBinary(), "Cannot call this method for binary matrix row." ); return values[ segmentView.getGlobalIndex( localIdx ) ]; } Loading src/TNL/Matrices/SparseMatrixView.h +1 −1 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ class SparseMatrixView : public MatrixView< Real, Device, Index > { public: static constexpr bool isSymmetric() { return MatrixType::isSymmetric(); }; static constexpr bool isBinary() { return std::is_same< Real, bool >::value; }; static constexpr bool isBinary() { return MatrixType::isBinary(); }; using RealType = Real; template< typename Device_, typename Index_ > Loading src/TNL/Matrices/SparseMatrixView.hpp +34 −8 Original line number Diff line number Diff line Loading @@ -227,6 +227,7 @@ addElement( const IndexType row, col = this->columnIndexes.getElement( globalIdx ); if( col == column ) { if( ! isBinary() ) this->values.setElement( globalIdx, thisElementMultiplicator * this->values.getElement( globalIdx ) + value ); return; } Loading @@ -242,6 +243,7 @@ addElement( const IndexType row, if( col == this->getPaddingIndex() ) { this->columnIndexes.setElement( globalIdx, column ); if( ! isBinary() ) this->values.setElement( globalIdx, value ); return; } Loading @@ -255,6 +257,7 @@ addElement( const IndexType row, TNL_ASSERT_LT( globalIdx1, this->columnIndexes.getSize(), "" ); TNL_ASSERT_LT( globalIdx2, this->columnIndexes.getSize(), "" ); this->columnIndexes.setElement( globalIdx1, this->columnIndexes.getElement( globalIdx2 ) ); if( ! isBinary() ) this->values.setElement( globalIdx1, this->values.getElement( globalIdx2 ) ); j--; } Loading Loading @@ -287,8 +290,13 @@ getElement( const IndexType row, TNL_ASSERT_LT( globalIdx, this->columnIndexes.getSize(), "" ); const IndexType col = this->columnIndexes.getElement( globalIdx ); if( col == column ) { if( isBinary() ) return 1; else return this->values.getElement( globalIdx ); } } return 0.0; } Loading Loading @@ -334,6 +342,8 @@ vectorProduct( const InVector& inVector, compute = ( column != paddingIndex ); if( ! compute ) return 0.0; if( isBinary() ) return inVectorView[ column ]; return valuesView[ globalIdx ] * inVectorView[ column ]; }; auto reduction = [] __cuda_callable__ ( RealType& sum, const RealType& value ) { Loading Loading @@ -382,7 +392,12 @@ rowsReduction( IndexType first, IndexType last, Fetch& fetch, Reduce& reduce, Ke auto fetch_ = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType globalIdx, bool& compute ) mutable -> decltype( fetch( IndexType(), IndexType(), IndexType(), RealType() ) ) { IndexType columnIdx = columns_view[ globalIdx ]; if( columnIdx != paddingIndex_ ) { if( isBinary() ) return fetch( rowIdx, columnIdx, globalIdx, 1 ); else return fetch( rowIdx, columnIdx, globalIdx, values_view[ globalIdx ] ); } return zero; }; this->segments.segmentsReduction( first, last, fetch_, reduce, keep, zero ); Loading Loading @@ -415,6 +430,9 @@ forRows( IndexType first, IndexType last, Function& function ) const const auto values_view = this->values.getConstView(); const IndexType paddingIndex_ = this->getPaddingIndex(); auto f = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType globalIdx, bool& compute ) mutable -> bool { if( isBinary() ) function( rowIdx, localIdx, columns_view[ globalIdx ], 1, compute ); else function( rowIdx, localIdx, columns_view[ globalIdx ], values_view[ globalIdx ], compute ); return true; }; Loading @@ -435,6 +453,9 @@ forRows( IndexType first, IndexType last, Function& function ) auto values_view = this->values.getView(); const IndexType paddingIndex_ = this->getPaddingIndex(); auto f = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType globalIdx, bool& compute ) mutable { if( isBinary() ) function( rowIdx, localIdx, columns_view[ globalIdx ], 1, compute ); else function( rowIdx, localIdx, columns_view[ globalIdx ], values_view[ globalIdx ], compute ); }; this->segments.forSegments( first, last, f ); Loading Loading @@ -573,7 +594,12 @@ print( std::ostream& str ) const const IndexType column = this->columnIndexes.getElement( globalIdx ); if( column == this->getPaddingIndex() ) break; str << " Col:" << column << "->" << this->values.getElement( globalIdx ) << "\t"; RealType value; if( isBinary() ) value = 1.0; else value = this->values.getElement( globalIdx ); str << " Col:" << column << "->" << value << "\t"; } str << std::endl; } Loading Loading
src/TNL/Matrices/MatrixType.h +36 −0 Original line number Diff line number Diff line Loading @@ -13,15 +13,51 @@ namespace TNL { namespace Matrices { template< bool Symmetric, bool Binary > struct MatrixType { static constexpr bool isSymmetric() { return Symmetric; } static constexpr bool isBinary() { return Binary; } }; struct GeneralMatrix { static constexpr bool isSymmetric() { return false; } static constexpr bool isBinary() { return false; } }; struct SymmetricMatrix { static constexpr bool isSymmetric() { return true; } static constexpr bool isBinary() { return false; } }; struct BinaryMatrix { static constexpr bool isSymmetric() { return false; } static constexpr bool isBinary() { return true; } }; struct BinarySymmetricMatrix { static constexpr bool isSymmetric() { return false; } static constexpr bool isBinary() { return true; } }; struct SymmetricBinaryMatrix { static constexpr bool isSymmetric() { return false; } static constexpr bool isBinary() { return true; } }; } //namespace Matrices } //namespace TNL No newline at end of file
src/TNL/Matrices/SparseMatrix.h +1 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ class SparseMatrix : public Matrix< Real, Device, Index, RealAllocator > { public: static constexpr bool isSymmetric() { return MatrixType::isSymmetric(); }; static constexpr bool isBinary() { return std::is_same< Real, bool >::value; }; static constexpr bool isBinary() { return MatrixType::isBinary(); }; using RealType = Real; template< typename Device_, typename Index_, typename IndexAllocator_ > Loading
src/TNL/Matrices/SparseMatrixRowView.hpp +2 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,7 @@ SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView, isBinary_ >:: getValue( const IndexType localIdx ) const -> const RealType& { TNL_ASSERT_LT( localIdx, this->getSize(), "Local index exceeds matrix row capacity." ); TNL_ASSERT_FALSE( isBinary(), "Cannot call this method for binary matrix row." ); return values[ segmentView.getGlobalIndex( localIdx ) ]; } Loading @@ -84,6 +85,7 @@ SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView, isBinary_ >:: getValue( const IndexType localIdx ) -> RealType& { TNL_ASSERT_LT( localIdx, this->getSize(), "Local index exceeds matrix row capacity." ); TNL_ASSERT_FALSE( isBinary(), "Cannot call this method for binary matrix row." ); return values[ segmentView.getGlobalIndex( localIdx ) ]; } Loading
src/TNL/Matrices/SparseMatrixView.h +1 −1 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ class SparseMatrixView : public MatrixView< Real, Device, Index > { public: static constexpr bool isSymmetric() { return MatrixType::isSymmetric(); }; static constexpr bool isBinary() { return std::is_same< Real, bool >::value; }; static constexpr bool isBinary() { return MatrixType::isBinary(); }; using RealType = Real; template< typename Device_, typename Index_ > Loading
src/TNL/Matrices/SparseMatrixView.hpp +34 −8 Original line number Diff line number Diff line Loading @@ -227,6 +227,7 @@ addElement( const IndexType row, col = this->columnIndexes.getElement( globalIdx ); if( col == column ) { if( ! isBinary() ) this->values.setElement( globalIdx, thisElementMultiplicator * this->values.getElement( globalIdx ) + value ); return; } Loading @@ -242,6 +243,7 @@ addElement( const IndexType row, if( col == this->getPaddingIndex() ) { this->columnIndexes.setElement( globalIdx, column ); if( ! isBinary() ) this->values.setElement( globalIdx, value ); return; } Loading @@ -255,6 +257,7 @@ addElement( const IndexType row, TNL_ASSERT_LT( globalIdx1, this->columnIndexes.getSize(), "" ); TNL_ASSERT_LT( globalIdx2, this->columnIndexes.getSize(), "" ); this->columnIndexes.setElement( globalIdx1, this->columnIndexes.getElement( globalIdx2 ) ); if( ! isBinary() ) this->values.setElement( globalIdx1, this->values.getElement( globalIdx2 ) ); j--; } Loading Loading @@ -287,8 +290,13 @@ getElement( const IndexType row, TNL_ASSERT_LT( globalIdx, this->columnIndexes.getSize(), "" ); const IndexType col = this->columnIndexes.getElement( globalIdx ); if( col == column ) { if( isBinary() ) return 1; else return this->values.getElement( globalIdx ); } } return 0.0; } Loading Loading @@ -334,6 +342,8 @@ vectorProduct( const InVector& inVector, compute = ( column != paddingIndex ); if( ! compute ) return 0.0; if( isBinary() ) return inVectorView[ column ]; return valuesView[ globalIdx ] * inVectorView[ column ]; }; auto reduction = [] __cuda_callable__ ( RealType& sum, const RealType& value ) { Loading Loading @@ -382,7 +392,12 @@ rowsReduction( IndexType first, IndexType last, Fetch& fetch, Reduce& reduce, Ke auto fetch_ = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType globalIdx, bool& compute ) mutable -> decltype( fetch( IndexType(), IndexType(), IndexType(), RealType() ) ) { IndexType columnIdx = columns_view[ globalIdx ]; if( columnIdx != paddingIndex_ ) { if( isBinary() ) return fetch( rowIdx, columnIdx, globalIdx, 1 ); else return fetch( rowIdx, columnIdx, globalIdx, values_view[ globalIdx ] ); } return zero; }; this->segments.segmentsReduction( first, last, fetch_, reduce, keep, zero ); Loading Loading @@ -415,6 +430,9 @@ forRows( IndexType first, IndexType last, Function& function ) const const auto values_view = this->values.getConstView(); const IndexType paddingIndex_ = this->getPaddingIndex(); auto f = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType globalIdx, bool& compute ) mutable -> bool { if( isBinary() ) function( rowIdx, localIdx, columns_view[ globalIdx ], 1, compute ); else function( rowIdx, localIdx, columns_view[ globalIdx ], values_view[ globalIdx ], compute ); return true; }; Loading @@ -435,6 +453,9 @@ forRows( IndexType first, IndexType last, Function& function ) auto values_view = this->values.getView(); const IndexType paddingIndex_ = this->getPaddingIndex(); auto f = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType globalIdx, bool& compute ) mutable { if( isBinary() ) function( rowIdx, localIdx, columns_view[ globalIdx ], 1, compute ); else function( rowIdx, localIdx, columns_view[ globalIdx ], values_view[ globalIdx ], compute ); }; this->segments.forSegments( first, last, f ); Loading Loading @@ -573,7 +594,12 @@ print( std::ostream& str ) const const IndexType column = this->columnIndexes.getElement( globalIdx ); if( column == this->getPaddingIndex() ) break; str << " Col:" << column << "->" << this->values.getElement( globalIdx ) << "\t"; RealType value; if( isBinary() ) value = 1.0; else value = this->values.getElement( globalIdx ); str << " Col:" << column << "->" << value << "\t"; } str << std::endl; } Loading