Line | |
---|
1 | /* |
---|
2 | * $Id: vecaccum.cc,v 1.3 2003/12/11 03:44:22 julianc Exp $ |
---|
3 | * |
---|
4 | * Copyright (C) 1997 Todd Veldhuizen <tveldhui@oonumerics.org> |
---|
5 | * All rights reserved. Please see <blitz/blitz.h> for terms and |
---|
6 | * conditions of use. |
---|
7 | * |
---|
8 | */ |
---|
9 | |
---|
10 | #ifndef BZ_VECACCUM_CC |
---|
11 | #define BZ_VECACCUM_CC |
---|
12 | |
---|
13 | #ifndef BZ_VECGLOBS_H |
---|
14 | #error <blitz/vecaccum.cc> must be included via <blitz/vecglobs.h> |
---|
15 | #endif |
---|
16 | |
---|
17 | BZ_NAMESPACE(blitz) |
---|
18 | |
---|
19 | template<typename P> |
---|
20 | inline |
---|
21 | Vector<BZ_SUMTYPE(_bz_typename P::T_numtype)> _bz_vec_accumulate(P expr) |
---|
22 | { |
---|
23 | typedef BZ_SUMTYPE(_bz_typename P::T_numtype) T_sumtype; |
---|
24 | int length = expr._bz_suggestLength(); |
---|
25 | Vector<T_sumtype> z(length); |
---|
26 | T_sumtype sum = 0; |
---|
27 | |
---|
28 | if (expr._bz_hasFastAccess()) |
---|
29 | { |
---|
30 | for (int i=0; i < length; ++i) |
---|
31 | { |
---|
32 | sum += expr._bz_fastAccess(i); |
---|
33 | z[i] = sum; |
---|
34 | } |
---|
35 | } |
---|
36 | else { |
---|
37 | for (int i=0; i < length; ++i) |
---|
38 | { |
---|
39 | sum += expr(i); |
---|
40 | z[i] = sum; |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | return z; |
---|
45 | } |
---|
46 | template<typename P_numtype> |
---|
47 | Vector<BZ_SUMTYPE(P_numtype)> accumulate(const Vector<P_numtype>& x) |
---|
48 | { |
---|
49 | return _bz_vec_accumulate(x); |
---|
50 | } |
---|
51 | |
---|
52 | template<typename P_expr> |
---|
53 | Vector<BZ_SUMTYPE(_bz_typename P_expr::T_numtype)> |
---|
54 | accumulate(_bz_VecExpr<P_expr> x) |
---|
55 | { |
---|
56 | return _bz_vec_accumulate(x); |
---|
57 | } |
---|
58 | |
---|
59 | template<typename P_numtype> |
---|
60 | Vector<BZ_SUMTYPE(P_numtype)> accumulate(const VectorPick<P_numtype>& x) |
---|
61 | { |
---|
62 | return _bz_vec_accumulate(x); |
---|
63 | } |
---|
64 | |
---|
65 | BZ_NAMESPACE_END |
---|
66 | |
---|
67 | #endif // BZ_VECACCUM_CC |
---|
68 | |
---|
Note: See
TracBrowser
for help on using the repository browser.