ROL
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ROL::StdArray< Real, array_size, pool_size > Class Template Reference

Provides the std::array implementation of the ROL::Vector interface. More...

#include <ROL_StdArray.hpp>

+ Inheritance diagram for ROL::StdArray< Real, array_size, pool_size >:

Public Types

using data_type = std::array< Real, array_size >
 

Public Member Functions

 StdArray ()
 
Real & operator[] (std::size_t i)
 
const Real & operator[] (std::size_t i) const
 
std::array< Real, array_size > & get_array ()
 
const std::array< Real,
array_size > & 
get_array () const
 
void set (const Vector< Real > &x)
 Set \(y \leftarrow x\) where \(y = \mathtt{*this}\). More...
 
void plus (const Vector< Real > &x)
 Compute \(y \leftarrow y + x\), where \(y = \mathtt{*this}\). More...
 
void axpy (const Real alpha, const Vector< Real > &x)
 Compute \(y \leftarrow \alpha x + y\) where \(y = \mathtt{*this}\). More...
 
void scale (const Real alpha)
 Compute \(y \leftarrow \alpha y\) where \(y = \mathtt{*this}\). More...
 
virtual Real dot (const Vector< Real > &x) const
 Compute \( \langle y,x \rangle \) where \(y = \mathtt{*this}\). More...
 
Real norm () const
 Returns \( \| y \| \) where \(y = \mathtt{*this}\). More...
 
virtual Ptr< Vector< Real > > clone () const
 Clone to make a new (uninitialized) vector. More...
 
Ptr< Vector< Real > > basis (const int i) const
 Return i-th basis vector. More...
 
int dimension () const
 Return dimension of the vector space. More...
 
void zero ()
 Set to zero vector. More...
 
void applyUnary (const Elementwise::UnaryFunction< Real > &f)
 
void applyBinary (const Elementwise::BinaryFunction< Real > &f, const Vector< Real > &x)
 
Real reduce (const Elementwise::ReductionOp< Real > &r) const
 
void setScalar (const Real alpha)
 Set \(y \leftarrow C\) where \(C\in\mathbb{R}\). More...
 
void randomize (const Real l=-1.0, const Real u=1.0)
 Set vector to be uniform random between [l,u]. More...
 
virtual void print (std::ostream &outStream) const
 
- Public Member Functions inherited from ROL::Vector< Real >
virtual ~Vector ()
 
virtual const Vectordual () const
 Return dual representation of \(\mathtt{*this}\), for example, the result of applying a Riesz map, or change of basis, or change of memory layout. More...
 
virtual std::vector< Real > checkVector (const Vector< Real > &x, const Vector< Real > &y, const bool printToStream=true, std::ostream &outStream=std::cout) const
 Verify vector-space methods. More...
 

Static Public Member Functions

static void initialize_pool ()
 
static std::size_t pool_count ()
 

Private Member Functions

 StdArray (Ptr< std::array< Real, array_size >> p)
 
const std::array< Real,
array_size > & 
_array (const Vector< Real > &x) const
 

Private Attributes

Ptr< std::array< Real,
array_size > > 
data
 

Static Private Attributes

static std::array< std::array
< Real, array_size >
, pool_size > 
pool
 
static std::array< Ptr
< std::array< Real, array_size >
>, pool_size > 
pool_ptr
 

Detailed Description

template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
class ROL::StdArray< Real, array_size, pool_size >

Provides the std::array implementation of the ROL::Vector interface.

Definition at line 61 of file ROL_StdArray.hpp.

Member Typedef Documentation

template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
using ROL::StdArray< Real, array_size, pool_size >::data_type = std::array<Real,array_size>

Definition at line 64 of file ROL_StdArray.hpp.

Constructor & Destructor Documentation

template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
ROL::StdArray< Real, array_size, pool_size >::StdArray ( )
inline
template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
ROL::StdArray< Real, array_size, pool_size >::StdArray ( Ptr< std::array< Real, array_size >>  p)
inlineprivate

Definition at line 177 of file ROL_StdArray.hpp.

Member Function Documentation

