dpctl raises an exception for either any edge as NaN or both edges as NaN passed to dpctl.tensor.clip function.
While NumPy accept any of below combinations without an issue:
dpctl.__version__# Out: '0.15.1dev2+28.gebf94b04cf'# create an arraya=dpt.arange(7)
# clip with any edge as NaN, where another is Nonedpt.clip(a, numpy.nan, None)
---------------------------------------------------------------------------TypeErrorTraceback (mostrecentcalllast)
CellIn[3], line1---->1dpt.clip(a, numpy.nan, None)
File~/miniconda3/envs/dpnp_dev/lib/python3.9/site-packages/dpctl/tensor/_clip.py:433, inclip(x, min, max, out, order)
429raiseValueError(
430"only one of `min` and `max` is permitted to be `None`"431 )
432elifmaxisNone:
-->433return_clip_none(x, min, out, order, tei._maximum)
434elifminisNone:
435return_clip_none(x, max, out, order, tei._minimum)
File~/miniconda3/envs/dpnp_dev/lib/python3.9/site-packages/dpctl/tensor/_clip.py:249, in_clip_none(x, val, out, order, _binary_fn)
247_fp16=sycl_dev.has_aspect_fp16248_fp64=sycl_dev.has_aspect_fp64-->249ifnot_can_cast(val_dtype, res_dt, _fp16, _fp64):
250raiseValueError(
251f"function 'clip' does not support input types "252f"({x_dtype}, {val_dtype}), "253"and the inputs could not be safely coerced to any "254"supported types according to the casting rule ''safe''."255 )
257orig_out=outFile~/miniconda3/envs/dpnp_dev/lib/python3.9/site-packages/dpctl/tensor/_type_utils.py:103, in_can_cast(from_, to_, _fp16, _fp64)
98def_can_cast(from_: dpt.dtype, to_: dpt.dtype, _fp16: bool, _fp64: bool):
99""" 100 Can `from_` be cast to `to_` safely on a device with 101 fp16 and fp64 aspects as given? 102 """-->103can_cast_v=dpt.can_cast(from_, to_) # ask NumPy104if_fp16and_fp64:
105returncan_cast_vFile~/miniconda3/envs/dpnp_dev/lib/python3.9/site-packages/dpctl/tensor/_manipulation_functions.py:706, incan_cast(from_, to, casting)
701raiseTypeError("Expected dtype type.")
703dtype_to=dpt.dtype(to)
705dtype_from= (
-->706from_.dtypeifisinstance(from_, dpt.usm_ndarray) elsedpt.dtype(from_)
707 )
709_supported_dtype([dtype_from, dtype_to])
711returnnp.can_cast(dtype_from, dtype_to, casting)
TypeError: Tuplemusthavesize2, buthassize1# clip with both edges as NaNsdpt.clip(a, numpy.nan, numpy.nan)
---------------------------------------------------------------------------ValueErrorTraceback (mostrecentcalllast)
CellIn[10], line1---->1dpt.clip(a, numpy.nan, numpy.nan)
File~/miniconda3/envs/dpnp_dev/lib/python3.9/site-packages/dpctl/tensor/_clip.py:531, inclip(x, min, max, out, order)
523buf1_dt, buf2_dt, res_dt=_check_clip_dtypes(
524x_dtype,
525min_dtype,
526max_dtype,
527sycl_dev,
528 )
530ifres_dtisNone:
-->531raiseValueError(
532f"function '{clip}' does not support input types "533f"({x_dtype}, {min_dtype}, {max_dtype}), "534"and the inputs could not be safely coerced to any "535"supported types according to the casting rule ''safe''."536 )
538orig_out=out539ifoutisnotNone:
ValueError: function'<function clip at 0x7fade5dad310>'doesnotsupportinputtypes (int64, float32, float32), andtheinputscouldnotbesafelycoercedtoanysupportedtypesaccordingtothecastingrule''safe''.
# clip with any edge as NaN, where another is a numberdpt.clip(a, -2, numpy.nan)
---------------------------------------------------------------------------ValueErrorTraceback (mostrecentcalllast)
CellIn[12], line1---->1dpt.clip(a, -2, numpy.nan)
File~/miniconda3/envs/dpnp_dev/lib/python3.9/site-packages/dpctl/tensor/_clip.py:531, inclip(x, min, max, out, order)
523buf1_dt, buf2_dt, res_dt=_check_clip_dtypes(
524x_dtype,
525min_dtype,
526max_dtype,
527sycl_dev,
528 )
530ifres_dtisNone:
-->531raiseValueError(
532f"function '{clip}' does not support input types "533f"({x_dtype}, {min_dtype}, {max_dtype}), "534"and the inputs could not be safely coerced to any "535"supported types according to the casting rule ''safe''."536 )
538orig_out=out539ifoutisnotNone:
ValueError: function'<function clip at 0x7fade5dad310>'doesnotsupportinputtypes (int64, int64, float32), andtheinputscouldnotbesafelycoercedtoanysupportedtypesaccordingtothecastingrule''safe''.
dpctl raises an exception for either any edge as NaN or both edges as NaN passed to
dpctl.tensor.clipfunction.While NumPy accept any of below combinations without an issue:
The below is example of errors raised by dpctl: