Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DMatrix5x1.h
Go to the documentation of this file.
1 #include <align_16.h>
2 
3 #ifndef USE_SSE2
4 
5 // Matrix class without SIMD instructions
6 class DMatrix5x1{
7 public:
9  for (unsigned int i=0;i<5;i++) mA[i]=0.;
10  }
11  DMatrix5x1(double a1, double a2, double a3, double a4, double a5){
12  mA[0]=a1;
13  mA[1]=a2;
14  mA[2]=a3;
15  mA[3]=a4;
16  mA[4]=a5;
17  }
19 
20  // Access by row number
21  double &operator() (int row){
22  return mA[row];
23  }
24  double operator() (int row) const{
25  return mA[row];
26  }
27  // Copy constructor
28  DMatrix5x1(const DMatrix5x1 &m2){
29  for (unsigned int i=0;i<5;i++){
30  mA[i]=m2(i);
31  }
32  }
33  // Assignment operator
35  for (unsigned int i=0;i<5;i++){
36  mA[i]=m2(i);
37  }
38  return *this;
39  }
40  // Matrix addition
41  DMatrix5x1 operator+(const DMatrix5x1 &m2) const{
42  return DMatrix5x1(mA[0]+m2(0),mA[1]+m2(1),mA[2]+m2(2),mA[3]+m2(3),
43  mA[4]+m2(4));
44 
45  }
47  for (unsigned int i=0;i<5;i++){
48  mA[i]+=m2(i);
49  }
50  return *this;
51  }
52 
53  // Matrix subtraction
54  DMatrix5x1 operator-(const DMatrix5x1 &m2) const{
55  return DMatrix5x1(mA[0]-m2(0),mA[1]-m2(1),mA[2]-m2(2),mA[3]-m2(3),
56  mA[4]-m2(4));
57 
58  }
59 
60  bool IsFinite(){
61  return (isfinite(mA[0]) && isfinite(mA[1]) && isfinite(mA[2]) && isfinite(mA[3]) && isfinite(mA[4]));
62  }
63 
64 
65  void Print(){
66  cout << "DMatrix5x1:" <<endl;
67  cout << " | 0 |" <<endl;
68  cout << "----------------------" <<endl;
69  for (unsigned int i=0;i<5;i++){
70  cout <<" "<<i<<" |" << setw(11)<<setprecision(6) << mA[i] << endl;
71  }
72  }
73 
74 private:
75  double mA[5];
76 };
77 
78 // Scale 5x1 matrix by a floating point number
79 inline DMatrix5x1 operator*(const double c,const DMatrix5x1 &M){
80  return DMatrix5x1(c*M(0),c*M(1),c*M(2),c*M(3),c*M(4));
81 }
82 
83 #else
84 
85 // Matrix class with SIMD instructions
86 
87  class DMatrix5x1{
88  public:
89  DMatrix5x1()
90  : mA( ALIGNED_16_BLOCK_PTR(union dvec, 1, mA) )
91  {
92  for (unsigned int j=0;j<3;j++){
93  mA->v[j]=_mm_setzero_pd();
94  }
95  }
96  DMatrix5x1(__m128d v1, __m128d v2, __m128d v3)
97  : mA( ALIGNED_16_BLOCK_PTR(union dvec, 1, mA) )
98  {
99  mA->v[0]=v1;
100  mA->v[1]=v2;
101  mA->v[2]=v3;
102  }
103  DMatrix5x1(double a1, double a2, double a3, double a4, double a5)
104  : mA( ALIGNED_16_BLOCK_PTR(union dvec, 1, mA) )
105  {
106  mA->d[0]=a1;
107  mA->d[1]=a2;
108  mA->d[2]=a3;
109  mA->d[3]=a4;
110  mA->d[4]=a5;
111  mA->d[5]=0.;
112  }
113  ~DMatrix5x1(){};
114 
115  __m128d GetV(int pair) const{
116  return mA->v[pair];
117  }
118 
119  // Copy constructor
120  DMatrix5x1(const DMatrix5x1 &m2)
121  : mA( ALIGNED_16_BLOCK_PTR(union dvec, 1, mA) )
122  {
123  mA->v[0]=m2.GetV(0);
124  mA->v[1]=m2.GetV(1);
125  mA->v[2]=m2.GetV(2);
126  }
127  // Access by row number
128  double &operator() (int row){
129  return mA->d[row];
130  }
131  double operator() (int row) const{
132  return mA->d[row];
133  }
134  // Assignment operator
135  DMatrix5x1 &operator=(const DMatrix5x1 &m2){
136  mA->v[0]=m2.GetV(0);
137  mA->v[1]=m2.GetV(1);
138  mA->v[2]=m2.GetV(2);
139  return *this;
140  }
141 
142  // Matrix addition
143  DMatrix5x1 operator+(const DMatrix5x1 &m2) const{
144  return DMatrix5x1(_mm_add_pd(GetV(0),m2.GetV(0)),
145  _mm_add_pd(GetV(1),m2.GetV(1)),
146  _mm_add_pd(GetV(2),m2.GetV(2)));
147  }
148  DMatrix5x1 &operator+=(const DMatrix5x1 &m2){
149  mA->v[0]=_mm_add_pd(GetV(0),m2.GetV(0));
150  mA->v[1]=_mm_add_pd(GetV(1),m2.GetV(1));
151  mA->v[2]=_mm_add_pd(GetV(2),m2.GetV(2));
152  return *this;
153  }
154 
155  // Matrix subtraction
156  DMatrix5x1 operator-(const DMatrix5x1 &m2) const{
157  return DMatrix5x1(_mm_sub_pd(GetV(0),m2.GetV(0)),
158  _mm_sub_pd(GetV(1),m2.GetV(1)),
159  _mm_sub_pd(GetV(2),m2.GetV(2)));
160  }
161 
162  void Print(){
163  cout << "DMatrix5x1:" <<endl;
164  cout << " | 0 |" <<endl;
165  cout << "----------------------" <<endl;
166  for (unsigned int i=0;i<5;i++){
167  cout <<" "<<i<<" |" << setw(11)<<setprecision(4) << mA->d[i] << endl;
168  }
169  }
170 
171  private:
172  union dvec{
173  __m128d v[3];
174  double d[6];
175  };
176  ALIGNED_16_BLOCK(union dvec, 1, mA)
177 
178  };
179 
180 // Scale 5x1 matrix by a floating point number
181 inline DMatrix5x1 operator*(const double c,const DMatrix5x1 &M){
182  ALIGNED_16_BLOCK_WITH_PTR(__m128d, 1, p)
183  __m128d &scale=p[0];
184  scale=_mm_set1_pd(c);
185  return DMatrix5x1(_mm_mul_pd(scale,M.GetV(0)),
186  _mm_mul_pd(scale,M.GetV(1)),
187  _mm_mul_pd(scale,M.GetV(2)));
188 }
189 
190 #endif
DMatrix2x1 operator*(const double c, const DMatrix2x1 &M)
Definition: DMatrix2x1.h:58
#define ALIGNED_16_BLOCK_PTR(TYPE, NUM, PTR)
Definition: align_16.h:24
DMatrix5x1(double a1, double a2, double a3, double a4, double a5)
Definition: DMatrix5x1.h:11
DMatrix5x1 & operator+=(const DMatrix5x1 &m2)
Definition: DMatrix5x1.h:46
#define c
#define ALIGNED_16_BLOCK_WITH_PTR(TYPE, NUM, PTR)
Definition: align_16.h:27
bool IsFinite()
Definition: DMatrix5x1.h:60
DMatrix5x1 & operator=(const DMatrix5x1 &m2)
Definition: DMatrix5x1.h:34
DMatrix5x1()
Definition: DMatrix5x1.h:8
double mA[5]
Definition: DMatrix5x1.h:75
DMatrix5x1 operator-(const DMatrix5x1 &m2) const
Definition: DMatrix5x1.h:54
DMatrix5x1(const DMatrix5x1 &m2)
Definition: DMatrix5x1.h:28
void Print()
Definition: DMatrix5x1.h:65
double & operator()(int row)
Definition: DMatrix5x1.h:21
DMatrix5x1 operator+(const DMatrix5x1 &m2) const
Definition: DMatrix5x1.h:41
#define ALIGNED_16_BLOCK(TYPE, NUM, PTR)
Definition: align_16.h:19