27 template<
typename REAL>
28 class Vector :
public std::vector<REAL>
35 static bool bScientific;
36 static std::size_t nIndexWidth;
37 static std::size_t nValueWidth;
38 static std::size_t nValuePrecision;
49 const REAL defaultvalue_ = 0
51 : std::vector<REAL>( size, defaultvalue_ )
81 const size_t s = this->size();
83 for(
size_t i=0; i<s; ++i)
102 for (size_type j=i; j<i+m; j++){
155 for (
size_t i = 0; i < this->size(); ++i)
165 for (
size_t i = 0; i < this->size(); ++i)
174 assert( this->size() == y.size());
176 for (
size_t i = 0; i < this->size(); ++i)
185 assert( this->size() == y.size());
187 for (
size_t i = 0; i < this->size(); ++i)
196 assert( this->size() == y.size());
198 for (
size_t i = 0; i < this->size(); ++i)
199 self[i] += alpha * y[i];
237 assert( x.size() == this->size() );
239 const Vector &
self = *
this;
240 for(
size_t i = 0; i < this->size(); ++i )
241 sum +=
self[i] * x[i];
282 assert( x.size() == this->size() );
324 assert( x.size() == this->size() );
336 const Vector &
self = *
this;
337 for (
size_t i = 0; i < (size_t) this->size(); ++i)
338 sum +=
self[i] *
self[i];
424 return nValuePrecision;
449 template<
typename REAL>
452 template<
typename REAL>
455 template<
typename REAL>
458 template<
typename REAL>
483 template <
typename REAL>
484 inline std::ostream & operator <<(std::ostream & os, const Vector<REAL> & x)
488 for (
size_t r = 0; r < x.size(); ++r)
493 << std::setw(x.iwidth())
498 << std::setw( x.width() )
499 << std::setprecision( x.precision() )
506 << std::setw(x.iwidth())
511 << std::setw( x.width() )
512 << std::setprecision( x.precision() )
544 template<
typename REAL>
546 const std::string& fname,
550 std::fstream f(fname.c_str(),std::ios::out);
555 f << std::setw(x.
width())
559 << std::setw( x.
width() )
566 f << std::setw(x.
width())
570 << std::setw( x.
width() )
580 template<
typename REAL>
582 const std::string& fname,
587 std::fstream f(fname.c_str(),std::ios::out);
592 f << std::setw(x.
width())
596 << std::setw( x.
width() )
600 << std::setw( x.
width() )
607 f << std::setw(x.
width())
611 << std::setw( x.
width() )
615 << std::setw( x.
width() )
655 template<
typename REAL>
659 std::ifstream fin( filename.c_str() );
665 if( sub.length()>0 ){
666 REAL a = atof(sub.c_str());
674 HDNUM_ERROR(
"Could not open file!");
Class with mathematical vector operations.
Definition: vector.hh:28
Vector & operator=(const REAL value)
Assign all values of the Vector from one scalar value: x = value.
Definition: vector.hh:79
Vector & operator-=(const Vector &y)
Subtract another vector (x -= y)
Definition: vector.hh:183
std::size_t precision() const
get data precision for pretty-printing
Definition: vector.hh:422
Vector sub(size_type i, size_type m)
Subvector extraction.
Definition: vector.hh:97
Vector()
default constructor, also inherited from the STL vector default constructor
Definition: vector.hh:43
Vector operator-(Vector &x) const
vector subtraction x-y
Definition: vector.hh:322
REAL operator*(Vector &x) const
Inner product with another vector.
Definition: vector.hh:235
void fill(Vector< REAL > &x, const REAL &t, const REAL &dt)
Fill vector, with entries starting at t, consecutively shifted by dt.
Definition: vector.hh:728
void unitvector(Vector< REAL > &x, std::size_t j)
Defines j-th unitvector (j=0,...,n-1) where n = length of the vector.
Definition: vector.hh:762
Vector & update(const REAL alpha, const Vector &y)
Update vector by addition of a scaled vector (x += a y )
Definition: vector.hh:194
bool scientific() const
pretty-print output property: true = scientific, false = fixed point representation ...
Definition: vector.hh:372
void precision(std::size_t i) const
set data precision for pretty-printing
Definition: vector.hh:440
void gnuplot(const std::string &fname, const Vector< REAL > x)
Output contents of a Vector x to a text file named fname.
Definition: vector.hh:545
REAL two_norm() const
Euclidean norm of a vector.
Definition: vector.hh:366
void scientific(bool b) const
scientific(true) is the default, scientific(false) switches to the fixed point representation ...
Definition: vector.hh:404
Vector & operator/=(const REAL value)
Division by a scalar value (x /= value)
Definition: vector.hh:162
Vector(const size_t size, const REAL defaultvalue_=0)
another constructor, with arguments, setting the default value for all entries of the vector of given...
Definition: vector.hh:48
Vector & operator*=(const REAL value)
Multiplication by a scalar value (x *= value)
Definition: vector.hh:152
Vector & operator+=(const Vector &y)
Add another vector (x += y)
Definition: vector.hh:172
void iwidth(std::size_t i) const
set index field width for pretty-printing
Definition: vector.hh:428
void readVectorFromFile(const std::string &filename, Vector< REAL > &vector)
Read vector from a text file.
Definition: vector.hh:656
std::size_t width() const
get data field width for pretty-printing
Definition: vector.hh:416
std::size_t iwidth() const
get index field width for pretty-printing
Definition: vector.hh:410
Definition: densematrix.hh:21
REAL two_norm_2() const
Square of the Euclidean norm.
Definition: vector.hh:333
Vector operator+(Vector &x) const
Adding two vectors x+y.
Definition: vector.hh:280
std::size_t size_type
Type used for array indices.
Definition: vector.hh:32
void width(std::size_t i) const
set data field width for pretty-printing
Definition: vector.hh:434