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