QMCPACK
TinyMatrixOps.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
8 //
9 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #ifndef OHMMS_TINYMATRIX_OPERATORS_H
14 #define OHMMS_TINYMATRIX_OPERATORS_H
15 
16 namespace qmcplusplus
17 {
18 ///////////////////////////////////////////////////////////////////////
19 // specialized assignment and element-by-element binary functors for tinymatrix
20 //
21 // Generic Assignment operators (defined in OhmmsTinyMeta.h)
22 // template<class T1, class T2, class OP> struct OTAssign {};
23 //
24 // Generic Binary operators (defined in OhmmsTinyMeta.h)
25 // template<class T1, class T2, class OP> struct OTBinary {};
26 //
27 ///////////////////////////////////////////////////////////////////////
28 
29 //////////////////////////////////////////////////////////////////////
30 // Specializations for TinyMatrixs of arbitrary size.
31 //////////////////////////////////////////////////////////////////////
32 template<class T1, class T2, class OP, unsigned D1, unsigned D2>
33 struct OTAssign<TinyMatrix<T1, D1, D2>, TinyMatrix<T2, D1, D2>, OP>
34 {
35  inline static void apply(TinyMatrix<T1, D1, D2>& lhs, const TinyMatrix<T2, D1, D2>& rhs, OP op)
36  {
37  for (unsigned d = 0; d < D1 * D2; ++d)
38  op(lhs[d], rhs[d]);
39  }
40 };
41 
42 template<class T1, class T2, class OP, unsigned D1, unsigned D2>
43 struct OTAssign<TinyMatrix<T1, D1, D2>, T2, OP>
44 {
45  inline static void apply(TinyMatrix<T1, D1, D2>& lhs, const T2& rhs, OP op)
46  {
47  for (unsigned d = 0; d < D1 * D2; ++d)
48  op(lhs[d], rhs);
49  }
50 };
51 
52 
53 //////////////////////////////////////////////////////////////////////
54 // Specializations for TinyMatrixs with D=1 x1
55 //////////////////////////////////////////////////////////////////////
56 
57 template<class T1, class T2, class OP>
58 struct OTAssign<TinyMatrix<T1, 1, 1>, TinyMatrix<T2, 1, 1>, OP>
59 {
60  inline static void apply(TinyMatrix<T1, 1, 1>& lhs, const TinyMatrix<T2, 1, 1>& rhs, OP op) { op(lhs[0], rhs[0]); }
61 };
62 
63 template<class T1, class T2, class OP>
64 struct OTAssign<TinyMatrix<T1, 1, 1>, T2, OP>
65 {
66  inline static void apply(TinyMatrix<T1, 1, 1>& lhs, const T2& rhs, OP op) { op(lhs[0], rhs); }
67 };
68 
69 //////////////////////////////////////////////////////////////////////
70 // Specializations for TinyMatrixs with D=1x2 and 2x1
71 //////////////////////////////////////////////////////////////////////
72 
73 template<class T1, class T2, class OP>
74 struct OTAssign<TinyMatrix<T1, 1, 2>, TinyMatrix<T2, 1, 2>, OP>
75 {
76  inline static void apply(TinyMatrix<T1, 1, 2>& lhs, const TinyMatrix<T2, 1, 2>& rhs, OP op)
77  {
78  op(lhs[0], rhs[0]);
79  op(lhs[1], rhs[1]);
80  }
81 };
82 
83 template<class T1, class T2, class OP>
84 struct OTAssign<TinyMatrix<T1, 1, 2>, T2, OP>
85 {
86  inline static void apply(TinyMatrix<T1, 1, 2>& lhs, const T2& rhs, OP op)
87  {
88  op(lhs[0], rhs);
89  op(lhs[1], rhs);
90  }
91 };
92 
93 template<class T1, class T2, class OP>
94 struct OTAssign<TinyMatrix<T1, 2, 1>, TinyMatrix<T2, 2, 1>, OP>
95 {
96  inline static void apply(TinyMatrix<T1, 2, 1>& lhs, const TinyMatrix<T2, 2, 1>& rhs, OP op)
97  {
98  op(lhs[0], rhs[0]);
99  op(lhs[1], rhs[1]);
100  }
101 };
102 
103 template<class T1, class T2, class OP>
104 struct OTAssign<TinyMatrix<T1, 2, 1>, T2, OP>
105 {
106  inline static void apply(TinyMatrix<T1, 2, 1>& lhs, const T2& rhs, OP op)
107  {
108  op(lhs[0], rhs);
109  op(lhs[1], rhs);
110  }
111 };
112 //////////////////////////////////////////////////////////////////////
113 // Specializations for TinyMatrixs with D=3x1 1x3
114 //////////////////////////////////////////////////////////////////////
115 
116 template<class T1, class T2, class OP>
117 struct OTAssign<TinyMatrix<T1, 1, 3>, TinyMatrix<T2, 1, 3>, OP>
118 {
119  inline static void apply(TinyMatrix<T1, 1, 3>& lhs, const TinyMatrix<T2, 1, 3>& rhs, OP op)
120  {
121  op(lhs[0], rhs[0]);
122  op(lhs[1], rhs[1]);
123  op(lhs[2], rhs[2]);
124  }
125 };
126 
127 template<class T1, class T2, class OP>
128 struct OTAssign<TinyMatrix<T1, 1, 3>, T2, OP>
129 {
130  inline static void apply(TinyMatrix<T1, 1, 3>& lhs, const T2& rhs, OP op)
131  {
132  op(lhs[0], rhs);
133  op(lhs[1], rhs);
134  op(lhs[2], rhs);
135  }
136 };
137 
138 template<class T1, class T2, class OP>
139 struct OTAssign<TinyMatrix<T1, 3, 1>, TinyMatrix<T2, 3, 1>, OP>
140 {
141  inline static void apply(TinyMatrix<T1, 3, 1>& lhs, const TinyMatrix<T2, 3, 1>& rhs, OP op)
142  {
143  op(lhs[0], rhs[0]);
144  op(lhs[1], rhs[1]);
145  op(lhs[2], rhs[2]);
146  }
147 };
148 
149 template<class T1, class T2, class OP>
150 struct OTAssign<TinyMatrix<T1, 3, 1>, T2, OP>
151 {
152  inline static void apply(TinyMatrix<T1, 3, 1>& lhs, const T2& rhs, OP op)
153  {
154  op(lhs[0], rhs);
155  op(lhs[1], rhs);
156  op(lhs[2], rhs);
157  }
158 };
159 //////////////////////////////////////////////////////////////////////
160 // Specializations for TinyMatrix with D=2x2
161 //////////////////////////////////////////////////////////////////////
162 
163 template<class T1, class T2, class OP>
164 struct OTAssign<TinyMatrix<T1, 2, 2>, TinyMatrix<T2, 2, 2>, OP>
165 {
166  inline static void apply(TinyMatrix<T1, 2, 2>& lhs, const TinyMatrix<T2, 2, 2>& rhs, OP op)
167  {
168  op(lhs[0], rhs[0]);
169  op(lhs[1], rhs[1]);
170  op(lhs[2], rhs[2]);
171  op(lhs[3], rhs[3]);
172  }
173 };
174 
175 template<class T1, class T2, class OP>
176 struct OTAssign<TinyMatrix<T1, 2, 2>, T2, OP>
177 {
178  inline static void apply(TinyMatrix<T1, 2, 2>& lhs, const T2& rhs, OP op)
179  {
180  op(lhs[0], rhs);
181  op(lhs[1], rhs);
182  op(lhs[2], rhs);
183  op(lhs[3], rhs);
184  }
185 };
186 
187 //////////////////////////////////////////////////////////////////////
188 // Specializations for TinyMatrix with D=3x3
189 //////////////////////////////////////////////////////////////////////
190 
191 template<class T1, class T2, class OP>
192 struct OTAssign<TinyMatrix<T1, 3, 3>, TinyMatrix<T2, 3, 3>, OP>
193 {
194  inline static void apply(TinyMatrix<T1, 3, 3>& lhs, const TinyMatrix<T2, 3, 3>& rhs, OP op)
195  {
196  op(lhs[0], rhs[0]);
197  op(lhs[1], rhs[1]);
198  op(lhs[2], rhs[2]);
199  op(lhs[3], rhs[3]);
200  op(lhs[4], rhs[4]);
201  op(lhs[5], rhs[5]);
202  op(lhs[6], rhs[6]);
203  op(lhs[7], rhs[7]);
204  op(lhs[8], rhs[8]);
205  }
206 };
207 
208 template<class T1, class T2, class OP>
209 struct OTAssign<TinyMatrix<T1, 3, 3>, T2, OP>
210 {
211  inline static void apply(TinyMatrix<T1, 3, 3>& lhs, const T2& rhs, OP op)
212  {
213  op(lhs[0], rhs);
214  op(lhs[1], rhs);
215  op(lhs[2], rhs);
216  op(lhs[3], rhs);
217  op(lhs[4], rhs);
218  op(lhs[5], rhs);
219  op(lhs[6], rhs);
220  op(lhs[7], rhs);
221  op(lhs[8], rhs);
222  }
223 };
224 
225 //////////////////////////////////////////////////////////////////////
226 // Specializations for TinyMatrix with D=4x4
227 //////////////////////////////////////////////////////////////////////
228 
229 template<class T1, class T2, class OP>
230 struct OTAssign<TinyMatrix<T1, 4, 4>, TinyMatrix<T2, 4, 4>, OP>
231 {
232  inline static void apply(TinyMatrix<T1, 4, 4>& lhs, const TinyMatrix<T2, 4, 4>& rhs, OP op)
233  {
234  op(lhs[0], rhs[0]);
235  op(lhs[1], rhs[1]);
236  op(lhs[2], rhs[2]);
237  op(lhs[3], rhs[3]);
238  op(lhs[4], rhs[4]);
239  op(lhs[5], rhs[5]);
240  op(lhs[6], rhs[6]);
241  op(lhs[7], rhs[7]);
242  op(lhs[8], rhs[8]);
243  op(lhs[9], rhs[9]);
244  op(lhs[10], rhs[10]);
245  op(lhs[11], rhs[11]);
246  op(lhs[12], rhs[12]);
247  op(lhs[13], rhs[13]);
248  op(lhs[14], rhs[14]);
249  op(lhs[15], rhs[15]);
250  }
251 };
252 
253 template<class T1, class T2, class OP>
254 struct OTAssign<TinyMatrix<T1, 4, 4>, T2, OP>
255 {
256  inline static void apply(TinyMatrix<T1, 4, 4>& lhs, const T2& rhs, OP op)
257  {
258  op(lhs[0], rhs);
259  op(lhs[1], rhs);
260  op(lhs[2], rhs);
261  op(lhs[3], rhs);
262  op(lhs[4], rhs);
263  op(lhs[5], rhs);
264  op(lhs[6], rhs);
265  op(lhs[7], rhs);
266  op(lhs[8], rhs);
267  op(lhs[9], rhs);
268  op(lhs[10], rhs);
269  op(lhs[11], rhs);
270  op(lhs[12], rhs);
271  op(lhs[13], rhs);
272  op(lhs[14], rhs);
273  op(lhs[15], rhs);
274  }
275 };
276 
277 ///////////////////////////////////////////////////////////////////////
278 //
279 // Binary operators
280 // template<class T1, class T2, class OP> struct OTBinary {};
281 //
282 ///////////////////////////////////////////////////////////////////////
283 
284 //////////////////////////////////////////////////////////////////////
285 // Specializations for TinyMatrixs of arbitrary size.
286 //////////////////////////////////////////////////////////////////////
287 
288 template<class T1, class T2, class OP, unsigned D1, unsigned D2>
289 struct OTBinary<TinyMatrix<T1, D1, D2>, TinyMatrix<T2, D1, D2>, OP>
290 {
293  const TinyMatrix<T2, D1, D2>& rhs,
294  OP op)
295  {
297  for (unsigned d = 0; d < D1 * D2; ++d)
298  ret[d] = op(lhs[d], rhs[d]);
299  return ret;
300  }
301 };
302 
303 template<class T1, class T2, class OP, unsigned D1, unsigned D2>
304 struct OTBinary<TinyMatrix<T1, D1, D2>, T2, OP>
305 {
307  inline static TinyMatrix<Type_t, D1, D2> apply(const TinyMatrix<T1, D1, D2>& lhs, const T2& rhs, OP op)
308  {
310  for (unsigned d = 0; d < D1 * D2; ++d)
311  ret[d] = op(lhs[d], rhs);
312  return ret;
313  }
314 };
315 
316 template<class T1, class T2, class OP, unsigned D1, unsigned D2>
317 struct OTBinary<T1, TinyMatrix<T2, D1, D2>, OP>
318 {
320  inline static TinyMatrix<Type_t, D1, D2> apply(const T1& lhs, const TinyMatrix<T2, D1, D2>& rhs, OP op)
321  {
323  for (unsigned d = 0; d < D1 * D2; ++d)
324  ret[d] = op(lhs, rhs[d]);
325  return ret;
326  }
327 };
328 
329 //////////////////////////////////////////////////////////////////////
330 // Specializations of OTBinary for TinyMatrix with D=1 x 1
331 //////////////////////////////////////////////////////////////////////
332 
333 template<class T1, class T2, class OP>
334 struct OTBinary<TinyMatrix<T1, 1, 1>, TinyMatrix<T2, 1, 1>, OP>
335 {
337  inline static TinyMatrix<Type_t, 1, 1> apply(const TinyMatrix<T1, 1, 1>& lhs, const TinyMatrix<T2, 1, 1>& rhs, OP op)
338  {
339  return TinyMatrix<Type_t, 1, 1>(op(lhs[0], rhs[0]));
340  }
341 };
342 
343 template<class T1, class T2, class OP>
344 struct OTBinary<TinyMatrix<T1, 1, 1>, T2, OP>
345 {
347  inline static TinyMatrix<Type_t, 1, 1> apply(const TinyMatrix<T1, 1, 1>& lhs, const T2& rhs, OP op)
348  {
349  return TinyMatrix<Type_t, 1, 1>(op(lhs[0], rhs));
350  }
351 };
352 
353 template<class T1, class T2, class OP>
354 struct OTBinary<T1, TinyMatrix<T2, 1, 1>, OP>
355 {
357  inline static TinyMatrix<Type_t, 1, 1> apply(const T1& lhs, const TinyMatrix<T2, 1, 1>& rhs, OP op)
358  {
359  return TinyMatrix<Type_t, 1, 1>(op(lhs, rhs[0]));
360  }
361 };
362 
363 //////////////////////////////////////////////////////////////////////
364 // Specializations of OTBinary for TinyMatrixs with 1 x 2
365 //////////////////////////////////////////////////////////////////////
366 
367 template<class T1, class T2, class OP>
368 struct OTBinary<TinyMatrix<T1, 1, 2>, TinyMatrix<T2, 1, 2>, OP>
369 {
371  inline static TinyMatrix<Type_t, 1, 2> apply(const TinyMatrix<T1, 1, 2>& lhs, const TinyMatrix<T2, 1, 2>& rhs, OP op)
372  {
373  return TinyMatrix<Type_t, 1, 2>(op(lhs[0], rhs[0]), op(lhs[1], rhs[1]));
374  }
375 };
376 
377 template<class T1, class T2, class OP>
378 struct OTBinary<TinyMatrix<T1, 1, 2>, T2, OP>
379 {
381  inline static TinyMatrix<Type_t, 1, 2> apply(const TinyMatrix<T1, 1, 2>& lhs, const T2& rhs, OP op)
382  {
383  return TinyMatrix<Type_t, 1, 2>(op(lhs[0], rhs), op(lhs[1], rhs));
384  }
385 };
386 
387 template<class T1, class T2, class OP>
388 struct OTBinary<T1, TinyMatrix<T2, 1, 2>, OP>
389 {
391  inline static TinyMatrix<Type_t, 1, 2> apply(const T1& lhs, const TinyMatrix<T2, 1, 2>& rhs, OP op)
392  {
393  return TinyMatrix<Type_t, 1, 2>(op(lhs, rhs[0]), op(lhs, rhs[1]));
394  }
395 };
396 
397 //////////////////////////////////////////////////////////////////////
398 // Specializations for TinyMatrixs with D=3x1 1x3
399 //////////////////////////////////////////////////////////////////////
400 template<class T1, class T2, class OP>
401 struct OTBinary<TinyMatrix<T1, 1, 3>, TinyMatrix<T2, 1, 3>, OP>
402 {
404  inline static TinyMatrix<Type_t, 1, 3> apply(const TinyMatrix<T1, 1, 3>& lhs, const TinyMatrix<T2, 1, 3>& rhs, OP op)
405  {
406  return TinyMatrix<Type_t, 1, 3>(op(lhs[0], rhs[0]), op(lhs[1], rhs[1]), op(lhs[2], rhs[2]));
407  }
408 };
409 
410 template<class T1, class T2, class OP>
411 struct OTBinary<TinyMatrix<T1, 1, 3>, T2, OP>
412 {
414  inline static TinyMatrix<Type_t, 1, 3> apply(const TinyMatrix<T1, 1, 3>& lhs, const T2& rhs, OP op)
415  {
416  return TinyMatrix<Type_t, 1, 3>(op(lhs[0], rhs), op(lhs[1], rhs), op(lhs[2], rhs));
417  }
418 };
419 
420 template<class T1, class T2, class OP>
421 struct OTBinary<T1, TinyMatrix<T2, 1, 3>, OP>
422 {
424  inline static TinyMatrix<Type_t, 1, 3> apply(const T1& lhs, const TinyMatrix<T2, 1, 3>& rhs, OP op)
425  {
426  return TinyMatrix<Type_t, 1, 3>(op(lhs, rhs[0]), op(lhs, rhs[1]), op(lhs, rhs[2]));
427  }
428 };
429 
430 //////////////////////////////////////////////////////////////////////
431 // Specializations of OTBinary for TinyMatrixs with D=2x2
432 //////////////////////////////////////////////////////////////////////
433 
434 template<class T1, class T2, class OP>
435 struct OTBinary<TinyMatrix<T1, 2, 2>, TinyMatrix<T2, 2, 2>, OP>
436 {
438  inline static TinyMatrix<Type_t, 2, 2> apply(const TinyMatrix<T1, 2, 2>& lhs, const TinyMatrix<T2, 2, 2>& rhs, OP op)
439  {
440  return TinyMatrix<Type_t, 2, 2>(op(lhs[0], rhs[0]), op(lhs[1], rhs[1]), op(lhs[2], rhs[2]), op(lhs[3], rhs[3]));
441  }
442 };
443 
444 template<class T1, class T2, class OP>
445 struct OTBinary<TinyMatrix<T1, 2, 2>, T2, OP>
446 {
448  inline static TinyMatrix<Type_t, 2, 2> apply(const TinyMatrix<T1, 2, 2>& lhs, const T2& rhs, OP op)
449  {
450  return TinyMatrix<Type_t, 2, 2>(op(lhs[0], rhs), op(lhs[1], rhs), op(lhs[2], rhs), op(lhs[3], rhs));
451  }
452 };
453 
454 template<class T1, class T2, class OP>
455 struct OTBinary<T1, TinyMatrix<T2, 2, 2>, OP>
456 {
458  inline static TinyMatrix<Type_t, 2, 2> apply(const T1& lhs, const TinyMatrix<T2, 2, 2>& rhs, OP op)
459  {
460  return TinyMatrix<Type_t, 2, 2>(op(lhs, rhs[0]), op(lhs, rhs[1]), op(lhs, rhs[2]), op(lhs, rhs[3]));
461  }
462 };
463 
464 ///////////////////////////////////////////////////////////////
465 // Specialization for 3x3
466 ///////////////////////////////////////////////////////////////
467 template<class T1, class T2, class OP>
468 struct OTBinary<TinyMatrix<T1, 3, 3>, TinyMatrix<T2, 3, 3>, OP>
469 {
472  inline static Return_t apply(const TinyMatrix<T1, 3, 3>& lhs, const TinyMatrix<T2, 3, 3>& rhs, OP op)
473  {
474  return Return_t(op(lhs[0], rhs[0]), op(lhs[1], rhs[1]), op(lhs[2], rhs[2]), op(lhs[3], rhs[3]), op(lhs[4], rhs[4]),
475  op(lhs[5], rhs[5]), op(lhs[6], rhs[6]), op(lhs[7], rhs[7]), op(lhs[8], rhs[8]));
476  }
477 };
478 
479 template<class T1, class T2, class OP>
480 struct OTBinary<TinyMatrix<T1, 3, 3>, T2, OP>
481 {
484  inline static Return_t apply(const TinyMatrix<T1, 3, 3>& lhs, T2 rhs, OP op)
485  {
486  return Return_t(op(lhs[0], rhs), op(lhs[1], rhs), op(lhs[2], rhs), op(lhs[3], rhs), op(lhs[4], rhs),
487  op(lhs[5], rhs), op(lhs[6], rhs), op(lhs[7], rhs), op(lhs[8], rhs));
488  }
489 };
490 
491 template<class T1, class T2, class OP>
492 struct OTBinary<T1, TinyMatrix<T2, 3, 3>, OP>
493 {
496  inline static Return_t apply(T1 lhs, const TinyMatrix<T2, 3, 3>& rhs, OP op)
497  {
498  return Return_t(op(lhs, rhs[0]), op(lhs, rhs[1]), op(lhs, rhs[2]), op(lhs, rhs[3]), op(lhs, rhs[4]),
499  op(lhs, rhs[5]), op(lhs, rhs[6]), op(lhs, rhs[7]), op(lhs, rhs[8]));
500  }
501 };
502 
503 ///////////////////////////////////////////////////////////////
504 // Specialization for 4x4
505 ///////////////////////////////////////////////////////////////
506 template<class T1, class T2, class OP>
507 struct OTBinary<TinyMatrix<T1, 4, 4>, TinyMatrix<T2, 4, 4>, OP>
508 {
511  inline static Return_t apply(const TinyMatrix<T1, 4, 4>& lhs, const TinyMatrix<T2, 4, 4>& rhs, OP op)
512  {
513  return Return_t(op(lhs[0], rhs[0]), op(lhs[1], rhs[1]), op(lhs[2], rhs[2]), op(lhs[3], rhs[3]), op(lhs[4], rhs[4]),
514  op(lhs[5], rhs[5]), op(lhs[6], rhs[6]), op(lhs[7], rhs[7]), op(lhs[8], rhs[8]), op(lhs[9], rhs[9]),
515  op(lhs[10], rhs[10]), op(lhs[11], rhs[11]), op(lhs[12], rhs[12]), op(lhs[13], rhs[13]),
516  op(lhs[14], rhs[14]), op(lhs[15], rhs[15]));
517  }
518 };
519 
520 template<class T1, class T2, class OP>
521 struct OTBinary<TinyMatrix<T1, 4, 4>, T2, OP>
522 {
525  inline static Return_t apply(const TinyMatrix<T1, 4, 4>& lhs, T2 rhs, OP op)
526  {
527  return Return_t(op(lhs[0], rhs), op(lhs[1], rhs), op(lhs[2], rhs), op(lhs[3], rhs), op(lhs[4], rhs),
528  op(lhs[5], rhs), op(lhs[6], rhs), op(lhs[7], rhs), op(lhs[8], rhs), op(lhs[9], rhs),
529  op(lhs[10], rhs), op(lhs[11], rhs), op(lhs[12], rhs), op(lhs[13], rhs), op(lhs[14], rhs),
530  op(lhs[15], rhs));
531  }
532 };
533 
534 template<class T1, class T2, class OP>
535 struct OTBinary<T1, TinyMatrix<T2, 4, 4>, OP>
536 {
539  inline static Return_t apply(T1 lhs, const TinyMatrix<T2, 4, 4>& rhs, OP op)
540  {
541  return Return_t(op(lhs, rhs[0]), op(lhs, rhs[1]), op(lhs, rhs[2]), op(lhs, rhs[3]), op(lhs, rhs[4]),
542  op(lhs, rhs[5]), op(lhs, rhs[6]), op(lhs, rhs[7]), op(lhs, rhs[8]), op(lhs, rhs[9]),
543  op(lhs, rhs[10]), op(lhs, rhs[11]), op(lhs, rhs[12]), op(lhs, rhs[13]), op(lhs, rhs[14]),
544  op(lhs, rhs[15]));
545  }
546 };
547 
548 //////////////////////////////////////////////////////////////////////
549 //
550 // ! = Transpose of matrix(D1,D2) to matrix(D2,D1)
551 //
552 //////////////////////////////////////////////////////////////////////
553 template<class T1, unsigned D1, unsigned D2>
555 {
557  for (int i = 0; i < D1; i++)
558  for (int j = 0; j < D2; j++)
559  res(i, j) = a(j, i);
560  return res;
561 }
562 
563 //////////////////////////////////////////////////////////////////////
564 // ! specialization for 3x3
565 //////////////////////////////////////////////////////////////////////
566 template<class T1>
568 {
569  return TinyMatrix<T1, 3, 3>(a(0, 0), a(1, 0), a(2, 0), a(0, 1), a(1, 1), a(2, 1), a(0, 2), a(1, 2), a(2, 2));
570 }
571 
572 //////////////////////////////////////////////////////////////////////
573 // ! specialization for 4x4
574 //////////////////////////////////////////////////////////////////////
575 template<class T1>
577 {
578  return TinyMatrix<T1, 4, 4>(a(0, 0), a(1, 0), a(2, 0), a(3, 0), a(0, 1), a(1, 1), a(2, 1), a(3, 1), a(0, 2), a(1, 2),
579  a(2, 2), a(3, 2), a(0, 3), a(1, 3), a(2, 3), a(3, 3));
580 }
581 
582 //////////////////////////////////////////////////////////////////////
583 //
584 // template<class T1, class T2> struct OTDot {};
585 // Specializations for TinyMatrix x TinyMatrix matrix multiplication
586 // Matrix(D1,D2)* Matrix(D2,D3) = Matrix(D1,D3)
587 //
588 //////////////////////////////////////////////////////////////////////
589 template<class T1, class T2, unsigned D1, unsigned D2, unsigned D3>
590 struct OTDot<TinyMatrix<T1, D1, D2>, TinyMatrix<T2, D2, D3>>
591 {
594  inline static Return_t apply(const TinyMatrix<T1, D1, D2>& lhs, const TinyMatrix<T2, D2, D3>& rhs)
595  {
596  Return_t res;
597  for (int i = 0; i < D1; i++)
598  for (int j = 0; j < D3; j++)
599  {
600  Type_t tmp = 0.0e0;
601  for (int k = 0; k < D2; k++)
602  tmp += lhs(i, k) * rhs(k, j);
603  res(i, j) = tmp;
604  }
605  return res;
606  }
607 };
608 
609 template<class T1, class T2>
610 struct OTDot<TinyMatrix<T1, 3, 3>, TinyMatrix<T2, 3, 3>>
611 {
614  inline static Return_t apply(const TinyMatrix<T1, 3, 3>& lhs, const TinyMatrix<T2, 3, 3>& rhs)
615  {
616  return Return_t(lhs(0, 0) * rhs(0, 0) + lhs(0, 1) * rhs(1, 0) + lhs(0, 2) * rhs(2, 0),
617  lhs(0, 0) * rhs(0, 1) + lhs(0, 1) * rhs(1, 1) + lhs(0, 2) * rhs(2, 1),
618  lhs(0, 0) * rhs(0, 2) + lhs(0, 1) * rhs(1, 2) + lhs(0, 2) * rhs(2, 2),
619  lhs(1, 0) * rhs(0, 0) + lhs(1, 1) * rhs(1, 0) + lhs(1, 2) * rhs(2, 0),
620  lhs(1, 0) * rhs(0, 1) + lhs(1, 1) * rhs(1, 1) + lhs(1, 2) * rhs(2, 1),
621  lhs(1, 0) * rhs(0, 2) + lhs(1, 1) * rhs(1, 2) + lhs(1, 2) * rhs(2, 2),
622  lhs(2, 0) * rhs(0, 0) + lhs(2, 1) * rhs(1, 0) + lhs(2, 2) * rhs(2, 0),
623  lhs(2, 0) * rhs(0, 1) + lhs(2, 1) * rhs(1, 1) + lhs(2, 2) * rhs(2, 1),
624  lhs(2, 0) * rhs(0, 2) + lhs(2, 1) * rhs(1, 2) + lhs(2, 2) * rhs(2, 2));
625  }
626 };
627 
628 //////////////////////////////////////////////////////////////////////
629 //
630 // template<class T1, class T2> struct OTDot {};
631 // Specializations for TinyMatrix x TinyVector multiplication
632 //
633 //////////////////////////////////////////////////////////////////////
634 template<class T1, class T2, unsigned D1, unsigned D2>
635 struct OTDot<TinyMatrix<T1, D1, D2>, TinyVector<T2, D2>>
636 {
639  inline static Return_t apply(const TinyMatrix<T1, D1, D2>& lhs, const TinyVector<T2, D2>& rhs)
640  {
641  Return_t res;
642  for (int i = 0; i < D1; i++)
643  {
644  res(i) = lhs(i, 0) * rhs(0);
645  for (int j = 1; j < D2; j++)
646  res(i) += lhs(i, j) * rhs(j);
647  }
648  return res;
649  }
650 };
651 
652 template<class T1, class T2, unsigned D1, unsigned D2>
653 struct OTDot<TinyVector<T1, D1>, TinyMatrix<T2, D1, D2>>
654 {
657  inline static Return_t apply(const TinyVector<T1, D1>& lhs, const TinyMatrix<T2, D1, D2>& rhs)
658  {
659  Return_t res;
660  for (int i = 0; i < D2; i++)
661  {
662  res(i) = lhs(0) * rhs(0, i);
663  for (int j = 1; j < D1; j++)
664  res(i) += lhs(j) * rhs(j, i);
665  }
666  return res;
667  }
668 };
669 
670 
671 //////////////////////////////////////////////////////////////////////
672 // Specializations for TinyMatrixs with D=3x3
673 //////////////////////////////////////////////////////////////////////
674 template<class T1, class T2>
675 struct OTDot<TinyMatrix<T1, 3, 3>, TinyVector<T2, 3>>
676 {
679  inline static Return_t apply(const TinyMatrix<T1, 3, 3>& lhs, const TinyVector<T2, 3>& rhs)
680  {
681  return Return_t(lhs(0, 0) * rhs(0) + lhs(0, 1) * rhs(1) + lhs(0, 2) * rhs(2),
682  lhs(1, 0) * rhs(0) + lhs(1, 1) * rhs(1) + lhs(1, 2) * rhs(2),
683  lhs(2, 0) * rhs(0) + lhs(2, 1) * rhs(1) + lhs(2, 2) * rhs(2));
684  }
685 };
686 
687 template<class T1, class T2>
688 struct OTDot<TinyVector<T1, 3>, TinyMatrix<T2, 3, 3>>
689 {
692  inline static Return_t apply(const TinyVector<T1, 3>& lhs, const TinyMatrix<T2, 3, 3>& rhs)
693  {
694  return Return_t(lhs(0) * rhs(0, 0) + lhs(1) * rhs(1, 0) + lhs(2) * rhs(2, 0),
695  lhs(0) * rhs(0, 1) + lhs(1) * rhs(1, 1) + lhs(2) * rhs(2, 1),
696  lhs(0) * rhs(0, 2) + lhs(1) * rhs(1, 2) + lhs(2) * rhs(2, 2));
697  }
698 };
699 
700 //////////////////////////////////////////////////////////////////////
701 // Specializations for TinyMatrixs with D=4x4
702 //////////////////////////////////////////////////////////////////////
703 template<class T1, class T2>
704 struct OTDot<TinyMatrix<T1, 4, 4>, TinyVector<T2, 4>>
705 {
708  inline static Return_t apply(const TinyMatrix<T1, 4, 4>& lhs, const TinyVector<T2, 4>& rhs)
709  {
710  return Return_t(lhs(0, 0) * rhs(0) + lhs(0, 1) * rhs(1) + lhs(0, 2) * rhs(2) + lhs(0, 3) * rhs(3),
711  lhs(1, 0) * rhs(0) + lhs(1, 1) * rhs(1) + lhs(1, 2) * rhs(2) + lhs(1, 3) * rhs(3),
712  lhs(2, 0) * rhs(0) + lhs(2, 1) * rhs(1) + lhs(2, 2) * rhs(2) + lhs(2, 3) * rhs(3),
713  lhs(3, 0) * rhs(0) + lhs(3, 1) * rhs(1) + lhs(3, 2) * rhs(2) + lhs(3, 3) * rhs(3));
714  }
715 };
716 
717 template<class T1, class T2>
718 struct OTDot<TinyVector<T1, 4>, TinyMatrix<T2, 4, 4>>
719 {
722  inline static Return_t apply(const TinyVector<T1, 4>& lhs, const TinyMatrix<T2, 4, 4>& rhs)
723  {
724  return Return_t(lhs(0) * rhs(0, 0) + lhs(1) * rhs(1, 0) + lhs(2) * rhs(2, 0) + lhs(3) * rhs(3, 0),
725  lhs(0) * rhs(0, 1) + lhs(1) * rhs(1, 1) + lhs(2) * rhs(2, 1) + lhs(3) * rhs(3, 1),
726  lhs(0) * rhs(0, 2) + lhs(1) * rhs(1, 2) + lhs(2) * rhs(2, 2) + lhs(3) * rhs(3, 2),
727  lhs(0) * rhs(0, 3) + lhs(1) * rhs(1, 3) + lhs(2) * rhs(2, 3) + lhs(3) * rhs(3, 3));
728  }
729 };
730 
731 
732 template<class T1, class T2>
733 struct OTDot<TinyMatrix<T1, 4, 4>, TinyMatrix<T2, 4, 4>>
734 {
737  inline static Return_t apply(const TinyMatrix<T1, 4, 4>& lhs, const TinyMatrix<T2, 4, 4>& rhs)
738  {
739  return Return_t(lhs(0, 0) * rhs(0, 0) + lhs(0, 1) * rhs(1, 0) + lhs(0, 2) * rhs(2, 0) + lhs(0, 3) * rhs(3, 0),
740  lhs(0, 0) * rhs(0, 1) + lhs(0, 1) * rhs(1, 1) + lhs(0, 2) * rhs(2, 1) + lhs(0, 3) * rhs(3, 1),
741  lhs(0, 0) * rhs(0, 2) + lhs(0, 1) * rhs(1, 2) + lhs(0, 2) * rhs(2, 2) + lhs(0, 3) * rhs(3, 2),
742  lhs(0, 0) * rhs(0, 3) + lhs(0, 1) * rhs(1, 3) + lhs(0, 2) * rhs(2, 3) + lhs(0, 3) * rhs(3, 3),
743  lhs(1, 0) * rhs(0, 0) + lhs(1, 1) * rhs(1, 0) + lhs(1, 2) * rhs(2, 0) + lhs(1, 3) * rhs(3, 0),
744  lhs(1, 0) * rhs(0, 1) + lhs(1, 1) * rhs(1, 1) + lhs(1, 2) * rhs(2, 1) + lhs(1, 3) * rhs(3, 1),
745  lhs(1, 0) * rhs(0, 2) + lhs(1, 1) * rhs(1, 2) + lhs(1, 2) * rhs(2, 2) + lhs(1, 3) * rhs(3, 2),
746  lhs(1, 0) * rhs(0, 3) + lhs(1, 1) * rhs(1, 3) + lhs(1, 2) * rhs(2, 3) + lhs(1, 3) * rhs(3, 3),
747  lhs(2, 0) * rhs(0, 0) + lhs(2, 1) * rhs(1, 0) + lhs(2, 2) * rhs(2, 0) + lhs(2, 3) * rhs(3, 0),
748  lhs(2, 0) * rhs(0, 1) + lhs(2, 1) * rhs(1, 1) + lhs(2, 2) * rhs(2, 1) + lhs(2, 3) * rhs(3, 1),
749  lhs(2, 0) * rhs(0, 2) + lhs(2, 1) * rhs(1, 2) + lhs(2, 2) * rhs(2, 2) + lhs(2, 3) * rhs(3, 2),
750  lhs(2, 0) * rhs(0, 3) + lhs(2, 1) * rhs(1, 3) + lhs(2, 2) * rhs(2, 3) + lhs(2, 3) * rhs(3, 3),
751  lhs(3, 0) * rhs(0, 0) + lhs(3, 1) * rhs(1, 0) + lhs(3, 2) * rhs(2, 0) + lhs(3, 3) * rhs(3, 0),
752  lhs(3, 0) * rhs(0, 1) + lhs(3, 1) * rhs(1, 1) + lhs(3, 2) * rhs(2, 1) + lhs(3, 3) * rhs(3, 1),
753  lhs(3, 0) * rhs(0, 2) + lhs(3, 1) * rhs(1, 2) + lhs(3, 2) * rhs(2, 2) + lhs(3, 3) * rhs(3, 2),
754  lhs(3, 0) * rhs(0, 3) + lhs(3, 1) * rhs(1, 3) + lhs(3, 2) * rhs(2, 3) + lhs(3, 3) * rhs(3, 3));
755  }
756 };
757 
758 } // namespace qmcplusplus
759 #endif // OHMMS_TINYVECTOR_OPERATORS_H
static Return_t apply(const TinyMatrix< T1, 4, 4 > &lhs, T2 rhs, OP op)
typename Promote< T1, T2 >::Type_t Type_t
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
static void apply(TinyMatrix< T1, 2, 2 > &lhs, const TinyMatrix< T2, 2, 2 > &rhs, OP op)
static void apply(TinyMatrix< T1, 3, 3 > &lhs, const T2 &rhs, OP op)
typename BinaryReturn< T1, T2, OpMultiply >::Type_t Type_t
typename BinaryReturn< T1, T2, OpMultiply >::Type_t Type_t
typename BinaryReturn< T1, T2, OP >::Type_t Type_t
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
static Return_t apply(const TinyMatrix< T1, 4, 4 > &lhs, const TinyMatrix< T2, 4, 4 > &rhs, OP op)
static void apply(TinyMatrix< T1, D1, D2 > &lhs, const TinyMatrix< T2, D1, D2 > &rhs, OP op)
Definition: TinyMatrixOps.h:35
static TinyMatrix< Type_t, 1, 1 > apply(const T1 &lhs, const TinyMatrix< T2, 1, 1 > &rhs, OP op)
typename BinaryReturn< T1, T2, OP >::Type_t Type_t
static TinyMatrix< Type_t, 1, 3 > apply(const T1 &lhs, const TinyMatrix< T2, 1, 3 > &rhs, OP op)
static TinyMatrix< Type_t, 1, 2 > apply(const T1 &lhs, const TinyMatrix< T2, 1, 2 > &rhs, OP op)
static void apply(TinyMatrix< T1, 3, 1 > &lhs, const TinyMatrix< T2, 3, 1 > &rhs, OP op)
static Return_t apply(const TinyMatrix< T1, 3, 3 > &lhs, const TinyMatrix< T2, 3, 3 > &rhs, OP op)
typename BinaryReturn< T1, T2, OpMultiply >::Type_t Type_t
typename BinaryReturn< T1, T2, OP >::Type_t Type_t
typename BinaryReturn< T1, T2, OP >::Type_t Type_t
typename BinaryReturn< T1, T2, OP >::Type_t Type_t
static TinyMatrix< Type_t, 2, 2 > apply(const T1 &lhs, const TinyMatrix< T2, 2, 2 > &rhs, OP op)
static Return_t apply(const TinyMatrix< T1, 3, 3 > &lhs, T2 rhs, OP op)
static void apply(TinyMatrix< T1, 3, 3 > &lhs, const TinyMatrix< T2, 3, 3 > &rhs, OP op)
static Return_t apply(const TinyVector< T1, D1 > &lhs, const TinyMatrix< T2, D1, D2 > &rhs)
static TinyMatrix< Type_t, 1, 3 > apply(const TinyMatrix< T1, 1, 3 > &lhs, const T2 &rhs, OP op)
static void apply(TinyMatrix< T1, 1, 3 > &lhs, const TinyMatrix< T2, 1, 3 > &rhs, OP op)
static TinyMatrix< Type_t, 1, 2 > apply(const TinyMatrix< T1, 1, 2 > &lhs, const T2 &rhs, OP op)
typename BinaryReturn< T1, T2, OpMultiply >::Type_t Type_t
static TinyMatrix< Type_t, 1, 2 > apply(const TinyMatrix< T1, 1, 2 > &lhs, const TinyMatrix< T2, 1, 2 > &rhs, OP op)
typename BinaryReturn< T1, T2, OP >::Type_t Type_t
static void apply(TinyMatrix< T1, 1, 3 > &lhs, const T2 &rhs, OP op)
static Return_t apply(const TinyMatrix< T1, 3, 3 > &lhs, const TinyMatrix< T2, 3, 3 > &rhs)
static TinyMatrix< Type_t, D1, D2 > apply(const T1 &lhs, const TinyMatrix< T2, D1, D2 > &rhs, OP op)
typename BinaryReturn< T1, T2, OP >::Type_t Type_t
typename BinaryReturn< T1, T2, OP >::Type_t Type_t
typename BinaryReturn< T1, T2, OP >::Type_t Type_t
static Return_t apply(T1 lhs, const TinyMatrix< T2, 4, 4 > &rhs, OP op)
static Return_t apply(T1 lhs, const TinyMatrix< T2, 3, 3 > &rhs, OP op)
static void apply(TinyMatrix< T1, 2, 1 > &lhs, const TinyMatrix< T2, 2, 1 > &rhs, OP op)
Definition: TinyMatrixOps.h:96
typename BinaryReturn< T1, T2, OpMultiply >::Type_t Type_t
typename BinaryReturn< T1, T2, OP >::Type_t Type_t
typename BinaryReturn< T1, T2, OP >::Type_t Type_t
static void apply(TinyMatrix< T1, 1, 2 > &lhs, const TinyMatrix< T2, 1, 2 > &rhs, OP op)
Definition: TinyMatrixOps.h:76
typename BinaryReturn< T1, T2, OP >::Type_t Type_t
static Return_t apply(const TinyMatrix< T1, 4, 4 > &lhs, const TinyMatrix< T2, 4, 4 > &rhs)
static TinyMatrix< Type_t, D1, D2 > apply(const TinyMatrix< T1, D1, D2 > &lhs, const TinyMatrix< T2, D1, D2 > &rhs, OP op)
static Return_t apply(const TinyMatrix< T1, D1, D2 > &lhs, const TinyMatrix< T2, D2, D3 > &rhs)
static Return_t apply(const TinyVector< T1, 4 > &lhs, const TinyMatrix< T2, 4, 4 > &rhs)
static void apply(TinyMatrix< T1, 3, 1 > &lhs, const T2 &rhs, OP op)
typename BinaryReturn< T1, T2, OpMultiply >::Type_t Type_t
static Return_t apply(const TinyVector< T1, 3 > &lhs, const TinyMatrix< T2, 3, 3 > &rhs)
static void apply(TinyMatrix< T1, 1, 1 > &lhs, const T2 &rhs, OP op)
Definition: TinyMatrixOps.h:66
static void apply(TinyMatrix< T1, 4, 4 > &lhs, const TinyMatrix< T2, 4, 4 > &rhs, OP op)
typename BinaryReturn< T1, T2, OP >::Type_t Type_t
static Return_t apply(const TinyMatrix< T1, 4, 4 > &lhs, const TinyVector< T2, 4 > &rhs)
MakeReturn< UnaryNode< OpNot, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t operator!(const Vector< T1, C1 > &l)
static Return_t apply(const TinyMatrix< T1, D1, D2 > &lhs, const TinyVector< T2, D2 > &rhs)
static TinyMatrix< Type_t, D1, D2 > apply(const TinyMatrix< T1, D1, D2 > &lhs, const T2 &rhs, OP op)
static void apply(TinyMatrix< T1, D1, D2 > &lhs, const T2 &rhs, OP op)
Definition: TinyMatrixOps.h:45
static void apply(TinyMatrix< T1, 1, 1 > &lhs, const TinyMatrix< T2, 1, 1 > &rhs, OP op)
Definition: TinyMatrixOps.h:60
static void apply(TinyMatrix< T1, 4, 4 > &lhs, const T2 &rhs, OP op)
static TinyMatrix< Type_t, 2, 2 > apply(const TinyMatrix< T1, 2, 2 > &lhs, const T2 &rhs, OP op)
typename BinaryReturn< T1, T2, OpMultiply >::Type_t Type_t
typename BinaryReturn< T1, T2, OpMultiply >::Type_t Type_t
static TinyMatrix< Type_t, 1, 1 > apply(const TinyMatrix< T1, 1, 1 > &lhs, const T2 &rhs, OP op)
static TinyMatrix< Type_t, 1, 3 > apply(const TinyMatrix< T1, 1, 3 > &lhs, const TinyMatrix< T2, 1, 3 > &rhs, OP op)
static TinyMatrix< Type_t, 2, 2 > apply(const TinyMatrix< T1, 2, 2 > &lhs, const TinyMatrix< T2, 2, 2 > &rhs, OP op)
typename BinaryReturn< T1, T2, OpMultiply >::Type_t Type_t
static void apply(TinyMatrix< T1, 2, 1 > &lhs, const T2 &rhs, OP op)
static void apply(TinyMatrix< T1, 2, 2 > &lhs, const T2 &rhs, OP op)
static Return_t apply(const TinyMatrix< T1, 3, 3 > &lhs, const TinyVector< T2, 3 > &rhs)
BareKineticEnergy::Return_t Return_t
static void apply(TinyMatrix< T1, 1, 2 > &lhs, const T2 &rhs, OP op)
Definition: TinyMatrixOps.h:86
static TinyMatrix< Type_t, 1, 1 > apply(const TinyMatrix< T1, 1, 1 > &lhs, const TinyMatrix< T2, 1, 1 > &rhs, OP op)
typename BinaryReturn< T1, T2, OP >::Type_t Type_t