From 64c2d435eeacb92fb39066e0273d7d66082f26cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Oberhuber?= <oberhuber.tomas@gmail.com>
Date: Thu, 23 Jan 2020 21:32:56 +0100
Subject: [PATCH] Fixed sparse matrix assignment.

---
 src/TNL/Containers/Segments/CSR.hpp           |  1 +
 src/TNL/Containers/Segments/CSRView.h         |  2 ++
 src/TNL/Containers/Segments/CSRView.hpp       |  6 ++--
 src/TNL/Containers/Segments/Ellpack.hpp       |  3 +-
 src/TNL/Containers/Segments/EllpackView.h     |  6 ++--
 src/TNL/Containers/Segments/EllpackView.hpp   |  9 +++--
 src/TNL/Containers/Segments/SlicedEllpack.hpp |  1 +
 .../Containers/Segments/SlicedEllpackView.h   |  2 ++
 .../Containers/Segments/SlicedEllpackView.hpp |  3 ++
 src/TNL/Matrices/Dense.hpp                    |  1 -
 src/TNL/Matrices/DenseMatrixView.hpp          |  1 +
 src/TNL/Matrices/MatrixView.hpp               |  1 +
 src/TNL/Matrices/Multidiagonal.h              |  2 ++
 src/TNL/Matrices/Multidiagonal.hpp            |  3 +-
 src/TNL/Matrices/MultidiagonalMatrixView.h    |  2 ++
 src/TNL/Matrices/MultidiagonalMatrixView.hpp  |  1 +
 src/TNL/Matrices/SparseMatrix.h               |  2 +-
 src/TNL/Matrices/SparseMatrix.hpp             | 34 ++++++++++---------
 src/TNL/Matrices/SparseMatrixView.hpp         |  3 +-
 src/TNL/Matrices/Tridiagonal.h                |  2 ++
 src/TNL/Matrices/Tridiagonal.hpp              |  1 +
 .../Containers/Segments/SegmentsTest.hpp      |  5 ---
 src/UnitTests/Matrices/SparseMatrixCopyTest.h |  5 +++
 23 files changed, 62 insertions(+), 34 deletions(-)

diff --git a/src/TNL/Containers/Segments/CSR.hpp b/src/TNL/Containers/Segments/CSR.hpp
index 9a05d84f75..55dcba74c9 100644
--- a/src/TNL/Containers/Segments/CSR.hpp
+++ b/src/TNL/Containers/Segments/CSR.hpp
@@ -253,6 +253,7 @@ CSR< Device, Index, IndexAllocator >::
 operator=( const CSR< Device_, Index_, IndexAllocator_ >& source )
 {
    this->offsets = source.offsets;
+   return *this;
 }
 
 template< typename Device,
diff --git a/src/TNL/Containers/Segments/CSRView.h b/src/TNL/Containers/Segments/CSRView.h
index 2ad849f976..759fe8ff7f 100644
--- a/src/TNL/Containers/Segments/CSRView.h
+++ b/src/TNL/Containers/Segments/CSRView.h
@@ -52,8 +52,10 @@ class CSRView
 
       static String getSerializationType();
 
+      __cuda_callable__
       ViewType getView();
 
