11from typing import Final
22
33from ._dtypes import (
4- DType , float32 , float64 , complex64 , complex128 , int64 ,
4+ DType , float32 , float64 , complex64 , complex128 , int64 , uint64 , int32 ,
55 _all_dtypes , _boolean_dtypes , _signed_integer_dtypes ,
66 _unsigned_integer_dtypes , _integer_dtypes , _real_floating_dtypes ,
77 _complex_floating_dtypes , _numeric_dtypes
88)
99
10- _ALL_DEVICE_NAMES = ("CPU_DEVICE" , "device1" , "device2" , "no_float64" )
10+ _ALL_DEVICE_NAMES = ("CPU_DEVICE" , "device1" , "device2" , "no_float64" , "no_x64" )
1111
1212class Device :
1313 _device : Final [str ]
@@ -32,8 +32,11 @@ def __hash__(self) -> int:
3232
3333CPU_DEVICE = Device ()
3434NO_FLOAT64_DEVICE = Device ("no_float64" )
35+ NO_X64_DEVICE = Device ("no_x64" )
3536
36- ALL_DEVICES = (CPU_DEVICE , Device ("device1" ), Device ("device2" ), NO_FLOAT64_DEVICE )
37+ ALL_DEVICES = (
38+ CPU_DEVICE , Device ("device1" ), Device ("device2" ), NO_FLOAT64_DEVICE , NO_X64_DEVICE
39+ )
3740
3841
3942def check_device (device : Device | None ) -> None :
@@ -55,6 +58,14 @@ def get_default_dtypes(device: Device | None = None) -> dict[str, DType]:
5558 "integral" : int64 ,
5659 "indexing" : int64 ,
5760 }
61+ elif device == NO_X64_DEVICE :
62+ # mimic JAX default: no float64, no int64
63+ return {
64+ "real floating" : float32 ,
65+ "complex floating" : complex64 ,
66+ "integral" : int32 ,
67+ "indexing" : int32 ,
68+ }
5869 elif device == Device ('device2' ):
5970 # mimic a torch CPU device: support float64 but default to float32
6071 return {
@@ -77,6 +88,9 @@ def device_supports_dtype(device: Device | None, dtype: DType |None) -> bool:
7788 # Device("no_float64") supports all dtypes except float64 and complex128
7889 if device == NO_FLOAT64_DEVICE :
7990 return dtype not in (float64 , complex128 )
91+ if device == NO_X64_DEVICE :
92+ # "no_x64" only supports 32-bit ints and floats
93+ return dtype not in (float64 , complex128 , int64 , uint64 )
8094
8195 # All other devices support all dtypes
8296 return True
0 commit comments