Loading src/TNL/Algorithms/Segments/SegmentElement.h 0 → 100644 +57 −0 Original line number Diff line number Diff line /*************************************************************************** SegmentElement.h - description ------------------- begin : Apr 5, 2021 copyright : (C) 2021 by Tomas Oberhuber email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #pragma once #include <ostream> #include <TNL/Cuda/CudaCallable.h> namespace TNL { namespace Algorithms { namespace Segments { template< typename Index > class SegmentElement { public: using IndexType = Index; __cuda_callable__ SegmentElement( const IndexType& segmentIdx, const IndexType& localIdx, const IndexType globalIdx ) : segmentIdx( segmentIdx ), localIdx( localIdx ), globalIdx( globalIdx ) {}; __cuda_callable__ const IndexType& segmentIndex() const { return segmentIdx; }; __cuda_callable__ const IndexType& localIndex() const { return localIdx; }; __cuda_callable__ const IndexType& globalIndex() const { return globalIdx; }; protected: const IndexType& segmentIdx; const IndexType& localIdx; const IndexType globalIdx; }; } // namespace Segments } // namespace Algorithms } // namespace TNL src/TNL/Algorithms/Segments/SegmentView.h +69 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ #pragma once #include <TNL/Algorithms/Segments/ElementsOrganization.h> #include <TNL/Algorithms/Segments/SegmentViewIterator.h> namespace TNL { namespace Algorithms { Loading @@ -27,6 +28,8 @@ class SegmentView< Index, ColumnMajorOrder > using IndexType = Index; using IteratorType = SegmentViewIterator< SegmentView >; __cuda_callable__ SegmentView( const IndexType segmentIdx, const IndexType offset, Loading Loading @@ -57,6 +60,38 @@ class SegmentView< Index, ColumnMajorOrder > return this->segmentIdx; }; /** * \brief Returns iterator pointing at the beginning of the segment. * * \return iterator pointing at the beginning. */ __cuda_callable__ IteratorType begin() const { return IteratorType( *this, 0 ); }; /** * \brief Returns iterator pointing at the end of the segment. * * \return iterator pointing at the end. */ __cuda_callable__ IteratorType end() const { return IteratorType( *this, this->getSize() ); }; /** * \brief Returns constant iterator pointing at the beginning of the segment. * * \return iterator pointing at the beginning. */ __cuda_callable__ const IteratorType cbegin() const { return IteratorType( *this, 0 ); }; /** * \brief Returns constant iterator pointing at the end of the segment. * * \return iterator pointing at the end. */ __cuda_callable__ const IteratorType cend() const { return IteratorType( *this, this->getSize() ); }; protected: IndexType segmentIdx, segmentOffset, segmentSize, step; Loading @@ -69,6 +104,8 @@ class SegmentView< Index, RowMajorOrder > using IndexType = Index; using IteratorType = SegmentViewIterator< SegmentView >; __cuda_callable__ SegmentView( const IndexType segmentIdx, const IndexType offset, Loading @@ -95,6 +132,38 @@ class SegmentView< Index, RowMajorOrder > return this->segmentIdx; }; /** * \brief Returns iterator pointing at the beginning of the segment. * * \return iterator pointing at the beginning. */ __cuda_callable__ IteratorType begin() const { return IteratorType( *this, 0 ); }; /** * \brief Returns iterator pointing at the end of the segment. * * \return iterator pointing at the end. */ __cuda_callable__ IteratorType end() const { return IteratorType( *this, this->getSize() ); }; /** * \brief Returns constant iterator pointing at the beginning of the segment. * * \return iterator pointing at the beginning. */ __cuda_callable__ const IteratorType cbegin() const { return IteratorType( *this, 0 ); }; /** * \brief Returns constant iterator pointing at the end of the segment. * * \return iterator pointing at the end. */ __cuda_callable__ const IteratorType cend() const { return IteratorType( *this, this->getSize() ); }; protected: IndexType segmentIdx, segmentOffset, segmentSize; Loading src/TNL/Algorithms/Segments/SegmentViewIterator.h 0 → 100644 +84 −0 Original line number Diff line number Diff line /*************************************************************************** SegmentViewIterator.h - description ------------------- begin : Apr 5, 2021 copyright : (C) 2021 by Tomas Oberhuber email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #pragma once #include <ostream> #include <TNL/Cuda/CudaCallable.h> #include <TNL/Algorithms/Segments/SegmentElement.h> namespace TNL { namespace Algorithms { namespace Segments { template< typename SegmentView > class SegmentViewIterator { public: /** * \brief Type of SegmentView */ using SegmentViewType = SegmentView; /** * \brief The type used for matrix elements indexing. */ using IndexType = typename SegmentViewType::IndexType; /** * \brief The type of related matrix element. */ using SegmentElementType = SegmentElement< IndexType >; __cuda_callable__ SegmentViewIterator( const SegmentViewType& segmentView, const IndexType& localIdx ); /** * \brief Comparison of two matrix Segment iterators. * * \param other is another matrix Segment iterator. * \return \e true if both iterators points at the same point of the same matrix, \e false otherwise. */ __cuda_callable__ bool operator==( const SegmentViewIterator& other ) const; /** * \brief Comparison of two matrix Segment iterators. * * \param other is another matrix Segment iterator. * \return \e false if both iterators points at the same point of the same matrix, \e true otherwise. */ __cuda_callable__ bool operator!=( const SegmentViewIterator& other ) const; __cuda_callable__ SegmentViewIterator& operator++(); __cuda_callable__ SegmentViewIterator& operator--(); __cuda_callable__ const SegmentElementType operator*() const; protected: const SegmentViewType& segmentView; IndexType localIdx = 0; }; } // namespace Segments } // namespace Algorithms } // namespace TNL #include <TNL/Algorithms/Segments/SegmentViewIterator.hpp> src/TNL/Algorithms/Segments/SegmentViewIterator.hpp 0 → 100644 +83 −0 Original line number Diff line number Diff line /*************************************************************************** SegmentViewIterator.hpp - description ------------------- begin : Apr 5, 2021 copyright : (C) 2021 by Tomas Oberhuber email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #pragma once #include <TNL/Algorithms/Segments/SegmentView.h> #include <TNL/Assert.h> namespace TNL { namespace Algorithms { namespace Segments { template< typename SegmentView > __cuda_callable__ SegmentViewIterator< SegmentView >:: SegmentViewIterator( const SegmentViewType& segmentView, const IndexType& localIdx ) : segmentView( segmentView ), localIdx( localIdx ) { } template< typename SegmentView > __cuda_callable__ bool SegmentViewIterator< SegmentView >:: operator==( const SegmentViewIterator& other ) const { if( &this->segmentView == &other.segmentView && localIdx == other.localIdx ) return true; return false; } template< typename SegmentView > __cuda_callable__ bool SegmentViewIterator< SegmentView >:: operator!=( const SegmentViewIterator& other ) const { return ! ( other == *this ); } template< typename SegmentView > __cuda_callable__ SegmentViewIterator< SegmentView >& SegmentViewIterator< SegmentView >:: operator++() { if( localIdx < segmentView.getSize() ) localIdx ++; return *this; } template< typename SegmentView > __cuda_callable__ SegmentViewIterator< SegmentView >& SegmentViewIterator< SegmentView >:: operator--() { if( localIdx > 0 ) localIdx --; return *this; } template< typename SegmentView > __cuda_callable__ auto SegmentViewIterator< SegmentView >:: operator*() const -> const SegmentElementType { return SegmentElementType( this->segmentView.getSegmentIndex(), this->localIdx, this->segmentView.getGlobalIndex( this->localIdx ) ); } } // namespace Segments } // namespace Algorithms } // namespace TNL src/TNL/Matrices/MatrixRowViewIterator.hpp +1 −1 Original line number Diff line number Diff line /*************************************************************************** SparseMatrixRowView.hpp - description MatrixRowViewIterator.hpp - description ------------------- begin : Mar 20, 2021 copyright : (C) 2021 by Tomas Oberhuber Loading Loading
src/TNL/Algorithms/Segments/SegmentElement.h 0 → 100644 +57 −0 Original line number Diff line number Diff line /*************************************************************************** SegmentElement.h - description ------------------- begin : Apr 5, 2021 copyright : (C) 2021 by Tomas Oberhuber email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #pragma once #include <ostream> #include <TNL/Cuda/CudaCallable.h> namespace TNL { namespace Algorithms { namespace Segments { template< typename Index > class SegmentElement { public: using IndexType = Index; __cuda_callable__ SegmentElement( const IndexType& segmentIdx, const IndexType& localIdx, const IndexType globalIdx ) : segmentIdx( segmentIdx ), localIdx( localIdx ), globalIdx( globalIdx ) {}; __cuda_callable__ const IndexType& segmentIndex() const { return segmentIdx; }; __cuda_callable__ const IndexType& localIndex() const { return localIdx; }; __cuda_callable__ const IndexType& globalIndex() const { return globalIdx; }; protected: const IndexType& segmentIdx; const IndexType& localIdx; const IndexType globalIdx; }; } // namespace Segments } // namespace Algorithms } // namespace TNL
src/TNL/Algorithms/Segments/SegmentView.h +69 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ #pragma once #include <TNL/Algorithms/Segments/ElementsOrganization.h> #include <TNL/Algorithms/Segments/SegmentViewIterator.h> namespace TNL { namespace Algorithms { Loading @@ -27,6 +28,8 @@ class SegmentView< Index, ColumnMajorOrder > using IndexType = Index; using IteratorType = SegmentViewIterator< SegmentView >; __cuda_callable__ SegmentView( const IndexType segmentIdx, const IndexType offset, Loading Loading @@ -57,6 +60,38 @@ class SegmentView< Index, ColumnMajorOrder > return this->segmentIdx; }; /** * \brief Returns iterator pointing at the beginning of the segment. * * \return iterator pointing at the beginning. */ __cuda_callable__ IteratorType begin() const { return IteratorType( *this, 0 ); }; /** * \brief Returns iterator pointing at the end of the segment. * * \return iterator pointing at the end. */ __cuda_callable__ IteratorType end() const { return IteratorType( *this, this->getSize() ); }; /** * \brief Returns constant iterator pointing at the beginning of the segment. * * \return iterator pointing at the beginning. */ __cuda_callable__ const IteratorType cbegin() const { return IteratorType( *this, 0 ); }; /** * \brief Returns constant iterator pointing at the end of the segment. * * \return iterator pointing at the end. */ __cuda_callable__ const IteratorType cend() const { return IteratorType( *this, this->getSize() ); }; protected: IndexType segmentIdx, segmentOffset, segmentSize, step; Loading @@ -69,6 +104,8 @@ class SegmentView< Index, RowMajorOrder > using IndexType = Index; using IteratorType = SegmentViewIterator< SegmentView >; __cuda_callable__ SegmentView( const IndexType segmentIdx, const IndexType offset, Loading @@ -95,6 +132,38 @@ class SegmentView< Index, RowMajorOrder > return this->segmentIdx; }; /** * \brief Returns iterator pointing at the beginning of the segment. * * \return iterator pointing at the beginning. */ __cuda_callable__ IteratorType begin() const { return IteratorType( *this, 0 ); }; /** * \brief Returns iterator pointing at the end of the segment. * * \return iterator pointing at the end. */ __cuda_callable__ IteratorType end() const { return IteratorType( *this, this->getSize() ); }; /** * \brief Returns constant iterator pointing at the beginning of the segment. * * \return iterator pointing at the beginning. */ __cuda_callable__ const IteratorType cbegin() const { return IteratorType( *this, 0 ); }; /** * \brief Returns constant iterator pointing at the end of the segment. * * \return iterator pointing at the end. */ __cuda_callable__ const IteratorType cend() const { return IteratorType( *this, this->getSize() ); }; protected: IndexType segmentIdx, segmentOffset, segmentSize; Loading
src/TNL/Algorithms/Segments/SegmentViewIterator.h 0 → 100644 +84 −0 Original line number Diff line number Diff line /*************************************************************************** SegmentViewIterator.h - description ------------------- begin : Apr 5, 2021 copyright : (C) 2021 by Tomas Oberhuber email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #pragma once #include <ostream> #include <TNL/Cuda/CudaCallable.h> #include <TNL/Algorithms/Segments/SegmentElement.h> namespace TNL { namespace Algorithms { namespace Segments { template< typename SegmentView > class SegmentViewIterator { public: /** * \brief Type of SegmentView */ using SegmentViewType = SegmentView; /** * \brief The type used for matrix elements indexing. */ using IndexType = typename SegmentViewType::IndexType; /** * \brief The type of related matrix element. */ using SegmentElementType = SegmentElement< IndexType >; __cuda_callable__ SegmentViewIterator( const SegmentViewType& segmentView, const IndexType& localIdx ); /** * \brief Comparison of two matrix Segment iterators. * * \param other is another matrix Segment iterator. * \return \e true if both iterators points at the same point of the same matrix, \e false otherwise. */ __cuda_callable__ bool operator==( const SegmentViewIterator& other ) const; /** * \brief Comparison of two matrix Segment iterators. * * \param other is another matrix Segment iterator. * \return \e false if both iterators points at the same point of the same matrix, \e true otherwise. */ __cuda_callable__ bool operator!=( const SegmentViewIterator& other ) const; __cuda_callable__ SegmentViewIterator& operator++(); __cuda_callable__ SegmentViewIterator& operator--(); __cuda_callable__ const SegmentElementType operator*() const; protected: const SegmentViewType& segmentView; IndexType localIdx = 0; }; } // namespace Segments } // namespace Algorithms } // namespace TNL #include <TNL/Algorithms/Segments/SegmentViewIterator.hpp>
src/TNL/Algorithms/Segments/SegmentViewIterator.hpp 0 → 100644 +83 −0 Original line number Diff line number Diff line /*************************************************************************** SegmentViewIterator.hpp - description ------------------- begin : Apr 5, 2021 copyright : (C) 2021 by Tomas Oberhuber email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #pragma once #include <TNL/Algorithms/Segments/SegmentView.h> #include <TNL/Assert.h> namespace TNL { namespace Algorithms { namespace Segments { template< typename SegmentView > __cuda_callable__ SegmentViewIterator< SegmentView >:: SegmentViewIterator( const SegmentViewType& segmentView, const IndexType& localIdx ) : segmentView( segmentView ), localIdx( localIdx ) { } template< typename SegmentView > __cuda_callable__ bool SegmentViewIterator< SegmentView >:: operator==( const SegmentViewIterator& other ) const { if( &this->segmentView == &other.segmentView && localIdx == other.localIdx ) return true; return false; } template< typename SegmentView > __cuda_callable__ bool SegmentViewIterator< SegmentView >:: operator!=( const SegmentViewIterator& other ) const { return ! ( other == *this ); } template< typename SegmentView > __cuda_callable__ SegmentViewIterator< SegmentView >& SegmentViewIterator< SegmentView >:: operator++() { if( localIdx < segmentView.getSize() ) localIdx ++; return *this; } template< typename SegmentView > __cuda_callable__ SegmentViewIterator< SegmentView >& SegmentViewIterator< SegmentView >:: operator--() { if( localIdx > 0 ) localIdx --; return *this; } template< typename SegmentView > __cuda_callable__ auto SegmentViewIterator< SegmentView >:: operator*() const -> const SegmentElementType { return SegmentElementType( this->segmentView.getSegmentIndex(), this->localIdx, this->segmentView.getGlobalIndex( this->localIdx ) ); } } // namespace Segments } // namespace Algorithms } // namespace TNL
src/TNL/Matrices/MatrixRowViewIterator.hpp +1 −1 Original line number Diff line number Diff line /*************************************************************************** SparseMatrixRowView.hpp - description MatrixRowViewIterator.hpp - description ------------------- begin : Mar 20, 2021 copyright : (C) 2021 by Tomas Oberhuber Loading