- Added new 8-bit unsigned float type:
ml_dtypes.float8_e5m3fnu
(#407). ml_dtypestypes now use the NumPy 2 DType API
(#374, #418, #424):- Fixed
np.result_typeandnp.promote_typesforml_dtypestypes and
Python scalars. Mixed operations with Pythonint,float, andcomplex
values now follow NumPy 2 (NEP 50) promotion rules instead of upcasting to
float64orcomplex128(for example,bfloat16(2.0) + 1e-3stays in
bfloat16). Comparing a finite-only or unsigned float against an
out-of-range Python float converts the Python float to theml_dtypestype
first (e.g.,float8_e4m3fn(448.0) < 1000.0isFalsebecause
float8_e4m3fn(1000.0)overflows toNaN; usefloat(x) < 1000.0for
wider bounds). - Fixed
np.can_castso lossy casts between 1-byte types (such as
float8_e4m3fntofloat4_e2m1fn) are no longer reported as"safe", and
wideningintNcasts tolonglongandulonglongare now"safe". - Added casts between all pairs of
ml_dtypestypes, including narrowing and
mixed-signintNcasts,int4/uint4<->float6_e2m3fn, and casts
involvingfloat8_e8m0fnu. - Multi-axis and empty-array ufunc reductions now work across all
ml_dtypes
types. - Casting non-finite or out-of-range floats to integers now consistently
returns0and emits aninvalidwarning; casting complex types to real or
integerml_dtypestypes emitsComplexWarning; integer division by zero
respectsnp.errstate; andnp.ldexpsupports 64-bit integer exponents on
all platforms.
- Fixed
- Registered byte-aligned
ml_dtypestypes with NumPy's DLPack support on
NumPy 2.5+ (#402). np.finfonow supportsml_dtypesfloat and complex types,ml_dtypes.finfo
now accepts"complex32", andnp.float_poweris now supported for float and
complex types (#395).- Changed
np.dtype(complex32).kindfrom'V'to'c', and changed
dtype.charforcomplex32andbcomplex32to'J'and'K'
(#357). arr.realandarr.imagnow return correct results forbcomplex32and
complex32arrays on NumPy 2.5+ (#383).- Fixed byte-swapping of
bcomplex32andcomplex32arrays
(#383). - Fixed
NaNordering forcomplex32andbcomplex32innp.sortand
np.searchsorted(#429),
casting purely imaginary values tobool
(#395), andTypeError
handling in two-argumentcomplex32(real, imag)/bcomplex32(real, imag)
(#439). - Fixed double rounding when converting to
ml_dtypesfloat and complex types
fromfloat64,longdouble,complex128,clongdouble, 32- and 64-bit
integers, and Python/NumPy scalars, and fixed a crash when constructing floats
from invalid strings (#401). - Constructing a float or complex scalar from a Python
intoutside theint64
range no longer raisesOverflowErrorwhen the value fits infloat64
(#447). - Fixed
int(x)onml_dtypesfloat and complex scalars for large values,
inf, andNaN(#444). - Constructing
intNvalues from Python floats now truncates toward zero before
range checking (e.g.int4(7.5)returns7instead of raising
OverflowError) (#443), and
out-of-range errors now name the actualintNtype instead of"int4"
(#403). - Casts to
float8_e8m0fnunow round values between 2-127 and
1.5 × 2-127 down to 2-127 instead of up to
2-126
(#434). np.copysignof zero no longer returnsNaNfor*fnuztypes, and
np.signandnp.heavisideof the smallestfloat8_e8m0fnuvalue now
return 1 (#408,
#416).- Fixed spurious
invalid valuewarnings when casting quietNaNs on ARM64
(#426,
#428). complex_types.hcan now be included in C++ without Python or NumPy headers
(#422).float8.hno longer depends onEigen::numext::get_integer_by_size, which is
unavailable in Eigen 3.4.x
(#414).