diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c8efbbb2c9b06..a20dff79ae6fc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,7 +13,7 @@ repos: - id: ruff args: [ --fix ] - repo: https://github.com/psf/black-pre-commit-mirror - rev: 24.1.1 + rev: 24.2.0 hooks: - id: black language_version: python3 diff --git a/ivy/__init__.py b/ivy/__init__.py index a3ec566d6609e..00e5039fd4099 100644 --- a/ivy/__init__.py +++ b/ivy/__init__.py @@ -930,45 +930,47 @@ def __deepcopy__(self, memo): # defines ivy.globals attribute -globals_vars = GlobalsDict({ - "backend_stack": backend_stack, - "default_device_stack": device.default_device_stack, - "valid_dtypes": valid_dtypes, - "valid_numeric_dtypes": valid_numeric_dtypes, - "valid_int_dtypes": valid_int_dtypes, - "valid_uint_dtypes": valid_uint_dtypes, - "valid_complex_dtypes": valid_complex_dtypes, - "valid_devices": valid_devices, - "invalid_dtypes": invalid_dtypes, - "invalid_numeric_dtypes": invalid_numeric_dtypes, - "invalid_int_dtypes": invalid_int_dtypes, - "invalid_float_dtypes": invalid_float_dtypes, - "invalid_uint_dtypes": invalid_uint_dtypes, - "invalid_complex_dtypes": invalid_complex_dtypes, - "invalid_devices": invalid_devices, - "array_significant_figures_stack": array_significant_figures_stack, - "array_decimal_values_stack": array_decimal_values_stack, - "warning_level_stack": warning_level_stack, - "queue_timeout_stack": general.queue_timeout_stack, - "array_mode_stack": general.array_mode_stack, - "inplace_mode_stack": general.inplace_mode_stack, - "soft_device_mode_stack": device.soft_device_mode_stack, - "shape_array_mode_stack": general.shape_array_mode_stack, - "show_func_wrapper_trace_mode_stack": general.show_func_wrapper_trace_mode_stack, - "min_denominator_stack": general.min_denominator_stack, - "min_base_stack": general.min_base_stack, - "tmp_dir_stack": general.tmp_dir_stack, - "precise_mode_stack": general.precise_mode_stack, - "nestable_mode_stack": general.nestable_mode_stack, - "exception_trace_mode_stack": general.exception_trace_mode_stack, - "default_dtype_stack": data_type.default_dtype_stack, - "default_float_dtype_stack": data_type.default_float_dtype_stack, - "default_int_dtype_stack": data_type.default_int_dtype_stack, - "default_uint_dtype_stack": data_type.default_uint_dtype_stack, - "nan_policy_stack": nan_policy_stack, - "dynamic_backend_stack": dynamic_backend_stack, - "cython_wrappers_stack": cython_wrappers_stack, -}) +globals_vars = GlobalsDict( + { + "backend_stack": backend_stack, + "default_device_stack": device.default_device_stack, + "valid_dtypes": valid_dtypes, + "valid_numeric_dtypes": valid_numeric_dtypes, + "valid_int_dtypes": valid_int_dtypes, + "valid_uint_dtypes": valid_uint_dtypes, + "valid_complex_dtypes": valid_complex_dtypes, + "valid_devices": valid_devices, + "invalid_dtypes": invalid_dtypes, + "invalid_numeric_dtypes": invalid_numeric_dtypes, + "invalid_int_dtypes": invalid_int_dtypes, + "invalid_float_dtypes": invalid_float_dtypes, + "invalid_uint_dtypes": invalid_uint_dtypes, + "invalid_complex_dtypes": invalid_complex_dtypes, + "invalid_devices": invalid_devices, + "array_significant_figures_stack": array_significant_figures_stack, + "array_decimal_values_stack": array_decimal_values_stack, + "warning_level_stack": warning_level_stack, + "queue_timeout_stack": general.queue_timeout_stack, + "array_mode_stack": general.array_mode_stack, + "inplace_mode_stack": general.inplace_mode_stack, + "soft_device_mode_stack": device.soft_device_mode_stack, + "shape_array_mode_stack": general.shape_array_mode_stack, + "show_func_wrapper_trace_mode_stack": general.show_func_wrapper_trace_mode_stack, + "min_denominator_stack": general.min_denominator_stack, + "min_base_stack": general.min_base_stack, + "tmp_dir_stack": general.tmp_dir_stack, + "precise_mode_stack": general.precise_mode_stack, + "nestable_mode_stack": general.nestable_mode_stack, + "exception_trace_mode_stack": general.exception_trace_mode_stack, + "default_dtype_stack": data_type.default_dtype_stack, + "default_float_dtype_stack": data_type.default_float_dtype_stack, + "default_int_dtype_stack": data_type.default_int_dtype_stack, + "default_uint_dtype_stack": data_type.default_uint_dtype_stack, + "nan_policy_stack": nan_policy_stack, + "dynamic_backend_stack": dynamic_backend_stack, + "cython_wrappers_stack": cython_wrappers_stack, + } +) _default_globals = copy.deepcopy(globals_vars) diff --git a/ivy/data_classes/container/base.py b/ivy/data_classes/container/base.py index b782245f53dae..bb004b709a37f 100644 --- a/ivy/data_classes/container/base.py +++ b/ivy/data_classes/container/base.py @@ -1367,15 +1367,17 @@ def cont_flatten_key_chain( if below_depth and num_keys > below_depth: pre_keys = flat_keys[0:below_depth] del flat_keys[0:below_depth] - return "/".join([ - k - for k in [ - "/".join(pre_keys), - replacement.join(flat_keys), - "/".join(post_keys), + return "/".join( + [ + k + for k in [ + "/".join(pre_keys), + replacement.join(flat_keys), + "/".join(post_keys), + ] + if k ] - if k - ]) + ) @staticmethod def cont_trim_key(key, max_length): @@ -1697,16 +1699,18 @@ def cont_all_true( Boolean, whether all entries are boolean True. """ return bool( - np.prod([ - v - for k, v in self.cont_as_bools( - assert_is_bool, - key_chains, - to_apply, - prune_unapplied, - map_sequences, - ).cont_to_iterator() - ]) + np.prod( + [ + v + for k, v in self.cont_as_bools( + assert_is_bool, + key_chains, + to_apply, + prune_unapplied, + map_sequences, + ).cont_to_iterator() + ] + ) ) def cont_all_false( @@ -1742,16 +1746,18 @@ def cont_all_false( Boolean, whether all entries are boolean False. """ return not bool( - np.sum([ - v - for k, v in self.cont_as_bools( - assert_is_bool, - key_chains, - to_apply, - prune_unapplied, - map_sequences, - ).cont_to_iterator() - ]) + np.sum( + [ + v + for k, v in self.cont_as_bools( + assert_is_bool, + key_chains, + to_apply, + prune_unapplied, + map_sequences, + ).cont_to_iterator() + ] + ) ) def cont_slice_via_key(self, slice_key): @@ -1843,11 +1849,15 @@ def cont_unstack_conts(self, axis, keepdims=False, dim_size=None): if keepdims: # noinspection PyTypeChecker return [ - self[( - slice(i, i + 1, 1) - if axis == 0 - else tuple([slice(None, None, None)] * axis + [slice(i, i + 1, 1)]) - )] + self[ + ( + slice(i, i + 1, 1) + if axis == 0 + else tuple( + [slice(None, None, None)] * axis + [slice(i, i + 1, 1)] + ) + ) + ] for i in range(dim_size) ] # noinspection PyTypeChecker @@ -3690,10 +3700,12 @@ def _pre_pad_alpha_line(str_in): padded = True return "\\n" + indent_str + indented_key_str + str_in - leading_str_to_keep = ", ".join([ - _pre_pad_alpha_line(s) if s[0].isalpha() and i != 0 else s - for i, s in enumerate(leading_str_to_keep.split(", ")) - ]) + leading_str_to_keep = ", ".join( + [ + _pre_pad_alpha_line(s) if s[0].isalpha() and i != 0 else s + for i, s in enumerate(leading_str_to_keep.split(", ")) + ] + ) local_indent_str = "" if padded else indent_str leading_str = leading_str_to_keep.split("\\n")[-1].replace('"', "") remaining_str = array_str_in_split[1] @@ -3710,23 +3722,25 @@ def _pre_pad_alpha_line(str_in): uniform_indent_wo_overflow_list = list( filter(None, uniform_indent_wo_overflow.split("\\n")) ) - uniform_indent = "\n".join([ - ( - local_indent_str + extra_indent + " " + s - if ( - s[0].isnumeric() - or s[0] == "-" - or s[0:3] == "..." - or max(ss in s[0:6] for ss in ["nan, ", "inf, "]) - ) - else ( - indent_str + indented_key_str + s - if (not s[0].isspace() and s[0] != '"') - else s + uniform_indent = "\n".join( + [ + ( + local_indent_str + extra_indent + " " + s + if ( + s[0].isnumeric() + or s[0] == "-" + or s[0:3] == "..." + or max(ss in s[0:6] for ss in ["nan, ", "inf, "]) + ) + else ( + indent_str + indented_key_str + s + if (not s[0].isspace() and s[0] != '"') + else s + ) ) - ) - for s in uniform_indent_wo_overflow_list - ]) + for s in uniform_indent_wo_overflow_list + ] + ) indented = uniform_indent # 10 dimensions is a sensible upper bound for the number in a single array for i in range(2, 10): @@ -3832,14 +3846,16 @@ def _align_arrays(str_in): def _add_newline(str_in): str_in_split = str_in.split("\n") str_split_size = len(str_in_split) - return "\n".join([ - ( - ("\n" * self._print_line_spacing + ss) - if i == (str_split_size - 1) - else ss - ) - for i, ss in enumerate(str_in_split) - ]) + return "\n".join( + [ + ( + ("\n" * self._print_line_spacing + ss) + if i == (str_split_size - 1) + else ss + ) + for i, ss in enumerate(str_in_split) + ] + ) json_dumped_str = '":'.join( [_add_newline(s) for s in json_dumped_str.split('":')] @@ -3850,9 +3866,12 @@ def _add_newline(str_in): json_dumped_str = ( json_dumped_str_split[0] + ", " - + ", ".join([ - "'".join(ss.split("'")[1:]) for ss in json_dumped_str_split[1:] - ]) + + ", ".join( + [ + "'".join(ss.split("'")[1:]) + for ss in json_dumped_str_split[1:] + ] + ) ) json_dumped_str = ( json_dumped_str.replace(":shape", ", shape") @@ -3863,24 +3882,26 @@ def _add_newline(str_in): # color keys json_dumped_str_split = json_dumped_str.split('":') split_size = len(json_dumped_str_split) - json_dumped_str = '":'.join([ - ( - ' "'.join( - sub_str.split(' "')[:-1] - + [ - termcolor.colored( - ivy.Container.cont_trim_key( - sub_str.split(' "')[-1], self._key_length_limit - ), - self._default_key_color, - ) - ] + json_dumped_str = '":'.join( + [ + ( + ' "'.join( + sub_str.split(' "')[:-1] + + [ + termcolor.colored( + ivy.Container.cont_trim_key( + sub_str.split(' "')[-1], self._key_length_limit + ), + self._default_key_color, + ) + ] + ) + if i < split_size - 1 + else sub_str ) - if i < split_size - 1 - else sub_str - ) - for i, sub_str in enumerate(json_dumped_str_split) - ]) + for i, sub_str in enumerate(json_dumped_str_split) + ] + ) # remove quotation marks, shape tuple, and color other elements of the dict ret = ( json_dumped_str.replace('"', "") diff --git a/ivy/data_classes/factorized_tensor/cp_tensor.py b/ivy/data_classes/factorized_tensor/cp_tensor.py index e81c18f929f6e..7def7d8288202 100644 --- a/ivy/data_classes/factorized_tensor/cp_tensor.py +++ b/ivy/data_classes/factorized_tensor/cp_tensor.py @@ -68,10 +68,12 @@ def to_unfolded(self, mode): return ivy.CPTensor.cp_to_unfolded(self, mode) def cp_copy(self): - return CPTensor(( - ivy.copy_array(self.weights), - [ivy.copy_array(self.factors[i]) for i in range(len(self.factors))], - )) + return CPTensor( + ( + ivy.copy_array(self.weights), + [ivy.copy_array(self.factors[i]) for i in range(len(self.factors))], + ) + ) def mode_dot(self, matrix_or_vector, mode, keep_dim=False, copy=True): """N-mode product of a CP tensor and a matrix or vector at the diff --git a/ivy/data_classes/factorized_tensor/tucker_tensor.py b/ivy/data_classes/factorized_tensor/tucker_tensor.py index 17f5d27f6c0c3..5984be2efe365 100644 --- a/ivy/data_classes/factorized_tensor/tucker_tensor.py +++ b/ivy/data_classes/factorized_tensor/tucker_tensor.py @@ -83,10 +83,12 @@ def to_unfolded(self, mode): return TuckerTensor.tucker_to_unfolded(self, mode) def tucker_copy(self): - return TuckerTensor(( - deepcopy(self.core), - [deepcopy(self.factors[i]) for i in range(len(self.factors))], - )) + return TuckerTensor( + ( + deepcopy(self.core), + [deepcopy(self.factors[i]) for i in range(len(self.factors))], + ) + ) def to_vec(self): return TuckerTensor.tucker_to_vec(self) diff --git a/ivy/func_wrapper.py b/ivy/func_wrapper.py index 7338bec329843..5e02cb26cde62 100644 --- a/ivy/func_wrapper.py +++ b/ivy/func_wrapper.py @@ -1658,14 +1658,16 @@ def __exit__(self, *exec): if globals_getter_func().get(item, None): if isinstance(globals_getter_func()[item], FunctionType): # we need to add the decorator - globals_getter_func([ - item, - ( - _dtype_device_wrapper_creator("unsupported_dtypes", tuple)( - *self.args, **self.kwargs - ) - )(globals_getter_func()[item]), - ]) + globals_getter_func( + [ + item, + ( + _dtype_device_wrapper_creator( + "unsupported_dtypes", tuple + )(*self.args, **self.kwargs) + )(globals_getter_func()[item]), + ] + ) class with_supported_dtypes(contextlib.ContextDecorator): @@ -1692,14 +1694,16 @@ def __exit__(self, *exec): if globals_getter_func().get(item, None): if isinstance(globals_getter_func()[item], FunctionType): # we need to add the decorator - globals_getter_func([ - item, - ( - _dtype_device_wrapper_creator("supported_dtypes", tuple)( - *self.args, **self.kwargs - ) - )(globals_getter_func()[item]), - ]) + globals_getter_func( + [ + item, + ( + _dtype_device_wrapper_creator( + "supported_dtypes", tuple + )(*self.args, **self.kwargs) + )(globals_getter_func()[item]), + ] + ) class with_unsupported_devices(contextlib.ContextDecorator): @@ -1726,14 +1730,16 @@ def __exit__(self, *exec): if globals_getter_func().get(item, None): if isinstance(globals_getter_func()[item], FunctionType): # we need to add the decorator - globals_getter_func([ - item, - ( - _dtype_device_wrapper_creator("unsupported_devices", tuple)( - *self.args, **self.kwargs - ) - )(globals_getter_func()[item]), - ]) + globals_getter_func( + [ + item, + ( + _dtype_device_wrapper_creator( + "unsupported_devices", tuple + )(*self.args, **self.kwargs) + )(globals_getter_func()[item]), + ] + ) class with_supported_devices(contextlib.ContextDecorator): @@ -1760,14 +1766,16 @@ def __exit__(self, *exec): if globals_getter_func().get(item, None): if isinstance(globals_getter_func()[item], FunctionType): # we need to add the decorator - globals_getter_func([ - item, - ( - _dtype_device_wrapper_creator("supported_devices", tuple)( - *self.args, **self.kwargs - ) - )(globals_getter_func()[item]), - ]) + globals_getter_func( + [ + item, + ( + _dtype_device_wrapper_creator( + "supported_devices", tuple + )(*self.args, **self.kwargs) + )(globals_getter_func()[item]), + ] + ) class with_unsupported_device_and_dtypes(contextlib.ContextDecorator): @@ -1816,14 +1824,16 @@ def __exit__(self, *exec): if globals_getter_func().get(item, None): if isinstance(globals_getter_func()[item], FunctionType): # we need to add the decorator - globals_getter_func([ - item, - ( - _dtype_device_wrapper_creator( - "unsupported_device_and_dtype", tuple - )(*self.args, **self.kwargs) - )(globals_getter_func()[item]), - ]) + globals_getter_func( + [ + item, + ( + _dtype_device_wrapper_creator( + "unsupported_device_and_dtype", tuple + )(*self.args, **self.kwargs) + )(globals_getter_func()[item]), + ] + ) class with_supported_device_and_dtypes(contextlib.ContextDecorator): @@ -1872,14 +1882,16 @@ def __exit__(self, *exec): if globals_getter_func().get(item, None): if isinstance(globals_getter_func()[item], FunctionType): # we need to add the decorator - globals_getter_func([ - item, - ( - _dtype_device_wrapper_creator( - "supported_device_and_dtype", tuple - )(*self.args, **self.kwargs) - )(globals_getter_func()[item]), - ]) + globals_getter_func( + [ + item, + ( + _dtype_device_wrapper_creator( + "supported_device_and_dtype", tuple + )(*self.args, **self.kwargs) + )(globals_getter_func()[item]), + ] + ) class override(contextlib.ContextDecorator): diff --git a/ivy/functional/backends/jax/random.py b/ivy/functional/backends/jax/random.py index 4422cec77481f..ef0555fabf6d7 100644 --- a/ivy/functional/backends/jax/random.py +++ b/ivy/functional/backends/jax/random.py @@ -106,10 +106,12 @@ def multinomial( if probs is None: probs = ( - jnp.ones(( - batch_size, - population_size, - )) + jnp.ones( + ( + batch_size, + population_size, + ) + ) / population_size ) orig_probs_shape = list(probs.shape) diff --git a/ivy/functional/backends/mxnet/creation.py b/ivy/functional/backends/mxnet/creation.py index 5da540614b9e3..d32d312efc394 100644 --- a/ivy/functional/backends/mxnet/creation.py +++ b/ivy/functional/backends/mxnet/creation.py @@ -35,16 +35,18 @@ def arange( @_asarray_handle_nestable @_asarray_inputs_to_native_shapes def asarray( - obj: Union[( - None, - mx.ndarray.NDArray, - bool, - int, - float, - NestedSequence, - SupportsBufferProtocol, - np.ndarray, - )], + obj: Union[ + ( + None, + mx.ndarray.NDArray, + bool, + int, + float, + NestedSequence, + SupportsBufferProtocol, + np.ndarray, + ) + ], /, *, copy: Optional[bool] = None, diff --git a/ivy/functional/backends/mxnet/experimental/linear_algebra.py b/ivy/functional/backends/mxnet/experimental/linear_algebra.py index 458c945791b83..dd31f5eeb070d 100644 --- a/ivy/functional/backends/mxnet/experimental/linear_algebra.py +++ b/ivy/functional/backends/mxnet/experimental/linear_algebra.py @@ -15,11 +15,13 @@ def eigh_tridiagonal( Union[(Tuple[(int, int)], List[int], None, mx.ndarray.NDArray)] ] = None, tol: Optional[float] = None, -) -> Union[( - None, - mx.ndarray.NDArray, - Tuple[(Union[(None, mx.ndarray.NDArray)], Union[(None, mx.ndarray.NDArray)])], -)]: +) -> Union[ + ( + None, + mx.ndarray.NDArray, + Tuple[(Union[(None, mx.ndarray.NDArray)], Union[(None, mx.ndarray.NDArray)])], + ) +]: raise IvyNotImplementedException() diff --git a/ivy/functional/backends/mxnet/experimental/norms.py b/ivy/functional/backends/mxnet/experimental/norms.py index da6b8b5311adf..19fea95289a8d 100644 --- a/ivy/functional/backends/mxnet/experimental/norms.py +++ b/ivy/functional/backends/mxnet/experimental/norms.py @@ -26,11 +26,13 @@ def batch_norm( eps: float = 1e-05, momentum: float = 0.1, out: Optional[None] = None, -) -> Tuple[( - Union[(None, mx.ndarray.NDArray)], - Union[(None, mx.ndarray.NDArray)], - Union[(None, mx.ndarray.NDArray)], -)]: +) -> Tuple[ + ( + Union[(None, mx.ndarray.NDArray)], + Union[(None, mx.ndarray.NDArray)], + Union[(None, mx.ndarray.NDArray)], + ) +]: raise IvyNotImplementedException() @@ -46,11 +48,13 @@ def instance_norm( eps: float = 1e-05, momentum: float = 0.1, out: Optional[None] = None, -) -> Tuple[( - Union[(None, mx.ndarray.NDArray)], - Union[(None, mx.ndarray.NDArray)], - Union[(None, mx.ndarray.NDArray)], -)]: +) -> Tuple[ + ( + Union[(None, mx.ndarray.NDArray)], + Union[(None, mx.ndarray.NDArray)], + Union[(None, mx.ndarray.NDArray)], + ) +]: raise IvyNotImplementedException() diff --git a/ivy/functional/backends/mxnet/set.py b/ivy/functional/backends/mxnet/set.py index 1617ed1539d12..cb9a9cc9906e6 100644 --- a/ivy/functional/backends/mxnet/set.py +++ b/ivy/functional/backends/mxnet/set.py @@ -6,12 +6,14 @@ def unique_all( x: Union[(None, mx.ndarray.NDArray)], /, *, axis: Optional[int] = None -) -> Tuple[( - Union[(None, mx.ndarray.NDArray)], - Union[(None, mx.ndarray.NDArray)], - Union[(None, mx.ndarray.NDArray)], - Union[(None, mx.ndarray.NDArray)], -)]: +) -> Tuple[ + ( + Union[(None, mx.ndarray.NDArray)], + Union[(None, mx.ndarray.NDArray)], + Union[(None, mx.ndarray.NDArray)], + Union[(None, mx.ndarray.NDArray)], + ) +]: raise IvyNotImplementedException() diff --git a/ivy/functional/backends/numpy/experimental/elementwise.py b/ivy/functional/backends/numpy/experimental/elementwise.py index ab35f7d972aa7..821c287a722b5 100644 --- a/ivy/functional/backends/numpy/experimental/elementwise.py +++ b/ivy/functional/backends/numpy/experimental/elementwise.py @@ -338,16 +338,18 @@ def modf( # ---digamma---# kLanczosGamma = 7 # aka g kBaseLanczosCoeff = 0.99999999999980993227684700473478 -kLanczosCoefficients = np.array([ - 676.520368121885098567009190444019, - -1259.13921672240287047156078755283, - 771.3234287776530788486528258894, - -176.61502916214059906584551354, - 12.507343278686904814458936853, - -0.13857109526572011689554707, - 9.984369578019570859563e-6, - 1.50563273514931155834e-7, -]) +kLanczosCoefficients = np.array( + [ + 676.520368121885098567009190444019, + -1259.13921672240287047156078755283, + 771.3234287776530788486528258894, + -176.61502916214059906584551354, + 12.507343278686904814458936853, + -0.13857109526572011689554707, + 9.984369578019570859563e-6, + 1.50563273514931155834e-7, + ] +) def digamma( @@ -397,36 +399,40 @@ def digamma( # --- LGAMMA --- # LANCZOS_N = 13 lanczos_g = 6.024680040776729583740234375 -lanczos_num_coeffs = np.array([ - 23531376880.410759688572007674451636754734846804940, - 42919803642.649098768957899047001988850926355848959, - 35711959237.355668049440185451547166705960488635843, - 17921034426.037209699919755754458931112671403265390, - 6039542586.3520280050642916443072979210699388420708, - 1439720407.3117216736632230727949123939715485786772, - 248874557.86205415651146038641322942321632125127801, - 31426415.585400194380614231628318205362874684987640, - 2876370.6289353724412254090516208496135991145378768, - 186056.26539522349504029498971604569928220784236328, - 8071.6720023658162106380029022722506138218516325024, - 210.82427775157934587250973392071336271166969580291, - 2.5066282746310002701649081771338373386264310793408, -]) -lanczos_den_coeffs = np.array([ - 0.0, - 39916800.0, - 120543840.0, - 150917976.0, - 105258076.0, - 45995730.0, - 13339535.0, - 2637558.0, - 357423.0, - 32670.0, - 1925.0, - 66.0, - 1.0, -]) +lanczos_num_coeffs = np.array( + [ + 23531376880.410759688572007674451636754734846804940, + 42919803642.649098768957899047001988850926355848959, + 35711959237.355668049440185451547166705960488635843, + 17921034426.037209699919755754458931112671403265390, + 6039542586.3520280050642916443072979210699388420708, + 1439720407.3117216736632230727949123939715485786772, + 248874557.86205415651146038641322942321632125127801, + 31426415.585400194380614231628318205362874684987640, + 2876370.6289353724412254090516208496135991145378768, + 186056.26539522349504029498971604569928220784236328, + 8071.6720023658162106380029022722506138218516325024, + 210.82427775157934587250973392071336271166969580291, + 2.5066282746310002701649081771338373386264310793408, + ] +) +lanczos_den_coeffs = np.array( + [ + 0.0, + 39916800.0, + 120543840.0, + 150917976.0, + 105258076.0, + 45995730.0, + 13339535.0, + 2637558.0, + 357423.0, + 32670.0, + 1925.0, + 66.0, + 1.0, + ] +) def sinpi(x): @@ -512,45 +518,53 @@ def func(x): # --- erfc --- # # Polynomials for computing erf/erfc. Originally from cephes library. # https://netlib.org/cephes/doubldoc.html -kErfcPCoefficient = np.array([ - 2.46196981473530512524e-10, - 5.64189564831068821977e-1, - 7.46321056442269912687e0, - 4.86371970985681366614e1, - 1.96520832956077098242e2, - 5.26445194995477358631e2, - 9.34528527171957607540e2, - 1.02755188689515710272e3, - 5.57535335369399327526e2, -]) -kErfcQCoefficient = np.array([ - 1.00000000000000000000e0, - 1.32281951154744992508e1, - 8.67072140885989742329e1, - 3.54937778887819891062e2, - 9.75708501743205489753e2, - 1.82390916687909736289e3, - 2.24633760818710981792e3, - 1.65666309194161350182e3, - 5.57535340817727675546e2, -]) -kErfcRCoefficient = np.array([ - 5.64189583547755073984e-1, - 1.27536670759978104416e0, - 5.01905042251180477414e0, - 6.16021097993053585195e0, - 7.40974269950448939160e0, - 2.97886665372100240670e0, -]) -kErfcSCoefficient = np.array([ - 1.00000000000000000000e0, - 2.26052863220117276590e0, - 9.39603524938001434673e0, - 1.20489539808096656605e1, - 1.70814450747565897222e1, - 9.60896809063285878198e0, - 3.36907645100081516050e0, -]) +kErfcPCoefficient = np.array( + [ + 2.46196981473530512524e-10, + 5.64189564831068821977e-1, + 7.46321056442269912687e0, + 4.86371970985681366614e1, + 1.96520832956077098242e2, + 5.26445194995477358631e2, + 9.34528527171957607540e2, + 1.02755188689515710272e3, + 5.57535335369399327526e2, + ] +) +kErfcQCoefficient = np.array( + [ + 1.00000000000000000000e0, + 1.32281951154744992508e1, + 8.67072140885989742329e1, + 3.54937778887819891062e2, + 9.75708501743205489753e2, + 1.82390916687909736289e3, + 2.24633760818710981792e3, + 1.65666309194161350182e3, + 5.57535340817727675546e2, + ] +) +kErfcRCoefficient = np.array( + [ + 5.64189583547755073984e-1, + 1.27536670759978104416e0, + 5.01905042251180477414e0, + 6.16021097993053585195e0, + 7.40974269950448939160e0, + 2.97886665372100240670e0, + ] +) +kErfcSCoefficient = np.array( + [ + 1.00000000000000000000e0, + 2.26052863220117276590e0, + 9.39603524938001434673e0, + 1.20489539808096656605e1, + 1.70814450747565897222e1, + 9.60896809063285878198e0, + 3.36907645100081516050e0, + ] +) # Evaluate the polynomial given coefficients and `x`. diff --git a/ivy/functional/backends/numpy/random.py b/ivy/functional/backends/numpy/random.py index 4d3daa4a00c6e..17a9d19fc4698 100644 --- a/ivy/functional/backends/numpy/random.py +++ b/ivy/functional/backends/numpy/random.py @@ -69,10 +69,12 @@ def multinomial( np.random.seed(seed) if probs is None: probs = ( - np.ones(( - batch_size, - population_size, - )) + np.ones( + ( + batch_size, + population_size, + ) + ) / population_size ) orig_probs_shape = list(probs.shape) diff --git a/ivy/functional/backends/paddle/experimental/elementwise.py b/ivy/functional/backends/paddle/experimental/elementwise.py index 0ecef27c3ec71..c26898376ea69 100644 --- a/ivy/functional/backends/paddle/experimental/elementwise.py +++ b/ivy/functional/backends/paddle/experimental/elementwise.py @@ -715,45 +715,53 @@ def digamma( # --- erfc --- # # Polynomials for computing erf/erfc. Originally from cephes library. # https://netlib.org/cephes/doubldoc.html -kErfcPCoefficient = paddle.to_tensor([ - 2.46196981473530512524e-10, - 5.64189564831068821977e-1, - 7.46321056442269912687e0, - 4.86371970985681366614e1, - 1.96520832956077098242e2, - 5.26445194995477358631e2, - 9.34528527171957607540e2, - 1.02755188689515710272e3, - 5.57535335369399327526e2, -]) -kErfcQCoefficient = paddle.to_tensor([ - 1.00000000000000000000e0, - 1.32281951154744992508e1, - 8.67072140885989742329e1, - 3.54937778887819891062e2, - 9.75708501743205489753e2, - 1.82390916687909736289e3, - 2.24633760818710981792e3, - 1.65666309194161350182e3, - 5.57535340817727675546e2, -]) -kErfcRCoefficient = paddle.to_tensor([ - 5.64189583547755073984e-1, - 1.27536670759978104416e0, - 5.01905042251180477414e0, - 6.16021097993053585195e0, - 7.40974269950448939160e0, - 2.97886665372100240670e0, -]) -kErfcSCoefficient = paddle.to_tensor([ - 1.00000000000000000000e0, - 2.26052863220117276590e0, - 9.39603524938001434673e0, - 1.20489539808096656605e1, - 1.70814450747565897222e1, - 9.60896809063285878198e0, - 3.36907645100081516050e0, -]) +kErfcPCoefficient = paddle.to_tensor( + [ + 2.46196981473530512524e-10, + 5.64189564831068821977e-1, + 7.46321056442269912687e0, + 4.86371970985681366614e1, + 1.96520832956077098242e2, + 5.26445194995477358631e2, + 9.34528527171957607540e2, + 1.02755188689515710272e3, + 5.57535335369399327526e2, + ] +) +kErfcQCoefficient = paddle.to_tensor( + [ + 1.00000000000000000000e0, + 1.32281951154744992508e1, + 8.67072140885989742329e1, + 3.54937778887819891062e2, + 9.75708501743205489753e2, + 1.82390916687909736289e3, + 2.24633760818710981792e3, + 1.65666309194161350182e3, + 5.57535340817727675546e2, + ] +) +kErfcRCoefficient = paddle.to_tensor( + [ + 5.64189583547755073984e-1, + 1.27536670759978104416e0, + 5.01905042251180477414e0, + 6.16021097993053585195e0, + 7.40974269950448939160e0, + 2.97886665372100240670e0, + ] +) +kErfcSCoefficient = paddle.to_tensor( + [ + 1.00000000000000000000e0, + 2.26052863220117276590e0, + 9.39603524938001434673e0, + 1.20489539808096656605e1, + 1.70814450747565897222e1, + 9.60896809063285878198e0, + 3.36907645100081516050e0, + ] +) # Evaluate the polynomial given coefficients and `x`. diff --git a/ivy/functional/backends/paddle/general.py b/ivy/functional/backends/paddle/general.py index 2d1804e87c315..0f9747fe6353e 100644 --- a/ivy/functional/backends/paddle/general.py +++ b/ivy/functional/backends/paddle/general.py @@ -70,11 +70,13 @@ def _squeeze_helper(query, x_ndim): ) if any(slice_squeeze): - squeeze_indices = tuple([ - idx - for idx, val in enumerate(slice_squeeze) - if (val is False and query[idx] is not None) - ]) + squeeze_indices = tuple( + [ + idx + for idx, val in enumerate(slice_squeeze) + if (val is False and query[idx] is not None) + ] + ) elif return_scalar: squeeze_indices = () else: diff --git a/ivy/functional/backends/paddle/gradients.py b/ivy/functional/backends/paddle/gradients.py index 0a0a9ab9b7c80..925e49c865bc1 100644 --- a/ivy/functional/backends/paddle/gradients.py +++ b/ivy/functional/backends/paddle/gradients.py @@ -116,10 +116,12 @@ def execute_with_gradients( xs = xs1 if isinstance(xs, ivy.Container): duplicate_indices = list( - chain.from_iterable([ - map(lambda x: x.split("/"), duplicate_index_chain[1:]) - for duplicate_index_chain in required_duplicate_index_chains - ]) + chain.from_iterable( + [ + map(lambda x: x.split("/"), duplicate_index_chain[1:]) + for duplicate_index_chain in required_duplicate_index_chains + ] + ) ) xs = ivy.set_nest_at_indices(xs, duplicate_indices, None, shallow=False) diff --git a/ivy/functional/backends/paddle/set.py b/ivy/functional/backends/paddle/set.py index 789218824f1d6..1d73d6b200496 100644 --- a/ivy/functional/backends/paddle/set.py +++ b/ivy/functional/backends/paddle/set.py @@ -63,12 +63,14 @@ def unique_all( axis = 0 values_ = paddle.moveaxis(values, axis, 0) values_ = paddle.reshape(values_, (values_.shape[0], -1)) - sort_idx = paddle.to_tensor([ - i[0] - for i in sorted( - enumerate(values_.numpy().tolist()), key=lambda x: tuple(x[1]) - ) - ]) + sort_idx = paddle.to_tensor( + [ + i[0] + for i in sorted( + enumerate(values_.numpy().tolist()), key=lambda x: tuple(x[1]) + ) + ] + ) values = paddle.gather(values, sort_idx, axis=axis) counts = paddle.gather(counts, sort_idx) indices = paddle.gather(indices, sort_idx) diff --git a/ivy/functional/backends/tensorflow/experimental/layers.py b/ivy/functional/backends/tensorflow/experimental/layers.py index f13eb3e9290c9..3aa7d1126f5fe 100644 --- a/ivy/functional/backends/tensorflow/experimental/layers.py +++ b/ivy/functional/backends/tensorflow/experimental/layers.py @@ -1208,11 +1208,13 @@ def shape_initialization(shape, axes, x): def rank_initialization(axes): rank = tf.size(axes) - with tf.control_dependencies([ - tf.debugging.assert_less_equal( - rank, 3, message="N-D FFT supported only up to 3-D." - ) - ]): + with tf.control_dependencies( + [ + tf.debugging.assert_less_equal( + rank, 3, message="N-D FFT supported only up to 3-D." + ) + ] + ): rank = tf.identity(rank) return rank diff --git a/ivy/functional/backends/tensorflow/module.py b/ivy/functional/backends/tensorflow/module.py index 919f21b630924..9c7d670aa977d 100644 --- a/ivy/functional/backends/tensorflow/module.py +++ b/ivy/functional/backends/tensorflow/module.py @@ -84,10 +84,12 @@ def __repr__(self, indent: int = 0) -> str: indent += len(repr_prefix) children_specs_str += self.children_specs[0].__repr__(indent) children_specs_str += "," if len(self.children_specs) > 1 else "" - children_specs_str += ",".join([ - "\n" + " " * indent + child.__repr__(indent) - for child in self.children_specs[1:] - ]) + children_specs_str += ",".join( + [ + "\n" + " " * indent + child.__repr__(indent) + for child in self.children_specs[1:] + ] + ) repr_suffix: str = f"{children_specs_str}])" return repr_prefix + repr_suffix @@ -426,10 +428,12 @@ def _find_variables( if ( v is not None and k[0:2] != "__" - and not k.startswith(( - "_module_dict", - "_self_", - )) + and not k.startswith( + ( + "_module_dict", + "_self_", + ) + ) ): ret = self._find_variables( obj=v, diff --git a/ivy/functional/backends/tensorflow/random.py b/ivy/functional/backends/tensorflow/random.py index dcb320508614d..65828a02669d9 100644 --- a/ivy/functional/backends/tensorflow/random.py +++ b/ivy/functional/backends/tensorflow/random.py @@ -80,10 +80,12 @@ def multinomial( ) -> Union[tf.Tensor, tf.Variable]: if probs is None: probs = ( - tf.ones(( - batch_size, - population_size, - )) + tf.ones( + ( + batch_size, + population_size, + ) + ) / population_size ) diff --git a/ivy/functional/backends/torch/experimental/gradients.py b/ivy/functional/backends/torch/experimental/gradients.py index a959d5ab83e03..b6c0a7cedf6e4 100644 --- a/ivy/functional/backends/torch/experimental/gradients.py +++ b/ivy/functional/backends/torch/experimental/gradients.py @@ -34,10 +34,12 @@ def backward(ctx, upstream): def vjp(func: Callable, *primals): flattened_primals, ret_idxs = _flatten_containers(primals) - unique_keys = list({ - ivy.index_nest(ret_idxs, i) - for i in ivy.nested_argwhere(ret_idxs, lambda x: isinstance(x, str)) - }) + unique_keys = list( + { + ivy.index_nest(ret_idxs, i) + for i in ivy.nested_argwhere(ret_idxs, lambda x: isinstance(x, str)) + } + ) def grad_fn(*x_in): ret, idxs = _flatten_containers( @@ -93,10 +95,12 @@ def vjpfun(*x_in): def jvp(func: Callable, primals, tangents): flattened_primals, ret_idxs = _flatten_containers(primals) flattened_tangents, _ = _flatten_containers(tangents) - unique_keys = list({ - ivy.index_nest(ret_idxs, i) - for i in ivy.nested_argwhere(ret_idxs, lambda x: isinstance(x, str)) - }) + unique_keys = list( + { + ivy.index_nest(ret_idxs, i) + for i in ivy.nested_argwhere(ret_idxs, lambda x: isinstance(x, str)) + } + ) def grad_fn(*x_in): ret, idxs = _flatten_containers( diff --git a/ivy/functional/backends/torch/experimental/statistical.py b/ivy/functional/backends/torch/experimental/statistical.py index f8cfbaa6a64a9..d5aa9e44c085a 100644 --- a/ivy/functional/backends/torch/experimental/statistical.py +++ b/ivy/functional/backends/torch/experimental/statistical.py @@ -292,10 +292,12 @@ def _handle_axis(a, q, fn, keepdims=False, axis=None): for i, s in enumerate(sorted(keep)): a = torch.moveaxis(a, s, i) - a = a.view([ - *a.shape[:nkeep], - -1, - ]) + a = a.view( + [ + *a.shape[:nkeep], + -1, + ] + ) axis_arg = -1 ret = fn(a, q, axis=axis_arg) diff --git a/ivy/functional/backends/torch/random.py b/ivy/functional/backends/torch/random.py index 944413c523b21..f4ee4e0cdf2ad 100644 --- a/ivy/functional/backends/torch/random.py +++ b/ivy/functional/backends/torch/random.py @@ -78,10 +78,12 @@ def multinomial( ) -> torch.Tensor: if probs is None: probs = ( - torch.ones(( - batch_size, - population_size, - )) + torch.ones( + ( + batch_size, + population_size, + ) + ) / population_size ) if seed: diff --git a/ivy/functional/ivy/experimental/layers.py b/ivy/functional/ivy/experimental/layers.py index 27974eeb898f7..38ba820389006 100644 --- a/ivy/functional/ivy/experimental/layers.py +++ b/ivy/functional/ivy/experimental/layers.py @@ -1405,11 +1405,13 @@ def _tf_area_interpolate(x, size, scale, dims): d_in, d_in1, d_index = _tf_area_indices(d_dim, scale[0]) h_in, h_in1, h_index = _tf_area_indices(h_dim, scale[1]) w_in, w_in1, w_index = _tf_area_indices(w_dim, scale[2]) - sum_data = ivy.zeros(( - d_index[1] - d_index[0], - h_index[1] - h_index[0], - w_index[1] - w_index[0], - )) + sum_data = ivy.zeros( + ( + d_index[1] - d_index[0], + h_index[1] - h_index[0], + w_index[1] - w_index[0], + ) + ) for d_ind in range(d_index[0], d_index[1]): scale_z = _tf_area_dim_scale( d_ind, d_in, scale[0], d_in1 @@ -1912,14 +1914,18 @@ def interpolate( right = int(math.ceil(p_j + 2)) top = int(math.floor(p_i - 2)) bottom = int(math.ceil(p_i + 2)) - kernel_w = ivy.array([ - _mitchellcubic_kernel((p_j - j) * scale_w) - for i in range(left, right) - ]) - kernel_h = ivy.array([ - _mitchellcubic_kernel((p_i - i) * scale_h) - for j in range(top, bottom) - ]) + kernel_w = ivy.array( + [ + _mitchellcubic_kernel((p_j - j) * scale_w) + for i in range(left, right) + ] + ) + kernel_h = ivy.array( + [ + _mitchellcubic_kernel((p_i - i) * scale_h) + for j in range(top, bottom) + ] + ) left_pad = max(0, -left) right_pad = max(0, right - in_width) top_pad = max(0, -top) diff --git a/ivy/functional/ivy/experimental/linear_algebra.py b/ivy/functional/ivy/experimental/linear_algebra.py index cad3733c69dcc..f98ec8a896e14 100644 --- a/ivy/functional/ivy/experimental/linear_algebra.py +++ b/ivy/functional/ivy/experimental/linear_algebra.py @@ -1051,12 +1051,14 @@ def svd_flip( ) V = V * signs[:, None] if ivy.shape(U)[1] > ivy.shape(V)[0]: - signs = ivy.concat(( - signs, - ivy.ones( - ivy.shape(U)[1] - ivy.shape(V)[0], - ), - )) + signs = ivy.concat( + ( + signs, + ivy.ones( + ivy.shape(U)[1] - ivy.shape(V)[0], + ), + ) + ) U = U * signs[: ivy.shape(U)[1]] return U, V diff --git a/ivy/functional/ivy/experimental/sparse_array.py b/ivy/functional/ivy/experimental/sparse_array.py index 623a38a918afa..4a82fb4f97ad9 100644 --- a/ivy/functional/ivy/experimental/sparse_array.py +++ b/ivy/functional/ivy/experimental/sparse_array.py @@ -766,10 +766,12 @@ def _bsr_to_dense_coordinates(self): for col in cols: for col_index in range(nblockcols): for row_index in range(nblockrows): - all_coordinates.append([ - nblockrows * row + row_index, - nblockcols * col + col_index, - ]) + all_coordinates.append( + [ + nblockrows * row + row_index, + nblockcols * col + col_index, + ] + ) return all_coordinates def _bsc_to_dense_coordinates(self): @@ -785,10 +787,12 @@ def _bsc_to_dense_coordinates(self): for row in rows: for col_index in range(nblockcols): for row_index in range(nblockrows): - all_coordinates.append([ - nblockrows * row + row_index, - nblockcols * col + col_index, - ]) + all_coordinates.append( + [ + nblockrows * row + row_index, + nblockcols * col + col_index, + ] + ) return all_coordinates def to_dense_array(self, *, native=False): diff --git a/ivy/functional/ivy/meta.py b/ivy/functional/ivy/meta.py index 5b3151c9accc6..f468ded38a0e3 100644 --- a/ivy/functional/ivy/meta.py +++ b/ivy/functional/ivy/meta.py @@ -88,10 +88,12 @@ def cost_fn_with_variable(v): else variables.cont_prune_key_chains(outer_v, ignore_none=True) ) - inner_grads = ivy.Container({ - k: ivy.zeros_like(v) if k not in inner_grads else inner_grads[k] - for k, v in var.cont_to_iterator() - }) + inner_grads = ivy.Container( + { + k: ivy.zeros_like(v) if k not in inner_grads else inner_grads[k] + for k, v in var.cont_to_iterator() + } + ) if batched: inner_grads = ivy.multiply(inner_grads, num_tasks) @@ -151,14 +153,16 @@ def _train_task( if keep_innver_v else variables.cont_prune_key_chains(inner_v, ignore_none=True) ) - inner_update_grads = ivy.Container({ - k: ( - ivy.zeros_like(v) - if k not in inner_update_grads - else inner_update_grads[k] - ) - for k, v in var.cont_to_iterator() - }) + inner_update_grads = ivy.Container( + { + k: ( + ivy.zeros_like(v) + if k not in inner_update_grads + else inner_update_grads[k] + ) + for k, v in var.cont_to_iterator() + } + ) if batched: inner_update_grads = ivy.multiply(inner_update_grads, num_tasks) diff --git a/ivy/functional/ivy/nest.py b/ivy/functional/ivy/nest.py index 60e9f1f279f43..2725361c86bba 100644 --- a/ivy/functional/ivy/nest.py +++ b/ivy/functional/ivy/nest.py @@ -1341,14 +1341,16 @@ def copy_nest( return class_instance(**dict(zip(nest._fields, ret_list))) return class_instance(tuple(ret_list)) elif check_fn(nest, list): - return class_instance([ - copy_nest( - i, - include_derived=include_derived, - to_mutable=to_mutable, - ) - for i in nest - ]) + return class_instance( + [ + copy_nest( + i, + include_derived=include_derived, + to_mutable=to_mutable, + ) + for i in nest + ] + ) elif check_fn(nest, dict): class_instance = type(nest) dict_ = { diff --git a/ivy/stateful/module.py b/ivy/stateful/module.py index 12a16f95f39dc..d8ad7d80455d1 100644 --- a/ivy/stateful/module.py +++ b/ivy/stateful/module.py @@ -803,10 +803,12 @@ def _create_variables(self, device=None, dtype=None): def _build(self, *args, **kwargs): self._native_params = ivy.Container( OrderedDict( - sorted([ - (k.replace(".", "/"), v) - for k, v in dict(self._native_module.named_parameters()).items() - ]) + sorted( + [ + (k.replace(".", "/"), v) + for k, v in dict(self._native_module.named_parameters()).items() + ] + ) ), dynamic_backend=False, ) @@ -834,10 +836,12 @@ def _create_variables(self, device=None, dtype=None): def _build(self, *args, **kwargs): self._native_params = ivy.Container( OrderedDict( - sorted([ - (k.replace(".", "/"), v) - for k, v in dict(self._native_module.named_parameters()).items() - ]) + sorted( + [ + (k.replace(".", "/"), v) + for k, v in dict(self._native_module.named_parameters()).items() + ] + ) ), dynamic_backend=False, ) diff --git a/ivy/utils/binaries.py b/ivy/utils/binaries.py index 5f050892f2044..8b22ed383a159 100644 --- a/ivy/utils/binaries.py +++ b/ivy/utils/binaries.py @@ -33,10 +33,12 @@ def check_for_binaries(): for path in binaries_paths: if not os.path.exists(path): if initial: - config_str = "\n".join([ - f"{module} : {', '.join(configs)}" - for module, configs in available_configs.items() - ]) + config_str = "\n".join( + [ + f"{module} : {', '.join(configs)}" + for module, configs in available_configs.items() + ] + ) logging.warning( "\tSome binaries seem to be missing in your system. This could " "be either because we don't have compatible binaries for your " diff --git a/ivy_tests/test_ivy/conftest.py b/ivy_tests/test_ivy/conftest.py index 3501bdbf4dc01..3776351090e77 100644 --- a/ivy_tests/test_ivy/conftest.py +++ b/ivy_tests/test_ivy/conftest.py @@ -198,12 +198,14 @@ def pytest_configure(config): continue for trace_graph in trace_modes: for implicit in implicit_modes: - TEST_PARAMS_CONFIG.append(( - device, - backend_str, - trace_graph, - implicit, - )) + TEST_PARAMS_CONFIG.append( + ( + device, + backend_str, + trace_graph, + implicit, + ) + ) process_cl_flags(config) diff --git a/ivy_tests/test_ivy/helpers/function_testing.py b/ivy_tests/test_ivy/helpers/function_testing.py index 0914fe641c0e2..4e0f7126b1dd4 100644 --- a/ivy_tests/test_ivy/helpers/function_testing.py +++ b/ivy_tests/test_ivy/helpers/function_testing.py @@ -529,15 +529,17 @@ def test_function( if mod_backend[backend_to_test]: # multiprocessing proc, input_queue, output_queue = mod_backend[backend_to_test] - input_queue.put(( - "function_backend_computation", - backend_to_test, - test_flags, - all_as_kwargs_np, - input_dtypes, - on_device, - fn_name, - )) + input_queue.put( + ( + "function_backend_computation", + backend_to_test, + test_flags, + all_as_kwargs_np, + input_dtypes, + on_device, + fn_name, + ) + ) ( ret_from_target, ret_np_flat_from_target, @@ -576,20 +578,22 @@ def test_function( # compute the return with a Ground Truth backend if mod_backend[ground_truth_backend]: proc, input_queue, output_queue = mod_backend[ground_truth_backend] - input_queue.put(( - "function_ground_truth_computation", - ground_truth_backend, - on_device, - args_np, - arg_np_arrays, - arrays_args_indices, - kwargs_np, - arrays_kwargs_indices, - kwarg_np_arrays, - input_dtypes, - test_flags, - fn_name, - )) + input_queue.put( + ( + "function_ground_truth_computation", + ground_truth_backend, + on_device, + args_np, + arg_np_arrays, + arrays_args_indices, + kwargs_np, + arrays_kwargs_indices, + kwarg_np_arrays, + input_dtypes, + test_flags, + fn_name, + ) + ) ( ret_from_gt, ret_np_from_gt_flat, @@ -621,13 +625,15 @@ def test_function( if test_flags.transpile: if mod_backend[backend_to_test]: proc, input_queue, output_queue = mod_backend[backend_to_test] - input_queue.put(( - "transpile_if_required_backend", - backend_to_test, - fn_name, - args_np, - kwargs_np, - )) + input_queue.put( + ( + "transpile_if_required_backend", + backend_to_test, + fn_name, + args_np, + kwargs_np, + ) + ) else: _transpile_if_required_backend( backend_to_test, fn_name, args=args_np, kwargs=kwargs_np @@ -1274,23 +1280,25 @@ def gradient_test( if mod_backend[backend_to_test]: # do this using multiprocessing proc, input_queue, output_queue = mod_backend[backend_to_test] - input_queue.put(( - "gradient_backend_computation", - backend_to_test, - args_np, - arg_np_vals, - args_idxs, - kwargs_np, - kwarg_np_vals, - kwargs_idxs, - input_dtypes, - test_flags, - on_device, - fn, - test_trace, - xs_grad_idxs, - ret_grad_idxs, - )) + input_queue.put( + ( + "gradient_backend_computation", + backend_to_test, + args_np, + arg_np_vals, + args_idxs, + kwargs_np, + kwarg_np_vals, + kwargs_idxs, + input_dtypes, + test_flags, + on_device, + fn, + test_trace, + xs_grad_idxs, + ret_grad_idxs, + ) + ) grads_np_flat = output_queue.get() else: @@ -1314,24 +1322,26 @@ def gradient_test( if mod_backend[ground_truth_backend]: # do this using multiprocessing proc, input_queue, output_queue = mod_backend[ground_truth_backend] - input_queue.put(( - "gradient_ground_truth_computation", - ground_truth_backend, - on_device, - fn, - input_dtypes, - all_as_kwargs_np, - args_np, - arg_np_vals, - args_idxs, - kwargs_np, - kwarg_np_vals, - test_flags, - kwargs_idxs, - test_trace, - xs_grad_idxs, - ret_grad_idxs, - )) + input_queue.put( + ( + "gradient_ground_truth_computation", + ground_truth_backend, + on_device, + fn, + input_dtypes, + all_as_kwargs_np, + args_np, + arg_np_vals, + args_idxs, + kwargs_np, + kwarg_np_vals, + test_flags, + kwargs_idxs, + test_trace, + xs_grad_idxs, + ret_grad_idxs, + ) + ) grads_np_from_gt_flat = output_queue.get() else: grads_np_from_gt_flat = test_gradient_ground_truth_computation( @@ -1739,22 +1749,24 @@ def test_method( if mod_backend[backend_to_test]: # yep, multiprocessing proc, input_queue, output_queue = mod_backend[backend_to_test] - input_queue.put(( - "method_backend_computation", - init_input_dtypes, - init_flags, - backend_to_test, - init_all_as_kwargs_np, - on_device, - method_input_dtypes, - method_flags, - method_all_as_kwargs_np, - class_name, - method_name, - init_with_v, - test_trace, - method_with_v, - )) + input_queue.put( + ( + "method_backend_computation", + init_input_dtypes, + init_flags, + backend_to_test, + init_all_as_kwargs_np, + on_device, + method_input_dtypes, + method_flags, + method_all_as_kwargs_np, + class_name, + method_name, + init_with_v, + test_trace, + method_with_v, + ) + ) ( ret, ret_np_flat, @@ -1803,24 +1815,26 @@ def test_method( if mod_backend[ground_truth_backend]: # yep, multiprocessing proc, input_queue, output_queue = mod_backend[ground_truth_backend] - input_queue.put(( - "method_ground_truth_computation", - ground_truth_backend, - on_device, - org_con_data, - args_np_method, - met_arg_np_vals, - met_args_idxs, - kwargs_np_method, - met_kwarg_np_vals, - met_kwargs_idxs, - method_input_dtypes, - method_flags, - class_name, - method_name, - test_trace, - v_np, - )) + input_queue.put( + ( + "method_ground_truth_computation", + ground_truth_backend, + on_device, + org_con_data, + args_np_method, + met_arg_np_vals, + met_args_idxs, + kwargs_np_method, + met_kwarg_np_vals, + met_kwargs_idxs, + method_input_dtypes, + method_flags, + class_name, + method_name, + test_trace, + v_np, + ) + ) ( ret_from_gt, ret_np_from_gt_flat, diff --git a/ivy_tests/test_ivy/helpers/multiprocessing.py b/ivy_tests/test_ivy/helpers/multiprocessing.py index 86f2d20971336..39234c644de27 100644 --- a/ivy_tests/test_ivy/helpers/multiprocessing.py +++ b/ivy_tests/test_ivy/helpers/multiprocessing.py @@ -101,19 +101,21 @@ def backend_proc(input_queue, output_queue): ) # ret_from_target to be none, because main process has # framework imports blocked - output_queue.put(( - (None), - ret_np_flat_from_target, - ret_device, - args_np, - arg_np_arrays, - arrays_args_indices, - kwargs_np, - arrays_kwargs_indices, - kwarg_np_arrays, - test_flags, - input_dtypes, - )) + output_queue.put( + ( + (None), + ret_np_flat_from_target, + ret_device, + args_np, + arg_np_arrays, + arrays_args_indices, + kwargs_np, + arrays_kwargs_indices, + kwarg_np_arrays, + test_flags, + input_dtypes, + ) + ) elif data[0] == "function_ground_truth_computation": # it's the ground_truth return computation ( @@ -150,13 +152,15 @@ def backend_proc(input_queue, output_queue): fn_name, ) # ret_from gt is none because main process has frameworks is None - output_queue.put(( - (None), - ret_np_from_gt_flat, - ret_from_gt_device, - test_flags, - fw_list, - )) + output_queue.put( + ( + (None), + ret_np_from_gt_flat, + ret_from_gt_device, + test_flags, + fw_list, + ) + ) elif data[0] == "gradient_backend_computation": # gradient testing , part where it uses the backend ( @@ -279,20 +283,22 @@ def backend_proc(input_queue, output_queue): method_with_v, ) # ret is none here, because main process doesn't import framework - output_queue.put(( - (None), - ret_np_flat, - ret_device, - org_con_data, - args_np_method, - met_arg_np_vals, - met_args_idxs, - kwargs_np_method, - met_kwarg_np_vals, - met_kwargs_idxs, - v_np, - fw_list, - )) + output_queue.put( + ( + (None), + ret_np_flat, + ret_device, + org_con_data, + args_np_method, + met_arg_np_vals, + met_args_idxs, + kwargs_np_method, + met_kwarg_np_vals, + met_kwargs_idxs, + v_np, + fw_list, + ) + ) elif data[0] == "method_ground_truth_computation": ( diff --git a/ivy_tests/test_ivy/helpers/testing_helpers.py b/ivy_tests/test_ivy/helpers/testing_helpers.py index 6c76e6e9f645a..5830b076674f6 100644 --- a/ivy_tests/test_ivy/helpers/testing_helpers.py +++ b/ivy_tests/test_ivy/helpers/testing_helpers.py @@ -231,13 +231,15 @@ def _get_method_supported_devices_dtypes( if mod_backend[backend_str]: # we gotta do this using multiprocessing proc, input_queue, output_queue = mod_backend[backend_str] - input_queue.put(( - "method supported dtypes", - method_name, - class_module.__name__, - class_name, - backend_str, - )) + input_queue.put( + ( + "method supported dtypes", + method_name, + class_module.__name__, + class_name, + backend_str, + ) + ) supported_device_dtypes[backend_str] = output_queue.get() else: supported_device_dtypes[backend_str] = ( diff --git a/scripts/backend_generation/tree_generation.py b/scripts/backend_generation/tree_generation.py index 51834c55bb8c6..7c94d01ef603c 100644 --- a/scripts/backend_generation/tree_generation.py +++ b/scripts/backend_generation/tree_generation.py @@ -292,15 +292,17 @@ def generate(config_file): generated_file.write(astunparse.unparse(tree_to_write)) subprocess.run(["black", "-q", backend_generation_path]) - subprocess.run([ - "autoflake", - "-i", - "--remove-all-unused-imports", - "--ignore-init-module-imports", - "--quiet", - "-r", - backend_generation_path, - ]) + subprocess.run( + [ + "autoflake", + "-i", + "--remove-all-unused-imports", + "--ignore-init-module-imports", + "--quiet", + "-r", + backend_generation_path, + ] + ) if __name__ == "__main__":