Skip to content

Tighten signature of iszero and isone fallbacks #57671

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

Closed

Conversation

lgoettgens
Copy link
Contributor

Resolves #57372. Please see that issue for the motivation behind the change.

Could someone please run a PkgEval on this? If there are breakages in the ecosystem, I think this is a sign to not follow down this any further.

@nsajko nsajko added needs pkgeval Tests for all registered packages should be run with this change maths Mathematical functions DO NOT MERGE Do not merge this PR! labels Mar 7, 2025
@nsajko
Copy link
Contributor

nsajko commented Mar 7, 2025

This PR currently breaks some tests:

  • linear algebra
  • sparse arrays
  • dates
  • TwicePrecision (used for floating-point ranges)

@jishnub
Copy link
Member

jishnub commented Mar 8, 2025

This seems to be quite breaking for somewhat limited gains. A lot of the breakage might happen in the wild, and wouldn't be caught by a PkgEvalrun.

I'm also not fully certain about the motivation here. One of the examples in the issue is iszero(Int) returns false, but probably a specific method should be added for Types to avoid such comparisons? Also, probably a similar method may be added for Ring? After all, iszero(x) is documented to be a check for x == zero(x), where zero(x) is the additive identity. Special cases should generally be added when this isn't what zero returns.

@StefanKarpinski StefanKarpinski added the triage This should be discussed on a triage call label Apr 1, 2025
@StefanKarpinski
Copy link
Member

StefanKarpinski commented Apr 10, 2025

In principle I like this, but we definitely need PkgEval here to evaluate the chaos it could cause.

TwicePrecision (used for floating-point ranges)

This is strictly internal, so doesn't matter. I think this should be broadened to include iszero for arrays since the all-zero array is the additive identity of arrays. But that should really have a specialized definition for efficiency. For isone on matrices you also really want a specialized method. Not sure about Dates... What is the zero date? What is the one date? Seems like this shouldn't really break Dates and maybe that should just be fixed.

@LilithHafner
Copy link
Member

Here's one option, very hackey but gets the right answer most of the time:

isone(x::Union{Number, AbstractArray}) = x == one(x)
function isone(x)
    o = one(x)
    if typeof(o) == typeof(x)
        o == x
    else
        throw ArgumentError("...")
    end
end

@LilithHafner
Copy link
Member

@nanosoldier runtests()

@nsajko
Copy link
Contributor

nsajko commented Apr 24, 2025

As far as I remember this still fails a bunch of tests in the test suite here, so running PkgEval is probably just a waste.

@LilithHafner
Copy link
Member

I think it only fails on stdlibs so this should be somewhat realistic (though not fully).

@nanosoldier
Copy link
Collaborator

The package evaluation job you requested has completed - possible new issues were detected.
The full report is available.

Report summary

❗ Packages that crashed

1 packages crashed only on the current version.

  • The process was aborted: 1 packages

3 packages crashed on the previous version too.

✖ Packages that failed

37 packages failed only on the current version.

  • Package fails to precompile: 1 packages
  • Package has test failures: 2 packages
  • Package tests unexpectedly errored: 25 packages
  • Tests became inactive: 1 packages
  • Test duration exceeded the time limit: 8 packages

1489 packages failed on the previous version too.

✔ Packages that passed tests

25 packages passed tests only on the current version.

  • Other: 25 packages

5191 packages passed tests on the previous version too.

~ Packages that at least loaded

9 packages successfully loaded only on the current version.

  • Other: 9 packages

2836 packages successfully loaded on the previous version too.

➖ Packages that were skipped altogether

1 packages were skipped only on the current version.

  • Package could not be installed: 1 packages

917 packages were skipped on the previous version too.

@LilithHafner
Copy link
Member

Looking at a few of the nano-soldier results, I estimate this breakage will require fixes to be applied to at least 19 registered packages, even once patches are applied to fix the LinearAlgebra case. This is far too breaking.

@nsajko nsajko removed the needs pkgeval Tests for all registered packages should be run with this change label Apr 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DO NOT MERGE Do not merge this PR! maths Mathematical functions triage This should be discussed on a triage call
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tighten signature of iszero and isone fallbacks?
6 participants