Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose std_normal_log_qf #1258

Merged
merged 2 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/middle/Stan_math_signatures.ml
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ let math_sigs =
; ([basic_vectorized], "sinh", [DDeepVectorized], SoA)
; ([basic_vectorized], "sqrt", [DDeepVectorized], SoA)
; ([basic_vectorized], "square", [DDeepVectorized], SoA)
(* TODO: Eventually will want to move _qf to be part of the distribution list above *)
; ([basic_vectorized], "std_normal_qf", [DDeepVectorized], SoA)
(* std_normal_qf is an alias for inv_Phi *)
; ([basic_vectorized], "std_normal_log_qf", [DDeepVectorized], SoA)
; ([basic_vectorized], "step", [DReal], SoA)
; ([basic_vectorized], "tan", [DDeepVectorized], SoA)
; ([basic_vectorized], "tanh", [DDeepVectorized], SoA)
Expand Down
8 changes: 3 additions & 5 deletions src/stan_math_backend/Expression_gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ let fn_renames =
; (FnNegInf, "stan::math::negative_infinity")
; (FnResizeToMatch, "stan::math::resize_to_match")
; (FnNaN, "std::numeric_limits<double>::quiet_NaN") ]
@ [ ("lmultiply", "stan::math::multiply_log")
; ("lchoose", "stan::math::binomial_coefficient_log")
; ("std_normal_qf", "stan::math::inv_Phi") ]
|> String.Map.of_alist_exn

