You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following example raises a ValueError in dpctl while it works fine in NumPy.
importdpctl.tensorasdpt, numpydtype=numpy.dtype(numpy.float64)
scalar=dtype.type(3)
numpy.result_type(scalar, scalar)
# dtype('float64')>>>dpt.result_type(scalar, scalar)
# File ~/micromamba/envs/dpnp_2024/lib/python3.11/site-packages/dpctl/tensor/_type_utils.py:785, in result_type(*arrays_and_dtypes)# 783 res_dt = _to_device_supported_dtype_impl(res_dt, has_fp16, has_fp64)# 784 else:#--> 785 res_dt = np.result_type(*dtypes)# 786 if weak_dtypes:# 787 weak_dt_obj = [wdt.get() for wdt in weak_dtypes]#ValueError: at least one array or dtype is required
I think the real issue is that dpt.result_type does not raise if none of the arguments is an array. I intend to fix that.
The discrepancy you found with np.float32 and np.float64 comes from np.dtype(np.float64).type being Python native built-in type float, whereas np.dtype(np.float32).type is a custom scalar type np.float32.
dpt.result_type treats Python scalars bool, int, float and complex as weak types as per NEP-0050, but treats other types as possible inputs to dpt.dtype constructor.
Activity
oleksandr-pavlyk commentedon Oct 22, 2024
Don't you think this is as designed?
dpctlcan not combine two scalars, and so it is reasonable forresult_typeto raise for such inputs as well.vtavana commentedon Oct 22, 2024
It does not raise an error for all the cases, for instance, it works fine with
float32.oleksandr-pavlyk commentedon Oct 22, 2024
I think the real issue is that
dpt.result_typedoes not raise if none of the arguments is an array. I intend to fix that.The discrepancy you found with
np.float32andnp.float64comes fromnp.dtype(np.float64).typebeing Python native built-in typefloat, whereasnp.dtype(np.float32).typeis a custom scalar typenp.float32.dpt.result_typetreats Python scalarsbool,int,floatandcomplexas weak types as per NEP-0050, but treats other types as possible inputs todpt.dtypeconstructor.oleksandr-pavlyk commentedon Oct 23, 2024
Ok, the
result_typeimplementation has an issue when all inputs of weak dtypes, i.e. Python scalarsMerge pull request #1877 from IntelPython/bugfix/gh-1874-result_type