source: Sophya/trunk/SophyaExt/Blitz/blitz/vecmin.cc@ 3879

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