@@ -49,6 +49,8 @@ module TypeError = struct
4949 | IllTypedLaplaceMarginal of string * bool * UnsizedType .argumentlist
5050 | LaplaceCompatibilityIssue of string
5151 | IlltypedLaplaceTooMany of string * int
52+ | IlltypedLaplaceHessianBlockSize of
53+ string * (UnsizedType .autodifftype * UnsizedType .t ) option
5254 | IlltypedLaplaceTolArgs of string * SignatureMismatch .function_mismatch
5355 | AmbiguousFunctionPromotion of
5456 string
@@ -80,14 +82,38 @@ module TypeError = struct
8082 | 1 -> " first element of the control parameter tuple (initial guess)"
8183 | 2 -> " second element of the control parameter tuple (tolerance)"
8284 | 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)"
85+ | 4 -> " fourth element of the control parameter tuple (solver)"
86+ | 5 ->
87+ " fifth element of the control parameter tuple (max_steps_line_search)"
88+ | 6 -> " sixth element of the control parameter tuple (allow_fallthrough)"
8889 | n ->
8990 Fmt. str " %a element of the control parameter tuple" (Fmt. ordinal () ) n
9091
92+ let generic_laplace_usage info ppf (name , supplied ) =
93+ let req = Stan_math_signatures. laplace_helper_param_types name in
94+ let is_helper = not @@ List. is_empty req in
95+ let pp_lik_args ppf =
96+ if is_helper then Fmt. (list ~sep: comma UnsizedType. pp_fun_arg) ppf req
97+ else Fmt. pf ppf " (vector, T_l%t) => real,@ tuple(T_l%t)" ellipsis ellipsis
98+ in
99+ let pp_laplace_tols ppf =
100+ if String. is_substring ~substring: " _tol" name then
101+ Fmt. pf ppf " , %a"
102+ Fmt. (list ~sep: comma UnsizedType. pp_fun_arg)
103+ Stan_math_signatures. laplace_tolerance_argument_types in
104+ let pp_supplied_tys ppf =
105+ if List. is_empty supplied then Fmt. nop ppf ()
106+ else
107+ Fmt. pf ppf " @ However, we received the types:@ @[<hov 2>(%a)@]"
108+ Fmt. (list ~sep: comma UnsizedType. pp_fun_arg)
109+ supplied in
110+ Fmt. pf ppf
111+ " @[<v>Ill-typed arguments supplied to function %a.@ The valid signature \
112+ of this function is@ @[<hov 2>%s(%t,@ data int,@ (T_k%t) => matrix,@ \
113+ tuple(T_k%t)%t)@]%t@ @[%a@]@]"
114+ quoted name name pp_lik_args ellipsis ellipsis pp_laplace_tols
115+ pp_supplied_tys info ()
116+
91117 let rec expected_types : UnsizedType.t Common.Nonempty_list.t Fmt.t =
92118 let ust = expected_style UnsizedType. pp in
93119 fun ppf l ->
@@ -193,39 +219,24 @@ module TypeError = struct
193219 details
194220 Fmt. (list ~sep: comma (expected_style UnsizedType. pp_fun_arg))
195221 expected
196- | IllTypedLaplaceMarginal (name , early , supplied ) ->
197- let req = Stan_math_signatures. laplace_helper_param_types name in
198- let is_helper = not @@ List. is_empty req in
199- let info =
200- if early then
222+ | IllTypedLaplaceMarginal (name , true , supplied ) ->
223+ let info ppf () =
224+ Fmt. text ppf
201225 " We were unable to start more in-depth checking. Please ensure you \
202226 are passing enough arguments and that the first argument is a \
203- function."
204- else
205- let n = if is_helper then List. length req else 2 in
206- Fmt. str
207- " Typechecking failed after checking the first %d arguments. \
208- Please ensure you are passing enough arguments and that the %a \
209- is a function."
210- n (Fmt. ordinal () ) (n + 1 ) in
211- let pp_lik_args ppf =
212- if is_helper then Fmt. (list ~sep: comma UnsizedType. pp_fun_arg) ppf req
213- else
214- Fmt. pf ppf " (vector, T_l%t) => real,@ tuple(T_l%t)" ellipsis
215- ellipsis in
216- let pp_laplace_tols ppf =
217- if String. is_substring ~substring: " _tol" name then
218- Fmt. pf ppf " , %a"
219- Fmt. (list ~sep: comma UnsizedType. pp_fun_arg)
220- Stan_math_signatures. laplace_tolerance_argument_types in
221- Fmt. pf ppf
222- " @[<v>Ill-typed arguments supplied to function %a.@ The valid \
223- signature of this function is@ @[<hov 2>%s(%t,@ vector,@ (T_k%t) => \
224- matrix,@ tuple(T_k%t)%t)@]@ However, we received the types:@ @[<hov \
225- 2>(%a)@]@ @[%a@]@]"
226- quoted name name pp_lik_args ellipsis ellipsis pp_laplace_tols
227- Fmt. (list ~sep: comma UnsizedType. pp_fun_arg)
228- supplied Fmt. text info
227+ function." in
228+ generic_laplace_usage info ppf (name, supplied)
229+ | IllTypedLaplaceMarginal (name , false , supplied ) ->
230+ let req = Stan_math_signatures. laplace_helper_param_types name in
231+ let is_helper = not @@ List. is_empty req in
232+ let info ppf () =
233+ let n = (if is_helper then List. length req else 2 ) + 1 in
234+ Fmt. pf ppf
235+ " Typechecking failed after checking the first %d arguments.@ \
236+ Please ensure you are passing enough arguments and that the %a is \
237+ a function."
238+ n (Fmt. ordinal () ) (n + 1 ) in
239+ generic_laplace_usage info ppf (name, supplied)
229240 | LaplaceCompatibilityIssue banned_function ->
230241 Fmt. pf ppf
231242 " The function %a, called by this likelihood function,@ does not \
@@ -239,6 +250,28 @@ module TypeError = struct
239250 " Only a single tuple of control parameters is expected."
240251 else if n_args = 1 then " Did you mean to call the _tol version?"
241252 else " Did you mean to call the _tol version with a tuple of these?" )
253+ | IlltypedLaplaceHessianBlockSize (name , None) ->
254+ let info ppf () =
255+ Fmt. pf ppf
256+ " @[<hov>Missing the hessian block size (data-only %a) and \
257+ remaining arguments.@]"
258+ (expected_style UnsizedType. pp)
259+ UInt in
260+ generic_laplace_usage info ppf (name, [] )
261+ | IlltypedLaplaceHessianBlockSize (name , Some (DataOnly, ty )) ->
262+ Fmt. pf ppf
263+ " @[<hov>The hessian block size argument to %a must be a data-only \
264+ %a.%a@]"
265+ quoted name
266+ (expected_style UnsizedType. pp)
267+ UInt found_type ty
268+ | IlltypedLaplaceHessianBlockSize (name , Some (_ , ty )) ->
269+ Fmt. pf ppf
270+ " @[<hov>The hessian block size argument to %a must be a data-only \
271+ %a.%a@ %a@]"
272+ quoted name
273+ (expected_style UnsizedType. pp)
274+ UInt found_type ty SignatureMismatch. data_only_msg ()
242275 | IlltypedLaplaceTolArgs (name , ArgNumMismatch (_ , 0 )) ->
243276 Fmt. pf ppf
244277 " Missing control parameter tuple at the end of the call to %a.@ \
@@ -777,6 +810,9 @@ let laplace_compatibility loc banned_function =
777810let illtyped_laplace_extra_args loc name args =
778811 (loc, TypeError (TypeError. IlltypedLaplaceTooMany (name, args)))
779812
813+ let illtyped_laplace_hessian_block_size_arg loc name arg_ty =
814+ (loc, TypeError (TypeError. IlltypedLaplaceHessianBlockSize (name, arg_ty)))
815+
780816let illtyped_laplace_tolerance_args loc name mismatch =
781817 (loc, TypeError (TypeError. IlltypedLaplaceTolArgs (name, mismatch)))
782818
0 commit comments