HalleyChebyAD
 All Classes Files Functions Variables Friends
SimpleVector.hpp
Go to the documentation of this file.
1 // tminres is free software; you can redistribute it and/or modify it under the
2 // terms of the GNU Lesser General Public License (as published by the Free
3 // Software Foundation) version 2.1 dated February 1999.
4 //
5 // Authors:
6 // - Umberto Villa, Emory University - uvilla@emory.edu
7 // - Michael Saunders, Stanford University
8 // - Santiago Akle, Stanford University
9 
16 #ifndef SIMPLEVECTOR_HPP_
17 #define SIMPLEVECTOR_HPP_
18 
19 #include <iostream>
20 
22 
28 {
29 public:
30 
32 
35  SimpleVector(int length);
37  virtual ~SimpleVector();
38 
40  SimpleVector & operator=(const double & val);
42  SimpleVector & operator=(const SimpleVector & RHS);
43 
44  SimpleVector(const SimpleVector& other);
46  void Scale(const double & val);
48  SimpleVector * Clone();
49 
51  void ToDouble(double * dcopy);
53  void CopyDouble(const double * source);
54 
56  double & operator[](const int i);
58  const double & operator[](const int i) const;
60  const double at(const int i) const;
61 
63  void Randomize(int seed);
64 
66  void Print(std::ostream & os) const;
67  void Print() const;
69  friend void add(const SimpleVector & v1, const double & c2, const SimpleVector & v2, SimpleVector & result);
71  friend void add(const double & c1, const SimpleVector & v1, const double & c2, const SimpleVector & v2, SimpleVector & result);
73  friend void add(const double & alpha, const SimpleVector & v1, const SimpleVector & v2, SimpleVector & result);
75  friend void add(const SimpleVector & v1, const SimpleVector & v2, const SimpleVector & v3, SimpleVector & result);
77  friend void subtract(const SimpleVector & v1, const SimpleVector & v2, SimpleVector & result);
79  friend double InnerProduct(const SimpleVector & v1, const SimpleVector & v2);
80  friend double Norm(const SimpleVector & v1);
81 
82 private:
83  double * data;
84  int length;
85 };
86 
87 
88 
89 #endif /* SIMPLEVECTOR_HPP_ */
void Print(std::ostream &os) const
Print all the entries of the vector.
Definition: SimpleVector.cpp:107
virtual ~SimpleVector()
Destructor.
Definition: SimpleVector.cpp:30
friend double InnerProduct(const SimpleVector &v1, const SimpleVector &v2)
return the inner product of v1 and v2
Definition: SimpleVector.cpp:212
void ToDouble(double *dcopy)
Copies entries of THIS into dcopy.
Definition: SimpleVector.cpp:66
SimpleVector(int length)
Constructor.
Definition: SimpleVector.cpp:22
friend void add(const SimpleVector &v1, const double &c2, const SimpleVector &v2, SimpleVector &result)
result = v1 + c2*v2
Definition: SimpleVector.cpp:123
friend void subtract(const SimpleVector &v1, const SimpleVector &v2, SimpleVector &result)
result = v1 - v2
Definition: SimpleVector.cpp:193
SimpleVector & operator=(const double &val)
Set all the entries of the Vector equal to val.
Definition: SimpleVector.cpp:41
SimpleVector * Clone()
Create a new vector with the same structure of THIS. Values are not initialized.
Definition: SimpleVector.cpp:60
void Randomize(int seed)
Fill the entries of the vector with random numbers. The vector is normalized with norm 1...
Definition: SimpleVector.cpp:96
const double at(const int i) const
Access entry i. if i < 0 return 0.
Definition: SimpleVector.cpp:87
void Scale(const double &val)
multiply THIS by a scalar value
Definition: SimpleVector.cpp:54
void CopyDouble(const double *source)
Copies entries of source into THIS.
Definition: SimpleVector.cpp:72
double & operator[](const int i)
Access entry i (non const version)
Definition: SimpleVector.cpp:76
Implementation of a dense serial vector according to Vector_traits.
Definition: SimpleVector.hpp:27