MultiVector< ValueType > Class Template Reference

MultiVector&lt; ValueType &gt; Class Template Reference#

Reference API: gko::batch::MultiVector< ValueType > Class Template Reference
Reference API
gko::batch::MultiVector< ValueType > Class Template Reference

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

Inheritance diagram for gko::batch::MultiVector< ValueType >:
[legend]

Public Types

using value_type = ValueType
 
using index_type = int32
 
using unbatch_type = gko::matrix::Dense< ValueType >
 
using absolute_type = remove_complex< MultiVector< ValueType > >
 
using complex_type = to_complex< MultiVector< ValueType > >
 
- Public Types inherited from gko::EnablePolymorphicAssignment< ConcreteType, ResultType >
using result_type = ResultType
 
- Public Types inherited from gko::ConvertibleTo< ResultType >
using result_type = ResultType
 

Public Member Functions

void convert_to (MultiVector< next_precision< ValueType > > *result) const override
 
void move_to (MultiVector< next_precision< ValueType > > *result) override
 
void convert_to (MultiVector< next_precision< next_precision< ValueType > > > *result) const override
 
void move_to (MultiVector< next_precision< next_precision< ValueType > > > *result) override
 
std::unique_ptr< unbatch_typecreate_view_for_item (size_type item_id)
 
std::unique_ptr< const unbatch_typecreate_const_view_for_item (size_type item_id) const
 
batch_dim< 2 > get_size () const
 
size_type get_num_batch_items () const
 
dim< 2 > get_common_size () const
 
value_type * get_values () noexcept
 
const value_type * get_const_values () const noexcept
 
value_type * get_values_for_item (size_type batch_id) noexcept
 
const value_type * get_const_values_for_item (size_type batch_id) const noexcept
 
size_type get_num_stored_elements () const noexcept
 
size_type get_cumulative_offset (size_type batch_id) const
 
value_type & at (size_type batch_id, size_type row, size_type col)
 
value_type at (size_type batch_id, size_type row, size_type col) const
 
ValueType & at (size_type batch_id, size_type idx) noexcept
 
ValueType at (size_type batch_id, size_type idx) const noexcept
 
void scale (ptr_param< const MultiVector< ValueType > > alpha)
 
void add_scaled (ptr_param< const MultiVector< ValueType > > alpha, ptr_param< const MultiVector< ValueType > > b)
 
void compute_dot (ptr_param< const MultiVector< ValueType > > b, ptr_param< MultiVector< ValueType > > result) const
 
void compute_conj_dot (ptr_param< const MultiVector< ValueType > > b, ptr_param< MultiVector< ValueType > > result) const
 
void compute_norm2 (ptr_param< MultiVector< remove_complex< ValueType > > > result) const
 
void fill (ValueType value)
 
- Public Member Functions inherited from gko::EnableAbstractPolymorphicObject< AbstractObject, PolymorphicBase >
std::unique_ptr< AbstractObject > create_default (std::shared_ptr< const Executor > exec) const
 
std::unique_ptr< AbstractObject > create_default () const
 
std::unique_ptr< AbstractObject > clone (std::shared_ptr< const Executor > exec) const
 
std::unique_ptr< AbstractObject > clone () const
 
AbstractObject * copy_from (const PolymorphicObject *other)
 
template<typename Derived >
std::enable_if_t< std::is_base_of< PolymorphicObject, std::decay_t< Derived > >::value, AbstractObject > * copy_from (std::unique_ptr< Derived > &&other)
 
template<typename Derived >
std::enable_if_t< std::is_base_of< PolymorphicObject, std::decay_t< Derived > >::value, AbstractObject > * copy_from (const std::unique_ptr< Derived > &other)
 
AbstractObject * copy_from (const std::shared_ptr< const PolymorphicObject > &other)
 
AbstractObject * move_from (ptr_param< PolymorphicObject > other)
 
AbstractObject * clear ()
 
- Public Member Functions inherited from gko::PolymorphicObject
PolymorphicObjectoperator= (const PolymorphicObject &)
 
