ROL
Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
ROL::ProfiledVector< Ordinal, Real > Class Template Reference

By keeping a pointer to this in a derived Vector class, a tally of all methods is kept for profiling function calls. More...

#include <ROL_ProfiledVector.hpp>

+ Inheritance diagram for ROL::ProfiledVector< Ordinal, Real >:

Public Member Functions

 ProfiledVector (const ROL::Ptr< Vector< Real > > &v)
 
virtual ~ProfiledVector ()
 
void plus (const Vector< Real > &x)
 Compute \(y \leftarrow y + x\), where \(y = \mathtt{*this}\).
 
void scale (const Real alpha)
 Compute \(y \leftarrow \alpha y\) where \(y = \mathtt{*this}\).
 
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}\).
 
ROL::Ptr< Vector< Real > > clone () const
 Clone to make a new (uninitialized) vector.
 
void axpy (const Real alpha, const Vector< Real > &x)
 Compute \(y \leftarrow \alpha x + y\) where \(y = \mathtt{*this}\).
 
void zero ()
 Set to zero vector.
 
ROL::Ptr< Vector< Real > > basis (const int i) const
 Return i-th basis vector.
 
int dimension () const
 Return dimension of the vector space.
 
void set (const Vector< Real > &x)
 Set \(y \leftarrow x\) where \(y = \mathtt{*this}\).
 
const Vector< Real > & dual () 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.
 
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())}\).
 
ROL::Ptr< Vector< Real > > getVector ()
 
ROL::Ptr< const Vector< Real > > getVector () const
 
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 C)
 Set \(y \leftarrow C\) where \(C\in\mathbb{R}\).
 
void randomize (const Real l=0.0, const Real u=1.0)
 Set vector to be uniform random between [l,u].
 
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.
 

Private Types

typedef Vector< Real > V
 

Private Member Functions

ROL::VectorFunctionCalls< int > functionCalls_
 
ROL::VectorFunctionCalls< size_typefunctionCalls_
 

Private Attributes

ROL::Ptr< Vector< Real > > v_
 

Static Private Attributes

static VectorFunctionCalls< Ordinal > functionCalls_
 

Friends

VectorFunctionCalls< Ordinal > getVectorFunctionCalls (const ProfiledVector< Ordinal, Real > &)
 
void printVectorFunctionCalls (const ProfiledVector< Ordinal, Real > &, std::ostream &)
 

Detailed Description

template<class Ordinal, class Real>
class ROL::ProfiledVector< Ordinal, Real >

By keeping a pointer to this in a derived Vector class, a tally of all methods is kept for profiling function calls.

NOTE: This class is not yet compatible with vectors that have true duals

In the cpp file where this is used, you must initialize the VectorFunctionCalls object.

Example usage:

template<> VectorFunctionCalls<int> ProfiledVector<int,double>::functionCalls = VectorFunctionCalls<int>();

Definition at line 135 of file ROL_ProfiledVector.hpp.

Member Typedef Documentation

◆ V

template<class Ordinal , class Real >
typedef Vector<Real> ROL::ProfiledVector< Ordinal, Real >::V
private

Definition at line 137 of file ROL_ProfiledVector.hpp.

Constructor & Destructor Documentation

◆ ProfiledVector()

template<class Ordinal , class Real >
ROL::ProfiledVector< Ordinal, Real >::ProfiledVector ( const ROL::Ptr< Vector< Real > > &  v)
inline

◆ ~ProfiledVector()

template<class Ordinal , class Real >
virtual ROL::ProfiledVector< Ordinal, Real >::~ProfiledVector ( )
inlinevirtual

Member Function Documentation

◆ plus()

template<class Ordinal , class Real >
void ROL::ProfiledVector< Ordinal, Real >::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 160 of file ROL_ProfiledVector.hpp.

References ROL::ProfiledVector< Ordinal, Real >::functionCalls_, ROL::ProfiledVector< Ordinal, Real >::getVector(), and ROL::ProfiledVector< Ordinal, Real >::v_.

