Ginkgo  Generated from pipelines/1330831941 branch based on master. Ginkgo version 1.8.0
A numerical linear algebra library targeting many-core architectures
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
gko::matrix_data< ValueType, IndexType > Struct Template Reference

This structure is used as an intermediate data type to store a sparse matrix. More...

#include <ginkgo/core/base/matrix_data.hpp>

Collaboration diagram for gko::matrix_data< ValueType, IndexType >:
[legend]

Public Types

using value_type = ValueType
 
using index_type = IndexType
 
using nonzero_type = matrix_data_entry< value_type, index_type >
 

Public Member Functions

 matrix_data (dim< 2 > size_=dim< 2 >{}, ValueType value=zero< ValueType >())
 Initializes a matrix filled with the specified value. More...
 
template<typename RandomDistribution , typename RandomEngine >
 matrix_data (dim< 2 > size_, RandomDistribution &&dist, RandomEngine &&engine)
 Initializes a matrix with random values from the specified distribution. More...
 
 matrix_data (std::initializer_list< std::initializer_list< ValueType >> values)
 List-initializes the structure from a matrix of values. More...
 
 matrix_data (dim< 2 > size_, std::initializer_list< detail::input_triple< ValueType, IndexType >> nonzeros_)
 Initializes the structure from a list of nonzeros. More...
 
 matrix_data (dim< 2 > size_, const matrix_data &block)
 Initializes a matrix out of a matrix block via duplication. More...
 
template<typename Accessor >
 matrix_data (const range< Accessor > &data)
 Initializes a matrix from a range. More...
 
void sort_row_major ()
 Sorts the nonzero vector so the values follow row-major order.
 
void ensure_row_major_order ()
 Sorts the nonzero vector so the values follow row-major order.
 
void remove_zeros ()
 Remove entries with value zero from the matrix data.
 
void sum_duplicates ()
 Sum up all values that refer to the same matrix entry. More...
 

Static Public Member Functions

static matrix_data diag (dim< 2 > size_, ValueType value)
 Initializes a diagonal matrix. More...
 
static matrix_data diag (dim< 2 > size_, std::initializer_list< ValueType > nonzeros_)
 Initializes a diagonal matrix using a list of diagonal elements. More...
 
static matrix_data diag (dim< 2 > size_, const matrix_data &block)
 Initializes a block-diagonal matrix. More...
 
template<typename ForwardIterator >
static matrix_data diag (ForwardIterator begin, ForwardIterator end)
 Initializes a block-diagonal matrix from a list of diagonal blocks. More...
 
static matrix_data diag (std::initializer_list< matrix_data > blocks)
 Initializes a block-diagonal matrix from a list of diagonal blocks. More...
 
template<typename RandomDistribution , typename RandomEngine >
static matrix_data cond (size_type size, remove_complex< ValueType > condition_number, RandomDistribution &&dist, RandomEngine &&engine, size_type num_reflectors)
 Initializes a random dense matrix with a specific condition number. More...
 
template<typename RandomDistribution , typename RandomEngine >
static matrix_data cond (size_type size, remove_complex< ValueType > condition_number, RandomDistribution &&dist, RandomEngine &&engine)
 Initializes a random dense matrix with a specific condition number. More...
 

Public Attributes

dim< 2 > size
 Size of the matrix.
 
std::vector< nonzero_typenonzeros
 A vector of tuples storing the non-zeros of the matrix. More...
 

Detailed Description

template<typename ValueType = default_precision, typename IndexType = int32>
struct gko::matrix_data< ValueType, IndexType >

This structure is used as an intermediate data type to store a sparse matrix.

The matrix is stored as a sequence of nonzero elements, where each element is a triple of the form (row_index, column_index, value).

Note
All Ginkgo functions returning such a structure will return the nonzeros sorted in row-major order.
All Ginkgo functions that take this structure as input expect that the nonzeros are sorted in row-major order and that the index pair (row_index, column_index) of each nonzero is unique.
This structure is not optimized for usual access patterns and it can only exist on the CPU. Thus, it should only be used for utility functions which do not have to be optimized for performance.
Template Parameters
ValueTypetype of matrix values stored in the structure
IndexTypetype of matrix indexes stored in the structure

Constructor & Destructor Documentation

◆ matrix_data() [1/6]

