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

Implementation of dense matrix, i.e. matrix storing explicitly all of its elements including zeros. More...

#include <TNL/Matrices/DenseMatrix.h>

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

Public Types

using ConstViewType = typename DenseMatrixView< Real, Device, Index, Organization >::ConstViewType
 Matrix view type for constant instances.
 
using RealAllocatorType = RealAllocator
 The allocator for matrix elements.
 
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 = DenseMatrix< _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 = DenseMatrixView< Real, Device, Index, Organization >
 Type of related matrix view.
 
- Public Types inherited from TNL::Matrices::DenseMatrixBase< double, Devices::Host, int, Algorithms::Segments::DefaultElementsOrganization< Devices::Host >::getOrganization() >
using ConstRowView
 Type for accessing immutable matrix row.
 
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 RowView
 Type for accessing matrix row.
 
- 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

 DenseMatrix (const DenseMatrix &matrix)
 Copy constructor.
 
 DenseMatrix (const RealAllocatorType &allocator=RealAllocatorType())
 Constructor only with values allocator.
 
 DenseMatrix (DenseMatrix &&matrix) noexcept=default
 Move constructor.
 
 DenseMatrix (Index rows, Index columns, const RealAllocatorType &allocator=RealAllocatorType())
 Constructor with matrix dimensions.
 
template<typename Value >
 DenseMatrix (std::initializer_list< std::initializer_list< Value > > data, const RealAllocatorType &allocator=RealAllocatorType())
 Constructor with 2D initializer list.
 
ConstViewType getConstView () const
 Returns a non-modifiable view of the dense matrix.
 
template<int tileDim = 16>
void getInPlaceTransposition (Real matrixMultiplicator=1.0)
 Performs an in-place transposition of this matrix.
 
template<typename Matrix1 , typename Matrix2 , int tileDim = 16>
void getMatrixProduct (const Matrix1 &matrix1, const Matrix2 &matrix2, Real matrixMultiplicator=1.0, TransposeState transposeA=TransposeState::None, TransposeState transposeB=TransposeState::None)
 Computes the product of two matrices and stores the result in this matrix.
 
template<typename Matrix , int tileDim = 16>
void getTransposition (const Matrix &matrix, Real matrixMultiplicator=1.0)
 Computes the transposition of a given matrix and stores the result in this matrix.
 
ViewType getView ()
 Returns a modifiable view of the dense 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.
 
DenseMatrixoperator= (const DenseMatrix &matrix)
 Copy-assignment of exactly the same matrix type.
 
template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
DenseMatrix< Real, Device, Index, Organization, RealAllocator > & operator= (const DenseMatrix< Real, Device, Index, Organization, RealAllocator > &matrix)
 
template<typename RHSReal , typename RHSDevice , typename RHSIndex , typename RHSRealAllocator >
DenseMatrixoperator= (const DenseMatrix< RHSReal, RHSDevice, RHSIndex, Organization, RHSRealAllocator > &matrix)
 Assignment operator with the same organization.
 
template<typename RHSReal , typename RHSDevice , typename RHSIndex , typename RHSRealAllocator >
DenseMatrix< Real, Device, Index, Organization, RealAllocator > & operator= (const DenseMatrix< RHSReal, RHSDevice, RHSIndex, Organization, RHSRealAllocator > &matrix)
 
template<typename RHSReal , typename RHSDevice , typename RHSIndex , ElementsOrganization RHSOrganization, typename RHSRealAllocator >
DenseMatrixoperator= (const DenseMatrix< RHSReal, RHSDevice, RHSIndex, RHSOrganization, RHSRealAllocator > &matrix)
 Assignment operator with other dense matrices.
 
template<typename RHSReal , typename RHSDevice , typename RHSIndex , ElementsOrganization RHSOrganization, typename RHSRealAllocator >
DenseMatrix< Real, Device, Index, Organization, RealAllocator > & operator= (const DenseMatrix< RHSReal, RHSDevice, RHSIndex, RHSOrganization, RHSRealAllocator > &matrix)
 
template<typename RHSReal , typename RHSDevice , typename RHSIndex >
DenseMatrixoperator= (const DenseMatrixView< RHSReal, RHSDevice, RHSIndex, Organization > &matrix)
 Assignment operator with matrix view having the same elements organization.
 
template<typename RHSReal , typename RHSDevice , typename RHSIndex >
DenseMatrix< Real, Device, Index, Organization, RealAllocator > & operator= (const DenseMatrixView< RHSReal, RHSDevice, RHSIndex, Organization > &matrix)
 
template<typename RHSReal , typename RHSDevice , typename RHSIndex , ElementsOrganization RHSOrganization>
DenseMatrixoperator= (const DenseMatrixView< RHSReal, RHSDevice, RHSIndex, RHSOrganization > &matrix)
 Assignment operator with other dense matrices.
 
template<typename RHSReal , typename RHSDevice , typename RHSIndex , ElementsOrganization RHSOrganization>
DenseMatrix< Real, Device, Index, Organization, RealAllocator > & operator= (const DenseMatrixView< RHSReal, RHSDevice, RHSIndex, RHSOrganization > &matrix)
 
template<typename RHSMatrix >
DenseMatrixoperator= (const RHSMatrix &matrix)
 Assignment operator with other (sparse) types of matrices.
 
