Skip to content

Commit

Permalink
Fix /(x::MC,c::Float64) and add min_kernel(x::MC, y::MC, z)
Browse files Browse the repository at this point in the history
  • Loading branch information
mewilhel committed May 11, 2020
1 parent 2affe52 commit da9446a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/forward_operators/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ end
@inline div_kernel(x::Float64, y::MC, z::Interval{Float64}) = mult_kernel(x, inv(y), z)
@inline div_kernel(x::MC, y::C, z::Interval{Float64}) where {C <: NumberNotRelax} = mult_kernel(x, inv(y), z)
@inline div_kernel(x::C, y::MC, z::Interval{Float64}) where {C <: NumberNotRelax} = mult_kernel(x, inv(y), z)
@inline /(x::MC, y::Float64) = x*y
@inline /(x::MC, y::Float64) = x*inv(y)
@inline /(x::Float64, y::MC) = x*inv(y)
@inline /(x::MC, y::C) where {C <: NumberNotRelax} = x*inv(convert(Float64,y))
@inline /(x::C, y::MC) where {C <: NumberNotRelax} = convert(Float64,x)*inv(y)
Expand Down
25 changes: 22 additions & 3 deletions src/forward_operators/extrema.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ end
cc = x.cc
cc_grad = x.cnst ? zero(SVector{N,Float64}) : x.cc_grad
else
ccMC = (x + y + abs(x - y))/2.0
ccMC = 0.5*(x + y + abs(x - y))
cc = ccMC.cc
cc_grad = ccMC.cc_grad
end
Expand All @@ -184,6 +184,25 @@ end
return MC{N, NS}(cv, cc, z, cv_grad, cc_grad, y.cnst ? x.cnst : (x.cnst ? y.cnst : (x.cnst || y.cnst)))
end

@inline function min_kernel(x::MC{N, NS}, y::MC{N, NS}, z::Interval{Float64}) where N
if x.Intv.hi <= y.Intv.lo
cv = x.cv
cv_grad = x.cnst ? zero(SVector{N,Float64}) : x.cv_grad
elseif x.Intv.lo >= y.Intv.hi
cv = y.cv
cv_grad = y.cnst ? zero(SVector{N,Float64}) : y.cv_grad
else
cvMC = 0.5*(x + y - abs(x - y))
cv = cvMC.cv
cv_grad = cvMC.cv_grad
end
cc = min(x.cc, y.cc)
cc_grad = (x.cv > y.cv) ? (x.cnst ? zero(SVector{N,Float64}) : x.cv_grad) :
(y.cnst ? zero(SVector{N,Float64}) : y.cv_grad)
cv, cc, cv_grad, cc_grad = cut(z.lo, z.hi, cv, cc, cv_grad, cc_grad)
return MC{N, NS}(cv, cc, z, cv_grad, cc_grad, y.cnst ? x.cnst : (x.cnst ? y.cnst : (x.cnst || y.cnst)))
end

@inline max(x::MC, y::MC) = max_kernel(x, y, max(x.Intv, y.Intv))
@inline min_kernel(x::MC, y::MC, z::Interval{Float64}) = -max(-x, -y)
@inline min(x::MC, y::MC) = -max(-x, -y)
@inline min_kernel(x::MC{N,T}, y::MC{N,T}, z::Interval{Float64}) where {N, T<:Union{MV, Diff}} = -max(-x, -y)
@inline min(x::MC, y::MC) = min_kernel(x, y, min(x.Intv, y.Intv))

2 comments on commit da9446a

@mewilhel
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/14565

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.3 -m "<description of version>" da9446a77d1cba810b863eee6cb9fdc6a0bdfb36
git push origin v0.4.3

Please sign in to comment.