[Kst] extragear/graphics/kst/kst
Ted Kisner
tskisner.public at gmail.com
Tue Oct 25 18:44:23 CEST 2005
SVN commit 474182 by tskisner:
Ignore NAN values when computing matrix statistics. Initialize min/max to the first finite, non-NAN value (rather than just the first value). Fixes autoscaling if matrix contains NANs
M +27 -11 kstmatrix.cpp
--- trunk/extragear/graphics/kst/kst/kstmatrix.cpp #474181:474182
@@ -27,7 +27,9 @@
#include "kstdatacollection.h"
#include "kstdataobject.h"
#include "kstdebug.h"
+#include "ksdebug.h"
#include "kstmatrix.h"
+#include "kstmath.h"
// used for resizing; set to 1 for loop zeroing, 2 to use memset
#define ZERO_MEMORY 2
@@ -234,26 +236,40 @@
double max = _z[0];
double minpos = (_z[0] > 0) ? _z[0] : 1.0E300;
double sum = 0.0, sumsquared = 0.0;
+ bool initialized = false;
_NRealS = 0;
for (int i = 0; i < _zSize; i++) {
- if (finite(_z[i])) {
- if (min > _z[i]) {
+ if (finite(_z[i]) && !KST_ISNAN(_z[i])) {
+ if (!initialized) {
min = _z[i];
- }
- if (max < _z[i]) {
max = _z[i];
+ minpos = (_z[0] > 0) ? _z[0] : 1.0E300;
+ initialized = true;
+ _NRealS++;
+ } else {
+ if (min > _z[i]) {
+ min = _z[i];
+ }
+ if (max < _z[i]) {
+ max = _z[i];
+ }
+ if (minpos > _z[i] && _z[i] > 0) {
+ minpos = _z[i];
+ }
+ sum += _z[i];
+ sumsquared += _z[i] * _z[i];
+
+ _NRealS++;
}
- if (minpos > _z[i] && _z[i] > 0) {
- minpos = _z[i];
- }
- sum += _z[i];
- sumsquared += _z[i] * _z[i];
-
- _NRealS++;
}
}
+ if (!initialized) { // no valid data in matrix
+ min = NAN;
+ max = NAN;
+ minpos = NAN;
+ }
_statScalars["sum"]->setValue(sum);
_statScalars["sumsquared"]->setValue(sumsquared);
_statScalars["max"]->setValue(max);
More information about the Kst
mailing list