| 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 |  | 
|---|
| 27 | BZ_NAMESPACE(blitz) | 
|---|
| 28 |  | 
|---|
| 29 | template<class P> | 
|---|
| 30 | inline | 
|---|
| 31 | Vector<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 | } | 
|---|
| 56 | template<class P_numtype> | 
|---|
| 57 | Vector<BZ_SUMTYPE(P_numtype)> accumulate(const Vector<P_numtype>& x) | 
|---|
| 58 | { | 
|---|
| 59 | return _bz_vec_accumulate(x); | 
|---|
| 60 | } | 
|---|
| 61 |  | 
|---|
| 62 | template<class P_expr> | 
|---|
| 63 | Vector<BZ_SUMTYPE(_bz_typename P_expr::T_numtype)> | 
|---|
| 64 | accumulate(_bz_VecExpr<P_expr> x) | 
|---|
| 65 | { | 
|---|
| 66 | return _bz_vec_accumulate(x); | 
|---|
| 67 | } | 
|---|
| 68 |  | 
|---|
| 69 | template<class P_numtype> | 
|---|
| 70 | Vector<BZ_SUMTYPE(P_numtype)> accumulate(const VectorPick<P_numtype>& x) | 
|---|
| 71 | { | 
|---|
| 72 | return _bz_vec_accumulate(x); | 
|---|
| 73 | } | 
|---|
| 74 |  | 
|---|
| 75 | BZ_NAMESPACE_END | 
|---|
| 76 |  | 
|---|
| 77 | #endif // BZ_VECACCUM_CC | 
|---|
| 78 |  | 
|---|