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