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