diff --git a/src/stan_math_signatures/Generate.ml b/src/stan_math_signatures/Generate.ml index a7d9f26b3..1a8ae82f2 100644 --- a/src/stan_math_signatures/Generate.ml +++ b/src/stan_math_signatures/Generate.ml @@ -2681,6 +2681,40 @@ let () = ; (DataOnly, UInt) ] ~required_fn_rt:UnsizedType.UVector ~required_fn_args:[UnsizedType.(AutoDiffable, UVector)] + (); + (* variadic versions of integrate_1d *) + add_variadic_fn "integrate_1d_gauss_kronrod" ~return_type:UnsizedType.UReal + ~control_args: + UnsizedType. + [(* interval a, b *) (AutoDiffable, UReal); (AutoDiffable, UReal)] + ~required_fn_rt:UnsizedType.UReal + ~required_fn_args: + UnsizedType.[(* x, xc *) (AutoDiffable, UReal); (AutoDiffable, UReal)] + (); + add_variadic_fn "integrate_1d_double_exponential" + ~return_type:UnsizedType.UReal + ~control_args:UnsizedType.[(AutoDiffable, UReal); (AutoDiffable, UReal)] + ~required_fn_rt:UnsizedType.UReal + ~required_fn_args:UnsizedType.[(AutoDiffable, UReal); (AutoDiffable, UReal)] + (); + (* _tol version accept rel_tol, abs_tol, and max_depth/max_refinements *) + add_variadic_fn "integrate_1d_double_exponential_tol" + ~return_type:UnsizedType.UReal + ~control_args: + UnsizedType. + [ (AutoDiffable, UReal); (AutoDiffable, UReal); (DataOnly, UReal) + ; (DataOnly, UReal); (DataOnly, UInt) ] + ~required_fn_rt:UnsizedType.UReal + ~required_fn_args:UnsizedType.[(AutoDiffable, UReal); (AutoDiffable, UReal)] + (); + add_variadic_fn "integrate_1d_gauss_kronrod_tol" + ~return_type:UnsizedType.UReal + ~control_args: + UnsizedType. + [ (AutoDiffable, UReal); (AutoDiffable, UReal); (DataOnly, UReal) + ; (DataOnly, UReal); (DataOnly, UInt) ] + ~required_fn_rt:UnsizedType.UReal + ~required_fn_args:UnsizedType.[(AutoDiffable, UReal); (AutoDiffable, UReal)] () (** Print a module definition to [file] that contains the signatures computed diff --git a/test/integration/good/function-signatures/math/functions/integrate_1d.stan b/test/integration/good/function-signatures/math/functions/integrate_1d.stan index b9590055d..5f6dd3705 100644 --- a/test/integration/good/function-signatures/math/functions/integrate_1d.stan +++ b/test/integration/good/function-signatures/math/functions/integrate_1d.stan @@ -14,7 +14,6 @@ parameters { model { real y = integrate_1d(integrand, 0, 1, x, x_r, x_i); real z = integrate_1d(integrand, 0, 1, x, x_r, x_i, 1e-8); - + x ~ normal(y + z, 1.0); } - diff --git a/test/integration/good/integrate_1d_double_exponential.stan b/test/integration/good/integrate_1d_double_exponential.stan new file mode 100644 index 000000000..114164340 --- /dev/null +++ b/test/integration/good/integrate_1d_double_exponential.stan @@ -0,0 +1,16 @@ +functions { + real integrand(real x, real xc, vector theta, matrix alpha) { + return 0.0; + } +} + +parameters { + vector[10] theta; + matrix[2,4] alpha; +} +model { + real y = integrate_1d_double_exponential(integrand, 0, 1, theta, alpha); + real z = integrate_1d_double_exponential_tol(integrand, 0, 1, 1e-8, 0.0, 1, theta, alpha); + + y + z ~ normal(0, 1.0); +} diff --git a/test/integration/good/integrate_1d_gauss_kronrod.stan b/test/integration/good/integrate_1d_gauss_kronrod.stan new file mode 100644 index 000000000..972ec5551 --- /dev/null +++ b/test/integration/good/integrate_1d_gauss_kronrod.stan @@ -0,0 +1,16 @@ +functions { + real integrand(real x, real xc, vector theta, matrix alpha) { + return 0.0; + } +} + +parameters { + vector[10] theta; + matrix[2,4] alpha; +} +model { + real y = integrate_1d_gauss_kronrod(integrand, 0, 1, theta, alpha); + real z = integrate_1d_gauss_kronrod_tol(integrand, 0, 1, 1e-8, 0.0, 1, theta, alpha); + + y+z ~ normal(0, 1.0); +} diff --git a/test/integration/good/warning/integrate_1d_good.stan b/test/integration/good/integrate_1d_good.stan similarity index 100% rename from test/integration/good/warning/integrate_1d_good.stan rename to test/integration/good/integrate_1d_good.stan diff --git a/test/integration/good/pretty.expected b/test/integration/good/pretty.expected index 6b0fa8d9c..6d05b581c 100644 --- a/test/integration/good/pretty.expected +++ b/test/integration/good/pretty.expected @@ -3758,6 +3758,76 @@ model { y_p ~ normal(0, 1); } +[exit 0] + $ ../../../../install/default/bin/stanc --auto-format integrate_1d_double_exponential.stan +functions { + real integrand(real x, real xc, vector theta, matrix alpha) { + return 0.0; + } +} +parameters { + vector[10] theta; + matrix[2, 4] alpha; +} +model { + real y = integrate_1d_double_exponential(integrand, 0, 1, theta, alpha); + real z = integrate_1d_double_exponential_tol(integrand, 0, 1, 1e-8, 0.0, 1, + theta, alpha); + + y + z ~ normal(0, 1.0); +} + +[exit 0] + $ ../../../../install/default/bin/stanc --auto-format integrate_1d_gauss_kronrod.stan +functions { + real integrand(real x, real xc, vector theta, matrix alpha) { + return 0.0; + } +} +parameters { + vector[10] theta; + matrix[2, 4] alpha; +} +model { + real y = integrate_1d_gauss_kronrod(integrand, 0, 1, theta, alpha); + real z = integrate_1d_gauss_kronrod_tol(integrand, 0, 1, 1e-8, 0.0, 1, + theta, alpha); + + y + z ~ normal(0, 1.0); +} + +[exit 0] + $ ../../../../install/default/bin/stanc --auto-format integrate_1d_good.stan +functions { + real foo(real x, real xc, array[] real theta, array[] real x_r, + array[] int x_i) { + return x ^ 2; + } +} +data { + array[2] real x_r; + array[10] int x_i; +} +transformed data { + array[3] real theta_d; + real int_foo1 = integrate_1d(foo, 0.2, 1.3, theta_d, x_r, x_i, 0.01); +} +parameters { + real lb; + real ub; + array[3] real theta; +} +model { + real int_foo2 = integrate_1d(foo, 0.2, 1.3, theta, x_r, x_i, 0.01); + real int_foo3 = integrate_1d(foo, lb, 1.3, theta, x_r, x_i, 0.01); + real int_foo4 = integrate_1d(foo, 0.2, ub, theta, x_r, x_i, 0.01); + real int_foo5 = integrate_1d(foo, lb, ub, theta, x_r, x_i, 0.01); + real int_foo6 = integrate_1d(foo, 0.2, 1.3, theta_d, x_r, x_i, 0.01); + real int_foo7 = integrate_1d(foo, lb, 1.3, theta_d, x_r, x_i, 0.01); + real int_foo8 = integrate_1d(foo, 0.2, ub, theta_d, x_r, x_i, 0.01); + real int_foo9 = integrate_1d(foo, lb, ub, theta_d, x_r, x_i, 0.01); +} + [exit 0] $ ../../../../install/default/bin/stanc --auto-format io_example.stan transformed data { diff --git a/test/integration/good/warning/pretty.expected b/test/integration/good/warning/pretty.expected index bc4b61361..f1d117580 100644 --- a/test/integration/good/warning/pretty.expected +++ b/test/integration/good/warning/pretty.expected @@ -119,38 +119,6 @@ Warning in 'int_div_user.stan', line 7, column 6 to column 10: write the division as a[1] * 1.0 / b[2] If rounding is intended please use the integer division operator %/%. -[exit 0] - $ ../../../../../install/default/bin/stanc --auto-format integrate_1d_good.stan -functions { - real foo(real x, real xc, array[] real theta, array[] real x_r, - array[] int x_i) { - return x ^ 2; - } -} -data { - array[2] real x_r; - array[10] int x_i; -} -transformed data { - array[3] real theta_d; - real int_foo1 = integrate_1d(foo, 0.2, 1.3, theta_d, x_r, x_i, 0.01); -} -parameters { - real lb; - real ub; - array[3] real theta; -} -model { - real int_foo2 = integrate_1d(foo, 0.2, 1.3, theta, x_r, x_i, 0.01); - real int_foo3 = integrate_1d(foo, lb, 1.3, theta, x_r, x_i, 0.01); - real int_foo4 = integrate_1d(foo, 0.2, ub, theta, x_r, x_i, 0.01); - real int_foo5 = integrate_1d(foo, lb, ub, theta, x_r, x_i, 0.01); - real int_foo6 = integrate_1d(foo, 0.2, 1.3, theta_d, x_r, x_i, 0.01); - real int_foo7 = integrate_1d(foo, lb, 1.3, theta_d, x_r, x_i, 0.01); - real int_foo8 = integrate_1d(foo, 0.2, ub, theta_d, x_r, x_i, 0.01); - real int_foo9 = integrate_1d(foo, lb, ub, theta_d, x_r, x_i, 0.01); -} - [exit 0] $ ../../../../../install/default/bin/stanc --auto-format integrate_ode_adams.stan functions {