Skip to content
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

Function reformatting vector_norm #10457

Merged
merged 8 commits into from
Feb 17, 2023

Conversation

nikifaets
Copy link
Contributor

@nikifaets nikifaets commented Feb 9, 2023

Close #10311

@nikifaets
Copy link
Contributor Author

nikifaets commented Feb 9, 2023

Added docstring examples in:

  • ivy functional method
  • array method
  • container instance and static method

While writing the examples, I suspect I found two bugs:

  • numpy backend implementation of vector_norm is returning false result when norm is inf or -inf:
>>> x = ivy.array([[1., 2., 3.], [2., -1., 0.]])
>>> ivy.functional.backends.numpy.linalg.vector_norm(x, axis = 0, ord = float("inf"))
array([1., 1., 1.], dtype=float32)
>>> np.linalg.norm(x, axis = 0, ord = float("inf"))
array([2., 2., 3.], dtype=float32)

  • container in static method is not working for arrays:
>>> x = ivy.array([1,2,3])
>>> ivy.Container.static_vector_norm(x)
  File "<stdin>", line 1, in <module>
  File "/home/nikifaets/code/ivy/ivy/container/linear_algebra.py", line 2721, in static_vector_norm
    ) -> ivy.Container:
  File "/home/nikifaets/code/ivy/ivy/container/base.py", line 209, in cont_multi_map_in_function
    cont0 = conts[0]

IndexError: list index out of range

@ivy-leaves ivy-leaves added Array API Conform to the Array API Standard, created by The Consortium for Python Data API Standards Ivy Functional API labels Feb 9, 2023
@guillesanbri
Copy link
Contributor

Hi! Thank you for the contribution! As this is a formatting task, please, follow the steps here https://lets-unify.ai/ivy/contributing/open_tasks.html#formatting-checklist 🙂 Thanks!

@guillesanbri
Copy link
Contributor

Added docstring examples in:

  • ivy functional method
  • array method
  • container instance and static method

While writing the examples, I suspect I found two bugs:

  • numpy backend implementation of vector_norm is returning false result when norm is inf or -inf:
>>> x = ivy.array([[1., 2., 3.], [2., -1., 0.]])
>>> ivy.functional.backends.numpy.linalg.vector_norm(x, axis = 0, ord = float("inf"))
array([1., 1., 1.], dtype=float32)
>>> np.linalg.norm(x, axis = 0, ord = float("inf"))
array([2., 2., 3.], dtype=float32)
  • container in static method is not working for arrays:
>>> x = ivy.array([1,2,3])
>>> ivy.Container.static_vector_norm(x)
  File "<stdin>", line 1, in <module>
  File "/home/nikifaets/code/ivy/ivy/container/linear_algebra.py", line 2721, in static_vector_norm
    ) -> ivy.Container:
  File "/home/nikifaets/code/ivy/ivy/container/base.py", line 209, in cont_multi_map_in_function
    cont0 = conts[0]

IndexError: list index out of range

seems like vector_norm is not working correctly indeed, thanks for the heads up! Can you please open a separate issue with the first example? this is definitely a bug

Regarding the second example, I don't think that's the expected use of the function, I'll confirm and update!

@nikifaets
Copy link
Contributor Author

nikifaets commented Feb 10, 2023

Reformatting Task Checklist

IMPORTANT NOTICE 🚨:

The Ivy Docs represent the ground truth for the task descriptions and this checklist should only be used as a supplementary item to aid with the review process.

LEGEND 🗺:

  • ❌ : Check item is not completed.
  • ✅ : Check item is ready for review.
  • 🆘 : Stuck/Doubting implementation (PR author should add comments explaining why).
  • ⏩ : Check is not applicable to function (skip).
  • 🆗 : Check item is already implemented and does not require any edits.

