Ginkgo  Generated from tags/v1.0.0^0 branch based on master. Ginkgo version 1.0.0
A numerical linear algebra library targeting many-core architectures
Public Types | Public Member Functions | Static Public Member Functions | List of all members
gko::Array< ValueType > Class Template Reference

An Array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the Array. More...

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

Public Types

using value_type = ValueType
 The type of elements stored in the array.
 
using default_deleter = executor_deleter< value_type[]>
 The default deleter type used by Array.
 
using view_deleter = null_deleter< value_type[]>
 The deleter type used for views.
 

Public Member Functions

 Array () noexcept
 Creates an empty Array not tied to any executor. More...
 
 Array (std::shared_ptr< const Executor > exec) noexcept
 Creates an empty Array tied to the specified Executor. More...
 
 Array (std::shared_ptr< const Executor > exec, size_type num_elems)
 Creates an Array on the specified Executor. More...
 
template<typename DeleterType >
 Array (std::shared_ptr< const Executor > exec, size_type num_elems, value_type *data, DeleterType deleter)
 Creates an Array from existing memory. More...
 
 Array (std::shared_ptr< const Executor > exec, size_type num_elems, value_type *data)
 Creates an Array from existing memory. More...
 
template<typename RandomAccessIterator >
 Array (std::shared_ptr< const Executor > exec, RandomAccessIterator begin, RandomAccessIterator end)
 Creates an array on the specified Executor and initializes it with values. More...
 
template<typename T >
 Array (std::shared_ptr< const Executor > exec, std::initializer_list< T > init_list)
 Creates an array on the specified Executor and initializes it with values. More...
 
 Array (std::shared_ptr< const Executor > exec, const Array &other)
 Creates a copy of another array on a different executor. More...
 
 Array (const Array &other)
 Creates a copy of another array. More...
 
 Array (std::shared_ptr< const Executor > exec, Array &&other)
 Moves another array to a different executor. More...
 
 Array (Array &&other)
 Moves another array. More...
 
Arrayoperator= (const Array &other)
 Copies data from another array. More...
 
Arrayoperator= (Array &&other)
 Moves data from another array. More...
 
void clear () noexcept
 Deallocates all data used by the Array. More...
 
void resize_and_reset (size_type num_elems)
 Resizes the array so it is able to hold the specified number of elements. More...
 
size_type get_num_elems () const noexcept
 Returns the number of elements in the Array. More...
 
value_typeget_data () noexcept
 Returns a pointer to the block of memory used to store the elements of the Array. More...
 
const value_typeget_const_data () const noexcept
 Returns a constant pointer to the block of memory used to store the elements of the Array. More...
 
std::shared_ptr< const Executorget_executor () const noexcept
 Returns the Executor associated with the array. More...
 
void set_executor (std::shared_ptr< const Executor > exec)
 Changes the Executor of the Array, moving the allocated data to the new Executor. More...
 

Static Public Member Functions

static Array view (std::shared_ptr< const Executor > exec, size_type num_elems, value_type *data)
 Creates an Array from existing memory. More...
 

Detailed Description

template<typename ValueType>
class gko::Array< ValueType >

An Array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the Array.

The array stores and transfers its data as raw memory, which means that the constructors of its elements are not called when constructing, copying or moving the Array. Thus, the Array class is most suitable for storing POD types.

Template Parameters
ValueTypethe type of elements stored in the array

Constructor & Destructor Documentation

◆ Array() [1/11]

template<typename ValueType>
gko::Array< ValueType >::Array ( )
inlinenoexcept

Creates an empty Array not tied to any executor.

An array without an assigned executor can only be empty. Attempts to change its size (e.g. via the resize_and_reset method) will result in an exception. If such an array is used as the right hand side of an assignment or move assignment expression, the data of the target array will be cleared, but its executor will not be modified.

The executor can later be set by using the set_executor method. If an Array with no assigned executor is assigned or moved to, it will inherit the executor of the source Array.

◆ Array() [2/11]

template<typename ValueType>
gko::Array< ValueType >::Array ( std::shared_ptr< const Executor exec)
inlinenoexcept

Creates an empty Array tied to the specified Executor.

Parameters
execthe Executor where the array data is allocated

◆ Array() [3/11]

template<typename ValueType>
gko::Array< ValueType >::Array ( std::shared_ptr< const Executor exec,
size_type  num_elems 
)
inline

Creates an Array on the specified Executor.

Parameters
execthe Executor where the array data will be allocated
num_elemsthe amount of memory (expressed as the number of value_type elements) allocated on the Executor

◆ Array() [4/11]

template<typename ValueType>
template<typename DeleterType >
gko::Array< ValueType >::Array ( std::shared_ptr< const Executor exec,
size_type  num_elems,
value_type data,
DeleterType  deleter 
)
inline

Creates an Array from existing memory.

The memory will be managed by the array, and deallocated using the specified deleter (e.g. use std::default_delete for data allocated with new).

Template Parameters
DeleterTypetype of the deleter
Parameters
execexecutor where data is located
num_elemsnumber of elements in data
datachunk of memory used to create the array
deleterthe deleter used to free the memory
See also
Array::view() to create an array that does not deallocate memory
Array(std::shared_ptr<cont Executor>, size_type, value_type*) to deallocate the memory using Executor::free() method

◆ Array() [5/11]

template<typename ValueType>
gko::Array< ValueType >::Array ( std::shared_ptr< const Executor exec,
size_type  num_elems,
value_type data 
)
inline