std::unique_ptr< PolymorphicObjectcreate_default (std::shared_ptr< const Executor > exec) const
 
std::unique_ptr< PolymorphicObjectcreate_default () const
 
std::unique_ptr< PolymorphicObjectclone (std::shared_ptr< const Executor > exec) const
 
std::unique_ptr< PolymorphicObjectclone () const
 
PolymorphicObjectcopy_from (const PolymorphicObject *other)
 
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)
 
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)
 
PolymorphicObjectcopy_from (const std::shared_ptr< const PolymorphicObject > &other)
 
PolymorphicObjectmove_from (ptr_param< PolymorphicObject > other)
 
PolymorphicObjectclear ()
 
std::shared_ptr< const Executorget_executor () const noexcept
 
- 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< ConcreteType, ResultType >
void convert_to (result_type *result) const override
 
void move_to (result_type *result) override
 
- Public Member Functions inherited from gko::ConvertibleTo< ResultType >
void convert_to (ptr_param< result_type > result) const
 
void move_to (ptr_param< result_type > result)
 

Static Public Member Functions

static std::unique_ptr< MultiVectorcreate_with_config_of (ptr_param< const MultiVector > other)
 
static std::unique_ptr< MultiVectorcreate (std::shared_ptr< const Executor > exec, const batch_dim< 2 > &size=batch_dim< 2 >{})
 
static std::unique_ptr< MultiVectorcreate (std::shared_ptr< const Executor > exec, const batch_dim< 2 > &size, array< value_type > values)
 
template<typename InputValueType >
static std::unique_ptr< MultiVectorcreate (std::shared_ptr< const Executor > exec, const batch_dim< 2 > &size, std::initializer_list< InputValueType > values)
 create(std::shared_ptr<constExecutor>, const batch_dim<2>&, array<value_type>)
 
static std::unique_ptr< const MultiVectorcreate_const (std::shared_ptr< const Executor > exec, const batch_dim< 2 > &sizes, gko::detail::const_array_view< ValueType > &&values)
 

Protected Member Functions

void set_size (const batch_dim< 2 > &value) noexcept
 
 MultiVector (std::shared_ptr< const Executor > exec, const batch_dim< 2 > &size=batch_dim< 2 >{})
 
 MultiVector (std::shared_ptr< const Executor > exec, const batch_dim< 2 > &size, array< value_type > values)
 
std::unique_ptr< MultiVectorcreate_with_same_config () const
 
size_type linearize_index (size_type batch, size_type row, size_type col) const noexcept
 
size_type linearize_index (size_type batch, size_type idx) const noexcept
 
- Protected Member Functions inherited from gko::EnablePolymorphicObject< ConcreteObject, PolymorphicBase >
std::unique_ptr< PolymorphicObjectcreate_default_impl (std::shared_ptr< const Executor > exec) const override
 
PolymorphicObjectcopy_from_impl (const PolymorphicObject *other) override
 
PolymorphicObjectcopy_from_impl (std::unique_ptr< PolymorphicObject > other) override
 
PolymorphicObjectmove_from_impl (PolymorphicObject *other) override
 
PolymorphicObjectmove_from_impl (std::unique_ptr< PolymorphicObject > other) override
 
PolymorphicObjectclear_impl () override
 
- Protected Member Functions inherited from gko::PolymorphicObject
 PolymorphicObject (std::shared_ptr< const Executor > exec)
 
 PolymorphicObject (const PolymorphicObject &other)
 
- Protected Member Functions inherited from gko::log::EnableLogging< PolymorphicObject >
void log (Params &&... params) const
 

Friends

class EnablePolymorphicObject< MultiVector >
 
class MultiVector< to_complex< ValueType > >
 
class MultiVector< previous_precision< ValueType > >
 
class MultiVector< previous_precision< previous_precision< ValueType > > >
 

Additional Inherited Members

- Protected Attributes inherited from gko::log::EnableLogging< PolymorphicObject >
std::vector< std::shared_ptr< const Logger > > loggers_
 

Detailed Description