+      __cuda_callable__
       ConstViewType getConstView() const;
 
       /**
diff --git a/src/TNL/Containers/Segments/CSRView.hpp b/src/TNL/Containers/Segments/CSRView.hpp
index d6ec55b6af..043e06e04e 100644
--- a/src/TNL/Containers/Segments/CSRView.hpp
+++ b/src/TNL/Containers/Segments/CSRView.hpp
@@ -66,6 +66,7 @@ getSerializationType()
 
 template< typename Device,
           typename Index >
+__cuda_callable__
 typename CSRView< Device, Index >::ViewType
 CSRView< Device, Index >::
 getView()
@@ -75,6 +76,7 @@ getView()
 
 template< typename Device,
           typename Index >
+__cuda_callable__
 typename CSRView< Device, Index >::ConstViewType
 CSRView< Device, Index >::
 getConstView() const
@@ -156,7 +158,6 @@ auto
 CSRView< Device, Index >::
 getSegmentView( const IndexType segmentIdx ) const -> SegmentViewType
 {
-   printf( "----> segmentIdx %d offset %d size %d ptr %p \n",  segmentIdx, offsets[ segmentIdx ], offsets.getSize(), offsets.getData() );
    return SegmentViewType( offsets[ segmentIdx ], offsets[ segmentIdx + 1 ] - offsets[ segmentIdx ], 1 );
 }
 
@@ -167,7 +168,7 @@ void
 CSRView< Device, Index >::
 forSegments( IndexType first, IndexType last, Function& f, Args... args ) const
 {
-   const auto offsetsView = this->offsets.getConstView();
+   const auto offsetsView = this->offsets;
    auto l = [=] __cuda_callable__ ( const IndexType segmentIdx, Args... args ) mutable {
       const IndexType begin = offsetsView[ segmentIdx ];
       const IndexType end = offsetsView[ segmentIdx + 1 ];
@@ -228,6 +229,7 @@ CSRView< Device, Index >::
 operator=( const CSRView& view )
 {
    this->offsets.copy( view.offsets );
+   return *this;
 }
 
 template< typename Device,
diff --git a/src/TNL/Containers/Segments/Ellpack.hpp b/src/TNL/Containers/Segments/Ellpack.hpp
index 8763c2e5dc..663a65bc80 100644
--- a/src/TNL/Containers/Segments/Ellpack.hpp
+++ b/src/TNL/Containers/Segments/Ellpack.hpp
@@ -293,7 +293,7 @@ void
 Ellpack< Device, Index, IndexAllocator, RowMajorOrder, Alignment >::
 forAll( Function& f, Args... args ) const
 {
-   this->forSegments( 0, this->getSize(), f, args... );
+   this->forSegments( 0, this->getSegmentsCount(), f, args... );
 }
 
 template< typename Device,
@@ -364,6 +364,7 @@ operator=( const Ellpack< Device_, Index_, IndexAllocator_, RowMajorOrder_, Alig
    this->segmentSize = source.segmentSize;
    this->size = source.size;
    this->alignedSize = roundUpDivision( size, this->getAlignment() ) * this->getAlignment();
+   return *this;
 }
 
 template< typename Device,
diff --git a/src/TNL/Containers/Segments/EllpackView.h b/src/TNL/Containers/Segments/EllpackView.h
index f64b04068e..3870f08028 100644
--- a/src/TNL/Containers/Segments/EllpackView.h
+++ b/src/TNL/Containers/Segments/EllpackView.h
@@ -37,7 +37,7 @@ class EllpackView
       template< typename Device_, typename Index_ >
       using ViewTemplate = EllpackView< Device_, Index_ >;
       using ViewType = EllpackView;
-      //using ConstViewType = EllpackView< Device, std::add_const_t< Index > >;
+      using ConstViewType = EllpackView< Device, std::add_const_t< Index > >;
       using SegmentViewType = SegmentView< IndexType, RowMajorOrder >;
 
       __cuda_callable__
@@ -54,9 +54,11 @@ class EllpackView
 
       static String getSerializationType();
 
+      __cuda_callable__
       ViewType getView();
 
-      //ConstViewType getConstView() const;
+      __cuda_callable__
+      ConstViewType getConstView() const;
 
       /**
        * \brief Number segments.
diff --git a/src/TNL/Containers/Segments/EllpackView.hpp b/src/TNL/Containers/Segments/EllpackView.hpp
index c0d0b37215..ea2dc0d216 100644
--- a/src/TNL/Containers/Segments/EllpackView.hpp
+++ b/src/TNL/Containers/Segments/EllpackView.hpp
@@ -78,6 +78,7 @@ template< typename Device,
           typename Index,
           bool RowMajorOrder,
           int Alignment >
+__cuda_callable__
 typename EllpackView< Device, Index, RowMajorOrder, Alignment >::ViewType
 EllpackView< Device, Index, RowMajorOrder, Alignment >::
 getView()
@@ -85,16 +86,17 @@ getView()
    return ViewType( segmentSize, size, alignedSize );
 }
 
-/*template< typename Device,
+template< typename Device,
           typename Index,
           bool RowMajorOrder,
           int Alignment >
+__cuda_callable__
 typename EllpackView< Device, Index, RowMajorOrder, Alignment >::ConstViewType
 EllpackView< Device, Index, RowMajorOrder, Alignment >::
 getConstView() const
 {
    return ConstViewType( segmentSize, size, alignedSize );
-}*/
+}
 
 template< typename Device,
           typename Index,
