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

MAINT: special: factorial clean-ups #19989

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

h-vetinari
Copy link
Member

Preparation for complex support in factorial functions (see #18409), which needs some preparations in the tests, as well as an auxiliary function _is_subdtype to be able to sanely express the necessary subtype conditions.

No functional changes in this PR, aside from changing the text of some warning messages. Also tightens some tests that were using the woefully inadequate default of rtol=1e-7 in assert_allclose

Preview of what this PR is preparing for can be found in #19988

@github-actions github-actions bot added scipy.special maintenance Items related to regular maintenance tasks labels Jan 28, 2024
@h-vetinari
Copy link
Member Author

The failures here are just minor tolerance violations (because I tightened things from the very loose default of 1e-7 of assert_allclose) - I'll bump the tolerance as necessary once there are any review requests.

@@ -2088,55 +2089,79 @@ def test_expm1more(self):
assert_array_almost_equal(ex1,exrl1,8)


def assert_really_equal(x, y, rtol=None):
Copy link
Member

Choose a reason for hiding this comment

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

drive-by comment as I don't have time to review in detail now, but this seems to be repeating some work that was done in gh-19186 - perhaps you could use scipy._lib._array_api.xp_assert_equal(..., check_namespace=False)? (see the comment in _check_scalar from that PR for the discussion of how we're testing 0-d arrays vs scalars in cluster right now)

Copy link
Member Author

Choose a reason for hiding this comment

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

Are we will willing to use xp_assert_* also for regular functions that don't use anything about the array API?

Also, would people be willing to enhance the strict check to distinguish nans vs. complex nans? I'm not introducing this in this PR, but I need something along the lines of ed245ec (see #19988). If I should incorporate that into xp_assert_{equal,close}, that's OK for me as well.

Copy link
Member

Choose a reason for hiding this comment

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

would people be willing to enhance the strict check to distinguish nans vs. complex nans?

cc @mdhaber

Are we will willing to use xp_assert_* also for regular functions that don't use anything about the array API?

From my perspective it makes sense since ultimately they will be replaced with xp-assertions anyway. The only superfluous check for now can be turned off with check_namespace=False.

Copy link
Contributor

@mdhaber mdhaber Feb 11, 2024

Choose a reason for hiding this comment

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

enhance the strict check to distinguish nans vs. complex nans

Do you mean:

  • distinguishing between

    • a complex number x for which np.isnan(x) is True

      and

    • a complex number x for which np.isnan(x.real) and np.isnan(x.imag) is True

    or

  • distinguishing between

    • a number x for which np.isnan(x) is True

      and

    • a number x for which np.isnan(x) and np.issubdtype(x.dtype, np.complexfloating) is True

? (One of the points of the strict checks is to check dtype, so I think the second thing is covered already.)

Copy link
Member Author

Choose a reason for hiding this comment

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

The type equality is already included in the strict mode, but I want to distinguish NaN from NaN + 0j from NaN + NaN*j, so this:

a complex number x for which np.isnan(x.real) and np.isnan(x.imag) is True

Copy link
Contributor

Choose a reason for hiding this comment

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

OK. Yeah, that sounds OK.

@lucascolley lucascolley removed the request for review from person142 February 2, 2024 11:14
@h-vetinari
Copy link
Member Author

Just saw numpy/numpy#24680 & numpy/numpy#24770 in the numpy 2.0 release notes. That's even nicer (and IMO enough if we're testing this on numpy 2.0 only). Thanks a lot @mdhaber! 🙏

@lucascolley lucascolley changed the title MAINT: factorial clean-ups MAINT: special: factorial clean-ups May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Items related to regular maintenance tasks scipy.special
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants