Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions TEST_STATUS_NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Test Status Notes for PR #28917

**Author:** Kallal Mukherjee (7908837174)
**PR:** Add tolist method to JAX Array and TensorFlow EagerTensor frontends
**Issue:** #19170

## Test Results Summary

### ✅ Our Implementation Tests
- **JAX Array tolist**: ✅ Working correctly
- **TensorFlow EagerTensor tolist**: ✅ Working correctly
- **Implementation**: Both methods use `ivy.to_list(self.ivy_array)` for consistency

### ❌ Unrelated Test Failure
**Test:** `test_torch_avg_pool2d[cpu-numpy-False-False]`
**Error:** `AssertionError: returned dtype = float64, ground-truth returned dtype = float32`
**Status:** **NOT RELATED TO OUR CHANGES**

This test failure is in the PyTorch frontend pooling functions and is a pre-existing issue with dtype handling in the `avg_pool2d` function. It has nothing to do with our `tolist` method implementations.

### Analysis of the Failing Test
- **File:** `ivy_tests/test_ivy/test_frontends/test_torch/test_nn/test_functional/test_pooling_functions.py`
- **Function:** `test_torch_avg_pool2d`
- **Issue:** The function returns `float64` when it should return `float32`
- **Root Cause:** Dtype preservation issue in the pooling implementation, not our tolist methods

### Our Changes Are Safe
1. ✅ **No modifications to existing functionality**
2. ✅ **Only added new methods to JAX and TensorFlow frontends**
3. ✅ **Used existing `ivy.to_list()` function for consistency**
4. ✅ **Added proper test coverage for our new methods**
5. ✅ **No impact on pooling functions or dtype handling**

### Verification
Our `tolist` implementations:
- Use the same pattern as existing frontends (NumPy, PyTorch, Paddle)
- Call `ivy.to_list(self.ivy_array)` which is already tested and working
- Return Python lists, not arrays (no dtype issues)
- Are completely isolated from pooling functionality

## Conclusion
The failing test is a pre-existing issue unrelated to our `tolist` implementation. Our changes are safe, well-tested, and follow Ivy's established patterns.
10 changes: 10 additions & 0 deletions ivy/functional/frontends/jax/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,16 @@ def var(
def swapaxes(self, axis1, axis2):
return jax_frontend.numpy.swapaxes(self, axis1=axis1, axis2=axis2)

def tolist(self):
"""Convert the array to a (possibly nested) list.

Returns
-------
list
A list representation of the array.
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Convert the array to a (possibly nested) list.
Returns
-------
list
A list representation of the array.
"""

The convention we've been following is to not include docstrings for frontend functions/methods, so you can remove these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added value limits to test cases - Both tests now include min_value=-1e05 and max_value=1e05 to prevent overflow with high example counts

return ivy.to_list(self.ivy_array)


# Jax supports DeviceArray from 0.4.13 and below
# Hence aliasing it here
Expand Down
10 changes: 10 additions & 0 deletions ivy/functional/frontends/tensorflow/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ def __iter__(self):
for i in range(self.shape[0]):
yield self[i]

def tolist(self):
"""Convert the tensor to a (possibly nested) list.

Returns
-------
list
A list representation of the tensor.
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Convert the tensor to a (possibly nested) list.
Returns
-------
list
A list representation of the tensor.
"""

return ivy.to_list(self.ivy_array)


class TensorShape:
# TODO: there are still some methods that may need implementing
Expand Down
40 changes: 40 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_jax/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -2826,3 +2826,43 @@ 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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
max_dim_size=10,
max_dim_size=10,
min_value=-1e05,
max_value=1e05,

We need to add this so the values don't overflow and fail the test when running with a high number of examples (--num-examples 100)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed TEST_STATUS_NOTES.md file - Eliminated unnecessary documentation clutter

),
)
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
)
40 changes: 40 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_tensorflow/test_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1607,3 +1607,43 @@ 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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
max_dim_size=10,
max_dim_size=10,
min_value=-1e05,
max_value=1e05,

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed docstrings from frontend methods - Now follows Ivy's convention for clean, minimal frontend implementations

),
)
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
)