Commit d502b075 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

ValuesHolder for matrices was not good idea :-).

parent 4a70c74f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -36,8 +36,8 @@ class Dense : public Matrix< Real, Device, Index >
      using IndexType = Index;
      using RealAllocatorType = RealAllocator;
      using BaseType = Matrix< Real, Device, Index, RealAllocator >;
      using ValuesHolderType = typename BaseType::ValuesHolderType;
      using ValuesViewType = typename ValuesHolderType::ViewType;
      using ValuesVectorType = typename BaseType::ValuesVectorType;
      using ValuesViewType = typename ValuesVectorType::ViewType;
      using SegmentsType = Containers::Segments::Ellpack< DeviceType, IndexType, typename Allocators::Default< Device >::template Allocator< IndexType >, RowMajorOrder, 1 >;
      using SegmentViewType = typename SegmentsType::SegmentViewType;
      using ViewType = DenseMatrixView< Real, Device, Index, RowMajorOrder >;
+2 −2
Original line number Diff line number Diff line
@@ -39,8 +39,8 @@ class DenseMatrixView : public MatrixView< Real, Device, Index >
      using DeviceType = Device;
      using IndexType = Index;
      using BaseType = Matrix< Real, Device, Index >;
      using ValuesHolderType = typename BaseType::ValuesHolderType;
      using ValuesViewType = typename ValuesHolderType::ViewType;
      using ValuesVectorType = typename BaseType::ValuesVectorType;
      using ValuesViewType = typename ValuesVectorType::ViewType;
      using SegmentsType = Containers::Segments::Ellpack< DeviceType, IndexType, typename Allocators::Default< Device >::template Allocator< IndexType >, RowMajorOrder, 1 >;
      using SegmentsViewType = typename SegmentsType::ViewType;
      using SegmentViewType = typename SegmentsType::SegmentViewType;
+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ class Sparse : public Matrix< Real, Device, Index >
   typedef Real RealType;
   typedef Device DeviceType;
   typedef Index IndexType;
   typedef typename Matrix< RealType, DeviceType, IndexType >::ValuesHolderType ValuesVector;
   typedef typename Matrix< RealType, DeviceType, IndexType >::ValuesVectorType ValuesVector;
   typedef Containers::Vector< IndexType, DeviceType, IndexType > ColumnIndexesVector;
   typedef Matrix< Real, Device, Index > BaseType;
   typedef SparseRow< RealType, IndexType > MatrixRow;
+5 −7
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@
#include <TNL/Containers/Vector.h>
#include <TNL/Containers/VectorView.h>
#include <TNL/Matrices/MatrixView.h>
#include <TNL/Matrices/details/ValuesHolder.h>

