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}\).
 
void plus (const Vector< Real > &x)
 Compute \(y \leftarrow y + x\), where \(y = \mathtt{*this}\).
 
void axpy (const Real alpha, const Vector< Real > &x)
 Compute \(y \leftarrow \alpha x + y\) where \(y = \mathtt{*this}\).
 
void scale (const Real alpha)
 Compute \(y \leftarrow \alpha y\) where \(y = \mathtt{*this}\).
 
virtual Real dot (const Vector< Real > &x) const
 Compute \( \langle y,x \rangle \) where \(y = \mathtt{*this}\).
 
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::Vector< Real >
virtual ~Vector ()
 
virtual void plus (const Vector &x)=0
 Compute \(y \leftarrow y + x\), where \(y = \mathtt{*this}\).
 
virtual void scale (const Real alpha)=0
 Compute \(y \leftarrow \alpha y\) where \(y = \mathtt{*this}\).
 
virtual Real dot (const Vector &x) const =0
 Compute \( \langle y,x \rangle \) where \(y = \mathtt{*this}\).
 
virtual Real norm () const =0
 Returns \( \| y \| \) where \(y = \mathtt{*this}\).
 
virtual ROL::Ptr< Vectorclone () const =0
 Clone to make a new (uninitialized) vector.
 
virtual void axpy (const Real alpha, const Vector &x)
 Compute \(y \leftarrow \alpha x + y\) where \(y = \mathtt{*this}\).
 
virtual void zero ()
 Set to zero vector.
 
virtual ROL::Ptr< Vectorbasis (const int i) const
 Return i-th basis vector.
 
virtual int dimension () const
 Return dimension of the vector space.
 
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 applyUnary (const Elementwise::UnaryFunction< Real > &f)
 
virtual void applyBinary (const Elementwise::BinaryFunction< Real > &f, const Vector &x)
 
virtual Real reduce (const Elementwise::ReductionOp< Real > &r) const
 
virtual void print (std::ostream &outStream) const
 
virtual void setScalar (const Real C)
 Set \(y \leftarrow C\) where \(C\in\mathbb{R}\).
 
virtual void randomize (const Real l=0.0, const Real u=1.0)
 Set vector to be uniform random between [l,u].
 
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 62 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 65 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

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

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

◆ 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

◆ 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

◆ 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

◆ 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)
inlinevirtual

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

   @param[in]      x     is a vector.

   On return \f$\mathtt{*this} = x\f$.
   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 86 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::_array(), and ROL::StdArray< Real, array_size, pool_size >::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)
inlinevirtual

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

   @param[in]      x  is the vector to be added to \f$\mathtt{*this}\f$.

   On return \f$\mathtt{*this} = \mathtt{*this} + x\f$.

   ---

Implements ROL::Vector< Real >.

Definition at line 91 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::_array(), and ROL::StdArray< Real, array_size, pool_size >::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 
)
inlinevirtual

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

   @param[in]      alpha is the scaling of @b x.
   @param[in]      x     is a vector.

   On return \f$\mathtt{*this} = \mathtt{*this} + \alpha x \f$.
   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 96 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::_array(), and ROL::StdArray< Real, array_size, pool_size >::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::Vector< Real >.

Definition at line 101 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::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

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

   @param[in]      x  is the vector that forms the dot product with \f$\mathtt{*this}\f$.
   @return         The number equal to \f$\langle \mathtt{*this}, x \rangle\f$.

   ---

Implements ROL::Vector< Real >.

Definition at line 105 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::_array(), and ROL::StdArray< Real, array_size, pool_size >::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::Vector< Real >.

Definition at line 112 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::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::Vector< Real >.

Definition at line 118 of file ROL_StdArray.hpp.

Referenced by ROL::StdArray< Real, array_size, pool_size >::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::Vector< Real >.

Definition at line 122 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().

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

Definition at line 130 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::Vector< Real >.

Definition at line 132 of file ROL_StdArray.hpp.

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

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

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

Definition at line 134 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::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 
)
inlinevirtual

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

Definition at line 145 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::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::Vector< Real >.

Definition at line 151 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::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::Vector< Real >.

Definition at line 153 of file ROL_StdArray.hpp.

References ROL::StdArray< Real, array_size, pool_size >::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::Vector< Real >.

Definition at line 160 of file ROL_StdArray.hpp.

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

◆ initialize_pool()

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

◆ pool_count()

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

References ROL::StdArray< Real, array_size, pool_size >::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

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>
std::array< std::array< Real, array_size >, pool_size > ROL::StdArray< Real, array_size, pool_size >::pool
staticprivate

◆ pool_ptr

template<typename Real , std::size_t array_size, std::size_t pool_size>
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: