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