Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
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
13namespace JMATH {}
14namespace JPP { using namespace JMATH; }
15
16namespace 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
I/O manipulators.
JFormat_t & getFormat()
Get format for given type.
Definition JManip.hh:682
Auxiliary classes and methods for mathematical operations.
Definition JEigen3D.hh:88
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Data structure for format specifications.
Definition JManip.hh:524
Auxiliary class to temporarily define format specifications.
Definition JManip.hh:636
Nx1 matrix.
Definition JVectorND.hh:23
JVectorND()
Default constructor.
Definition JVectorND.hh:27
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
double getDot(const JVectorND &vector) const
Get dot product.
Definition JVectorND.hh:59
JVectorND(size_t size)
Constructor.
Definition JVectorND.hh:37