66struct LoggedFun{F}
77 f:: F
88 args:: Any
9+ error_nonfinite:: Bool
910end
1011LoggedFunctionException (lf:: LoggedFun , args, msg) = LoggedFunctionException (
1112 " Function $(lf. f) ($(join (lf. args, " , " )) ) " * msg * " with input" *
@@ -20,22 +21,22 @@ function (lf::LoggedFun)(args...)
2021 catch err
2122 throw (LoggedFunctionException (lf, args, " errors" )) # Julia automatically attaches original error message
2223 end
23- if ! isfinite (val)
24+ if lf . error_nonfinite && ! isfinite (val)
2425 throw (LoggedFunctionException (lf, args, " output non-finite value $val " ))
2526 end
2627 return val
2728end
2829
29- function logged_fun (f, args... )
30+ function logged_fun (f, args... ; error_nonfinite = true ) # remember to update error_nonfinite in debug_system() docstring
3031 # 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)
3233end
3334
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 ... )
3637 iscall (ex) || return ex
3738 f = operation (ex)
3839 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 ... ) :
4041 maketerm (typeof (ex), f, args, metadata (ex))
4142end
0 commit comments