Ginkgo: gko::batch::matrix::Csr< ValueType, IndexType > Class Template Reference

| Ginkgo Generated from branch based on main. Ginkgo version 1.11.0 A numerical linear algebra library targeting many-core architectures

Loading...
Searching...
No Matches
gko::batch::matrix::Csr< ValueType, IndexType > Class Template Referencefinal
Linear Operators » SpMV employing different Matrix formats | BatchLinOp

Csr is a general sparse matrix format that stores the column indices for each nonzero entry and a cumulative sum of the number of nonzeros in each row. More...

`#include <ginkgo/core/matrix/batch_csr.hpp>`

Inheritance diagram for gko::batch::matrix::Csr< ValueType, IndexType >:
[legend]
Collaboration diagram for gko::batch::matrix::Csr< ValueType, IndexType >:
[legend]

## Public Types
using | value_type = ValueType
using | index_type = IndexType
using | unbatch_type = gko::matrix::Csr<value_type, index_type>
using | absolute_type = remove_complex<Csr>
using | complex_type = to_complex<Csr>
Public Types inherited from gko::EnablePolymorphicAssignment< Csr< default_precision, int32 > >
using | result_type

## Public Member Functions
void | convert_to (Csr< next_precision< ValueType >, IndexType > *result) const override
void | move_to (Csr< next_precision< ValueType >, IndexType > *result) override
std::unique_ptr< unbatch_type > | create_view_for_item (size_type item_id)
| Creates a mutable view (of matrix::Csr type) of one item of the batch::matrix::Csr<value_type> object.
std::unique_ptr< const unbatch_type > | create_const_view_for_item (size_type item_id) const
| Creates a mutable view (of matrix::Csr type) of one item of the batch::matrix::Csr<value_type> object.
value_type * | get_values () noexcept
| Returns a pointer to the array of values of the matrix.
const value_type * | get_const_values () const noexcept
| Returns a pointer to the array of values of the matrix.
index_type * | get_col_idxs () noexcept
| Returns a pointer to the array of column indices of the matrix.
const index_type * | get_const_col_idxs () const noexcept
| Returns a pointer to the array of column indices of the matrix.
index_type * | get_row_ptrs () noexcept
| Returns a pointer to the array of row pointers of the matrix.
const index_type * | get_const_row_ptrs () const noexcept
| Returns a pointer to the array of row pointers of the matrix.
size_type | get_num_stored_elements () const noexcept
| Returns the number of elements explicitly stored in the batch matrix, cumulative across all the batch items.
size_type | get_num_elements_per_item () const noexcept
| Returns the number of stored elements in each batch item.
value_type * | get_values_for_item (size_type batch_id) noexcept
| Returns a pointer to the array of values of the matrix for a specific batch item.
const value_type * | get_const_values_for_item (size_type batch_id) const noexcept
| Returns a pointer to the array of values of the matrix for a specific batch item.
Csr * | apply (ptr_param< const MultiVector< value_type > > b, ptr_param< MultiVector< value_type > > x)
| Apply the matrix to a multi-vector.
Csr * | apply (ptr_param< const MultiVector< value_type > > alpha, ptr_param< const MultiVector< value_type > > b, ptr_param< const MultiVector< value_type > > beta, ptr_param< MultiVector< value_type > > x)
| Apply the matrix to a multi-vector with a linear combination of the given input vector.
const Csr * | apply (ptr_param< const MultiVector< value_type > > b, ptr_param< MultiVector< value_type > > x) const
const Csr * | apply (ptr_param< const MultiVector< value_type > > alpha, ptr_param< const MultiVector< value_type > > b, ptr_param< const MultiVector< value_type > > beta, ptr_param< MultiVector< value_type > > x) const
void | scale (const array< value_type > &row_scale, const array< value_type > &col_scale)
| Performs in-place row and column scaling for this matrix.
void | add_scaled_identity (ptr_param< const MultiVector< value_type > > alpha, ptr_param< const MultiVector< value_type > > beta)
| Performs the operation this = alpha*I + beta*this.
Public Member Functions inherited from gko::EnablePolymorphicAssignment< Csr< default_precision, int32 > >
void | convert_to (result_type *result) const override
void | move_to (result_type *result) override

