1 | /***************************************************************************
|
---|
2 | * blitz/meta/dot.h Tiny vector dot product metaprogram
|
---|
3 | *
|
---|
4 | * $Id: dot.h,v 1.1.1.1 1999-04-09 17:59:03 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.2 1998/03/14 00:08:44 tveldhui
|
---|
27 | * 0.2-alpha-05
|
---|
28 | *
|
---|
29 | * Revision 1.1 1997/07/16 14:51:20 tveldhui
|
---|
30 | * Update: Alpha release 0.2 (Arrays)
|
---|
31 | *
|
---|
32 | */
|
---|
33 |
|
---|
34 | #ifndef BZ_META_DOT_H
|
---|
35 | #define BZ_META_DOT_H
|
---|
36 |
|
---|
37 | #ifndef BZ_PROMOTE_H
|
---|
38 | #include <blitz/promote.h>
|
---|
39 | #endif
|
---|
40 |
|
---|
41 | #ifndef BZ_METAPROG_H
|
---|
42 | #include <blitz/meta/metaprog.h>
|
---|
43 | #endif
|
---|
44 |
|
---|
45 | BZ_NAMESPACE(blitz)
|
---|
46 |
|
---|
47 | template<int N, int I>
|
---|
48 | class _bz_meta_vectorDot {
|
---|
49 | public:
|
---|
50 | enum { loopFlag = (I < N-1) ? 1 : 0 };
|
---|
51 |
|
---|
52 | template<class T_expr1, class T_expr2>
|
---|
53 | static inline BZ_PROMOTE(_bz_typename T_expr1::T_numtype,
|
---|
54 | _bz_typename T_expr2::T_numtype)
|
---|
55 | f(const T_expr1& a, const T_expr2& b)
|
---|
56 | {
|
---|
57 | return a[I] * b[I]
|
---|
58 | + _bz_meta_vectorDot<loopFlag * N, loopFlag * (I+1)>::f(a,b);
|
---|
59 | }
|
---|
60 |
|
---|
61 | template<class T_expr1, class T_expr2>
|
---|
62 | static inline BZ_PROMOTE(_bz_typename T_expr1::T_numtype,
|
---|
63 | _bz_typename T_expr2::T_numtype)
|
---|
64 | f_value_ref(T_expr1 a, const T_expr2& b)
|
---|
65 | {
|
---|
66 | return a[I] * b[I]
|
---|
67 | + _bz_meta_vectorDot<loopFlag * N, loopFlag * (I+1)>::f(a,b);
|
---|
68 | }
|
---|
69 |
|
---|
70 | template<class T_expr1, class T_expr2>
|
---|
71 | static inline BZ_PROMOTE(_bz_typename T_expr1::T_numtype,
|
---|
72 | _bz_typename T_expr2::T_numtype)
|
---|
73 | f_ref_value(const T_expr1& a, T_expr2 b)
|
---|
74 | {
|
---|
75 | return a[I] * b[I]
|
---|
76 | + _bz_meta_vectorDot<loopFlag * N, loopFlag * (I+1)>::f(a,b);
|
---|
77 | }
|
---|
78 |
|
---|
79 | template<class T_expr1, class P_numtype2>
|
---|
80 | static inline BZ_PROMOTE(_bz_typename T_expr1::T_numtype,
|
---|
81 | P_numtype2)
|
---|
82 | dotWithArgs(const T_expr1& a, P_numtype2 i1, P_numtype2 i2=0,
|
---|
83 | P_numtype2 i3=0, P_numtype2 i4=0, P_numtype2 i5=0, P_numtype2 i6=0,
|
---|
84 | P_numtype2 i7=0, P_numtype2 i8=0, P_numtype2 i9=0, P_numtype2 i10=0)
|
---|
85 | {
|
---|
86 | return a[I] * i1
|
---|
87 | + _bz_meta_vectorDot<loopFlag * N, loopFlag * (I+1)>::dotWithArgs
|
---|
88 | (a, i2, i3, i4, i5, i6, i7, i8, i9);
|
---|
89 | }
|
---|
90 | };
|
---|
91 |
|
---|
92 | template<>
|
---|
93 | class _bz_meta_vectorDot<0,0> {
|
---|
94 | public:
|
---|
95 | template<class T_expr1, class T_expr2>
|
---|
96 | static inline _bz_meta_nullOperand f(const T_expr1&, const T_expr2&)
|
---|
97 | { return _bz_meta_nullOperand(); }
|
---|
98 |
|
---|
99 | template<class T_expr1, class P_numtype2>
|
---|
100 | static inline _bz_meta_nullOperand
|
---|
101 | dotWithArgs(const T_expr1& a, P_numtype2 i1, P_numtype2 i2=0,
|
---|
102 | P_numtype2 i3=0, P_numtype2 i4=0, P_numtype2 i5=0, P_numtype2 i6=0,
|
---|
103 | P_numtype2 i7=0, P_numtype2 i8=0, P_numtype2 i9=0, P_numtype2 i10=0)
|
---|
104 | {
|
---|
105 | return _bz_meta_nullOperand();
|
---|
106 | }
|
---|
107 |
|
---|
108 | };
|
---|
109 |
|
---|
110 | BZ_NAMESPACE_END
|
---|
111 |
|
---|
112 | #endif // BZ_META_DOT_H
|
---|