Skip to content

Commit 8fd8cef

Browse files
Fix NaN/Inf check to handle arrays properly
Use any(isnan, G) || any(isinf, G) instead of lambda function to correctly handle array elements and hierarchical structures
1 parent 0b17bc9 commit 8fd8cef

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/OptimizationOptimisers/src/OptimizationOptimisers.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ function SciMLBase.__solve(cache::OptimizationCache{O}) where {O <: AbstractRule
130130
end
131131
end
132132
# Skip update if gradient contains NaN or Inf values
133-
if !any(x -> isnan(x) || isinf(x), G)
133+
has_nan_or_inf = any(isnan, G) || any(isinf, G)
134+
if !has_nan_or_inf
134135
state, θ = Optimisers.update(state, θ, G)
135136
else
136137
@warn "Skipping parameter update due to NaN or Inf in gradients at iteration $iterations" maxlog=10

0 commit comments

Comments
 (0)