-
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
Matrix evaluation for Taylor1 and TaylorN polynomials #144
Conversation
Really nice! Works like a charm! 👏 |
travis failure on nightly (macOS) seems to be related to a test which asks for identical equality ( @test A*B==Y The occasional failure of this test is a recurrent issue which has been usually handled by restarting tests, but perhaps it could be fixed if we use an approximate equality, i.e. something like: @test norm(A*B-Y,1) ≤ eps(max(norm(A*B,1), norm(Y,1)))
#or something like:
@test norm(A*B-Y,1) ≤ eps()*max(norm(A*B,1), norm(Y,1)) Note that I didn't use |
Many thanks! =)
Nice that you noticed this! I actually had no idea on why travis was failing!
Maybe this suffices: import Base: norm, isapprox
norm(v::Vector{T},p::Real=2) where T <: AbstractSeries = norm(norm.(v,p),p)
function isapprox(x::Vector{T}, y::Vector{S}; rtol::Real=rtoldefault(T,S), atol::Real=0.0,
nans::Bool=false) where {T<:AbstractSeries, S<:AbstractSeries}
x == y || norm(x-y,1) <= atol + rtol*max(norm(x,1), norm(y,1)) ||
(nans && isnan(x) && isnan(y))
end I've tried this with silly examples and does the job, but I'm not sure is the best way to go. |
@blas-ko do you think a similar thing could be done for 1 and 2 dimensional |
Well, it LGTM! I think for the moment being you could try that, unless @lbenet or @dpsanders have some other suggestions 😄 |
Upon adding your proposal to the corresponding code files, and substituting @test A*B ≈ Y atol=0.0 rtol=eps() or @test isapprox(A*B, Y, atol=0.0, rtol=eps()) tests pass 👍 |
I mean, tests pass locally |
Thanks for the contribution, LGTM! I've just restarted the travis job in mac for Julia 0.7 which was failing. Let's see if it passes now and then I'll merge... |
I'm about to push changes suggested by @PerezHz, so it includes |
Ok. Then, I'll wait for the next test round with travis! |
Tests are not passing in Julia nightly on Mac, seemingly with an unrelated issue with the matrix multiplication tests; I'm restarting that test... |
By some reason i do not understand, tests fail locally on nighties on a mac with Julia 0.7.0-DEV.3329. The problem appears in matrix multiplication ( Maybe we should allow failures in Julia nightly. cc: @dpsanders |
@PerezHz noted that for the Is it ok if I push the |
I guess what you mean is to replace line 452 in @test reduce(&, A*B .≈ Y ) Is that what you mean? In any case, just go ahead and let's see how travis reacts. |
Can't you just do |
Yes, but it's much slower and it doesn't have the function feature using TaylorSeries, BenchmarkTools
t = Taylor1(5)
A = [t 2t ; 3t 4t]
@btime evaluate.(A,3.0)
4.385 μs (24 allocations: 1.19 KiB)
@btime evaluate(A,3.0)
282.176 ns (12 allocations: 592 bytes) |
Ah OK, thanks. Note that you need @btime evaluate.($A, 3.0) |
@@ -449,7 +456,7 @@ end | |||
A_mul_B!(Y,A,B) | |||
|
|||
# do we get the same result when using the `A*B` form? | |||
@test A*B==Y | |||
@test A*B≈Y |
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.
Thanks @blas-ko for this change! I'd only insist in specifying both atol
and rtol
as:
@test A*B ≈ Y atol=0.0 rtol=eps()
otherwise, since we are being consistent with Base.isapprox
, the default rtol
value is sqrt(eps())
, which is ~1e-8
note that @blas-ko defined an |
Why not using for the test broadcasting? In current master, the following works: julia> using TaylorSeries
julia> a = Taylor1(randn(4));
julia> a ≈ a
true
julia> [a] .≈ [a] # the warnings are related to Julia 0.7
┌ Warning: `rtoldefault(x, y)` is deprecated, use `rtoldefault(x, y, 0)` instead.
│ caller = isapprox at other_functions.jl:189 [inlined]
└ @ Core other_functions.jl:189
1-element BitArray{1}:
true
julia> [a a] .≈ [a a]
┌ Warning: `rtoldefault(x, y)` is deprecated, use `rtoldefault(x, y, 0)` instead.
│ caller = isapprox at other_functions.jl:189 [inlined]
└ @ Core other_functions.jl:189
1×2 BitArray{2}:
true true The result of julia> reduce(&, [a a] .≈ [a a])
true
julia> reduce(&, [a a] .≈ [a 2a])
┌ Warning: `Array{T}(m::Int) where T` is deprecated, use `Array{T}(uninitialized, m)` instead.
│ caller = *(::Int64, ::Taylor1{Float64}) at arithmetic.jl:215
└ @ TaylorSeries arithmetic.jl:215
false Does extending |
We could do both: @test reduce(&, A*B .≈ Y )
@test A*B ≈ Y atol=0.0 rtol=eps() I agree that for fixing this test we have two solutions and one doesn't involve defining new methods. I just thought that it'd be meaningful to define |
Let's leave it as it is now, and,if it is not necessary, we'll remove it eventually. |
Merged! Thanks a lot! |
Straightforward name! This allows the user to evaluate Taylor-element matrices via
evaluate
or the function feature for evaluationA(x)
.