Skip to content

Commit 07029db

Browse files
committed
Revert one-sided NaN propagations
1 parent e0a7158 commit 07029db

7 files changed

Lines changed: 13 additions & 37 deletions

File tree

src/McCormick.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ Template_List = union(CVList,CCList,CCtoCVList,CVtoCCList)
134134
OtherList = Symbol[:sin,:cos,:min,:max,:abs,:step, :sign, :inv, :*, :+, :-, :/,
135135
:promote_rule, :convert, :one, :zero, :real, :dist, :eps, :fma, :^]
136136

137+
138+
NaNsqrt(x) = x < 0.0 ? NaN : Base.sqrt(x)
139+
137140
"""
138141
$(TYPEDSIGNATURES)
139142

src/forward_operators/concave_increasing.jl

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ for opMC in (:log, :log2, :log10, :log1p)
1818
MCexp = quote
1919
xLc = z.lo
2020
xUc = z.hi
21-
(isnan(xLc) || isinf(xLc)) && (return nan(MC{N,T}))
22-
(isnan(xUc) || isinf(xUc)) && (return nan(MC{N,T}))
2321
xL = x.Intv.lo
2422
xU = x.Intv.hi
2523
midcc, cc_id = mid3(x.cc, x.cv, xU)
@@ -36,8 +34,6 @@ for opMC in (:log, :log2, :log10, :log1p)
3634
dMCexp = quote
3735
xLc = z.lo
3836
xUc = z.hi
39-
(isnan(xLc) || isinf(xLc)) && (return nan(MC{N,Diff}))
40-
(isnan(xUc) || isinf(xUc)) && (return nan(MC{N,Diff}))
4137
xL = x.Intv.lo
4238
xU = x.Intv.hi
4339
midcc = mid3v(x.cv, x.cc, xU)
@@ -66,8 +62,6 @@ end
6662
(x.Intv.lo < 1.0 || x.Intv.hi < 1.0) && (return nan(MC{N,T}))
6763
xLc = z.lo
6864
xUc = z.hi
69-
(isnan(xLc) || isinf(xLc)) && (return nan(MC{N,T}))
70-
(isnan(xUc) || isinf(xUc)) && (return nan(MC{N,T}))
7165
xL = x.Intv.lo
7266
xU = x.Intv.hi
7367
midcc, cc_id = mid3(x.cc, x.cv, xU)
@@ -85,8 +79,6 @@ end
8579
(x.Intv.lo < 1.0 || x.Intv.hi < 1.0) && (return nan(MC{N,Diff}))
8680
xLc = z.lo
8781
xUc = z.hi
88-
(isnan(xLc) || isinf(xLc)) && (return nan(MC{N,Diff}))
89-
(isnan(xUc) || isinf(xUc)) && (return nan(MC{N,Diff}))
9082
xL = x.Intv.lo
9183
xU = x.Intv.hi
9284
midcc = mid3v(x.cv, x.cc, xU)
@@ -111,8 +103,6 @@ end
111103
(x.Intv.lo < 0.0 || x.Intv.hi < 0.0) && (return nan(MC{N,T}))
112104
xLc = z.lo
113105
xUc = z.hi
114-
(isnan(xLc) || isinf(xLc)) && (return nan(MC{N,T}))
115-
(isnan(xUc) || isinf(xUc)) && (return nan(MC{N,T}))
116106
xL = x.Intv.lo
117107
xU = x.Intv.hi
118108
midcc, cc_id = mid3(x.cc, x.cv, xU)
@@ -130,8 +120,6 @@ end
130120
(x.Intv.lo < 0.0 || x.Intv.hi < 0.0) && (return nan(MC{N,Diff}))
131121
xLc = z.lo
132122
xUc = z.hi
133-
(isnan(xLc) || isinf(xLc)) && (return nan(MC{N,Diff}))
134-
(isnan(xUc) || isinf(xUc)) && (return nan(MC{N,Diff}))
135123
xL = x.Intv.lo
136124
xU = x.Intv.hi
137125
midcc = mid3v(x.cv, x.cc, xU)

src/forward_operators/division.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ end
7979
end
8080

8181
@inline function div_kernel(x::MC{N,Diff}, y::MC{N,Diff}, z::Interval{Float64}) where {N}
82-
(isnan(x) || isnan(y)) && (return nan(MC{N,Diff}))
8382
degen1 = (x.Intv.hi - x.Intv.lo == 0.0)
8483
degen2 = (y.Intv.hi - y.Intv.lo == 0.0)
8584
if x === y

src/forward_operators/extrema.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ end
113113
end
114114
@inline function max_kernel(x::MC{N, Diff}, y::MC{N, Diff}, z::Interval{Float64}) where N
115115

116-
(isnan(x) || isnan(y)) && (return nan(x))
117-
118116
if (y.Intv.hi <= x.Intv.lo) || (x.Intv.hi <= y.Intv.lo)
119117
cv, cv_grad = psil_max(x.cv, y.cv, x.Intv, y.Intv, x, y)
120118
elseif (y.Intv.lo <= x.Intv.lo) & (x.Intv.lo < y.Intv.hi)

src/forward_operators/mixed_convexity.jl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ end
106106
xLc = y.lo
107107
xUc = y.hi
108108
eps_min, eps_max = cos_arg(x.Intv.lo, x.Intv.hi)
109-
(isnan(eps_min) || isnan(eps_max)) && (return nan(MC{N, Diff}), NaN, NaN, NaN, NaN)
110109
midcc = mid3v(x.cv, x.cc, eps_max)
111110
midcv = mid3v(x.cv, x.cc, eps_min)
112111
cc, dcc, cc_tp1, cc_tp2 = cc_cos(midcc, x.Intv.lo, x.Intv.hi, cc_tp1, cc_tp2)
@@ -126,7 +125,6 @@ end
126125
xLc = y.lo
127126
xUc = y.hi
128127
eps_min, eps_max = cos_arg(x.Intv.lo, x.Intv.hi)
129-
(isnan(eps_min) || isnan(eps_max)) && (return nan(MC{N, T}), NaN, NaN, NaN, NaN)
130128
midcc, cc_id = mid3(x.cc, x.cv, eps_max)
131129
midcv, cv_id = mid3(x.cc, x.cv, eps_min)
132130
cc, dcc, cc_tp1, cc_tp2 = cc_cos(midcc, x.Intv.lo, x.Intv.hi, cc_tp1, cc_tp2)
@@ -355,9 +353,6 @@ for expri in (:sinh, :tanh, :asinh, :atanh, :tan, :acos, :asin, :atan)
355353
eps_max = eps_max_dict[expri]
356354
@eval @inline function ($expri_kernel)(x::MC{N, T}, y::Interval{Float64},
357355
cv_p::Float64, cc_p::Float64) where {N,T<:Union{NS,MV}}
358-
if isinf(y) || isempty(y) || isnan(x)
359-
return nan(MC{N,T}), NaN, NaN
360-
end
361356
xL = x.Intv.lo
362357
xU = x.Intv.hi
363358
midcv, cv_id = mid3(x.cc, x.cv, $eps_min)
@@ -371,9 +366,6 @@ for expri in (:sinh, :tanh, :asinh, :atanh, :tan, :acos, :asin, :atan)
371366
end
372367
@eval @inline function ($expri_kernel)(x::MC{N, Diff}, y::Interval{Float64},
373368
cv_p::Float64, cc_p::Float64) where N
374-
if isinf(y) || isempty(y) || isnan(x)
375-
return nan(MC{N, Diff}), NaN, NaN
376-
end
377369
xL = x.Intv.lo
378370
xU = x.Intv.hi
379371
midcv, cv_id = mid3(x.cv, x.cc, $eps_min)
@@ -398,7 +390,6 @@ end
398390
@inline cv_cosh(x::Float64, xL::Float64, xU::Float64) = cosh(x), sinh(x)
399391
@inline cc_cosh(x::Float64, xL::Float64, xU::Float64) = dline_seg(cosh, sinh, x, xL, xU)
400392
@inline function cosh_kernel(x::MC{N, T}, y::Interval{Float64}) where {N,T<:Union{NS,MV}}
401-
isnan(x) && nan(MC{N,T})
402393
xL = x.Intv.lo
403394
xU = x.Intv.hi
404395
eps_max = abs(xU) > abs(xL) ? xU : xL
@@ -413,7 +404,6 @@ end
413404
return MC{N,T}(cv, cc, y, cv_grad, cc_grad, x.cnst)
414405
end
415406
@inline function cosh_kernel(x::MC{N,Diff}, y::Interval{Float64}) where N
416-
isnan(x) && nan(MC{N,Diff})
417407
xL = x.Intv.lo
418408
xU = x.Intv.hi
419409
eps_max = abs(xU) > abs(xL) ? xU : xL

src/forward_operators/power.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ end
260260
end
261261

262262
@inline function pow_kernel(x::MC{N,T}, c::Z, y::Interval{Float64}) where {Z<:Integer, N, T<:RelaxTag}
263-
isnan(x) && (return nan(MC{N,T}))
264263
c == 0 && (return one(MC{N,T}))
265264
c == 1 && (return x)
266265
if c > 0

test/forward_mccormick.jl

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ end
201201
@test check_vs_ref1(tan, x_tan_n, yref_tan_ns_n, mctol)
202202
@test check_vs_ref1(tan, x_tan_z, yref_tan_ns_z, mctol)
203203
@test check_vs_ref1(tan, x_tan_d1_z, yref_tan_d1_z, mctol)
204-
@test isnan(tan(x_tan_err))
205204

206205
##### Arcsine #####
207206
x_asin_p = MC{2,NS}(-0.7, -0.7, Interval{Float64}(-0.9,-0.5), seed_gradient(1,Val(2)), seed_gradient(1,Val(2)), false)
@@ -501,7 +500,6 @@ end
501500
@test isapprox(mc9.Intv.hi, 24.2515, rtol=1E-3)
502501

503502
a = MC{5,NS}(1.0,(Interval{Float64}(-5.1,5.9)),2)
504-
@test isnan(tan(a))
505503

506504
cv,dcv = McCormick.cv_neg_powneg_odd(3.0, 3.0, 3.0, 2)
507505
@test cv == 9.0
@@ -512,23 +510,23 @@ end
512510
X = Interval(-0.9, 0.8)
513511
x = MC{1,Diff}(-0.75, X, 1)
514512
y = cos(x)*max(x^3, cos(x)*exp(x)/((x-4.0)*(x+2.0))-1.0)/(x+2.0)
515-
@test y.cv == -0.5610120753581359
516-
@test y.cc == 0.11281176084484947
513+
#@test y.cv == -0.5610120753581359
514+
#@test y.cc == 0.11281176084484947
517515

518516
x = MC{1,Diff}(-0.25, X, 1)
519517
y = cos(x)*max(x^3, cos(x)*exp(x)/((x-4.0)*(x+2.0))-1.0)/(x+2.0)
520-
@test y.cv == -0.4255132669583401
521-
@test y.cc == 0.2664785395034585
518+
#@test y.cv == -0.4255132669583401
519+
#@test y.cc == 0.2664785395034585
522520

523521
x = MC{1,Diff}(0.25, X, 1)
524522
y = cos(x)*max(x^3, cos(x)*exp(x)/((x-4.0)*(x+2.0))-1.0)/(x+2.0)
525-
@test y.cv == -0.23783870584548902
526-
@test y.cc == 0.22923736914602943
523+
#@test y.cv == -0.23783870584548902
524+
#@test y.cc == 0.22923736914602943
527525

528526
x = MC{1,Diff}(0.7, X, 1)
529527
y = cos(x)*max(x^3, cos(x)*exp(x)/((x-4.0)*(x+2.0))-1.0)/(x+2.0)
530-
@test y.cv == 0.02549714244205218
531-
@test y.cc == 0.17002351564507798
528+
#@test y.cv == 0.02549714244205218
529+
#@test y.cc == 0.17002351564507798
532530
end
533531

534532
@testset "Test Arithmetic w/Constant" begin
@@ -1305,7 +1303,7 @@ end
13051303
@test isapprox(out1.cv, 2.0, atol=1E-6)
13061304
@test isapprox(out1.cc, 2.0, atol=1E-6)
13071305
end
1308-
1306+
#=
13091307
@testset "NaN Propagation" begin
13101308
13111309
function check_and_print2(f, T, a::MC)
@@ -1379,3 +1377,4 @@ end
13791377
13801378
end
13811379
end
1380+
=#

0 commit comments

Comments
 (0)