Commit 527ad5cc authored by Tomáš Oberhuber's avatar Tomáš Oberhuber Committed by Jakub Klinkovský
Browse files

Fixed method forElements in SparseMatrixView for case when segments manage...

Fixed method forElements in SparseMatrixView for case when segments manage more elements than matrix columns.
parent 0e118aae
Loading
Loading
Loading
Loading
+19 −11
Original line number Diff line number Diff line
@@ -594,12 +594,16 @@ forElements( IndexType begin, IndexType end, Function& function ) const
   const auto columns_view = this->columnIndexes.getConstView();
   const auto values_view = this->values.getConstView();
   //const IndexType paddingIndex_ = this->getPaddingIndex();
   auto f = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType globalIdx ) mutable -> bool {
   auto columns = this->getColumns();
   auto f = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType globalIdx ) mutable {
      if( localIdx < columns )
      {
         if( isBinary() )
            function( rowIdx, localIdx, columns_view[ globalIdx ], 1 );
         else
            function( rowIdx, localIdx, columns_view[ globalIdx ], values_view[ globalIdx ] );
      return true;
      }
      //return true;
   };
   this->segments.forElements( begin, end, f );
}
@@ -618,7 +622,10 @@ forElements( IndexType begin, IndexType end, Function& function )
   auto columns_view = this->columnIndexes.getView();
   auto values_view = this->values.getView();
   const IndexType paddingIndex_ = this->getPaddingIndex();
   auto columns = this->getColumns();
   auto f = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType globalIdx ) mutable {
      if( localIdx < columns )
      {
         if( isBinary() )
         {
            RealType one( columns_view[ globalIdx ] != paddingIndex_ );
@@ -626,6 +633,7 @@ forElements( IndexType begin, IndexType end, Function& function )
         }
         else
            function( rowIdx, localIdx, columns_view[ globalIdx ], values_view[ globalIdx ] );
      }
   };
   this->segments.forElements( begin, end, f );
}
+15 −24
Original line number Diff line number Diff line
@@ -424,13 +424,8 @@ void test_VectorProduct_longRowsMatrix()
   using MatrixSegmentsType = typename Matrix::SegmentsType;
   constexpr TNL::Algorithms::Segments::ElementsOrganization organization = MatrixSegmentsType::getOrganization();
   using ChunkedEllpackView_ = TNL::Algorithms::Segments::ChunkedEllpackView< DeviceType, IndexType, organization >;
   if( ! std::is_same< typename Matrix::SegmentsViewType, ChunkedEllpackView_ >::value )
   {
      // TODO: Fix ChunkedEllpack for this test - seems that it allocates too much memory
   for( auto columns : { 64, 65, 128, 129, 256, 257, 512, 513, 1024, 1025, 2048, 2049, 3000 } )
   {
         //std::cerr << "Long-rows-matrix-test: columns = " << columns << std::endl;
         //const int columns = 3000;
      const int rows = 33;
      Matrix m3( rows, columns );
      TNL::Containers::Vector< IndexType, DeviceType, IndexType > rowsCapacities( rows );
@@ -444,12 +439,8 @@ void test_VectorProduct_longRowsMatrix()
      TNL::Containers::Vector< double, DeviceType, IndexType > in( columns, 1.0 ), out( rows, 0.0 );
      m3.vectorProduct( in, out );
      for( IndexType rowIdx = 0; rowIdx < rows; rowIdx++ )
         {
            //std::cerr << "Long-rows-matrix-test: rowIndex = " << rowIdx << std::endl;
         EXPECT_EQ( out.getElement( rowIdx ), ( double ) columns * ( double ) (columns - 1 ) / 2.0 + columns * rowIdx );
   }
}
   }
}

#endif