CHECKS 📑:

    • 🆗: Make sure that the aforementioned methods are added into the correct category-specific parent class, such as ivy.ArrayWithElementwise, ivy.ContainerWithManipulation etc.
    • ✅: Add the correct Docstrings to every function and its relevant methods, including those you did not implement yourself. The following should be added:
        • ✅: The function's Array API standard description in ivy/functional/linear_algebra.py. If the function is not part of the Array API standard then a description of similar style should be added to the same file.
          The following modifications should be made to the description:
          • 🆗: Remove type definitions in the Parameters and Returns sections.
          • 🆗: Add out to the Parameters section if function accepts an out argument.
          • 🆗: Replace out with ret in the Returns section.
    • ✅: Add thorough Docstring Examples for every function and its relevant methods and ensure they pass the docstring tests.

      Functional Examples in ivy/functional/linear_algebra.py.

        • ✅: Cover all possible variants for each of the arguments independently (not combinatorily).
        • ✅: Vary the values and input shapes considerably between examples.
        • ✅: Start out simple and get more complex with each example.
        • ✅: Show an example with:
          • ✅: out unused.
          • ✅: out used to update a new array y.
          • ⏩: out used to inplace update the input array x (if x has the same dtype and shape as the return).
        • ⏩: If broadcasting is relevant for the function, then show examples which highlight this.

      Nestable Function Examples in ivy/functional/linear_algebra.py.
      Only if the function supports nestable operations.

        • ✅: Add an example that passes in an ivy.Container instance in place of one of the arguments.
        • ⏩: Add an example passes in ivy.Container instances for multiple arguments.

      Container Static Method Examples in ivy/container/linear_algebra.py.

        • ✅: The example from point (6.f) should be replicated, but added to the ivy.Container static method docstring in with ivy.<func_name> replaced with ivy.Container.static_<func_name> in the example.
        • ⏩: The example from point (6.g) should be replicated, but added to the ivy.Container static method docstring, with ivy.<func_name> replaced with ivy.Container.static_<func_name> in the example.

      Array Instance Method Example in ivy/array/linear_algebra.py.

        • ✅: Call this instance method of the ivy.Array class.

      Container Instance Method Example in ivy/container/linear_algebra.py.

        • ✅: Call this instance method of the ivy.Container class.

      Array Operator Examples in ivy/array/array.py.

        • ⏩: Call the operator on two ivy.Array instances.
        • ⏩: Call the operator with an ivy.Array instance on the left and ivy.Container on the right.

      Array Reverse Operator Example in ivy/array/array.py.

        • ⏩: Call the operator with a Number on the left and an ivy.Array instance on the right.

      Container Operator Examples in ivy/container/container.py.

        • ⏩: Call the operator on two ivy.Container instances containing Number instances at the leaves.
        • ⏩: Call the operator on two ivy.Container instances containing ivy.Array instances at the leaves.
        • ⏩: Call the operator with an ivy.Container instance on the left and ivy.Array on the right.

      Container Reverse Operator Example in ivy/container/container.py.

        • ⏩: Following example in the ivy.Container.__radd__ docstring, with the operator called with a Number on the left and an ivy.Container instance on the right.

      Tests

        • 🆘: Docstring examples tests passing.
        • 🆗: Lint checks passing.

@nikifaets
Copy link
Contributor Author

nikifaets commented Feb 10, 2023

@guillesanbri I opened the bug report for the numpy backend case: #10480

I believe this PR is ready for review.

Regarding the SOS for the docstring tests:
I see they are not run as a CI job. If I understand correctly the config in test-docstrings.yml, the PR needs the Function Reformatting label to trigger the job?

However, I ran the docstring tests locally. In the logs I see the tests only check the backend docstrings which does not cover any of my changes. Am I missing something on how to run the docstrings tests with 100% coverage or specifically for my files/methods?

I used pytest ivy_tests/test_docstrings.py in the docker workspace.

Here's the local docstring test summary:

=========================== short test summary info ============================
FAILED ivy_tests/test_docstrings.py::test_docstrings[jax] - AssertionError: 
FAILED ivy_tests/test_docstrings.py::test_docstrings[numpy] - AssertionError: 
FAILED ivy_tests/test_docstrings.py::test_docstrings[tensorflow] - AssertionE...
FAILED ivy_tests/test_docstrings.py::test_docstrings[torch] - AssertionError: 
======================= 4 failed, 35 warnings in 11.15s ========================

Note that the failing tests are for methods that aren't changed by this PR.

Also, because of the numpy backend bug, we are expecting the docstring tests to fail for the examples that use the problematic ord arguments. This is because I computed the output values with numpy; I did not use the original ivy output where the results were wrong.

Thank you.

@nikifaets nikifaets changed the title #10311 Function reformatting vector_norm Function reformatting vector_norm Feb 11, 2023
@guillesanbri guillesanbri added the Function Reformatting Reformat all Ivy functions in accordance with the latest coding style in the contributor guide label Feb 15, 2023
Copy link
Contributor

@guillesanbri guillesanbri left a comment

Choose a reason for hiding this comment

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

I'll take a look at why the error is not showing up, requested a couple of changes in the meantime! thanks!

@guillesanbri
Copy link
Contributor

the CI seems to hung up when running the docstring tests, do they work fine in your local env?

@nikifaets
Copy link
Contributor Author

nikifaets commented Feb 17, 2023

@guillesanbri Locally, they are failing for the same functions that fail on master. Not the ones I have implemented.

@guillesanbri
Copy link
Contributor

guillesanbri commented Feb 17, 2023

ah, I see, took me a bit haha seems like you are not using print explicitly on the command, which is what the test looks for

@nikifaets
Copy link
Contributor Author

I totally missed this too. Updated the examples.

@guillesanbri
Copy link
Contributor

looks good to me now! I've seen your two messages on the discord server, given that it's something on our side I'll merge this. Thanks for the contribution!

@guillesanbri guillesanbri merged commit d852f10 into ivy-llc:master Feb 17, 2023
vedpatwardhan pushed a commit to vedpatwardhan/ivy that referenced this pull request Feb 23, 2023
vedpatwardhan pushed a commit to vedpatwardhan/ivy that referenced this pull request Feb 23, 2023
vedpatwardhan pushed a commit to vedpatwardhan/ivy that referenced this pull request Feb 26, 2023
vedpatwardhan pushed a commit to vedpatwardhan/ivy that referenced this pull request Feb 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Array API Conform to the Array API Standard, created by The Consortium for Python Data API Standards Function Reformatting Reformat all Ivy functions in accordance with the latest coding style in the contributor guide Ivy Functional API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vector_norm
3 participants