Unverified Kaydet (Commit) a47f394a authored tarafından Raymond Hettinger's avatar Raymond Hettinger Kaydeden (comit) GitHub

Minor code clean-up. Don't alter the input vector. Use variables instead. GH-8748

üst 00414597
...@@ -2056,7 +2056,7 @@ the *vec* is a NaN. ...@@ -2056,7 +2056,7 @@ the *vec* is a NaN.
static inline double static inline double
vector_norm(Py_ssize_t n, double *vec, double max, int found_nan) vector_norm(Py_ssize_t n, double *vec, double max, int found_nan)
{ {
double x, csum = 0.0, oldcsum, frac = 0.0; double x, csum = 0.0, oldcsum, frac = 0.0, last;
Py_ssize_t i; Py_ssize_t i;
if (Py_IS_INFINITY(max)) { if (Py_IS_INFINITY(max)) {
...@@ -2069,12 +2069,13 @@ vector_norm(Py_ssize_t n, double *vec, double max, int found_nan) ...@@ -2069,12 +2069,13 @@ vector_norm(Py_ssize_t n, double *vec, double max, int found_nan)
return 0.0; return 0.0;
} }
assert(n > 0); assert(n > 0);
last = vec[n-1];
for (i=0 ; i < n-1 ; i++) { for (i=0 ; i < n-1 ; i++) {
x = vec[i]; x = vec[i];
assert(Py_IS_FINITE(x) && x >= 0.0 && x <= max); assert(Py_IS_FINITE(x) && x >= 0.0 && x <= max);
if (x == max) { if (x == max) {
x = vec[n-1]; x = last;
vec[n-1] = max; last = max;
} }
x /= max; x /= max;
x = x*x - frac; x = x*x - frac;
...@@ -2082,7 +2083,7 @@ vector_norm(Py_ssize_t n, double *vec, double max, int found_nan) ...@@ -2082,7 +2083,7 @@ vector_norm(Py_ssize_t n, double *vec, double max, int found_nan)
csum += x; csum += x;
frac = (csum - oldcsum) - x; frac = (csum - oldcsum) - x;
} }
assert(vec[n-1] == max); assert(last == max);
csum += 1.0 - frac; csum += 1.0 - frac;
return max * sqrt(csum); return max * sqrt(csum);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment