Skip to content

Commit

Permalink
Change typeof(x) <: y to x isa y
Browse files Browse the repository at this point in the history
  • Loading branch information
Pepijn de Vos committed Nov 2, 2023
1 parent 185d9fd commit b1f82f5
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/src/optimization_packages/optim.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ Gradient-based optimizers are optimizers which utilize the gradient information
* `P = nothing`
* `precondprep = (P, x) -> nothing`
* `manifold = Flat()`
* `scaleinvH0::Bool = true && (typeof(P) <: Nothing)`
* `scaleinvH0::Bool = true && (P isa Nothing)`
- [`Optim.NGMRES()`](https://julianlsolvers.github.io/Optim.jl/stable/#algo/ngmres/)
- [`Optim.OACCEL()`](https://julianlsolvers.github.io/Optim.jl/stable/#algo/ngmres/)

Expand Down
4 changes: 2 additions & 2 deletions ext/OptimizationEnzymeExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function Optimization.instantiate_function(f::OptimizationFunction{true}, x,

if cons !== nothing && f.cons_j === nothing
cons_j = function (J, θ)
if typeof(J) <: Vector
if J isa Vector

Check warning on line 101 in ext/OptimizationEnzymeExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/OptimizationEnzymeExt.jl#L101

Added line #L101 was not covered by tests
J .= Enzyme.jacobian(Enzyme.Forward, cons_oop, θ)[1, :]
else
J .= Enzyme.jacobian(Enzyme.Forward, cons_oop, θ)
Expand Down Expand Up @@ -232,7 +232,7 @@ function Optimization.instantiate_function(f::OptimizationFunction{true},

if cons !== nothing && f.cons_j === nothing
cons_j = function (J, θ)
if typeof(J) <: Vector
if J isa Vector

Check warning on line 235 in ext/OptimizationEnzymeExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/OptimizationEnzymeExt.jl#L235

Added line #L235 was not covered by tests
J .= Enzyme.jacobian(Enzyme.Forward, cons_oop, θ)[1, :]
else
J .= Enzyme.jacobian(Enzyme.Forward, cons_oop, θ)
Expand Down
2 changes: 1 addition & 1 deletion lib/OptimizationBBO/src/OptimizationBBO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function SciMLBase.__solve(cache::Optimization.OptimizationCache{
cb_call = cache.callback(decompose_trace(trace, cache.progress), x...)
end

if !(typeof(cb_call) <: Bool)
if !(cb_call isa Bool)

Check warning on line 121 in lib/OptimizationBBO/src/OptimizationBBO.jl

View check run for this annotation

Codecov / codecov/patch

lib/OptimizationBBO/src/OptimizationBBO.jl#L121

Added line #L121 was not covered by tests
error("The callback should return a boolean `halt` for whether to stop the optimization process.")
end
if cb_call == true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function SciMLBase.__solve(cache::OptimizationCache{

function _cb(trace)
cb_call = cache.callback(decompose_trace(trace).metadata["x"], trace.value...)
if !(typeof(cb_call) <: Bool)
if !(cb_call isa Bool)

Check warning on line 79 in lib/OptimizationCMAEvolutionStrategy/src/OptimizationCMAEvolutionStrategy.jl

View check run for this annotation

Codecov / codecov/patch

lib/OptimizationCMAEvolutionStrategy/src/OptimizationCMAEvolutionStrategy.jl#L79

Added line #L79 was not covered by tests
error("The callback should return a boolean `halt` for whether to stop the optimization process.")
end
cur, state = iterate(data, state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function SciMLBase.__solve(cache::OptimizationCache{

function _cb(trace)
cb_call = cache.callback(decompose_trace(trace).metadata["x"], trace.value...)
if !(typeof(cb_call) <: Bool)
if !(cb_call isa Bool)

Check warning on line 88 in lib/OptimizationEvolutionary/src/OptimizationEvolutionary.jl

View check run for this annotation

Codecov / codecov/patch

lib/OptimizationEvolutionary/src/OptimizationEvolutionary.jl#L88

Added line #L88 was not covered by tests
error("The callback should return a boolean `halt` for whether to stop the optimization process.")
end
cur, state = iterate(cache.data, state)
Expand Down
2 changes: 1 addition & 1 deletion lib/OptimizationFlux/src/OptimizationFlux.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function SciMLBase.__solve(cache::OptimizationCache{
cache.f.grad(G, θ, d...)
x = cache.f(θ, cache.p, d...)
cb_call = cache.callback(θ, x...)
if !(typeof(cb_call) <: Bool)
if !(cb_call isa Bool)

Check warning on line 69 in lib/OptimizationFlux/src/OptimizationFlux.jl

View check run for this annotation

Codecov / codecov/patch

lib/OptimizationFlux/src/OptimizationFlux.jl#L69

Added line #L69 was not covered by tests
error("The callback should return a boolean `halt` for whether to stop the optimization process. Please see the sciml_train documentation for information.")
elseif cb_call
break
Expand Down
6 changes: 3 additions & 3 deletions lib/OptimizationOptimJL/src/OptimizationOptimJL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function SciMLBase.__solve(cache::OptimizationCache{
cache.callback(decompose_trace(trace).metadata["centroid"],
x...) :
cache.callback(decompose_trace(trace).metadata["x"], x...)
if !(typeof(cb_call) <: Bool)
if !(cb_call isa Bool)
error("The callback should return a boolean `halt` for whether to stop the optimization process.")
end
nx_itr = iterate(cache.data, state)
Expand Down Expand Up @@ -252,7 +252,7 @@ function SciMLBase.__solve(cache::OptimizationCache{
cache.callback(decompose_trace(trace).metadata["centroid"],
x...) :
cache.callback(decompose_trace(trace).metadata["x"], x...)
if !(typeof(cb_call) <: Bool)
if !(cb_call isa Bool)

Check warning on line 255 in lib/OptimizationOptimJL/src/OptimizationOptimJL.jl

View check run for this annotation

Codecov / codecov/patch

lib/OptimizationOptimJL/src/OptimizationOptimJL.jl#L255

Added line #L255 was not covered by tests
error("The callback should return a boolean `halt` for whether to stop the optimization process.")
end
nx_itr = iterate(cache.data, state)
Expand Down Expand Up @@ -335,7 +335,7 @@ function SciMLBase.__solve(cache::OptimizationCache{

function _cb(trace)
cb_call = cache.callback(decompose_trace(trace).metadata["x"], x...)
if !(typeof(cb_call) <: Bool)
if !(cb_call isa Bool)
error("The callback should return a boolean `halt` for whether to stop the optimization process.")
end
nx_itr = iterate(cache.data, state)
Expand Down
2 changes: 1 addition & 1 deletion lib/OptimizationOptimisers/src/OptimizationOptimisers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function SciMLBase.__solve(cache::OptimizationCache{
cache.f.grad(G, θ, d...)
x = cache.f(θ, cache.p, d...)
cb_call = cache.callback(θ, x...)
if !(typeof(cb_call) <: Bool)
if !(cb_call isa Bool)
error("The callback should return a boolean `halt` for whether to stop the optimization process. Please see the sciml_train documentation for information.")
elseif cb_call
break
Expand Down
2 changes: 1 addition & 1 deletion lib/OptimizationOptimisers/src/sophia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function SciMLBase.__solve(cache::OptimizationCache{
f.grad(gₜ, θ, d...)
x = cache.f(θ, cache.p, d...)
cb_call = cache.callback(θ, x...)
if !(typeof(cb_call) <: Bool)
if !(cb_call isa Bool)

Check warning on line 96 in lib/OptimizationOptimisers/src/sophia.jl

View check run for this annotation

Codecov / codecov/patch

lib/OptimizationOptimisers/src/sophia.jl#L96

Added line #L96 was not covered by tests
error("The callback should return a boolean `halt` for whether to stop the optimization process. Please see the sciml_train documentation for information.")
elseif cb_call
break
Expand Down

0 comments on commit b1f82f5

Please sign in to comment.