Template Numerical Library version\ main:bb09b17
Loading...
Searching...
No Matches
TNL::Matrices::TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator > Class Template Reference

Implementation of sparse tridiagonal matrix. More...

#include <TNL/Matrices/TridiagonalMatrix.h>

Inheritance diagram for TNL::Matrices::TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator >:
Collaboration diagram for TNL::Matrices::TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator >:

Public Types

using ConstViewType = typename ViewType::ConstViewType
 Matrix view type for constant instances.
 
using RealAllocatorType = RealAllocator
 The allocator for matrix elements values.
 
template<typename _Real = Real, typename _Device = Device, typename _Index = Index, ElementsOrganization _Organization = Algorithms::Segments::DefaultElementsOrganization< _Device >::getOrganization(), typename _RealAllocator = typename Allocators::Default< _Device >::template Allocator< _Real >>
using Self = TridiagonalMatrix< _Real, _Device, _Index, _Organization, _RealAllocator >
 Helper type for getting self type or its modifications.
 
using ValuesVectorType = Containers::Vector< Real, Device, Index, RealAllocator >
 Type of vector holding values of matrix elements.
 
using ViewType = TridiagonalMatrixView< Real, Device, Index, Organization >
 Type of related matrix view.
 
- Public Types inherited from TNL::Matrices::TridiagonalMatrixBase< double, Devices::Host, int, Algorithms::Segments::DefaultElementsOrganization< Devices::Host >::getOrganization() >
using ConstRowView
 Type for accessing constant matrix rows.
 
using DeviceType
 The device where the matrix is allocated.
 
using IndexerType
 
using IndexType
 The type used for matrix elements indexing.
 
using RealType
 The type of matrix elements.
 
using RowView
 Type for accessing matrix rows.
 
- Public Types inherited from TNL::Matrices::MatrixBase< double, Devices::Host, int, GeneralMatrix, Organization >
using ConstValuesViewType
 Type of constant vector view holding values of matrix elements.
 
using DeviceType
 The device where the matrix is allocated.
 
using IndexType
 The type used for matrix elements indexing.
 
using RealType
 The type of matrix elements.
 
using RowCapacitiesType
 
using ValuesViewType
 Type of vector view holding values of matrix elements.
 

Public Member Functions

 TridiagonalMatrix ()=default
 Constructor with no parameters.
 
 TridiagonalMatrix (const TridiagonalMatrix &matrix)
 Copy constructor.
 
template<typename ListReal >
 TridiagonalMatrix (Index columns, const std::initializer_list< std::initializer_list< ListReal > > &data)
 Constructor with matrix dimensions, diagonals offsets and matrix elements.
 
 TridiagonalMatrix (Index rows, Index columns)
 Constructor with matrix dimensions.
 
 TridiagonalMatrix (TridiagonalMatrix &&) noexcept=default
 Move constructor.
 
ConstViewType getConstView () const
 Returns a non-modifiable view of the tridiagonal matrix.
 
template<typename Real2 , typename Index2 >
void getTransposition (const TridiagonalMatrix< Real2, Device, Index2 > &matrix, const Real &matrixMultiplicator=1.0)
 
ViewType getView ()
 Returns a modifiable view of the tridiagonal matrix.
 
void load (const String &fileName)
 Method for loading the matrix from the file with given filename.
 
void load (File &file) override
 Method for loading the matrix from a file.
 
TridiagonalMatrixoperator= (const TridiagonalMatrix &matrix)
 Assignment of exactly the same matrix type.
 
template<typename Real_ , typename Device_ , typename Index_ , ElementsOrganization Organization_, typename RealAllocator_ >
TridiagonalMatrixoperator= (const TridiagonalMatrix< Real_, Device_, Index_, Organization_, RealAllocator_ > &matrix)
 Assignment of another tridiagonal matrix.
 
template<typename Real_ , typename Device_ , typename Index_ , ElementsOrganization Organization_, typename RealAllocator_ >
TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator > & operator= (const TridiagonalMatrix< Real_, Device_, Index_, Organization_, RealAllocator_ > &matrix)
 
