source: Sophya/trunk/SophyaExt/Blitz/blitz/vecnorm1.cc@ 3128

Last change on this file since 3128 was 221, checked in by ansari, 26 years ago

Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99

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