template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
Real& ROL::StdArray< Real, array_size, pool_size >::operator[] ( std::size_t  i)
inline
template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
const Real& ROL::StdArray< Real, array_size, pool_size >::operator[] ( std::size_t  i) const
inline
template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
std::array<Real,array_size>& ROL::StdArray< Real, array_size, pool_size >::get_array ( )
inline
template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
const std::array<Real,array_size>& ROL::StdArray< Real, array_size, pool_size >::get_array ( ) const
inline
template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
void ROL::StdArray< Real, array_size, pool_size >::set ( const Vector< Real > &  x)
inlinevirtual

Set \(y \leftarrow x\) where \(y = \mathtt{*this}\).

Parameters
[in]xis a vector.

On return \(\mathtt{*this} = x\). Uses zero and plus methods for the computation. Please overload if a more efficient implementation is needed.


Reimplemented from ROL::Vector< Real >.

Definition at line 85 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::_array(), and ROL::StdArray< Real, array_size, pool_size >::data.

template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
void ROL::StdArray< Real, array_size, pool_size >::plus ( const Vector< Real > &  x)
inlinevirtual

Compute \(y \leftarrow y + x\), where \(y = \mathtt{*this}\).

Parameters
[in]xis the vector to be added to \(\mathtt{*this}\).

On return \(\mathtt{*this} = \mathtt{*this} + x\).


Implements ROL::Vector< Real >.

Definition at line 90 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::_array(), and ROL::StdArray< Real, array_size, pool_size >::data.

template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
void ROL::StdArray< Real, array_size, pool_size >::axpy ( const Real  alpha,
const Vector< Real > &  x 
)
inlinevirtual

Compute \(y \leftarrow \alpha x + y\) where \(y = \mathtt{*this}\).

Parameters
[in]alphais the scaling of x.
[in]xis a vector.

On return \(\mathtt{*this} = \mathtt{*this} + \alpha x \). Uses clone, set, scale and plus for the computation. Please overload if a more efficient implementation is needed.


Reimplemented from ROL::Vector< Real >.

Definition at line 95 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::_array(), and ROL::StdArray< Real, array_size, pool_size >::data.

template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
void ROL::StdArray< Real, array_size, pool_size >::scale ( const Real  alpha)
inlinevirtual

Compute \(y \leftarrow \alpha y\) where \(y = \mathtt{*this}\).

Parameters
[in]alphais the scaling of \(\mathtt{*this}\).

On return \(\mathtt{*this} = \alpha (\mathtt{*this}) \).


Implements ROL::Vector< Real >.

Definition at line 100 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::data.

Referenced by main().

template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
virtual Real ROL::StdArray< Real, array_size, pool_size >::dot ( const Vector< Real > &  x) const
inlinevirtual

Compute \( \langle y,x \rangle \) where \(y = \mathtt{*this}\).

Parameters
[in]xis the vector that forms the dot product with \(\mathtt{*this}\).
Returns
The number equal to \(\langle \mathtt{*this}, x \rangle\).

Implements ROL::Vector< Real >.

Definition at line 104 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::_array(), and ROL::StdArray< Real, array_size, pool_size >::data.

template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
Real ROL::StdArray< Real, array_size, pool_size >::norm ( ) const
inlinevirtual

Returns \( \| y \| \) where \(y = \mathtt{*this}\).

Returns
A nonnegative number equal to the norm of \(\mathtt{*this}\).

Implements ROL::Vector< Real >.

Definition at line 111 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::data.

template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
virtual Ptr<Vector<Real> > ROL::StdArray< Real, array_size, pool_size >::clone ( ) const
inlinevirtual

Clone to make a new (uninitialized) vector.

Returns
A reference-counted pointer to the cloned vector.

Provides the means of allocating temporary memory in ROL.


Implements ROL::Vector< Real >.

Definition at line 117 of file ROL_StdArray.hpp.

Referenced by ROL::StdArray< Real, array_size, pool_size >::basis(), and main().

template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
Ptr<Vector<Real> > ROL::StdArray< Real, array_size, pool_size >::basis ( const int  i) const
inlinevirtual

