dpnp.can_cast
- dpnp.can_cast(from_, to, casting='safe')[source]
Returns
True
if cast between data types can occur according to the casting rule.For full documentation refer to
numpy.can_cast
.- Parameters:
- Returns:
out --
True
if cast can occur according to the casting rule,False
otherwise.- Return type:
See also
dpnp.result_type
Returns the type that results from applying the NumPy type promotion rules to the arguments.
Examples
Basic examples
>>> import dpnp as np >>> np.can_cast(np.int32, np.int64) True >>> np.can_cast(np.float64, complex) True >>> np.can_cast(complex, float) False
>>> np.can_cast('i8', 'f8') True >>> np.can_cast('i8', 'f4') False
Array scalar checks the value, array does not
>>> np.can_cast(np.array(1000.0), np.float32) True >>> np.can_cast(np.array([1000.0]), np.float32) False
Using the casting rules
>>> np.can_cast('i8', 'i8', 'no') True >>> np.can_cast('<i8', '>i8', 'no') False
>>> np.can_cast('<i8', '>i8', 'equiv') True >>> np.can_cast('<i4', '>i8', 'equiv') False
>>> np.can_cast('<i4', '>i8', 'safe') True >>> np.can_cast('<i8', '>i4', 'safe') False
>>> np.can_cast('<i8', '>i4', 'same_kind') True >>> np.can_cast('<i8', '>u4', 'same_kind') False
>>> np.can_cast('<i8', '>u4', 'unsafe') True