6
6
struct LoggedFun{F}
7
7
f:: F
8
8
args:: Any
9
+ error_nonfinite:: Bool
9
10
end
10
11
LoggedFunctionException (lf:: LoggedFun , args, msg) = LoggedFunctionException (
11
12
" Function $(lf. f) ($(join (lf. args, " , " )) ) " * msg * " with input" *
@@ -20,22 +21,22 @@ function (lf::LoggedFun)(args...)
20
21
catch err
21
22
throw (LoggedFunctionException (lf, args, " errors" )) # Julia automatically attaches original error message
22
23
end
23
- if ! isfinite (val)
24
+ if lf . error_nonfinite && ! isfinite (val)
24
25
throw (LoggedFunctionException (lf, args, " output non-finite value $val " ))
25
26
end
26
27
return val
27
28
end
28
29
29
- function logged_fun (f, args... )
30
+ function logged_fun (f, args... ; error_nonfinite = true ) # remember to update error_nonfinite in debug_system() docstring
30
31
# Currently we don't really support complex numbers
31
- term (LoggedFun (f, args), args... , type = Real)
32
+ term (LoggedFun (f, args, error_nonfinite ), args... , type = Real)
32
33
end
33
34
34
- debug_sub (eq:: Equation ) = debug_sub (eq. lhs) ~ debug_sub (eq. rhs)
35
- function debug_sub (ex)
35
+ debug_sub (eq:: Equation ; kw ... ) = debug_sub (eq. lhs; kw ... ) ~ debug_sub (eq. rhs; kw ... )
36
+ function debug_sub (ex; kw ... )
36
37
iscall (ex) || return ex
37
38
f = operation (ex)
38
39
args = map (debug_sub, arguments (ex))
39
- f in LOGGED_FUN ? logged_fun (f, args... ) :
40
+ f in LOGGED_FUN ? logged_fun (f, args... ; kw ... ) :
40
41
maketerm (typeof (ex), f, args, metadata (ex))
41
42
end
0 commit comments