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