source: Sophya/trunk/Poubelle/DPC:FitsIOServer/Blitz/blitz/vecsum.cc@ 658

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

no message

File size: 2.6 KB
Line 
1/*
2 * $Id: vecsum.cc,v 1.1.1.1 1999-11-26 16:37:06 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:59 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_VECSUM_CC
24#define BZ_VECSUM_CC
25
26#ifndef BZ_VECGLOBS_H
27 #error <blitz/vecsum.cc> must be included via <blitz/vecglobs.h>
28#endif
29
30BZ_NAMESPACE(blitz)
31
32template<class P_expr>
33inline
34BZ_SUMTYPE(_bz_typename P_expr::T_numtype)
35_bz_vec_sum(P_expr vector)
36{
37 typedef _bz_typename P_expr::T_numtype T_numtype;
38 typedef BZ_SUMTYPE(T_numtype) T_sumtype;
39
40 T_sumtype sum = 0;
41 int length = vector._bz_suggestLength();
42
43 if (vector._bz_hasFastAccess())
44 {
45 for (int i=0; i < length; ++i)
46 sum += vector._bz_fastAccess(i);
47 }
48 else {
49 for (int i=0; i < length; ++i)
50 sum += vector(i);
51 }
52
53 return sum;
54}
55
56template<class P_numtype>
57inline
58BZ_SUMTYPE(P_numtype) sum(const Vector<P_numtype>& x)
59{
60 return _bz_vec_sum(x._bz_asVecExpr());
61}
62
63// sum(expr)
64template<class P_expr>
65inline
66BZ_SUMTYPE(_bz_typename P_expr::T_numtype)
67sum(_bz_VecExpr<P_expr> expr)
68{
69 return _bz_vec_sum(expr);
70}
71
72// sum(vecpick)
73template<class P_numtype>
74inline
75BZ_SUMTYPE(P_numtype)
76sum(const VectorPick<P_numtype>& x)
77{
78 return _bz_vec_sum(x._bz_asVecExpr());
79}
80
81// mean(vector)
82template<class P_numtype>
83inline
84BZ_FLOATTYPE(BZ_SUMTYPE(P_numtype)) mean(const Vector<P_numtype>& x)
85{
86 BZPRECONDITION(x.length() > 0);
87
88 typedef BZ_FLOATTYPE(BZ_SUMTYPE(P_numtype)) T_floattype;
89 return _bz_vec_sum(x._bz_asVecExpr()) / (T_floattype) x.length();
90}
91
92// mean(expr)
93template<class P_expr>
94inline
95BZ_FLOATTYPE(BZ_SUMTYPE(_bz_typename P_expr::T_numtype))
96mean(_bz_VecExpr<P_expr> expr)
97{
98 BZPRECONDITION(expr._bz_suggestLength() > 0);
99
100 typedef BZ_FLOATTYPE(BZ_SUMTYPE(_bz_typename P_expr::T_numtype))
101 T_floattype;
102 return _bz_vec_sum(expr) / (T_floattype) expr._bz_suggestLength();
103}
104
105// mean(vecpick)
106template<class P_numtype>
107inline
108BZ_FLOATTYPE(BZ_SUMTYPE(P_numtype))
109mean(const VectorPick<P_numtype>& x)
110{
111 BZPRECONDITION(x.length() > 0);
112
113 typedef BZ_FLOATTYPE(BZ_SUMTYPE(P_numtype)) T_floattype;
114 return _bz_vec_sum(x._bz_asVecExpr()) / (T_floattype) x.length();
115}
116
117BZ_NAMESPACE_END
118
119#endif // BZ_VECSUM_CC
120
Note: See TracBrowser for help on using the repository browser.