Overview
np.all() throws NotSupportedException for non-boolean dtypes, while NumPy treats any dtype as truthy (0 = False, non-zero = True).
Reproduction
var arr = np.array(new[] { 1, 2, 3 });
var result = np.all(arr); // Throws NotSupportedException
Expected (NumPy behavior)
>>> import numpy as np
>>> np.all(np.array([1, 2, 3]))
True
>>> np.all(np.array([1, 0, 3]))
False
>>> np.all(np.array([1.5, 2.5]))
True
>>> np.all(np.array([0.0]))
False
NumPy treats:
0, 0.0, False → False
- Any non-zero value → True
Actual
System.NotSupportedException: DefaultEngine.All supports only boolean dtype.
Root Cause
Default.All.cs line ~15:
if (nd.typecode != NPTypeCode.Boolean)
throw new NotSupportedException("DefaultEngine.All supports only boolean dtype."); //TODO!
Proposed Fix
Convert input to boolean before evaluation:
public override bool All(NDArray nd)
{
// For non-boolean types, treat as truthy (0 = False, non-zero = True)
if (nd.typecode != NPTypeCode.Boolean)
nd = nd != 0; // Element-wise comparison creates bool array
// ... existing boolean logic
}
Or use the existing IL kernel infrastructure to handle all types directly.
Related
np.any() may have the same issue
- The axis overload
np.all(arr, axis=...) throws NotImplementedException entirely (separate issue)
Overview
np.all()throwsNotSupportedExceptionfor non-boolean dtypes, while NumPy treats any dtype as truthy (0 = False, non-zero = True).Reproduction
Expected (NumPy behavior)
NumPy treats:
0,0.0,False→ FalseActual
Root Cause
Default.All.csline ~15:Proposed Fix
Convert input to boolean before evaluation:
Or use the existing IL kernel infrastructure to handle all types directly.
Related
np.any()may have the same issuenp.all(arr, axis=...)throwsNotImplementedExceptionentirely (separate issue)