-
Notifications
You must be signed in to change notification settings - Fork 53
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
norm methods for AbstractSeries #128
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.
LGTM; I have included two suggestions that are related to the tests.
I am not sure if this implementation is enough to address this comment, without adding new methods for isapprox
. Can you please check it?
test/mixtures.jl
Outdated
@@ -133,4 +133,10 @@ using Base.Test | |||
@test xx*δx + Taylor1(typeof(δx),5) == δx + δx^2 + Taylor1(typeof(δx),5) | |||
@test xx/(1+δx) == one(xx) | |||
@test typeof(xx+δx) == Taylor1{TaylorN{Float64}} | |||
|
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.
Maybe you should convert X
and/or Y
to Taylor1{TaylorN{Float64}}
s and include another test for that.
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.
Great, I'll do this in a moment!
@@ -263,6 +263,17 @@ using Base.Test | |||
@test string(ta(0)^3-3) == " - 3 + 1 t³ + 𝒪(t¹⁶)" | |||
@test TaylorSeries.pretty_print(ta(3im)) == " ( 3 im ) + ( 1 ) t + 𝒪(t¹⁶)" | |||
@test string(Taylor1([1,2,3,4,5], 2)) == string(Taylor1([1,2,3])) | |||
|
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.
My suggestion here it to test the norm
of something like t_C = complex(3.0,4.0) * t_a
against the norm
of complex(3.0,4.0) * a
; as defined below, t_C
is only a constant Taylor series.
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'll change this too!
4 similar comments
Do you understand why some tests fail in travis and others pass? Incidentally, at some point you will have to rebase to current master. |
I am restarting the tests; it may be some glitch... |
Methods have to be extended for
Yes, I'll do your proposed changes and a rebase! |
julia> methods(isapprox)
# 3 methods for generic function "isapprox":
isapprox(x::Number, y::Number; rtol, atol, nans) in Base at floatfuncs.jl:204
isapprox(x::AbstractArray, y::AbstractArray; rtol, atol, nans, norm) in Base.LinAlg at linalg/generic.jl:1280
isapprox(J1::UniformScaling{T}, J2::UniformScaling{S}; rtol, atol, nans) where {T<:Number, S<:Number} in Base.LinAlg at linalg/uniformscaling.jl:178 The reason I think we may get it for free (using the implementation of |
Tests are passing! It was a travis thing... |
Julia 0.6 code for the relevant function isapprox(x::Number, y::Number; rtol::Real=rtoldefault(x,y), atol::Real=0, nans::Bool=false)
x == y || (isfinite(x) && isfinite(y) && abs(x-y) <= atol + rtol*max(abs(x), abs(y))) || (nans && isnan(x) && isnan(y))
end Note the use of the Using this method, if on this branch ( using TaylorSeries
import Base: rtoldefault, isfinite
# rtoldefault ans isfinite overloading for TaylorSeries
rtoldefault(::Type{T}) where T<:AbstractSeries = sqrt(eps())
isfinite(x::AbstractSeries) = !isinf(x)
t = Taylor1(25)
p = sin(t)
q = sin(t+eps()) then ERROR: ArgumentError: The 0th order Taylor1 coefficient must be non-zero
(abs(x) is not differentiable at x=0).
Stacktrace:
[1] abs(::TaylorSeries.Taylor1{Float64}) at /Users/Jorge/fork-bo/TaylorSeries.jl/src/other_functions.jl:86
[2] #isapprox#399(::Float64, ::Int64, ::Bool, ::Function, ::TaylorSeries.Taylor1{Float64}, ::TaylorSeries.Taylor1{Float64}) at ./floatfuncs.jl:204
[3] isapprox(::TaylorSeries.Taylor1{Float64}, ::TaylorSeries.Taylor1{Float64}) at ./floatfuncs.jl:204 Which is related to the fact that
On another comment, I proposed an overloading of function isapprox{T<:AbstractSeries}(x::T, y::T; rtol::Real=rtoldefault(x,y), atol::Real=0, nans::Bool=false)
x == y || (isfinite(x) && isfinite(y) && norm(x-y,1) <= atol + rtol*max(norm(x,1), norm(y,1))) || (nans && isnan(x) && isnan(y))
end Note that this is essentially the same method as So, if on this branch we do: using TaylorSeries
import Base: rtoldefault, isfinite, isapprox
# rtoldefault, isfinite and isapprox overloading for TaylorSeries
rtoldefault(::Type{T}) where T<:AbstractSeries = sqrt(eps())
isfinite(x::AbstractSeries) = !isinf(x)
function isapprox{T<:AbstractSeries}(x::T, y::T; rtol::Real=rtoldefault(x,y), atol::Real=0, nans::Bool=false)
x == y || (isfinite(x) && isfinite(y) && norm(x-y,1) <= atol + rtol*max(norm(x,1), norm(y,1))) || (nans && isnan(x) && isnan(y))
end
t = Taylor1(25)
p = sin(t)
q = sin(t+eps())
Then The second option, re-defining using TaylorSeries
import Base: rtoldefault, isfinite, abs
# rtoldefault, isfinite and abs overloading for TaylorSeries
rtoldefault(::Type{T}) where T<:AbstractSeries = sqrt(eps())
isfinite(x::AbstractSeries) = !isinf(x)
abs{T<:AbstractSeries}(x::T) = norm(x,1)
t = Taylor1(25)
p = sin(t)
q = sin(t+eps()) then, again,
I'm happy with the |
src/other_functions.jl
Outdated
|
||
#norm | ||
norm(x::AbstractSeries, p::Real=2) = norm( norm.(x.coeffs, p), p) | ||
norm{T<:NumberNotSeries}(x::Taylor1{T}, p::Real=2) = norm(x.coeffs, p) |
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.
Cool!👌
You are right @PerezHz, we do need specialized methods for I would then suggest to add somewhere in the documentation the distinction: |
4 similar comments
Travis failed again. Nevertheless, this time error log shows something different. There are tests that are not passing for Mac's
and other 3 similar errors with |
@dpsanders Do you know what is going on with travis for mac? This PR passes very nicely in linux, but not mac. Are strings treated differently in mac w.r.t. linux? My proposal is to merge this and address in another PR the compatibility issues related to mac. |
I agree! |
I don't know what's going on. I only saw that there have been certain issues with Mac on Travis, but haven't been following the discussion, sorry. You might want to write ask on discourse.julialang.org. |
Just as a side note, since the last mac and linux builds were done with different julia nightlies, the difference may also be due to recent changes in julia 0.7.0-DEV: travis linux julia version:
travis mac julia version:
I agree to merge this and work out the nightlies failures for mac on a new PR! Also, there's some discussion going on in JuliaLang/julia#23983 about the Meanwhile, I'll try to work out an MWE regarding the |
Can confirm that, using julia version |
test/manyvariables.jl
Outdated
@test norm(a) == norm([3,4,6,8.0]) | ||
@test norm(a,4) == sum([3,4,6,8.0].^4)^(1/4.) | ||
@test norm(a,Inf) == 8. | ||
@test norm((3.+4im)*x) == abs(3.+4im) |
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 am checking what is going on with travis for julia 0.7-dev on mac, and on doing this, I just noticed that julia 0.7 complains about 3.+4im
as ambiguous (due to parsing conflicts, essentially to know if you mean 3. + ...
or 3 .+ ...
). I suggest to write it as 3.0 + 4im
. Can you change it? See JuliaLang/julia#19089.
I've been checking the problem with the subscripts in julia 0.7 in a mac, and it seems the problem is with printing things like Still, I don't understand why it works in linux but it doesn't in mac... |
I think the different behavior may be due to different julia versions in linux vs mac on travis |
I restarted the linux nighties job... |
I think I was able to get a MWE of the Using julia version julia> str1 = "a "
"a "
julia> str2 = "a"
"a"
julia> str2 == str1[1:end-1] # works fine
true
julia> str1 = "₁ "
"₁ "
julia> str2 = "₁"
"₁"
julia> str2 == str1[1:end-1] # Unicode character; throws error
ERROR: UnicodeError: invalid character index
Stacktrace:
[1] getindex(::String, ::UnitRange{Int64}) at ./strings/string.jl:292 So, as @dpsanders suggested, I asked on Discourse if this was a known issue; turns out there's a breaking change introduced by JuliaLang/julia#22572, which corresponds to julia version julia> str1 = "₁ "
"₁ "
julia> str2 = "₁"
"₁"
julia> str2 == str1[1:prevind(str1, end)]
true So the issue should be solved if, on line 135 of |
Thanks a lot for the fix @PerezHz ! I also found a less elegant but equivalent solution; yours is simply better. Can you push the fix, and also address this comment ? |
Sure! Just pushed the requested changes to @blas-ko's fork of TaylorSeries, where this PR is hosted |
Just merged @PerezHz PR which addresses |
Let's see how travis reacts! |
Green lights! |
Merging! Thanks a lot to all for contributing to this! |
Follows discussion #127.
isapprox
is not yet added @PerezHz, but it may be easily included if we all agree with thenorm
methods here.