Commit 4e22efa
authored
* polygonize: cupy backend honours numba _is_close tolerance for floats (#2151)
The cupy backend binned float pixels into regions by exact value while
the numba CPU path (used by the numpy, dask and dask+cupy backends)
compares neighbouring pixels with `_is_close` (atol=1e-8, rtol=1e-5).
On float rasters with near-equal values this produced different polygon
sets across backends.
For float dtypes, group sorted unique values in the cupy backend using
the same tolerance and label each group as a single region. Integer
dtypes keep the existing exact-equality path.
Adds a regression test asserting that the cupy backend yields the same
polygon count and per-value areas as the numpy backend on a float
raster with values 1.0 and 1.000001.
Also records this finding in the accuracy sweep state CSV.
* polygonize: route cupy float path through CPU CCL for true _is_close parity
The first pass at #2151 added value-only greedy chaining of unique float
values in _calculate_regions_cupy. That fixed the reported pattern
(adjacent near-equal pixels) but still diverged from the CPU path when
three or more transitively-close values were present in the raster
without intermediate adjacent pixels. Example:
[1.0, 1.000018]
[1.000009, 3.0 ]
CPU spatial CCL yields three regions: 1.0 + 1.000009 (close, adjacent),
1.000018 alone (not close to either neighbour), and 3.0 alone. The
value-grouping heuristic chained 1.0 -> 1.000009 -> 1.000018 and labeled
the connected mask as a single region, returning two regions on cupy.
Route float dtypes through _polygonize_numpy in _polygonize_cupy so the
numba _is_close predicate is applied to spatially adjacent pixels, the
only place CPU and GPU semantics can agree without re-implementing CCL.
The data is already transferred to host for boundary tracing, so the
fall-back cost is one extra _calculate_regions call.
Drop _group_float_values_by_tolerance and the float branch of
_calculate_regions_cupy as dead code. Extend the regression test to
parametrize over the original adjacent pattern and the transitivity
edge case.
1 parent 6549a48 commit 4e22efa
3 files changed
Lines changed: 76 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
594 | 594 | | |
595 | 595 | | |
596 | 596 | | |
597 | | - | |
| 597 | + | |
598 | 598 | | |
599 | 599 | | |
600 | 600 | | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
601 | 607 | | |
602 | 608 | | |
603 | 609 | | |
| |||
609 | 615 | | |
610 | 616 | | |
611 | 617 | | |
612 | | - | |
613 | | - | |
614 | 618 | | |
615 | 619 | | |
616 | | - | |
617 | | - | |
618 | 620 | | |
619 | | - | |
| 621 | + | |
620 | 622 | | |
621 | 623 | | |
622 | 624 | | |
| |||
669 | 671 | | |
670 | 672 | | |
671 | 673 | | |
672 | | - | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
673 | 683 | | |
674 | 684 | | |
| 685 | + | |
| 686 | + | |
675 | 687 | | |
676 | 688 | | |
677 | 689 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
459 | 459 | | |
460 | 460 | | |
461 | 461 | | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
462 | 518 | | |
463 | 519 | | |
464 | 520 | | |
| |||
0 commit comments