@@ -233,7 +235,7 @@ void
 EllpackView< Device, Index, RowMajorOrder, Alignment >::
 forAll( Function& f, Args... args ) const
 {
-   this->forSegments( 0, this->getSize(), f, args... );
+   this->forSegments( 0, this->getSegmentsCount(), f, args... );
 }
 
 template< typename Device,
@@ -302,6 +304,7 @@ operator=( const EllpackView< Device, Index, RowMajorOrder, Alignment >& view )
    this->segmentSize = view.segmentSize;
    this->size = view.size;
    this->alignedSize = view.alignedSize;
+   return *this;
 }
 
 template< typename Device,
diff --git a/src/TNL/Containers/Segments/SlicedEllpack.hpp b/src/TNL/Containers/Segments/SlicedEllpack.hpp
index 62e2ca7d58..3d3a6d8c3d 100644
--- a/src/TNL/Containers/Segments/SlicedEllpack.hpp
+++ b/src/TNL/Containers/Segments/SlicedEllpack.hpp
@@ -408,6 +408,7 @@ operator=( const SlicedEllpack< Device_, Index_, IndexAllocator_, RowMajorOrder_
    this->segmentsCount = source.segmentsCount;
    this->sliceOffsets = source.sliceOffsets;
    this->sliceSegmentSizes = source.sliceSegmentSizes;
+   return *this;
 }
 
 template< typename Device,
diff --git a/src/TNL/Containers/Segments/SlicedEllpackView.h b/src/TNL/Containers/Segments/SlicedEllpackView.h
index c8c73c3f26..2b310a805a 100644
--- a/src/TNL/Containers/Segments/SlicedEllpackView.h
+++ b/src/TNL/Containers/Segments/SlicedEllpackView.h
@@ -56,8 +56,10 @@ class SlicedEllpackView
 
       static String getSerializationType();
 
+      __cuda_callable__
       ViewType getView();
 
+      __cuda_callable__
       ConstViewType getConstView() const;
 
       __cuda_callable__
diff --git a/src/TNL/Containers/Segments/SlicedEllpackView.hpp b/src/TNL/Containers/Segments/SlicedEllpackView.hpp
index 98a3d9b814..3e3c8c09c2 100644
--- a/src/TNL/Containers/Segments/SlicedEllpackView.hpp
+++ b/src/TNL/Containers/Segments/SlicedEllpackView.hpp
@@ -89,6 +89,7 @@ template< typename Device,
           typename Index,
           bool RowMajorOrder,
           int SliceSize >
+__cuda_callable__
 typename SlicedEllpackView< Device, Index, RowMajorOrder, SliceSize >::ViewType
 SlicedEllpackView< Device, Index, RowMajorOrder, SliceSize >::
 getView()
@@ -100,6 +101,7 @@ template< typename Device,
           typename Index,
           bool RowMajorOrder,
           int SliceSize >
+__cuda_callable__
 typename SlicedEllpackView< Device, Index, RowMajorOrder, SliceSize >::ConstViewType
 SlicedEllpackView< Device, Index, RowMajorOrder, SliceSize >::
 getConstView() const
@@ -357,6 +359,7 @@ operator=( const SlicedEllpackView< Device, Index, RowMajorOrder, SliceSize >& v
    this->segmentsCount = view.segmentsCount;
    this->sliceOffsets.copy( view.sliceOffsets );
    this->sliceSegmentSizes.copy( view.sliceSegmentSizes );
+   return *this;
 }
 
 template< typename Device,
