Skip to content

Commit 3a28325

Browse files
Fix debug docs + example_debug_post_op_callback (#2276)
1 parent f8c92ee commit 3a28325

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

docs/src/debugging.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ end of every `ClimaCore` operation, the function
3333
nothing. So, the second ingredient is to define a method:
3434
```@example clima_debug
3535
function ClimaCore.DebugOnly.post_op_callback(result, args...; kwargs...)
36-
if any(isnan, parent(result))
37-
println("NaNs found!")
36+
has_nans = result isa Number ? isnan(result) : any(isnan, parent(result))
37+
has_inf = result isa Number ? isinf(result) : any(isinf, parent(result))
38+
if has_nans || has_inf
39+
has_nans && println("NaNs found!")
40+
has_inf && println("Infs found!")
3841
end
3942
end
4043
```
@@ -53,8 +56,11 @@ Now, let us put everything together and demonstrate a complete example:
5356
import ClimaCore
5457
ClimaCore.DebugOnly.call_post_op_callback() = true
5558
function ClimaCore.DebugOnly.post_op_callback(result, args...; kwargs...)
56-
if any(isnan, parent(result))
57-
println("NaNs found!")
59+
has_nans = result isa Number ? isnan(result) : any(isnan, parent(result))
60+
has_inf = result isa Number ? isinf(result) : any(isinf, parent(result))
61+
if has_nans || has_inf
62+
has_nans && println("NaNs found!")
63+
has_inf && println("Infs found!")
5864
end
5965
end
6066

src/DebugOnly/DebugOnly.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ call_post_op_callback() = false
3939
An example `post_op_callback` method, that checks for `NaN`s and `Inf`s.
4040
"""
4141
function example_debug_post_op_callback(result, args...; kwargs...)
42-
if any(isnan, parent(result))
43-
error("NaNs found!")
44-
elseif any(isinf, parent(result))
45-
error("Inf found!")
42+
has_nans = result isa Number ? isnan(result) : any(isnan, parent(result))
43+
has_inf = result isa Number ? isinf(result) : any(isinf, parent(result))
44+
if has_nans || has_inf
45+
has_nans && error("NaNs found!")
46+
has_inf && error("Infs found!")
4647
end
4748
end
4849

0 commit comments

Comments
 (0)