[80] | 1 | /* |
---|
| 2 | * $Id: vecdelta.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_VECDELTA_CC |
---|
| 11 | #define BZ_VECDELTA_CC |
---|
| 12 | |
---|
| 13 | #ifndef BZ_VECGLOBS_H |
---|
| 14 | #error <blitz/vecdelta.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_DIFFTYPE(_bz_typename P::T_numtype)> _bz_vec_delta(P expr) |
---|
| 22 | { |
---|
| 23 | typedef _bz_typename P::T_numtype T_numtype; |
---|
| 24 | typedef BZ_DIFFTYPE(T_numtype) T_difftype; |
---|
| 25 | |
---|
| 26 | int length = expr._bz_suggestLength(); |
---|
| 27 | Vector<T_difftype> z(length); |
---|
| 28 | T_numtype currentElement = 0; |
---|
| 29 | T_numtype previousElement = 0; |
---|
| 30 | |
---|
| 31 | if (expr._bz_hasFastAccess()) |
---|
| 32 | { |
---|
| 33 | for (int i=0; i < length; ++i) |
---|
| 34 | { |
---|
| 35 | currentElement = expr._bz_fastAccess(i); |
---|
| 36 | z[i] = currentElement - previousElement; |
---|
| 37 | previousElement = currentElement; |
---|
| 38 | } |
---|
| 39 | } |
---|
| 40 | else { |
---|
| 41 | for (int i=1; i < length; ++i) |
---|
| 42 | { |
---|
| 43 | currentElement = expr(i); |
---|
| 44 | z[i] = currentElement - previousElement; |
---|
| 45 | previousElement = currentElement; |
---|
| 46 | } |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | return z; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | template<typename P_numtype> |
---|
| 53 | Vector<BZ_DIFFTYPE(P_numtype)> delta(const Vector<P_numtype>& x) |
---|
| 54 | { |
---|
| 55 | return _bz_vec_delta(x); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | // delta(expr) |
---|
| 59 | template<typename P_expr> |
---|
| 60 | Vector<BZ_DIFFTYPE(_bz_typename P_expr::T_numtype)> delta(_bz_VecExpr<P_expr> x) |
---|
| 61 | { |
---|
| 62 | return _bz_vec_delta(x); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | // delta(vecpick) |
---|
| 66 | template<typename P_numtype> |
---|
| 67 | Vector<BZ_DIFFTYPE(P_numtype)> delta(const VectorPick<P_numtype>& x) |
---|
| 68 | { |
---|
| 69 | return _bz_vec_delta(x); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | BZ_NAMESPACE_END |
---|
| 73 | |
---|
| 74 | #endif // BZ_VECDELTA_CC |
---|
| 75 | |
---|