template<typename ValueType = default_precision, typename IndexType = int32>
gko::matrix_data< ValueType, IndexType >::matrix_data ( dim< 2 >  size_ = dim<2>{},
ValueType  value = zero<ValueType>() 
)
inline

Initializes a matrix filled with the specified value.

Parameters
size_dimensions of the matrix
valuevalue used to fill the elements of the matrix

◆ matrix_data() [2/6]

template<typename ValueType = default_precision, typename IndexType = int32>
template<typename RandomDistribution , typename RandomEngine >
gko::matrix_data< ValueType, IndexType >::matrix_data ( dim< 2 >  size_,
RandomDistribution &&  dist,
RandomEngine &&  engine 
)
inline

Initializes a matrix with random values from the specified distribution.

Template Parameters
RandomDistributionrandom distribution type
RandomEnginerandom engine type
Parameters
size_dimensions of the matrix
distrandom distribution of the elements of the matrix
enginerandom engine used to generate random values

◆ matrix_data() [3/6]

template<typename ValueType = default_precision, typename IndexType = int32>
gko::matrix_data< ValueType, IndexType >::matrix_data ( std::initializer_list< std::initializer_list< ValueType >>  values)
inline

List-initializes the structure from a matrix of values.

Parameters
valuesa 2D braced-init-list of matrix values.

◆ matrix_data() [4/6]

template<typename ValueType = default_precision, typename IndexType = int32>
gko::matrix_data< ValueType, IndexType >::matrix_data ( dim< 2 >  size_,
std::initializer_list< detail::input_triple< ValueType, IndexType >>  nonzeros_ 
)
inline

Initializes the structure from a list of nonzeros.

Parameters
size_dimensions of the matrix
nonzeros_list of nonzero elements

◆ matrix_data() [5/6]

template<typename ValueType = default_precision, typename IndexType = int32>
gko::matrix_data< ValueType, IndexType >::matrix_data ( dim< 2 >  size_,
const matrix_data< ValueType, IndexType > &  block 
)
inline

Initializes a matrix out of a matrix block via duplication.

Parameters
sizesize of the block-matrix (in blocks)
diag_blockmatrix block used to fill the complete matrix

References gko::matrix_data< ValueType, IndexType >::size.

◆ matrix_data() [6/6]

template<typename ValueType = default_precision, typename IndexType = int32>
template<typename Accessor >
gko::matrix_data< ValueType, IndexType >::matrix_data ( const range< Accessor > &  data)
inline

Initializes a matrix from a range.

Template Parameters
Accessoraccessor type of the input range
Parameters
datarange used to initialize the matrix

References gko::range< Accessor >::length().

Member Function Documentation

◆ cond() [1/2]

template<typename ValueType = default_precision, typename IndexType = int32>
template<typename RandomDistribution , typename RandomEngine >
static matrix_data gko::matrix_data< ValueType, IndexType >::cond ( size_type  size,
remove_complex< ValueType >  condition_number,
RandomDistribution &&  dist,
RandomEngine &&  engine 
)
inlinestatic

Initializes a random dense matrix with a specific condition number.

The matrix is generated by applying a series of random Hausholder reflectors to a diagonal matrix with diagonal entries uniformly distributed between sqrt(condition_number) and 1/sqrt(condition_number).

This version of the function applies size - 1 reflectors to each side of the diagonal matrix.

Template Parameters
RandomDistributionthe type of the random distribution
RandomEnginethe type of the random engine
Parameters
sizenumber of rows and columns of the matrix
condition_numbercondition number of the matrix
distrandom distribution used to generate reflectors
enginerandom engine used to generate reflectors
Returns
the dense matrix with the specified condition number

References gko::matrix_data< ValueType, IndexType >::cond(), and gko::matrix_data< ValueType, IndexType >::size.

◆ cond() [2/2]

template<typename ValueType = default_precision, typename IndexType = int32>
template<typename RandomDistribution , typename RandomEngine >
static matrix_data gko::matrix_data< ValueType, IndexType >::cond ( size_type  size,
remove_complex< ValueType >  condition_number,
RandomDistribution &&  dist,
RandomEngine &&  engine,
size_type  num_reflectors 
)
inlinestatic

Initializes a random dense matrix with a specific condition number.

The matrix is generated by applying a series of random Hausholder reflectors to a diagonal matrix with diagonal entries uniformly distributed between sqrt(condition_number) and 1/sqrt(condition_number).