diff --git a/src/TNL/Matrices/Dense.hpp b/src/TNL/Matrices/Dense.hpp
index e1acfee67e..91a98e7f95 100644
--- a/src/TNL/Matrices/Dense.hpp
+++ b/src/TNL/Matrices/Dense.hpp
@@ -925,7 +925,6 @@ operator=( const Dense< RHSReal, RHSDevice, RHSIndex, RHSRowMajorOrder, RHSRealA
    auto this_view = this->view;
    if( std::is_same< DeviceType, RHSDeviceType >::value )
    {
-      const auto segments_view = this->segments.getView();
       auto f = [=] __cuda_callable__ ( RHSIndexType rowIdx, RHSIndexType localIdx, RHSIndexType columnIdx, const RHSRealType& value, bool& compute ) mutable {
          this_view( rowIdx, columnIdx ) = value;
       };
diff --git a/src/TNL/Matrices/DenseMatrixView.hpp b/src/TNL/Matrices/DenseMatrixView.hpp
index 890606436c..a11ff263cd 100644
--- a/src/TNL/Matrices/DenseMatrixView.hpp
+++ b/src/TNL/Matrices/DenseMatrixView.hpp
@@ -901,6 +901,7 @@ operator=( const DenseMatrixView& matrix )
 {
    MatrixView< Real, Device, Index >::operator=( matrix );
    this->segments = matrix.segments;
+   return *this;
 }
 
 template< typename Real,
diff --git a/src/TNL/Matrices/MatrixView.hpp b/src/TNL/Matrices/MatrixView.hpp
index 275a228704..360478d055 100644
--- a/src/TNL/Matrices/MatrixView.hpp
+++ b/src/TNL/Matrices/MatrixView.hpp
@@ -131,6 +131,7 @@ operator=( const MatrixView& view )
    rows = view.rows;
    columns = view.columns;
    values.copy( view.values );
+   return *this;
 }
 
 template< typename Real,
diff --git a/src/TNL/Matrices/Multidiagonal.h b/src/TNL/Matrices/Multidiagonal.h
index 927e524491..749ddfae7f 100644
--- a/src/TNL/Matrices/Multidiagonal.h
+++ b/src/TNL/Matrices/Multidiagonal.h
@@ -113,8 +113,10 @@ class Multidiagonal : public Matrix< Real, Device, Index, RealAllocator >
       template< typename Real_, typename Device_, typename Index_, bool RowMajorOrder_, typename RealAllocator_ >
       bool operator != ( const Multidiagonal< Real_, Device_, Index_, RowMajorOrder_, RealAllocator_ >& matrix ) const;
 
+      __cuda_callable__
       RowView getRow( const IndexType& rowIdx );
 
+      __cuda_callable__
       const RowView getRow( const IndexType& rowIdx ) const;
 
       void setValue( const RealType& v );
diff --git a/src/TNL/Matrices/Multidiagonal.hpp b/src/TNL/Matrices/Multidiagonal.hpp
index 5d83004f29..659d6d4ebe 100644
--- a/src/TNL/Matrices/Multidiagonal.hpp
+++ b/src/TNL/Matrices/Multidiagonal.hpp
@@ -683,9 +683,7 @@ operator=( const Multidiagonal< Real_, Device_, Index_, RowMajorOrder_, RealAllo
          Containers::Vector< RealType, DeviceType, IndexType, RealAllocatorType > thisValuesBuffer( bufferSize );
          Containers::Vector< IndexType, DeviceType, IndexType, IndexAllocatorType > thisColumnsBuffer( bufferSize );
          auto matrixValuesBuffer_view = matrixValuesBuffer.getView();
-         auto matrixColumnsBuffer_view = matrixColumnsBuffer.getView();
          auto thisValuesBuffer_view = thisValuesBuffer.getView();
-         auto thisColumnsBuffer_view = thisColumnsBuffer.getView();
 
          IndexType baseRow( 0 );
          const IndexType rowsCount = this->getRows();
@@ -716,6 +714,7 @@ operator=( const Multidiagonal< Real_, Device_, Index_, RowMajorOrder_, RealAllo
          }
       }
    }
+   return *this;
 }
 
 template< typename Real,
diff --git a/src/TNL/Matrices/MultidiagonalMatrixView.h b/src/TNL/Matrices/MultidiagonalMatrixView.h
index f623a3ca66..97ff94f85c 100644
--- a/src/TNL/Matrices/MultidiagonalMatrixView.h
+++ b/src/TNL/Matrices/MultidiagonalMatrixView.h
@@ -87,8 +87,10 @@ class MultidiagonalMatrixView : public MatrixView< Real, Device, Index >
       template< typename Real_, typename Device_, typename Index_, bool RowMajorOrder_ >
       bool operator != ( const MultidiagonalMatrixView< Real_, Device_, Index_, RowMajorOrder_ >& matrix ) const;
 
+      __cuda_callable__
       RowView getRow( const IndexType& rowIdx );
 
+      __cuda_callable__
       const RowView getRow( const IndexType& rowIdx ) const;
 
       void setValue( const RealType& v );
