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