44 #ifndef ROL_VECTORPROFILER_H 45 #define ROL_VECTORPROFILER_H 69 template<
class Ordinal>
90 constructor_(0), destructor_(0), plus_(0), scale_(0), dot_(0), norm_(0), clone_(0),
91 axpy_(0), zero_(0), basis_(0), dimension_(0), set_(0), dual_(0), applyUnary_(0),
92 applyBinary_(0), reduce_(0), setScalar_(0), randomize_(0) {}
98 template<
class Ordinal,
class Real>
101 template<
class Ordinal,
class Real>
106 template<
class Ordinal,
class Real>
108 outStream <<
"Total Vector Function Calls" << std::endl;
109 outStream <<
"---------------------------" << std::endl;
110 outStream <<
"Constructor : " << x.
functionCalls_.constructor_ << std::endl;
111 outStream <<
"Destructor : " << x.
functionCalls_.destructor_ << std::endl;
122 outStream <<
"dimension : " << x.
functionCalls_.dimension_ << std::endl;
123 outStream <<
"applyUnary : " << x.
functionCalls_.applyUnary_ << std::endl;
124 outStream <<
"applyBinary : " << x.
functionCalls_.applyBinary_ << std::endl;
125 outStream <<
"reduce : " << x.
functionCalls_.reduce_ << std::endl;
126 outStream <<
"setScalar : " << x.
functionCalls_.setScalar_ << std::endl;
127 outStream <<
"randomize : " << x.
functionCalls_.randomize_ << std::endl;
132 template<
class Ordinal,
class Real>
138 ROL::Ptr<Vector<Real> >
v_;
144 ROL::Ptr<ProfiledVector> pv = ROL::nullPtr;
145 pv = ROL::dynamicPtrCast<ProfiledVector>(v);
146 ROL_TEST_FOR_EXCEPTION( pv != ROL::nullPtr, std::logic_error,
"ProfiledVector class " 147 "cannot encapsulate a ProfiledVector object!");
159 ROL::Ptr<const V> xp =
dynamic_cast<const ProfiledVector&
>(x).getVector();
161 functionCalls_.
plus_++;
171 ROL::Ptr<const V> xp =
dynamic_cast<const ProfiledVector&
>(x).getVector();
172 functionCalls_.
dot_++;
177 functionCalls_.
norm_++;
181 ROL::Ptr<Vector<Real> >
clone()
const {
183 return ROL::makePtr<ProfiledVector>( v_->clone() );
187 ROL::Ptr<const V> xp =
dynamic_cast<const ProfiledVector&
>(x).getVector();
188 functionCalls_.
axpy_++;
189 return v_->axpy(alpha,*xp);
193 functionCalls_.
zero_++;
197 ROL::Ptr<Vector<Real> >
basis(
const int i )
const {
199 return ROL::makePtr<ProfiledVector>( v_->basis(i) );
204 return v_->dimension();
208 ROL::Ptr<const V> xp =
dynamic_cast<const ProfiledVector&
>(x).getVector();
209 functionCalls_.
set_++;
215 functionCalls_.
dual_++;
227 void applyUnary(
const Elementwise::UnaryFunction<Real> &f ) {
234 v_->applyBinary(f,x);
237 Real
reduce(
const Elementwise::ReductionOp<Real> &r )
const {
239 return v_->reduce(r);
252 void print( std::ostream &outStream )
const {
253 v_->print(outStream);
264 #endif // ROL_RANDOMVECTOR_H ROL::Ptr< Vector< Real > > basis(const int i) const
Return i-th basis vector.
const Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Real dot(const Vector< Real > &x) const
Compute where .
void print(std::ostream &outStream) const
Real norm() const
Returns where .
Defines the linear algebra or vector space interface.
void scale(const Real alpha)
Compute where .
ROL::Ptr< Vector< Real > > getVector()
ROL::Ptr< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
ProfiledVector(const ROL::Ptr< Vector< Real > > &v)
static VectorFunctionCalls< Ordinal > functionCalls_
ROL::Ptr< const Vector< Real > > getVector() const
void zero()
Set to zero vector.
void randomize(const Real l=0.0, const Real u=1.0)
Set vector to be uniform random between [l,u].
void applyUnary(const Elementwise::UnaryFunction< Real > &f)
ROL::Ptr< Vector< Real > > v_
void printVectorFunctionCalls(const ProfiledVector< Ordinal, Real > &x, std::ostream &outStream=std::cout)
virtual ~ProfiledVector()
By keeping a pointer to this in a derived Vector class, a tally of all methods is kept for profiling ...
Real reduce(const Elementwise::ReductionOp< Real > &r) const
void applyBinary(const Elementwise::BinaryFunction< Real > &f, const Vector< Real > &x)
void plus(const Vector< Real > &x)
Compute , where .
void axpy(const Real alpha, const Vector< Real > &x)
Compute where .
VectorFunctionCalls< Ordinal > getVectorFunctionCalls(const ProfiledVector< Ordinal, Real > &x)
void setScalar(const Real C)
Set where .
int dimension() const
Return dimension of the vector space.