source: Sophya/trunk/SophyaExt/Blitz/blitz/vecdot.cc@ 3059

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

Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99

File size: 3.5 KB
RevLine 
[221]1/*
2 * $Id: vecdot.cc,v 1.1.1.1 1999-04-09 17:58:58 ansari Exp $
3 *
4 * Copyright (C) 1997 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca>
5 * All rights reserved. Please see <blitz/blitz.h> for terms and
6 * conditions of use.
7 *
8 * $Log: not supported by cvs2svn $
9 * Revision 1.4 1998/03/14 00:04:47 tveldhui
10 * 0.2-alpha-05
11 *
12 * Revision 1.3 1997/07/16 14:51:20 tveldhui
13 * Update: Alpha release 0.2 (Arrays)
14 *
15 * Revision 1.2 1997/01/24 14:42:00 tveldhui
16 * Periodic RCS update
17 *
18 */
19
20#ifndef BZ_VECDOT_CC
21#define BZ_VECDOT_CC
22
23#ifndef BZ_VECGLOBS_H
24 #error <blitz/vecdot.cc> must be included via <blitz/vecglobs.h>
25#endif
26
27BZ_NAMESPACE(blitz)
28
29template<class P1, class P2>
30inline
31BZ_SUMTYPE(BZ_PROMOTE(_bz_typename P1::T_numtype, _bz_typename P2::T_numtype))
32_bz_dot(P1 vector1, P2 vector2)
33{
34 BZPRECONDITION(vector1._bz_suggestLength() == vector2._bz_suggestLength());
35
36 typedef BZ_SUMTYPE(BZ_PROMOTE(_bz_typename P1::T_numtype,
37 _bz_typename P2::T_numtype)) T_sumtype;
38
39 T_sumtype sum = 0;
40 int length = vector1._bz_suggestLength();
41
42 if (vector1._bz_hasFastAccess() && vector2._bz_hasFastAccess())
43 {
44 for (int i=0; i < length; ++i)
45 sum += vector1._bz_fastAccess(i)
46 * vector2._bz_fastAccess(i);
47 }
48 else {
49 for (int i=0; i < length; ++i)
50 sum += vector1[i] * vector2[i];
51 }
52
53 return sum;
54}
55
56
57// dot()
58template<class P_numtype1, class P_numtype2>
59inline
60BZ_SUMTYPE(BZ_PROMOTE(P_numtype1,P_numtype2))
61dot(const Vector<P_numtype1>& a, const Vector<P_numtype2>& b)
62{
63 return _bz_dot(a, b);
64}
65
66// dot(expr,expr)
67template<class P_expr1, class P_expr2>
68inline
69BZ_SUMTYPE(BZ_PROMOTE(_bz_typename P_expr1::T_numtype,
70 _bz_typename P_expr2::T_numtype))
71dot(_bz_VecExpr<P_expr1> expr1, _bz_VecExpr<P_expr2> expr2)
72{
73 return _bz_dot(expr1, expr2);
74}
75
76// dot(expr,vec)
77template<class P_expr1, class P_numtype2>
78inline
79BZ_SUMTYPE(BZ_PROMOTE(_bz_typename P_expr1::T_numtype, P_numtype2))
80dot(_bz_VecExpr<P_expr1> expr1, const Vector<P_numtype2>& vector2)
81{
82 return _bz_dot(vector2, expr1);
83}
84
85// dot(vec,expr)
86template<class P_numtype1, class P_expr2>
87inline
88BZ_SUMTYPE(BZ_PROMOTE(P_numtype1, _bz_typename P_expr2::T_numtype))
89dot(const Vector<P_numtype1>& vector1, _bz_VecExpr<P_expr2> expr2)
90{
91 return _bz_dot(vector1, expr2);
92}
93
94// dot(vec,vecpick)
95template<class P_numtype1, class P_numtype2>
96inline
97BZ_SUMTYPE(BZ_PROMOTE(P_numtype1, P_numtype2))
98dot(const Vector<P_numtype1>& vector1, const VectorPick<P_numtype2>& vector2)
99{
100 return _bz_dot(vector1, vector2);
101}
102
103// dot(vecpick,vec)
104template<class P_numtype1, class P_numtype2>
105inline
106BZ_SUMTYPE(BZ_PROMOTE(P_numtype1, P_numtype2))
107dot(const VectorPick<P_numtype1>& vector1, const Vector<P_numtype2>& vector2)
108{
109 return _bz_dot(vector1, vector2);
110}
111
112// dot(vecpick,vecpick)
113template<class P_numtype1, class P_numtype2>
114inline
115BZ_SUMTYPE(BZ_PROMOTE(P_numtype1, P_numtype2))
116dot(const VectorPick<P_numtype1>& vector1, const VectorPick<P_numtype2>& vector2)
117{
118 return _bz_dot(vector1, vector2);
119}
120
121// dot(expr, vecpick)
122template<class P_expr1, class P_numtype2>
123inline
124BZ_SUMTYPE(BZ_PROMOTE(_bz_typename P_expr1::T_numtype, P_numtype2))
125dot(_bz_VecExpr<P_expr1> expr1, const VectorPick<P_numtype2>& vector2)
126{
127 return _bz_dot(expr1, vector2);
128}
129
130// dot(vecpick, expr)
131template<class P_numtype1, class P_expr2>
132inline
133BZ_SUMTYPE(BZ_PROMOTE(P_numtype1, _bz_typename P_expr2::T_numtype))
134dot(const VectorPick<P_numtype1>& vector1, _bz_VecExpr<P_expr2> expr2)
135{
136 return _bz_dot(vector1, expr2);
137}
138
139BZ_NAMESPACE_END
140
141#endif // BZ_VECDOT_CC
142
Note: See TracBrowser for help on using the repository browser.