Return i-th basis vector.

Parameters
[in]iis the index of the basis function.
Returns
A reference-counted pointer to the basis vector with index i.

Overloading the basis is only required if the default gradient implementation is used, which computes a finite-difference approximation.


Reimplemented from ROL::Vector< Real >.

Definition at line 121 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::clone(), and ROL::StdArray< Real, array_size, pool_size >::zero().

Referenced by main().

template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
int ROL::StdArray< Real, array_size, pool_size >::dimension ( void  ) const
inlinevirtual

Return dimension of the vector space.

Returns
The dimension of the vector space, i.e., the total number of basis vectors.

Overload if the basis is overloaded.


Reimplemented from ROL::Vector< Real >.

Definition at line 129 of file ROL_StdArray.hpp.

template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
void ROL::StdArray< Real, array_size, pool_size >::zero ( )
inlinevirtual

Set to zero vector.

Uses scale by zero for the computation. Please overload if a more efficient implementation is needed.


Reimplemented from ROL::Vector< Real >.

Definition at line 131 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::data.

Referenced by ROL::StdArray< Real, array_size, pool_size >::basis().

template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
void ROL::StdArray< Real, array_size, pool_size >::applyUnary ( const Elementwise::UnaryFunction< Real > &  f)
inlinevirtual

Reimplemented from ROL::Vector< Real >.

Definition at line 133 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::data.

template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
void ROL::StdArray< Real, array_size, pool_size >::applyBinary ( const Elementwise::BinaryFunction< Real > &  f,
const Vector< Real > &  x 
)
inlinevirtual
template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
Real ROL::StdArray< Real, array_size, pool_size >::reduce ( const Elementwise::ReductionOp< Real > &  r) const
inlinevirtual

Reimplemented from ROL::Vector< Real >.

Definition at line 144 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::data.

template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
void ROL::StdArray< Real, array_size, pool_size >::setScalar ( const Real  C)
inlinevirtual

Set \(y \leftarrow C\) where \(C\in\mathbb{R}\).

Parameters
[in]Cis a scalar.

On return \(\mathtt{*this} = C\). Uses applyUnary methods for the computation. Please overload if a more efficient implementation is needed.


Reimplemented from ROL::Vector< Real >.

Definition at line 150 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::data.

template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
void ROL::StdArray< Real, array_size, pool_size >::randomize ( const Real  l = -1.0,
const Real  u = 1.0 
)
inlinevirtual

Set vector to be uniform random between [l,u].

Parameters
[in]lis a the lower bound.
[in]uis a the upper bound.

On return the components of \(\mathtt{*this}\) are uniform random numbers on the interval \([l,u]\). The default implementation uses applyUnary methods for the computation. Please overload if a more efficient implementation is needed.


Reimplemented from ROL::Vector< Real >.

Definition at line 152 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::data.

Referenced by main().

template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
virtual void ROL::StdArray< Real, array_size, pool_size >::print ( std::ostream &  outStream) const
inlinevirtual

Reimplemented from ROL::Vector< Real >.

Definition at line 159 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::data.

template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
static void ROL::StdArray< Real, array_size, pool_size >::initialize_pool ( )
inlinestatic
template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
static std::size_t ROL::StdArray< Real, array_size, pool_size >::pool_count ( )
inlinestatic

Definition at line 169 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::pool_ptr.

Referenced by main().

template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
const std::array<Real,array_size>& ROL::StdArray< Real, array_size, pool_size >::_array ( const Vector< Real > &  x) const
inlineprivate

Member Data Documentation

template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
Ptr<std::array<Real,array_size> > ROL::StdArray< Real, array_size, pool_size >::data
private
template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
std::array< std::array< Real, array_size >, pool_size > ROL::StdArray< Real, array_size, pool_size >::pool
staticprivate
template<typename Real, std::size_t array_size, std::size_t pool_size = 100u>
std::array< Ptr< std::array< Real, array_size > >, pool_size > ROL::StdArray< Real, array_size, pool_size >::pool_ptr
staticprivate

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