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

Add standard_t function to numpy frontend #21549

Merged

Conversation

MichalisPanayides
Copy link
Contributor

@MichalisPanayides MichalisPanayides commented Aug 9, 2023

Close #21547

@github-actions
Copy link
Contributor

github-actions bot commented Aug 9, 2023

Thanks for contributing to Ivy! 😊👏
Here are some of the important points from our Contributing Guidelines 📝:
1. Feel free to ignore the run_tests (1), run_tests (2), … jobs, and only look at the display_test_results job. 👀 It contains the following two sections:
- Combined Test Results: This shows the results of all the ivy tests that ran on the PR. ✔️
- New Failures Introduced: This lists the tests that are passing on master, but fail on the PR Fork. Please try to make sure that there are no such tests. 💪
2. The lint / Check formatting / check-formatting tests check for the formatting of your code. 📜 If it fails, please check the exact error message in the logs and fix the same. ⚠️🔧
3. Finally, the test-docstrings / run-docstring-tests check for the changes made in docstrings of the functions. This may be skipped, as well. 📚
Happy coding! 🎉👨‍💻

@ivy-leaves ivy-leaves added the NumPy Frontend Developing the NumPy Frontend, checklist triggered by commenting add_frontend_checklist label Aug 9, 2023
@ivy-leaves
Copy link

If you are working on an open task, please edit the PR description to link to the issue you've created.

For more information, please check ToDo List Issues Guide.

Thank you 🤗

Comment on lines 104 to 105
denominator = ivy.gamma(df / 2, 1.0, shape=size, dtype="float64")
return ivy.sqrt(df / 2) * ivy.divide(numerator, ivy.sqrt(denominator))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I be using the division function implemented in ivy here (ivy.divide)? I tried to do that but the gamma function fails because it expects to have integers or floats as inputs rather than ivy.arrays.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gamma accepts both Array and NativeArray so this shouldn't be an issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
denominator = ivy.gamma(df / 2, 1.0, shape=size, dtype="float64")
return ivy.sqrt(df / 2) * ivy.divide(numerator, ivy.sqrt(denominator))
denominator = ivy.gamma(ivy.divide(df, 2), 1.0, shape=size, dtype="float64")
return ivy.sqrt(ivy.divide(df, 2)) * ivy.divide(numerator, ivy.sqrt(denominator))

When I run the tests locally with ivy.divide I get an error saying:

ivy.utils.exceptions.IvyBackendException: numpy: gamma: low and high bounds must be numerics when shape is specified

Copy link
Contributor

@aparajith21 aparajith21 Aug 17, 2023

Choose a reason for hiding this comment

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

Error on the CI seems to be somewhat different anbd suggest input issues. Please check the same and request a review once done
https://github.com/unifyai/ivy/actions/runs/5811559595/job/15755368193?pr=21549#step:3:543

@MichalisPanayides
Copy link
Contributor Author

The mathematical formula that was implemented was found from numpy's source code

@@ -410,6 +410,40 @@ def test_numpy_standard_gamma(
)


@handle_frontend_test(
fn_tree="numpy.random.standard_t",
df=st.floats(min_value=0, max_value=20, exclude_min=True),
Copy link
Contributor

@aparajith21 aparajith21 Aug 11, 2023

Choose a reason for hiding this comment

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

Please get integers here instead of floats for df

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had it as integers initially, but the documentation of numpy.random.standard_t says that df is a float. Do you still want me to change that to integers?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is okay then, unless its causing failures elsewhere

@aparajith21
Copy link
Contributor

Thanks for contributing, could you please comment add_frontend_checklist and check the items there!

@MichalisPanayides
Copy link
Contributor Author

MichalisPanayides commented Aug 11, 2023

Frontend 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.

Please note that the contributor is not expected to understand everything in the checklist. It's mainly here for the reviewer to make sure everything has been done correctly 🙂

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 implemented and does not require any edits.

CHECKS 📑:

    • ✅: The function/method definition is not missing any of the original arguments.
    • ✅: In case the function/method to be implemented is an alias of an existing function/method:
        • ✅: It is being declared as such by setting fun1 = fun2, rather than being re-implemented from scratch.
        • ✅: The alias is added to the existing function/method's test in the aliases parameter of handle_frontend_test/handle_frontend_method.
    • ✅: The naming of the function/method and its arguments exactly matches the original.
    • ✅: No defined argument is being ignored in the function/method's implementation.
    • ✅: In special cases where an argument's implementation should be pending due to an incomplete superset of an ivy function:
        • ✅: A ToDo comment has been added prompting to pass the frontend argument to the ivy function whose behavior is to be extended.
    • ❌: In case a frontend function is being added:
        • ❌: It is a composition of ivy functions.
        • ✅: In case the needed composition is long (using numerous ivy functions), a Missing Function Suggestion issue has been opened to suggest a new ivy function should be added to shorten the frontend implementation.
        • ✅: @to_ivy_arrays_and_back has been added to the function.
    • ✅: In case a frontend method is being added:
        • ✅: It is composed of existing frontend functions or methods.
        • ✅: If a required frontend function has not yet been added, the method may be implemented as a composition of ivy functions, making sure that:
          • ✅: @to_ivy_arrays_and_back has been added to the method.
          • ✅: A ToDo comment has been made prompting to remove the decorator and update the implementation as soon as the missing function has been added.
    • ✅: The function/method's test has been added (except in the alias case mentioned in <2>):
        • ✅: All supported arguments are being generated in handle_frontend_test/handle_frontend_method and passed to test_frontend_function/test_frontend_method.
        • ✅: The argument generation covers all possible supported values. Array sizes, dimensions, and axes adhere to the full supported set of the original function/method.
        • ✅: The available_dtypes parameter passed to the helper generating the function/method's input array is set to helpers.get_dtypes("valid"). If there are unsupported dtypes that cause the test to fail, they should be handled by adding @with_supported_dtypes/@with_unsupported_dtype to the function/method.
    • ❌: The PR is not introducing any test failures.
        • ✅: The lint checks are passing.
        • ❌: The implemented test is passing for all backends.
    • ✅: The PR closes a Sub Task issue linked to one of the open frontend ToDo lists.
    • ✅: The function/method and its test have been added to the correct .py files corresponding to the addressed ToDo list.
    • ✅: The PR only contains changes relevant to the addressed subtask.

@@ -410,6 +410,40 @@ def test_numpy_standard_gamma(
)


@handle_frontend_test(
fn_tree="numpy.random.standard_t",
df=st.floats(min_value=1, max_value=20),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aparajith21 The tests failed when df was so small that it was practically 0 even though the exclude_min argument was set to True. I changed the min_value of floats from 0 to 1 and I believe everything passes now 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Alright, thanks for the contribution! LGTM now then. Sorry for the late review, really busy personally.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please request review again once you resolve merge conflicts, and will then merge it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aparajith21 No problem at all. Have resolved the merge conflict but now some tests fail on the jax backend 🤷‍♂️

Copy link
Contributor

Choose a reason for hiding this comment

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

No issues, sorry for the late review, believe it's not directly related to your PR, will go ahead and merge, thanks!

@aparajith21 aparajith21 merged commit 1ef0125 into ivy-llc:main Sep 3, 2023
druvdub pushed a commit to druvdub/ivy that referenced this pull request Oct 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NumPy Frontend Developing the NumPy Frontend, checklist triggered by commenting add_frontend_checklist
Projects
None yet
Development

Successfully merging this pull request may close these issues.

standard_t
3 participants