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

consistently use NoInverse instead of exceptions #40

Closed
wants to merge 4 commits into from

Conversation

aplavin
Copy link
Contributor

@aplavin aplavin commented Nov 25, 2023

Currently, some inverse(non-invertible f) return NoInverse, some throw an exception. (the latter is code from my earlier PRs, sorry for that!)
Here, I make it consistent by always returning NoInverse.

Copy link

codecov bot commented Nov 25, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d397fef) 100.00% compared to head (7856164) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##            master       #40   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            5         5           
  Lines          121       121           
=========================================
  Hits           121       121           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@oschulz
Copy link
Collaborator

oschulz commented Nov 25, 2023

Hm, one the one hand, this makes things more consistent. But it does introduce type instabilities, and the functions in question may well be used in time-critical code.

I would suggest to keep throwing an exception here for practical reasons. True, we'll then get a failure on certain single points, e.g. at zero. But on the other hand, if an application encounters a zero in such places, it's very likely that something is wrong, and throwing an exception would make sense.

The idea behind NoInverse is to enable code to check if a function is invertible, and then take a different code paths if it's not. But I don't think this should come at the cost of type instability.

@aplavin
Copy link
Contributor Author

aplavin commented Jan 2, 2024

Yeah, tend to agree with the type stability concerns! I didn't manage to write any small self-contained benchmark that demonstrates any performance difference between NoInverse vs exception, but agree that type stability should be kept whenever possible.

@aplavin aplavin closed this Jan 2, 2024
@aplavin aplavin deleted the patch-3 branch April 24, 2024 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants