Ginkgo  Generated from pipelines/1556235455 branch based on develop. Ginkgo version 1.9.0
A numerical linear algebra library targeting many-core architectures
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
gko::matrix::Diagonal< ValueType > Class Template Reference

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

#include <ginkgo/core/matrix/diagonal.hpp>

Inheritance diagram for gko::matrix::Diagonal< ValueType >:
[legend]
Collaboration diagram for gko::matrix::Diagonal< ValueType >:
[legend]

Public Types

using value_type = ValueType
 
using index_type = int64
 
using mat_data = matrix_data< ValueType, int64 >
 
using mat_data32 = matrix_data< ValueType, int32 >
 
using device_mat_data = device_matrix_data< ValueType, int64 >
 
using device_mat_data32 = device_matrix_data< ValueType, int32 >
 
using absolute_type = remove_complex< Diagonal >
 
- Public Types inherited from gko::EnablePolymorphicAssignment< Diagonal< ValueType > >
using result_type = Diagonal< ValueType >
 
- Public Types inherited from gko::ConvertibleTo< Diagonal< ValueType > >
using result_type = Diagonal< ValueType >
 
- Public Types inherited from gko::ConvertibleTo< Csr< ValueType, int32 > >
using result_type = Csr< ValueType, int32 >
 
- Public Types inherited from gko::ConvertibleTo< Csr< ValueType, int64 > >
using result_type = Csr< ValueType, int64 >
 
- Public Types inherited from gko::ConvertibleTo< Diagonal< next_precision< ValueType > > >
using result_type = Diagonal< next_precision< ValueType > >
 
- Public Types inherited from gko::WritableToMatrixData< ValueType, int32 >
using value_type = ValueType
 
using index_type = int32
 
- Public Types inherited from gko::WritableToMatrixData< ValueType, int64 >
using value_type = ValueType
 
using index_type = int64
 
- Public Types inherited from gko::ReadableFromMatrixData< ValueType, int32 >
using value_type = ValueType
 
using index_type = int32
 
- Public Types inherited from gko::ReadableFromMatrixData< ValueType, int64 >
using value_type = ValueType
 
using index_type = int64
 
- Public Types inherited from gko::EnableAbsoluteComputation< remove_complex< Diagonal< ValueType > > >
using absolute_type = remove_complex< Diagonal< ValueType > >
 

Public Member Functions

std::unique_ptr< LinOptranspose () const override
 Returns a LinOp representing the transpose of the Transposable object. More...
 
std::unique_ptr< LinOpconj_transpose () const override
 Returns a LinOp representing the conjugate transpose of the Transposable object. More...
 
void convert_to (Diagonal< next_precision< ValueType >> *result) const override
 
void move_to (Diagonal< next_precision< ValueType >> *result) override
 
void convert_to (Csr< ValueType, int32 > *result) const override
 
void move_to (Csr< ValueType, int32 > *result) override
 
void convert_to (Csr< ValueType, int64 > *result) const override
 
void move_to (Csr< ValueType, int64 > *result) override
 
std::unique_ptr< absolute_type > compute_absolute () const override
 Gets the AbsoluteLinOp. More...
 
void compute_absolute_inplace () override
 Compute absolute inplace on each element.
 
value_type * get_values () noexcept
 Returns a pointer to the array of values of the matrix. More...
 
const value_type * get_const_values () const noexcept
 Returns a pointer to the array of values of the matrix. More...
 
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. More...
 
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. More...
 
void read (const mat_data &data) override
 
void read (const mat_data32 &data) override
 
void read (const device_mat_data &data) override
 
void read (const device_mat_data32 &data) override
 
void read (device_mat_data &&data) override
 
void read (device_mat_data32 &&data) override
 
void write (mat_data &data) const override
 
void write (mat_data32 &data) const override
 
- Public Member Functions inherited from gko::EnableLinOp< Diagonal< ValueType > >
const Diagonal< ValueType > * apply (ptr_param< const LinOp > b, ptr_param< LinOp > x) const
 
Diagonal< ValueType > * apply (ptr_param< const LinOp > b, ptr_param< LinOp > x)
 
const Diagonal< ValueType > * apply (ptr_param< const LinOp > alpha, ptr_param< const LinOp > b, ptr_param< const LinOp > beta, ptr_param< LinOp > x) const
 
Diagonal< ValueType > * apply (ptr_param< const LinOp > alpha, ptr_param< const LinOp > b, ptr_param< const LinOp > beta, ptr_param< LinOp > x)
 
- Public Member Functions inherited from gko::EnableAbstractPolymorphicObject< Diagonal< ValueType >, LinOp >
std::unique_ptr< Diagonal< ValueType > > create_default (std::shared_ptr< const Executor > exec) const
 
