ROL
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)
void plus (const Vector< Real > &x)
void axpy (const Real alpha, const Vector< Real > &x)
void scale (const Real alpha)
 Compute \(y \leftarrow \alpha y\) where \(y = \mathtt{*this}\).
virtual Real dot (const Vector< Real > &x) const
Real norm () const
 Returns \( \| y \| \) where \(y = \mathtt{*this}\).
virtual Ptr< Vector< Real > > clone () const
 Clone to make a new (uninitialized) vector.
Ptr< Vector< Real > > basis (const int i) const
 Return i-th basis vector.
int dimension () const
 Return dimension of the vector space.
void zero ()
 Set to zero vector.
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}\).
void randomize (const Real l=-1.0, const Real u=1.0)
 Set vector to be uniform random between [l,u].
virtual void print (std::ostream &outStream) const
Public Member Functions inherited from ROL::ROL::Vector< Real >
virtual ~Vector ()
virtual void plus (const Vector &x)=0
 Compute \(y \leftarrow y + x\), where \(y = \mathtt{*this}\).
virtual Real dot (const Vector &x) const =0
 Compute \( \langle y,x \rangle \) where \(y = \mathtt{*this}\).
virtual void axpy (const Real alpha, const Vector &x)
 Compute \(y \leftarrow \alpha x + y\) where \(y = \mathtt{*this}\).
virtual void set (const Vector &x)
 Set \(y \leftarrow x\) where \(y = \mathtt{*this}\).
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.
virtual Real apply (const Vector< Real > &x) const
 Apply \(\mathtt{*this}\) to a dual vector. This is equivalent to the call \(\mathtt{this->dot(x.dual())}\).
virtual void applyBinary (const Elementwise::BinaryFunction< Real > &f, const Vector &x)
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.

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 28 of file ROL_StdArray.hpp.

Member Typedef Documentation

◆ data_type

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 31 of file ROL_StdArray.hpp.

Constructor & Destructor Documentation

◆ StdArray() [1/2]

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

Definition at line 33 of file ROL_StdArray.hpp.

References data, and pool_ptr.

Referenced by _array(), and basis().

◆ StdArray() [2/2]

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 144 of file ROL_StdArray.hpp.

References data.

Member Function Documentation

◆ operator[]() [1/2]

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

Definition at line 46 of file ROL_StdArray.hpp.

References data.

◆ operator[]() [2/2]

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

Definition at line 47 of file ROL_StdArray.hpp.

References data.

◆ get_array() [1/2]

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

Definition at line 49 of file ROL_StdArray.hpp.

References data.

Referenced by _array().

◆ get_array() [2/2]

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

Definition at line 50 of file ROL_StdArray.hpp.

References data.

◆ set()

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)
inline

Definition at line 52 of file ROL_StdArray.hpp.

References _array(), and data.

◆ plus()

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)
inline

Definition at line 57 of file ROL_StdArray.hpp.

References _array(), and data.

◆ axpy()

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 )
inline

Definition at line 62 of file ROL_StdArray.hpp.

References _array(), and data.

◆ scale()

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}\).

  @param[in]      alpha is the scaling of \f$\mathtt{*this}\f$.

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

  ---

Implements ROL::ROL::Vector< Real >.

Definition at line 67 of file ROL_StdArray.hpp.

References data.

Referenced by main().

◆ dot()

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

Definition at line 71 of file ROL_StdArray.hpp.

References _array(), and data.

◆ norm()

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}\).

  @return         A nonnegative number equal to the norm of \f$\mathtt{*this}\f$.

  ---

Implements ROL::ROL::Vector< Real >.

Definition at line 78 of file ROL_StdArray.hpp.

References data.

◆ clone()

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.

  @return         A reference-counted pointer to the cloned vector.

  Provides the means of allocating temporary memory in ROL.

  ---             

Implements ROL::ROL::Vector< Real >.

Definition at line 84 of file ROL_StdArray.hpp.

Referenced by basis(), and main().

◆ basis()

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.

  @param[in] i is the index of the basis function.
  @return A reference-counted pointer to the basis vector with index @b i.

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

  ---

Reimplemented from ROL::ROL::Vector< Real >.

Definition at line 88 of file ROL_StdArray.hpp.

References clone(), and StdArray().

Referenced by main().

◆ dimension()

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.

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

  Overload if the basis is overloaded.

  ---

Reimplemented from ROL::ROL::Vector< Real >.

Definition at line 96 of file ROL_StdArray.hpp.

◆ zero()

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::ROL::Vector< Real >.

Definition at line 98 of file ROL_StdArray.hpp.

References data.

◆ applyUnary()

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::ROL::Vector< Real >.

Definition at line 100 of file ROL_StdArray.hpp.

References data.

◆ applyBinary()

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 )
inline

Definition at line 104 of file ROL_StdArray.hpp.

References _array(), and data.

◆ reduce()

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::ROL::Vector< Real >.

Definition at line 111 of file ROL_StdArray.hpp.

References data.

◆ setScalar()

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}\).

  @param[in]      C     is a scalar.

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

  ---

Reimplemented from ROL::ROL::Vector< Real >.

Definition at line 117 of file ROL_StdArray.hpp.

References data.

◆ randomize()

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].

  @param[in]      l     is a the lower bound.
  @param[in]      u     is a the upper bound.

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

  ---

Reimplemented from ROL::ROL::Vector< Real >.

Definition at line 119 of file ROL_StdArray.hpp.

References data.

Referenced by main().

◆ print()

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::ROL::Vector< Real >.

Definition at line 126 of file ROL_StdArray.hpp.

References data.

◆ initialize_pool()

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

Definition at line 131 of file ROL_StdArray.hpp.

References pool, and pool_ptr.

Referenced by main().

◆ pool_count()

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

Definition at line 136 of file ROL_StdArray.hpp.

References pool_ptr.

Referenced by main().

◆ _array()

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

Definition at line 146 of file ROL_StdArray.hpp.

References get_array(), and StdArray().

Referenced by applyBinary(), axpy(), dot(), plus(), and set().

Member Data Documentation

◆ data

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

◆ pool

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

Definition at line 153 of file ROL_StdArray.hpp.

Referenced by initialize_pool().

◆ pool_ptr

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

Definition at line 154 of file ROL_StdArray.hpp.

Referenced by initialize_pool(), pool_count(), and StdArray().


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