source: XMLIO_V2/external/include/blitz/vecmax.cc @ 73

Last change on this file since 73 was 73, checked in by ymipsl, 14 years ago
File size: 3.1 KB
Line 
1/*
2 * $Id: vecmax.cc,v 1.4 2005/06/02 18:56:52 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_VECMAX_CC
11#define BZ_VECMAX_CC
12
13#ifndef BZ_VECGLOBS_H
14 #error <blitz/vecmax.cc> must be included via <blitz/vecglobs.h>
15#endif
16
17BZ_NAMESPACE(blitz)
18
19template<typename P_expr>
20inline
21Extremum<_bz_typename P_expr::T_numtype, int> _bz_vec_max(P_expr vector)
22{
23    typedef _bz_typename P_expr::T_numtype T_numtype;
24
25    T_numtype maxValue = vector(0);
26    int maxIndex = 0;
27    int length = vector._bz_suggestLength();
28
29    if (vector._bz_hasFastAccess())
30    {
31        for (int i=1; i < length; ++i)
32        {
33            T_numtype value = vector._bz_fastAccess(i);
34            if (value > maxValue)
35            {
36                maxValue = value;
37                maxIndex = i;
38            }
39        }
40    }
41    else {
42        for (int i=1; i < length; ++i)
43        {
44            T_numtype value = vector(i);
45            if (value > maxValue)
46            {
47                maxValue = value;
48                maxIndex = i;
49            }
50        }
51    }
52
53    return Extremum<T_numtype, int>(maxValue, maxIndex);
54}
55
56// max(vector)
57template<typename P_numtype>
58inline
59Extremum<P_numtype, int> (max)(const Vector<P_numtype>& x)
60{
61    return _bz_vec_max(x._bz_asVecExpr());
62}
63
64// max(expr)
65template<typename P_expr>
66inline
67Extremum<_bz_typename P_expr::T_numtype,int> (max)(_bz_VecExpr<P_expr> x)
68{
69    return _bz_vec_max(x);
70}
71
72// max(vecpick)
73template<typename P_numtype>
74inline
75Extremum<P_numtype, int> (max)(const VectorPick<P_numtype>& x)
76{
77    return _bz_vec_max(x._bz_asVecExpr());
78}
79
80// max(TinyVector)
81template<typename P_numtype, int N_length>
82inline
83Extremum<P_numtype, int> (max)(const TinyVector<P_numtype, N_length>& x)
84{
85    return _bz_vec_max(x._bz_asVecExpr());
86}
87
88
89// maxIndex(vector)
90template<typename P_numtype>
91inline
92int maxIndex(const Vector<P_numtype>& x)
93{
94    return _bz_vec_max(x).index();
95}
96
97// maxIndex(expr)
98template<typename P_expr>
99inline
100int maxIndex(_bz_VecExpr<P_expr> x)
101{
102    return _bz_vec_max(x._bz_asVecExpr()).index();
103}
104
105// maxIndex(vecpick)
106template<typename P_numtype>
107int maxIndex(const VectorPick<P_numtype>& x)
108{
109    return _bz_vec_max(x._bz_asVecExpr()).index();
110}
111
112// maxIndex(TinyVector)
113template<typename P_numtype, int N_length>
114int maxIndex(const TinyVector<P_numtype, N_length>& x)
115{
116    return _bz_vec_max(x._bz_asVecExpr()).index();
117}
118
119// maxValue(vector)
120template<typename P_numtype>
121inline
122int maxValue(const Vector<P_numtype>& x)
123{
124    return _bz_vec_max(x._bz_asVecExpr()).value();
125}
126
127// maxValue(expr)
128template<typename P_expr>
129inline
130int maxValue(_bz_VecExpr<P_expr> x)
131{
132    return _bz_vec_max(x).value();
133}
134
135// maxValue(vecpick)
136template<typename P_numtype>
137int maxValue(const VectorPick<P_numtype>& x)
138{
139    return _bz_vec_max(x._bz_asVecExpr()).value();
140}
141
142// maxValue(TinyVector)
143template<typename P_numtype, int N_length>
144int maxValue(const TinyVector<P_numtype, N_length>& x)
145{
146    return _bz_vec_max(x._bz_asVecExpr()).value();
147}
148
149BZ_NAMESPACE_END
150
151#endif // BZ_VECMAX_CC
152
Note: See TracBrowser for help on using the repository browser.