diff --git a/ivy/functional/frontends/jax/array.py b/ivy/functional/frontends/jax/array.py index 2e049123c166a..7d41f138f9598 100644 --- a/ivy/functional/frontends/jax/array.py +++ b/ivy/functional/frontends/jax/array.py @@ -413,6 +413,16 @@ def var( def swapaxes(self, axis1, axis2): return jax_frontend.numpy.swapaxes(self, axis1=axis1, axis2=axis2) + def floor(self): + return jax_frontend.numpy.floor(self) + + def floor_(self): + self._ivy_array = ivy.inplace_update(self._ivy_array, ivy.floor(self._ivy_array)) + return self + + def tolist(self): + return ivy.to_list(self.ivy_array) + # Jax supports DeviceArray from 0.4.13 and below # Hence aliasing it here diff --git a/ivy/functional/frontends/numpy/ndarray/ndarray.py b/ivy/functional/frontends/numpy/ndarray/ndarray.py index c248bea37f627..dba4faa5e284a 100644 --- a/ivy/functional/frontends/numpy/ndarray/ndarray.py +++ b/ivy/functional/frontends/numpy/ndarray/ndarray.py @@ -649,6 +649,13 @@ def __lshift__(self, value, /): def __ilshift__(self, value, /): return ivy.bitwise_left_shift(self.ivy_array, value, out=self) + def floor(self): + return np_frontend.floor(self) + + def floor_(self): + self._ivy_array = ivy.inplace_update(self._ivy_array, ivy.floor(self._ivy_array)) + return self + def round(self, decimals=0, out=None): return np_frontend.round(self, decimals=decimals, out=out) diff --git a/ivy/functional/frontends/tensorflow/tensor.py b/ivy/functional/frontends/tensorflow/tensor.py index b9b9745af3ae3..e309fb8b063bc 100644 --- a/ivy/functional/frontends/tensorflow/tensor.py +++ b/ivy/functional/frontends/tensorflow/tensor.py @@ -225,6 +225,16 @@ def __iter__(self): for i in range(self.shape[0]): yield self[i] + def floor(self): + return tensorflow_frontend.floor(self) + + def floor_(self): + self.ivy_array = ivy.inplace_update(self.ivy_array, ivy.floor(self.ivy_array)) + return self + + def tolist(self): + return ivy.to_list(self.ivy_array) + class TensorShape: # TODO: there are still some methods that may need implementing diff --git a/ivy_tests/test_ivy/test_frontends/test_jax/test_array.py b/ivy_tests/test_ivy/test_frontends/test_jax/test_array.py index 546387bf6b111..77b76dd36535a 100644 --- a/ivy_tests/test_ivy/test_frontends/test_jax/test_array.py +++ b/ivy_tests/test_ivy/test_frontends/test_jax/test_array.py @@ -2826,3 +2826,120 @@ def test_jax_swapaxes( method_flags=method_flags, on_device=on_device, ) + + +# tolist +@handle_frontend_method( + class_tree=CLASS_TREE, + init_tree="jax.numpy.array", + method_name="tolist", + dtype_and_x=helpers.dtype_and_values( + available_dtypes=helpers.get_dtypes("valid"), + min_num_dims=0, + max_num_dims=5, + min_dim_size=1, + max_dim_size=10, + min_value=-1e05, + max_value=1e05, + ), +) +def test_jax_array_tolist( + dtype_and_x, + frontend_method_data, + init_flags, + method_flags, + frontend, + on_device, + backend_fw, +): + input_dtypes, x = dtype_and_x + helpers.test_frontend_method( + init_input_dtypes=input_dtypes, + backend_to_test=backend_fw, + init_all_as_kwargs_np={ + "object": x[0], + }, + method_input_dtypes=input_dtypes, + method_all_as_kwargs_np={}, + frontend_method_data=frontend_method_data, + init_flags=init_flags, + method_flags=method_flags, + frontend=frontend, + on_device=on_device, + test_values=False, # tolist returns Python list, not array + ) + + +# floor +@handle_frontend_method( + class_tree=CLASS_TREE, + init_tree="jax.numpy.array", + method_name="floor", + dtype_and_x=helpers.dtype_and_values( + available_dtypes=helpers.get_dtypes("float"), + min_value=-1e05, + max_value=1e05, + ), +) +def test_jax_array_floor( + dtype_and_x, + frontend_method_data, + init_flags, + method_flags, + frontend, + on_device, + backend_fw, +): + input_dtypes, x = dtype_and_x + helpers.test_frontend_method( + init_input_dtypes=input_dtypes, + backend_to_test=backend_fw, + init_all_as_kwargs_np={ + "object": x[0], + }, + method_input_dtypes=input_dtypes, + method_all_as_kwargs_np={}, + frontend_method_data=frontend_method_data, + init_flags=init_flags, + method_flags=method_flags, + frontend=frontend, + on_device=on_device, + ) + + +# floor_ +@handle_frontend_method( + class_tree=CLASS_TREE, + init_tree="jax.numpy.array", + method_name="floor_", + dtype_and_x=helpers.dtype_and_values( + available_dtypes=helpers.get_dtypes("float"), + min_value=-1e05, + max_value=1e05, + ), + test_inplace=st.just(True), +) +def test_jax_array_floor_( + dtype_and_x, + frontend_method_data, + init_flags, + method_flags, + frontend, + on_device, + backend_fw, +): + input_dtypes, x = dtype_and_x + helpers.test_frontend_method( + init_input_dtypes=input_dtypes, + backend_to_test=backend_fw, + init_all_as_kwargs_np={ + "object": x[0], + }, + method_input_dtypes=input_dtypes, + method_all_as_kwargs_np={}, + frontend_method_data=frontend_method_data, + init_flags=init_flags, + method_flags=method_flags, + frontend=frontend, + on_device=on_device, + ) diff --git a/ivy_tests/test_ivy/test_frontends/test_numpy/test_ndarray/test_ndarray.py b/ivy_tests/test_ivy/test_frontends/test_numpy/test_ndarray/test_ndarray.py index 6404b98dade7f..dbb5d4e179776 100644 --- a/ivy_tests/test_ivy/test_frontends/test_numpy/test_ndarray/test_ndarray.py +++ b/ivy_tests/test_ivy/test_frontends/test_numpy/test_ndarray/test_ndarray.py @@ -3878,3 +3878,78 @@ def test_numpy_view( frontend_method_data=frontend_method_data, on_device=on_device, ) + + +# floor +@handle_frontend_method( + class_tree=CLASS_TREE, + init_tree="numpy.array", + method_name="floor", + dtype_and_x=helpers.dtype_and_values( + available_dtypes=helpers.get_dtypes("float"), + min_value=-1e05, + max_value=1e05, + ), +) +def test_numpy_ndarray_floor( + dtype_and_x, + frontend_method_data, + init_flags, + method_flags, + frontend, + on_device, + backend_fw, +): + input_dtypes, x = dtype_and_x + helpers.test_frontend_method( + init_input_dtypes=input_dtypes, + backend_to_test=backend_fw, + init_all_as_kwargs_np={ + "object": x[0], + }, + method_input_dtypes=input_dtypes, + method_all_as_kwargs_np={}, + init_flags=init_flags, + method_flags=method_flags, + frontend=frontend, + frontend_method_data=frontend_method_data, + on_device=on_device, + ) + + +# floor_ +@handle_frontend_method( + class_tree=CLASS_TREE, + init_tree="numpy.array", + method_name="floor_", + dtype_and_x=helpers.dtype_and_values( + available_dtypes=helpers.get_dtypes("float"), + min_value=-1e05, + max_value=1e05, + ), + test_inplace=st.just(True), +) +def test_numpy_ndarray_floor_( + dtype_and_x, + frontend_method_data, + init_flags, + method_flags, + frontend, + on_device, + backend_fw, +): + input_dtypes, x = dtype_and_x + helpers.test_frontend_method( + init_input_dtypes=input_dtypes, + backend_to_test=backend_fw, + init_all_as_kwargs_np={ + "object": x[0], + }, + method_input_dtypes=input_dtypes, + method_all_as_kwargs_np={}, + init_flags=init_flags, + method_flags=method_flags, + frontend=frontend, + frontend_method_data=frontend_method_data, + on_device=on_device, + ) diff --git a/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_tensor.py b/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_tensor.py index 153f2089e184b..26b6712b8088e 100644 --- a/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_tensor.py +++ b/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_tensor.py @@ -1607,3 +1607,120 @@ def test_tensorflow_shape( x.ivy_array.shape, ivy.Shape(shape), as_array=False ) ivy.previous_backend() + + +# tolist +@handle_frontend_method( + class_tree=CLASS_TREE, + init_tree="tensorflow.constant", + method_name="tolist", + dtype_and_x=helpers.dtype_and_values( + available_dtypes=helpers.get_dtypes("valid"), + min_num_dims=0, + max_num_dims=5, + min_dim_size=1, + max_dim_size=10, + min_value=-1e05, + max_value=1e05, + ), +) +def test_tensorflow_tensor_tolist( + dtype_and_x, + frontend_method_data, + init_flags, + method_flags, + frontend, + on_device, + backend_fw, +): + input_dtypes, x = dtype_and_x + helpers.test_frontend_method( + init_input_dtypes=input_dtypes, + backend_to_test=backend_fw, + init_all_as_kwargs_np={ + "value": x[0], + }, + method_input_dtypes=input_dtypes, + method_all_as_kwargs_np={}, + frontend_method_data=frontend_method_data, + init_flags=init_flags, + method_flags=method_flags, + frontend=frontend, + on_device=on_device, + test_values=False, # tolist returns Python list, not array + ) + + +# floor +@handle_frontend_method( + class_tree=CLASS_TREE, + init_tree="tensorflow.constant", + method_name="floor", + dtype_and_x=helpers.dtype_and_values( + available_dtypes=helpers.get_dtypes("float"), + min_value=-1e05, + max_value=1e05, + ), +) +def test_tensorflow_tensor_floor( + dtype_and_x, + frontend_method_data, + init_flags, + method_flags, + frontend, + on_device, + backend_fw, +): + input_dtypes, x = dtype_and_x + helpers.test_frontend_method( + init_input_dtypes=input_dtypes, + backend_to_test=backend_fw, + init_all_as_kwargs_np={ + "value": x[0], + }, + method_input_dtypes=input_dtypes, + method_all_as_kwargs_np={}, + frontend_method_data=frontend_method_data, + init_flags=init_flags, + method_flags=method_flags, + frontend=frontend, + on_device=on_device, + ) + + +# floor_ +@handle_frontend_method( + class_tree=CLASS_TREE, + init_tree="tensorflow.constant", + method_name="floor_", + dtype_and_x=helpers.dtype_and_values( + available_dtypes=helpers.get_dtypes("float"), + min_value=-1e05, + max_value=1e05, + ), + test_inplace=st.just(True), +) +def test_tensorflow_tensor_floor_( + dtype_and_x, + frontend_method_data, + init_flags, + method_flags, + frontend, + on_device, + backend_fw, +): + input_dtypes, x = dtype_and_x + helpers.test_frontend_method( + init_input_dtypes=input_dtypes, + backend_to_test=backend_fw, + init_all_as_kwargs_np={ + "value": x[0], + }, + method_input_dtypes=input_dtypes, + method_all_as_kwargs_np={}, + frontend_method_data=frontend_method_data, + init_flags=init_flags, + method_flags=method_flags, + frontend=frontend, + on_device=on_device, + )