template<typename RHSMatrix >
DenseMatrix< Real, Device, Index, Organization, RealAllocator > & operator= (const RHSMatrix &matrix)
 
DenseMatrixoperator= (DenseMatrix &&matrix) noexcept(false)
 Move-assignment of exactly the same matrix type.
 
template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
DenseMatrix< Real, Device, Index, Organization, RealAllocator > & operator= (DenseMatrix< Real, Device, Index, Organization, RealAllocator > &&matrix) noexcept(false)
 
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 number of rows and columns of this matrix.
 
template<typename MapIndex , typename MapValue >
void setElements (const std::map< std::pair< MapIndex, MapIndex >, MapValue > &map)
 This method sets the dense matrix elements from std::map.
 
template<typename Value >
void setElements (std::initializer_list< std::initializer_list< Value > > data)
 This method recreates the dense matrix from 2D initializer list.
 
template<typename Matrix >
void setLike (const Matrix &matrix)
 Set the number of matrix rows and columns by the given matrix.
 
template<typename Matrix_ >
void setLike (const Matrix_ &matrix)
 
template<typename RowCapacitiesVector >
void setRowCapacities (const RowCapacitiesVector &rowCapacities)
 This method is only for the compatibility with the sparse matrices.
 
- 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::DenseMatrixBase< double, Devices::Host, int, Algorithms::Segments::DefaultElementsOrganization< Devices::Host >::getOrganization() >
__cuda_callable__ DenseMatrixBase ()=default
 Constructor without parameters.
 
__cuda_callable__ DenseMatrixBase (const DenseMatrixBase &matrix)=default
 Copy constructor.
 
__cuda_callable__ DenseMatrixBase (DenseMatrixBase &&matrix) noexcept=default
 Move constructor.
 
__cuda_callable__ DenseMatrixBase (IndexType rows, IndexType columns, typename Base::ValuesViewType values)
 Constructor with matrix dimensions and values.
 
__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 Matrix &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.
 
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__ double getElement (IndexType row, IndexType column) const
 Returns value of matrix element at position given by its row and column index.
 
__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.
 
__cuda_callable__ IndexType getRowCapacity (IndexType row) const
 Returns capacity of given matrix row.
 
bool operator!= (const DenseMatrixBase< Real_, Device_, Index_, Organization > &matrix) const
 Comparison operator with another dense matrix view.
 
__cuda_callable__ double & operator() (IndexType row, IndexType column)
 Returns non-constant reference to element at row row and column column.
 
__cuda_callable__ const double & operator() (IndexType row, IndexType column) const
 Returns constant reference to element at row row and column column.
 
DenseMatrixBaseoperator= (const DenseMatrixBase &)=delete
 Copy-assignment operator.
 
DenseMatrixBaseoperator= (DenseMatrixBase &&)=delete
 Move-assignment operator.
 
bool operator== (const DenseMatrixBase< Real_, Device_, Index_, Organization > &matrix) const
 Comparison operator with another dense matrix view.
 
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 reduceRows (IndexType begin, IndexType end, Fetch &&fetch, const Reduce &reduce, Keep &&keep, const FetchValue &identity) const
 
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 &v)
 Sets all matrix elements to value v.
 