template<typename ValueType = default_precision>
class gko::batch::MultiVector< ValueType >

MultiVector stores multiple vectors in a batched fashion and is useful for batched operations. For example, if you want to store two batch items with multi-vectors of size (3 x 2) given below:

[1 2 ; 3 4 1 2 ; 3 4 1 2 ; 3 4]

In memory, they would be stored as a single array: [1 2 1 2 1 2 3 4 3 4 3 4].

Access functions @at can help access individual item if necessary.

The values of the different batch items are stored consecutively and in each batch item, the multi-vectors are stored in a row-major fashion.

Template Parameters
ValueTypeprecision of multi-vector elements

Member Function Documentation

◆ add_scaled()

template<typename ValueType = default_precision>
void gko::batch::MultiVector< ValueType >::add_scaled ( ptr_param< const MultiVector< ValueType > >  alpha,
ptr_param< const MultiVector< ValueType > >  b 
)

Adds b scaled by alpha to the vector (aka: BLAS axpy).

Parameters
alphathe scalar
ba multi-vector of the same dimension as this
Note
If alpha is 1x1 MultiVector matrix, the entire multi-vector (all batches) is scaled by alpha. If it is a MultiVector row vector of values, then i-th column of the vector is scaled with the i-th element of alpha (the number of columns of alpha has to match the number of columns of the multi-vector).

◆ at() [1/4]

template<typename ValueType = default_precision>
ValueType gko::batch::MultiVector< ValueType >::at ( size_type  batch_id,
size_type  idx 
) const
inlinenoexcept

Returns a single element for a particular batch item.

Parameters
batch_idthe batch item index to be queried
rowthe row of the requested element
colthe column of the requested element
Note
the method has to be called on the same Executor the vector is stored at (e.g. trying to call this method on a GPU multi-vector from the OMP results in a runtime error)

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

◆ at() [2/4]

template<typename ValueType = default_precision>
ValueType & gko::batch::MultiVector< ValueType >::at ( size_type  batch_id,
size_type  idx 
)
inlinenoexcept

Returns a single element for a particular batch item.

Useful for iterating across all elements of the vector. However, it is less efficient than the two-parameter variant of this method.

Parameters
batch_idthe batch item index to be queried
idxa linear index of the requested element
Note
the method has to be called on the same Executor the vector is stored at (e.g. trying to call this method on a GPU multi-vector from the OMP results in a runtime error)

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

◆ at() [3/4]

template<typename ValueType = default_precision>
value_type & gko::batch::MultiVector< ValueType >::at ( size_type  batch_id,
size_type  row,
size_type  col 
)
inline

Returns a single element for a particular batch item.

Parameters
batch_idthe batch item index to be queried
rowthe row of the requested element
colthe column of the requested element
Note
the method has to be called on the same Executor the vector is stored at (e.g. trying to call this method on a GPU multi-vector from the OMP results in a runtime error)

References gko::array< ValueType >::get_data(), and gko::batch::MultiVector< ValueType >::get_num_batch_items().

◆ at() [4/4]

template<typename ValueType = default_precision>
value_type gko::batch::MultiVector< ValueType >::at ( size_type  batch_id,
size_type  row,
size_type  col 
) const
inline

Returns a single element for a particular batch item.

Parameters
batch_idthe batch item index to be queried
rowthe row of the requested element
colthe column of the requested element
Note
the method has to be called on the same Executor the vector is stored at (e.g. trying to call this method on a GPU multi-vector from the OMP results in a runtime error)

References gko::array< ValueType >::get_const_data(), and gko::batch::MultiVector< ValueType >::get_num_batch_items().

◆ compute_conj_dot()

template<typename ValueType = default_precision>
void gko::batch::MultiVector< ValueType >::compute_conj_dot ( ptr_param< const MultiVector< ValueType > >  b,
ptr_param< MultiVector< ValueType > >  result 
) const

Computes the column-wise conjugate dot product of each multi-vector in this batch and its corresponding entry in b. If the vector has complex value_type, then the conjugate of this is taken.