void reset ()
 Resets the matrix to zero dimensions.
 
void save (const String &fileName) const
 Method for saving the matrix to the file with given filename.
 
void save (File &file) const override
 Method for saving the matrix to a file.
 
void setDimensions (Index rows, Index columns)
 Set matrix dimensions.
 
template<typename ListReal >
void setElements (const std::initializer_list< std::initializer_list< ListReal > > &data)
 Set matrix elements from an initializer list.
 
template<typename Real_ , typename Device_ , typename Index_ , ElementsOrganization Organization_, typename RealAllocator_ >
void setLike (const TridiagonalMatrix< Real_, Device_, Index_, Organization_, RealAllocator_ > &matrix)
 Setup the matrix dimensions and diagonals offsets based on another tridiagonal matrix.
 
template<typename RowCapacitiesVector >
void setRowCapacities (const RowCapacitiesVector &rowCapacities)
 This method is for compatibility with SparseMatrix.
 
- Public Member Functions inherited from TNL::Object
virtual ~Object ()=default
 Destructor.
 
virtual std::string getSerializationTypeVirtual () const
 
void load (const String &fileName)
 Method for restoring the object from a file.
 
void save (const String &fileName) const
 Method for saving the object to a file as a binary data.
 
- Public Member Functions inherited from TNL::Matrices::TridiagonalMatrixBase< double, Devices::Host, int, Algorithms::Segments::DefaultElementsOrganization< Devices::Host >::getOrganization() >
__cuda_callable__ TridiagonalMatrixBase ()=default
 Constructor with no parameters.
 
__cuda_callable__ TridiagonalMatrixBase (const TridiagonalMatrixBase &)=default
 Copy constructor.
 
__cuda_callable__ TridiagonalMatrixBase (TridiagonalMatrixBase &&) noexcept=default
 Move constructor.
 
__cuda_callable__ TridiagonalMatrixBase (typename Base::ValuesViewType values, IndexerType indexer)
 Constructor with all necessary data and views.
 
__cuda_callable__ void addElement (IndexType row, IndexType column, const RealType &value, const RealType &thisElementMultiplicator=1.0)
 Add element at given row and column to given value.
 
void addMatrix (const TridiagonalMatrixBase< Real_, Device_, Index_, Organization_ > &matrix, const RealType &matrixMultiplicator=1.0, const RealType &thisMatrixMultiplicator=1.0)
 
void forAllElements (Function &function)
 This method calls forElements for all matrix rows.
 
void forAllElements (Function &function) const
 This method calls forElements for all matrix rows (for constant instances).
 
void forAllRows (Function &&function)
 Method for parallel iteration over all matrix rows.
 
void forAllRows (Function &&function) const
 Method for parallel iteration over all matrix rows for constant instances.
 
void forElements (IndexType begin, IndexType end, Function &function)
 Method for iteration over all matrix rows for non-constant instances.
 
void forElements (IndexType begin, IndexType end, Function &function) const
 Method for iteration over all matrix rows for constant instances.
 
void forRows (IndexType begin, IndexType end, Function &&function)
 Method for parallel iteration over matrix rows from interval [begin, end).
 
void forRows (IndexType begin, IndexType end, Function &&function) const
 Method for parallel iteration over matrix rows from interval [begin, end) for constant instances.
 
void getCompressedRowLengths (Vector &rowLengths) const
 Computes number of non-zeros in each row.
 
__cuda_callable__ RealType getElement (IndexType row, IndexType column) const
 Returns value of matrix element at position given by its row and column index.
 
__cuda_callable__ IndexerTypegetIndexer ()
 This method returns matrix elements indexer used by this matrix.
 
__cuda_callable__ const IndexerTypegetIndexer () const
 This method returns matrix elements indexer used by this matrix.
 
IndexType getNonzeroElementsCount () const override
 Returns number of non-zero matrix elements.
 
