mirror of
https://github.com/wassname/jaxtyping.git
synced 2026-09-09 11:24:55 +08:00
Removed unused elements from unions, e.g. Float[ArrayLike, ...] will no longer include Float[np.bool, ...].
This commit is contained in:
@@ -498,6 +498,16 @@ def _make_array(array_type, dim_str, dtypes, name):
|
||||
return array_type
|
||||
else:
|
||||
return _not_made
|
||||
elif array_type is np.bool_:
|
||||
if _check_scalar("bool", dtypes, dims):
|
||||
return array_type
|
||||
else:
|
||||
return _not_made
|
||||
elif array_type is np.generic or array_type is np.number:
|
||||
if _check_scalar("", dtypes, dims):
|
||||
return array_type
|
||||
else:
|
||||
return _not_made
|
||||
if issubclass(array_type, AbstractArray):
|
||||
if dtypes is _any_dtype:
|
||||
dtypes = array_type.dtypes
|
||||
|
||||
@@ -496,22 +496,18 @@ def test_arraylike(typecheck, getkey):
|
||||
assert set(get_args(floatlike1)) == {
|
||||
Float32[Array, ""],
|
||||
Float32[np.ndarray, ""],
|
||||
Float32[np.bool_, ""],
|
||||
Float32[np.number, ""],
|
||||
float,
|
||||
}
|
||||
assert set(get_args(floatlike2)) == {
|
||||
Float[Array, ""],
|
||||
Float[np.ndarray, ""],
|
||||
Float[np.bool_, ""],
|
||||
Float[np.number, ""],
|
||||
float,
|
||||
}
|
||||
assert set(get_args(floatlike3)) == {
|
||||
Float32[Array, "4"],
|
||||
Float32[np.ndarray, "4"],
|
||||
Float32[np.bool_, "4"],
|
||||
Float32[np.number, "4"],
|
||||
}
|
||||
|
||||
shaped1 = Shaped[ArrayLike, ""]
|
||||
@@ -531,8 +527,6 @@ def test_arraylike(typecheck, getkey):
|
||||
assert set(get_args(shaped2)) == {
|
||||
Shaped[Array, "4"],
|
||||
Shaped[np.ndarray, "4"],
|
||||
Shaped[np.bool_, "4"],
|
||||
Shaped[np.number, "4"],
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user