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