You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
uncertainty is zero for np.sqrt but pow(x, 0.5) is okay #74
Reproduced on current master (3748f450) with NumPy 2.0.2 and 2.5.5. Before preparing a production patch, there is a ufunc-dispatch question that affects a correct fix.
The existing __array_wrap__ hook does not receive where. For input [4, 9] +/- [0.4, 0.6] m**2 and an existing output [2, 3] +/- [1, 2] m, masks [True, False] and [False, True] leave identical magnitudes visible to that hook, but require different uncertainties: [0.1, 2] versus [1, 0.1]. A wrap-only derivative update cannot preserve the unselected entries.
A sqrt-only __array_ufunc__ override with a simple super() fallback also makes previously working multiplication, addition and reductions return NotImplemented. Converting all fallback arguments to plain Quantity avoids that error but loses the uncertain subclass and output identity. These cases were reproduced on both NumPy versions.
A local numerical prototype passes 26 cases covering units, dtype, masks, output identity, broadcasting and in-place output, but it is not integrated into the production class. Would a shared Quantity/UncertainQuantity ufunc-dispatch implementation be an acceptable direction, preserving existing non-sqrt behavior and foreign/subclass dispatch? This would be broader than a change to the sqrt uncertainty formula alone.
AI assistance: Codex prepared the investigation, prototype and tests and ran the checks described here. This is design evidence, not a completed fix or a claim of human review.
Activity
FFspiky commentedon Nov 16, 2026
Reproduced on current master (
3748f450) with NumPy 2.0.2 and 2.5.5. Before preparing a production patch, there is a ufunc-dispatch question that affects a correct fix.The existing
__array_wrap__hook does not receivewhere. For input[4, 9] +/- [0.4, 0.6] m**2and an existing output[2, 3] +/- [1, 2] m, masks[True, False]and[False, True]leave identical magnitudes visible to that hook, but require different uncertainties:[0.1, 2]versus[1, 0.1]. A wrap-only derivative update cannot preserve the unselected entries.A sqrt-only
__array_ufunc__override with a simplesuper()fallback also makes previously working multiplication, addition and reductions returnNotImplemented. Converting all fallback arguments to plainQuantityavoids that error but loses the uncertain subclass and output identity. These cases were reproduced on both NumPy versions.A local numerical prototype passes 26 cases covering units, dtype, masks, output identity, broadcasting and in-place output, but it is not integrated into the production class. Would a shared
Quantity/UncertainQuantityufunc-dispatch implementation be an acceptable direction, preserving existing non-sqrt behavior and foreign/subclass dispatch? This would be broader than a change to the sqrt uncertainty formula alone.AI assistance: Codex prepared the investigation, prototype and tests and ran the checks described here. This is design evidence, not a completed fix or a claim of human review.