__cuda_callable__ RowView getRow (IndexType rowIdx)
 Non-constant getter of simple structure for accessing given matrix row.
 
__cuda_callable__ ConstRowView getRow (IndexType rowIdx) const
 Constant getter of simple structure for accessing given matrix row.
 
void getRowCapacities (Vector &rowCapacities) const
 Compute capacities of all rows.
 
bool operator!= (const TridiagonalMatrixBase< Real_, Device_, Index_, Organization_ > &matrix) const
 Comparison operator with another multidiagonal matrix.
 
TridiagonalMatrixBaseoperator= (const TridiagonalMatrixBase &)=delete
 Copy-assignment operator.
 
TridiagonalMatrixBaseoperator= (TridiagonalMatrixBase &&)=delete
 Move-assignment operator.
 
bool operator== (const TridiagonalMatrixBase< Real_, Device_, Index_, Organization_ > &matrix) const
 Comparison operator with another tridiagonal matrix.
 
void print (std::ostream &str) const
 Method for printing the matrix to output stream.
 
void reduceAllRows (Fetch &&fetch, const Reduce &reduce, Keep &&keep, const FetchReal &identity) const
 Method for performing general reduction on all matrix rows for constant instances.
 
void reduceRows (IndexType begin, IndexType end, Fetch &&fetch, const Reduce &reduce, Keep &&keep, const FetchReal &identity) const
 Method for performing general reduction on matrix rows for constant instances.
 
void sequentialForAllRows (Function &function)
 This method calls sequentialForRows for all matrix rows.
 
void sequentialForAllRows (Function &function) const
 This method calls sequentialForRows for all matrix rows (for constant instances).
 
void sequentialForRows (IndexType begin, IndexType end, Function &function)
 Method for sequential iteration over all matrix rows for non-constant instances.
 
void sequentialForRows (IndexType begin, IndexType end, Function &function) const
 Method for sequential iteration over all matrix rows for constant instances.
 
__cuda_callable__ void setElement (IndexType row, IndexType column, const RealType &value)
 Sets element at given row and column to given value.
 
void setValue (const RealType &value)
 Set all matrix elements to given value.
 
void vectorProduct (const InVector &inVector, OutVector &outVector, RealType matrixMultiplicator=1.0, RealType outVectorMultiplicator=0.0, IndexType begin=0, IndexType end=0) const
 Computes product of matrix and vector.
 
- Public Member Functions inherited from TNL::Matrices::MatrixBase< double, Devices::Host, int, GeneralMatrix, Organization >
__cuda_callable__ MatrixBase ()=default
 Basic constructor with no parameters.
 
__cuda_callable__ MatrixBase (const MatrixBase &view)=default
 Shallow copy constructor.
 
__cuda_callable__ MatrixBase (IndexType rows, IndexType columns, ValuesViewType values)
 Constructor with matrix dimensions and matrix elements values.
 
__cuda_callable__ MatrixBase (MatrixBase &&view) noexcept=default
 Move constructor.
 
IndexType getAllocatedElementsCount () const
 Tells the number of allocated matrix elements.
 
__cuda_callable__ IndexType getColumns () const
 Returns number of matrix columns.
 
__cuda_callable__ IndexType getRows () const
 Returns number of matrix rows.
 
__cuda_callable__ ValuesViewTypegetValues ()
 Returns a reference to a vector with the matrix elements values.
 
__cuda_callable__ const ValuesViewTypegetValues () const
 Returns a constant reference to a vector with the matrix elements values.
 
bool operator!= (const Matrix &matrix) const
 Comparison operator with another arbitrary matrix view type.
 
bool operator!= (const MatrixT &matrix) const
 
__cuda_callable__ MatrixBaseoperator= (const MatrixBase &)=delete
 Copy-assignment operator.
 
__cuda_callable__ MatrixBaseoperator= (MatrixBase &&)=delete
 Move-assignment operator.
 
bool operator== (const Matrix &matrix) const
 Comparison operator with another arbitrary matrix view type.
 
