From 9119ddd838cd65acc1307851bcaa603d22a23703 Mon Sep 17 00:00:00 2001 From: Mahmoud Ashraf <32404268+MahmoudAshraf97@users.noreply.github.com> Date: Wed, 15 Mar 2023 16:43:35 +0200 Subject: [PATCH 1/4] fix complex behaviour in ivy.divide --- ivy/functional/backends/jax/elementwise.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ivy/functional/backends/jax/elementwise.py b/ivy/functional/backends/jax/elementwise.py index 2f460f9150a22..a5aa4e8ef6fa9 100644 --- a/ivy/functional/backends/jax/elementwise.py +++ b/ivy/functional/backends/jax/elementwise.py @@ -154,7 +154,7 @@ def divide( ) -> JaxArray: x1, x2 = ivy.promote_types_of_inputs(x1, x2) ret = jax.numpy.divide(x1, x2) - if ivy.is_float_dtype(x1.dtype): + if ivy.is_float_dtype(x1.dtype) or ivy.is_complex_dtype(x1.dtype): ret = jnp.asarray(ret, dtype=x1.dtype) else: ret = jnp.asarray(ret, dtype=ivy.default_float_dtype(as_native=True)) From 6c4c5e907a7d4beb41b6911edc2139834ed4d493 Mon Sep 17 00:00:00 2001 From: Mahmoud Ashraf <32404268+MahmoudAshraf97@users.noreply.github.com> Date: Wed, 15 Mar 2023 16:44:15 +0200 Subject: [PATCH 2/4] fix complex behaviour in ivy.divide --- ivy/functional/backends/numpy/elementwise.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ivy/functional/backends/numpy/elementwise.py b/ivy/functional/backends/numpy/elementwise.py index 14eb434a2c23f..2e34930b2d647 100644 --- a/ivy/functional/backends/numpy/elementwise.py +++ b/ivy/functional/backends/numpy/elementwise.py @@ -232,7 +232,7 @@ def divide( ) -> np.ndarray: x1, x2 = ivy.promote_types_of_inputs(x1, x2) ret = np.divide(x1, x2, out=out) - if ivy.is_float_dtype(x1): + if ivy.is_float_dtype(x1.dtype) or ivy.is_complex_dtype(x1.dtype): ret = np.asarray(ret, dtype=x1.dtype) else: ret = np.asarray(ret, dtype=ivy.default_float_dtype(as_native=True)) From 16cce000ce4a25c1186da5138527dc721e424f6f Mon Sep 17 00:00:00 2001 From: Mahmoud Ashraf <32404268+MahmoudAshraf97@users.noreply.github.com> Date: Wed, 15 Mar 2023 16:45:16 +0200 Subject: [PATCH 3/4] fix complex behaviour in ivy.divide --- ivy/functional/backends/tensorflow/elementwise.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ivy/functional/backends/tensorflow/elementwise.py b/ivy/functional/backends/tensorflow/elementwise.py index 1ea85b8321fb1..59b16362ce591 100644 --- a/ivy/functional/backends/tensorflow/elementwise.py +++ b/ivy/functional/backends/tensorflow/elementwise.py @@ -227,7 +227,7 @@ def divide( ) -> Union[tf.Tensor, tf.Variable]: x1, x2 = ivy.promote_types_of_inputs(x1, x2) ret = tf.experimental.numpy.divide(x1, x2) - if ivy.is_float_dtype(x1.dtype): + if ivy.is_float_dtype(x1.dtype) or ivy.is_complex_dtype(x1.dtype): ret = tf.cast(ret, dtype=x1.dtype) else: ret = tf.cast(ret, dtype=ivy.default_float_dtype(as_native=True)) From 64814ce2d113d8b7755336b72adbc70f53312c54 Mon Sep 17 00:00:00 2001 From: Mahmoud Ashraf <32404268+MahmoudAshraf97@users.noreply.github.com> Date: Wed, 15 Mar 2023 16:45:46 +0200 Subject: [PATCH 4/4] fix complex behaviour in ivy.divide --- ivy/functional/backends/torch/elementwise.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ivy/functional/backends/torch/elementwise.py b/ivy/functional/backends/torch/elementwise.py index 7eb33204b8b0c..3cee2aefcd638 100644 --- a/ivy/functional/backends/torch/elementwise.py +++ b/ivy/functional/backends/torch/elementwise.py @@ -291,7 +291,7 @@ def divide( ) -> torch.Tensor: x1, x2 = ivy.promote_types_of_inputs(x1, x2) ret = torch.div(x1, x2) - if ivy.is_float_dtype(x1.dtype): + if ivy.is_float_dtype(x1.dtype) or ivy.is_complex_dtype(x1.dtype): ret = ivy.astype(ret, x1.dtype, copy=False) else: ret = ivy.astype(ret, ivy.default_float_dtype(as_native=True), copy=False)