diff --git a/src/TNL/Matrices/MultidiagonalMatrixView.hpp b/src/TNL/Matrices/MultidiagonalMatrixView.hpp
index f35c6d713f..33010cebc8 100644
--- a/src/TNL/Matrices/MultidiagonalMatrixView.hpp
+++ b/src/TNL/Matrices/MultidiagonalMatrixView.hpp
@@ -338,6 +338,7 @@ operator=( const MultidiagonalMatrixView& view )
    this->diagonalsShifts.copy( view.diagonalsShifts );
    this->hostDiagonalsShifts.copy( view.hostDiagonalsShifts );
    this->indexer = view.indexer;
+   return *this;
 }
 
 template< typename Real,
diff --git a/src/TNL/Matrices/SparseMatrix.h b/src/TNL/Matrices/SparseMatrix.h
index 26d5d2d840..9f91ee7d18 100644
--- a/src/TNL/Matrices/SparseMatrix.h
+++ b/src/TNL/Matrices/SparseMatrix.h
@@ -93,7 +93,7 @@ class SparseMatrix : public Matrix< Real, Device, Index, RealAllocator >
       void getCompressedRowLengths( Vector& rowLengths ) const;
 
       [[deprecated]]
-      virtual IndexType getRowLength( const IndexType row ) const {};
+      virtual IndexType getRowLength( const IndexType row ) const { return 0;};
 
       template< typename Matrix >
       void setLike( const Matrix& matrix );
diff --git a/src/TNL/Matrices/SparseMatrix.hpp b/src/TNL/Matrices/SparseMatrix.hpp
index 447d8d2509..cf4472922b 100644
--- a/src/TNL/Matrices/SparseMatrix.hpp
+++ b/src/TNL/Matrices/SparseMatrix.hpp
@@ -210,7 +210,7 @@ Index
 SparseMatrix< Real, Device, Index, MatrixType, Segments, RealAllocator, IndexAllocator >::
 getNumberOfNonzeroMatrixElements() const
 {
-   this->view.getNumberOfNonzeroMatrixElements();
+   return this->view.getNumberOfNonzeroMatrixElements();
 }
 
 template< typename Real,
@@ -602,7 +602,6 @@ operator=( const Dense< Real_, Device_, Index_, RowMajorOrder, RealAllocator_ >&
       Containers::Vector< IndexType, DeviceType, IndexType, IndexAllocatorType > thisColumnsBuffer( bufferSize );
       auto matrixValuesBuffer_view = matrixValuesBuffer.getView();
       auto thisValuesBuffer_view = thisValuesBuffer.getView();
-      auto thisColumnsBuffer_view = thisColumnsBuffer.getView();
 
       IndexType baseRow( 0 );
       const IndexType rowsCount = this->getRows();
@@ -689,11 +688,10 @@ operator=( const RHSMatrix& matrix )
    auto rowLocalIndexes_view = rowLocalIndexes.getView();
    columns_view = paddingIndex;
 
-   if( std::is_same< DeviceType, RHSDeviceType >::value )
+   /*if( std::is_same< DeviceType, RHSDeviceType >::value )
    {
       const auto segments_view = this->segments.getView();
       auto f = [=] __cuda_callable__ ( RHSIndexType rowIdx, RHSIndexType localIdx_, RHSIndexType columnIndex, const RHSRealType& value, bool& compute ) mutable {
-         RealType inValue( 0.0 );
          IndexType localIdx( rowLocalIndexes_view[ rowIdx ] );
          if( value != 0.0 && columnIndex != paddingIndex )
          {
@@ -705,7 +703,7 @@ operator=( const RHSMatrix& matrix )
       };
       matrix.forAllRows( f );
    }
-   else
+   else*/
    {
       const IndexType maxRowLength = max( rowLengths );
       const IndexType bufferRowsCount( 128 );
@@ -714,10 +712,13 @@ operator=( const RHSMatrix& matrix )
       Containers::Vector< RHSIndexType, RHSDeviceType, RHSIndexType > matrixColumnsBuffer( bufferSize );
       Containers::Vector< RealType, DeviceType, IndexType, RealAllocatorType > thisValuesBuffer( bufferSize );
       Containers::Vector< IndexType, DeviceType, IndexType > thisColumnsBuffer( bufferSize );
+      Containers::Vector< IndexType, DeviceType, IndexType > thisRowLengths;
+      thisRowLengths = rowLengths;
       auto matrixValuesBuffer_view = matrixValuesBuffer.getView();
       auto matrixColumnsBuffer_view = matrixColumnsBuffer.getView();
       auto thisValuesBuffer_view = thisValuesBuffer.getView();
       auto thisColumnsBuffer_view = thisColumnsBuffer.getView();
+      matrixValuesBuffer_view = 0.0;
 
       IndexType baseRow( 0 );
       const IndexType rowsCount = this->getRows();
@@ -735,6 +736,7 @@ operator=( const RHSMatrix& matrix )
                const IndexType bufferIdx = ( rowIdx - baseRow ) * maxRowLength + localIdx;
                matrixColumnsBuffer_view[ bufferIdx ] = columnIndex;
                matrixValuesBuffer_view[ bufferIdx ] = value;
+               //std::cerr << " <<<<< rowIdx = " << rowIdx << " localIdx = " << localIdx << " value = " << value << " bufferIdx = " << bufferIdx << std::endl;
             }
          };
          matrix.forRows( baseRow, lastRow, f1 );
