-
Notifications
You must be signed in to change notification settings - Fork 74
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
Implement isapprox
and ==
#98
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems useful to have.
==(n::Number, p1::Poly) = (p1 == n) | ||
|
||
function isapprox{T,S}(p1::Poly{T}, p2::Poly{S}; | ||
rtol::Real = sqrt(eps(promote_type(T,S))), atol::Real = 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It isn't exported, but Base.rtoldefault(T,S)
does this. Maybe that should be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hadn't known Base.rtoldefaults
before. Seems like a good function! I just implemented by reading what is available with ?isapprox
. But, then, we should remove import Base.eps
and any method overloads related to eps
to have consistency in the package. What do you think?
Since Polynomials
already introduces eps
for our use (for roots
and gcd
), I wanted to use eps
and the documentation provided to us (what reltol
is for isapprox
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to remove the Base.eps
overload.
In gcd
we have this check: reduce(&, (@compat abs.(b.a)) .<=2*eps(S))
. Which requires defining eps(Integer)
. I'd much rather see something like b ≈ zero(S)
there. This would even work with Integer types, as rtoldefaults(Integer, Integer) = 0
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to do this within this PR or should we merge this in, and do that in another?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do that. How should we implement truncate
and chop
then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... and should isapprox
allowed to be throw as in isapprox([1,2], [1,2,3])
(DimensionMismatch
), or should it just return false
? I am asking this, because the way I have implemented is allowed to throw. Then, you have problems in pade
. But I can just return false
by checking against degree(p1) == 0
when it is with respect to Number
s, or against degree(p1) == degree(p2)
when it is between two Poly
s. What do you think? Or, we can use chop
and padd the vectors to have the same dimension, and check using isapprox
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, there is some thinking to do here. My first inclination would to truncate before calling isapprox, and then return false
if they aren't the same. I don't really like throwing an error here, as that seems unexpected, especially as we allow the comparison of polys to numbers. Likely it is beset to merge this in first and discuss these issues separately.
end | ||
|
||
function isapprox{T,S<:Number}(p1::Poly{T}, n::S; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These could use a doc string? This efficiently compares p1 with Poly([n1]). There are other norms that might be expected here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking back with ?isapprox
, you are right. The documentation says there is a keyword argument norm::Function
, but since it is not listed in the signature of the function in the documentation, I just disregarded it.
Thanks for the important notes!
- [x] Implemented `isapprox` and `==` between `Number`s and `Poly`s, - [x] Removed occurances of `eps` and changed them to `Base.rtoldefault`. Closes #96.
@jverzani how does it look now?
Sorry for merging them all, but I thought they were all related. |
I'll merge when the tests pass. Thanks again. My one concern is the change of tolerance for |
Correct --- but the tests are passing in Now, as you might have already noticed, I could also shrink the code for Thanks for the tip on |
Thanks again. |
Implemented
isapprox
and==
betweenNumber
s andPoly
s.Closes #96.