void vectorProduct (const InVector &inVector, OutVector &outVector, const RealType &matrixMultiplicator=1.0, const 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.
 
virtual IndexType getNonzeroElementsCount () const
 Computes a current number of nonzero matrix elements.
 
__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::DenseMatrixBase< 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

Base::SegmentsType segments
 Instance of the segments used for indexing in the dense matrix.
 
ValuesVectorType values
 Vector containing the allocated matrix elements.
 
- Protected Attributes inherited from TNL::Matrices::DenseMatrixBase< double, Devices::Host, int, Algorithms::Segments::DefaultElementsOrganization< Devices::Host >::getOrganization() >
SegmentsViewType segments
 
- Protected Attributes inherited from TNL::Matrices::MatrixBase< double, Devices::Host, int, GeneralMatrix, Organization >
IndexType columns
 
IndexType rows
 
ValuesViewType values
 

Additional Inherited Members

- Protected Types inherited from TNL::Matrices::DenseMatrixBase< double, Devices::Host, int, Algorithms::Segments::DefaultElementsOrganization< Devices::Host >::getOrganization() >
using Base
 
using SegmentsReductionKernel
 
using SegmentsType
 
using SegmentsViewType
 
using SegmentViewType
 
- Protected Member Functions inherited from TNL::Matrices::DenseMatrixBase< double, Devices::Host, int, Algorithms::Segments::DefaultElementsOrganization< Devices::Host >::getOrganization() >
__cuda_callable__ void bind (IndexType rows, IndexType columns, typename Base::ValuesViewType values, SegmentsViewType segments)
 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::DenseMatrix< Real, Device, Index, Organization, RealAllocator >

Implementation of dense matrix, i.e. matrix storing explicitly all of its elements including zeros.

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::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::ConstViewType = typename DenseMatrixView< Real, Device, Index, Organization >::ConstViewType

Matrix view type for constant instances.

See DenseMatrixView.

◆ 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::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::ViewType = DenseMatrixView< Real, Device, Index, Organization >

Type of related matrix view.

See DenseMatrixView.

Constructor & Destructor Documentation

◆ DenseMatrix() [1/5]

template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::DenseMatrix ( const RealAllocatorType & allocator = RealAllocatorType())

Constructor only with values allocator.

Parameters
allocatoris used for allocation of matrix elements values.

◆ DenseMatrix() [2/5]

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

Copy constructor.

Parameters
matrixis the source matrix

◆ DenseMatrix() [3/5]

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 >>
TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::DenseMatrix ( DenseMatrix< Real, Device, Index, Organization, RealAllocator > && matrix)
defaultnoexcept

Move constructor.

Parameters
matrixis the source matrix

◆ DenseMatrix() [4/5]

template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::DenseMatrix ( Index rows,
Index columns,
const RealAllocatorType & allocator = RealAllocatorType() )

Constructor with matrix dimensions.

Parameters
rowsis number of matrix rows.
columnsis number of matrix columns.
allocatoris used for allocation of matrix elements values.

◆ DenseMatrix() [5/5]

template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
template<typename Value >
TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::DenseMatrix ( std::initializer_list< std::initializer_list< Value > > data,
const RealAllocatorType & allocator = RealAllocatorType() )

Constructor with 2D initializer list.

The number of matrix rows is set to the outer list size and the number of matrix columns is set to maximum size of inner lists. Missing elements are filled in with zeros.

Parameters
datais a initializer list of initializer lists representing list of matrix rows.
allocatoris used for allocation of matrix elements values.
Example
#include <iostream>
#include <TNL/Matrices/DenseMatrix.h>
#include <TNL/Devices/Host.h>
template< typename Device >
void
initializerListExample()
{
// clang-format off
{ 1, 2, 3, 4, 5, 6 },
{ 7, 8, 9, 10, 11, 12 },
{ 13, 14, 15, 16, 17, 18 }
// clang-format on
};
std::cout << "General dense matrix: " << std::endl << matrix << std::endl;
// clang-format off
{ 1 },
{ 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9, 10 },
{ 11, 12, 13, 14, 15 }
// clang-format on
};
std::cout << "Triangular dense matrix: " << std::endl << triangularMatrix << std::endl;
}
int
main( int argc, char* argv[] )
{
std::cout << "Creating matrices on CPU ... " << std::endl;
initializerListExample< TNL::Devices::Host >();
#ifdef __CUDACC__
std::cout << "Creating matrices on CUDA GPU ... " << std::endl;
initializerListExample< TNL::Devices::Cuda >();
#endif
}
Implementation of dense matrix, i.e. matrix storing explicitly all of its elements including zeros.
Definition DenseMatrix.h:32
T endl(T... args)
Output
Creating matrices on CPU ...
General dense matrix:
Row: 0 -> 0:1 1:2 2:3 3:4 4:5 5:6
Row: 1 -> 0:7 1:8 2:9 3:10 4:11 5:12
Row: 2 -> 0:13 1:14 2:15 3:16 4:17 5:18
Triangular dense matrix:
Row: 0 -> 0:1 1:0 2:0 3:0 4:0
Row: 1 -> 0:2 1:3 2:0 3:0 4:0
Row: 2 -> 0:4 1:5 2:6 3:0 4:0
Row: 3 -> 0:7 1:8 2:9 3:10 4:0
Row: 4 -> 0:11 1:12 2:13 3:14 4:15
Creating matrices on CUDA GPU ...
General dense matrix:
Row: 0 -> 0:1 1:2 2:3 3:4 4:5 5:6
Row: 1 -> 0:7 1:8 2:9 3:10 4:11 5:12
Row: 2 -> 0:13 1:14 2:15 3:16 4:17 5:18
Triangular dense matrix:
Row: 0 -> 0:1 1:0 2:0 3:0 4:0
Row: 1 -> 0:2 1:3 2:0 3:0 4:0
Row: 2 -> 0:4 1:5 2:6 3:0 4:0
Row: 3 -> 0:7 1:8 2:9 3:10 4:0
Row: 4 -> 0:11 1:12 2:13 3:14 4:15

Member Function Documentation

◆ getConstView()

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

Returns a non-modifiable view of the dense matrix.

See DenseMatrixView.

Returns
dense matrix view.

◆ getInPlaceTransposition()

template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
template<int tileDim>
void TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::getInPlaceTransposition ( Real matrixMultiplicator = 1.0)

Performs an in-place transposition of this matrix.

This method transposes this matrix in place, modifying the original matrix. The operation can optionally scale the matrix by a specified factor.

