From b07e812dfad2348b609b47a7138117e4964857ac Mon Sep 17 00:00:00 2001 From: Mr-Array22 Date: Sat, 10 Feb 2024 17:53:42 +0200 Subject: [PATCH 1/4] reformat dtype_method --- ivy/functional/ivy/data_type.py | 171 ++++++++++++++++++-------------- 1 file changed, 98 insertions(+), 73 deletions(-) diff --git a/ivy/functional/ivy/data_type.py b/ivy/functional/ivy/data_type.py index 4b074b58a3795..32aad0baf4014 100644 --- a/ivy/functional/ivy/data_type.py +++ b/ivy/functional/ivy/data_type.py @@ -298,8 +298,8 @@ def astype( copy: bool = True, out: Optional[ivy.Array] = None, ) -> ivy.Array: - """Copy an array to a specified data type irrespective of :ref:`type- - promotion` rules. + """ + Copy an array to a specified data type irrespective of :ref:`type- promotion` rules. .. note:: Casting floating-point ``NaN`` and ``infinity`` values to integral data types @@ -398,7 +398,8 @@ def astype( @handle_array_function @handle_device def broadcast_arrays(*arrays: Union[ivy.Array, ivy.NativeArray]) -> List[ivy.Array]: - """Broadcasts one or more arrays against one another. + """ + Broadcasts one or more arrays against one another. Parameters ---------- @@ -485,7 +486,8 @@ def broadcast_to( *, out: Optional[ivy.Array] = None, ) -> ivy.Array: - """Broadcasts an array to a specified shape. + """ + Broadcasts an array to a specified shape. Parameters ---------- @@ -553,8 +555,9 @@ def can_cast( to: ivy.Dtype, /, ) -> bool: - """Determine if one data type can be cast to another data type according to - :ref:`type- promotion` rules. + """ + Determine if one data type can be cast to another data type according to :ref:`type- + promotion` rules. Parameters ---------- @@ -627,7 +630,8 @@ def finfo( type: Union[ivy.Dtype, str, ivy.Array, ivy.NativeArray], /, ) -> Finfo: - """Machine limits for floating-point data types. + """ + Machine limits for floating-point data types. Parameters ---------- @@ -714,7 +718,8 @@ def iinfo( type: Union[ivy.Dtype, str, ivy.Array, ivy.NativeArray], /, ) -> Iinfo: - """Machine limits for integer data types. + """ + Machine limits for integer data types. Parameters ---------- @@ -790,8 +795,9 @@ def iinfo( def result_type( *arrays_and_dtypes: Union[ivy.Array, ivy.NativeArray, ivy.Dtype] ) -> ivy.Dtype: - """Return the dtype that results from applying the type promotion rules - (see :ref:`type-promotion`) to the arguments. + """ + Return the dtype that results from applying the type promotion rules (see + :ref:`type-promotion`) to the arguments. .. note:: If provided mixed dtypes (e.g., integer and floating-point), the returned dtype @@ -944,7 +950,8 @@ def __exit__(self, exc_type, exc_val, exc_tb): @handle_exceptions def dtype_bits(dtype_in: Union[ivy.Dtype, ivy.NativeDtype, str], /) -> int: - """Get the number of bits used for representing the input data type. + """ + Get the number of bits used for representing the input data type. Parameters ---------- @@ -979,7 +986,8 @@ def dtype_bits(dtype_in: Union[ivy.Dtype, ivy.NativeDtype, str], /) -> int: @handle_exceptions def is_hashable_dtype(dtype_in: Union[ivy.Dtype, ivy.NativeDtype], /) -> bool: - """Check if the given data type is hashable or not. + """ + Check if the given data type is hashable or not. Parameters ---------- @@ -1004,7 +1012,8 @@ def is_hashable_dtype(dtype_in: Union[ivy.Dtype, ivy.NativeDtype], /) -> bool: @handle_exceptions def as_ivy_dtype(dtype_in: Union[ivy.Dtype, str], /) -> ivy.Dtype: - """Convert native data type to string representation. + """ + Convert native data type to string representation. Parameters ---------- @@ -1021,7 +1030,8 @@ def as_ivy_dtype(dtype_in: Union[ivy.Dtype, str], /) -> ivy.Dtype: @handle_exceptions def as_native_dtype(dtype_in: Union[ivy.Dtype, ivy.NativeDtype], /) -> ivy.NativeDtype: - """Convert data type string representation to native data type. + """ + Convert data type string representation to native data type. Parameters ---------- @@ -1057,7 +1067,8 @@ def _check_complex128(input) -> bool: @handle_exceptions def closest_valid_dtype(type: Union[ivy.Dtype, str, None], /) -> Union[ivy.Dtype, str]: - """Determine the closest valid datatype to the datatype passed as input. + """ + Determine the closest valid datatype to the datatype passed as input. Parameters ---------- @@ -1194,7 +1205,8 @@ def default_float_dtype( def infer_default_dtype( dtype: Union[ivy.Dtype, ivy.NativeDtype, str], as_native: bool = False ) -> Union[ivy.Dtype, ivy.NativeDtype]: - """Summary. + """ + Summary. Parameters ---------- @@ -1650,7 +1662,8 @@ def default_complex_dtype( def dtype( x: Union[ivy.Array, ivy.NativeArray], *, as_native: bool = False ) -> Union[ivy.Dtype, ivy.NativeDtype]: - """Get the data type for input array x. + """ + Get the data type for input array x. Parameters ---------- @@ -1666,27 +1679,20 @@ def dtype( Examples -------- - With :class:`ivy.Array` inputs: - - >>> x1 = ivy.array([1.0, 2.0, 3.5, 4.5, 5, 6]) - >>> y = ivy.dtype(x1) - >>> print(y) - float32 - - With :class:`ivy.NativeArray` inputs: - - >>> x1 = ivy.native_array([1, 0, 1, -1, 0]) - >>> y = ivy.dtype(x1) - >>> print(y) - int32 - - With :class:`ivy.Container` inputs: - - >>> x = ivy.Container(a=ivy.native_array([1.0, 2.0, -1.0, 4.0, 1.0]), - ... b=ivy.native_array([1, 0, 0, 0, 1])) - >>> y = ivy.dtype(x.a) - >>> print(y) - float32 + With :class:`ivy.Array` input: + >>> x = ivy.array([1, 2, 3], dtype="int32") + >>> ivy.dtype(x) + 'int32' + With :class:`ivy.NativeArray` input: + >>> x = ivy.native_array([1, 2, 3], dtype="int32") + >>> ivy.dtype(x) + 'int32' + With :class:`ivy.Container` input: + >>> c = ivy.Container(x=ivy.array([1, 2, 3], dtype="int32")) + >>> ivy.dtype(c) + { + x: 'int32' + } """ return current_backend(x).dtype(x, as_native=as_native) @@ -1694,10 +1700,10 @@ def dtype( @handle_exceptions @handle_nestable def function_supported_dtypes(fn: Callable, recurse: bool = True) -> Union[Tuple, dict]: - """Return the supported data types of the current backend's function. The - function returns a dict containing the supported dtypes for the - compositional and primary implementations in case of partial mixed - functions. + """ + Return the supported data types of the current backend's function. The function + returns a dict containing the supported dtypes for the compositional and primary + implementations in case of partial mixed functions. Parameters ---------- @@ -1745,10 +1751,10 @@ def function_supported_dtypes(fn: Callable, recurse: bool = True) -> Union[Tuple def function_unsupported_dtypes( fn: Callable, recurse: bool = True ) -> Union[Tuple, dict]: - """Return the unsupported data types of the current backend's function. The - function returns a dict containing the unsupported dtypes for the - compositional and primary implementations in case of partial mixed - functions. + """ + Return the unsupported data types of the current backend's function. The function + returns a dict containing the unsupported dtypes for the compositional and primary + implementations in case of partial mixed functions. Parameters ---------- @@ -1794,8 +1800,8 @@ def function_unsupported_dtypes( @handle_exceptions def invalid_dtype(dtype_in: Union[ivy.Dtype, ivy.NativeDtype, str, None], /) -> bool: - """Determine whether the provided data type is not support by the current - framework. + """ + Determine whether the provided data type is not support by the current framework. Parameters ---------- @@ -1833,7 +1839,8 @@ def is_bool_dtype( dtype_in: Union[ivy.Dtype, str, ivy.Array, ivy.NativeArray, Number], /, ) -> bool: - """Determine whether the input data type is a bool data type. + """ + Determine whether the input data type is a bool data type. Parameters ---------- @@ -1872,7 +1879,8 @@ def is_int_dtype( dtype_in: Union[ivy.Dtype, str, ivy.Array, ivy.NativeArray, Number], /, ) -> bool: - """Determine whether the input data type is an int data type. + """ + Determine whether the input data type is an int data type. Parameters ---------- @@ -1947,7 +1955,8 @@ def nested_fun(x): @handle_exceptions def check_float(x: Any) -> bool: - """Check if the input is a float or a float-like object. + """ + Check if the input is a float or a float-like object. Parameters ---------- @@ -1969,7 +1978,8 @@ def is_float_dtype( dtype_in: Union[ivy.Dtype, str, ivy.Array, ivy.NativeArray, Number], /, ) -> bool: - """Determine whether the input data type is a float dtype. + """ + Determine whether the input data type is a float dtype. Parameters ---------- @@ -2017,7 +2027,8 @@ def is_uint_dtype( dtype_in: Union[ivy.Dtype, str, ivy.Array, ivy.NativeArray, Number], /, ) -> bool: - """Determine whether the input data type is a uint dtype. + """ + Determine whether the input data type is a uint dtype. Parameters ---------- @@ -2064,7 +2075,8 @@ def is_complex_dtype( dtype_in: Union[ivy.Dtype, str, ivy.Array, ivy.NativeArray, Number], /, ) -> bool: - """Determine whether the input data type is a complex dtype. + """ + Determine whether the input data type is a complex dtype. Parameters ---------- @@ -2112,8 +2124,8 @@ def promote_types( *, array_api_promotion: bool = False, ) -> ivy.Dtype: - """Promote the datatypes type1 and type2, returning the data type they - promote to. + """ + Promote the datatypes type1 and type2, returning the data type they promote to. Parameters ---------- @@ -2147,7 +2159,8 @@ def _promote(query): @handle_exceptions def set_default_dtype(dtype: Union[ivy.Dtype, ivy.NativeDtype, str], /): - """Set the datatype `dtype` as default data type. + """ + Set the datatype `dtype` as default data type. Parameters ---------- @@ -2182,7 +2195,8 @@ def set_default_dtype(dtype: Union[ivy.Dtype, ivy.NativeDtype, str], /): @handle_exceptions def set_default_float_dtype(float_dtype: Union[ivy.Dtype, str], /): - """Set the 'float_dtype' as the default data type. + """ + Set the 'float_dtype' as the default data type. Parameters ---------- @@ -2209,7 +2223,8 @@ def set_default_float_dtype(float_dtype: Union[ivy.Dtype, str], /): @handle_exceptions def set_default_int_dtype(int_dtype: Union[ivy.Dtype, str], /): - """Set the 'int_dtype' as the default data type. + """ + Set the 'int_dtype' as the default data type. Parameters ---------- @@ -2236,7 +2251,8 @@ def set_default_int_dtype(int_dtype: Union[ivy.Dtype, str], /): @handle_exceptions def set_default_uint_dtype(uint_dtype: Union[ivy.Dtype, str], /): - """Set the uint dtype to be default. + """ + Set the uint dtype to be default. Parameters ---------- @@ -2261,7 +2277,8 @@ def set_default_uint_dtype(uint_dtype: Union[ivy.Dtype, str], /): @handle_exceptions def set_default_complex_dtype(complex_dtype: Union[ivy.Dtype, str], /): - """Set the 'complex_dtype' as the default data type. + """ + Set the 'complex_dtype' as the default data type. Parameters ---------- @@ -2292,8 +2309,9 @@ def type_promote_arrays( x2: Union[ivy.Array, ivy.NativeArray], /, ) -> Tuple: - """Type promote the input arrays, returning new arrays with the shared - correct data type. + """ + Type promote the input arrays, returning new arrays with the shared correct data + type. Parameters ---------- @@ -2313,7 +2331,8 @@ def type_promote_arrays( @handle_exceptions def unset_default_dtype(): - """Reset the current default dtype to the previous state. + """ + Reset the current default dtype to the previous state. Examples -------- @@ -2337,7 +2356,8 @@ def unset_default_dtype(): @handle_exceptions def unset_default_float_dtype(): - """Reset the current default float dtype to the previous state. + """ + Reset the current default float dtype to the previous state. Examples -------- @@ -2357,7 +2377,8 @@ def unset_default_float_dtype(): @handle_exceptions def unset_default_int_dtype(): - """Reset the current default int dtype to the previous state. + """ + Reset the current default int dtype to the previous state. Examples -------- @@ -2376,7 +2397,8 @@ def unset_default_int_dtype(): @handle_exceptions def unset_default_uint_dtype(): - """Reset the current default uint dtype to the previous state. + """ + Reset the current default uint dtype to the previous state. Examples -------- @@ -2395,7 +2417,8 @@ def unset_default_uint_dtype(): @handle_exceptions def unset_default_complex_dtype(): - """Reset the current default complex dtype to the previous state. + """ + Reset the current default complex dtype to the previous state. Examples -------- @@ -2415,8 +2438,8 @@ def unset_default_complex_dtype(): @handle_exceptions def valid_dtype(dtype_in: Union[ivy.Dtype, ivy.NativeDtype, str, None], /) -> bool: - """Determine whether the provided data type is supported by the current - framework. + """ + Determine whether the provided data type is supported by the current framework. Parameters ---------- @@ -2455,8 +2478,9 @@ def promote_types_of_inputs( *, array_api_promotion: bool = False, ) -> Tuple[ivy.NativeArray, ivy.NativeArray]: - """Promote the dtype of the given native array inputs to a common dtype - based on type promotion rules. + """ + Promote the dtype of the given native array inputs to a common dtype based on type + promotion rules. While passing float or integer values or any other non-array input to this function, it should be noted that the return will be an @@ -2504,7 +2528,8 @@ def _get_target_dtype(scalar, arr): @handle_exceptions def is_native_dtype(dtype_in: Union[ivy.Dtype, ivy.NativeDtype], /) -> bool: - """Determine whether the input dtype is a Native dtype. + """ + Determine whether the input dtype is a Native dtype. Parameters ---------- From e211970e621a7373018574750a81ba66be9fbfeb Mon Sep 17 00:00:00 2001 From: ivy-branch Date: Sat, 10 Feb 2024 15:57:46 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=A4=96=20Lint=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ivy/functional/ivy/data_type.py | 136 ++++++++++++-------------------- 1 file changed, 52 insertions(+), 84 deletions(-) diff --git a/ivy/functional/ivy/data_type.py b/ivy/functional/ivy/data_type.py index 32aad0baf4014..1d82c3151f106 100644 --- a/ivy/functional/ivy/data_type.py +++ b/ivy/functional/ivy/data_type.py @@ -298,8 +298,8 @@ def astype( copy: bool = True, out: Optional[ivy.Array] = None, ) -> ivy.Array: - """ - Copy an array to a specified data type irrespective of :ref:`type- promotion` rules. + """Copy an array to a specified data type irrespective of :ref:`type- + promotion` rules. .. note:: Casting floating-point ``NaN`` and ``infinity`` values to integral data types @@ -398,8 +398,7 @@ def astype( @handle_array_function @handle_device def broadcast_arrays(*arrays: Union[ivy.Array, ivy.NativeArray]) -> List[ivy.Array]: - """ - Broadcasts one or more arrays against one another. + """Broadcasts one or more arrays against one another. Parameters ---------- @@ -486,8 +485,7 @@ def broadcast_to( *, out: Optional[ivy.Array] = None, ) -> ivy.Array: - """ - Broadcasts an array to a specified shape. + """Broadcasts an array to a specified shape. Parameters ---------- @@ -555,9 +553,8 @@ def can_cast( to: ivy.Dtype, /, ) -> bool: - """ - Determine if one data type can be cast to another data type according to :ref:`type- - promotion` rules. + """Determine if one data type can be cast to another data type according to + :ref:`type- promotion` rules. Parameters ---------- @@ -630,8 +627,7 @@ def finfo( type: Union[ivy.Dtype, str, ivy.Array, ivy.NativeArray], /, ) -> Finfo: - """ - Machine limits for floating-point data types. + """Machine limits for floating-point data types. Parameters ---------- @@ -718,8 +714,7 @@ def iinfo( type: Union[ivy.Dtype, str, ivy.Array, ivy.NativeArray], /, ) -> Iinfo: - """ - Machine limits for integer data types. + """Machine limits for integer data types. Parameters ---------- @@ -795,9 +790,8 @@ def iinfo( def result_type( *arrays_and_dtypes: Union[ivy.Array, ivy.NativeArray, ivy.Dtype] ) -> ivy.Dtype: - """ - Return the dtype that results from applying the type promotion rules (see - :ref:`type-promotion`) to the arguments. + """Return the dtype that results from applying the type promotion rules + (see :ref:`type-promotion`) to the arguments. .. note:: If provided mixed dtypes (e.g., integer and floating-point), the returned dtype @@ -950,8 +944,7 @@ def __exit__(self, exc_type, exc_val, exc_tb): @handle_exceptions def dtype_bits(dtype_in: Union[ivy.Dtype, ivy.NativeDtype, str], /) -> int: - """ - Get the number of bits used for representing the input data type. + """Get the number of bits used for representing the input data type. Parameters ---------- @@ -986,8 +979,7 @@ def dtype_bits(dtype_in: Union[ivy.Dtype, ivy.NativeDtype, str], /) -> int: @handle_exceptions def is_hashable_dtype(dtype_in: Union[ivy.Dtype, ivy.NativeDtype], /) -> bool: - """ - Check if the given data type is hashable or not. + """Check if the given data type is hashable or not. Parameters ---------- @@ -1012,8 +1004,7 @@ def is_hashable_dtype(dtype_in: Union[ivy.Dtype, ivy.NativeDtype], /) -> bool: @handle_exceptions def as_ivy_dtype(dtype_in: Union[ivy.Dtype, str], /) -> ivy.Dtype: - """ - Convert native data type to string representation. + """Convert native data type to string representation. Parameters ---------- @@ -1030,8 +1021,7 @@ def as_ivy_dtype(dtype_in: Union[ivy.Dtype, str], /) -> ivy.Dtype: @handle_exceptions def as_native_dtype(dtype_in: Union[ivy.Dtype, ivy.NativeDtype], /) -> ivy.NativeDtype: - """ - Convert data type string representation to native data type. + """Convert data type string representation to native data type. Parameters ---------- @@ -1067,8 +1057,7 @@ def _check_complex128(input) -> bool: @handle_exceptions def closest_valid_dtype(type: Union[ivy.Dtype, str, None], /) -> Union[ivy.Dtype, str]: - """ - Determine the closest valid datatype to the datatype passed as input. + """Determine the closest valid datatype to the datatype passed as input. Parameters ---------- @@ -1205,8 +1194,7 @@ def default_float_dtype( def infer_default_dtype( dtype: Union[ivy.Dtype, ivy.NativeDtype, str], as_native: bool = False ) -> Union[ivy.Dtype, ivy.NativeDtype]: - """ - Summary. + """Summary. Parameters ---------- @@ -1662,8 +1650,7 @@ def default_complex_dtype( def dtype( x: Union[ivy.Array, ivy.NativeArray], *, as_native: bool = False ) -> Union[ivy.Dtype, ivy.NativeDtype]: - """ - Get the data type for input array x. + """Get the data type for input array x. Parameters ---------- @@ -1700,10 +1687,10 @@ def dtype( @handle_exceptions @handle_nestable def function_supported_dtypes(fn: Callable, recurse: bool = True) -> Union[Tuple, dict]: - """ - Return the supported data types of the current backend's function. The function - returns a dict containing the supported dtypes for the compositional and primary - implementations in case of partial mixed functions. + """Return the supported data types of the current backend's function. The + function returns a dict containing the supported dtypes for the + compositional and primary implementations in case of partial mixed + functions. Parameters ---------- @@ -1751,10 +1738,10 @@ def function_supported_dtypes(fn: Callable, recurse: bool = True) -> Union[Tuple def function_unsupported_dtypes( fn: Callable, recurse: bool = True ) -> Union[Tuple, dict]: - """ - Return the unsupported data types of the current backend's function. The function - returns a dict containing the unsupported dtypes for the compositional and primary - implementations in case of partial mixed functions. + """Return the unsupported data types of the current backend's function. The + function returns a dict containing the unsupported dtypes for the + compositional and primary implementations in case of partial mixed + functions. Parameters ---------- @@ -1800,8 +1787,8 @@ def function_unsupported_dtypes( @handle_exceptions def invalid_dtype(dtype_in: Union[ivy.Dtype, ivy.NativeDtype, str, None], /) -> bool: - """ - Determine whether the provided data type is not support by the current framework. + """Determine whether the provided data type is not support by the current + framework. Parameters ---------- @@ -1839,8 +1826,7 @@ def is_bool_dtype( dtype_in: Union[ivy.Dtype, str, ivy.Array, ivy.NativeArray, Number], /, ) -> bool: - """ - Determine whether the input data type is a bool data type. + """Determine whether the input data type is a bool data type. Parameters ---------- @@ -1879,8 +1865,7 @@ def is_int_dtype( dtype_in: Union[ivy.Dtype, str, ivy.Array, ivy.NativeArray, Number], /, ) -> bool: - """ - Determine whether the input data type is an int data type. + """Determine whether the input data type is an int data type. Parameters ---------- @@ -1955,8 +1940,7 @@ def nested_fun(x): @handle_exceptions def check_float(x: Any) -> bool: - """ - Check if the input is a float or a float-like object. + """Check if the input is a float or a float-like object. Parameters ---------- @@ -1978,8 +1962,7 @@ def is_float_dtype( dtype_in: Union[ivy.Dtype, str, ivy.Array, ivy.NativeArray, Number], /, ) -> bool: - """ - Determine whether the input data type is a float dtype. + """Determine whether the input data type is a float dtype. Parameters ---------- @@ -2027,8 +2010,7 @@ def is_uint_dtype( dtype_in: Union[ivy.Dtype, str, ivy.Array, ivy.NativeArray, Number], /, ) -> bool: - """ - Determine whether the input data type is a uint dtype. + """Determine whether the input data type is a uint dtype. Parameters ---------- @@ -2075,8 +2057,7 @@ def is_complex_dtype( dtype_in: Union[ivy.Dtype, str, ivy.Array, ivy.NativeArray, Number], /, ) -> bool: - """ - Determine whether the input data type is a complex dtype. + """Determine whether the input data type is a complex dtype. Parameters ---------- @@ -2124,8 +2105,8 @@ def promote_types( *, array_api_promotion: bool = False, ) -> ivy.Dtype: - """ - Promote the datatypes type1 and type2, returning the data type they promote to. + """Promote the datatypes type1 and type2, returning the data type they + promote to. Parameters ---------- @@ -2159,8 +2140,7 @@ def _promote(query): @handle_exceptions def set_default_dtype(dtype: Union[ivy.Dtype, ivy.NativeDtype, str], /): - """ - Set the datatype `dtype` as default data type. + """Set the datatype `dtype` as default data type. Parameters ---------- @@ -2195,8 +2175,7 @@ def set_default_dtype(dtype: Union[ivy.Dtype, ivy.NativeDtype, str], /): @handle_exceptions def set_default_float_dtype(float_dtype: Union[ivy.Dtype, str], /): - """ - Set the 'float_dtype' as the default data type. + """Set the 'float_dtype' as the default data type. Parameters ---------- @@ -2223,8 +2202,7 @@ def set_default_float_dtype(float_dtype: Union[ivy.Dtype, str], /): @handle_exceptions def set_default_int_dtype(int_dtype: Union[ivy.Dtype, str], /): - """ - Set the 'int_dtype' as the default data type. + """Set the 'int_dtype' as the default data type. Parameters ---------- @@ -2251,8 +2229,7 @@ def set_default_int_dtype(int_dtype: Union[ivy.Dtype, str], /): @handle_exceptions def set_default_uint_dtype(uint_dtype: Union[ivy.Dtype, str], /): - """ - Set the uint dtype to be default. + """Set the uint dtype to be default. Parameters ---------- @@ -2277,8 +2254,7 @@ def set_default_uint_dtype(uint_dtype: Union[ivy.Dtype, str], /): @handle_exceptions def set_default_complex_dtype(complex_dtype: Union[ivy.Dtype, str], /): - """ - Set the 'complex_dtype' as the default data type. + """Set the 'complex_dtype' as the default data type. Parameters ---------- @@ -2309,9 +2285,8 @@ def type_promote_arrays( x2: Union[ivy.Array, ivy.NativeArray], /, ) -> Tuple: - """ - Type promote the input arrays, returning new arrays with the shared correct data - type. + """Type promote the input arrays, returning new arrays with the shared + correct data type. Parameters ---------- @@ -2331,8 +2306,7 @@ def type_promote_arrays( @handle_exceptions def unset_default_dtype(): - """ - Reset the current default dtype to the previous state. + """Reset the current default dtype to the previous state. Examples -------- @@ -2356,8 +2330,7 @@ def unset_default_dtype(): @handle_exceptions def unset_default_float_dtype(): - """ - Reset the current default float dtype to the previous state. + """Reset the current default float dtype to the previous state. Examples -------- @@ -2377,8 +2350,7 @@ def unset_default_float_dtype(): @handle_exceptions def unset_default_int_dtype(): - """ - Reset the current default int dtype to the previous state. + """Reset the current default int dtype to the previous state. Examples -------- @@ -2397,8 +2369,7 @@ def unset_default_int_dtype(): @handle_exceptions def unset_default_uint_dtype(): - """ - Reset the current default uint dtype to the previous state. + """Reset the current default uint dtype to the previous state. Examples -------- @@ -2417,8 +2388,7 @@ def unset_default_uint_dtype(): @handle_exceptions def unset_default_complex_dtype(): - """ - Reset the current default complex dtype to the previous state. + """Reset the current default complex dtype to the previous state. Examples -------- @@ -2438,8 +2408,8 @@ def unset_default_complex_dtype(): @handle_exceptions def valid_dtype(dtype_in: Union[ivy.Dtype, ivy.NativeDtype, str, None], /) -> bool: - """ - Determine whether the provided data type is supported by the current framework. + """Determine whether the provided data type is supported by the current + framework. Parameters ---------- @@ -2478,9 +2448,8 @@ def promote_types_of_inputs( *, array_api_promotion: bool = False, ) -> Tuple[ivy.NativeArray, ivy.NativeArray]: - """ - Promote the dtype of the given native array inputs to a common dtype based on type - promotion rules. + """Promote the dtype of the given native array inputs to a common dtype + based on type promotion rules. While passing float or integer values or any other non-array input to this function, it should be noted that the return will be an @@ -2528,8 +2497,7 @@ def _get_target_dtype(scalar, arr): @handle_exceptions def is_native_dtype(dtype_in: Union[ivy.Dtype, ivy.NativeDtype], /) -> bool: - """ - Determine whether the input dtype is a Native dtype. + """Determine whether the input dtype is a Native dtype. Parameters ---------- From e10ef89a4007a78837803766c18bb4c1d534d1bd Mon Sep 17 00:00:00 2001 From: Mr-Array22 Date: Sat, 17 Feb 2024 21:46:39 +0200 Subject: [PATCH 3/4] update unique_all function --- ivy/functional/ivy/set.py | 72 ++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/ivy/functional/ivy/set.py b/ivy/functional/ivy/set.py index 5f9e92f400918..15947937a5ede 100644 --- a/ivy/functional/ivy/set.py +++ b/ivy/functional/ivy/set.py @@ -38,10 +38,10 @@ def unique_all( Union[ivy.Array, ivy.NativeArray], Union[ivy.Array, ivy.NativeArray], ]: - """Return the unique elements of an input array ``x``, the first occurring - indices for each unique element in ``x``, the indices from the set of - unique elements that reconstruct ``x``, and the corresponding counts for - each unique element in ``x``. + """ + Return the unique elements of an input array ``x``, the first occurring indices for + each unique element in ``x``, the indices from the set of unique elements that + reconstruct ``x``, and the corresponding counts for each unique element in ``x``. .. admonition:: Data-dependent output shape :class: important @@ -117,33 +117,32 @@ def unique_all( Examples -------- - With :class:`ivy.Array` input: + With Class:`ivy.Array` input: + >>> x = ivy.array([1,2,1,3,4,1,3]) + >>> y = ivy.unique_all(x) + >>> print(y) + Results(values=ivy.array([1, 2, 3, 4]), + indices=ivy.array([0, 1, 3, 4]), + inverse_indices=ivy.array([0, 1, 0, 2, 3, 0, 2]), + counts=ivy.array([3, 1, 2, 1])) + >>> x = ivy.array([0.2,0.3,0.4,0.2,1.4,2.3,0.2]) + >>> y = ivy.unique_all(x) + >>> print(y) + Results(values=ivy.array([0.2 , 0.30000001, 0.40000001, 1.39999998, + 2.29999995]), + indices=ivy.array([0, 1, 2, 4, 5]), + inverse_indices=ivy.array([0, 1, 2, 0, 3, 4, 0]), + counts=ivy.array([3, 1, 1, 1, 1])) - >>> x = ivy.randint(0, 10, shape=(2, 2), seed=0) - >>> z = ivy.unique_all(x) - >>> print(z) - Results(values=ivy.array([1, 2, 5, 9]), - indices=ivy.array([3, 2, 1, 0]), - inverse_indices=ivy.array([[3, 2], [1, 0]]), - counts=ivy.array([1, 1, 1, 1])) - - >>> x = ivy.array([[ 2.1141, 0.8101, 0.9298, 0.8460], - ... [-1.2119, -0.3519, -0.6252, 0.4033], - ... [ 0.7443, 0.2577, -0.3707, -0.0545], - ... [-0.3238, 0.5944, 0.0775, -0.4327]]) - >>> x[range(4), range(4)] = ivy.nan #Introduce NaN values - >>> z = ivy.unique_all(x) - >>> print(z) - Results(values=ivy.array([-1.2119 , -0.62519997, -0.3238 , -0.0545 , - 0.0775 , 0.2577 , 0.40329999, 0.59439999, 0.74430001, 0.81010002, - 0.84600002, 0.92979997, nan, nan, nan, nan]), - indices=ivy.array([ 4, 6, 12, 11, 14, 9, 7, 13, 8, 1, 3, 2, 0, 5, - 10, 15]), - inverse_indices=ivy.array([[12, 9, 11, 10], - [ 0, 12, 1, 6], - [ 8, 5, 12, 3], - [ 2, 7, 4, 12]]), - counts=ivy.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])) + With :class:`ivy.Container` input: + >>> x = ivy.Container(a=ivy.array([0., 1., 3. , 2. , 1. , 0.]), + ... b=ivy.array([1, 2, 1, 3, 4, 1, 3])) + >>> y = ivy.unique_all(x) + >>> print(y) + { + a: (list[2],shape=[4]), + b: (list[2],shape=[4]) + } """ return ivy.current_backend(x).unique_all(x, axis=axis, by_value=by_value) @@ -161,8 +160,9 @@ def unique_inverse( *, axis: Optional[int] = None, ) -> Tuple[Union[ivy.Array, ivy.NativeArray], Union[ivy.Array, ivy.NativeArray]]: - """Return the unique elements of an input array ``x``, and the indices from - the set of unique elements that reconstruct ``x``. + """ + Return the unique elements of an input array ``x``, and the indices from the set of + unique elements that reconstruct ``x``. .. admonition:: Data-dependent output shape :class: important @@ -261,7 +261,8 @@ def unique_values( *, out: Optional[ivy.Array] = None, ) -> ivy.Array: - """Return the unique elements of an input array ``x``. + """ + Return the unique elements of an input array ``x``. .. admonition:: Data-dependent output shape :class: important @@ -351,8 +352,9 @@ def unique_counts( x: Union[ivy.Array, ivy.NativeArray], /, ) -> Tuple[Union[ivy.Array, ivy.NativeArray], Union[ivy.Array, ivy.NativeArray]]: - """Return the unique elements of an input array ``x`` and the corresponding - counts for each unique element in ``x``. + """ + Return the unique elements of an input array ``x`` and the corresponding counts for + each unique element in ``x``. .. admonition:: Data-dependent output shape :class: important From cb70fc27af8e46530ceb99468555570c64f29add Mon Sep 17 00:00:00 2001 From: ivy-branch Date: Sat, 17 Feb 2024 19:48:23 +0000 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=A4=96=20Lint=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ivy/functional/ivy/set.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/ivy/functional/ivy/set.py b/ivy/functional/ivy/set.py index 15947937a5ede..bea4f31e35b54 100644 --- a/ivy/functional/ivy/set.py +++ b/ivy/functional/ivy/set.py @@ -38,10 +38,10 @@ def unique_all( Union[ivy.Array, ivy.NativeArray], Union[ivy.Array, ivy.NativeArray], ]: - """ - Return the unique elements of an input array ``x``, the first occurring indices for - each unique element in ``x``, the indices from the set of unique elements that - reconstruct ``x``, and the corresponding counts for each unique element in ``x``. + """Return the unique elements of an input array ``x``, the first occurring + indices for each unique element in ``x``, the indices from the set of + unique elements that reconstruct ``x``, and the corresponding counts for + each unique element in ``x``. .. admonition:: Data-dependent output shape :class: important @@ -160,9 +160,8 @@ def unique_inverse( *, axis: Optional[int] = None, ) -> Tuple[Union[ivy.Array, ivy.NativeArray], Union[ivy.Array, ivy.NativeArray]]: - """ - Return the unique elements of an input array ``x``, and the indices from the set of - unique elements that reconstruct ``x``. + """Return the unique elements of an input array ``x``, and the indices from + the set of unique elements that reconstruct ``x``. .. admonition:: Data-dependent output shape :class: important @@ -261,8 +260,7 @@ def unique_values( *, out: Optional[ivy.Array] = None, ) -> ivy.Array: - """ - Return the unique elements of an input array ``x``. + """Return the unique elements of an input array ``x``. .. admonition:: Data-dependent output shape :class: important @@ -352,9 +350,8 @@ def unique_counts( x: Union[ivy.Array, ivy.NativeArray], /, ) -> Tuple[Union[ivy.Array, ivy.NativeArray], Union[ivy.Array, ivy.NativeArray]]: - """ - Return the unique elements of an input array ``x`` and the corresponding counts for - each unique element in ``x``. + """Return the unique elements of an input array ``x`` and the corresponding + counts for each unique element in ``x``. .. admonition:: Data-dependent output shape :class: important