@@ -748,20 +750,20 @@ operator=( const RHSMatrix& matrix )
          // Copy matrix elements from the buffer to the matrix and ignoring
          // zero matrix elements
          const IndexType matrix_columns = this->getColumns();
-         auto matrix_view = matrix.getView();
-         auto f2 = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx_, IndexType& columnIndex, RealType& value, bool& compute ) mutable {
+         const auto thisRowLengths_view = thisRowLengths.getConstView();
+         auto f2 = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType& columnIndex, RealType& value, bool& compute ) mutable {
             RealType inValue( 0.0 );
-            IndexType bufferIdx, localIdx( rowLocalIndexes_view[ rowIdx ] );
-            auto matrixRow = matrix_view.getRow( rowIdx );
-            IndexType s = matrixRow.getSize();
-            //printf( " row %d size %d \n", rowIdx, s );
-            while( inValue == 0.0 && localIdx < 0 )
+            size_t bufferIdx;
+            IndexType bufferLocalIdx( rowLocalIndexes_view[ rowIdx ] );
+            while( inValue == 0.0 && localIdx < thisRowLengths_view[ rowIdx ] )
             {
-               bufferIdx = ( rowIdx - baseRow ) * maxRowLength + localIdx++;
+               bufferIdx = ( rowIdx - baseRow ) * maxRowLength + bufferLocalIdx++;
                TNL_ASSERT_LT( bufferIdx, bufferSize, "" );
-               //inValue = thisValuesBuffer_view[ bufferIdx ];
+               inValue = thisValuesBuffer_view[ bufferIdx ];
             }
-            /*rowLocalIndexes_view[ rowIdx ] = localIdx;
+            //std::cerr << "rowIdx = " << rowIdx << " localIdx = " << localIdx << " bufferLocalIdx = " << bufferLocalIdx 
+            //          << " inValue = " << inValue << " bufferIdx = " << bufferIdx << std::endl;
+            rowLocalIndexes_view[ rowIdx ] = bufferLocalIdx;
             if( inValue == 0.0 )
             {
                columnIndex = paddingIndex;
@@ -771,7 +773,7 @@ operator=( const RHSMatrix& matrix )
             {
                columnIndex = thisColumnsBuffer_view[ bufferIdx ];//column - 1;
                value = inValue;
-            }*/
+            }
          };
          this->forRows( baseRow, lastRow, f2 );
          baseRow += bufferRowsCount;
diff --git a/src/TNL/Matrices/SparseMatrixView.hpp b/src/TNL/Matrices/SparseMatrixView.hpp
index 965a51b8b6..4ac0a29b80 100644
--- a/src/TNL/Matrices/SparseMatrixView.hpp
+++ b/src/TNL/Matrices/SparseMatrixView.hpp
@@ -139,7 +139,7 @@ Index
 SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView >::
 getRowLength( const IndexType row ) const
 {
-
+   return 0;
 }
 
 template< typename Real,
@@ -525,6 +525,7 @@ operator=( const SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView
    MatrixView< Real, Device, Index >::operator=( matrix );
    this->columnIndexes.copy( matrix.columnIndexes );
    this->segments = matrix.segments;
+   return *this;
 }
 
 template< typename Real,