Template Parameters
tileDimTile dimension for GPU computation optimization. Default is 16.
Parameters
matrixMultiplicatorA scalar value by which the matrix is scaled during the transposition. Default is 1.0.
Example
#include <iostream>
#include <TNL/Matrices/DenseMatrix.h>
#include <TNL/Devices/Host.h>
template< typename Device >
void
getInPlaceTranspositionExample()
{
// clang-format off
{ 1, 2, 3, 4 },
{ 6, 7, 8, 9 },
{ 10, 11, 12, 13 },
{ 14, 15, 16, 17 }
};
// clang-format on
std::cout << "Dense matrix: " << std::endl << matrix << std::endl;
matrix.getInPlaceTransposition();
std::cout << "Transposed dense matrix: " << std::endl << matrix << std::endl;
}
int
main( int argc, char* argv[] )
{
std::cout << "Creating matrix on CPU ... " << std::endl;
getInPlaceTranspositionExample< TNL::Devices::Host >();
#ifdef __CUDACC__
std::cout << "Creating matrix on CUDA GPU ... " << std::endl;
getInPlaceTranspositionExample< TNL::Devices::Cuda >();
#endif
}
Output
Creating matrix on CPU ...
Dense matrix:
Row: 0 -> 0:1 1:2 2:3 3:4
Row: 1 -> 0:6 1:7 2:8 3:9
Row: 2 -> 0:10 1:11 2:12 3:13
Row: 3 -> 0:14 1:15 2:16 3:17
Transposed dense matrix:
Row: 0 -> 0:1 1:6 2:10 3:14
Row: 1 -> 0:2 1:7 2:11 3:15
Row: 2 -> 0:3 1:8 2:12 3:16
Row: 3 -> 0:4 1:9 2:13 3:17
Creating matrix on CUDA GPU ...
Dense matrix:
Row: 0 -> 0:1 1:2 2:3 3:4
Row: 1 -> 0:6 1:7 2:8 3:9
Row: 2 -> 0:10 1:11 2:12 3:13
Row: 3 -> 0:14 1:15 2:16 3:17
Transposed dense matrix:
Row: 0 -> 0:1 1:6 2:10 3:14
Row: 1 -> 0:2 1:7 2:11 3:15
Row: 2 -> 0:3 1:8 2:12 3:16
Row: 3 -> 0:4 1:9 2:13 3:17

◆ getMatrixProduct()

template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
template<typename Matrix1 , typename Matrix2 , int tileDim>
void TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::getMatrixProduct ( const Matrix1 & matrix1,
const Matrix2 & matrix2,
Real matrixMultiplicator = 1.0,
TransposeState transposeA = TransposeState::None,
TransposeState transposeB = TransposeState::None )

Computes the product of two matrices and stores the result in this matrix.

This method calculates the product of two given matrices (matrix1 and matrix2) and stores the result in this matrix. It optionally supports transposing the input matrices before performing the multiplication and scaling the result by a specified factor.

