@@ -672,37 +672,40 @@ def __repr__(self):
672672
673673
674674def can_cast (from_ , to , / , * , casting = "safe" ) -> bool :
675- """can_cast(from, to, casting="safe")
676-
677- Determines if one data type can be cast to another data type according \
675+ """
676+ Determines if one data type can be cast to another data type according
678677 to Type Promotion Rules.
679678
680- Args:
681- from_ (Union[usm_ndarray, dtype]):
682- source data type. If `from_` is an array, a device-specific type
683- promotion rules apply.
684- to (dtype):
685- target data type
686- casting (Optional[str]):
687- controls what kind of data casting may occur.
688-
689- * "no" means data types should not be cast at all.
690- * "safe" means only casts that preserve values are allowed.
691- * "same_kind" means only safe casts and casts within a kind,
692- like `float64` to `float32`, are allowed.
693- * "unsafe" means any data conversion can be done.
694-
695- Default: `"safe"`.
696-
697- Returns:
698- bool:
699- Gives `True` if cast can occur according to the casting rule.
679+ Parameters
680+ ----------
681+ from_ : {usm_ndarray, dtype}
682+ Source data type. If `from_` is an array, device-specific type
683+ promotion rules apply.
684+ to : dtype
685+ Target data type.
686+ casting : str, optional
687+ Controls what kind of data casting may occur.
688+
689+ * "no" means data types should not be cast at all.
690+ * "safe" means only casts that preserve values are allowed.
691+ * "same_kind" means only safe casts and casts within a kind,
692+ like `float64` to `float32`, are allowed.
693+ * "unsafe" means any data conversion can be done.
694+
695+ Default: ``"safe"``.
696+
697+ Returns
698+ -------
699+ out : bool
700+ Gives `True` if cast can occur according to the casting rule.
700701
701702 Device-specific type promotion rules take into account which data type are
702703 and are not supported by a specific device.
704+
703705 """
706+
704707 if isinstance (to , dpt .usm_ndarray ):
705- raise TypeError (f"Expected `dpt .dtype` type, got { type (to )} ." )
708+ raise TypeError (f"Expected `dpnp.tensor .dtype` type, got { type (to )} ." )
706709
707710 dtype_to = dpt .dtype (to )
708711 _supported_dtype ([dtype_to ])
@@ -725,20 +728,22 @@ def can_cast(from_, to, /, *, casting="safe") -> bool:
725728
726729def result_type (* arrays_and_dtypes ):
727730 """
728- result_type(*arrays_and_dtypes)
731+ Returns the dtype that results from applying the Type Promotion Rules to
732+ the arguments.
729733
730- Returns the dtype that results from applying the Type Promotion Rules to \
731- the arguments.
734+ Parameters
735+ ----------
736+ arrays_and_dtypes : {usm_ndarray, dtype}
737+ An arbitrary length sequence of usm_ndarray objects or dtypes.
732738
733- Args:
734- arrays_and_dtypes (Union[usm_ndarray, dtype]):
735- An arbitrary length sequence of usm_ndarray objects or dtypes.
739+ Returns
740+ -------
741+ out : dtype
742+ The dtype resulting from an operation involving the
743+ input arrays and dtypes.
736744
737- Returns:
738- dtype:
739- The dtype resulting from an operation involving the
740- input arrays and dtypes.
741745 """
746+
742747 dtypes = []
743748 devices = []
744749 weak_dtypes = []
@@ -807,66 +812,69 @@ def result_type(*arrays_and_dtypes):
807812
808813
809814def iinfo (dtype , / ):
810- """iinfo(dtype)
811-
815+ """
812816 Returns machine limits for integer data types.
813817
814- Args:
815- dtype (dtype, usm_ndarray):
816- integer dtype or
817- an array with integer dtype.
818-
819- Returns:
820- iinfo_object:
821- An object with the following attributes:
822-
823- * bits: int
824- number of bits occupied by the data type
825- * max: int
826- largest representable number.
827- * min: int
828- smallest representable number.
829- * dtype: dtype
830- integer data type.
818+ Parameters
819+ ----------
820+ dtype : {dtype, usm_ndarray}
821+ Integer dtype or an array with integer dtype.
822+
823+ Returns
824+ -------
825+ out : iinfo_object
826+ An object with the following attributes:
827+
828+ * bits: int
829+ number of bits occupied by the data type
830+ * max: int
831+ largest representable number.
832+ * min: int
833+ smallest representable number.
834+ * dtype: dtype
835+ integer data type.
836+
831837 """
838+
832839 if isinstance (dtype , dpt .usm_ndarray ):
833840 dtype = dtype .dtype
834841 _supported_dtype ([dpt .dtype (dtype )])
835842 return np .iinfo (dtype )
836843
837844
838845def finfo (dtype , / ):
839- """finfo(type)
840-
846+ """
841847 Returns machine limits for floating-point data types.
842848
843- Args:
844- dtype (dtype, usm_ndarray): floating-point dtype or
845- an array with floating point data type.
846- If complex, the information is about its component
847- data type.
848-
849- Returns:
850- finfo_object:
851- an object have the following attributes:
852-
853- * bits: int
854- number of bits occupied by dtype.
855- * eps: float
856- difference between 1.0 and the next smallest representable
857- real-valued floating-point number larger than 1.0 according
858- to the IEEE-754 standard.
859- * max: float
860- largest representable real-valued number.
861- * min: float
862- smallest representable real-valued number.
863- * smallest_normal: float
864- smallest positive real-valued floating-point number with
865- full precision.
866- * dtype: dtype
867- real-valued floating-point data type.
849+ Parameters
850+ ----------
851+ dtype : {dtype, usm_ndarray}
852+ Floating-point dtype or an array with floating point data type.
853+ If complex, the information is about its component data type.
854+
855+ Returns
856+ -------
857+ out : finfo_object
858+ An object with the following attributes:
859+
860+ * bits: int
861+ number of bits occupied by dtype.
862+ * eps: float
863+ difference between 1.0 and the next smallest representable
864+ real-valued floating-point number larger than 1.0 according
865+ to the IEEE-754 standard.
866+ * max: float
867+ largest representable real-valued number.
868+ * min: float
869+ smallest representable real-valued number.
870+ * smallest_normal: float
871+ smallest positive real-valued floating-point number with
872+ full precision.
873+ * dtype: dtype
874+ real-valued floating-point data type.
868875
869876 """
877+
870878 if isinstance (dtype , dpt .usm_ndarray ):
871879 dtype = dtype .dtype
872880 _supported_dtype ([dpt .dtype (dtype )])
@@ -876,23 +884,37 @@ def finfo(dtype, /):
876884def _supported_dtype (dtypes ):
877885 for dtype in dtypes :
878886 if dtype .char not in "?bBhHiIlLqQefdFD" :
879- raise ValueError (f"Dpctl doesn't support dtype { dtype } ." )
887+ raise ValueError (f"dpnp.tensor doesn't support dtype { dtype } ." )
880888 return True
881889
882890
883891def isdtype (dtype , kind ):
884- """isdtype(dtype, kind)
885-
892+ """
886893 Returns a boolean indicating whether a provided `dtype` is
887894 of a specified data type `kind`.
888895
889896 See [array API](array_api) for more information.
890897
891898 [array_api]: https://data-apis.org/array-api/latest/
899+
900+ Parameters
901+ ----------
902+ dtype : dtype
903+ Data type to test.
904+ kind : {dtype, str, tuple}
905+ Data type kind.
906+
907+ Returns
908+ -------
909+ out : bool
910+ Whether the provided `dtype` is of the specified data type `kind`.
911+
892912 """
893913
894914 if not isinstance (dtype , np .dtype ):
895- raise TypeError (f"Expected instance of `dpt.dtype`, got { dtype } " )
915+ raise TypeError (
916+ f"Expected instance of `dpnp.tensor.dtype`, got { dtype } "
917+ )
896918
897919 if isinstance (kind , np .dtype ):
898920 return dtype == kind
0 commit comments