Add tolist method to JAX Array and TensorFlow EagerTensor frontends#28917
Conversation
…r frontends - Add tolist() instance method to JAX Array frontend class - Add tolist() instance method to TensorFlow EagerTensor frontend class - Both methods use ivy.to_list() for consistency with existing implementations - Add comprehensive test cases for both frontend implementations - Resolves issue ivy-llc#19170 The tolist method converts arrays/tensors to Python lists, providing compatibility with native framework APIs. This completes the tolist functionality across all major Ivy frontends (NumPy, PyTorch, TensorFlow, JAX, and Paddle). Co-authored-by: Kallal Mukherjee <ritamukherje62@gmail.com>
- Document that test_torch_avg_pool2d failure is unrelated to tolist implementation - Clarify that our tolist methods are working correctly and isolated - Provide analysis of the dtype issue in pooling functions - Confirm our changes are safe and follow established patterns
Test Status UpdateI've noticed there's a failing test in the CI, but I want to clarify that this test failure is completely unrelated to our Failing Test (Unrelated)Test: AnalysisThis is a pre-existing issue with dtype handling in the PyTorch frontend's Our Changes Are Safe
Our Implementation Tests# JAX Array tolist - Working
jax_array = jax_frontend.Array([[1, 2, 3], [4, 5, 6]])
result = jax_array.tolist() # Returns [[1, 2, 3], [4, 5, 6]]
# TensorFlow EagerTensor tolist - Working
tf_tensor = tf_frontend.EagerTensor([[1, 2, 3], [4, 5, 6]])
result = tf_tensor.tolist() # Returns [[1, 2, 3], [4, 5, 6]]DocumentationI've added Summary: The failing test is a pre-existing pooling function issue unrelated to our |
Sam-Armstrong
left a comment
There was a problem hiding this comment.
Yeah that's fine, don't worry about the other test failure. Could you just remove the TEST_STATUS_NOTES.md file you've added, and address the other couple of comments I've made, then we should be good to merge. Thanks for the contribution!
| min_num_dims=0, | ||
| max_num_dims=5, | ||
| min_dim_size=1, | ||
| max_dim_size=10, |
There was a problem hiding this comment.
| 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)
There was a problem hiding this comment.
Removed TEST_STATUS_NOTES.md file - Eliminated unnecessary documentation clutter
| min_num_dims=0, | ||
| max_num_dims=5, | ||
| min_dim_size=1, | ||
| max_dim_size=10, |
There was a problem hiding this comment.
| max_dim_size=10, | |
| max_dim_size=10, | |
| min_value=-1e05, | |
| max_value=1e05, |
same here
There was a problem hiding this comment.
Removed docstrings from frontend methods - Now follows Ivy's convention for clean, minimal frontend implementations
| """Convert the array to a (possibly nested) list. | ||
|
|
||
| Returns | ||
| ------- | ||
| list | ||
| A list representation of the array. | ||
| """ |
There was a problem hiding this comment.
| """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.
There was a problem hiding this comment.
Added value limits to test cases - Both tests now include min_value=-1e05 and max_value=1e05 to prevent overflow with high example counts
| """Convert the tensor to a (possibly nested) list. | ||
|
|
||
| Returns | ||
| ------- | ||
| list | ||
| A list representation of the tensor. | ||
| """ |
There was a problem hiding this comment.
| """Convert the tensor to a (possibly nested) list. | |
| Returns | |
| ------- | |
| list | |
| A list representation of the tensor. | |
| """ |
- Remove TEST_STATUS_NOTES.md file as requested - Remove docstrings from frontend methods following Ivy convention - Add min_value and max_value parameters to test cases to prevent overflow - Ensure tests work correctly with high number of examples (--num-examples 100) Thanks for the feedback @Sam-Armstrong! Ready for merge.
…ithub.com/7908837174/ivy-KALLAL into feature/implement-tolist-frontend-methods
|
Hi @Sam-Armstrong! Thanks for the quick review and helpful feedback! I've addressed all your comments: Changes Made:
Updated Implementation:JAX Array: def tolist(self):
return ivy.to_list(self.ivy_array)TensorFlow EagerTensor: def tolist(self):
return ivy.to_list(self.ivy_array)Test configurations now include: 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, # ← Added
max_value=1e05, # ← Added
),The implementation is now much cleaner and follows Ivy's conventions properly. Should be ready for merge! Thanks again for the guidance and for helping me learn the Ivy codebase conventions! |
|
Thank you 🙂..
…On Tue, 22 Jul, 2025, 03:33 Sam Armstrong, ***@***.***> wrote:
Merged #28917 <#28917> into main.
—
Reply to this email directly, view it on GitHub
<#28917 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/BLR2IIOW2O3BT3YNIVKDYH33JVPTPAVCNFSM6AAAAACB7QNKOSVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJYG4ZTONZSGM3TQMI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
What does this PR do?
This PR implements the missing
tolist()method for JAX Array and TensorFlow EagerTensor frontend classes, resolving issue #19170.Description
I noticed that while most Ivy frontends (NumPy, PyTorch, Paddle) already have the
tolist()method implemented, JAX and TensorFlow frontends were missing this functionality. This creates inconsistency in the API and can cause issues when users expect this method to be available.Changes Made
JAX Array Frontend (
ivy/functional/frontends/jax/array.py)tolist()instance method that callsivy.to_list(self.ivy_array)TensorFlow EagerTensor Frontend (
ivy/functional/frontends/tensorflow/tensor.py)tolist()instance method that callsivy.to_list(self.ivy_array)Test Coverage
tolist()methodtolist()methodTesting
I've tested the implementation with various array shapes and data types:
Consistency Check
Verified that existing implementations in other frontends work correctly:
return self._ivy_array.to_list()return self.ivy_array.to_list()All implementations now use the same underlying
ivy.to_list()function for consistency.Why This Matters
tolistfunctionalitytolist()being available across all frontendsChecklist
Related Issues
Closes #19170
Note: This implementation maintains full backward compatibility and doesn't modify any existing functionality. It simply adds the missing methods that users would naturally expect to be available.
Looking forward to your feedback! 😊