Template Parameters
Matrix1Type of the first input matrix.
Matrix2Type of the second input matrix.
tileDimTile dimension for GPU computation optimization. Default is 16.
Parameters
matrix1The first input matrix.
matrix2The second input matrix.
matrixMultiplicatorA scalar value by which the matrix product is scaled. Default is 1.0.
transposeASpecifies whether to transpose matrix1 before multiplication. Default is TransposeState::None.
transposeBSpecifies whether to transpose matrix2 before multiplication. Default is TransposeState::None.
Example
#include "TNL/Algorithms/Segments/ElementsOrganization.h"
#include <iostream>
#include <TNL/Matrices/DenseMatrix.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
template< typename Device, TNL::Matrices::ElementsOrganization Organization >
void
matrixProductExample( TNL::Matrices::TransposeState transposeA, TNL::Matrices::TransposeState transposeB )
{
std::cout << "Matrix product (";
std::cout << ( transposeA == TNL::Matrices::TransposeState::Transpose ? "Transposed x " : "Normal x " );
std::cout << ( transposeB == TNL::Matrices::TransposeState::Transpose ? "Transposed)" : "Normal)" ) << std::endl;
if( transposeA == TNL::Matrices::TransposeState::Transpose ) {
// clang-format off
matrix1 = {
{ 5, 6, 6 },
{ 6, 5, 7 },
{ 7, 2, 1 },
{ 3, 3, 9 } };
// clang-format on
}
else {
// clang-format off
matrix1 = {
{ 5, 6, 7, 3 },
{ 6, 5, 2, 3 },
{ 6, 7, 1, 9 } };
// clang-format on
}
std::cout << "Dense matrix 1: " << std::endl << matrix1 << std::endl;
if( transposeB == TNL::Matrices::TransposeState::Transpose ) {
// clang-format off
matrix2 = {
{ 4, 3, 2, 6 },
{ 3, 4, 2, 8 },
{ 1, 4, 7, 9 },
{ 2, 3, 8, 0 },
{ 7, 6, 5, 4 } };
// clang-format on
}
else {
// clang-format off
matrix2 = {
{ 4, 3, 2, 6, 7 },
{ 3, 4, 2, 8, 6 },
{ 1, 4, 7, 9, 5 },
{ 2, 3, 8, 0, 4 } };
// clang-format on
}
std::cout << "Dense matrix 2: " << std::endl << matrix2 << std::endl;
resultMatrix.getMatrixProduct( matrix1, matrix2, 1.0, transposeA, transposeB );
std::cout << "Product: " << std::endl << resultMatrix << std::endl;
}
int
main( int argc, char* argv[] )
{
std::cout << "Creating matrices on CPU ... " << std::endl;
std::cout << "Stored in Row Major Order ... " << std::endl;
matrixProductExample< TNL::Devices::Host, TNL::Algorithms::Segments::ElementsOrganization::RowMajorOrder >(
TNL::Matrices::TransposeState::None, TNL::Matrices::TransposeState::None );
std::cout << "Stored in Column Major Order" << std::endl;
matrixProductExample< TNL::Devices::Host, TNL::Algorithms::Segments::ElementsOrganization::ColumnMajorOrder >(
TNL::Matrices::TransposeState::None, TNL::Matrices::TransposeState::None );
#ifdef __CUDACC__
std::cout << "Creating matrices on CUDA GPU ... " << std::endl;
std::cout << "Stored in Row Major Order ... " << std::endl;
matrixProductExample< TNL::Devices::Cuda, TNL::Algorithms::Segments::ElementsOrganization::RowMajorOrder >(
TNL::Matrices::TransposeState::None, TNL::Matrices::TransposeState::None );
std::cout << "Stored in Column Major Order ... " << std::endl;
matrixProductExample< TNL::Devices::Cuda, TNL::Algorithms::Segments::ElementsOrganization::ColumnMajorOrder >(
TNL::Matrices::TransposeState::None, TNL::Matrices::TransposeState::None );
std::cout << "Stored in Row Major Order ... " << std::endl;
matrixProductExample< TNL::Devices::Cuda, TNL::Algorithms::Segments::ElementsOrganization::RowMajorOrder >(
TNL::Matrices::TransposeState::Transpose, TNL::Matrices::TransposeState::None );
std::cout << "Stored in Column Major Order ... " << std::endl;
matrixProductExample< TNL::Devices::Cuda, TNL::Algorithms::Segments::ElementsOrganization::ColumnMajorOrder >(
TNL::Matrices::TransposeState::Transpose, TNL::Matrices::TransposeState::None );
std::cout << "Stored in Row Major Order ... " << std::endl;
matrixProductExample< TNL::Devices::Cuda, TNL::Algorithms::Segments::ElementsOrganization::RowMajorOrder >(
TNL::Matrices::TransposeState::None, TNL::Matrices::TransposeState::Transpose );
std::cout << "Stored in Column Major Order ... " << std::endl;
matrixProductExample< TNL::Devices::Cuda, TNL::Algorithms::Segments::ElementsOrganization::ColumnMajorOrder >(
TNL::Matrices::TransposeState::None, TNL::Matrices::TransposeState::Transpose );
std::cout << "Stored in Row Major Order ... " << std::endl;
matrixProductExample< TNL::Devices::Cuda, TNL::Algorithms::Segments::ElementsOrganization::RowMajorOrder >(
TNL::Matrices::TransposeState::Transpose, TNL::Matrices::TransposeState::Transpose );
std::cout << "Stored in Column Major Order ... " << std::endl;
matrixProductExample< TNL::Devices::Cuda, TNL::Algorithms::Segments::ElementsOrganization::ColumnMajorOrder >(
TNL::Matrices::TransposeState::Transpose, TNL::Matrices::TransposeState::Transpose );
#endif
}
void getMatrixProduct(const Matrix1 &matrix1, const Matrix2 &matrix2, Real matrixMultiplicator=1.0, TransposeState transposeA=TransposeState::None, TransposeState transposeB=TransposeState::None)
Computes the product of two matrices and stores the result in this matrix.
Definition DenseMatrix.hpp:158
Output
Creating matrices on CPU ...
Stored in Row Major Order ...
Matrix product (Normal x Normal)
Dense matrix 1:
Row: 0 -> 0:5 1:6 2:7 3:3
Row: 1 -> 0:6 1:5 2:2 3:3
Row: 2 -> 0:6 1:7 2:1 3:9
Dense matrix 2:
Row: 0 -> 0:4 1:3 2:2 3:6 4:7
Row: 1 -> 0:3 1:4 2:2 3:8 4:6
Row: 2 -> 0:1 1:4 2:7 3:9 4:5
Row: 3 -> 0:2 1:3 2:8 3:0 4:4
Product:
Row: 0 -> 0:51 1:76 2:95 3:141 4:118
Row: 1 -> 0:47 1:55 2:60 3:94 4:94
Row: 2 -> 0:64 1:77 2:105 3:101 4:125
Stored in Column Major Order
Matrix product (Normal x Normal)
Dense matrix 1:
Row: 0 -> 0:5 1:6 2:7 3:3
Row: 1 -> 0:6 1:5 2:2 3:3
Row: 2 -> 0:6 1:7 2:1 3:9
Dense matrix 2:
Row: 0 -> 0:4 1:3 2:2 3:6 4:7
Row: 1 -> 0:3 1:4 2:2 3:8 4:6
Row: 2 -> 0:1 1:4 2:7 3:9 4:5
Row: 3 -> 0:2 1:3 2:8 3:0 4:4
Product:
Row: 0 -> 0:51 1:76 2:95 3:141 4:118
Row: 1 -> 0:47 1:55 2:60 3:94 4:94
Row: 2 -> 0:64 1:77 2:105 3:101 4:125
Creating matrices on CUDA GPU ...
Stored in Row Major Order ...
Matrix product (Normal x Normal)
Dense matrix 1:
Row: 0 -> 0:5 1:6 2:7 3:3
Row: 1 -> 0:6 1:5 2:2 3:3
Row: 2 -> 0:6 1:7 2:1 3:9
Dense matrix 2:
Row: 0 -> 0:4 1:3 2:2 3:6 4:7
Row: 1 -> 0:3 1:4 2:2 3:8 4:6
Row: 2 -> 0:1 1:4 2:7 3:9 4:5
Row: 3 -> 0:2 1:3 2:8 3:0 4:4
Product:
Row: 0 -> 0:51 1:76 2:95 3:141 4:118
Row: 1 -> 0:47 1:55 2:60 3:94 4:94
Row: 2 -> 0:64 1:77 2:105 3:101 4:125
Stored in Column Major Order ...
Matrix product (Normal x Normal)
Dense matrix 1:
Row: 0 -> 0:5 1:6 2:7 3:3
Row: 1 -> 0:6 1:5 2:2 3:3
Row: 2 -> 0:6 1:7 2:1 3:9
Dense matrix 2:
Row: 0 -> 0:4 1:3 2:2 3:6 4:7
Row: 1 -> 0:3 1:4 2:2 3:8 4:6
Row: 2 -> 0:1 1:4 2:7 3:9 4:5
Row: 3 -> 0:2 1:3 2:8 3:0 4:4
Product:
Row: 0 -> 0:51 1:76 2:95 3:141 4:118
Row: 1 -> 0:47 1:55 2:60 3:94 4:94
Row: 2 -> 0:64 1:77 2:105 3:101 4:125
Stored in Row Major Order ...
Matrix product (Transposed x Normal)
Dense matrix 1:
Row: 0 -> 0:5 1:6 2:6
Row: 1 -> 0:6 1:5 2:7
Row: 2 -> 0:7 1:2 2:1
Row: 3 -> 0:3 1:3 2:9
Dense matrix 2:
Row: 0 -> 0:4 1:3 2:2 3:6 4:7
Row: 1 -> 0:3 1:4 2:2 3:8 4:6
Row: 2 -> 0:1 1:4 2:7 3:9 4:5
Row: 3 -> 0:2 1:3 2:8 3:0 4:4
Product:
Row: 0 -> 0:51 1:76 2:95 3:141 4:118
Row: 1 -> 0:47 1:55 2:60 3:94 4:94
Row: 2 -> 0:64 1:77 2:105 3:101 4:125
Stored in Column Major Order ...
Matrix product (Transposed x Normal)
Dense matrix 1:
Row: 0 -> 0:5 1:6 2:6
Row: 1 -> 0:6 1:5 2:7
Row: 2 -> 0:7 1:2 2:1
Row: 3 -> 0:3 1:3 2:9
Dense matrix 2:
Row: 0 -> 0:4 1:3 2:2 3:6 4:7
Row: 1 -> 0:3 1:4 2:2 3:8 4:6
Row: 2 -> 0:1 1:4 2:7 3:9 4:5
Row: 3 -> 0:2 1:3 2:8 3:0 4:4
Product:
Row: 0 -> 0:51 1:76 2:95 3:141 4:118
Row: 1 -> 0:47 1:55 2:60 3:94 4:94
Row: 2 -> 0:64 1:77 2:105 3:101 4:125
Stored in Row Major Order ...
Matrix product (Normal x Transposed)
Dense matrix 1:
Row: 0 -> 0:5 1:6 2:7 3:3
Row: 1 -> 0:6 1:5 2:2 3:3
Row: 2 -> 0:6 1:7 2:1 3:9
Dense matrix 2:
Row: 0 -> 0:4 1:3 2:2 3:6
Row: 1 -> 0:3 1:4 2:2 3:8
Row: 2 -> 0:1 1:4 2:7 3:9
Row: 3 -> 0:2 1:3 2:8 3:0
Row: 4 -> 0:7 1:6 2:5 3:4
Product:
Row: 0 -> 0:70 1:77 2:105 3:84 4:118
Row: 1 -> 0:61 1:66 2:67 3:43 4:94
Row: 2 -> 0:101 1:120 2:122 3:41 4:125
Stored in Column Major Order ...
Matrix product (Normal x Transposed)
Dense matrix 1:
Row: 0 -> 0:5 1:6 2:7 3:3
Row: 1 -> 0:6 1:5 2:2 3:3
Row: 2 -> 0:6 1:7 2:1 3:9
Dense matrix 2:
Row: 0 -> 0:4 1:3 2:2 3:6
Row: 1 -> 0:3 1:4 2:2 3:8
Row: 2 -> 0:1 1:4 2:7 3:9
Row: 3 -> 0:2 1:3 2:8 3:0
Row: 4 -> 0:7 1:6 2:5 3:4
Product:
Row: 0 -> 0:70 1:77 2:105 3:84 4:118
Row: 1 -> 0:61 1:66 2:67 3:43 4:94
Row: 2 -> 0:101 1:120 2:122 3:41 4:125
Stored in Row Major Order ...
Matrix product (Transposed x Transposed)
Dense matrix 1:
Row: 0 -> 0:5 1:6 2:6
Row: 1 -> 0:6 1:5 2:7
Row: 2 -> 0:7 1:2 2:1
Row: 3 -> 0:3 1:3 2:9
Dense matrix 2:
Row: 0 -> 0:4 1:3 2:2 3:6
Row: 1 -> 0:3 1:4 2:2 3:8
Row: 2 -> 0:1 1:4 2:7 3:9
Row: 3 -> 0:2 1:3 2:8 3:0
Row: 4 -> 0:7 1:6 2:5 3:4
Product:
Row: 0 -> 0:70 1:77 2:105 3:84 4:118
Row: 1 -> 0:61 1:66 2:67 3:43 4:94
Row: 2 -> 0:101 1:120 2:122 3:41 4:125
Stored in Column Major Order ...
Matrix product (Transposed x Transposed)
Dense matrix 1:
Row: 0 -> 0:5 1:6 2:6
Row: 1 -> 0:6 1:5 2:7
Row: 2 -> 0:7 1:2 2:1
Row: 3 -> 0:3 1:3 2:9
Dense matrix 2:
Row: 0 -> 0:4 1:3 2:2 3:6
Row: 1 -> 0:3 1:4 2:2 3:8
Row: 2 -> 0:1 1:4 2:7 3:9
Row: 3 -> 0:2 1:3 2:8 3:0
Row: 4 -> 0:7 1:6 2:5 3:4
Product:
Row: 0 -> 0:70 1:77 2:105 3:84 4:118
Row: 1 -> 0:61 1:66 2:67 3:43 4:94
Row: 2 -> 0:101 1:120 2:122 3:41 4:125

