|
4 | 4 |
|
5 | 5 | #include "_transforms.h" |
6 | 6 | #include "mplutils.h" |
| 7 | +#include "MPL_isnan.h" |
7 | 8 |
|
8 | 9 |
|
9 | 10 | #include "numpy/arrayobject.h" |
10 | | -#include "numpy/ufuncobject.h" |
11 | | -#if !defined(isfinite) |
12 | | -#define isfinite(x) (!(isinf((x)) || isnan((x)))) |
13 | | -#endif |
| 11 | +//#include "numpy/ufuncobject.h" |
| 12 | + |
| 13 | + |
| 14 | +//bool skip_float(double x) { |
| 15 | +// return !MPL_isnan64(x) && !isinf(x); |
| 16 | +//} |
14 | 17 |
|
15 | 18 | Value::~Value() { |
16 | 19 | _VERBOSE("Value::~Value"); |
@@ -467,23 +470,31 @@ Bbox::update(const Py::Tuple &args) { |
467 | 470 |
|
468 | 471 | Py::Tuple tup; |
469 | 472 | if (ignore) { |
470 | | - minx = miny = std::numeric_limits<double>::max(); |
471 | | - maxx = maxy = std::numeric_limits<double>::min(); |
| 473 | + tup = xys[0]; |
| 474 | + double x = Py::Float(tup[0]); |
| 475 | + double y = Py::Float(tup[1]); |
| 476 | + |
| 477 | + minx=x; |
| 478 | + maxx=x; |
| 479 | + miny=y; |
| 480 | + maxy=y; |
472 | 481 | } |
473 | 482 |
|
| 483 | + |
474 | 484 | for (size_t i=0; i<Nx; ++i) { |
475 | 485 | tup = xys[i]; |
476 | 486 | double x = Py::Float(tup[0]); |
477 | 487 | double y = Py::Float(tup[1]); |
478 | | - if (isnan(x) || isnan(y)) continue; |
479 | 488 | _posx.update(x); |
480 | 489 | _posy.update(y); |
481 | 490 | if (x<minx) minx=x; |
482 | 491 | if (x>maxx) maxx=x; |
483 | 492 | if (y<miny) miny=y; |
484 | 493 | if (y>maxy) maxy=y; |
| 494 | + |
485 | 495 | } |
486 | 496 |
|
| 497 | + |
487 | 498 | _ll->x_api()->set_api(minx); |
488 | 499 | _ll->y_api()->set_api(miny); |
489 | 500 | _ur->x_api()->set_api(maxx); |
@@ -539,7 +550,7 @@ Bbox::update_numerix_xy(const Py::Tuple &args) { |
539 | 550 | for (size_t i=0; i< Nxy; ++i) { |
540 | 551 | thisx = *(double *)(xyin->data + i*xyin->strides[0]); |
541 | 552 | thisy = *(double *)(xyin->data + i*xyin->strides[0] + xyin->strides[1]); |
542 | | - if (isnan(thisx) || isnan(thisy)) continue; |
| 553 | + if (MPL_isnan64(thisx) || MPL_isnan64(thisy)) continue; |
543 | 554 | _posx.update(thisx); |
544 | 555 | _posy.update(thisy); |
545 | 556 | if (thisx<minx) minx=thisx; |
@@ -606,14 +617,37 @@ Bbox::update_numerix(const Py::Tuple &args) { |
606 | 617 | _ignore = 0; // don't ignore future updates |
607 | 618 | } |
608 | 619 | if (ignore) { |
609 | | - minx = miny = std::numeric_limits<double>::max(); |
610 | | - maxx = maxy = std::numeric_limits<double>::min(); |
| 620 | + int xok=0; |
| 621 | + int yok=0; |
| 622 | + // loop through values until we find some nans... |
| 623 | + for (size_t i=0; i< Nx; ++i) { |
| 624 | + thisx = *(double *)(x->data + i*x->strides[0]); |
| 625 | + thisy = *(double *)(y->data + i*y->strides[0]); |
| 626 | + |
| 627 | + if (!xok) { |
| 628 | + if (!MPL_isnan64(thisx)) { |
| 629 | + minx=thisx; |
| 630 | + maxx=thisx; |
| 631 | + xok=1; |
| 632 | + } |
| 633 | + } |
| 634 | + |
| 635 | + if (!yok) { |
| 636 | + if (!MPL_isnan64(thisy)) { |
| 637 | + miny=thisy; |
| 638 | + maxy=thisy; |
| 639 | + yok=1; |
| 640 | + } |
| 641 | + } |
| 642 | + |
| 643 | + if (xok && yok) break; |
| 644 | + } |
611 | 645 | } |
612 | 646 |
|
613 | 647 | for (size_t i=0; i< Nx; ++i) { |
614 | 648 | thisx = *(double *)(x->data + i*x->strides[0]); |
615 | 649 | thisy = *(double *)(y->data + i*y->strides[0]); |
616 | | - if (isnan(thisx) || isnan(thisy)) continue; |
| 650 | + |
617 | 651 | _posx.update(thisx); |
618 | 652 | _posy.update(thisy); |
619 | 653 | if (thisx<minx) minx=thisx; |
@@ -1255,18 +1289,18 @@ Transformation::nonlinear_only_numerix(const Py::Tuple & args, const Py::Dict &k |
1255 | 1289 |
|
1256 | 1290 | double thisx = *(double *)(x->data + i*x->strides[0]); |
1257 | 1291 | double thisy = *(double *)(y->data + i*y->strides[0]); |
1258 | | - if (isnan(thisx) || isnan(thisy)) { |
| 1292 | + if (MPL_isnan64(thisx) || MPL_isnan64(thisy)) { |
1259 | 1293 | if (returnMask) { |
1260 | 1294 | *(unsigned char *)(retmask->data + i*retmask->strides[0]) = 0; |
1261 | 1295 | } |
1262 | | - double MPL_not_finite; // don't require C99 math features - find our own nan |
1263 | | - if (isnan(thisx)) { |
1264 | | - MPL_not_finite=thisx; |
| 1296 | + double MPLnan; // don't require C99 math features - find our own nan |
| 1297 | + if (MPL_isnan64(thisx)) { |
| 1298 | + MPLnan=thisx; |
1265 | 1299 | } else { |
1266 | | - MPL_not_finite=thisy; |
| 1300 | + MPLnan=thisy; |
1267 | 1301 | } |
1268 | | - *(double *)(retx->data + i*retx->strides[0]) = MPL_not_finite; |
1269 | | - *(double *)(rety->data + i*rety->strides[0]) = MPL_not_finite; |
| 1302 | + *(double *)(retx->data + i*retx->strides[0]) = MPLnan; |
| 1303 | + *(double *)(rety->data + i*rety->strides[0]) = MPLnan; |
1270 | 1304 | } else { |
1271 | 1305 | try { |
1272 | 1306 | this->nonlinear_only_api(&thisx, &thisy); |
|
0 commit comments