source: Sophya/trunk/SophyaExt/Blitz/blitz/vecaccum.cc@ 3832

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

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

File size: 1.7 KB
Line 
1/*
2 * $Id: vecaccum.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_VECACCUM_CC
21#define BZ_VECACCUM_CC
22
23#ifndef BZ_VECGLOBS_H
24 #error <blitz/vecaccum.cc> must be included via <blitz/vecglobs.h>
25#endif
26
27BZ_NAMESPACE(blitz)
28
29template<class P>
30inline
31Vector<BZ_SUMTYPE(_bz_typename P::T_numtype)> _bz_vec_accumulate(P expr)
32{
33 typedef BZ_SUMTYPE(_bz_typename P::T_numtype) T_sumtype;
34 int length = expr._bz_suggestLength();
35 Vector<T_sumtype> z(length);
36 T_sumtype sum = 0;
37
38 if (expr._bz_hasFastAccess())
39 {
40 for (int i=0; i < length; ++i)
41 {
42 sum += expr._bz_fastAccess(i);
43 z[i] = sum;
44 }
45 }
46 else {
47 for (int i=0; i < length; ++i)
48 {
49 sum += expr(i);
50 z[i] = sum;
51 }
52 }
53
54 return z;
55}
56template<class P_numtype>
57Vector<BZ_SUMTYPE(P_numtype)> accumulate(const Vector<P_numtype>& x)
58{
59 return _bz_vec_accumulate(x);
60}
61
62template<class P_expr>
63Vector<BZ_SUMTYPE(_bz_typename P_expr::T_numtype)>
64accumulate(_bz_VecExpr<P_expr> x)
65{
66 return _bz_vec_accumulate(x);
67}
68
69template<class P_numtype>
70Vector<BZ_SUMTYPE(P_numtype)> accumulate(const VectorPick<P_numtype>& x)
71{
72 return _bz_vec_accumulate(x);
73}
74
75BZ_NAMESPACE_END
76
77#endif // BZ_VECACCUM_CC
78
Note: See TracBrowser for help on using the repository browser.