diff --git a/src/TNL/Matrices/Tridiagonal.h b/src/TNL/Matrices/Tridiagonal.h
index 3f89023106..6f0c6a548e 100644
--- a/src/TNL/Matrices/Tridiagonal.h
+++ b/src/TNL/Matrices/Tridiagonal.h
@@ -91,8 +91,10 @@ class Tridiagonal : public Matrix< Real, Device, Index, RealAllocator >
       template< typename Real_, typename Device_, typename Index_, bool RowMajorOrder_, typename RealAllocator_ >
       bool operator != ( const Tridiagonal< Real_, Device_, Index_, RowMajorOrder_, RealAllocator_ >& matrix ) const;
 
+      __cuda_callable__
       RowView getRow( const IndexType& rowIdx );
 
+      __cuda_callable__
       const RowView getRow( const IndexType& rowIdx ) const;
 
       void setValue( const RealType& v );
diff --git a/src/TNL/Matrices/Tridiagonal.hpp b/src/TNL/Matrices/Tridiagonal.hpp
index d99715a47c..2ccdc4838f 100644
--- a/src/TNL/Matrices/Tridiagonal.hpp
+++ b/src/TNL/Matrices/Tridiagonal.hpp
@@ -592,6 +592,7 @@ operator=( const Tridiagonal< Real_, Device_, Index_, RowMajorOrder_, RealAlloca
          this->forAllRows( f );
       }
    }
+   return *this;
 }
 
 template< typename Real,
diff --git a/src/UnitTests/Containers/Segments/SegmentsTest.hpp b/src/UnitTests/Containers/Segments/SegmentsTest.hpp
index 590b39881f..6d4692dbe7 100644
--- a/src/UnitTests/Containers/Segments/SegmentsTest.hpp
+++ b/src/UnitTests/Containers/Segments/SegmentsTest.hpp
@@ -127,17 +127,12 @@ void test_AllReduction_MaximumInSegments()
 
    TNL::Containers::Vector< IndexType, DeviceType, IndexType > v( segments.getStorageSize() );
 
-   /*IndexType k( 1 );
-   for( IndexType i = 0; i < segmentsCount; i++ )
-      for( IndexType j = 0; j < segmentSize; j++ )
-         v.setElement( segments.getGlobalIndex( i, j ), k++ );*/
    auto view = v.getView();
    auto init = [=] __cuda_callable__ ( const IndexType segmentIdx, const IndexType localIdx, const IndexType globalIdx ) mutable -> bool {
       view[ globalIdx ] =  segmentIdx * 5 + localIdx + 1;
       return true;
    };
    segments.forAll( init );
-   std::cerr << v << std::endl;
 
    TNL::Containers::Vector< IndexType, DeviceType, IndexType >result( segmentsCount );
 
diff --git a/src/UnitTests/Matrices/SparseMatrixCopyTest.h b/src/UnitTests/Matrices/SparseMatrixCopyTest.h
index 46777f6c00..053f1e9fb5 100644
--- a/src/UnitTests/Matrices/SparseMatrixCopyTest.h
+++ b/src/UnitTests/Matrices/SparseMatrixCopyTest.h
@@ -458,6 +458,7 @@ void tridiagonalMatrixAssignment()
    RowCapacitiesType rowCapacities;
    matrix.getCompressedRowLengths( rowCapacities );
    RowCapacitiesType exactRowLengths{ 1, 3, 3, 3, 3, 3, 3, 3, 3, 2 };
+
    EXPECT_EQ( rowCapacities, exactRowLengths );
    for( IndexType i = 0; i < rows; i++ )
       for( IndexType j = 0; j < columns; j++ )
@@ -510,6 +511,10 @@ void multidiagonalMatrixAssignment()
    RowCapacitiesType rowCapacities;
    matrix.getCompressedRowLengths( rowCapacities );
    RowCapacitiesType exactRowLengths{ 3, 4, 5, 5, 6, 5, 5, 4, 4, 3 };
+   /*std::cerr << "hostMatrix " << hostMatrix << std::endl;
+   std::cerr << "matrix " << matrix << std::endl;
+   std::cerr << "rowCapacities " << rowCapacities << std::endl;*/
+
    EXPECT_EQ( rowCapacities, exactRowLengths );
    for( IndexType i = 0; i < rows; i++ )
       for( IndexType j = 0; j < columns; j++ )
-- 
GitLab