◆ 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::DenseMatrixBase< Real, Device, Index, Organization >::getSerializationType ( )
staticnodiscard

Returns string with serialization type.

The string has a form `MatricesDenseMatrix< RealType, [any_device], IndexType, [any_allocator], true/false >`.

Returns
String with the serialization type.

◆ getTransposition()

template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
template<typename Matrix , int tileDim>
void TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::getTransposition ( const Matrix & matrix,
Real matrixMultiplicator = 1.0 )

Computes the transposition of a given matrix and stores the result in this matrix.

This method calculates the transpose of a given matrix and stores the result in this matrix. The result can also be scaled by a specified factor.

Template Parameters
MatrixType of the input matrix.
tileDimTile dimension for GPU computation optimization. Default is 16.
Parameters
matrixThe input matrix to be transposed.
matrixMultiplicatorA scalar value by which the transposed matrix is scaled. Default is 1.0.
Example
#include <iostream>
#include <TNL/Matrices/DenseMatrix.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
template< typename Device >
void
getTranspositionExample()
{
// clang-format off
{ 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 },
{ 10, 11, 12 },
{ 13, 14, 15 } };
// clang-format on
std::cout << "Dense matrix: " << std::endl << matrix << std::endl;
outputMatrix.getTransposition( matrix );
std::cout << "Transposed dense matrix: " << std::endl << outputMatrix << std::endl;
}
int
main( int argc, char* argv[] )
{
std::cout << "Creating matrix on CPU ... " << std::endl;
getTranspositionExample< TNL::Devices::Host >();
#ifdef __CUDACC__
std::cout << "Creating matrix on CUDA GPU ... " << std::endl;
getTranspositionExample< TNL::Devices::Cuda >();
#endif
}
void getTransposition(const Matrix &matrix, Real matrixMultiplicator=1.0)
Computes the transposition of a given matrix and stores the result in this matrix.
Definition DenseMatrix.hpp:170
Output
Creating matrix on CPU ...
Dense matrix:
Row: 0 -> 0:1 1:2 2:3
Row: 1 -> 0:4 1:5 2:6
Row: 2 -> 0:7 1:8 2:9
Row: 3 -> 0:10 1:11 2:12
Row: 4 -> 0:13 1:14 2:15
Transposed dense matrix:
Row: 0 -> 0:1 1:4 2:7 3:10 4:13
Row: 1 -> 0:2 1:5 2:8 3:11 4:14
Row: 2 -> 0:3 1:6 2:9 3:12 4:15
Creating matrix on CUDA GPU ...
Dense matrix:
Row: 0 -> 0:1 1:2 2:3
Row: 1 -> 0:4 1:5 2:6
Row: 2 -> 0:7 1:8 2:9
Row: 3 -> 0:10 1:11 2:12
Row: 4 -> 0:13 1:14 2:15
Transposed dense matrix:
Row: 0 -> 0:1 1:4 2:7 3:10 4:13
Row: 1 -> 0:2 1:5 2:8 3:11 4:14
Row: 2 -> 0:3 1:6 2:9 3:12 4:15