namespace TNL {
/**
@@ -27,8 +26,7 @@ namespace Matrices {
template< typename Real = double,
          typename Device = Devices::Host,
          typename Index = int,
          typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >,
          typename ValuesHolder = typename details::ValuesHolder< Real, Device, Index, RealAllocator > >
          typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real > >
class Matrix : public Object
{
public:
@@ -38,7 +36,7 @@ public:
   using CompressedRowLengthsVector = Containers::Vector< IndexType, DeviceType, IndexType >;
   using CompressedRowLengthsVectorView = Containers::VectorView< IndexType, DeviceType, IndexType >;
   using ConstCompressedRowLengthsVectorView = typename CompressedRowLengthsVectorView::ConstViewType;
   using ValuesHolderType = ValuesHolder;
   using ValuesVectorType = Containers::Vector< Real, Device, Index, RealAllocator >;
   using RealAllocatorType = RealAllocator;
   using ViewType = MatrixView< Real, Device, Index >;
   using ConstViewType = MatrixView< std::add_const_t< Real >, Device, Index >;
@@ -92,9 +90,9 @@ public:
   virtual Real getElement( const IndexType row,
                            const IndexType column ) const = 0;

   const ValuesHolderType& getValues() const;
   const ValuesVectorType& getValues() const;

   ValuesHolderType& getValues();
   ValuesVectorType& getValues();

   // TODO: parallelize and optimize for sparse matrices
   template< typename Matrix >
@@ -133,7 +131,7 @@ public:

   IndexType rows, columns, numberOfColors;

   ValuesHolderType values;
   ValuesVectorType values;
};

template< typename Real, typename Device, typename Index >
+43 −63
Original line number Diff line number Diff line
@@ -22,9 +22,8 @@ namespace Matrices {
template< typename Real,
          typename Device,
          typename Index,
          typename RealAllocator,
          typename ValuesHolder >
Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::
          typename RealAllocator >
Matrix< Real, Device, Index, RealAllocator >::
Matrix( const RealAllocatorType& allocator )
: rows( 0 ),
  columns( 0 ),
@@ -35,9 +34,8 @@ Matrix( const RealAllocatorType& allocator )
template< typename Real,
          typename Device,
          typename Index,
          typename RealAllocator,
          typename ValuesHolder >
Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::
          typename RealAllocator >
Matrix< Real, Device, Index, RealAllocator >::
Matrix( const IndexType rows_, const IndexType columns_, const RealAllocatorType& allocator )
: rows( rows_ ),
  columns( columns_ ),
@@ -48,9 +46,8 @@ Matrix( const IndexType rows_, const IndexType columns_, const RealAllocatorType
template< typename Real,
          typename Device,
          typename Index,
          typename RealAllocator,
          typename ValuesHolder >
void Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::setDimensions( const IndexType rows,
          typename RealAllocator >
void Matrix< Real, Device, Index, RealAllocator >::setDimensions( const IndexType rows,
                                                   const IndexType columns )
{
   TNL_ASSERT( rows > 0 && columns > 0,
@@ -63,7 +60,7 @@ void Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::setDimensions(
          typename Device,
          typename Index,
          typename RealAllocator >
void Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::getCompressedRowLengths( CompressedRowLengthsVector& rowLengths ) const
void Matrix< Real, Device, Index, RealAllocator >::getCompressedRowLengths( CompressedRowLengthsVector& rowLengths ) const
{
   rowLengths.setSize( this->getRows() );
   getCompressedRowLengths( rowLengths.getView() );
@@ -72,9 +69,8 @@ void Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::getCompressedRo
template< typename Real,
          typename Device,
          typename Index,
          typename RealAllocator,
          typename ValuesHolder >
void Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::getCompressedRowLengths( CompressedRowLengthsVectorView rowLengths ) const
          typename RealAllocator >
void Matrix< Real, Device, Index, RealAllocator >::getCompressedRowLengths( CompressedRowLengthsVectorView rowLengths ) const
{
   TNL_ASSERT_EQ( rowLengths.getSize(), this->getRows(), "invalid size of the rowLengths vector" );
   for( IndexType row = 0; row < this->getRows(); row++ )
@@ -84,10 +80,9 @@ void Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::getCompressedRo
template< typename Real,
          typename Device,
          typename Index,
          typename RealAllocator,
          typename ValuesHolder >
          typename RealAllocator >
   template< typename Matrix_ >
void Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::setLike( const Matrix_& matrix )
void Matrix< Real, Device, Index, RealAllocator >::setLike( const Matrix_& matrix )
{
   setDimensions( matrix.getRows(), matrix.getColumns() );
}
@@ -95,9 +90,8 @@ void Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::setLike( const
template< typename Real,
          typename Device,
          typename Index,
          typename RealAllocator,
          typename ValuesHolder >
Index Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::getAllocatedElementsCount() const
          typename RealAllocator >
Index Matrix< Real, Device, Index, RealAllocator >::getAllocatedElementsCount() const
{
   return this->values.getSize();
}
@@ -105,9 +99,8 @@ Index Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::getAllocatedEl
template< typename Real,
          typename Device,
          typename Index,
          typename RealAllocator,
          typename ValuesHolder >
Index Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::getNumberOfNonzeroMatrixElements() const
          typename RealAllocator >
Index Matrix< Real, Device, Index, RealAllocator >::getNumberOfNonzeroMatrixElements() const
{
   const auto values_view = this->values.getConstView();
   auto fetch = [=] __cuda_callable__ ( const IndexType i ) -> IndexType {
@@ -119,10 +112,9 @@ Index Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::getNumberOfNon
template< typename Real,
          typename Device,
          typename Index,
          typename RealAllocator,
          typename ValuesHolder >
          typename RealAllocator >
__cuda_callable__
Index Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::getRows() const
Index Matrix< Real, Device, Index, RealAllocator >::getRows() const
{
   return this->rows;
}
@@ -130,10 +122,9 @@ Index Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::getRows() cons
template< typename Real,
          typename Device,
          typename Index,
          typename RealAllocator,
          typename ValuesHolder >
          typename RealAllocator >
__cuda_callable__
Index Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::getColumns() const
Index Matrix< Real, Device, Index, RealAllocator >::getColumns() const
{
   return this->columns;
}
@@ -141,10 +132,9 @@ Index Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::getColumns() c
template< typename Real,
          typename Device,
          typename Index,
          typename RealAllocator,
          typename ValuesHolder >
const typename Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::ValuesHolderType&
Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::
          typename RealAllocator >
const typename Matrix< Real, Device, Index, RealAllocator >::ValuesVectorType&
Matrix< Real, Device, Index, RealAllocator >::
getValues() const
{
   return this->values;
@@ -153,10 +143,9 @@ getValues() const
template< typename Real,
          typename Device,
          typename Index,
          typename RealAllocator,
          typename ValuesHolder >
typename Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::ValuesHolderType&
Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::
          typename RealAllocator >
typename Matrix< Real, Device, Index, RealAllocator >::ValuesVectorType&
Matrix< Real, Device, Index, RealAllocator >::
getValues()
{
   return this->values;
@@ -165,9 +154,8 @@ getValues()
template< typename Real,
          typename Device,
          typename Index,
          typename RealAllocator,
          typename ValuesHolder >
void Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::reset()
          typename RealAllocator >
void Matrix< Real, Device, Index, RealAllocator >::reset()
{
   this->rows = 0;
   this->columns = 0;
@@ -177,10 +165,9 @@ void Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::reset()
template< typename Real,
          typename Device,
          typename Index,
          typename RealAllocator,
          typename ValuesHolder >
          typename RealAllocator >
   template< typename MatrixT >
bool Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::operator == ( const MatrixT& matrix ) const
bool Matrix< Real, Device, Index, RealAllocator >::operator == ( const MatrixT& matrix ) const
{
   if( this->getRows() != matrix.getRows() ||
       this->getColumns() != matrix.getColumns() )
@@ -195,10 +182,9 @@ bool Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::operator == ( c
template< typename Real,
          typename Device,
          typename Index,
          typename RealAllocator,
          typename ValuesHolder >
          typename RealAllocator >
   template< typename MatrixT >
bool Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::operator != ( const MatrixT& matrix ) const
bool Matrix< Real, Device, Index, RealAllocator >::operator != ( const MatrixT& matrix ) const
{
   return ! operator == ( matrix );
}
@@ -206,9 +192,8 @@ bool Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::operator != ( c
template< typename Real,
          typename Device,
          typename Index,
          typename RealAllocator,
          typename ValuesHolder >
void Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::save( File& file ) const
          typename RealAllocator >
void Matrix< Real, Device, Index, RealAllocator >::save( File& file ) const
{
   Object::save( file );
   file.save( &this->rows );
@@ -219,9 +204,8 @@ void Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::save( File& fil
template< typename Real,
          typename Device,
          typename Index,
          typename RealAllocator,
          typename ValuesHolder >
void Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::load( File& file )
          typename RealAllocator >
void Matrix< Real, Device, Index, RealAllocator >::load( File& file )
{
   Object::load( file );
   file.load( &this->rows );
@@ -232,20 +216,18 @@ void Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::load( File& fil
template< typename Real,
          typename Device,
          typename Index,
          typename RealAllocator,
          typename ValuesHolder >
void Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::print( std::ostream& str ) const
          typename RealAllocator >
void Matrix< Real, Device, Index, RealAllocator >::print( std::ostream& str ) const
{
}

template< typename Real,
          typename Device,
          typename Index,
          typename RealAllocator,
          typename ValuesHolder >
          typename RealAllocator >
__cuda_callable__
const Index&
Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::
Matrix< Real, Device, Index, RealAllocator >::
getNumberOfColors() const
{
   return this->numberOfColors;
@@ -254,10 +236,9 @@ getNumberOfColors() const
template< typename Real,
          typename Device,
          typename Index,
          typename RealAllocator,
          typename ValuesHolder >
          typename RealAllocator >
void
Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::
Matrix< Real, Device, Index, RealAllocator >::
computeColorsVector(Containers::Vector<Index, Device, Index> &colorsVector)
{
    for( IndexType i = this->getRows() - 1; i >= 0; i-- )
@@ -293,10 +274,9 @@ computeColorsVector(Containers::Vector<Index, Device, Index> &colorsVector)
template< typename Real,
          typename Device,
          typename Index,
          typename RealAllocator,
          typename ValuesHolder >
          typename RealAllocator >
void
Matrix< Real, Device, Index, RealAllocator, ValuesHolder >::
Matrix< Real, Device, Index, RealAllocator >::
copyFromHostToCuda( Matrix< Real, Devices::Host, Index >& matrix )
{
    this->numberOfColors = matrix.getNumberOfColors();
Loading