44 #ifndef ROL_STDVECTOR_H 45 #define ROL_STDVECTOR_H 59 template <
class Real,
class Element=Real>
62 typedef typename std::vector<Real>::size_type
uint;
74 TEUCHOS_TEST_FOR_EXCEPTION(
dimension() != x.dimension(),
75 std::invalid_argument,
76 "Error: Vectors must have the same dimension." );
79 const std::vector<Element>& xval = *ex.
getVector();
80 std::copy(xval.begin(),xval.end(),
std_vec_->begin());
86 std::invalid_argument,
87 "Error: Vectors must have the same dimension." );
90 const std::vector<Element>& xval = *ex.
getVector();
92 for (
uint i=0; i<dim; i++) {
93 (*std_vec_)[i] += xval[i];
100 std::invalid_argument,
101 "Error: Vectors must have the same dimension." );
104 const std::vector<Element>& xval = *ex.
getVector();
106 for (
uint i=0; i<dim; i++) {
107 (*std_vec_)[i] += alpha*xval[i];
113 for (
uint i=0; i<dim; i++) {
114 (*std_vec_)[i] *= alpha;
121 std::invalid_argument,
122 "Error: Vectors must have the same dimension." );
125 const std::vector<Element>& xval = *ex.
getVector();
128 for (
uint i=0; i<dim; i++) {
129 val += (*std_vec_)[i]*xval[i];
136 val = std::sqrt(
dot(*
this) );
140 virtual Teuchos::RCP<Vector<Real> >
clone()
const {
141 return Teuchos::rcp(
new StdVector( Teuchos::rcp(
new std::vector<Element>(
std_vec_->size())) ));
144 Teuchos::RCP<const std::vector<Element> >
getVector()
const {
152 Teuchos::RCP<Vector<Real> >
basis(
const int i )
const {
154 TEUCHOS_TEST_FOR_EXCEPTION( i >=
dimension() || i<0,
155 std::invalid_argument,
156 "Error: Basis index must be between 0 and vector dimension." );
158 Teuchos::RCP<StdVector> e = Teuchos::rcp(
new StdVector( Teuchos::rcp(
new std::vector<Element>(
std_vec_->size(), 0.0)) ));
159 (*e->getVector())[i] = 1.0;
164 return static_cast<int>(
std_vec_->size());
167 void applyUnary(
const Elementwise::UnaryFunction<Real> &f ) {
169 for(
uint i=0; i<dim; ++i) {
170 (*std_vec_)[i] = f.apply((*
std_vec_)[i]);
177 std::invalid_argument,
178 "Error: Vectors must have the same dimension." );
181 const std::vector<Element>& xval = *ex.
getVector();
183 for (
uint i=0; i<dim; i++) {
184 (*std_vec_)[i] = f.apply((*
std_vec_)[i],xval[i]);
189 Real
reduce(
const Elementwise::ReductionOp<Real> &r )
const {
190 Real result = r.initialValue();
192 for(
uint i=0; i<dim; ++i) {
void axpy(const Real alpha, const Vector< Real > &x)
Compute where .
void scale(const Real alpha)
Compute where .
virtual Real dot(const Vector< Real > &x) const
Compute where .
Teuchos::RCP< Vector< Real > > basis(const int i) const
Return i-th basis vector.
StdVector(const Teuchos::RCP< std::vector< Element > > &std_vec)
void applyBinary(const Elementwise::BinaryFunction< Real > &f, const Vector< Real > &x)
Defines the linear algebra or vector space interface.
Teuchos::RCP< std::vector< Element > > getVector()
Provides the std::vector implementation of the ROL::Vector interface.
void plus(const Vector< Real > &x)
Compute , where .
virtual int dimension() const
Return dimension of the vector space.
Teuchos::RCP< const std::vector< Element > > getVector() const
Teuchos::RCP< std::vector< Element > > std_vec_
std::vector< Real >::size_type uint
virtual Teuchos::RCP< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
int dimension() const
Return dimension of the vector space.
void applyUnary(const Elementwise::UnaryFunction< Real > &f)
Real norm() const
Returns where .
Real reduce(const Elementwise::ReductionOp< Real > &r) const