gko::matrix::Diagonal#

Diagonal matrix. Stores one value per diagonal entry; apply(b, x) performs element-wise multiplication. The natural representation for diagonal scalings, row/column rescaling preconditioners, and the diagonal preconditioner inside gko::preconditioner::Jacobi at block size 1.

template<typename ValueType = default_precision>
class Diagonal #

Inherits from

  • public gko::EnableLinOp<Diagonal<default_precision>>

  • public ConvertibleTo<Csr<default_precision, int32>>

  • public ConvertibleTo<Csr<default_precision, int64>>

  • public ConvertibleTo<Diagonal<next_precision<default_precision>>>

  • public ConvertibleTo<Diagonal<next_precision<default_precision, 2>>>

  • public ConvertibleTo<Diagonal<next_precision<default_precision, 3>>>

  • public gko::Transposable

  • public gko::WritableToMatrixData<default_precision, int32>

  • public gko::WritableToMatrixData<default_precision, int64>

  • public gko::ReadableFromMatrixData<default_precision, int32>

  • public gko::ReadableFromMatrixData<default_precision, int64>

  • public gko::EnableAbsoluteComputation<remove_complex<Diagonal<default_precision>>>

This class is a utility which efficiently implements the diagonal matrix (a linear operator which scales a vector row wise).

Objects of the Diagonal class always represent a square matrix, and require one array to store their values.

Template Parameters:
  • ValueType – precision of matrix elements

  • IndexType – precision of matrix indexes of a CSR matrix the diagonal is applied or converted to.

Public Functions

virtual std::unique_ptr<LinOp> transpose() const override#

Returns a LinOp representing the transpose of the Transposable object.

Returns:

a pointer to the new transposed object

virtual std::unique_ptr<LinOp> conj_transpose() const override#

Returns a LinOp representing the conjugate transpose of the Transposable object.

Returns:

a pointer to the new conjugate transposed object

virtual std::unique_ptr<absolute_type> compute_absolute(
) const override#

Gets the AbsoluteLinOp

Returns:

a pointer to the new absolute object

virtual void compute_absolute_inplace() override#

Compute absolute inplace on each element.

inline value_type *get_values() noexcept#

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

Returns:

the pointer to the array of values

inline const value_type *get_const_values() const noexcept#

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

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.

Returns:

the pointer to the array of values

inline void rapply(
ptr_param<const LinOp> b,
ptr_param<LinOp> x,
) const#

Applies the diagonal matrix from the right side to a matrix b, which means scales the columns of b with the according diagonal entries.

Parameters:
  • b – the input vector(s) on which the diagonal matrix is applied

  • x – the output vector(s) where the result is stored

inline void inverse_apply(
ptr_param<const LinOp> b,
ptr_param<LinOp> x,
) const#

Applies the inverse of the diagonal matrix to a matrix b, which means scales the columns of b with the inverse of the according diagonal entries.

Parameters:
  • b – the input vector(s) on which the inverse of the diagonal matrix is applied

  • x – the output vector(s) where the result is stored

Public Static Functions

static std::unique_ptr<Diagonal> create(
std::shared_ptr<const Executor> exec,
size_type size = 0,
)#

Creates an Diagonal matrix of the specified size.

Parameters:
  • execExecutor associated to the matrix

  • size – size of the matrix

Returns:

A smart pointer to the newly created matrix.

static std::unique_ptr<Diagonal> create(
std::shared_ptr<const Executor> exec,
const size_type size,
array<value_type> values,
)#

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

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.

Parameters:
  • execExecutor associated to the matrix

  • size – size of the matrix

  • values – array of matrix values

Returns:

A smart pointer to the newly created matrix.

template<typename InputValueType>
static inline std::unique_ptr<Diagonal> create(
std::shared_ptr<const Executor> exec,
const size_type size,
std::initializer_list<InputValueType> values,
)#

create(std::shared_ptr<constExecutor>, const size_type, array<value_type>)

create(std::shared_ptr<constExecutor>, const size_type, array<value_type>)

static std::unique_ptr<const Diagonal> create_const(
std::shared_ptr<const Executor> exec,
size_type size,
gko::detail::const_array_view<ValueType> &&values,
)#

Creates a constant (immutable) Diagonal matrix from a constant array.

Parameters:
  • exec – the executor to create the matrix on

  • size – the size of the square matrix

  • values – the value array 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.