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

Implementing the matrix formats.

parent 643690da
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -376,7 +376,8 @@ bool tnlChunkedEllpackMatrix< Real, Device, Index > :: setRow( const IndexType r
   const IndexType& chunkSize = slices.getElement( sliceIndex ).chunkSize;
   IndexType elementPointer = rowPointers[ row ];
   const IndexType rowEnd = rowPointers[ row + 1 ];
   if( elements > rowEnd - elementPointer )
   const IndexType rowLength = rowEnd - elementPointer;
   if( elements >  rowLength )
      return false;

   for( IndexType i = 0; i < elements; i++ )
@@ -385,7 +386,7 @@ bool tnlChunkedEllpackMatrix< Real, Device, Index > :: setRow( const IndexType r
      this->values[ elementPointer ] = values[ i ];
      elementPointer++;
   }
   for( IndexType i = elements; i < this->rowLengths; i++ )
   for( IndexType i = elements; i < rowLength; i++ )
      this->columnIndexes[ elementPointer++ ] = this->getColumns();
   return true;
}
+16 −3
Original line number Diff line number Diff line
@@ -95,6 +95,19 @@ Index tnlDenseMatrix< Real, Device, Index >::getNumberOfMatrixElements() const
   return this->getRows() * this->getColumns();
}

template< typename Real,
          typename Device,
          typename Index >
Index tnlDenseMatrix< Real, Device, Index >::getNumberOfNonzeroMatrixElements() const
{
   IndexType nonzeroElements( 0 );
   for( IndexType row = 0; row < this->getRows(); row++ )
      for( IndexType column = 0; column < this->getColumns(); column++ )
         if( this->getElement( row, column ) != 0 )
            nonzeroElements++;
   return nonzeroElements;
}

template< typename Real,
          typename Device,
          typename Index >
@@ -154,15 +167,15 @@ bool tnlDenseMatrix< Real, Device, Index >::addRow( const IndexType row,
                                                    const IndexType* columns,
                                                    const RealType* values,
                                                    const IndexType elements,
                                                    const RealType thisRowMultiplicator )
                                                    const RealType& thisRowMultiplicator )
{
   tnlAssert( elements <= this->columns,
            cerr << " elements = " << elements
                 << " this->columns = " << this->columns
                 << " this->getName() = " << this->getName() );
   for( IndexType i = 0; i < elements; i++ )
      this->operator[]( row, columns[ i ] ) =
               thisRowMultiplicator * this->operator[]( row, columns[ i ] ) + values[ i ];
      this->setElement( row, columns[ i ],
                       thisRowMultiplicator * this->getElement( row, columns[ i ] ) + values[ i ] );
   return true;
}

+30 −2
Original line number Diff line number Diff line
@@ -45,11 +45,11 @@ template< typename Real,
template< typename Real,
          typename Device,
          typename Index >
void tnlMatrix< Real, Device, Index >::getRowLentghs( tnlVector< IndexType, DeviceType, IndexType >& rowLengths ) const
void tnlMatrix< Real, Device, Index >::getRowLengths( tnlVector< IndexType, DeviceType, IndexType >& rowLengths ) const
{
   rowLengths.setSize( this->getRows() );
   for( IndexType row = 0; row < this->getRows(); row++ )
      rowLengths.setElement( row, this->getRowLengths( row ) );
      rowLengths.setElement( row, this->getRowLength( row ) );
}

template< typename Real,
@@ -88,6 +88,34 @@ void tnlMatrix< Real, Device, Index >::reset()
   this->columns = 0;
}

template< typename Real,
          typename Device,
          typename Index >
tnlMatrix< Real, Device, Index >& tnlMatrix< Real, Device, Index >::operator = ( const tnlMatrix< RealType, DeviceType, IndexType >& m )
{
   this->setLike( m );

   tnlVector< IndexType, DeviceType, IndexType > rowLengths;
   m.getRowLengths( rowLengths );
   this->setRowLengths( rowLengths );

   tnlVector< RealType, DeviceType, IndexType > rowValues;
   tnlVector< IndexType, DeviceType, IndexType > rowColumns;
   const IndexType maxRowLength = rowLengths.max();
   rowValues.setSize( maxRowLength );
   rowColumns.setSize( maxRowLength );
   for( IndexType row = 0; row < this->getRows(); row++ )
   {
      m.getRow( row,
                rowColumns.getData(),
                rowValues.getData() );
      this->setRow( row,
                    rowColumns.getData(),
                    rowValues.getData(),
                    rowLengths.getElement( row ) );
   }
}

template< typename Real,
          typename Device,
          typename Index >
+12 −0
Original line number Diff line number Diff line
@@ -146,6 +146,18 @@ Index tnlMultidiagonalMatrix< Real, Device, Index > :: getNumberOfMatrixElements
   return this->values.getSize();
}

template< typename Real,
          typename Device,
          typename Index >
Index tnlMultidiagonalMatrix< Real, Device, Index > :: getNumberOfNonzeroMatrixElements() const
{
   IndexType nonzeroElements;
   for( IndexType i = 0; i < this->values.getSize(); i++ )
      if( this->values.getElement( i ) != 0 )
         nonzeroElements++;
   return nonzeroElements;
}

template< typename Real,
          typename Device,
          typename Index >
+2 −2
Original line number Diff line number Diff line
@@ -111,7 +111,7 @@ template< typename Real,
          int SliceSize >
Index tnlSlicedEllpackMatrix< Real, Device, Index, SliceSize >::getRowLength( const IndexType row ) const
{
   const IndexType slice = roundUpDivision( this->row, SliceSize );
   const IndexType slice = roundUpDivision( row, SliceSize );
   return this->sliceRowLengths[ slice ];
}

@@ -259,7 +259,7 @@ bool tnlSlicedEllpackMatrix< Real, Device, Index, SliceSize > :: setRow( const I
      this->values[ elementPointer ] = values[ i ];
      elementPointer++;
   }
   for( IndexType i = elements; i < this->rowLengths; i++ )
   for( IndexType i = elements; i < rowLength; i++ )
      this->columnIndexes[ elementPointer++ ] = this->getColumns();
   return true;
}
Loading