let map_rect_calls = Int.Table.create ()
Expand Down Expand Up @@ -263,11 +266,6 @@ and gen_operator_app op ppf es_in =
and gen_misc_special_math_app (f : string) (mem_pattern : Mem_pattern.t)
(ret_type : UnsizedType.returntype option) =
match f with
| "lmultiply" ->
Some (fun ppf es -> pp_binary_f ppf "stan::math::multiply_log" es)
| "lchoose" ->
Some
(fun ppf es -> pp_binary_f ppf "stan::math::binomial_coefficient_log" es)
| "target" -> Some (fun ppf _ -> pf ppf "stan::math::get_lp(lp__, lp_accum__)")
| "get_lp" -> Some (fun ppf _ -> pf ppf "stan::math::get_lp(lp__, lp_accum__)")
| f when Map.mem fn_renames f ->
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
data {
int d_int;
real d_real;
array[d_int] int d_int_array;
array[d_int] real d_real_array;
matrix[d_int, d_int] d_matrix;
Expand All @@ -23,6 +24,7 @@ data {
array[3, 4, 5] matrix[2, 3] x5w;
}
transformed data {
real transformed_data_real;
matrix[d_int, d_int] transformed_data_matrix;
vector[d_int] transformed_data_vector;
row_vector[d_int] transformed_data_row_vector;
Expand All @@ -41,6 +43,8 @@ transformed data {
array[3, 4, 5] row_vector[2] trans_x4w;
array[3, 4, 5] matrix[2, 3] trans_x5w;

transformed_data_real = inv_Phi(d_int);
transformed_data_real = inv_Phi(d_real);
transformed_data_matrix = inv_Phi(d_matrix);
transformed_data_vector = inv_Phi(d_vector);
transformed_data_row_vector = inv_Phi(d_row_vector);
Expand Down Expand Up @@ -83,6 +87,8 @@ parameters {
array[3, 4, 5] matrix[2, 3] p_x5w;
}
transformed parameters {
real transformed_param_real;

matrix[d_int, d_int] transformed_param_matrix;
vector[d_int] transformed_param_vector;
row_vector[d_int] transformed_param_row_vector;
Expand All @@ -100,6 +106,10 @@ transformed parameters {
array[3, 4, 5] row_vector[2] trans_p_x4w;
array[3, 4, 5] matrix[2, 3] trans_p_x5w;

transformed_param_real = inv_Phi(d_int);
transformed_param_real = inv_Phi(d_real);
transformed_param_real = inv_Phi(p_real);

transformed_param_matrix = inv_Phi(d_matrix);
transformed_param_vector = inv_Phi(d_vector);
transformed_param_row_vector = inv_Phi(d_row_vector);
Expand All @@ -124,4 +134,3 @@ transformed parameters {
model {
y_p ~ normal(0, 1);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
data {
int d_int;
real d_real;
array[d_int] int d_int_array;
array[d_int] real d_real_array;
matrix[d_int, d_int] d_matrix;
vector[d_int] d_vector;
row_vector[d_int] d_row_vector;

array[3] vector[2] x3y;
array[3] row_vector[2] x4y;
array[3] matrix[2, 3] x5y;

array[3, 4] int x1z;
array[3, 4] real x2z;
array[3, 4] vector[2] x3z;
array[3, 4] row_vector[2] x4z;
array[3, 4] matrix[2, 3] x5z;

array[3, 4, 5] int x1w;
array[3, 4, 5] real x2w;
array[3, 4, 5] vector[2] x3w;
array[3, 4, 5] row_vector[2] x4w;
array[3, 4, 5] matrix[2, 3] x5w;
}
transformed data {
real transformed_data_real;
matrix[d_int, d_int] transformed_data_matrix;
vector[d_int] transformed_data_vector;
row_vector[d_int] transformed_data_row_vector;

array[3] vector[2] trans_x3y;
array[3] row_vector[2] trans_x4y;
array[3] matrix[2, 3] trans_x5y;

array[3, 4] real trans_x2z;
array[3, 4] vector[2] trans_x3z;
array[3, 4] row_vector[2] trans_x4z;
array[3, 4] matrix[2, 3] trans_x5z;

array[3, 4, 5] real trans_x2w;
array[3, 4, 5] vector[2] trans_x3w;
array[3, 4, 5] row_vector[2] trans_x4w;
array[3, 4, 5] matrix[2, 3] trans_x5w;

transformed_data_real = std_normal_log_qf(d_int);
transformed_data_real = std_normal_log_qf(d_real);
transformed_data_matrix = std_normal_log_qf(d_matrix);
transformed_data_vector = std_normal_log_qf(d_vector);
transformed_data_row_vector = std_normal_log_qf(d_row_vector);
trans_x3y = std_normal_log_qf(x3y);
trans_x4y = std_normal_log_qf(x4y);
trans_x5y = std_normal_log_qf(x5y);

trans_x2z = std_normal_log_qf(x1z);
trans_x2z = std_normal_log_qf(x2z);
trans_x3z = std_normal_log_qf(x3z);
trans_x4z = std_normal_log_qf(x4z);
trans_x5z = std_normal_log_qf(x5z);

trans_x2w = std_normal_log_qf(x1w);
trans_x2w = std_normal_log_qf(x2w);
trans_x3w = std_normal_log_qf(x3w);
trans_x4w = std_normal_log_qf(x4w);
trans_x5w = std_normal_log_qf(x5w);
}
parameters {
real p_real;
real y_p;
array[d_int] real p_real_array;
matrix[d_int, d_int] p_matrix;
vector[d_int] p_vector;
row_vector[d_int] p_row_vector;

array[3] vector[2] p_x3y;
array[3] row_vector[2] p_x4y;
array[3] matrix[2, 3] p_x5y;

array[3, 4] real p_x2z;
array[3, 4] vector[2] p_x3z;
array[3, 4] row_vector[2] p_x4z;
array[3, 4] matrix[2, 3] p_x5z;

array[3, 4, 5] real p_x2w;
array[3, 4, 5] vector[2] p_x3w;
array[3, 4, 5] row_vector[2] p_x4w;
array[3, 4, 5] matrix[2, 3] p_x5w;
}
transformed parameters {
real transformed_param_real;

matrix[d_int, d_int] transformed_param_matrix;
vector[d_int] transformed_param_vector;
row_vector[d_int] transformed_param_row_vector;
array[3] vector[2] trans_p_x3y;
array[3] row_vector[2] trans_p_x4y;
array[3] matrix[2, 3] trans_p_x5y;

array[3, 4] real trans_p_x2z;
array[3, 4] vector[2] trans_p_x3z;
array[3, 4] row_vector[2] trans_p_x4z;
array[3, 4] matrix[2, 3] trans_p_x5z;

array[3, 4, 5] real trans_p_x2w;
array[3, 4, 5] vector[2] trans_p_x3w;
array[3, 4, 5] row_vector[2] trans_p_x4w;
array[3, 4, 5] matrix[2, 3] trans_p_x5w;

transformed_param_real = std_normal_log_qf(d_int);
transformed_param_real = std_normal_log_qf(d_real);
transformed_param_real = std_normal_log_qf(p_real);

transformed_param_matrix = std_normal_log_qf(d_matrix);
transformed_param_vector = std_normal_log_qf(d_vector);
transformed_param_row_vector = std_normal_log_qf(d_row_vector);
transformed_param_matrix = std_normal_log_qf(p_matrix);
transformed_param_vector = std_normal_log_qf(p_vector);
transformed_param_row_vector = std_normal_log_qf(p_row_vector);

trans_p_x3y = std_normal_log_qf(p_x3y);
trans_p_x4y = std_normal_log_qf(p_x4y);
trans_p_x5y = std_normal_log_qf(p_x5y);

trans_p_x2z = std_normal_log_qf(p_x2z);
trans_p_x3z = std_normal_log_qf(p_x3z);
trans_p_x4z = std_normal_log_qf(p_x4z);
trans_p_x5z = std_normal_log_qf(p_x5z);

trans_p_x2w = std_normal_log_qf(p_x2w);
trans_p_x3w = std_normal_log_qf(p_x3w);
trans_p_x4w = std_normal_log_qf(p_x4w);
trans_p_x5w = std_normal_log_qf(p_x5w);
}
model {
y_p ~ normal(0, 1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
data {
int d_int;
real d_real;
array[d_int] int d_int_array;
array[d_int] real d_real_array;
matrix[d_int, d_int] d_matrix;
vector[d_int] d_vector;
row_vector[d_int] d_row_vector;

array[3] vector[2] x3y;
array[3] row_vector[2] x4y;
array[3] matrix[2, 3] x5y;

array[3, 4] int x1z;
array[3, 4] real x2z;
array[3, 4] vector[2] x3z;
array[3, 4] row_vector[2] x4z;
array[3, 4] matrix[2, 3] x5z;

array[3, 4, 5] int x1w;
array[3, 4, 5] real x2w;
array[3, 4, 5] vector[2] x3w;
array[3, 4, 5] row_vector[2] x4w;
array[3, 4, 5] matrix[2, 3] x5w;
}
transformed data {
real transformed_data_real;
matrix[d_int, d_int] transformed_data_matrix;
vector[d_int] transformed_data_vector;
row_vector[d_int] transformed_data_row_vector;

array[3] vector[2] trans_x3y;
array[3] row_vector[2] trans_x4y;
array[3] matrix[2, 3] trans_x5y;

array[3, 4] real trans_x2z;
array[3, 4] vector[2] trans_x3z;
array[3, 4] row_vector[2] trans_x4z;
array[3, 4] matrix[2, 3] trans_x5z;

array[3, 4, 5] real trans_x2w;
array[3, 4, 5] vector[2] trans_x3w;
array[3, 4, 5] row_vector[2] trans_x4w;
array[3, 4, 5] matrix[2, 3] trans_x5w;

transformed_data_real = std_normal_qf(d_int);
transformed_data_real = std_normal_qf(d_real);
transformed_data_matrix = std_normal_qf(d_matrix);
transformed_data_vector = std_normal_qf(d_vector);
transformed_data_row_vector = std_normal_qf(d_row_vector);
trans_x3y = std_normal_qf(x3y);
trans_x4y = std_normal_qf(x4y);
trans_x5y = std_normal_qf(x5y);

trans_x2z = std_normal_qf(x1z);
trans_x2z = std_normal_qf(x2z);
trans_x3z = std_normal_qf(x3z);
trans_x4z = std_normal_qf(x4z);
trans_x5z = std_normal_qf(x5z);

trans_x2w = std_normal_qf(x1w);
trans_x2w = std_normal_qf(x2w);
trans_x3w = std_normal_qf(x3w);
trans_x4w = std_normal_qf(x4w);
trans_x5w = std_normal_qf(x5w);
}
parameters {
real p_real;
real y_p;
array[d_int] real p_real_array;
matrix[d_int, d_int] p_matrix;
vector[d_int] p_vector;
row_vector[d_int] p_row_vector;

array[3] vector[2] p_x3y;
array[3] row_vector[2] p_x4y;
array[3] matrix[2, 3] p_x5y;

array[3, 4] real p_x2z;
array[3, 4] vector[2] p_x3z;
array[3, 4] row_vector[2] p_x4z;
array[3, 4] matrix[2, 3] p_x5z;

array[3, 4, 5] real p_x2w;
array[3, 4, 5] vector[2] p_x3w;
array[3, 4, 5] row_vector[2] p_x4w;
array[3, 4, 5] matrix[2, 3] p_x5w;
}
transformed parameters {
real transformed_param_real;

matrix[d_int, d_int] transformed_param_matrix;
vector[d_int] transformed_param_vector;
row_vector[d_int] transformed_param_row_vector;
array[3] vector[2] trans_p_x3y;
array[3] row_vector[2] trans_p_x4y;
array[3] matrix[2, 3] trans_p_x5y;

array[3, 4] real trans_p_x2z;
array[3, 4] vector[2] trans_p_x3z;
array[3, 4] row_vector[2] trans_p_x4z;
array[3, 4] matrix[2, 3] trans_p_x5z;

array[3, 4, 5] real trans_p_x2w;
array[3, 4, 5] vector[2] trans_p_x3w;
array[3, 4, 5] row_vector[2] trans_p_x4w;
array[3, 4, 5] matrix[2, 3] trans_p_x5w;

transformed_param_real = std_normal_qf(d_int);
transformed_param_real = std_normal_qf(d_real);
transformed_param_real = std_normal_qf(p_real);

transformed_param_matrix = std_normal_qf(d_matrix);
transformed_param_vector = std_normal_qf(d_vector);
transformed_param_row_vector = std_normal_qf(d_row_vector);
transformed_param_matrix = std_normal_qf(p_matrix);
transformed_param_vector = std_normal_qf(p_vector);
transformed_param_row_vector = std_normal_qf(p_row_vector);

trans_p_x3y = std_normal_qf(p_x3y);
trans_p_x4y = std_normal_qf(p_x4y);
trans_p_x5y = std_normal_qf(p_x5y);

trans_p_x2z = std_normal_qf(p_x2z);
trans_p_x3z = std_normal_qf(p_x3z);
trans_p_x4z = std_normal_qf(p_x4z);
trans_p_x5z = std_normal_qf(p_x5z);

trans_p_x2w = std_normal_qf(p_x2w);
trans_p_x3w = std_normal_qf(p_x3w);
trans_p_x4w = std_normal_qf(p_x4w);
trans_p_x5w = std_normal_qf(p_x5w);
}
model {
y_p ~ normal(0, 1);
}
Loading