## Static Public Member Functions
static std::unique_ptr< Csr > | create (std::shared_ptr< const Executor > exec, const batch_dim< 2 > &size=batch_dim< 2 >{}, size_type num_nonzeros_per_item={})
| Creates an uninitialized Csr matrix of the specified size.
static std::unique_ptr< Csr > | create (std::shared_ptr< const Executor > exec, const batch_dim< 2 > &size, array< value_type > values, array< index_type > col_idxs, array< index_type > row_ptrs)
| Creates a Csr matrix from an already allocated (and initialized) array.
template<typename InputValueType, typename ColIndexType, typename RowPtrType>
static std::unique_ptr< Csr > | create (std::shared_ptr< const Executor > exec, const batch_dim< 2 > &size, std::initializer_list< InputValueType > values, std::initializer_list< ColIndexType > col_idxs, std::initializer_list< RowPtrType > row_ptrs)
| create(std::shared_ptr<const Executor>,const batch_dim<2>&, array<value_type>, array<index_type>,array<index_type>)
static std::unique_ptr< const Csr > | create_const (std::shared_ptr< const Executor > exec, const batch_dim< 2 > &sizes, gko::detail::const_array_view< value_type > &&values, gko::detail::const_array_view< index_type > &&col_idxs, gko::detail::const_array_view< index_type > &&row_ptrs)
| Creates a constant (immutable) batch csr matrix from a constant array.

## Friends
class | EnablePolymorphicObject< Csr, BatchLinOp >
class | Csr< to_complex< ValueType >, IndexType >
class | Csr< previous_precision< ValueType >, IndexType >

## Detailed Description

template<typename ValueType = default_precision, typename IndexType = int32>
class gko::batch::matrix::Csr< ValueType, IndexType >

Csr is a general sparse matrix format that stores the column indices for each nonzero entry and a cumulative sum of the number of nonzeros in each row.

It is one of the most popular sparse matrix formats due to its versatility and ability to store a wide range of sparsity patterns in an efficient fashion.

Note
  It is assumed that the sparsity pattern of all the items in the batch is the same and therefore only a single copy of the sparsity pattern is stored.
  Currently only IndexType of int32 is supported.

Template Parameters

  ValueType | value precision of matrix elements
  IndexType | index precision of matrix elements

## Member Function Documentation

## ◆ add_scaled_identity()

template<typename ValueType = default_precision, typename IndexType = int32>

void gko::batch::matrix::Csr< ValueType, IndexType >::add_scaled_identity | ( | ptr_param< const MultiVector< value_type > > | alpha,
|  | ptr_param< const MultiVector< value_type > > | beta )

Performs the operation this = alpha*I + beta*this.

Parameters

  alpha | the scalar for identity
  beta | the scalar to multiply this matrix

Note
  Performs the operation in-place for this batch matrix
  This operation fails in case this matrix does not have all its diagonal entries.

## ◆ apply() [1/4]

template<typename ValueType = default_precision, typename IndexType = int32>

Csr * gko::batch::matrix::Csr< ValueType, IndexType >::apply | ( | ptr_param< const MultiVector< value_type > > | alpha,
|  | ptr_param< const MultiVector< value_type > > | b,
|  | ptr_param< const MultiVector< value_type > > | beta,
|  | ptr_param< MultiVector< value_type > > | x )

Apply the matrix to a multi-vector with a linear combination of the given input vector.

Represents the matrix vector multiplication, x = alpha * A

- b + beta * x, where x and b are both multi-vectors.

Parameters

  alpha | the scalar to scale the matrix-vector product with
  b | the multi-vector to be applied to
  beta | the scalar to scale the x vector with
  x | the output multi-vector

## ◆ apply() [2/4]

template<typename ValueType = default_precision, typename IndexType = int32>

const Csr * gko::batch::matrix::Csr< ValueType, IndexType >::apply | ( | ptr_param< const MultiVector< value_type > > | alpha,
|  | ptr_param< const MultiVector< value_type > > | b,
|  | ptr_param< const MultiVector< value_type > > | beta,
|  | ptr_param< MultiVector< value_type > > | x ) const

## ◆ apply() [3/4]

template<typename ValueType = default_precision, typename IndexType = int32>

Csr * gko::batch::matrix::Csr< ValueType, IndexType >::apply | ( | ptr_param< const MultiVector< value_type > > | b,
|  | ptr_param< MultiVector< value_type > > | x )

Apply the matrix to a multi-vector.

Represents the matrix vector multiplication, x = A * b, where x and b are both multi-vectors.

Parameters

  b | the multi-vector to be applied to
  x | the output multi-vector

## ◆ apply() [4/4]

template<typename ValueType = default_precision, typename IndexType = int32>

const Csr * gko::batch::matrix::Csr< ValueType, IndexType >::apply | ( | ptr_param< const MultiVector< value_type > > | b,
|  | ptr_param< MultiVector< value_type > > | x ) const

## ◆ create() [1/3]