bool operator== (const MatrixT &matrix) const
 

Static Public Member Functions

static std::string getSerializationType ()
 Returns string with serialization type.
 
- Static Public Member Functions inherited from TNL::Object
static std::string getSerializationType ()
 Static serialization type getter.
 
- Static Public Member Functions inherited from TNL::Matrices::TridiagonalMatrixBase< double, Devices::Host, int, Algorithms::Segments::DefaultElementsOrganization< Devices::Host >::getOrganization() >
static std::string getSerializationType ()
 Returns string with serialization type.
 
- Static Public Member Functions inherited from TNL::Matrices::MatrixBase< double, Devices::Host, int, GeneralMatrix, Organization >
static constexpr ElementsOrganization getOrganization ()
 Matrix elements organization getter.
 
static constexpr bool isBinary ()
 Test of binary matrix type.
 
static constexpr bool isSymmetric ()
 Test of symmetric matrix type.
 

Protected Attributes

ValuesVectorType values
 Vector containing the allocated matrix elements.
 
- Protected Attributes inherited from TNL::Matrices::TridiagonalMatrixBase< double, Devices::Host, int, Algorithms::Segments::DefaultElementsOrganization< Devices::Host >::getOrganization() >
IndexerType indexer
 
- Protected Attributes inherited from TNL::Matrices::MatrixBase< double, Devices::Host, int, GeneralMatrix, Organization >
IndexType columns
 
IndexType rows
 
ValuesViewType values
 

Additional Inherited Members

- Protected Member Functions inherited from TNL::Matrices::TridiagonalMatrixBase< double, Devices::Host, int, Algorithms::Segments::DefaultElementsOrganization< Devices::Host >::getOrganization() >
__cuda_callable__ void bind (typename Base::ValuesViewType values, IndexerType indexer)
 Re-initializes the internal attributes of the base class.
 
__cuda_callable__ IndexType getElementIndex (IndexType row, IndexType column) const
 
- Protected Member Functions inherited from TNL::Matrices::MatrixBase< double, Devices::Host, int, GeneralMatrix, Organization >
__cuda_callable__ void bind (IndexType rows, IndexType columns, ValuesViewType values)
 Re-initializes the internal attributes of the base class.
 

Detailed Description

template<typename Real = double, typename Device = Devices::Host, typename Index = int, ElementsOrganization Organization = Algorithms::Segments::DefaultElementsOrganization< Device >::getOrganization(), typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >>
class TNL::Matrices::TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator >

Implementation of sparse tridiagonal matrix.

Use this matrix type for storing of tridiagonal matrices i.e., matrices having non-zero matrix elements only on its diagonal and immediately above and bellow the diagonal. This is an example:

\[ \left( \begin{array}{ccccccc} 4 & -1 & . & . & . & . \\ -1 & 4 & -1 & . & . & . \\ . & -1 & 4 & -1 & . & . \\ . & . & -1 & 4 & -1 & . \\ . & . & . & -1 & 4 & -1 \\ . & . & . & . & -1 & 4 \end{array} \right) \]

Advantage is that we do not store the column indexes explicitly as it is in SparseMatrix. This can reduce significantly the memory requirements which also means better performance. See the following table for the storage requirements comparison between TridiagonalMatrix and SparseMatrix.

Real Index SparseMatrix TridiagonalMatrix Ratio
float 32-bit int 8 bytes per element 4 bytes per element 50%
double 32-bit int 12 bytes per element 8 bytes per element 75%
float 64-bit int 12 bytes per element 4 bytes per element 30%
double 64-bit int 16 bytes per element 8 bytes per element 50%
Template Parameters
Realis a type of matrix elements.
Deviceis a device where the matrix is allocated.
Indexis a type for indexing of the matrix elements.
Organizationtells the ordering of matrix elements. It is either RowMajorOrder or ColumnMajorOrder.
RealAllocatoris allocator for the matrix elements.

Member Typedef Documentation

◆ ConstViewType

