Skip to content

Commit

Permalink
Merge pull request #623 from pepijndevos/new-branch
Browse files Browse the repository at this point in the history
Change typeof(x) <: y to x isa y
  • Loading branch information
Vaibhavdixit02 authored Nov 2, 2023
2 parents 185d9fd + b1f82f5 commit 29d5407
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
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
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)
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)
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)
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)
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)
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)
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 29d5407

Please sign in to comment.