template<typename ValueType = default_precision, typename IndexType = int32>

std::unique_ptr< Csr > gko::batch::matrix::Csr< ValueType, IndexType >::create | ( | std::shared_ptr< const Executor > | exec,
|  | const batch_dim< 2 > & | size,
|  | array< value_type > | values,
|  | array< index_type > | col_idxs,
|  | array< index_type > | row_ptrs )
| static

Creates a Csr matrix from an already allocated (and initialized) array.

The column indices array needs to be the same for all batch items.

Parameters

  exec | Executor associated to the matrix
  size | size of the matrix
  values | array of matrix values
  col_idxs | the col_idxs array of a single batch item of the matrix.
  row_ptrs | the row_ptrs array of a single batch item of the matrix.

Note
  If values is not an rvalue, not an array of ValueType, or is on the wrong executor, an internal copy will be created, and the original array data will not be used in the matrix.

Returns
  A smart pointer to the newly created matrix.

## ◆ create() [2/3]

template<typename ValueType = default_precision, typename IndexType = int32>
template<typename InputValueType, typename ColIndexType, typename RowPtrType>

std::unique_ptr< Csr > gko::batch::matrix::Csr< ValueType, IndexType >::create | ( | std::shared_ptr< const Executor > | exec,
|  | const batch_dim< 2 > & | size,
|  | std::initializer_list< InputValueType > | values,
|  | std::initializer_list< ColIndexType > | col_idxs,
|  | std::initializer_list< RowPtrType > | row_ptrs )
| inlinestatic

create(std::shared_ptr<const Executor>,const batch_dim<2>&, array<value_type>, array<index_type>,array<index_type>)

create(std::shared_ptr<const Executor>,const batch_dim<2>&, array<value_type>, array<index_type>,array<index_type>)

## ◆ create() [3/3]

template<typename ValueType = default_precision, typename IndexType = int32>

std::unique_ptr< Csr > gko::batch::matrix::Csr< ValueType, IndexType >::create | ( | std::shared_ptr< const Executor > | exec,
|  | const batch_dim< 2 > & | size = batch_dim< 2 >{},
|  | size_type | num_nonzeros_per_item = {} )
| static

Creates an uninitialized Csr matrix of the specified size.

Parameters

  exec | Executor associated to the matrix
  size | size of the matrix
  num_nonzeros_per_item | number of nonzeros in each item of the batch matrix

Referenced by create().

## ◆ create_const()

template<typename ValueType = default_precision, typename IndexType = int32>

std::unique_ptr< const Csr > gko::batch::matrix::Csr< ValueType, IndexType >::create_const | ( | std::shared_ptr< const Executor > | exec,
|  | const batch_dim< 2 > & | sizes,
|  | gko::detail::const_array_view< value_type > && | values,
|  | gko::detail::const_array_view< index_type > && | col_idxs,
|  | gko::detail::const_array_view< index_type > && | row_ptrs )
| static

Creates a constant (immutable) batch csr matrix from a constant array.

Only a single sparsity pattern (column indices and row pointers) is stored and hence the user needs to ensure that each batch item has the same sparsity pattern.

Parameters

  exec | the executor to create the matrix on
  size | the dimensions of the matrix
  values | the value array of the matrix
  col_idxs | the col_idxs array of a single batch item of the matrix.
  row_ptrs | the row_ptrs array of a single batch item of the matrix.

Returns
  A smart pointer to the constant matrix wrapping the input array (if it resides on the same executor as the matrix) or a copy of the array on the correct executor.
  A smart pointer to the newly created matrix.

## ◆ create_const_view_for_item()

template<typename ValueType = default_precision, typename IndexType = int32>

std::unique_ptr< const unbatch_type > gko::batch::matrix::Csr< ValueType, IndexType >::create_const_view_for_item | ( | size_type | item_id | ) | const

Creates a mutable view (of matrix::Csr type) of one item of the batch::matrix::Csr<value_type> object.

Does not perform any deep copies, but only returns a view of the data.

Parameters

  item_id | The index of the batch item

Returns
  a batch::matrix::Csr object with the data from the batch item at the given index.

## ◆ create_view_for_item()

template<typename ValueType = default_precision, typename IndexType = int32>

std::unique_ptr< unbatch_type > gko::batch::matrix::Csr< ValueType, IndexType >::create_view_for_item | ( | size_type | item_id | ) |

Creates a mutable view (of matrix::Csr type) of one item of the batch::matrix::Csr<value_type> object.

Does not perform any deep copies, but only returns a view of the data.

Parameters

  item_id | The index of the batch item

Returns
  a batch::matrix::Csr object with the data from the batch item at the given index.

