Skip to content

Commit 4d3cfd9

Browse files
Merge pull request #1449 from devmotion/dw/ifelse
Remove IfElse.jl
2 parents 126700a + a2ba1fc commit 4d3cfd9

9 files changed

+14
-19
lines changed

Project.toml

-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
1616
DomainSets = "5b8099bc-c8ec-5219-889f-1d9e522a28bf"
1717
DynamicPolynomials = "7c1d4256-1411-5781-91ec-d7bc3513ac07"
1818
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
19-
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
2019
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
2120
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
2221
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
@@ -71,7 +70,6 @@ DomainSets = "0.6, 0.7"
7170
DynamicPolynomials = "0.5, 0.6"
7271
ForwardDiff = "0.10.36"
7372
Groebner = "0.8.2, 0.9"
74-
IfElse = "0.1"
7573
LaTeXStrings = "1.3"
7674
LambertW = "1.0.0"
7775
Latexify = "0.16"

docs/src/manual/functions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ differentiated. So for example:
103103
```julia
104104
function derivative(::typeof(min), args::NTuple{2,Any}, ::Val{1})
105105
x, y = args
106-
IfElse.ifelse(x < y, one(x), zero(x))
106+
ifelse(x < y, one(x), zero(x))
107107
end
108108
```
109109

docs/src/manual/variables.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,9 @@ This will work for any floating-point input, as well as symbolic input.
7171

7272
## Symbolic Control Flow
7373

74-
Control flow can be expressed in Symbolics.jl in the following ways:
74+
Control flow can be expressed in Symbolics.jl in the following way:
7575

76-
- `IfElse.ifelse(cond,x,y)`: this is a dispatch-able version of the `ifelse`
77-
function provided by `IfElse.jl` which allows for encoding conditionals in
76+
- `ifelse(cond,x,y)`: this function allows to encode conditionals in
7877
the symbolic branches.
7978

8079
## Inspection Functions

src/Symbolics.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import SymbolicUtils.Code: toexpr
3838

3939
import ArrayInterface
4040
using RuntimeGeneratedFunctions
41-
using SciMLBase, IfElse
41+
using SciMLBase
4242
import MacroTools
4343

4444
using SymbolicIndexingInterface

src/diff.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ function executediff(D, arg, simplify=false; occurrences=nothing)
187187
executediff(D, a)
188188
end
189189
end
190-
elseif op === (IfElse.ifelse)
190+
elseif op === ifelse
191191
args = arguments(arg)
192192
O = op(args[1],
193193
executediff(D, args[2], simplify; occurrences=arguments(occurrences)[2]),
@@ -295,7 +295,7 @@ julia> Dx = Differential(x) # Differentiate wrt x
295295
(::Differential) (generic function with 2 methods)
296296
297297
julia> dfx = expand_derivatives(Dx(f))
298-
(k*((2abs(x - y)) / y - 2z)*IfElse.ifelse(signbit(x - y), -1, 1)) / y
298+
(k*((2abs(x - y)) / y - 2z)*ifelse(signbit(x - y), -1, 1)) / y
299299
```
300300
"""
301301
function expand_derivatives(O::Symbolic, simplify=false)

src/extra_functions.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,23 @@ derivative(::typeof(sign), args::NTuple{1,Any}, ::Val{1}) = 0
3838

3939
@register_symbolic Base.signbit(x)::Bool
4040
derivative(::typeof(signbit), args::NTuple{1,Any}, ::Val{1}) = 0
41-
derivative(::typeof(abs), args::NTuple{1,Any}, ::Val{1}) = IfElse.ifelse(signbit(args[1]),-one(args[1]),one(args[1]))
41+
derivative(::typeof(abs), args::NTuple{1,Any}, ::Val{1}) = ifelse(signbit(args[1]),-one(args[1]),one(args[1]))
4242

4343
function derivative(::typeof(min), args::NTuple{2,Any}, ::Val{1})
4444
x, y = args
45-
IfElse.ifelse(x < y, one(x), zero(x))
45+
ifelse(x < y, one(x), zero(x))
4646
end
4747
function derivative(::typeof(min), args::NTuple{2,Any}, ::Val{2})
4848
x, y = args
49-
IfElse.ifelse(x < y, zero(y), one(y))
49+
ifelse(x < y, zero(y), one(y))
5050
end
5151
function derivative(::typeof(max), args::NTuple{2,Any}, ::Val{1})
5252
x, y = args
53-
IfElse.ifelse(x > y, one(x), zero(x))
53+
ifelse(x > y, one(x), zero(x))
5454
end
5555
function derivative(::typeof(max), args::NTuple{2,Any}, ::Val{2})
5656
x, y = args
57-
IfElse.ifelse(x > y, zero(y), one(y))
57+
ifelse(x > y, zero(y), one(y))
5858
end
5959

6060
@register_symbolic Base.ceil(x)

src/num.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Base.typemin(::Type{Num}) = Num(-Inf)
3333
Base.typemax(::Type{Num}) = Num(Inf)
3434
Base.float(x::Num) = x
3535

36-
IfElse.ifelse(x::Num,y,z) = Num(IfElse.ifelse(value(x), value(y), value(z)))
36+
Base.ifelse(x::Num,y,z) = Num(ifelse(value(x), value(y), value(z)))
3737

3838
Base.promote_rule(::Type{Bool}, ::Type{<:Num}) = Num
3939
for C in [Complex, Complex{Bool}]

test/diff.jl

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Symbolics
22
using Test
3-
using IfElse
43
using Symbolics: value
54

65
# Derivatives
@@ -255,8 +254,8 @@ expression2 = substitute(expression, Dict(collect(Differential(t).(x) .=> ẋ)))
255254
@test isequal(expression2, (ẋ[1] + ẋ[2] + ẋ[3] + ẋ[4])*cos(x[1] + x[2] + x[3] + x[4]))
256255

257256
@test isequal(
258-
Symbolics.derivative(IfElse.ifelse(signbit(b), b^2, sqrt(b)), b),
259-
IfElse.ifelse(signbit(b), 2b,(SymbolicUtils.unstable_pow(2Symbolics.unwrap(sqrt(b)), -1)))
257+
Symbolics.derivative(ifelse(signbit(b), b^2, sqrt(b)), b),
258+
ifelse(signbit(b), 2b,(SymbolicUtils.unstable_pow(2Symbolics.unwrap(sqrt(b)), -1)))
260259
)
261260

262261
# Chain rule

test/overloads.jl

-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ z2 = c + d * im
170170

171171
@test isequal(ℯ^a, exp(a))
172172

173-
using IfElse: ifelse
174173
@test isequal(Symbolics.derivative(abs(x), x), ifelse(signbit(x), -1, 1))
175174
@test isequal(Symbolics.derivative(sign(x), x), 0)
176175
@test isequal(Symbolics.derivative(signbit(x), x), 0)

0 commit comments

Comments
 (0)