◆ getView()

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

Returns a modifiable view of the dense matrix.

See DenseMatrixView.

Returns
dense matrix view.

◆ load() [1/2]

template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
void TNL::Matrices::DenseMatrix< 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::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::load ( File & file)
overridevirtual

Method for loading the matrix from a file.

Parameters
fileis the file from which the matrix will be loaded.

Reimplemented from TNL::Object.

◆ operator=() [1/7]

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 >>
DenseMatrix & TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::operator= ( const DenseMatrix< Real, Device, Index, Organization, RealAllocator > & matrix)

Copy-assignment of exactly the same matrix type.

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

◆ operator=() [2/7]

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 RHSReal , typename RHSDevice , typename RHSIndex , typename RHSRealAllocator >
DenseMatrix & TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::operator= ( const DenseMatrix< RHSReal, RHSDevice, RHSIndex, Organization, RHSRealAllocator > & matrix)

Assignment operator with the same organization.

Parameters
matrixis the right-hand side matrix.
Returns
reference to this matrix.

◆ operator=() [3/7]

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 RHSReal , typename RHSDevice , typename RHSIndex , ElementsOrganization RHSOrganization, typename RHSRealAllocator >
DenseMatrix & TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::operator= ( const DenseMatrix< RHSReal, RHSDevice, RHSIndex, RHSOrganization, RHSRealAllocator > & matrix)

Assignment operator with other dense matrices.

Parameters
matrixis the right-hand side matrix.
Returns
reference to this matrix.

◆ operator=() [4/7]

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 RHSReal , typename RHSDevice , typename RHSIndex >
DenseMatrix & TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::operator= ( const DenseMatrixView< RHSReal, RHSDevice, RHSIndex, Organization > & matrix)

