|
18 | 18 |
|
19 | 19 | from .ir import Operation, Builder |
20 | 20 | from .type import TileTy, LooselyTypedScalar |
21 | | -from .typing_support import typeof_pyval |
| 21 | +from .typing_support import dtype_of_constant_scalar |
22 | 22 | from .._datatype import DType, _DTypePromotionImpl, NumericDTypeCategory, PointerInfo |
23 | 23 |
|
24 | 24 |
|
@@ -206,7 +206,7 @@ def memory_order_has_release(memory_order: MemoryOrder): |
206 | 206 |
|
207 | 207 | def get_dtype(ty: TileTy | LooselyTypedScalar) -> datatype.DType: |
208 | 208 | if isinstance(ty, LooselyTypedScalar): |
209 | | - ty = typeof_pyval(ty.value) |
| 209 | + return dtype_of_constant_scalar(ty.value) |
210 | 210 | assert isinstance(ty, TileTy) |
211 | 211 | return ty.dtype |
212 | 212 |
|
@@ -241,9 +241,7 @@ class CompareOrdering(Enum): |
241 | 241 | def _promote_dtype_and_loosely_typed_constant(dtype: DType, |
242 | 242 | loose_const: Any, |
243 | 243 | force_float: bool) -> DType: |
244 | | - loose_ty = typeof_pyval(loose_const) |
245 | | - assert isinstance(loose_ty, TileTy) and loose_ty.ndim == 0 |
246 | | - loose_dtype = loose_ty.dtype |
| 244 | + loose_dtype = dtype_of_constant_scalar(loose_const) |
247 | 245 |
|
248 | 246 | cat = datatype.numeric_dtype_category(dtype) |
249 | 247 | if cat == NumericDTypeCategory.RestrictedFloat: |
@@ -272,11 +270,9 @@ def promote_dtypes(t1: DType | LooselyTypedScalar, |
272 | 270 | force_float: bool = False) -> DType: |
273 | 271 | match t1, t2: |
274 | 272 | case LooselyTypedScalar(val1), LooselyTypedScalar(val2): |
275 | | - type1 = typeof_pyval(val1) |
276 | | - assert isinstance(type1, TileTy) |
277 | | - type2 = typeof_pyval(val2) |
278 | | - assert isinstance(type2, TileTy) |
279 | | - return _DTypePromotionImpl.promote_dtypes(type1.dtype, type2.dtype, force_float) |
| 273 | + dtype1 = dtype_of_constant_scalar(val1) |
| 274 | + dtype2 = dtype_of_constant_scalar(val2) |
| 275 | + return _DTypePromotionImpl.promote_dtypes(dtype1, dtype2, force_float) |
280 | 276 | case LooselyTypedScalar(val), dtype: |
281 | 277 | return _promote_dtype_and_loosely_typed_constant(dtype, val, force_float) |
282 | 278 | case dtype, LooselyTypedScalar(val): |
@@ -329,8 +325,8 @@ def check_implicit_cast(src_ty: TileTy | LooselyTypedScalar, target_dtype: DType |
329 | 325 | raise TileValueError(f"cannot implicitly cast {src_ty.value}" |
330 | 326 | f" to a non-numeric dtype {target_dtype}") |
331 | 327 |
|
332 | | - cocnrete_ty = typeof_pyval(src_ty.value) |
333 | | - src_cat = datatype.numeric_dtype_category(cocnrete_ty.dtype) |
| 328 | + concrete_dtype = dtype_of_constant_scalar(src_ty.value) |
| 329 | + src_cat = datatype.numeric_dtype_category(concrete_dtype) |
334 | 330 | dst_cat = datatype.numeric_dtype_category(target_dtype) |
335 | 331 | if dst_cat == NumericDTypeCategory.Boolean: |
336 | 332 | if src_cat not in (NumericDTypeCategory.Boolean, NumericDTypeCategory.Integral) \ |
|
0 commit comments