Jpp  17.3.0-rc.2
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  * Get dot product.
44  *
45  * \param vector vector
46  * \return dot product
47  */
48  double getDot(const JVectorND& vector) const
49  {
50  double dot = 0.0;
51 
52  const double* p = this-> data();
53  const double* q = vector.data();
54 
55  for (size_t i = this->size(); i != 0; --i, ++p, ++q) {
56  dot += (*p) * (*q);
57  }
58 
59  return dot;
60  }
61 
62 
63  /**
64  * Print ASCII formatted output.
65  *
66  * \param out output stream
67  * \param object Nx1 matrix
68  * \return output stream
69  */
70  friend inline std::ostream& operator<<(std::ostream& out, const JVectorND& object)
71  {
72  using namespace std;
73 
74  const JFormat format(out, getFormat<JVectorND>(JFormat_t(9, 3, std::ios::fixed | std::ios::showpos)));
75 
76  for (JVectorND::const_iterator i = object.begin(); i != object.end(); ++i) {
77  out << format << *i << ' ';
78  }
79 
80  out << endl;
81 
82  return out;
83  }
84  };
85 }
86 
87 #endif
friend std::ostream & operator<<(std::ostream &out, const JVectorND &object)
Print ASCII formatted output.
Definition: JVectorND.hh:70
Auxiliary class to temporarily define format specifications.
Definition: JManip.hh:632
double getDot(const JVectorND &vector) const
Get dot product.
Definition: JVectorND.hh:48
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