Assignment operator with matrix view having the same elements organization.

Parameters
matrixis the right-hand side matrix.
Returns
reference to this matrix.

◆ operator=() [5/7]

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 RHSReal , typename RHSDevice , typename RHSIndex , ElementsOrganization RHSOrganization>
DenseMatrix & TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::operator= ( const DenseMatrixView< RHSReal, RHSDevice, RHSIndex, RHSOrganization > & matrix)

Assignment operator with other dense matrices.

Parameters
matrixis the right-hand side matrix.
Returns
reference to this matrix.

◆ operator=() [6/7]

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 RHSMatrix >
DenseMatrix & TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::operator= ( const RHSMatrix & matrix)

Assignment operator with other (sparse) types of matrices.

Parameters
matrixis the right-hand side matrix.
Returns
reference to this matrix.

◆ operator=() [7/7]

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 >>
DenseMatrix & TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::operator= ( DenseMatrix< Real, Device, Index, Organization, RealAllocator > && matrix)

Move-assignment of exactly the same matrix type.

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::DenseMatrix< 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::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::save ( File & file) const
overridevirtual

Method for saving the matrix to a file.

Parameters
fileis the file where the matrix will be saved.

Reimplemented from TNL::Object.

◆ setDimensions()

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

Set number of rows and columns of this matrix.

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

◆ setElements() [1/2]

template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
template<typename MapIndex , typename MapValue >
void TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::setElements ( const std::map< std::pair< MapIndex, MapIndex >, MapValue > & map)

This method sets the dense matrix elements from std::map.

This is intended for compatibility with SparseMatrix, the method is used e.g. in MatrixReader.

The matrix elements values are given as a map data where keys are std::pair of matrix coordinates ( {row, column} ) and value is the matrix element value.

Template Parameters
MapIndexis a type for indexing rows and columns.
MapValueis a type for matrix elements values in the map.
Parameters
mapis std::map containing matrix elements.

◆ setElements() [2/2]

template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator >
template<typename Value >
void TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::setElements ( std::initializer_list< std::initializer_list< Value > > data)

This method recreates the dense matrix from 2D initializer list.

The number of matrix rows is set to the outer list size and the number of matrix columns is set to maximum size of inner lists. Missing elements are filled in with zeros.

Parameters
datais a initializer list of initializer lists representing list of matrix rows.
Example
#include <iostream>
#include <TNL/Matrices/DenseMatrix.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
template< typename Device >
void
setElementsExample()
{
matrix.setElements( {
// clang-format off
{ 1, 2, 3, 4, 5, 6 },
{ 7, 8, 9, 10, 11, 12 },
{ 13, 14, 15, 16, 17, 18 }
// clang-format on
} );
std::cout << matrix << std::endl;
triangularMatrix.setElements( {
// clang-format off
{ 1 },
{ 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9, 10 },
{ 11, 12, 13, 14, 15 }
// clang-format on
} );
std::cout << triangularMatrix << std::endl;
}
int
main( int argc, char* argv[] )
{
std::cout << "Setting matrix elements on host: " << std::endl;
setElementsExample< TNL::Devices::Host >();
#ifdef __CUDACC__
std::cout << "Setting matrix elements on CUDA device: " << std::endl;
setElementsExample< TNL::Devices::Cuda >();
#endif
}
void setElements(std::initializer_list< std::initializer_list< Value > > data)
This method recreates the dense matrix from 2D initializer list.
Definition DenseMatrix.hpp:50
Output
Setting matrix elements on host:
Row: 0 -> 0:1 1:2 2:3 3:4 4:5 5:6
Row: 1 -> 0:7 1:8 2:9 3:10 4:11 5:12
Row: 2 -> 0:13 1:14 2:15 3:16 4:17 5:18
Row: 0 -> 0:1 1:0 2:0 3:0 4:0
Row: 1 -> 0:2 1:3 2:0 3:0 4:0
Row: 2 -> 0:4 1:5 2:6 3:0 4:0
Row: 3 -> 0:7 1:8 2:9 3:10 4:0
Row: 4 -> 0:11 1:12 2:13 3:14 4:15
Setting matrix elements on CUDA device:
Row: 0 -> 0:1 1:2 2:3 3:4 4:5 5:6
Row: 1 -> 0:7 1:8 2:9 3:10 4:11 5:12
Row: 2 -> 0:13 1:14 2:15 3:16 4:17 5:18
Row: 0 -> 0:1 1:0 2:0 3:0 4:0
Row: 1 -> 0:2 1:3 2:0 3:0 4:0
Row: 2 -> 0:4 1:5 2:6 3:0 4:0
Row: 3 -> 0:7 1:8 2:9 3:10 4:0
Row: 4 -> 0:11 1:12 2:13 3:14 4:15

◆ setLike()

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 Matrix >
void TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::setLike ( const Matrix & matrix)

Set the number of matrix rows and columns by the given matrix.

Template Parameters
Matrixis matrix type. This can be any matrix having methods getRows and getColumns.
Parameters
matrixin the input matrix dimensions of which are to be adopted.

◆ setRowCapacities()

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

This method is only for the compatibility with the sparse matrices.

This method does nothing. In debug mode it contains assertions checking that given rowCapacities are compatible with the current matrix dimensions.


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