std::unique_ptr< Diagonal< ValueType > > create_default () const
 
std::unique_ptr< Diagonal< ValueType > > clone (std::shared_ptr< const Executor > exec) const
 
std::unique_ptr< Diagonal< ValueType > > clone () const
 
Diagonal< ValueType > * copy_from (const PolymorphicObject *other)
 
std::enable_if_t< std::is_base_of< PolymorphicObject, std::decay_t< Derived > >::value, Diagonal< ValueType > > * copy_from (std::unique_ptr< Derived > &&other)
 
std::enable_if_t< std::is_base_of< PolymorphicObject, std::decay_t< Derived > >::value, Diagonal< ValueType > > * copy_from (const std::unique_ptr< Derived > &other)
 
Diagonal< ValueType > * copy_from (const std::shared_ptr< const PolymorphicObject > &other)
 
Diagonal< ValueType > * move_from (ptr_param< PolymorphicObject > other)
 
Diagonal< ValueType > * clear ()
 
- Public Member Functions inherited from gko::LinOp
LinOpapply (ptr_param< const LinOp > b, ptr_param< LinOp > x)
 Applies a linear operator to a vector (or a sequence of vectors). More...
 
const LinOpapply (ptr_param< const LinOp > b, ptr_param< LinOp > x) const
 
LinOpapply (ptr_param< const LinOp > alpha, ptr_param< const LinOp > b, ptr_param< const LinOp > beta, ptr_param< LinOp > x)
 Performs the operation x = alpha * op(b) + beta * x. More...
 
const LinOpapply (ptr_param< const LinOp > alpha, ptr_param< const LinOp > b, ptr_param< const LinOp > beta, ptr_param< LinOp > x) const
 
const dim< 2 > & get_size () const noexcept
 Returns the size of the operator. More...
 
virtual bool apply_uses_initial_guess () const
 Returns true if the linear operator uses the data given in x as an initial guess. More...
 
LinOpoperator= (const LinOp &)=default
 Copy-assigns a LinOp. More...
 
LinOpoperator= (LinOp &&other)
 Move-assigns a LinOp. More...
 
 LinOp (const LinOp &)=default
 Copy-constructs a LinOp. More...
 
 LinOp (LinOp &&other)
 Move-constructs a LinOp. More...
 
- Public Member Functions inherited from gko::EnableAbstractPolymorphicObject< LinOp >
std::unique_ptr< LinOpcreate_default (std::shared_ptr< const Executor > exec) const
 
std::unique_ptr< LinOpcreate_default () const
 
std::unique_ptr< LinOpclone (std::shared_ptr< const Executor > exec) const
 
std::unique_ptr< LinOpclone () const
 
LinOpcopy_from (const PolymorphicObject *other)
 
std::enable_if_t< std::is_base_of< PolymorphicObject, std::decay_t< Derived > >::value, LinOp > * copy_from (std::unique_ptr< Derived > &&other)
 
std::enable_if_t< std::is_base_of< PolymorphicObject, std::decay_t< Derived > >::value, LinOp > * copy_from (const std::unique_ptr< Derived > &other)
 
LinOpcopy_from (const std::shared_ptr< const PolymorphicObject > &other)
 
LinOpmove_from (ptr_param< PolymorphicObject > other)
 
LinOpclear ()
 
- Public Member Functions inherited from gko::PolymorphicObject
PolymorphicObjectoperator= (const PolymorphicObject &)
 
std::unique_ptr< PolymorphicObjectcreate_default (std::shared_ptr< const Executor > exec) const
 Creates a new "default" object of the same dynamic type as this object. More...
 
std::unique_ptr< PolymorphicObjectcreate_default () const
 Creates a new "default" object of the same dynamic type as this object. More...
 
std::unique_ptr< PolymorphicObjectclone (std::shared_ptr< const Executor > exec) const
 Creates a clone of the object. More...
 
std::unique_ptr< PolymorphicObjectclone () const
 Creates a clone of the object. More...
 
PolymorphicObjectcopy_from (const PolymorphicObject *other)
 Copies another object into this object. More...
 
template<typename Derived , typename Deleter >
std::enable_if_t< std::is_base_of< PolymorphicObject, std::decay_t< Derived > >::value, PolymorphicObject > * copy_from (std::unique_ptr< Derived, Deleter > &&other)
 Moves another object into this object. More...
 
template<typename Derived , typename Deleter >
std::enable_if_t< std::is_base_of< PolymorphicObject, std::decay_t< Derived > >::value, PolymorphicObject > * copy_from (const std::unique_ptr< Derived, Deleter > &other)
 Copies another object into this object. More...
 
