-
Notifications
You must be signed in to change notification settings - Fork 64
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
define divrem for FieldElement instead of FieldElem #252
Conversation
5e49984
to
61f2a9f
Compare
This is not quite enough. We need to ensure AbstractAlgebra does not export the definition, otherwise it is type piracy (defining a function that Julia already defines, for Julia types). Besides this, the Julia definition is probably more specific than this, so I doubt it will work anyway. We explicitly need to define it for Rationals in src/julia/Rational.jl. Again, you have to look at how we handled sqrt and exp. It's quite involved. It's best to grep for every instance of one of these to see all that needs to be done. |
divrem(a::BigFloat, b::BigFloat) divrem(a::Rational{T}, b::Rational{T}) where T <: Integer and do not export them
Indeed:
This is what you want to avoid, right?
What exactly do you mean will not work?
I tried to mimic this approach in the new commits. Now we get:
|
I think you've mostly done this right. I think you should instead define divrem in AbstractAlgebra.jl for any type T to call Base.divrem. This will be the fallback (inside AbstractAlgebra). Then you won't have to define it specifically for BigFloat and Integers and so on, as it will fall back to the Julia definition. Also, is it really necessary to call AbstractAlgebra.divrem from inside Generic? If so, then we would need to use AbstractAlgebra.divrem everywhere in Generic, not just in this one place. And everywhere we define a function divrem that is not for Julia types, we will have to define Base.divrem not just divrem. |
Oh, I just noticed, you did define divrem for all types T in AbstractAlgebra.jl. So why was it then necessary to define divrem for Int and BigFloat in the julia directory? |
As I understand it,
in src/AbstractAlgebra.jl ensures that the standard
in
in So I guess we need both if we want access to both, the standard divrem and to the new functions. An alternative would be to implement the divrem in AbstractAlgebra.jl as the other two functions in
Without this the fallback is used, which we do not want.
I guess it depends on what one wants in the specific situation. But yes, there migh be instances. The aim of this PR is first to fix #249. As the fallback is used at least I do not expect this PR to cause any regressions. |
Ok, I didn't realise you intended to replace the Julia definitions of divrem for Float and BigFloat inside AbstractAlgebra. That is fine of course. As for the second part of your comment, it is necessary to call AbstractAlgebra.divrem everywhere. Otherwise we will end up with inconsistent results from computations, depending on which version was used. Also, my final comment still applies. Everywhere we define a divrem in AbstractAlgebra (for one of our types) we now need to overload Base.divrem, instead of just divrem. |
I changed this in a few places where I think it is appropriate. However I am not sure whether these functions are tested. Are there further places where changes are necessary?
I do not quite understand why. |
If you don't put Base.divrem you are only defining divrem inside AbstractAlgebra, which means the definition is no longer available to users of AbstractAlgebra. I'm surprised the test code doesn't fail actually. The test code is not inside but outside, so any time it calls divrem for such a case, it should fail. |
I though this is usually accomplished using "export". But we do not export "divrem". I am actually also surprised. |
Base.divrem is already "exported", which is why overloading it has the same effect (for those definitions). |
@wbhart So |
I don't really know. |
Ok, I'll merge this, for now. I'm sure we'll know soon enough if it is broken. |
I also added a test in relation to #249.