Parameters
ba MultiVector of same dimension as this
resulta MultiVector row vector, used to store the dot product (the number of column in the vector must match the number of columns of this)

◆ compute_dot()

template<typename ValueType = default_precision>
void gko::batch::MultiVector< ValueType >::compute_dot ( ptr_param< const MultiVector< ValueType > >  b,
ptr_param< MultiVector< ValueType > >  result 
) const

Computes the column-wise dot product of each multi-vector in this batch and its corresponding entry in b.

Parameters
ba MultiVector of same dimension as this
resulta MultiVector row vector, used to store the dot product

◆ compute_norm2()

template<typename ValueType = default_precision>
void gko::batch::MultiVector< ValueType >::compute_norm2 ( ptr_param< MultiVector< remove_complex< ValueType > > >  result) const

Computes the Euclidean (L^2) norm of each multi-vector in this batch.

Parameters
resulta MultiVector, used to store the norm (the number of columns in the vector must match the number of columns of this)

◆ create() [1/3]

template<typename ValueType = default_precision>
static std::unique_ptr< MultiVector > gko::batch::MultiVector< ValueType >::create ( std::shared_ptr< const Executor exec,
const batch_dim< 2 > &  size,
array< value_type >  values 
)
static

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

Parameters
execExecutor associated to the vector
sizesizes of the batch matrices in a batch_dim object
valuesarray of 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 vector.

◆ create() [2/3]

template<typename ValueType = default_precision>
template<typename InputValueType >
static std::unique_ptr< MultiVector > gko::batch::MultiVector< ValueType >::create ( std::shared_ptr< const Executor exec,
const batch_dim< 2 > &  size,
std::initializer_list< InputValueType >  values 
)
inlinestatic

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

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

References gko::batch::MultiVector< ValueType >::create().

◆ create() [3/3]

template<typename ValueType = default_precision>
static std::unique_ptr< MultiVector > gko::batch::MultiVector< ValueType >::create ( std::shared_ptr< const Executor exec,
const batch_dim< 2 > &  size = batch_dim< 2 >{} 
)
static

Creates an uninitialized multi-vector of the specified size.

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

Referenced by gko::batch::MultiVector< ValueType >::create().

◆ create_const()

template<typename ValueType = default_precision>
static std::unique_ptr< const MultiVector > gko::batch::MultiVector< ValueType >::create_const ( std::shared_ptr< const Executor exec,
const batch_dim< 2 > &  sizes,
gko::detail::const_array_view< ValueType > &&  values 
)
static

Creates a constant (immutable) batch multi-vector from a constant array.

Parameters
execthe executor to create the vector on
sizethe dimensions of the vector
valuesthe value array of the vector
stridethe row-stride of the vector
Returns
A smart pointer to the constant multi-vector wrapping the input array (if it resides on the same executor as the vector) or a copy of the array on the correct executor.

◆ create_const_view_for_item()

template<typename ValueType = default_precision>
std::unique_ptr< const unbatch_type > gko::batch::MultiVector< ValueType >::create_const_view_for_item ( size_type  item_id) const

Creates a mutable view (of matrix::Dense type) of one item of the Batch MultiVector object. Does not perform any deep copies, but only returns a view of the data.

Parameters
item_idThe index of the batch item
Returns
a matrix::Dense object with the data from the batch item at the given index.

◆ create_view_for_item()

template<typename ValueType = default_precision>
std::unique_ptr< unbatch_type > gko::batch::MultiVector< ValueType >::create_view_for_item ( size_type  item_id)

Creates a mutable view (of matrix::Dense type) of one item of the Batch MultiVector object. Does not perform any deep copies, but only returns a view of the data.

Parameters
item_idThe index of the batch item
Returns
a matrix::Dense object with the data from the batch item at the given index.

◆ create_with_config_of()

template<typename ValueType = default_precision>
static std::unique_ptr< MultiVector > gko::batch::MultiVector< ValueType >::create_with_config_of ( ptr_param< const MultiVector< ValueType > >  other)
static

Creates a MultiVector with the configuration of another MultiVector.