PolymorphicObjectcopy_from (const std::shared_ptr< const PolymorphicObject > &other)
 Copies another object into this object. More...
 
PolymorphicObjectmove_from (ptr_param< PolymorphicObject > other)
 Moves another object into this object. More...
 
PolymorphicObjectclear ()
 Transforms the object into its default state. More...
 
std::shared_ptr< const Executorget_executor () const noexcept
 Returns the Executor of the object. More...
 
- Public Member Functions inherited from gko::log::EnableLogging< PolymorphicObject >
void add_logger (std::shared_ptr< const Logger > logger) override
 
void remove_logger (const Logger *logger) override
 
void remove_logger (ptr_param< const Logger > logger)
 
const std::vector< std::shared_ptr< const Logger > > & get_loggers () const override
 
void clear_loggers () override
 
- Public Member Functions inherited from gko::log::Loggable
void remove_logger (ptr_param< const Logger > logger)
 
- Public Member Functions inherited from gko::EnablePolymorphicAssignment< Diagonal< ValueType > >
void convert_to (result_type *result) const override
 Converts the implementer to an object of type result_type. More...
 
void move_to (result_type *result) override
 Converts the implementer to an object of type result_type by moving data from this object. More...
 
- Public Member Functions inherited from gko::ConvertibleTo< Diagonal< ValueType > >
void convert_to (ptr_param< result_type > result) const
 
void move_to (ptr_param< result_type > result)
 
- Public Member Functions inherited from gko::ConvertibleTo< Csr< ValueType, int32 > >
virtual void convert_to (result_type *result) const=0
 Converts the implementer to an object of type result_type. More...
 
void convert_to (ptr_param< result_type > result) const
 
virtual void move_to (result_type *result)=0
 Converts the implementer to an object of type result_type by moving data from this object. More...
 
void move_to (ptr_param< result_type > result)
 
- Public Member Functions inherited from gko::ConvertibleTo< Csr< ValueType, int64 > >
virtual void convert_to (result_type *result) const=0
 Converts the implementer to an object of type result_type. More...
 
void convert_to (ptr_param< result_type > result) const
 
virtual void move_to (result_type *result)=0
 Converts the implementer to an object of type result_type by moving data from this object. More...
 
void move_to (ptr_param< result_type > result)
 
- Public Member Functions inherited from gko::ConvertibleTo< Diagonal< next_precision< ValueType > > >
virtual void convert_to (result_type *result) const=0
 Converts the implementer to an object of type result_type. More...
 
void convert_to (ptr_param< result_type > result) const
 
virtual void move_to (result_type *result)=0
 Converts the implementer to an object of type result_type by moving data from this object. More...
 
void move_to (ptr_param< result_type > result)
 
- Public Member Functions inherited from gko::WritableToMatrixData< ValueType, int32 >
virtual void write (matrix_data< ValueType, int32 > &data) const=0
 Writes a matrix to a matrix_data structure. More...
 
- Public Member Functions inherited from gko::WritableToMatrixData< ValueType, int64 >
virtual void write (matrix_data< ValueType, int64 > &data) const=0
 Writes a matrix to a matrix_data structure. More...
 
- Public Member Functions inherited from gko::ReadableFromMatrixData< ValueType, int32 >
virtual void read (const matrix_data< ValueType, int32 > &data)=0
 Reads a matrix from a matrix_data structure. More...
 
void read (const matrix_assembly_data< ValueType, int32 > &data)
 Reads a matrix from a matrix_assembly_data structure. More...
 
virtual void read (const device_matrix_data< ValueType, int32 > &data)
 Reads a matrix from a device_matrix_data structure. More...
 
virtual void read (device_matrix_data< ValueType, int32 > &&data)
 Reads a matrix from a device_matrix_data structure. More...
 
- Public Member Functions inherited from gko::ReadableFromMatrixData< ValueType, int64 >
virtual void read (const matrix_data< ValueType, int64 > &data)=0
 Reads a matrix from a matrix_data structure. More...
 
void read (const matrix_assembly_data< ValueType, int64 > &data)
 Reads a matrix from a matrix_assembly_data structure. More...
 
virtual void read (const device_matrix_data< ValueType, int64 > &data)
 Reads a matrix from a device_matrix_data structure. More...
 
virtual void read (device_matrix_data< ValueType, int64 > &&data)
 Reads a matrix from a device_matrix_data structure. More...
 
- Public Member Functions inherited from gko::EnableAbsoluteComputation< remove_complex< Diagonal< ValueType > > >
std::unique_ptr< LinOpcompute_absolute_linop () const override
 Gets the absolute LinOp. More...
 

Static Public Member Functions

static std::unique_ptr< Diagonalcreate (std::shared_ptr< const Executor > exec, size_type size=0)
 Creates an Diagonal matrix of the specified size. More...
 
