Jpp  18.2.1-ARCA-DF-PATCH
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JVectorND.hh
Go to the documentation of this file.
1 #ifndef __JMATH__JVECTORND__
2 #define __JMATH__JVECTORND__
3 
4 #include <vector>
5 #include <ostream>
6 
7 #include "JLang/JManip.hh"
8 
9 /**
10  * \author mdejong
11  */
12 
13 namespace JMATH {}
14 namespace JPP { using namespace JMATH; }
15 
16 namespace JMATH {
17 
18  /**
19  * Nx1 matrix.
20  */
21  struct JVectorND :
22  public std::vector<double>
23  {
24  /**
25  * Default constructor.
26  */
28  std::vector<double>()
29  {}
30 
31 
32  /**
33  * Constructor.
34  *
35  * \param size size
36  */
37  JVectorND(size_t size) :
38  std::vector<double>(size, 0.0)
39  {}
40 
41 
42  /**
43  * Reset.
44  */
45  void reset()
46  {
47  for (iterator i = this->begin(); i != this->end(); ++i) {
48  *i = 0.0;
49  }
50  }
51 
52 
53  /**
54  * Get dot product.
55  *
56  * \param vector vector
57  * \return dot product
58  */
59  double getDot(const JVectorND& vector) const
60  {
61  double dot = 0.0;
62 
63  const double* p = this-> data();
64  const double* q = vector.data();
65 
66  for (size_t i = this->size(); i != 0; --i, ++p, ++q) {
67  dot += (*p) * (*q);
68  }
69 
70  return dot;
71  }
72 
73 
74  /**
75  * Print ASCII formatted output.
76  *
77  * \param out output stream
78  * \param object Nx1 matrix
79  * \return output stream
80  */
81  friend inline std::ostream& operator<<(std::ostream& out, const JVectorND& object)
82  {
83  using namespace std;
84 
85  const JFormat format(out, getFormat<JVectorND>(JFormat_t(9, 3, std::ios::fixed | std::ios::showpos)));
86 
87  for (JVectorND::const_iterator i = object.begin(); i != object.end(); ++i) {
88  out << format << *i << ' ';
89  }
90 
91  out << endl;
92 
93  return out;
94  }
95  };
96 }
97 
98 #endif
void reset()
Reset.
Definition: JVectorND.hh:45
friend std::ostream & operator<<(std::ostream &out, const JVectorND &object)
Print ASCII formatted output.
Definition: JVectorND.hh:81
Auxiliary class to temporarily define format specifications.
Definition: JManip.hh:632
double getDot(const JVectorND &vector) const
Get dot product.
Definition: JVectorND.hh:59
I/O manipulators.
JVectorND()
Default constructor.
Definition: JVectorND.hh:27
Data structure for format specifications.
Definition: JManip.hh:522
JVectorND(size_t size)
Constructor.
Definition: JVectorND.hh:37
Nx1 matrix.
Definition: JVectorND.hh:21