New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added code examples for ix_ function with better doc string. #20327
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
It's already signed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but please note that the implements
decorator will overwrite any docstring you define in the function. If you want to be able to add a customized docstring, we'll have to modify that decorator (or remove it, but I believe we have tests to check that all public APIs have this decorator)
Also, it looks like this content was copied from the text within numpy repository. We cannot have verbatim copies of other open source projects as part of the JAX source code, because it violates the OSS license requirements. If you want to write a docstring for this function, I'd suggest doing it from scratch, without referencing the original NumPy docstring. Alternatively, we can put the text in jax/third_party
and reference it here, although that's a bit awkward in the case of docstrings.
This licensing issue is one of the reasons we have not done this kind of docstring specialization in the past, instead relying on runtime rewrites via arguments to implements
.
Hi @jakevdp Is the following modification a doable solution for inserting embedded code examples (customized to JAX) for NumPy and SciPy? We would use @util.implements(np.ix_, lax_description="""Example:
>>> import jax.numpy as jnp
>>> a = jnp.arange(10).reshape(2, 5)
>>> a
Array([[0, 1, 2, 3, 4],
[5, 6, 7, 8, 9]], dtype=int32)
>>> ixgrid = jnp.ix_(jnp.array([0, 1]), jnp.array([2, 4]))
>>> ixgrid
(Array([[0],
[1]], dtype=int32), Array([[2, 4]], dtype=int32))
>>> ixgrid[0].shape, ixgrid[1].shape
((2, 1), (1, 2))
>>> a[ixgrid]
Array([[2, 4],
[7, 9]], dtype=int32)""")
def ix_(*args: ArrayLike) -> tuple[Array, ...]:
util.check_arraylike("ix", *args) If not, I will do it from scratch as you suggested earlier, without referencing the original NumPy docstring. Since the CLA has failed here, I will close and raise another PR. |
Typically the example comes below the description of the function parameters. I think in this case it would be best to rewrite the docstring from scratch. I'm doing some similar work in #20941 – you can do something similar for this case. |
Oh, and please don't open a new PR if possible – it's useful to keep all the conversation in one place. The failing CLA is probably due to whatever email you have attached to the commits on your branch: you can undo previous commits and redo new commits with the correct email in order to update this branch |
2c2893b
to
c6b8554
Compare
It make sene, docstring is rewritten from scratch and tried to squash the commits. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good! A few formatting pieces below (you might try building the docs locally to make sure the formatting is acceptable, rather than waiting for the github CI).
Also, you might add a See also
section that links to meshgrid
, mgrid
, and ogrid
Thanks @jakevdp 'See also' section added and indentations corrected. Locally, the formatting appears as follows: |
Thanks @jakevdp
|
unnecessary texts and example outputs are modified/removed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small change requested below. Also
Please run the linter on your change (see https://jax.readthedocs.io/en/latest/contributing.html#linting-and-type-checking)
I think you'll have to add ix_
to this list to satisfy tests:
Line 6021 in 17d0eb3
known_exceptions = { |
Finally, once you've made all changes, please squash everything into a single commit; see https://jax.readthedocs.io/en/latest/contributing.html#single-change-commits-and-pull-requests for details.
Looks like there are some lint issues with whitespace. You can fix these locally by running |
It seems the lint failure was below: removing whitespace before the following lines: resolve the issue? running
|
Yeah, removing all trailing whitespace should fix the error. Regarding the |
It seems like some other commits snuck into your PR! It looks like you both rebased and merged, but targeted different snapshots of the
In most cases this should work, though admittedly I don't really know what you've done to your local branch, so if you've done something really strange (like merged against branches with conflicts) then you may have to do more to fix it. |
It seems like some other commits snuck into your PR! It looks like you both rebased and merged, but targeted different snapshots of the
In most cases this should work, though admittedly I don't really know what you've done to your local branch, so if you've done something really strange (like merged against branches with conflicts) then you may have to do more to fix it. |
No description provided.