static std::unique_ptr< Diagonalcreate (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. More...
 
template<typename InputValueType >
static std::unique_ptr< Diagonalcreate (std::shared_ptr< const Executor > exec, const size_type size, std::initializer_list< InputValueType > values)
 create(std::shared_ptr<const More...
 
static std::unique_ptr< const Diagonalcreate_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. More...
 

Friends

class EnablePolymorphicObject< Diagonal, LinOp >
 
class Csr< ValueType, int32 >
 
class Csr< ValueType, int64 >
 
class Diagonal< to_complex< ValueType > >
 
class Diagonal< next_precision< ValueType > >
 

Detailed Description

template<typename ValueType = default_precision>
class gko::matrix::Diagonal< ValueType >

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
ValueTypeprecision of matrix elements
IndexTypeprecision of matrix indexes of a CSR matrix the diagonal is applied or converted to.

Member Function Documentation

◆ compute_absolute()

template<typename ValueType = default_precision>
std::unique_ptr<absolute_type> gko::matrix::Diagonal< ValueType >::compute_absolute ( ) const
overridevirtual

Gets the AbsoluteLinOp.

Returns
a pointer to the new absolute object

Implements gko::EnableAbsoluteComputation< remove_complex< Diagonal< ValueType > > >.

◆ conj_transpose()

template<typename ValueType = default_precision>
std::unique_ptr<LinOp> gko::matrix::Diagonal< ValueType >::conj_transpose ( ) const
overridevirtual

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

Returns
a pointer to the new conjugate transposed object

Implements gko::Transposable.

◆ create() [1/3]

template<typename ValueType = default_precision>
static std::unique_ptr<Diagonal> gko::matrix::Diagonal< ValueType >::create ( std::shared_ptr< const Executor exec,
const size_type  size,
array< value_type >  values 
)
static

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

Parameters
execExecutor associated to the matrix
sizesize of the matrix
valuesarray of matrix values
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>
template<typename InputValueType >
static std::unique_ptr<Diagonal> gko::matrix::Diagonal< ValueType >::create ( std::shared_ptr< const Executor exec,
const size_type  size,
std::initializer_list< InputValueType >  values 
)
inlinestatic

create(std::shared_ptr<const

create(std::shared_ptr<const executor>="">, const size_type, array<value_type>)

References gko::matrix::Diagonal< ValueType >::create().

◆ create() [3/3]

template<typename ValueType = default_precision>
static std::unique_ptr<Diagonal> gko::matrix::Diagonal< ValueType >::create ( std::shared_ptr< const Executor exec,
size_type  size = 0 
)
static

Creates an Diagonal matrix of the specified size.

Parameters
execExecutor associated to the matrix
sizesize of the matrix
Returns
A smart pointer to the newly created matrix.

Referenced by gko::matrix::Diagonal< ValueType >::create().

◆ create_const()

template<typename ValueType = default_precision>
static std::unique_ptr<const Diagonal> gko::matrix::Diagonal< ValueType >::create_const ( std::shared_ptr< const Executor exec,
size_type  size,
gko::detail::const_array_view< ValueType > &&  values 
)
static

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

Parameters
execthe executor to create the matrix on
sizethe size of the square matrix
valuesthe 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.

◆ get_const_values()

template<typename ValueType = default_precision>
const value_type* gko::matrix::Diagonal< ValueType >::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.

References gko::array< ValueType >::get_const_data().

◆ get_values()

template<typename ValueType = default_precision>
value_type* gko::matrix::Diagonal< ValueType >::get_values ( )
inlinenoexcept

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

Returns
the pointer to the array of values

References gko::array< ValueType >::get_data().

◆ inverse_apply()

template<typename ValueType = default_precision>
void gko::matrix::Diagonal< ValueType >::inverse_apply ( ptr_param< const LinOp b,
ptr_param< LinOp x 
) const
inline

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
bthe input vector(s) on which the inverse of the diagonal matrix is applied
xthe output vector(s) where the result is stored

References gko::ptr_param< T >::get().

◆ rapply()

template<typename ValueType = default_precision>
void gko::matrix::Diagonal< ValueType >::rapply ( ptr_param< const LinOp b,
ptr_param< LinOp x 
) const
inline

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
bthe input vector(s) on which the diagonal matrix is applied
xthe output vector(s) where the result is stored

References gko::ptr_param< T >::get().

◆ transpose()

template<typename ValueType = default_precision>
std::unique_ptr<LinOp> gko::matrix::Diagonal< ValueType >::transpose ( ) const
overridevirtual

Returns a LinOp representing the transpose of the Transposable object.

Returns
a pointer to the new transposed object

Implements gko::Transposable.


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