Parameters
otherThe other multi-vector whose configuration needs to copied.

◆ create_with_same_config()

template<typename ValueType = default_precision>
std::unique_ptr< MultiVector > gko::batch::MultiVector< ValueType >::create_with_same_config ( ) const
protected

Creates a MultiVector with the same configuration as the callers object.

Returns
a MultiVector with the same configuration as the caller.

◆ fill()

template<typename ValueType = default_precision>
void gko::batch::MultiVector< ValueType >::fill ( ValueType  value)

Fills the input MultiVector with a given value

Parameters
valuethe value to be filled

◆ get_common_size()

template<typename ValueType = default_precision>
dim< 2 > gko::batch::MultiVector< ValueType >::get_common_size ( ) const
inline

◆ get_const_values()

template<typename ValueType = default_precision>
const value_type * gko::batch::MultiVector< ValueType >::get_const_values ( ) const
inlinenoexcept

Returns a pointer to the array of values of the multi-vector

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_const_values_for_item()

template<typename ValueType = default_precision>
const value_type * gko::batch::MultiVector< ValueType >::get_const_values_for_item ( size_type  batch_id) const
inlinenoexcept

Returns a pointer to the array of values of the multi-vector for a specific batch item.

Parameters
batch_idthe 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.

References gko::array< ValueType >::get_const_data(), gko::batch::MultiVector< ValueType >::get_cumulative_offset(), and gko::batch::MultiVector< ValueType >::get_num_batch_items().

◆ get_cumulative_offset()

template<typename ValueType = default_precision>
size_type gko::batch::MultiVector< ValueType >::get_cumulative_offset ( size_type  batch_id) const
inline

Get the cumulative storage size offset

Parameters
batch_idthe batch id
Returns
the cumulative offset

References gko::batch::MultiVector< ValueType >::get_common_size().

Referenced by gko::batch::MultiVector< ValueType >::get_const_values_for_item(), and gko::batch::MultiVector< ValueType >::get_values_for_item().

◆ get_num_batch_items()

◆ get_num_stored_elements()

template<typename ValueType = default_precision>
size_type gko::batch::MultiVector< ValueType >::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

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

◆ get_size()

template<typename ValueType = default_precision>
batch_dim< 2 > gko::batch::MultiVector< ValueType >::get_size ( ) const
inline

Returns the batch size.

Returns
the batch size

◆ get_values()

template<typename ValueType = default_precision>
value_type * gko::batch::MultiVector< ValueType >::get_values ( )
inlinenoexcept

Returns a pointer to the array of values of the multi-vector

Returns
the pointer to the array of values

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

◆ get_values_for_item()

template<typename ValueType = default_precision>
value_type * gko::batch::MultiVector< ValueType >::get_values_for_item ( size_type  batch_id)
inlinenoexcept

Returns a pointer to the array of values of the multi-vector for a specific batch item.

Parameters
batch_idthe id of the batch item.
Returns
the pointer to the array of values

References gko::batch::MultiVector< ValueType >::get_cumulative_offset(), gko::array< ValueType >::get_data(), and gko::batch::MultiVector< ValueType >::get_num_batch_items().

◆ scale()

template<typename ValueType = default_precision>
void gko::batch::MultiVector< ValueType >::scale ( ptr_param< const MultiVector< ValueType > >  alpha)

Scales the vector with a scalar (aka: BLAS scal).

Parameters
alphathe scalar
Note
If alpha is 1x1 MultiVector matrix, the entire multi-vector (all batches) is scaled by alpha. If it is a MultiVector row vector of values, then i-th column of the vector is scaled with the i-th element of alpha (the number of columns of alpha has to match the number of columns of the multi-vector). If it is a MultiVector of the same size as this, then an element wise scaling is performed.

◆ set_size()

template<typename ValueType = default_precision>
void gko::batch::MultiVector< ValueType >::set_size ( const batch_dim< 2 > &  value)
protectednoexcept

Sets the size of the MultiVector.

Parameters
valuethe new size of the operator

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