source: XMLIO_V2/external/include/blitz/vecaccum.cc @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

File size: 1.4 KB
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
17BZ_NAMESPACE(blitz)
18
19template<typename P>
20inline
21Vector<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}
46template<typename P_numtype>
47Vector<BZ_SUMTYPE(P_numtype)> accumulate(const Vector<P_numtype>& x)
48{
49    return _bz_vec_accumulate(x);
50}
51
52template<typename P_expr>
53Vector<BZ_SUMTYPE(_bz_typename P_expr::T_numtype)>
54accumulate(_bz_VecExpr<P_expr> x)
55{
56    return _bz_vec_accumulate(x);
57}
58
59template<typename P_numtype>
60Vector<BZ_SUMTYPE(P_numtype)> accumulate(const VectorPick<P_numtype>& x)
61{
62    return _bz_vec_accumulate(x);
63}
64
65BZ_NAMESPACE_END
66
67#endif // BZ_VECACCUM_CC
68
Note: See TracBrowser for help on using the repository browser.