Repository navigation
Commit 619f5bd
authored
Drop the per-cell NaN early-out in the planar CPU slope kernel (#3742)
* Drop the per-cell NaN early-out in the planar CPU slope kernel (#3739)
_cpu started every interior cell with `if np.isnan(data[y, x]): continue`.
On DEMs with scattered nodata that branch is data-dependent and
mispredicts more than the few float32 ops and one arctan it skips.
Remove the branch and fold the centre back in with a select after the
arithmetic. Neighbour NaN already propagates through the Horn stencil,
so the select only has to cover a NaN centre with valid neighbours.
Results are bitwise identical to the old kernel on 2000x4000 float32
DEMs with no NaN, 30% random NaN and a NaN left half, and on 3x3, 1xN
and int16 inputs. On the 30% random NaN raster the kernel goes from
~92 ms to ~55 ms; the NaN-free and contiguous-NaN cases are within
noise.
Add a SlopeNaN asv benchmark with 30% random NaN over the interior so
the nodata path is timed from now on. get_xr_dataarray(include_nan=True)
only sets the [0, 0] corner to NaN, which the kernel never visits, so
the benchmark adds its own speckle.
Add tests pinning the NaN footprint on a speckled raster: NaN at every
centre-NaN cell and its 8-neighbours, finite elsewhere, on numpy and
dask+numpy.
* Address review notes on the slope NaN early-out PR (#3739)
Note in SlopeNaN that its dask timing forces the compute while
Slope.time_slope does not, so the two classes' dask numbers are not
comparable. Build the speckle mask from a float32 draw to halve the
setup allocation at nx=10000. State in the footprint test comment that
the tests pass on the old kernel too, since they pin behaviour rather
than reproduce a regression. Drop the stale "(unchanged)" from the
planar section banner.1 parent 3851c65 commit 619f5bd
3 files changed
Lines changed: 86 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | | - | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
58 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
59 | 62 | | |
60 | 63 | | |
61 | 64 | | |
| |||
67 | 70 | | |
68 | 71 | | |
69 | 72 | | |
70 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
71 | 76 | | |
72 | 77 | | |
73 | 78 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
625 | 625 | | |
626 | 626 | | |
627 | 627 | | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
0 commit comments