numpy.max/min and numpy.maximum/minimum drop NaN, and np.max can return a value that is neither the maximum nor NaN
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
Start by comparing the NumPy frontend replacements with ReductionType::Max and Min in reduction.h; the report says the shared reduction behavior also affects GPU atomics, SVE, and the Fortran frontend. Reproduce the shown NaN cases on CPU, then map which operations use each lowering path. Done means the affected max/min operations match NumPy’s NaN propagation without breaking the other listed backends; the implementation scope needs maintainer direction.
Written by the indexing model from the issue text.
Description
NumPy propagates NaN through np.max, np.min, np.maximum and np.minimum (np.fmax/np.fmin and np.nanmax are the NaN-ignoring variants). In DaCe all of them lower to max/min, implemented as (a > b) ? a : b, and every comparison with NaN is false, so a NaN resets the running result partway through a reduction:
import numpy as np, dace
A = np.array([1.0, 5.0, np.nan, 2.0, 3.0, -1.0, 0.0, 4.0])
@dace.program
def amax(A: dace.float64[8], out: dace.float64[1]):
out[0] = np.max(A)
@dace.program
def amin(A: dace.float64[8], out: dace.float64[1]):
out[0] = np.min(A)
o = np.zeros(1); amax(A.copy(), o); print(o, np.max(A)) # [2.] nan
o = np.zeros(1); amin(A.copy(), o); print(o, np.min(A)) # [2.] nan
On the same array A.max() returns 5.0 and np.maximum.reduce(A) returns 4.0, so the result depends on which path the program takes. Elementwise, np.maximum(A, B) and np.minimum(A, B) return the non-NaN operand where NumPy returns NaN, and np.clip(nan, ...), np.sign(nan) and np.heaviside(nan, h) return a number where NumPy returns NaN. Checked on main (413889d), CPU, with NumPy 2.4.6.
A fix probably needs NaN-propagating max/min for floating-point types in the NumPy frontend and in ReductionType::Max/Min (reduction.h), which also affects GPU atomics, SVE and the Fortran frontend's MAX/MIN, so I wanted to ask how you would like it done before sending a PR: NumPy-specific helpers used only by the NumPy replacements, or NaN propagation in the reduction types themselves.
- Dominant language
- Python
- Stars
- 602
- Forks
- 171
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 43
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from spcl/dace
-
Difficulty 3/5 Half a day Newbie friendliness 55/100
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
Maintainers usually reply within 2 days
-
Operational intensity raises TypeError on any library nodePossibly taken @abhinav-phi claimed this 4 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Maintainers usually reply within 2 days
-
ScalarToSymbolPromotion: replace the `0`-assignment fallback with guard-aware read/write analysisOpen
Difficulty 5/5 Over a week Newbie friendliness 42/100
Maintainers usually reply within 2 days
-
Difficulty 4/5 1-2 days Newbie friendliness 48/100
Maintainers usually reply within 2 days
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
software-mansion-labs/Diplomat#20 ·
Maintainers usually reply within 1 day
-
[Windows] Hidden title bar: a maximized window restored from minimized on a secondary monitor gets the primary monitor's work area as its client areaPossibly taken @lijy91 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
libnativeapi/nativeapi#53 · 1 reaction ·
Maintainers usually reply within 1 day
-
View Counts discarded due to field name mismatchPossibly taken @rsiva0400 claimed this today. Opensite-bug triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Model version publishes the new UK firm entity as a personPossibly taken @vahid-ahmadi claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
PolicyEngine/policyengine.py#764 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
spcl/HPCAgent-Bench#264 ·
Maintainers usually reply within 1 day