source: XMLIO_V2/external/include/blitz/vecnorm1.cc @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

File size: 1.7 KB
Line 
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
19BZ_NAMESPACE(blitz)
20
21template<typename P_expr>
22inline
23BZ_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)
46template<typename P_numtype>
47BZ_SUMTYPE(P_numtype) norm1(const Vector<P_numtype>& x)
48{
49    return _bz_vec_norm1(x._bz_asVecExpr());
50}
51
52// norm1(expr)
53template<typename P_expr>
54BZ_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)
60template<typename P_numtype>
61BZ_SUMTYPE(P_numtype) norm1(const VectorPick<P_numtype>& x)
62{
63    return _bz_vec_norm1(x._bz_asVecExpr());
64}
65
66// norm1(TinyVector)
67template<typename P_numtype, int N_dimensions>
68BZ_SUMTYPE(P_numtype) norm1(const TinyVector<P_numtype, N_dimensions>& x)
69{
70    return _bz_vec_norm1(x._bz_asVecExpr());
71}
72
73
74BZ_NAMESPACE_END
75
76#endif // BZ_VECNORM1_CC
77
Note: See TracBrowser for help on using the repository browser.