source: Sophya/trunk/SophyaExt/Blitz/blitz/vecmax.cc@ 3887

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

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

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