From c4969701619c8903bba4503310b965dac7412ffb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Oberhuber?= <oberhuber.tomas@gmail.com>
Date: Mon, 5 Apr 2021 11:58:10 +0200
Subject: [PATCH] Renaming OffsetsHolder to OffsetsContainer.

---
 src/TNL/Algorithms/Segments/BiEllpack.h       |  16 +--
 src/TNL/Algorithms/Segments/CSR.h             | 114 ++++++++++++++++--
 src/TNL/Algorithms/Segments/CSR.hpp           |   4 +-
 src/TNL/Algorithms/Segments/ChunkedEllpack.h  |  12 +-
 src/TNL/Algorithms/Segments/Ellpack.h         |   6 +-
 src/TNL/Algorithms/Segments/EllpackView.h     |   4 +-
 src/TNL/Algorithms/Segments/SlicedEllpack.h   |   6 +-
 .../Algorithms/Segments/detail/BiEllpack.h    |   6 +-
 .../Segments/detail/ChunkedEllpack.h          |   8 +-
 9 files changed, 134 insertions(+), 42 deletions(-)

diff --git a/src/TNL/Algorithms/Segments/BiEllpack.h b/src/TNL/Algorithms/Segments/BiEllpack.h
index 3cf46e0efd..48aa4e6be6 100644
--- a/src/TNL/Algorithms/Segments/BiEllpack.h
+++ b/src/TNL/Algorithms/Segments/BiEllpack.h
@@ -32,7 +32,7 @@ class BiEllpack
    public:
       using DeviceType = Device;
       using IndexType = std::remove_const_t<Index>;
-      using OffsetsHolder = Containers::Vector< IndexType, DeviceType, IndexType, IndexAllocator>;
+      using OffsetsContainer = Containers::Vector< IndexType, DeviceType, IndexType, IndexAllocator>;
       static constexpr ElementsOrganization getOrganization() { return Organization; }
       using ViewType = BiEllpackView< Device, Index, Organization, WarpSize >;
       template <typename Device_, typename Index_>
@@ -73,7 +73,7 @@ class BiEllpack
       /**
        * \brief Set sizes of particular segments.
        */
-      template <typename SizesHolder = OffsetsHolder>
+      template <typename SizesHolder = OffsetsContainer>
       void setSegmentsSizes(const SizesHolder &sizes);
 
       void reset();
@@ -138,11 +138,11 @@ class BiEllpack
       void printStructure(std::ostream &str) const;
 
       // TODO: nvcc needs this public because of lambda function used inside
-      template <typename SizesHolder = OffsetsHolder>
+      template <typename SizesHolder = OffsetsContainer>
       void performRowBubbleSort(const SizesHolder &segmentsSize);
 
       // TODO: the same as  above
-      template <typename SizesHolder = OffsetsHolder>
+      template <typename SizesHolder = OffsetsContainer>
       void computeColumnSizes(const SizesHolder &segmentsSizes);
 
    protected:
@@ -150,10 +150,10 @@ class BiEllpack
 
       static constexpr int getLogWarpSize() { return std::log2(WarpSize); };
 
-      template <typename SizesHolder = OffsetsHolder>
+      template <typename SizesHolder = OffsetsContainer>
       void verifyRowPerm(const SizesHolder &segmentsSizes);
 
-      template <typename SizesHolder = OffsetsHolder>
+      template <typename SizesHolder = OffsetsContainer>
       void verifyRowLengths(const SizesHolder &segmentsSizes);
 
       IndexType getStripLength(const IndexType stripIdx) const;
@@ -164,9 +164,9 @@ class BiEllpack
 
       IndexType virtualRows = 0;
 
-      OffsetsHolder rowPermArray;
+      OffsetsContainer rowPermArray;
 
-      OffsetsHolder groupPointers;
+      OffsetsContainer groupPointers;
 
       // TODO: Replace later
       __cuda_callable__ Index power(const IndexType number, const IndexType exponent) const
