source: Sophya/trunk/Poubelle/DPC:FitsIOServer/Blitz/blitz/vecmax.cc@ 658

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

no message

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