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

Fixing np.floor_divide frontend test #9333

Merged
merged 10 commits into from
Jan 17, 2023

Conversation

hello-fri-end
Copy link
Contributor

No description provided.

@ivy-leaves ivy-leaves added the NumPy Frontend Developing the NumPy Frontend, checklist triggered by commenting add_frontend_checklist label Jan 3, 2023
@hello-fri-end
Copy link
Contributor Author

@ahmedo42 Can you review this please?

…visionError and added a condition using hypothesis to make sure that the divisor is not zero after casting to dtype
Copy link
Contributor

@fnhirwa fnhirwa left a comment

Choose a reason for hiding this comment

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

Hey @hello-fri-end
The reason why we didn't do np.floor_divide or jnp.floor_divide in first place is due to special cases from array API. Doing so can lead to the failure of Array API tests.

@fnhirwa fnhirwa assigned fnhirwa and unassigned ahmedo42 Jan 16, 2023
@hello-fri-end
Copy link
Contributor Author

Hey @hello-fri-end

Hi @hirwa-nshuti ! Thanks for taking the time to review this PR.

The reason why we didn't do np.floor_divide or jnp.floor_divide in first place is due to special cases from array API. Doing so can lead to the failure of Array API tests.

Oh, thanks for the information. I have reverted my changes and added a few assume blocks in the test to make sure that the function is tested on valid inputs.

Copy link
Contributor

@fnhirwa fnhirwa left a comment

Choose a reason for hiding this comment

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

Hey check a few comments below

input_dtypes, x, casting, dtype = dtypes_values_casting
assume(not np.any(np.isclose(x[1], 0)))
assume(not np.any(np.isinf([x[1], x[0]])))
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to filter out inf as this is handled inside the data generation

input_dtypes, x, casting, dtype = dtypes_values_casting
assume(not np.any(np.isclose(x[1], 0)))
assume(not np.any(np.isinf([x[1], x[0]])))
if dtype:
assume(not np.any(np.isclose(np.cast[dtype](x[1]), 0)))
Copy link
Contributor

Choose a reason for hiding this comment

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

This also is handled by the above assume block

@hello-fri-end
Copy link
Contributor Author

Hey check a few comments below

Thanks for the suggestions. The tests are still failing and I'm not sure what the solution is here. It seems np.floor_divide does not simply return np.floor of np.divide. Consider this minimal example:

a= np.array([0.000977], dtype=float16)
b = np.array(-[32768.], dtype=float16)

>>> np.floor_divide(a,b)
-1.0

>>> np.divide(a, b)
-0.0
>>> np.floor(np.divide(a,b)).astype(a.dtype)
-0.0

Looks like np.divide already rounds the result. Maybe the difference is that np.divide will always return the result rounded to the nearest integer while np.floor_divide will always return floor of the division result. If that's the case, how can we make sure that we the same results from both?

@fnhirwa
Copy link
Contributor

fnhirwa commented Jan 17, 2023

As the ivy implementation conforms to Array API standards these edge cases should not pass as Numpy fully follows the python standards and we can't go ahead and modify the backend implementation🙂

Here we can generate values that are naturally not nearly close to zero to make our tests pass.
That's the direct solution we can take now😊

@hello-fri-end
Copy link
Contributor Author

As the ivy implementation conforms to Array API standards these edge cases should not pass as Numpy fully follows the python standards and we can't go ahead and modify the backend implementationslightly_smiling_face

Here we can generate values that are naturally not nearly close to zero to make our tests pass. That's the direct solution we can take nowblush

Thanks for the suggestions :) I've added bounds on the array values and the tests are passing for now 👍

@fnhirwa
Copy link
Contributor

fnhirwa commented Jan 17, 2023

What if we removed the limitations and use filtering for all values close to zero in inputs
assume(not np.any(np.isclose(x[0], 0))) and assume(not np.any(np.isclose(x[1], 0)))

@hello-fri-end
Copy link
Contributor Author

assume(not np.any(np.isclose(x[1], 0)))

This seems to work for now, although, I've kept the tolerance values as 1e-1. I've pushed the changes, please review them again :)

@fnhirwa fnhirwa merged commit 67ea41e into ivy-llc:master Jan 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 26, 2023
vedpatwardhan pushed a commit to vedpatwardhan/ivy that referenced this pull request Feb 26, 2023
@hello-fri-end hello-fri-end deleted the fixNumpyfloorDivide branch March 15, 2023 03:50
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.

4 participants