◆ scale()

template<class Ordinal , class Real >
void ROL::ProfiledVector< Ordinal, Real >::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 167 of file ROL_ProfiledVector.hpp.

References ROL::ProfiledVector< Ordinal, Real >::functionCalls_, and ROL::ProfiledVector< Ordinal, Real >::v_.

◆ dot()

template<class Ordinal , class Real >
Real ROL::ProfiledVector< Ordinal, Real >::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 172 of file ROL_ProfiledVector.hpp.

References ROL::ProfiledVector< Ordinal, Real >::functionCalls_, ROL::ProfiledVector< Ordinal, Real >::getVector(), and ROL::ProfiledVector< Ordinal, Real >::v_.

◆ norm()

template<class Ordinal , class Real >
Real ROL::ProfiledVector< Ordinal, Real >::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 178 of file ROL_ProfiledVector.hpp.

References ROL::ProfiledVector< Ordinal, Real >::functionCalls_, and ROL::ProfiledVector< Ordinal, Real >::v_.

◆ clone()

template<class Ordinal , class Real >
ROL::Ptr< Vector< Real > > ROL::ProfiledVector< Ordinal, Real >::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 183 of file ROL_ProfiledVector.hpp.

References ROL::ProfiledVector< Ordinal, Real >::functionCalls_, and ROL::ProfiledVector< Ordinal, Real >::v_.

◆ axpy()

template<class Ordinal , class Real >
void ROL::ProfiledVector< Ordinal, Real >::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 188 of file ROL_ProfiledVector.hpp.

References ROL::ProfiledVector< Ordinal, Real >::functionCalls_, ROL::ProfiledVector< Ordinal, Real >::getVector(), and ROL::ProfiledVector< Ordinal, Real >::v_.

◆ zero()

template<class Ordinal , class Real >
void ROL::ProfiledVector< Ordinal, Real >::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 194 of file ROL_ProfiledVector.hpp.

References ROL::ProfiledVector< Ordinal, Real >::functionCalls_, and ROL::ProfiledVector< Ordinal, Real >::v_.

◆ basis()

template<class Ordinal , class Real >
ROL::Ptr< Vector< Real > > ROL::ProfiledVector< Ordinal, Real >::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 199 of file ROL_ProfiledVector.hpp.

References ROL::ProfiledVector< Ordinal, Real >::functionCalls_, and ROL::ProfiledVector< Ordinal, Real >::v_.

◆ dimension()

template<class Ordinal , class Real >
int ROL::ProfiledVector< Ordinal, Real >::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 204 of file ROL_ProfiledVector.hpp.

References ROL::ProfiledVector< Ordinal, Real >::functionCalls_, and ROL::ProfiledVector< Ordinal, Real >::v_.

◆ set()

template<class Ordinal , class Real >
void ROL::ProfiledVector< Ordinal, Real >::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 209 of file ROL_ProfiledVector.hpp.

References ROL::ProfiledVector< Ordinal, Real >::functionCalls_, ROL::ProfiledVector< Ordinal, Real >::getVector(), and ROL::ProfiledVector< Ordinal, Real >::v_.

◆ dual()

template<class Ordinal , class Real >
const Vector< Real > & ROL::ProfiledVector< Ordinal, Real >::dual ( void  ) const
inlinevirtual

Return dual representation of \(\mathtt{*this}\), for example, the result of applying a Riesz map, or change of basis, or change of memory layout.

Returns
A const reference to dual representation.

By default, returns the current object. Please overload if you need a dual representation.


Reimplemented from ROL::Vector< Real >.

Definition at line 216 of file ROL_ProfiledVector.hpp.

References ROL::ProfiledVector< Ordinal, Real >::functionCalls_.

◆ apply()

template<class Ordinal , class Real >
Real ROL::ProfiledVector< Ordinal, Real >::apply ( const Vector< Real > &  x) const
inlinevirtual

