Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 19 additions & 25 deletions test/Nonlinear/test_SymbolicAD.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,47 +82,41 @@ function test_derivative()
# :^
op(:^, sin_x, 2)=>op(:*, 2.0, sin_x, cos_x),
op(:^, sin_x, 1)=>cos_x,
op(
:^,
x,
x,
)=>op(:+, op(:*, x, op(:^, x, x-1)), op(:*, op(:^, x, x), op(:log, x))),
op(:^, x, x)=>op(
:+,
op(:*, x, op(:^, x, x-1)),
op(:*, op(:^, x, x), op(:log, x)),
),
op(:^, x, 3)=>3.0*x*x,
# :/
op(:/, x, 2)=>0.5,
op(
:/,
op(:^, x, 2),
op(:+, x, 1),
)=>op(
op(:/, op(:^, x, 2), op(:+, x, 1))=>op(
:/,
op(:-, op(:*, 2, x, op(:+, x, 1)), op(:^, x, 2)),
op(:^, op(:+, x, 1), 2),
),
# :ifelse
op(:ifelse, z, 1.0*x*x, x)=>op(:ifelse, z, 2.0*x, 1.0),
# :atan
op(
:atan,
x,
sin_x,
)=>op(
op(:atan, x, sin_x)=>op(
:/,
op(:+, op(:*, x, cos_x), sin_x),
op(:+, op(:^, x, 2), op(:^, sin_x, 2)),
),
# :min
op(
:min,
x,
1.0*x*x,
)=>op(:ifelse, op(:(<=), x, op(:min, x, 1.0*x*x)), 1.0, 2.0*x),
op(:min, x, 1.0*x*x)=>op(
:ifelse,
op(:(<=), x, op(:min, x, 1.0*x*x)),
1.0,
2.0*x,
),
# :max
op(
:max,
x,
1.0*x*x,
)=>op(:ifelse, op(:(>=), x, op(:max, x, 1.0*x*x)), 1.0, 2.0*x),
op(:max, x, 1.0*x*x)=>op(
:ifelse,
op(:(>=), x, op(:max, x, 1.0*x*x)),
1.0,
2.0*x,
),
# comparisons
op(:(>=), x, y)=>false,
op(:(==), x, y)=>false,
Expand Down
4 changes: 2 additions & 2 deletions test/Utilities/test_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2045,13 +2045,13 @@ function test_ScalarNonlinearFunction_is_canonical()
end
@test MOI.Utilities.is_canonical(f)
@test MOI.Utilities.canonicalize!(f) isa MOI.ScalarNonlinearFunction
g = MOI.ScalarNonlinearFunction(:^, Any[1.0 * x + 1.0 * x, 2])
g = MOI.ScalarNonlinearFunction(:^, Any[1.0*x+1.0*x, 2])
for _ in 1:100_000
g = MOI.ScalarNonlinearFunction(:sin, Any[g])
end
@test !MOI.Utilities.is_canonical(g)
MOI.Utilities.canonicalize!(g)
h = MOI.ScalarNonlinearFunction(:^, Any[2.0 * x, 2])
h = MOI.ScalarNonlinearFunction(:^, Any[2.0*x, 2])
for _ in 1:100_000
h = MOI.ScalarNonlinearFunction(:sin, Any[h])
end
Expand Down
Loading