Creates an Array from existing memory.

The memory will be managed by the array, and deallocated using the Executor::free method.

Parameters
execexecutor where data is located
num_elemsnumber of elements in data
datachunk of memory used to create the array

◆ Array() [6/11]

template<typename ValueType>
template<typename RandomAccessIterator >
gko::Array< ValueType >::Array ( std::shared_ptr< const Executor exec,
RandomAccessIterator  begin,
RandomAccessIterator  end 
)
inline

Creates an array on the specified Executor and initializes it with values.

Template Parameters
RandomAccessIteratortype of the iterators
Parameters
execthe Executor where the array data will be allocated
beginstart of range of values
endend of range of values

◆ Array() [7/11]

template<typename ValueType>
template<typename T >
gko::Array< ValueType >::Array ( std::shared_ptr< const Executor exec,
std::initializer_list< T >  init_list 
)
inline

Creates an array on the specified Executor and initializes it with values.

Template Parameters
Ttype of values used to initialize the array (T has to be implicitly convertible to value_type)
Parameters
execthe Executor where the array data will be allocated
init_listlist of values used to initialize the Array

◆ Array() [8/11]

template<typename ValueType>
gko::Array< ValueType >::Array ( std::shared_ptr< const Executor exec,
const Array< ValueType > &  other 
)
inline

Creates a copy of another array on a different executor.

This does not invoke the constructors of the elements, instead they are copied as POD types.

Parameters
execthe executor where the new array will be created
otherthe Array to copy from

◆ Array() [9/11]

template<typename ValueType>
gko::Array< ValueType >::Array ( const Array< ValueType > &  other)
inline

Creates a copy of another array.

This does not invoke the constructors of the elements, instead they are copied as POD types.

Parameters
otherthe Array to copy from

◆ Array() [10/11]

template<typename ValueType>
gko::Array< ValueType >::Array ( std::shared_ptr< const Executor exec,
Array< ValueType > &&  other 
)
inline

Moves another array to a different executor.

This does not invoke the constructors of the elements, instead they are copied as POD types.

Parameters
execthe executor where the new array will be moved
otherthe Array to move

◆ Array() [11/11]

template<typename ValueType>
gko::Array< ValueType >::Array ( Array< ValueType > &&  other)
inline

Moves another array.

This does not invoke the constructors of the elements, instead they are copied as POD types.

Parameters
otherthe Array to move

Member Function Documentation

◆ clear()

template<typename ValueType>
void gko::Array< ValueType >::clear ( )
inlinenoexcept

Deallocates all data used by the Array.

The array is left in a valid, but empty state, so the same array can be used to allocate new memory. Calls to Array::get_data() will return a nullptr.

◆ get_const_data()

template<typename ValueType>
const value_type* gko::Array< ValueType >::get_const_data ( ) const
inlinenoexcept

◆ get_data()

template<typename ValueType>
value_type* gko::Array< ValueType >::get_data ( )
inlinenoexcept

◆ get_executor()

template<typename ValueType>
std::shared_ptr<const Executor> gko::Array< ValueType >::get_executor ( ) const
inlinenoexcept

Returns the Executor associated with the array.

Returns
the Executor associated with the array

Referenced by gko::matrix::Hybrid< ValueType, IndexType >::strategy_type::compute_hybrid_config(), and gko::Array< index_type >::operator=().

◆ get_num_elems()

template<typename ValueType>
size_type gko::Array< ValueType >::get_num_elems ( ) const
inlinenoexcept

◆ operator=() [1/2]

template<typename ValueType>
Array& gko::Array< ValueType >::operator= ( const Array< ValueType > &  other)
inline

Copies data from another array.

This does not invoke the constructors of the elements, instead they are copied as POD types.

The executor of this is preserved. In case this does not have an assigned executor, it will inherit the executor of other.

Parameters
otherthe Array to copy from
Returns
this

◆ operator=() [2/2]

template<typename ValueType>
Array& gko::Array< ValueType >::operator= ( Array< ValueType > &&  other)
inline

Moves data from another array.

This does not invoke the constructors of the elements, instead they are copied as POD types.

The executor of this is preserved. In case this does not have an assigned executor, it will inherit the executor of other.

Parameters
otherthe Array to move data from
Returns
this

◆ resize_and_reset()

template<typename ValueType>
void gko::Array< ValueType >::resize_and_reset ( size_type  num_elems)
inline

Resizes the array so it is able to hold the specified number of elements.

All data stored in the array will be lost.

If the Array is not assigned an executor, an exception will be thrown.

Parameters
num_elemsthe amount of memory (expressed as the number of value_type elements) allocated on the Executor

Referenced by gko::Array< index_type >::operator=().

◆ set_executor()

template<typename ValueType>
void gko::Array< ValueType >::set_executor ( std::shared_ptr< const Executor exec)
inline

Changes the Executor of the Array, moving the allocated data to the new Executor.

Parameters
execthe Executor where the data will be moved to

◆ view()

template<typename ValueType>
static Array gko::Array< ValueType >::view ( std::shared_ptr< const Executor exec,
size_type  num_elems,
value_type data 
)
inlinestatic

Creates an Array from existing memory.

The Array does not take ownership of the memory, and will not deallocate it once it goes out of scope.

Parameters
execexecutor where data is located
num_elemsnumber of elements in data
datachunk of memory used to create the array
Returns
an Array constructed from data

Referenced by gko::matrix::Dense< ValueType >::create_submatrix().


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