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

iszero #60

Open
blegat opened this issue Aug 23, 2024 · 4 comments
Open

iszero #60

blegat opened this issue Aug 23, 2024 · 4 comments

Comments

@blegat
Copy link
Member

blegat commented Aug 23, 2024

Not high priority but this won't work if the SparseCoefficients is not canonicalized:

Base.iszero(ac::AbstractCoefficients) = isempty(keys(ac))

This doesn't work for tuples:

Base.iszero(a::AlgebraElement) = iszero(coeffs(a))

@kalmarek
Copy link
Collaborator

Yes, we need to fix our semantics and develop a consistent mindset for dealing with canonicalization.

  1. Is is a temporary state within unsafe_ functions?
  2. If yes, do we bring the coefficients to canonical form upon construction, or should we trust the user?
  3. does canonical always perform its task, or is is a no-op (and hence we can call it freely in our code) for already canonicalized coeffs?

especially the latter will experience problems with thread-safety, but maybe its not our goal?

@blegat
Copy link
Member Author

blegat commented Aug 26, 2024

You can only bring it to a non-canonical state if we call unsafe_ function of UnsafeAddMul then you are responsible to call canonicalize!. I don't think it's a no-op then, we need canonicalize! to do its thing right. If the user calls it, it means the user know that he did unsafe things so he's calling it explicitly. If the user never calls unsafe methods then he should never have to canonicalize. If he does, then it's not a no-op and there is a cost, so he should just not do it ^^

@kalmarek
Copy link
Collaborator

if so, then I don't understand where is the issue:

  • Base.iszero is a user-facing function
  • user will not see non-canonicalized elements using only user-facing functions

It seems that Base.iszero is correctly implemented then?
Maybe the only thing that is missing is that we canonicalize at creation?

@blegat
Copy link
Member Author

blegat commented Aug 27, 2024

Yes, I guess that's all that's missing then, and stating this rule in the docstring and then we are good I think

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

No branches or pull requests

2 participants