Template Parameters
RandomDistributionthe type of the random distribution
RandomEnginethe type of the random engine
Parameters
sizenumber of rows and columns of the matrix
condition_numbercondition number of the matrix
distrandom distribution used to generate reflectors
enginerandom engine used to generate reflectors
num_reflectorsnumber of reflectors to apply from each side
Returns
the dense matrix with the specified condition number

References gko::matrix_data< ValueType, IndexType >::size.

Referenced by gko::matrix_data< ValueType, IndexType >::cond().

◆ diag() [1/5]

template<typename ValueType = default_precision, typename IndexType = int32>
static matrix_data gko::matrix_data< ValueType, IndexType >::diag ( dim< 2 >  size_,
const matrix_data< ValueType, IndexType > &  block 
)
inlinestatic

Initializes a block-diagonal matrix.

Parameters
size_the size of the matrix
diag_blockmatrix used to fill diagonal blocks
Returns
the block-diagonal matrix

References gko::matrix_data< ValueType, IndexType >::nonzeros, and gko::matrix_data< ValueType, IndexType >::size.

◆ diag() [2/5]

template<typename ValueType = default_precision, typename IndexType = int32>
static matrix_data gko::matrix_data< ValueType, IndexType >::diag ( dim< 2 >  size_,
std::initializer_list< ValueType >  nonzeros_ 
)
inlinestatic

Initializes a diagonal matrix using a list of diagonal elements.

Parameters
size_dimensions of the matrix
nonzeros_list of diagonal elements
Returns
the diagonal matrix

References gko::matrix_data< ValueType, IndexType >::nonzeros.

◆ diag() [3/5]

template<typename ValueType = default_precision, typename IndexType = int32>
static matrix_data gko::matrix_data< ValueType, IndexType >::diag ( dim< 2 >  size_,
ValueType  value 
)
inlinestatic

Initializes a diagonal matrix.

Parameters
size_dimensions of the matrix
valuevalue used to fill the elements of the matrix
Returns
the diagonal matrix

References gko::is_nonzero(), and gko::matrix_data< ValueType, IndexType >::nonzeros.

Referenced by gko::matrix_data< ValueType, IndexType >::diag().

◆ diag() [4/5]

template<typename ValueType = default_precision, typename IndexType = int32>
template<typename ForwardIterator >
static matrix_data gko::matrix_data< ValueType, IndexType >::diag ( ForwardIterator  begin,
ForwardIterator  end 
)
inlinestatic

Initializes a block-diagonal matrix from a list of diagonal blocks.

Template Parameters
ForwardIteratortype of list iterator
Parameters
beginthe first iterator of the list
endthe last iterator of the list
Returns
the block-diagonal matrix with diagonal blocks set to the blocks between begin (inclusive) and end (exclusive)

References gko::matrix_data< ValueType, IndexType >::nonzeros.

◆ diag() [5/5]

template<typename ValueType = default_precision, typename IndexType = int32>
static matrix_data gko::matrix_data< ValueType, IndexType >::diag ( std::initializer_list< matrix_data< ValueType, IndexType > >  blocks)
inlinestatic

Initializes a block-diagonal matrix from a list of diagonal blocks.

Parameters
blocksa list of blocks to initialize from
Returns
the block-diagonal matrix with diagonal blocks set to the blocks passed in blocks

References gko::matrix_data< ValueType, IndexType >::diag().

◆ sum_duplicates()

template<typename ValueType = default_precision, typename IndexType = int32>
void gko::matrix_data< ValueType, IndexType >::sum_duplicates ( )
inline

Sum up all values that refer to the same matrix entry.

The result is sorted in row-major order.

References gko::matrix_data< ValueType, IndexType >::nonzeros, and gko::matrix_data< ValueType, IndexType >::sort_row_major().

Member Data Documentation

◆ nonzeros

template<typename ValueType = default_precision, typename IndexType = int32>
std::vector<nonzero_type> gko::matrix_data< ValueType, IndexType >::nonzeros

A vector of tuples storing the non-zeros of the matrix.

The first two elements of the tuple are the row index and the column index of a matrix element, and its third element is the value at that position.

Referenced by gko::matrix_data< ValueType, IndexType >::diag(), gko::matrix_data< ValueType, IndexType >::remove_zeros(), gko::matrix_data< ValueType, IndexType >::sort_row_major(), and gko::matrix_data< ValueType, IndexType >::sum_duplicates().


The documentation for this struct was generated from the following file: