| 1 | /* | 
|---|
| 2 | * $Id: vecnorm1.cc,v 1.1.1.1 1999-11-26 16:37:06 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:59  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_VECNORM1_CC | 
|---|
| 24 | #define BZ_VECNORM1_CC | 
|---|
| 25 |  | 
|---|
| 26 | #ifndef BZ_VECGLOBS_H | 
|---|
| 27 | #error <blitz/vecnorm1.cc> must be included via <blitz/vecglobs.h> | 
|---|
| 28 | #endif | 
|---|
| 29 |  | 
|---|
| 30 | #include <blitz/applics.h> | 
|---|
| 31 |  | 
|---|
| 32 | BZ_NAMESPACE(blitz) | 
|---|
| 33 |  | 
|---|
| 34 | template<class P_expr> | 
|---|
| 35 | inline | 
|---|
| 36 | BZ_SUMTYPE(_bz_typename P_expr::T_numtype) | 
|---|
| 37 | _bz_vec_norm1(P_expr vector) | 
|---|
| 38 | { | 
|---|
| 39 | typedef _bz_typename P_expr::T_numtype T_numtype; | 
|---|
| 40 | typedef BZ_SUMTYPE(T_numtype)          T_sumtype; | 
|---|
| 41 |  | 
|---|
| 42 | T_sumtype sum = 0; | 
|---|
| 43 | int length = vector._bz_suggestLength(); | 
|---|
| 44 |  | 
|---|
| 45 | if (vector._bz_hasFastAccess()) | 
|---|
| 46 | { | 
|---|
| 47 | for (int i=0; i < length; ++i) | 
|---|
| 48 | sum += _bz_abs<T_numtype>::apply(vector._bz_fastAccess(i)); | 
|---|
| 49 | } | 
|---|
| 50 | else { | 
|---|
| 51 | for (int i=0; i < length; ++i) | 
|---|
| 52 | sum += _bz_abs<T_numtype>::apply(vector(i)); | 
|---|
| 53 | } | 
|---|
| 54 |  | 
|---|
| 55 | return sum; | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 | // norm1(vector) | 
|---|
| 59 | template<class P_numtype> | 
|---|
| 60 | BZ_SUMTYPE(P_numtype) norm1(const Vector<P_numtype>& x) | 
|---|
| 61 | { | 
|---|
| 62 | return _bz_vec_norm1(x._bz_asVecExpr()); | 
|---|
| 63 | } | 
|---|
| 64 |  | 
|---|
| 65 | // norm1(expr) | 
|---|
| 66 | template<class P_expr> | 
|---|
| 67 | BZ_SUMTYPE(_bz_typename P_expr::T_numtype) norm1(_bz_VecExpr<P_expr> expr) | 
|---|
| 68 | { | 
|---|
| 69 | return _bz_vec_norm1(expr); | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|
| 72 | // norm1(vecpick) | 
|---|
| 73 | template<class P_numtype> | 
|---|
| 74 | BZ_SUMTYPE(P_numtype) norm1(const VectorPick<P_numtype>& x) | 
|---|
| 75 | { | 
|---|
| 76 | return _bz_vec_norm1(x._bz_asVecExpr()); | 
|---|
| 77 | } | 
|---|
| 78 |  | 
|---|
| 79 | // norm1(TinyVector) | 
|---|
| 80 | template<class P_numtype, int N_dimensions> | 
|---|
| 81 | BZ_SUMTYPE(P_numtype) norm1(const TinyVector<P_numtype, N_dimensions>& x) | 
|---|
| 82 | { | 
|---|
| 83 | return _bz_vec_norm1(x._bz_asVecExpr()); | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 |  | 
|---|
| 87 | BZ_NAMESPACE_END | 
|---|
| 88 |  | 
|---|
| 89 | #endif // BZ_VECNORM1_CC | 
|---|
| 90 |  | 
|---|