44 #ifndef ROL_SCALEDSTDVECTOR_H 45 #define ROL_SCALEDSTDVECTOR_H 64 template <
class Real,
class Element=Real>
67 template <
class Real,
class Element=Real>
70 template <
class Real,
class Element>
73 typedef typename std::vector<Element>::size_type
uint;
79 mutable Teuchos::RCP<DualScaledStdVector<Real> >
dual_vec_;
84 const Teuchos::RCP<std::vector<Element> > & scaling_vec) :
85 std_vec_(std_vec), scaling_vec_(scaling_vec) {}
89 const std::vector<Element>& xval = *ex.
getVector();
90 std::copy(xval.begin(),xval.end(),std_vec_->begin());
95 const std::vector<Element>& xval = *ex.
getVector();
98 (*std_vec_)[i] += xval[i];
104 const std::vector<Element>& xval = *ex.
getVector();
107 (*std_vec_)[i] += alpha*xval[i];
114 (*std_vec_)[i] *= alpha;
120 const std::vector<Element>& xval = *ex.
getVector();
124 val += (*std_vec_)[i]*xval[i]*(*scaling_vec_)[i];
131 val = std::sqrt(
dot(*
this) );
135 Teuchos::RCP<Vector<Real> >
clone()
const {
139 Teuchos::RCP<const std::vector<Element> >
getVector()
const {
148 std::vector<Element> tmp_vec(*std_vec_);
149 tmp_vec[0] *= (*scaling_vec_)[0];
150 tmp_vec[1] *= (*scaling_vec_)[1];
151 dual_vec_ = Teuchos::rcp(
new DualScaledStdVector<Real>( Teuchos::rcp(
new std::vector<Element>(tmp_vec)), scaling_vec_ ) );
155 Teuchos::RCP<Vector<Real> >
basis(
const int i )
const {
156 Teuchos::RCP<PrimalScaledStdVector> e = Teuchos::rcp(
new PrimalScaledStdVector( Teuchos::rcp(
new std::vector<Element>(std_vec_->size(), 0.0)), scaling_vec_ ));
157 (*e->getVector())[i] = 1.0;
162 return std_vec_->size();
165 void applyUnary(
const Elementwise::UnaryFunction<Real> &f ) {
168 (*std_vec_)[i] = f.apply((*std_vec_)[i]);
174 Teuchos::RCP<const std::vector<Element> > xval = Teuchos::null;
179 catch (std::exception &e) {
185 (*std_vec_)[i] = f.apply((*std_vec_)[i],(*xval)[i]);
190 Real
reduce(
const Elementwise::ReductionOp<Real> &r )
const {
191 Real result = r.initialValue();
194 r.reduce((*std_vec_)[i],result);
203 template <
class Real,
class Element>
206 typedef typename std::vector<Element>::size_type
uint;
212 mutable Teuchos::RCP<PrimalScaledStdVector<Real> >
dual_vec_;
217 const Teuchos::RCP<std::vector<Element> > & scaling_vec) :
218 std_vec_(std_vec), scaling_vec_(scaling_vec) {}
222 const std::vector<Element>& xval = *ex.
getVector();
223 std::copy(xval.begin(),xval.end(),std_vec_->begin());
228 const std::vector<Element>& xval = *ex.
getVector();
231 (*std_vec_)[i] += xval[i];
237 const std::vector<Element>& xval = *ex.
getVector();
240 (*std_vec_)[i] += alpha*xval[i];
247 (*std_vec_)[i] *= alpha;
253 const std::vector<Element>& xval = *ex.
getVector();
257 val += (*std_vec_)[i]*xval[i]/(*scaling_vec_)[i];
264 val = std::sqrt(
dot(*
this) );
268 Teuchos::RCP<Vector<Real> >
clone()
const {
272 Teuchos::RCP<const std::vector<Element> >
getVector()
const {
281 std::vector<Element> tmp_vec(*std_vec_);
282 tmp_vec[0] /= (*scaling_vec_)[0];
283 tmp_vec[1] /= (*scaling_vec_)[1];
288 Teuchos::RCP<Vector<Real> >
basis(
const int i )
const {
289 Teuchos::RCP<DualScaledStdVector> e = Teuchos::rcp(
new DualScaledStdVector( Teuchos::rcp(
new std::vector<Element>(std_vec_->size(), 0.0)), scaling_vec_ ));
290 (*e->getVector())[i] = 1.0;
295 return std_vec_->size();
298 void applyUnary(
const Elementwise::UnaryFunction<Real> &f ) {
301 (*std_vec_)[i] = f.apply((*std_vec_)[i]);
307 Teuchos::RCP<const std::vector<Element> > xval = Teuchos::null;
312 catch (std::exception &e) {
318 (*std_vec_)[i] = f.apply((*std_vec_)[i],(*xval)[i]);
323 Real
reduce(
const Elementwise::ReductionOp<Real> &r )
const {
324 Real result = r.initialValue();
327 r.reduce((*std_vec_)[i],result);
Real reduce(const Elementwise::ReductionOp< Real > &r) const
Teuchos::RCP< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
std::vector< Element >::size_type uint
Teuchos::RCP< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
Teuchos::RCP< PrimalScaledStdVector< Real > > dual_vec_
Provides the std::vector implementation of the ROL::Vector interface that handles scalings in the inn...
Real norm() const
Returns where .
PrimalScaledStdVector(const Teuchos::RCP< std::vector< Element > > &std_vec, const Teuchos::RCP< std::vector< Element > > &scaling_vec)
void scale(const Real alpha)
Compute where .
void applyUnary(const Elementwise::UnaryFunction< Real > &f)
std::vector< Element >::size_type uint
Defines the linear algebra or vector space interface.
void applyBinary(const Elementwise::BinaryFunction< Real > &f, const Vector< Real > &x)
Real dot(const Vector< Real > &x) const
Compute where .
Teuchos::RCP< std::vector< Element > > std_vec_
Real dot(const Vector< Real > &x) const
Compute where .
Teuchos::RCP< std::vector< Element > > getVector()
const ROL::Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
void plus(const Vector< Real > &x)
Compute , where .
Teuchos::RCP< const std::vector< Element > > getVector() const
const ROL::Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Teuchos::RCP< DualScaledStdVector< Real > > dual_vec_
Teuchos::RCP< Vector< Real > > basis(const int i) const
Return i-th basis vector.
DualScaledStdVector(const Teuchos::RCP< std::vector< Element > > &std_vec, const Teuchos::RCP< std::vector< Element > > &scaling_vec)
void plus(const Vector< Real > &x)
Compute , where .
Teuchos::RCP< const std::vector< Element > > getVector() const
int dimension() const
Return dimension of the vector space.
Teuchos::RCP< std::vector< Element > > getVector()
void applyUnary(const Elementwise::UnaryFunction< Real > &f)
void applyBinary(const Elementwise::BinaryFunction< Real > &f, const Vector< Real > &x)
Real norm() const
Returns where .
Provides the std::vector implementation of the ROL::Vector interface that handles scalings in the inn...
Real reduce(const Elementwise::ReductionOp< Real > &r) const
Teuchos::RCP< std::vector< Element > > scaling_vec_
void axpy(const Real alpha, const Vector< Real > &x)
Compute where .
int dimension() const
Return dimension of the vector space.
Teuchos::RCP< std::vector< Element > > std_vec_
Teuchos::RCP< Vector< Real > > basis(const int i) const
Return i-th basis vector.
void scale(const Real alpha)
Compute where .
Teuchos::RCP< std::vector< Element > > scaling_vec_
void axpy(const Real alpha, const Vector< Real > &x)
Compute where .