| 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 |  | 
|---|
| 27 | BZ_NAMESPACE(blitz) | 
|---|
| 28 |  | 
|---|
| 29 | template<class P_expr> | 
|---|
| 30 | inline | 
|---|
| 31 | Extremum<_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) | 
|---|
| 67 | template<class P_numtype> | 
|---|
| 68 | inline | 
|---|
| 69 | Extremum<P_numtype,int> min(const Vector<P_numtype>& x) | 
|---|
| 70 | { | 
|---|
| 71 | return _bz_vec_min(x._bz_asVecExpr()); | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | // min(expr) | 
|---|
| 75 | template<class P_expr> | 
|---|
| 76 | inline | 
|---|
| 77 | Extremum<_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) | 
|---|
| 83 | template<class P_numtype> | 
|---|
| 84 | inline | 
|---|
| 85 | Extremum<P_numtype, int> min(const VectorPick<P_numtype>& x) | 
|---|
| 86 | { | 
|---|
| 87 | return _bz_vec_min(x._bz_asVecExpr()); | 
|---|
| 88 | } | 
|---|
| 89 |  | 
|---|
| 90 | // min(TinyVector) | 
|---|
| 91 | template<class P_numtype, int N_length> | 
|---|
| 92 | inline | 
|---|
| 93 | Extremum<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) | 
|---|
| 99 | template<class P_numtype> | 
|---|
| 100 | inline | 
|---|
| 101 | int  minIndex(const Vector<P_numtype>& x) | 
|---|
| 102 | { | 
|---|
| 103 | return _bz_vec_min(x._bz_asVecExpr()).index(); | 
|---|
| 104 | } | 
|---|
| 105 |  | 
|---|
| 106 | // maxIndex(expr) | 
|---|
| 107 | template<class P_expr> | 
|---|
| 108 | inline | 
|---|
| 109 | int  minIndex(_bz_VecExpr<P_expr> x) | 
|---|
| 110 | { | 
|---|
| 111 | return _bz_vec_min(x).index(); | 
|---|
| 112 | } | 
|---|
| 113 |  | 
|---|
| 114 | // minIndex(vecpick) | 
|---|
| 115 | template<class P_numtype> | 
|---|
| 116 | int  minIndex(const VectorPick<P_numtype>& x) | 
|---|
| 117 | { | 
|---|
| 118 | return _bz_vec_min(x._bz_asVecExpr()).index(); | 
|---|
| 119 | } | 
|---|
| 120 |  | 
|---|
| 121 | // minIndex(TinyVector) | 
|---|
| 122 | template<class P_numtype, int N_length> | 
|---|
| 123 | int minIndex(const TinyVector<P_numtype, N_length>& x) | 
|---|
| 124 | { | 
|---|
| 125 | return _bz_vec_min(x._bz_asVecExpr()).index(); | 
|---|
| 126 | } | 
|---|
| 127 |  | 
|---|
| 128 | // minValue(vector) | 
|---|
| 129 | template<class P_numtype> | 
|---|
| 130 | inline | 
|---|
| 131 | int  minValue(const Vector<P_numtype>& x) | 
|---|
| 132 | { | 
|---|
| 133 | return _bz_vec_min(x._bz_asVecExpr()).value(); | 
|---|
| 134 | } | 
|---|
| 135 |  | 
|---|
| 136 | // minValue(expr) | 
|---|
| 137 | template<class P_expr> | 
|---|
| 138 | inline | 
|---|
| 139 | int  minValue(_bz_VecExpr<P_expr> x) | 
|---|
| 140 | { | 
|---|
| 141 | return _bz_vec_min(x).value(); | 
|---|
| 142 | } | 
|---|
| 143 |  | 
|---|
| 144 | // minValue(vecpick) | 
|---|
| 145 | template<class P_numtype> | 
|---|
| 146 | int  minValue(const VectorPick<P_numtype>& x) | 
|---|
| 147 | { | 
|---|
| 148 | return _bz_vec_min(x._bz_asVecExpr()).value(); | 
|---|
| 149 | } | 
|---|
| 150 |  | 
|---|
| 151 | // minValue(TinyVector) | 
|---|
| 152 | template<class P_numtype, int N_length> | 
|---|
| 153 | int  minValue(const TinyVector<P_numtype, N_length>& x) | 
|---|
| 154 | { | 
|---|
| 155 | return _bz_vec_min(x._bz_asVecExpr()).value(); | 
|---|
| 156 | } | 
|---|
| 157 |  | 
|---|
| 158 | BZ_NAMESPACE_END | 
|---|
| 159 |  | 
|---|
| 160 | #endif // BZ_VECMIN_CC | 
|---|
| 161 |  | 
|---|