## ◆ get_col_idxs()

template<typename ValueType = default_precision, typename IndexType = int32>

index_type * gko::batch::matrix::Csr< ValueType, IndexType >::get_col_idxs | ( |  | ) |
| inlinenoexcept

Returns a pointer to the array of column indices of the matrix.

Returns
  the pointer to the array of column indices

## ◆ get_const_col_idxs()

template<typename ValueType = default_precision, typename IndexType = int32>

const index_type * gko::batch::matrix::Csr< ValueType, IndexType >::get_const_col_idxs | ( |  | ) | const
| inlinenoexcept

Returns a pointer to the array of column indices of the matrix.

Returns
  the pointer to the array of column indices

Note
  This is the constant version of the function, which can be significantly more memory efficient than the non-constant version, so always prefer this version.

## ◆ get_const_row_ptrs()

template<typename ValueType = default_precision, typename IndexType = int32>

const index_type * gko::batch::matrix::Csr< ValueType, IndexType >::get_const_row_ptrs | ( |  | ) | const
| inlinenoexcept

Returns a pointer to the array of row pointers of the matrix.

Returns
  the pointer to the array of row pointers

Note
  This is the constant version of the function, which can be significantly more memory efficient than the non-constant version, so always prefer this version.

## ◆ get_const_values()

template<typename ValueType = default_precision, typename IndexType = int32>

const value_type * gko::batch::matrix::Csr< ValueType, IndexType >::get_const_values | ( |  | ) | const
| inlinenoexcept

Returns a pointer to the array of values of the matrix.

Returns
  the pointer to the array of values

Note
  This is the constant version of the function, which can be significantly more memory efficient than the non-constant version, so always prefer this version.

## ◆ get_const_values_for_item()

template<typename ValueType = default_precision, typename IndexType = int32>

const value_type * gko::batch::matrix::Csr< ValueType, IndexType >::get_const_values_for_item | ( | size_type | batch_id | ) | const
| inlinenoexcept

Returns a pointer to the array of values of the matrix for a specific batch item.

Parameters

  batch_id | the id of the batch item.

Returns
  the pointer to the array of values

Note
  This is the constant version of the function, which can be significantly more memory efficient than the non-constant version, so always prefer this version.

## ◆ get_num_elements_per_item()

template<typename ValueType = default_precision, typename IndexType = int32>

size_type gko::batch::matrix::Csr< ValueType, IndexType >::get_num_elements_per_item | ( |  | ) | const
| inlinenoexcept

Returns the number of stored elements in each batch item.

Returns
  the number of stored elements per batch item.

Referenced by get_const_values_for_item(), and get_values_for_item().

## ◆ get_num_stored_elements()

template<typename ValueType = default_precision, typename IndexType = int32>

size_type gko::batch::matrix::Csr< ValueType, IndexType >::get_num_stored_elements | ( |  | ) | const
| inlinenoexcept

Returns the number of elements explicitly stored in the batch matrix, cumulative across all the batch items.

Returns
  the number of elements explicitly stored in the vector, cumulative across all the batch items

Referenced by get_num_elements_per_item().

## ◆ get_row_ptrs()

template<typename ValueType = default_precision, typename IndexType = int32>

index_type * gko::batch::matrix::Csr< ValueType, IndexType >::get_row_ptrs | ( |  | ) |
| inlinenoexcept

Returns a pointer to the array of row pointers of the matrix.

Returns
  the pointer to the array of row pointers

## ◆ get_values()

template<typename ValueType = default_precision, typename IndexType = int32>

value_type * gko::batch::matrix::Csr< ValueType, IndexType >::get_values | ( |  | ) |
| inlinenoexcept

Returns a pointer to the array of values of the matrix.

Returns
  the pointer to the array of values

## ◆ get_values_for_item()

template<typename ValueType = default_precision, typename IndexType = int32>

value_type * gko::batch::matrix::Csr< ValueType, IndexType >::get_values_for_item | ( | size_type | batch_id | ) |
| inlinenoexcept

Returns a pointer to the array of values of the matrix for a specific batch item.

Parameters

  batch_id | the id of the batch item.

Returns
  the pointer to the array of values

## ◆ scale()

template<typename ValueType = default_precision, typename IndexType = int32>

void gko::batch::matrix::Csr< ValueType, IndexType >::scale | ( | const array< value_type > & | row_scale,
|  | const array< value_type > & | col_scale )

Performs in-place row and column scaling for this matrix.

Parameters

  row_scale | the row scalars
  col_scale | the column scalars

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

- ginkgo/core/matrix/batch_csr.hpp