source: Sophya/trunk/Poubelle/DPC:FitsIOServer/Blitz/blitz/meta/dot.h@ 658

Last change on this file since 658 was 658, checked in by ansari, 26 years ago

no message

File size: 3.6 KB
Line 
1/***************************************************************************
2 * blitz/meta/dot.h Tiny vector dot product metaprogram
3 *
4 * $Id: dot.h,v 1.1.1.1 1999-11-26 16:37:07 ansari Exp $
5 *
6 * Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * Suggestions: blitz-suggest@cybervision.com
19 * Bugs: blitz-bugs@cybervision.com
20 *
21 * For more information, please see the Blitz++ Home Page:
22 * http://seurat.uwaterloo.ca/blitz/
23 *
24 ***************************************************************************
25 * $Log: not supported by cvs2svn $
26 * Revision 1.1.1.1 1999/04/09 17:59:03 ansari
27 * Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99
28 *
29 * Revision 1.2 1998/03/14 00:08:44 tveldhui
30 * 0.2-alpha-05
31 *
32 * Revision 1.1 1997/07/16 14:51:20 tveldhui
33 * Update: Alpha release 0.2 (Arrays)
34 *
35 */
36
37#ifndef BZ_META_DOT_H
38#define BZ_META_DOT_H
39
40#ifndef BZ_PROMOTE_H
41 #include <blitz/promote.h>
42#endif
43
44#ifndef BZ_METAPROG_H
45 #include <blitz/meta/metaprog.h>
46#endif
47
48BZ_NAMESPACE(blitz)
49
50template<int N, int I>
51class _bz_meta_vectorDot {
52public:
53 enum { loopFlag = (I < N-1) ? 1 : 0 };
54
55 template<class T_expr1, class T_expr2>
56 static inline BZ_PROMOTE(_bz_typename T_expr1::T_numtype,
57 _bz_typename T_expr2::T_numtype)
58 f(const T_expr1& a, const T_expr2& b)
59 {
60 return a[I] * b[I]
61 + _bz_meta_vectorDot<loopFlag * N, loopFlag * (I+1)>::f(a,b);
62 }
63
64 template<class T_expr1, class T_expr2>
65 static inline BZ_PROMOTE(_bz_typename T_expr1::T_numtype,
66 _bz_typename T_expr2::T_numtype)
67 f_value_ref(T_expr1 a, const T_expr2& b)
68 {
69 return a[I] * b[I]
70 + _bz_meta_vectorDot<loopFlag * N, loopFlag * (I+1)>::f(a,b);
71 }
72
73 template<class T_expr1, class T_expr2>
74 static inline BZ_PROMOTE(_bz_typename T_expr1::T_numtype,
75 _bz_typename T_expr2::T_numtype)
76 f_ref_value(const T_expr1& a, T_expr2 b)
77 {
78 return a[I] * b[I]
79 + _bz_meta_vectorDot<loopFlag * N, loopFlag * (I+1)>::f(a,b);
80 }
81
82 template<class T_expr1, class P_numtype2>
83 static inline BZ_PROMOTE(_bz_typename T_expr1::T_numtype,
84 P_numtype2)
85 dotWithArgs(const T_expr1& a, P_numtype2 i1, P_numtype2 i2=0,
86 P_numtype2 i3=0, P_numtype2 i4=0, P_numtype2 i5=0, P_numtype2 i6=0,
87 P_numtype2 i7=0, P_numtype2 i8=0, P_numtype2 i9=0, P_numtype2 i10=0)
88 {
89 return a[I] * i1
90 + _bz_meta_vectorDot<loopFlag * N, loopFlag * (I+1)>::dotWithArgs
91 (a, i2, i3, i4, i5, i6, i7, i8, i9);
92 }
93};
94
95template<>
96class _bz_meta_vectorDot<0,0> {
97public:
98 template<class T_expr1, class T_expr2>
99 static inline _bz_meta_nullOperand f(const T_expr1&, const T_expr2&)
100 { return _bz_meta_nullOperand(); }
101
102 template<class T_expr1, class P_numtype2>
103 static inline _bz_meta_nullOperand
104 dotWithArgs(const T_expr1& a, P_numtype2 i1, P_numtype2 i2=0,
105 P_numtype2 i3=0, P_numtype2 i4=0, P_numtype2 i5=0, P_numtype2 i6=0,
106 P_numtype2 i7=0, P_numtype2 i8=0, P_numtype2 i9=0, P_numtype2 i10=0)
107 {
108 return _bz_meta_nullOperand();
109 }
110
111};
112
113BZ_NAMESPACE_END
114
115#endif // BZ_META_DOT_H
Note: See TracBrowser for help on using the repository browser.