diff --git a/src/TNL/Algorithms/Segments/CSR.h b/src/TNL/Algorithms/Segments/CSR.h
index 5622a139b1..221c02b8a4 100644
--- a/src/TNL/Algorithms/Segments/CSR.h
+++ b/src/TNL/Algorithms/Segments/CSR.h
@@ -26,10 +26,16 @@ namespace TNL {
  *
  * See \ref TNL::Algorithms::Segments for more details about segments.
  *
- * \tparam Device 
- * \tparam Index 
- * \tparam CSRScalarKernel< Index, Device > 
- * \tparam Allocator< Index > 
+ * \tparam Device is type of device where the segments will be operating.
+ * \tparam Index is type for indexing of the elements managed by the segments.
+ * \tparam Kernel is type of kernel used for parallel operations with segments.
+ *    It can be any of the following:
+ *    \ref TNL::Containers::Segments::Kernels::CSRAdaptiveKernel,
+ *    \ref TNL::Containers::Segments::Kernels::CSRHybridKernel,
+ *    \ref TNL::Containers::Segments::Kernels::CSRScalarKernel,
+ *    \ref TNL::Containers::Segments::Kernels::CSRVectorKernel
+ *
+ * \tparam IndexAllocator is allocator for supporting index containers.
  */
 template< typename Device,
           typename Index,
@@ -39,31 +45,117 @@ class CSR
 {
    public:
 
+      /**
+       * \brief The device where the segments are operating.
+       */
       using DeviceType = Device;
+
+      /**
+       * \brief The type used for indexing of segments elements.
+       */
       using IndexType = std::remove_const_t< Index >;
+
+      /**
+       * \brief Type of kernel used for reduction operations.
+       */
       using KernelType = Kernel;
-      using OffsetsHolder = Containers::Vector< Index, DeviceType, IndexType, IndexAllocator >;
-      using SegmentsSizes = OffsetsHolder;
+
+      /**
+       * \brief Type of container storing offsets of particular rows.
+       */
+      using OffsetsContainer = Containers::Vector< Index, DeviceType, IndexType, IndexAllocator >;
+
+      /**
+       * \brief Templated view type.
+       *
+       * \tparam Device_ is alternative device type for the view.
+       * \tparam Index_ is alternative index type for the view.
+       */
       template< typename Device_, typename Index_ >
       using ViewTemplate = CSRView< Device_, Index_, KernelType >;
+
+      /**
+       * \brief Type of segments view.1
+       */
       using ViewType = CSRView< Device, Index, KernelType >;
+
+      /**
+       * \brief Type of constant segments view.
+       */
       using ConstViewType = CSRView< Device, std::add_const_t< IndexType >, KernelType >;
+
+      /**
+       * \brief Accessor type fro one particular segment.
+       */
       using SegmentViewType = SegmentView< IndexType, RowMajorOrder >;
 
-      static constexpr ElementsOrganization getOrganization() { return ColumnMajorOrder; }
+      /**
+       * \brief This functions says that CSR format is always organised in row-major order.
+       */
+      static constexpr ElementsOrganization getOrganization() { return RowMajorOrder; }
 
+      /**
+       * \brief This function says that CSR format does not use padding elements.
+       */
       static constexpr bool havePadding() { return false; };
 
+      /**
+       * \brief Construct with no parameters to create empty segments.
+       */
       CSR();
 
+      /**
+       * \brief Construct with segments sizes.
+       *
+       * The number of segments is given by the size of \e segmentsSizes. Particular elements
+       * of this container define sizes of particular segments.
+       *
+       * \tparam SizesContainer is a type of container for segments sizes.
+       * \param sizes is an instance of the container with the segments sizes.
+       *
+       * See the following example:
+       *
+       * \includelineno Algorithms/Segments/SegmentsExample_CSR_constructor_1.cpp
+       *
+       * The result looks as follows:
+       *
+       * \include SegmentsExample_CSR_constructor_1.out
+       */
       template< typename SizesContainer >
-      CSR( const SizesContainer& sizes );
+      CSR( const SizesContainer& segmentsSizes );
 
+      /**
+       * \brief Construct with segments sizes in initializer list..
+       *
+       * The number of segments is given by the size of \e segmentsSizes. Particular elements
+       * of this initializer list define sizes of particular segments.
+       *
+       * \tparam ListIndex is a type of indexes of the initializer list.
+       * \param sizes is an instance of the container with the segments sizes.
+       *
+       * See the following example:
+       *
+       * \includelineno Algorithms/Segments/SegmentsExample_constructor_2.cpp
+       *
+       * The result looks as follows:
+       *
+       * \include SegmentsExample_constructor_1.out
+       */
       template< typename ListIndex >
       CSR( const std::initializer_list< ListIndex >& segmentsSizes );
 
+      /**
+       * \brief Copy constructor.
+       *
+       * \param segments are the source segments.
+       */
       CSR( const CSR& segments );
 
+      /**
+       * \brief Move constructor.
+       *
+       * \param segments  are the source segments.
+       */
       CSR( const CSR&& segments );
 
       static String getSerializationType();
@@ -112,9 +204,9 @@ class CSR
       __cuda_callable__
       SegmentViewType getSegmentView( const IndexType segmentIdx ) const;
 
-      const OffsetsHolder& getOffsets() const;
+      const OffsetsContainer& getOffsets() const;
 
-      OffsetsHolder& getOffsets();
+      OffsetsContainer& getOffsets();
 
       /***
        * \brief Go over all segments and for each segment element call
@@ -154,7 +246,7 @@ class CSR
 
    protected:
 
-      OffsetsHolder offsets;
+      OffsetsContainer offsets;
 
       KernelType kernel;
 };
diff --git a/src/TNL/Algorithms/Segments/CSR.hpp b/src/TNL/Algorithms/Segments/CSR.hpp
index a3b4055c39..10bbc5847e 100644
--- a/src/TNL/Algorithms/Segments/CSR.hpp
+++ b/src/TNL/Algorithms/Segments/CSR.hpp
@@ -219,7 +219,7 @@ template< typename Device,
           typename IndexAllocator >
 auto
 CSR< Device, Index, Kernel, IndexAllocator >::
-getOffsets() const -> const OffsetsHolder&
+getOffsets() const -> const OffsetsContainer&
 {
    return this->offsets;
 }
@@ -230,7 +230,7 @@ template< typename Device,
           typename IndexAllocator >
 auto
 CSR< Device, Index, Kernel, IndexAllocator >::
-getOffsets() -> OffsetsHolder&
+getOffsets() -> OffsetsContainer&
 {
    return this->offsets;
 }
diff --git a/src/TNL/Algorithms/Segments/ChunkedEllpack.h b/src/TNL/Algorithms/Segments/ChunkedEllpack.h
index 97abb38644..d5d459a005 100644
--- a/src/TNL/Algorithms/Segments/ChunkedEllpack.h
+++ b/src/TNL/Algorithms/Segments/ChunkedEllpack.h
@@ -29,7 +29,7 @@ class ChunkedEllpack
 
       using DeviceType = Device;
       using IndexType = std::remove_const_t< Index >;
-      using OffsetsHolder = Containers::Vector< Index, DeviceType, IndexType, IndexAllocator >;
+      using OffsetsContainer = Containers::Vector< Index, DeviceType, IndexType, IndexAllocator >;
       static constexpr ElementsOrganization getOrganization() { return Organization; }
       using ViewType = ChunkedEllpackView< Device, Index, Organization >;
       template< typename Device_, typename Index_ >
@@ -72,7 +72,7 @@ class ChunkedEllpack
       /**
        * \brief Set sizes of particular segments.
        */
-      template< typename SizesHolder = OffsetsHolder >
+      template< typename SizesHolder = OffsetsContainer >
       void setSegmentsSizes( const SizesHolder& sizes );
 
       void reset();
@@ -150,19 +150,19 @@ class ChunkedEllpack
        * For each segment, this keeps index of the slice which contains the
        * segment.
        */
-      OffsetsHolder rowToSliceMapping;
+      OffsetsContainer rowToSliceMapping;
 
       /**
        * For each row, this keeps index of the first chunk within a slice.
        */
-      OffsetsHolder rowToChunkMapping;
+      OffsetsContainer rowToChunkMapping;
 
-      OffsetsHolder chunksToSegmentsMapping;
+      OffsetsContainer chunksToSegmentsMapping;
 
       /**
        * Keeps index of the first segment index.
        */
-      OffsetsHolder rowPointers;
+      OffsetsContainer rowPointers;
 
       ChunkedEllpackSliceInfoContainer slices;
 
diff --git a/src/TNL/Algorithms/Segments/Ellpack.h b/src/TNL/Algorithms/Segments/Ellpack.h
index 442a1b7c6e..e68ebdf622 100644
--- a/src/TNL/Algorithms/Segments/Ellpack.h
+++ b/src/TNL/Algorithms/Segments/Ellpack.h
@@ -31,8 +31,8 @@ class Ellpack
       using IndexType = std::remove_const_t< Index >;
       static constexpr int getAlignment() { return Alignment; }
       static constexpr ElementsOrganization getOrganization() { return Organization; }
-      using OffsetsHolder = Containers::Vector< IndexType, DeviceType, IndexType >;
-      using SegmentsSizes = OffsetsHolder;
+      using OffsetsContainer = Containers::Vector< IndexType, DeviceType, IndexType >;
+      using SegmentsSizes = OffsetsContainer;
       template< typename Device_, typename Index_ >
       using ViewTemplate = EllpackView< Device_, Index_, Organization, Alignment >;
       using ViewType = EllpackView< Device, Index, Organization, Alignment >;
@@ -66,7 +66,7 @@ class Ellpack
       /**
        * \brief Set sizes of particular segments.
        */
-      template< typename SizesHolder = OffsetsHolder >
+      template< typename SizesHolder = OffsetsContainer >
       void setSegmentsSizes( const SizesHolder& sizes );
 
       void setSegmentsSizes( const IndexType segmentsCount, const IndexType segmentSize );
diff --git a/src/TNL/Algorithms/Segments/EllpackView.h b/src/TNL/Algorithms/Segments/EllpackView.h
index aebe7b5914..865c0d8486 100644
--- a/src/TNL/Algorithms/Segments/EllpackView.h
+++ b/src/TNL/Algorithms/Segments/EllpackView.h
@@ -34,8 +34,8 @@ class EllpackView
       using IndexType = std::remove_const_t< Index >;
       static constexpr int getAlignment() { return Alignment; }
       static constexpr bool getOrganization() { return Organization; }
-      using OffsetsHolder = Containers::Vector< IndexType, DeviceType, IndexType >;
-      using SegmentsSizes = OffsetsHolder;
+      using OffsetsContainer = Containers::Vector< IndexType, DeviceType, IndexType >;
+      using SegmentsSizes = OffsetsContainer;
       template< typename Device_, typename Index_ >
       using ViewTemplate = EllpackView< Device_, Index_, Organization, Alignment >;
       using ViewType = EllpackView;
diff --git a/src/TNL/Algorithms/Segments/SlicedEllpack.h b/src/TNL/Algorithms/Segments/SlicedEllpack.h
index 69b86c100f..092af6a1f1 100644
--- a/src/TNL/Algorithms/Segments/SlicedEllpack.h
+++ b/src/TNL/Algorithms/Segments/SlicedEllpack.h
@@ -30,7 +30,7 @@ class SlicedEllpack
 
       using DeviceType = Device;
       using IndexType = std::remove_const_t< Index >;
-      using OffsetsHolder = Containers::Vector< Index, DeviceType, IndexType, IndexAllocator >;
+      using OffsetsContainer = Containers::Vector< Index, DeviceType, IndexType, IndexAllocator >;
       static constexpr int getSliceSize() { return SliceSize; }
       static constexpr ElementsOrganization getOrganization() { return Organization; }
       using ViewType = SlicedEllpackView< Device, Index, Organization, SliceSize >;
@@ -64,7 +64,7 @@ class SlicedEllpack
       /**
        * \brief Set sizes of particular segments.
        */
-      template< typename SizesHolder = OffsetsHolder >
+      template< typename SizesHolder = OffsetsContainer >
       void setSegmentsSizes( const SizesHolder& sizes );
 
       void reset();
@@ -131,7 +131,7 @@ class SlicedEllpack
 
       IndexType size, alignedSize, segmentsCount;
 
-      OffsetsHolder sliceOffsets, sliceSegmentSizes;
+      OffsetsContainer sliceOffsets, sliceSegmentSizes;
 };
 
 template <typename Device,
diff --git a/src/TNL/Algorithms/Segments/detail/BiEllpack.h b/src/TNL/Algorithms/Segments/detail/BiEllpack.h
index 5605c8fb63..43c42e43c8 100644
--- a/src/TNL/Algorithms/Segments/detail/BiEllpack.h
+++ b/src/TNL/Algorithms/Segments/detail/BiEllpack.h
@@ -31,10 +31,10 @@ class BiEllpack
       using DeviceType = Device;
       using IndexType = Index;
       static constexpr bool getOrganization() { return Organization; }
-      using OffsetsHolder = Containers::Vector< IndexType, DeviceType, IndexType >;
-      using OffsetsHolderView = typename OffsetsHolder::ViewType;
+      using OffsetsContainer = Containers::Vector< IndexType, DeviceType, IndexType >;
+      using OffsetsHolderView = typename OffsetsContainer::ViewType;
       using ConstOffsetsHolderView = typename OffsetsHolderView::ConstViewType;
-      using SegmentsSizes = OffsetsHolder;
+      using SegmentsSizes = OffsetsContainer;
       using SegmentViewType = BiEllpackSegmentView< IndexType, Organization >;
 
       static constexpr int getWarpSize() { return WarpSize; };
diff --git a/src/TNL/Algorithms/Segments/detail/ChunkedEllpack.h b/src/TNL/Algorithms/Segments/detail/ChunkedEllpack.h
index 19169b558f..3e279b02ba 100644
--- a/src/TNL/Algorithms/Segments/detail/ChunkedEllpack.h
+++ b/src/TNL/Algorithms/Segments/detail/ChunkedEllpack.h
@@ -62,10 +62,10 @@ class ChunkedEllpack
       using DeviceType = Device;
       using IndexType = Index;
       static constexpr ElementsOrganization getOrganization() { return Organization; }
-      using OffsetsHolder = Containers::Vector< IndexType, DeviceType, IndexType >;
-      using OffsetsHolderView = typename OffsetsHolder::ViewType;
-      using SegmentsSizes = OffsetsHolder;
-      using ChunkedEllpackSliceInfoType = detail::ChunkedEllpackSliceInfo< IndexType >;
+      using OffsetsContainer = Containers::Vector< IndexType, DeviceType, IndexType >;
+      using OffsetsHolderView = typename OffsetsContainer::ViewType;
+      using SegmentsSizes = OffsetsContainer;
+      using ChunkedEllpackSliceInfoType = details::ChunkedEllpackSliceInfo< IndexType >;
       using ChunkedEllpackSliceInfoAllocator = typename Allocators::Default< Device >::template Allocator< ChunkedEllpackSliceInfoType >;
       using ChunkedEllpackSliceInfoContainer = Containers::Array< ChunkedEllpackSliceInfoType, DeviceType, IndexType, ChunkedEllpackSliceInfoAllocator >;
       using ChunkedEllpackSliceInfoContainerView = typename ChunkedEllpackSliceInfoContainer::ViewType;
-- 
GitLab