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