template<typename Real = double, typename Device = Devices::Host, typename Index = int, ElementsOrganization Organization = Algorithms::Segments::DefaultElementsOrganization< Device >::getOrganization(), typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >>
using TNL::Matrices::TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator >::ConstViewType = typename ViewType::ConstViewType

Matrix view type for constant instances.

See TridiagonalMatrixView.

◆ ViewType

template<typename Real = double, typename Device = Devices::Host, typename Index = int, ElementsOrganization Organization = Algorithms::Segments::DefaultElementsOrganization< Device >::getOrganization(), typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >>
using TNL::Matrices::TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator >::ViewType = TridiagonalMatrixView< Real, Device, Index, Organization >

Type of related matrix view.

See TridiagonalMatrixView.

Constructor & Destructor Documentation

◆ TridiagonalMatrix() [1/2]

template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
TNL::Matrices::TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator >::TridiagonalMatrix ( Index rows,
Index columns )

Constructor with matrix dimensions.

Parameters
rowsis number of matrix rows.
columnsis number of matrix columns.

◆ TridiagonalMatrix() [2/2]

template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
template<typename ListReal >
TNL::Matrices::TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator >::TridiagonalMatrix ( Index columns,
const std::initializer_list< std::initializer_list< ListReal > > & data )

Constructor with matrix dimensions, diagonals offsets and matrix elements.

The number of matrix rows is deduced from the size of the initializer list data.

Template Parameters
ListRealis type used in the initializer list defining matrix elements values.
Parameters
columnsis number of matrix columns.
datais initializer list holding matrix elements. The size of the outer list defines the number of matrix rows. Each inner list defines values of each sub-diagonal and so its size should be lower or equal to three. Values of sub-diagonals which do not fit to given row are omitted.
Example
#include <iostream>
#include <TNL/Matrices/TridiagonalMatrix.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
template< typename Device >
void
createTridiagonalMatrix()
{
const int matrixSize = 6;
/***
* Setup the following matrix (dots represent zeros):
*
* / 2 -1 . . . . \
* | -1 2 -1 . . . |
* | . -1 2 -1 . . |
* | . . -1 2 -1 . |
* | . . . -1 2 -1 |
* \ . . . . -1 2 /
*
*/
matrixSize,
{ /***
* To set the matrix elements we first extend the diagonals to their full
* lengths even outside the matrix (dots represent zeros and zeros are
* artificial zeros used for memory alignment):
*
* 0 / 2 -1 . . . . \ -> { 0, 2, -1 }
* | -1 2 -1 . . . | -> { -1, 2, -1 }
* | . -1 2 -1 . . | -> { -1, 2, -1 }
* | . . -1 2 -1 . | -> { -1, 2, -1 }
* | . . . -1 2 -1 | -> { -1, 2, -1 }
* \ . . . . -1 2 / 0 -> { -1, 2, 0 }
*
*/
{ 0, 2, -1 },
{ -1, 2, -1 },
{ -1, 2, -1 },
{ -1, 2, -1 },
{ -1, 2, -1 },
{ -1, 2, 0 } } );
std::cout << "The matrix reads as: " << std::endl << matrix << std::endl;
}
int
main( int argc, char* argv[] )
{
std::cout << "Creating tridiagonal matrix on CPU ... " << std::endl;
createTridiagonalMatrix< TNL::Devices::Host >();
#ifdef __CUDACC__
std::cout << "Creating tridiagonal matrix on CUDA GPU ... " << std::endl;
createTridiagonalMatrix< TNL::Devices::Cuda >();
#endif
}
Implementation of sparse tridiagonal matrix.
Definition TridiagonalMatrix.h:56
T endl(T... args)
Output
Creating tridiagonal matrix on CPU ...
The matrix reads as:
Row: 0 -> 0:2 1:-1
Row: 1 -> 0:-1 1:2 2:-1
Row: 2 -> 1:-1 2:2 3:-1
Row: 3 -> 2:-1 3:2 4:-1
Row: 4 -> 3:-1 4:2 5:-1
Row: 5 -> 4:-1 5:2
Creating tridiagonal matrix on CUDA GPU ...
The matrix reads as:
Row: 0 -> 0:2 1:-1
Row: 1 -> 0:-1 1:2 2:-1
Row: 2 -> 1:-1 2:2 3:-1
Row: 3 -> 2:-1 3:2 4:-1
Row: 4 -> 3:-1 4:2 5:-1
Row: 5 -> 4:-1 5:2

