source: Sophya/trunk/Poubelle/DPC:FitsIOServer/Blitz/blitz/vecmin.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: vecmin.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_VECMIN_CC
24#define BZ_VECMIN_CC
25
26#ifndef BZ_VECGLOBS_H
27 #error <blitz/vecmin.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_min(P_expr vector)
35{
36 typedef _bz_typename P_expr::T_numtype T_numtype;
37
38 T_numtype minValue = vector(0);
39 int minIndex = 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 < minValue)
48 {
49 minValue = value;
50 minIndex = i;
51 }
52 }
53 }
54 else {
55 for (int i=1; i < length; ++i)
56 {
57 T_numtype value = vector(i);
58 if (value < minValue)
59 {
60 minValue = value;
61 minIndex = i;
62 }
63 }
64 }
65
66 return Extremum<T_numtype, int>(minValue, minIndex);
67}
68
69// min(vector)
70template<class P_numtype>
71inline
72Extremum<P_numtype,int> min(const Vector<P_numtype>& x)
73{
74 return _bz_vec_min(x._bz_asVecExpr());
75}
76
77// min(expr)
78template<class P_expr>
79inline
80Extremum<_bz_typename P_expr::T_numtype,int> min(_bz_VecExpr<P_expr> x)
81{
82 return _bz_vec_min(x);
83}
84
85// min(vecpick)
86template<class P_numtype>
87inline
88Extremum<P_numtype, int> min(const VectorPick<P_numtype>& x)
89{
90 return _bz_vec_min(x._bz_asVecExpr());
91}
92
93// min(TinyVector)
94template<class P_numtype, int N_length>
95inline
96Extremum<P_numtype, int> min(const TinyVector<P_numtype, N_length>& x)
97{
98 return _bz_vec_min(x._bz_asVecExpr());
99}
100
101// minIndex(vector)
102template<class P_numtype>
103inline
104int minIndex(const Vector<P_numtype>& x)
105{
106 return _bz_vec_min(x._bz_asVecExpr()).index();
107}
108
109// maxIndex(expr)
110template<class P_expr>
111inline
112int minIndex(_bz_VecExpr<P_expr> x)
113{
114 return _bz_vec_min(x).index();
115}
116
117// minIndex(vecpick)
118template<class P_numtype>
119int minIndex(const VectorPick<P_numtype>& x)
120{
121 return _bz_vec_min(x._bz_asVecExpr()).index();
122}
123
124// minIndex(TinyVector)
125template<class P_numtype, int N_length>
126int minIndex(const TinyVector<P_numtype, N_length>& x)
127{
128 return _bz_vec_min(x._bz_asVecExpr()).index();
129}
130
131// minValue(vector)
132template<class P_numtype>
133inline
134int minValue(const Vector<P_numtype>& x)
135{
136 return _bz_vec_min(x._bz_asVecExpr()).value();
137}
138
139// minValue(expr)
140template<class P_expr>
141inline
142int minValue(_bz_VecExpr<P_expr> x)
143{
144 return _bz_vec_min(x).value();
145}
146
147// minValue(vecpick)
148template<class P_numtype>
149int minValue(const VectorPick<P_numtype>& x)
150{
151 return _bz_vec_min(x._bz_asVecExpr()).value();
152}
153
154// minValue(TinyVector)
155template<class P_numtype, int N_length>
156int minValue(const TinyVector<P_numtype, N_length>& x)
157{
158 return _bz_vec_min(x._bz_asVecExpr()).value();
159}
160
161BZ_NAMESPACE_END
162
163#endif // BZ_VECMIN_CC
164
Note: See TracBrowser for help on using the repository browser.