Apply \(\mathtt{*this}\) to a dual vector. This is equivalent to the call \(\mathtt{this->dot(x.dual())}\).

Parameters
[in]xis a vector
Returns
The number equal to \(\langle \mathtt{*this}, x \rangle\).

Reimplemented from ROL::Vector< Real >.

Definition at line 221 of file ROL_ProfiledVector.hpp.

References ROL::ProfiledVector< Ordinal, Real >::functionCalls_, and ROL::ProfiledVector< Ordinal, Real >::v_.

◆ getVector() [1/2]

template<class Ordinal , class Real >
ROL::Ptr< Vector< Real > > ROL::ProfiledVector< Ordinal, Real >::getVector ( )
inline

◆ getVector() [2/2]

template<class Ordinal , class Real >
ROL::Ptr< const Vector< Real > > ROL::ProfiledVector< Ordinal, Real >::getVector ( ) const
inline

Definition at line 230 of file ROL_ProfiledVector.hpp.

References ROL::ProfiledVector< Ordinal, Real >::v_.

◆ applyUnary()

template<class Ordinal , class Real >
void ROL::ProfiledVector< Ordinal, Real >::applyUnary ( const Elementwise::UnaryFunction< Real > &  f)
inlinevirtual

◆ applyBinary()

template<class Ordinal , class Real >
void ROL::ProfiledVector< Ordinal, Real >::applyBinary ( const Elementwise::BinaryFunction< Real > &  f,
const Vector< Real > &  x 
)
inlinevirtual

◆ reduce()

template<class Ordinal , class Real >
Real ROL::ProfiledVector< Ordinal, Real >::reduce ( const Elementwise::ReductionOp< Real > &  r) const
inlinevirtual

◆ setScalar()

template<class Ordinal , class Real >
void ROL::ProfiledVector< Ordinal, Real >::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 249 of file ROL_ProfiledVector.hpp.

References ROL::ProfiledVector< Ordinal, Real >::functionCalls_, and ROL::ProfiledVector< Ordinal, Real >::v_.

◆ randomize()

template<class Ordinal , class Real >
void ROL::ProfiledVector< Ordinal, Real >::randomize ( const Real  l = 0.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 254 of file ROL_ProfiledVector.hpp.

References ROL::ProfiledVector< Ordinal, Real >::functionCalls_, and ROL::ProfiledVector< Ordinal, Real >::v_.

◆ print()

template<class Ordinal , class Real >
void ROL::ProfiledVector< Ordinal, Real >::print ( std::ostream &  outStream) const
inlinevirtual

Reimplemented from ROL::Vector< Real >.

Definition at line 259 of file ROL_ProfiledVector.hpp.

References ROL::ProfiledVector< Ordinal, Real >::v_.

◆ functionCalls_() [1/2]

ROL::VectorFunctionCalls< int > ROL::ProfiledVector< int, RealT >::functionCalls_
private

Definition at line 63 of file vector/test_06.cpp.

◆ functionCalls_() [2/2]

Definition at line 62 of file vector/test_09.cpp.

Friends And Related Function Documentation

◆ getVectorFunctionCalls

template<class Ordinal , class Real >
VectorFunctionCalls< Ordinal > getVectorFunctionCalls ( const ProfiledVector< Ordinal, Real > &  x)
friend

Definition at line 103 of file ROL_ProfiledVector.hpp.

◆ printVectorFunctionCalls

template<class Ordinal , class Real >
void printVectorFunctionCalls ( const ProfiledVector< Ordinal, Real > &  x,
std::ostream &  outStream = std::cout 
)
friend

Definition at line 108 of file ROL_ProfiledVector.hpp.

Member Data Documentation

◆ v_

template<class Ordinal , class Real >
ROL::Ptr<Vector<Real> > ROL::ProfiledVector< Ordinal, Real >::v_
private

◆ functionCalls_

template<class Ordinal , class Real >
VectorFunctionCalls<Ordinal> ROL::ProfiledVector< Ordinal, Real >::functionCalls_
staticprivate

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