Member Function Documentation

◆ getConstView()

template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
auto TNL::Matrices::TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator >::getConstView ( ) const
nodiscard

Returns a non-modifiable view of the tridiagonal matrix.

See TridiagonalMatrixView.

Returns
tridiagonal matrix view.

◆ getSerializationType()

template<typename Real = double, typename Device = Devices::Host, typename Index = int, ElementsOrganization Organization = Algorithms::Segments::DefaultElementsOrganization< Device >::getOrganization(), typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >>
std::string TNL::Matrices::TridiagonalMatrixBase< Real, Device, Index, Organization >::getSerializationType ( )
staticnodiscard

Returns string with serialization type.

The string has a form Matrices::TridiagonalMatrix< RealType, [any_device], IndexType, Organization >.

See TridiagonalMatrix::getSerializationType.

Returns
String with the serialization type.

◆ getView()

template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
auto TNL::Matrices::TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator >::getView ( )
nodiscard

Returns a modifiable view of the tridiagonal matrix.

See TridiagonalMatrixView.

Returns
tridiagonal matrix view.

◆ load() [1/2]

template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
void TNL::Matrices::TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator >::load ( const String & fileName)

Method for loading the matrix from the file with given filename.

Parameters
fileNameis name of the file.

◆ load() [2/2]

template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
void TNL::Matrices::TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator >::load ( File & file)
overridevirtual

Method for loading the matrix from a file.

Parameters
fileis the input file.

Reimplemented from TNL::Object.

◆ operator=() [1/2]

template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator > & TNL::Matrices::TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator >::operator= ( const TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator > & matrix)

Assignment of exactly the same matrix type.

Parameters
matrixis input matrix for the assignment.
Returns
reference to this matrix.

◆ operator=() [2/2]

template<typename Real = double, typename Device = Devices::Host, typename Index = int, ElementsOrganization Organization = Algorithms::Segments::DefaultElementsOrganization< Device >::getOrganization(), typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >>
template<typename Real_ , typename Device_ , typename Index_ , ElementsOrganization Organization_, typename RealAllocator_ >
TridiagonalMatrix & TNL::Matrices::TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator >::operator= ( const TridiagonalMatrix< Real_, Device_, Index_, Organization_, RealAllocator_ > & matrix)

Assignment of another tridiagonal matrix.

Parameters
matrixis input matrix for the assignment.
Returns
reference to this matrix.

◆ save() [1/2]

template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
void TNL::Matrices::TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator >::save ( const String & fileName) const

Method for saving the matrix to the file with given filename.

Parameters
fileNameis name of the file.

◆ save() [2/2]

template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
void TNL::Matrices::TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator >::save ( File & file) const
overridevirtual

Method for saving the matrix to a file.

Parameters
fileis the output file.

Reimplemented from TNL::Object.

◆ setDimensions()

template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
void TNL::Matrices::TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator >::setDimensions ( Index rows,
Index columns )

Set matrix dimensions.

Parameters
rowsis number of matrix rows.
columnsis number of matrix columns.

◆ setElements()

template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
template<typename ListReal >
void TNL::Matrices::TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator >::setElements ( const std::initializer_list< std::initializer_list< ListReal > > & data)

Set matrix elements from an initializer list.

