| 1 |
/* matrix/minmax_source.c |
| 2 |
* |
| 3 |
* Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 3 of the License, or (at |
| 8 |
* your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, but |
| 11 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program; if not, write to the Free Software |
| 17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
BASE |
| 21 |
FUNCTION (gsl_matrix, max) (const TYPE (gsl_matrix) * m) |
| 22 |
{ |
| 23 |
/* finds the largest element of a matrix */ |
| 24 |
|
| 25 |
const size_t M = m->size1; |
| 26 |
const size_t N = m->size2; |
| 27 |
const size_t tda = m->tda; |
| 28 |
|
| 29 |
BASE max = m->data[0 * tda + 0]; |
| 30 |
size_t i, j; |
| 31 |
|
| 32 |
for (i = 0; i < M; i++) |
| 33 |
{ |
| 34 |
for (j = 0; j < N; j++) |
| 35 |
{ |
| 36 |
BASE x = m->data[i * tda + j]; |
| 37 |
if (x > max) |
| 38 |
max = x; |
| 39 |
#ifdef FP |
| 40 |
if (isnan (x)) |
| 41 |
return x; |
| 42 |
#endif |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
return max; |
| 47 |
} |
| 48 |
|
| 49 |
BASE |
| 50 |
FUNCTION (gsl_matrix, min) (const TYPE (gsl_matrix) * m) |
| 51 |
{ |
| 52 |
/* finds the smallest element of a matrix */ |
| 53 |
|
| 54 |
const size_t M = m->size1; |
| 55 |
const size_t N = m->size2; |
| 56 |
const size_t tda = m->tda; |
| 57 |
|
| 58 |
BASE min = m->data[0 * tda + 0]; |
| 59 |
size_t i, j; |
| 60 |
|
| 61 |
for (i = 0; i < M; i++) |
| 62 |
{ |
| 63 |
for (j = 0; j < N; j++) |
| 64 |
{ |
| 65 |
BASE x = m->data[i * tda + j]; |
| 66 |
if (x < min) |
| 67 |
min = x; |
| 68 |
#ifdef FP |
| 69 |
if (isnan (x)) |
| 70 |
return x; |
| 71 |
#endif |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
return min; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
void |
| 80 |
FUNCTION (gsl_matrix, minmax) (const TYPE (gsl_matrix) * m, |
| 81 |
BASE * min_out, |
| 82 |
BASE * max_out) |
| 83 |
{ |
| 84 |
/* finds the smallest and largest elements of a matrix */ |
| 85 |
|
| 86 |
const size_t M = m->size1; |
| 87 |
const size_t N = m->size2; |
| 88 |
const size_t tda = m->tda; |
| 89 |
|
| 90 |
BASE max = m->data[0 * tda + 0]; |
| 91 |
BASE min = m->data[0 * tda + 0]; |
| 92 |
|
| 93 |
size_t i, j; |
| 94 |
|
| 95 |
for (i = 0; i < M; i++) |
| 96 |
{ |
| 97 |
for (j = 0; j < N; j++) |
| 98 |
{ |
| 99 |
BASE x = m->data[i * tda + j]; |
| 100 |
if (x < min) |
| 101 |
{ |
| 102 |
min = x; |
| 103 |
} |
| 104 |
if (x > max) |
| 105 |
{ |
| 106 |
max = x; |
| 107 |
} |
| 108 |
#ifdef FP |
| 109 |
if (isnan (x)) |
| 110 |
{ |
| 111 |
*min_out = x; |
| 112 |
*max_out = x; |
| 113 |
return; |
| 114 |
} |
| 115 |
#endif |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
*min_out = min; |
| 120 |
*max_out = max; |
| 121 |
} |
| 122 |
|
| 123 |
void |
| 124 |
FUNCTION (gsl_matrix, max_index) (const TYPE (gsl_matrix) * m, size_t * imax_out, size_t *jmax_out) |
| 125 |
{ |
| 126 |
/* finds the largest element of a matrix */ |
| 127 |
|
| 128 |
const size_t M = m->size1; |
| 129 |
const size_t N = m->size2; |
| 130 |
const size_t tda = m->tda; |
| 131 |
|
| 132 |
BASE max = m->data[0 * tda + 0]; |
| 133 |
size_t imax = 0, jmax = 0; |
| 134 |
size_t i, j; |
| 135 |
|
| 136 |
for (i = 0; i < M; i++) |
| 137 |
{ |
| 138 |
for (j = 0; j < N; j++) |
| 139 |
{ |
| 140 |
BASE x = m->data[i * tda + j]; |
| 141 |
if (x > max) |
| 142 |
{ |
| 143 |
max = x; |
| 144 |
imax = i; |
| 145 |
jmax = j; |
| 146 |
} |
| 147 |
#ifdef FP |
| 148 |
if (isnan (x)) |
| 149 |
{ |
| 150 |
*imax_out = i; |
| 151 |
*jmax_out = j; |
| 152 |
return; |
| 153 |
} |
| 154 |
#endif |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
*imax_out = imax; |
| 159 |
*jmax_out = jmax; |
| 160 |
} |
| 161 |
|
| 162 |
void |
| 163 |
FUNCTION (gsl_matrix, min_index) (const TYPE (gsl_matrix) * m, size_t * imin_out, size_t *jmin_out) |
| 164 |
{ |
| 165 |
/* finds the largest element of a matrix */ |
| 166 |
|
| 167 |
const size_t M = m->size1; |
| 168 |
const size_t N = m->size2; |
| 169 |
const size_t tda = m->tda; |
| 170 |
|
| 171 |
BASE min = m->data[0 * tda + 0]; |
| 172 |
size_t imin = 0, jmin = 0; |
| 173 |
size_t i, j; |
| 174 |
|
| 175 |
for (i = 0; i < M; i++) |
| 176 |
{ |
| 177 |
for (j = 0; j < N; j++) |
| 178 |
{ |
| 179 |
BASE x = m->data[i * tda + j]; |
| 180 |
if (x < min) |
| 181 |
{ |
| 182 |
min = x; |
| 183 |
imin = i; |
| 184 |
jmin = j; |
| 185 |
} |
| 186 |
#ifdef FP |
| 187 |
if (isnan (x)) |
| 188 |
{ |
| 189 |
*imin_out = i; |
| 190 |
*jmin_out = j; |
| 191 |
return; |
| 192 |
} |
| 193 |
#endif |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
*imin_out = imin; |
| 198 |
*jmin_out = jmin; |
| 199 |
} |
| 200 |
|
| 201 |
void |
| 202 |
FUNCTION (gsl_matrix, minmax_index) (const TYPE (gsl_matrix) * m, |
| 203 |
size_t * imin_out, |
| 204 |
size_t * jmin_out, |
| 205 |
size_t * imax_out, |
| 206 |
size_t * jmax_out) |
| 207 |
{ |
| 208 |
/* finds the smallest and largest elements of a matrix */ |
| 209 |
|
| 210 |
const size_t M = m->size1; |
| 211 |
const size_t N = m->size2; |
| 212 |
const size_t tda = m->tda; |
| 213 |
|
| 214 |
size_t imin = 0, jmin = 0, imax = 0, jmax = 0; |
| 215 |
BASE max = m->data[0 * tda + 0]; |
| 216 |
BASE min = m->data[0 * tda + 0]; |
| 217 |
|
| 218 |
size_t i, j; |
| 219 |
|
| 220 |
for (i = 0; i < M; i++) |
| 221 |
{ |
| 222 |
for (j = 0; j < N; j++) |
| 223 |
{ |
| 224 |
BASE x = m->data[i * tda + j]; |
| 225 |
if (x < min) |
| 226 |
{ |
| 227 |
min = x; |
| 228 |
imin = i; |
| 229 |
jmin = j; |
| 230 |
} |
| 231 |
if (x > max) |
| 232 |
{ |
| 233 |
max = x; |
| 234 |
imax = i; |
| 235 |
jmax = j; |
| 236 |
} |
| 237 |
#ifdef FP |
| 238 |
if (isnan (x)) |
| 239 |
{ |
| 240 |
*imin_out = i; |
| 241 |
*jmin_out = j; |
| 242 |
*imax_out = i; |
| 243 |
*jmax_out = j; |
| 244 |
return; |
| 245 |
} |
| 246 |
#endif |
| 247 |
} |
| 248 |
} |
| 249 |
|
| 250 |
*imin_out = imin; |
| 251 |
*jmin_out = jmin; |
| 252 |
*imax_out = imax; |
| 253 |
*jmax_out = jmax; |
| 254 |
} |