@@ -77,13 +77,16 @@ module TypeError = struct
7777
7878 let laplace_tolerance_arg_name n =
7979 match n with
80- | 1 -> " first control parameter (initial guess)"
81- | 2 -> " second control parameter (tolerance)"
82- | 3 -> " third control parameter (max_num_steps)"
83- | 4 -> " fourth control parameter (hessian_block_size)"
84- | 5 -> " fifth control parameter (solver)"
85- | 6 -> " sixth control parameter (max_steps_line_search)"
86- | n -> Fmt. str " %a control parameter" (Fmt. ordinal () ) n
80+ | 1 -> " first element of the control parameter tuple (initial guess)"
81+ | 2 -> " second element of the control parameter tuple (tolerance)"
82+ | 3 -> " third element of the control parameter tuple (max_num_steps)"
83+ | 4 -> " fourth element of the control parameter tuple (hessian_block_size)"
84+ | 5 -> " fifth element of the control parameter tuple (solver)"
85+ | 6 ->
86+ " sixth element of the control parameter tuple (max_steps_line_search)"
87+ | 7 -> " seventh element of the control parameter tuple (allow_fallthrough)"
88+ | n ->
89+ Fmt. str " %a element of the control parameter tuple" (Fmt. ordinal () ) n
8790
8891 let rec expected_types : UnsizedType.t Common.Nonempty_list.t Fmt.t =
8992 let ust = expected_style UnsizedType. pp in
@@ -230,17 +233,23 @@ module TypeError = struct
230233 an embedded Laplace approximation."
231234 quoted banned_function
232235 | IlltypedLaplaceTooMany (name , n_args ) ->
233- Fmt. pf ppf
234- " Received %d extra %a at the end of the call to %a.@ Did you mean to \
235- call the _tol version?"
236+ Fmt. pf ppf " Received %d extra %a at the end of the call to %a.@ %s"
236237 n_args arguments n_args quoted name
237- (* For tolerances, because these come at the end, we want to update their
238- position number accordingly, which is why these reimplement some of the
239- printing from [SignatureMismatch] *)
238+ (if String. is_substring ~substring: " _tol" name then
239+ " Only a single tuple of control parameters is expected."
240+ else if n_args = 1 then " Did you mean to call the _tol version?"
241+ else " Did you mean to call the _tol version with a tuple of these?" )
242+ | IlltypedLaplaceTolArgs (name , ArgNumMismatch (_ , 0 )) ->
243+ Fmt. pf ppf
244+ " Missing control parameter tuple at the end of the call to %a.@ \
245+ Expected a tuple of %a arguments for the control parameters."
246+ quoted name (expected_style Fmt. int )
247+ (List. length Stan_math_signatures. laplace_tolerance_argument_types)
240248 | IlltypedLaplaceTolArgs (name , ArgNumMismatch (_ , found )) ->
241249 Fmt. pf ppf
242- " @[<v>Received %a control %a at the end of the call to %a.@ Expected \
243- %a arguments for the control parameters instead.@]"
250+ " @[<v>Received a tuple of %a control %a at the end of the call to \
251+ %a.@ Expected tuple of %a arguments for the control parameters \
252+ instead.@]"
244253 (actual_style Fmt. int ) found arguments found quoted name
245254 (expected_style Fmt. int )
246255 (List. length Stan_math_signatures. laplace_tolerance_argument_types)
0 commit comments