Template Parameters
ListRealis data type of the initializer list.
Parameters
datais initializer list holding matrix elements. The size of the outer list defines the number of matrix rows. Each inner list defines values of each sub-diagonal and so its size should be lower or equal to three. Values of sub-diagonals which do not fit to given row are omitted.
Example
#include <iostream>
#include <TNL/Matrices/TridiagonalMatrix.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
template< typename Device >
void
createTridiagonalMatrix()
{
const int matrixSize = 6;
/***
* Setup the following matrix (dots represent zeros):
*
* / 2 -1 . . . . \
* | -1 2 -1 . . . |
* | . -1 2 -1 . . |
* | . . -1 2 -1 . |
* | . . . -1 2 -1 |
* \ . . . . -1 2 /
*
*/
TNL::Matrices::TridiagonalMatrix< double, Device > matrix( matrixSize, matrixSize );
matrix.setElements( { /***
* To set the matrix elements we first extend the diagonals to their full
* lengths even outside the matrix (dots represent zeros and zeros are
* artificial zeros used for memory alignment):
*
* 0 / 2 -1 . . . . \ -> { 0, 2, -1 }
* | -1 2 -1 . . . | -> { -1, 2, -1 }
* | . -1 2 -1 . . | -> { -1, 2, -1 }
* | . . -1 2 -1 . | -> { -1, 2, -1 }
* | . . . -1 2 -1 | -> { -1, 2, -1 }
* \ . . . . -1 2 / 0 -> { -1, 2, 0 }
*
*/
{ 0, 2, -1 },
{ -1, 2, -1 },
{ -1, 2, -1 },
{ -1, 2, -1 },
{ -1, 2, -1 },
{ -1, 2, 0 } } );
std::cout << "The matrix reads as: " << std::endl << matrix << std::endl;
}
int
main( int argc, char* argv[] )
{
std::cout << "Creating tridiagonal matrix on CPU ... " << std::endl;
createTridiagonalMatrix< TNL::Devices::Host >();
#ifdef __CUDACC__
std::cout << "Creating tridiagonal matrix on CUDA GPU ... " << std::endl;
createTridiagonalMatrix< TNL::Devices::Cuda >();
#endif
}
Output
Creating tridiagonal matrix on CPU ...
The matrix reads as:
Row: 0 -> 0:2 1:-1
Row: 1 -> 0:-1 1:2 2:-1
Row: 2 -> 1:-1 2:2 3:-1
Row: 3 -> 2:-1 3:2 4:-1
Row: 4 -> 3:-1 4:2 5:-1
Row: 5 -> 4:-1 5:2
Creating tridiagonal matrix on CUDA GPU ...
The matrix reads as:
Row: 0 -> 0:2 1:-1
Row: 1 -> 0:-1 1:2 2:-1
Row: 2 -> 1:-1 2:2 3:-1
Row: 3 -> 2:-1 3:2 4:-1
Row: 4 -> 3:-1 4:2 5:-1
Row: 5 -> 4:-1 5:2

◆ setLike()

template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
template<typename Real_ , typename Device_ , typename Index_ , ElementsOrganization Organization_, typename RealAllocator_ >
void TNL::Matrices::TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator >::setLike ( const TridiagonalMatrix< Real_, Device_, Index_, Organization_, RealAllocator_ > & matrix)

Setup the matrix dimensions and diagonals offsets based on another tridiagonal matrix.

Template Parameters
Real_is Real type of the source matrix.
Device_is Device type of the source matrix.
Index_is Index type of the source matrix.
Organization_is Organization of the source matrix.
RealAllocator_is RealAllocator of the source matrix.
Parameters
matrixis the source matrix.

◆ setRowCapacities()

template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
template<typename RowCapacitiesVector >
void TNL::Matrices::TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator >::setRowCapacities ( const RowCapacitiesVector & rowCapacities)

This method is for compatibility with SparseMatrix.

It checks if the number of matrix diagonals is compatible with required number of non-zero matrix elements in each row. If not exception is thrown.

Template Parameters
RowCapacitiesVectoris vector-like container type for holding required row capacities.
Parameters
rowCapacitiesis vector-like container holding required row capacities.

The documentation for this class was generated from the following files: