From 230c9a907fa1afa7a74b3bf877fe4d8eec5115ae Mon Sep 17 00:00:00 2001 From: Florian Deconinck Date: Fri, 14 Feb 2025 11:29:43 -0500 Subject: [PATCH 1/2] Fix the type hint of Float, Int --- ndsl/dsl/typing.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ndsl/dsl/typing.py b/ndsl/dsl/typing.py index 53c910dc..222b753a 100644 --- a/ndsl/dsl/typing.py +++ b/ndsl/dsl/typing.py @@ -1,5 +1,5 @@ import os -from typing import Tuple, Union, cast +from typing import Any, Tuple, Union, cast import gt4py.cartesian.gtscript as gtscript import numpy as np @@ -40,7 +40,9 @@ def get_precision() -> int: NDSL_64BIT_INT_TYPE = np.int64 -def global_set_precision() -> type: +def global_set_precision() -> Tuple[ + type[np.floating[Any]], type[np.signedinteger[Any]] +]: """Set the global precision for all references of Float and Int in the codebase. Defaults to 64 bit.""" global Float, Int From ba0b47a7a700ce0dc72f7e127b4a803926c248fc Mon Sep 17 00:00:00 2001 From: Florian Deconinck Date: Fri, 14 Feb 2025 11:38:54 -0500 Subject: [PATCH 2/2] Attempt using TypeAlias --- ndsl/dsl/typing.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/ndsl/dsl/typing.py b/ndsl/dsl/typing.py index 222b753a..1cae1063 100644 --- a/ndsl/dsl/typing.py +++ b/ndsl/dsl/typing.py @@ -1,5 +1,5 @@ import os -from typing import Any, Tuple, Union, cast +from typing import Tuple, TypeAlias, Union, cast import gt4py.cartesian.gtscript as gtscript import numpy as np @@ -34,15 +34,13 @@ def get_precision() -> int: # We redefine the type as a way to distinguish # the model definition of a float to other usage of the # common numpy type in the rest of the code. -NDSL_32BIT_FLOAT_TYPE = np.float32 -NDSL_64BIT_FLOAT_TYPE = np.float64 -NDSL_32BIT_INT_TYPE = np.int32 -NDSL_64BIT_INT_TYPE = np.int64 +NDSL_32BIT_FLOAT_TYPE: TypeAlias = np.float32 +NDSL_64BIT_FLOAT_TYPE: TypeAlias = np.float64 +NDSL_32BIT_INT_TYPE: TypeAlias = np.int32 +NDSL_64BIT_INT_TYPE: TypeAlias = np.int64 -def global_set_precision() -> Tuple[ - type[np.floating[Any]], type[np.signedinteger[Any]] -]: +def global_set_precision() -> Tuple[TypeAlias, TypeAlias]: """Set the global precision for all references of Float and Int in the codebase. Defaults to 64 bit.""" global Float, Int