From 82db3604f265899391d991a79ae7f139a88eeed4 Mon Sep 17 00:00:00 2001 From: Ryan Bernstein Date: Tue, 8 Oct 2019 15:56:18 -0400 Subject: [PATCH 01/10] Added a non-pretty MIR print option for optimized MIR --- src/stanc/stanc.ml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/stanc/stanc.ml b/src/stanc/stanc.ml index 2094e907b1..d9b7173b06 100644 --- a/src/stanc/stanc.ml +++ b/src/stanc/stanc.ml @@ -23,6 +23,7 @@ let dump_tx_mir = ref false let dump_stan_math_sigs = ref false let optimize = ref false let dump_opt_mir = ref false +let dump_opt_mir_pretty = ref false let output_file = ref "" let generate_data = ref false let warn_uninitialized = ref false @@ -57,7 +58,11 @@ let options = ; ( "--debug-optimized-mir" , Arg.Set dump_opt_mir , " For debugging purposes: print the MIR after it's been \ - optimized.Only has an effect when optimizations are turned on." ) + optimized. Only has an effect when optimizations are turned on." ) + ; ( "--debug-optimized-mir-pretty" + , Arg.Set dump_opt_mir + , " For debugging purposes: pretty print the MIR after it's been \ + optimized. Only has an effect when optimizations are turned on." ) ; ( "--debug-transformed-mir" , Arg.Set dump_tx_mir , " For debugging purposes: print the MIR after the backend has \ @@ -211,6 +216,8 @@ let use_file filename = Optimize.optimization_suite (optimization_settings ()) tx_mir in if !dump_opt_mir then + Sexp.pp_hum Format.std_formatter [%sexp (opt : Middle.typed_prog)] ; + if !dump_opt_mir_pretty then Middle.Pretty.pp_typed_prog Format.std_formatter opt ; opt ) else tx_mir From 20c87bf1ed65851c2e8eeb5868efa9bbc97dcbc6 Mon Sep 17 00:00:00 2001 From: Ryan Bernstein Date: Tue, 8 Oct 2019 16:04:29 -0400 Subject: [PATCH 02/10] Fixed issue where functions were converted to StanLib --- src/analysis_and_optimization/Partial_evaluator.ml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/analysis_and_optimization/Partial_evaluator.ml b/src/analysis_and_optimization/Partial_evaluator.ml index f0f37116e0..81f4619f0a 100644 --- a/src/analysis_and_optimization/Partial_evaluator.ml +++ b/src/analysis_and_optimization/Partial_evaluator.ml @@ -95,10 +95,10 @@ let rec eval_expr (e : Middle.expr_typed_located) = in let try_partially_evaluate_to e = match e with - | FunApp (StanLib, f', l') -> ( + | FunApp (t, f', l') -> ( match get_fun_or_op_rt_opt f' l' with - | Some _ -> FunApp (StanLib, f', l') - | None -> FunApp (StanLib, f, l) ) + | Some _ -> FunApp (t, f', l') + | None -> FunApp (t, f, l) ) | e -> e in try_partially_evaluate_to @@ -602,19 +602,19 @@ let rec eval_expr (e : Middle.expr_typed_located) = match op with | "PPlus__" | "PMinus__" | "PNot__" -> apply_prefix_operator_int op (Int.of_string i) - | _ -> FunApp (StanLib, op, l) ) + | _ -> FunApp (t, op, l) ) | op, [{expr= Lit (Real, r); _}] -> ( match op with | "PPlus__" | "PMinus__" -> apply_prefix_operator_real op (Float.of_string r) - | _ -> FunApp (StanLib, op, l) ) + | _ -> FunApp (t, op, l) ) | op, [{expr= Lit (Int, i1); _}; {expr= Lit (Int, i2); _}] -> ( match op with | "Plus__" | "Minus__" | "Times__" | "Divide__" | "Modulo__" |"Or__" | "And__" | "Equals__" | "NEquals__" | "Less__" |"Leq__" | "Greater__" | "Geq__" -> apply_operator_int op (Int.of_string i1) (Int.of_string i2) - | _ -> FunApp (StanLib, op, l) ) + | _ -> FunApp (t, op, l) ) | op, [{expr= Lit (Real, i1); _}; {expr= Lit (Real, i2); _}] |op, [{expr= Lit (Int, i1); _}; {expr= Lit (Real, i2); _}] |op, [{expr= Lit (Real, i1); _}; {expr= Lit (Int, i2); _}] -> ( @@ -626,7 +626,7 @@ let rec eval_expr (e : Middle.expr_typed_located) = |"Leq__" | "Greater__" | "Geq__" -> apply_logical_operator_real op (Float.of_string i1) (Float.of_string i2) - | _ -> FunApp (StanLib, op, l) ) + | _ -> FunApp (t, op, l) ) | _ -> FunApp (t, f, l) ) | TernaryIf (e1, e2, e3) -> ( match (eval_expr e1, eval_expr e2, eval_expr e3) with From dd48424c1d68ecc2c9d1029baf5f569c65d79cf0 Mon Sep 17 00:00:00 2001 From: Ryan Bernstein Date: Tue, 8 Oct 2019 16:06:37 -0400 Subject: [PATCH 03/10] Fixed my overstep --- src/analysis_and_optimization/Partial_evaluator.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/analysis_and_optimization/Partial_evaluator.ml b/src/analysis_and_optimization/Partial_evaluator.ml index 81f4619f0a..8fb5b1d43e 100644 --- a/src/analysis_and_optimization/Partial_evaluator.ml +++ b/src/analysis_and_optimization/Partial_evaluator.ml @@ -95,10 +95,10 @@ let rec eval_expr (e : Middle.expr_typed_located) = in let try_partially_evaluate_to e = match e with - | FunApp (t, f', l') -> ( + | FunApp (StanLib, f', l') -> ( match get_fun_or_op_rt_opt f' l' with - | Some _ -> FunApp (t, f', l') - | None -> FunApp (t, f, l) ) + | Some _ -> FunApp (StanLib, f', l') + | None -> FunApp (StanLib, f, l) ) | e -> e in try_partially_evaluate_to From b6f5c64b98fa7fcda85278b163946ef5867e239a Mon Sep 17 00:00:00 2001 From: Ryan Bernstein Date: Tue, 8 Oct 2019 16:23:14 -0400 Subject: [PATCH 04/10] Fix cli typo --- src/stanc/stanc.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stanc/stanc.ml b/src/stanc/stanc.ml index d9b7173b06..d6103888c6 100644 --- a/src/stanc/stanc.ml +++ b/src/stanc/stanc.ml @@ -60,7 +60,7 @@ let options = , " For debugging purposes: print the MIR after it's been \ optimized. Only has an effect when optimizations are turned on." ) ; ( "--debug-optimized-mir-pretty" - , Arg.Set dump_opt_mir + , Arg.Set dump_opt_mir_pretty , " For debugging purposes: pretty print the MIR after it's been \ optimized. Only has an effect when optimizations are turned on." ) ; ( "--debug-transformed-mir" From 5e38df96a41cccdf794b3ec7d89479494d2544b4 Mon Sep 17 00:00:00 2001 From: Ryan Bernstein Date: Tue, 8 Oct 2019 16:38:56 -0400 Subject: [PATCH 05/10] Added an option to print non-pretty transformed mir to CLI --- src/stanc/stanc.ml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/stanc/stanc.ml b/src/stanc/stanc.ml index d6103888c6..738f71572a 100644 --- a/src/stanc/stanc.ml +++ b/src/stanc/stanc.ml @@ -20,10 +20,11 @@ let print_model_cpp = ref false let dump_mir = ref false let dump_mir_pretty = ref false let dump_tx_mir = ref false -let dump_stan_math_sigs = ref false -let optimize = ref false +let dump_tx_mir_pretty = ref false let dump_opt_mir = ref false let dump_opt_mir_pretty = ref false +let dump_stan_math_sigs = ref false +let optimize = ref false let output_file = ref "" let generate_data = ref false let warn_uninitialized = ref false @@ -67,6 +68,10 @@ let options = , Arg.Set dump_tx_mir , " For debugging purposes: print the MIR after the backend has \ transformed it." ) + ; ( "--debug-transformed-mir-pretty" + , Arg.Set dump_tx_mir_pretty + , " For debugging purposes: pretty print the MIR after the backend has \ + transformed it." ) ; ( "--dump-stan-math-signatures" , Arg.Set dump_stan_math_sigs , "Dump out the list of supported type signatures for Stan Math backend." @@ -209,6 +214,8 @@ let use_file filename = print_warn_uninitialized uninitialized_vars ) ; let tx_mir = Transform_Mir.trans_prog mir in if !dump_tx_mir then + Sexp.pp_hum Format.std_formatter [%sexp (tx_mir : Middle.typed_prog)] ; + if !dump_tx_mir_pretty then Middle.Pretty.pp_typed_prog Format.std_formatter tx_mir ; let opt_mir = if !optimize then ( From ecf3caf333e52ebdb1a63c3b23a647f8203d8f1b Mon Sep 17 00:00:00 2001 From: Ryan Bernstein Date: Tue, 8 Oct 2019 16:42:30 -0400 Subject: [PATCH 06/10] Updating line numbers in test --- test/integration/bad/stanc.expected | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/bad/stanc.expected b/test/integration/bad/stanc.expected index fd8c916a01..f0cdcbbb79 100644 --- a/test/integration/bad/stanc.expected +++ b/test/integration/bad/stanc.expected @@ -1064,8 +1064,8 @@ Called from file "src/frontend/Ast_to_Mir.ml", line 532, characters 12-144 Called from file "src/list.ml", line 557, characters 34-40 Called from file "src/frontend/Ast_to_Mir.ml" (inlined), line 561, characters 22-76 Called from file "src/frontend/Ast_to_Mir.ml", line 653, characters 21-64 -Called from file "src/stanc/stanc.ml", line 195, characters 14-54 -Called from file "src/stanc/stanc.ml", line 240, characters 9-16 +Called from file "src/stanc/stanc.ml", line 205, characters 14-54 +Called from file "src/stanc/stanc.ml", line 254, characters 9-16 $ ../../../../install/default/bin/stanc fun-return-type1.stan Semantic error in 'fun-return-type1.stan', line 2, column 2 to column 72: From 81eb08ffb59169e1cc8554ae8e4e8c61f1425a7e Mon Sep 17 00:00:00 2001 From: Ryan Bernstein Date: Wed, 9 Oct 2019 12:51:26 -0400 Subject: [PATCH 07/10] Added Fn(Read|Write)Param to side effect list, disallowed propagating side effect-ful expressions --- .../Monotone_framework.ml | 6 +++++- src/analysis_and_optimization/Optimize.ml | 14 ++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/analysis_and_optimization/Monotone_framework.ml b/src/analysis_and_optimization/Monotone_framework.ml index b0fd6d492a..d21692a5d1 100644 --- a/src/analysis_and_optimization/Monotone_framework.ml +++ b/src/analysis_and_optimization/Monotone_framework.ml @@ -243,6 +243,7 @@ let constant_propagation_transfer (** The transfer function for an expression propagation analysis, AKA forward substitution (see page 396 of Muchnick) *) let expression_propagation_transfer + (can_side_effect_expr : Middle.expr_typed_located -> bool) (flowgraph_to_mir : (int, Middle.stmt_loc_num) Map.Poly.t) = ( module struct type labels = int @@ -258,7 +259,10 @@ let expression_propagation_transfer (* TODO: we are currently only propagating constants for scalars. We could do the same for matrix and array expressions if we wanted. *) | Middle.Assignment ((s, _, []), e) -> - Map.set m ~key:s ~data:(subst_expr m e) + if can_side_effect_expr e then + m + else + Map.set m ~key:s ~data:(subst_expr m e) | Middle.Decl {decl_id= s; _} |Middle.Assignment ((s, _, _ :: _), _) -> Map.remove m s diff --git a/src/analysis_and_optimization/Optimize.ml b/src/analysis_and_optimization/Optimize.ml index 1eacea4cd0..e8614c8e2d 100644 --- a/src/analysis_and_optimization/Optimize.ml +++ b/src/analysis_and_optimization/Optimize.ml @@ -520,16 +520,13 @@ let propagation let constant_propagation = propagation Monotone_framework.constant_propagation_transfer -let expression_propagation = - propagation Monotone_framework.expression_propagation_transfer - -let copy_propagation = propagation Monotone_framework.copy_propagation_transfer - let rec can_side_effect_expr (e : expr_typed_located) = match e.expr with | Var _ | Lit (_, _) -> false - | FunApp (_, f, es) -> + | FunApp (t, f, es) -> String.suffix f 3 = "_lp" || List.exists ~f:can_side_effect_expr es + || (t = CompilerInternal && f = string_of_internal_fn FnReadParam) + || (t = CompilerInternal && f = string_of_internal_fn FnWriteParam) | TernaryIf (e1, e2, e3) -> List.exists ~f:can_side_effect_expr [e1; e2; e3] | Indexed (e, is) -> can_side_effect_expr e || List.exists ~f:can_side_effect_idx is @@ -541,6 +538,11 @@ and can_side_effect_idx (i : expr_typed_located index) = | Single e | Upfrom e | MultiIndex e -> can_side_effect_expr e | Between (e1, e2) -> can_side_effect_expr e1 || can_side_effect_expr e2 +let expression_propagation = + propagation (Monotone_framework.expression_propagation_transfer can_side_effect_expr) + +let copy_propagation = propagation Monotone_framework.copy_propagation_transfer + let is_skip_break_continue s = match s with Skip | Break | Continue -> true | _ -> false From 44b0e7ecc2810977b93548cb7dd671b37d03b1f1 Mon Sep 17 00:00:00 2001 From: Ryan Bernstein Date: Wed, 9 Oct 2019 15:46:32 -0400 Subject: [PATCH 08/10] Fixing ad_level_optimization issue: Forcing _in__ constraint variables to be autodiffable if their parents are autodiffable --- src/analysis_and_optimization/Optimize.ml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/analysis_and_optimization/Optimize.ml b/src/analysis_and_optimization/Optimize.ml index e8614c8e2d..51f9acd3e3 100644 --- a/src/analysis_and_optimization/Optimize.ml +++ b/src/analysis_and_optimization/Optimize.ml @@ -809,8 +809,11 @@ let optimize_ad_levels mir = (module Rev_Flowgraph) flowgraph_to_mir initial_ad_variables in + let insert_constraint_variables vars = + Set.Poly.union vars (Set.Poly.map ~f:(fun x -> x ^ "_in__") vars) + in let optimize_ad_levels_stmt_base i stmt = - let autodiffable_variables = (Map.find_exn ad_levels i).exit in + let autodiffable_variables = insert_constraint_variables (Map.find_exn ad_levels i).exit in match map_statement (update_expr_ad_levels autodiffable_variables) From 6fc06b136ec07f5d0785e0bc776c3b34ddc7ab81 Mon Sep 17 00:00:00 2001 From: Ryan Bernstein Date: Wed, 9 Oct 2019 16:08:10 -0400 Subject: [PATCH 09/10] Added FnUnconstrain to list of impure functions, since it breaks expression propagation --- src/analysis_and_optimization/Optimize.ml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/analysis_and_optimization/Optimize.ml b/src/analysis_and_optimization/Optimize.ml index 51f9acd3e3..4abef45c11 100644 --- a/src/analysis_and_optimization/Optimize.ml +++ b/src/analysis_and_optimization/Optimize.ml @@ -527,6 +527,7 @@ let rec can_side_effect_expr (e : expr_typed_located) = String.suffix f 3 = "_lp" || List.exists ~f:can_side_effect_expr es || (t = CompilerInternal && f = string_of_internal_fn FnReadParam) || (t = CompilerInternal && f = string_of_internal_fn FnWriteParam) + || (t = CompilerInternal && f = string_of_internal_fn FnUnconstrain) | TernaryIf (e1, e2, e3) -> List.exists ~f:can_side_effect_expr [e1; e2; e3] | Indexed (e, is) -> can_side_effect_expr e || List.exists ~f:can_side_effect_idx is From 7636b77a288cf942bf062d0691da9c806c75e7e2 Mon Sep 17 00:00:00 2001 From: Ryan Bernstein Date: Wed, 9 Oct 2019 17:27:09 -0400 Subject: [PATCH 10/10] Fixing lazy code motion: Skip emits ";", try adds a Block if it's absent, update CPP test --- src/stan_math_backend/Stan_math_code_gen.ml | 7 +- src/stan_math_backend/Statement_gen.ml | 2 +- .../good/compiler-optimizations/cpp.expected | 369 +++++++++--------- 3 files changed, 196 insertions(+), 182 deletions(-) diff --git a/src/stan_math_backend/Stan_math_code_gen.ml b/src/stan_math_backend/Stan_math_code_gen.ml index 3f766b2145..701694846f 100644 --- a/src/stan_math_backend/Stan_math_code_gen.ml +++ b/src/stan_math_backend/Stan_math_code_gen.ml @@ -126,7 +126,12 @@ let pp_fun_def ppf {fdrt; fdname; fdargs; fdbody; _} = text "local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN());" ; pp_unused ppf "DUMMY_VAR__" ; - pp_located_error ppf (pp_statement, fdbody, "inside UDF " ^ fdname) ; + let blocked_fdbody = match fdbody.stmt with + | SList stmts -> {stmt= Block stmts; smeta= fdbody.smeta} + | Block _ -> fdbody + | _ -> {stmt= Block [fdbody]; smeta= fdbody.smeta} + in + pp_located_error ppf (pp_statement, blocked_fdbody, "inside UDF " ^ fdname) ; pf ppf "@ " in let templates = diff --git a/src/stan_math_backend/Statement_gen.ml b/src/stan_math_backend/Statement_gen.ml index 5d4c88cd21..e849b90c72 100644 --- a/src/stan_math_backend/Statement_gen.ml +++ b/src/stan_math_backend/Statement_gen.ml @@ -146,7 +146,7 @@ let rec pp_statement (ppf : Format.formatter) | Break -> string ppf "break;" | Continue -> string ppf "continue;" | Return e -> pf ppf "return %a;" (option pp_expr) e - | Skip -> () + | Skip -> string ppf ";" | IfElse (cond, ifbranch, elsebranch) -> let pp_else ppf x = pf ppf "else %a" pp_statement x in pf ppf "if (@[%a@]) %a %a" pp_expr cond pp_block_s ifbranch diff --git a/test/integration/good/compiler-optimizations/cpp.expected b/test/integration/good/compiler-optimizations/cpp.expected index 67b8e9fc67..1703bc4ac6 100644 --- a/test/integration/good/compiler-optimizations/cpp.expected +++ b/test/integration/good/compiler-optimizations/cpp.expected @@ -160,18 +160,20 @@ nrfun_lp(const T0__& x, const T1__& y, T_lp__& lp__, local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); (void) DUMMY_VAR__; // suppress unused var warning - try int sym34__; - int sym33__; - { - current_statement__ = 88; - if (logical_gt(x, 342)) { - { - current_statement__ = 87; - return ; - } - } else - current_statement__ = 8; - lp_accum__.add(y); + try { + int sym34__; + int sym33__; + { + current_statement__ = 88; + if (logical_gt(x, 342)) { + { + current_statement__ = 87; + return ; + } + } else ; + current_statement__ = 8; + lp_accum__.add(y); + } } catch (const std::exception& e) { stan::lang::rethrow_located( std::runtime_error(std::string("inside UDF nrfun_lp") + ": " + e.what()), locations_array__[current_statement__]); @@ -202,19 +204,21 @@ rfun(const T0__& y, std::ostream* pstream__) { local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); (void) DUMMY_VAR__; // suppress unused var warning - try int sym37__; - int sym36__; - int sym35__; - { - current_statement__ = 12; - if (logical_gt(y, 2)) { - { - current_statement__ = 11; - return (y + 24); - } - } else - current_statement__ = 89; - return (y + 2); + try { + int sym37__; + int sym36__; + int sym35__; + { + current_statement__ = 12; + if (logical_gt(y, 2)) { + { + current_statement__ = 11; + return (y + 24); + } + } else ; + current_statement__ = 89; + return (y + 2); + } } catch (const std::exception& e) { stan::lang::rethrow_located( std::runtime_error(std::string("inside UDF rfun") + ": " + e.what()), locations_array__[current_statement__]); @@ -242,10 +246,12 @@ rfun_lp(T_lp__& lp__, T_lp_accum__& lp_accum__, std::ostream* pstream__) { (void) DUMMY_VAR__; // suppress unused var warning try { - current_statement__ = 56; - lp_accum__.add(2); - current_statement__ = 90; - return 24; + { + current_statement__ = 56; + lp_accum__.add(2); + current_statement__ = 90; + return 24; + } } catch (const std::exception& e) { stan::lang::rethrow_located( std::runtime_error(std::string("inside UDF rfun_lp") + ": " + e.what()), locations_array__[current_statement__]); @@ -315,11 +321,7 @@ class optimizations_model : public model_base_crtp { stan::io::reader in__(params_r__, params_i__); try { - double sym113__; - double sym112__; - int sym111__; - int sym110__; - int sym109__; + local_scalar_t__ sym109__; int sym108__; int sym107__; int sym106__; @@ -350,23 +352,35 @@ class optimizations_model : public model_base_crtp { int sym81__; int sym80__; int sym79__; + int sym78__; + int sym77__; + int sym76__; local_scalar_t__ theta; - sym113__ = in__.scalar(); + current_statement__ = 2; + theta = in__.scalar(); local_scalar_t__ phi; + current_statement__ = 3; + phi = in__.scalar(); Eigen::Matrix x_matrix; x_matrix = Eigen::Matrix(3, 2); + current_statement__ = 4; + x_matrix = in__.matrix(3, 2); Eigen::Matrix x_vector; x_vector = Eigen::Matrix(2); + current_statement__ = 5; + x_vector = in__.vector(2); Eigen::Matrix x_cov; x_cov = Eigen::Matrix(2, 2); - Eigen::Matrix x_cov_in__; - x_cov_in__ = Eigen::Matrix(3); + Eigen::Matrix x_cov_in__; + x_cov_in__ = Eigen::Matrix(3); + current_statement__ = 6; + x_cov_in__ = in__.vector(3); { double x; @@ -412,7 +426,7 @@ class optimizations_model : public model_base_crtp { stan_print(pstream__, "\n"); } } - } else + } else ; int sym10__; int sym13__; for (size_t sym9__ = 1; sym9__ <= 1; ++sym9__) { @@ -461,22 +475,22 @@ class optimizations_model : public model_base_crtp { lp_accum__.add(3); }} } - sym109__ = (sym10__ + 1); + sym106__ = (sym10__ + 1); for (size_t sym12__ = 1; sym12__ <= 1; ++sym12__) { { { { sym13__ = 29; - sym109__ = (sym10__ + 1); + sym106__ = (sym10__ + 1); break; } } sym13__ = 7; - sym109__ = (sym10__ + 1); + sym106__ = (sym10__ + 1); break; }} } - for (size_t i = sym109__; i <= sym13__; ++i) { + for (size_t i = sym106__; i <= sym13__; ++i) { { { int sym16__; @@ -512,7 +526,7 @@ class optimizations_model : public model_base_crtp { }} }} } - } else + } else ; { { { @@ -568,40 +582,40 @@ class optimizations_model : public model_base_crtp { } { { - sym111__ = (2 * 2); - if (logical_lte(2, sym111__)) { + sym108__ = (2 * 2); + if (logical_lte(2, sym108__)) { { { - sym108__ = (2 + 1); + sym105__ = (2 + 1); lp_accum__.add(53); } current_statement__ = 20; - for (size_t k = sym108__; k <= sym111__; ++k) { + for (size_t k = sym105__; k <= sym108__; ++k) { { current_statement__ = 20; lp_accum__.add(53); }} } - } else + } else ; } } { { - sym111__ = (3 * 2); - if (logical_lte(3, sym111__)) { + sym108__ = (3 * 2); + if (logical_lte(3, sym108__)) { { { - sym108__ = (3 + 1); + sym105__ = (3 + 1); lp_accum__.add(53); } current_statement__ = 20; - for (size_t k = sym108__; k <= sym111__; ++k) { + for (size_t k = sym105__; k <= sym108__; ++k) { { current_statement__ = 20; lp_accum__.add(53); }} } - } else + } else ; } } } @@ -609,190 +623,190 @@ class optimizations_model : public model_base_crtp { } { { - sym107__ = (2 + 2); - if (logical_lte(2, sym107__)) { + sym104__ = (2 + 2); + if (logical_lte(2, sym104__)) { { { - sym110__ = (2 * 2); - if (logical_lte(2, sym110__)) { + sym107__ = (2 * 2); + if (logical_lte(2, sym107__)) { { { - sym106__ = (2 + 1); + sym103__ = (2 + 1); lp_accum__.add(53); } current_statement__ = 20; - for (size_t k = sym106__; k <= sym110__; ++k) { + for (size_t k = sym103__; k <= sym107__; ++k) { { current_statement__ = 20; lp_accum__.add(53); }} } } else { - sym106__ = (2 + 1); + sym103__ = (2 + 1); } } current_statement__ = 21; - for (size_t j = sym106__; j <= sym107__; ++j) { + for (size_t j = sym103__; j <= sym104__; ++j) { { - sym111__ = (j * 2); - if (logical_lte(j, sym111__)) { + sym108__ = (j * 2); + if (logical_lte(j, sym108__)) { { { - sym108__ = (j + 1); + sym105__ = (j + 1); lp_accum__.add(53); } current_statement__ = 20; - for (size_t k = sym108__; k <= sym111__; ++k) { + for (size_t k = sym105__; k <= sym108__; ++k) { { current_statement__ = 20; lp_accum__.add(53); }} } - } else + } else ; }} } - } else + } else ; } } { { - sym107__ = (3 + 2); - if (logical_lte(3, sym107__)) { + sym104__ = (3 + 2); + if (logical_lte(3, sym104__)) { { { - sym110__ = (3 * 2); - if (logical_lte(3, sym110__)) { + sym107__ = (3 * 2); + if (logical_lte(3, sym107__)) { { { - sym106__ = (3 + 1); + sym103__ = (3 + 1); lp_accum__.add(53); } current_statement__ = 20; - for (size_t k = sym106__; k <= sym110__; ++k) { + for (size_t k = sym103__; k <= sym107__; ++k) { { current_statement__ = 20; lp_accum__.add(53); }} } } else { - sym106__ = (3 + 1); + sym103__ = (3 + 1); } } current_statement__ = 21; - for (size_t j = sym106__; j <= sym107__; ++j) { + for (size_t j = sym103__; j <= sym104__; ++j) { { - sym111__ = (j * 2); - if (logical_lte(j, sym111__)) { + sym108__ = (j * 2); + if (logical_lte(j, sym108__)) { { { - sym108__ = (j + 1); + sym105__ = (j + 1); lp_accum__.add(53); } current_statement__ = 20; - for (size_t k = sym108__; k <= sym111__; ++k) { + for (size_t k = sym105__; k <= sym108__; ++k) { { current_statement__ = 20; lp_accum__.add(53); }} } - } else + } else ; }} } - } else + } else ; } } { { - sym107__ = (4 + 2); - if (logical_lte(4, sym107__)) { + sym104__ = (4 + 2); + if (logical_lte(4, sym104__)) { { { - sym110__ = (4 * 2); - if (logical_lte(4, sym110__)) { + sym107__ = (4 * 2); + if (logical_lte(4, sym107__)) { { { - sym106__ = (4 + 1); + sym103__ = (4 + 1); lp_accum__.add(53); } current_statement__ = 20; - for (size_t k = sym106__; k <= sym110__; ++k) { + for (size_t k = sym103__; k <= sym107__; ++k) { { current_statement__ = 20; lp_accum__.add(53); }} } } else { - sym106__ = (4 + 1); + sym103__ = (4 + 1); } } current_statement__ = 21; - for (size_t j = sym106__; j <= sym107__; ++j) { + for (size_t j = sym103__; j <= sym104__; ++j) { { - sym111__ = (j * 2); - if (logical_lte(j, sym111__)) { + sym108__ = (j * 2); + if (logical_lte(j, sym108__)) { { { - sym108__ = (j + 1); + sym105__ = (j + 1); lp_accum__.add(53); } current_statement__ = 20; - for (size_t k = sym108__; k <= sym111__; ++k) { + for (size_t k = sym105__; k <= sym108__; ++k) { { current_statement__ = 20; lp_accum__.add(53); }} } - } else + } else ; }} } - } else + } else ; } } { { - sym107__ = (5 + 2); - if (logical_lte(5, sym107__)) { + sym104__ = (5 + 2); + if (logical_lte(5, sym104__)) { { { - sym110__ = (5 * 2); - if (logical_lte(5, sym110__)) { + sym107__ = (5 * 2); + if (logical_lte(5, sym107__)) { { { - sym106__ = (5 + 1); + sym103__ = (5 + 1); lp_accum__.add(53); } current_statement__ = 20; - for (size_t k = sym106__; k <= sym110__; ++k) { + for (size_t k = sym103__; k <= sym107__; ++k) { { current_statement__ = 20; lp_accum__.add(53); }} } } else { - sym106__ = (5 + 1); + sym103__ = (5 + 1); } } current_statement__ = 21; - for (size_t j = sym106__; j <= sym107__; ++j) { + for (size_t j = sym103__; j <= sym104__; ++j) { { - sym111__ = (j * 2); - if (logical_lte(j, sym111__)) { + sym108__ = (j * 2); + if (logical_lte(j, sym108__)) { { { - sym108__ = (j + 1); + sym105__ = (j + 1); lp_accum__.add(53); } current_statement__ = 20; - for (size_t k = sym108__; k <= sym111__; ++k) { + for (size_t k = sym105__; k <= sym108__; ++k) { { current_statement__ = 20; lp_accum__.add(53); }} } - } else + } else ; }} } - } else + } else ; } } } @@ -805,7 +819,7 @@ class optimizations_model : public model_base_crtp { { break; } - } else + } else ; current_statement__ = 26; lp_accum__.add(2); }} @@ -817,7 +831,7 @@ class optimizations_model : public model_base_crtp { { continue; } - } else + } else ; current_statement__ = 31; lp_accum__.add(2); }} @@ -829,7 +843,7 @@ class optimizations_model : public model_base_crtp { { continue; } - } else + } else ; current_statement__ = 36; lp_accum__.add(2); }} @@ -990,11 +1004,11 @@ class optimizations_model : public model_base_crtp { { { - sym112__ = (sym113__ * 34); + sym109__ = (theta * 34); } } current_statement__ = 86; - lp_accum__.add(sym112__); + lp_accum__.add(sym109__); } } catch (const std::exception& e) { stan::lang::rethrow_located( @@ -1025,9 +1039,6 @@ class optimizations_model : public model_base_crtp { stan::math::accumulator lp_accum__; try { - double sym78__; - double sym77__; - double sym76__; double sym75__; double sym74__; double sym73__; @@ -1038,57 +1049,59 @@ class optimizations_model : public model_base_crtp { double sym68__; double sym67__; double sym66__; - double sym65__; - Eigen::Matrix sym64__; + Eigen::Matrix sym65__; + int sym64__; int sym63__; - int sym62__; + double sym62__; int sym61__; int sym60__; + double sym59__; double theta; - sym66__ = in__.scalar(); - theta = sym66__; + current_statement__ = 2; + theta = in__.scalar(); double phi; current_statement__ = 3; - phi = sym66__; + phi = in__.scalar(); Eigen::Matrix x_matrix; x_matrix = Eigen::Matrix(3, 2); - sym65__ = in__.matrix(3, 2); - x_matrix = sym65__; + current_statement__ = 4; + x_matrix = in__.matrix(3, 2); Eigen::Matrix x_vector; x_vector = Eigen::Matrix(2); - sym67__ = in__.vector(2); - x_vector = sym67__; + current_statement__ = 5; + x_vector = in__.vector(2); Eigen::Matrix x_cov; x_cov = Eigen::Matrix(2, 2); Eigen::Matrix x_cov_in__; x_cov_in__ = Eigen::Matrix(3); - sym68__ = in__.vector(3); - assign(sym64__, nil_index_list(), cov_matrix_constrain(sym68__, 2), "assigning variable sym64__"); - assign(x_cov, nil_index_list(), sym64__, "assigning variable x_cov"); - vars__.push_back(sym66__); - vars__.push_back(sym66__); + current_statement__ = 6; + x_cov_in__ = in__.vector(3); + assign(sym65__, nil_index_list(), cov_matrix_constrain(x_cov_in__, 2), "assigning variable sym65__"); + assign(x_cov, nil_index_list(), sym65__, "assigning variable x_cov"); + vars__.push_back(theta); + vars__.push_back(phi); { { { { { { - vars__.push_back(sym65__[(1 - 1)][(1 - 1)]); + vars__.push_back(rvalue(x_matrix, cons_list(index_uni(1), cons_list(index_uni(1), nil_index_list())), "x_matrix")); } { { - vars__.push_back(sym65__[(2 - 1)][(1 - 1)]); + vars__.push_back(rvalue(x_matrix, cons_list(index_uni(2), cons_list(index_uni(1), nil_index_list())), "x_matrix")); } } { { - vars__.push_back(sym65__[(3 - 1)][(1 - 1)]); + vars__.push_back(rvalue(x_matrix, cons_list(index_uni(3), cons_list(index_uni(1), nil_index_list())), "x_matrix")); } } } @@ -1099,16 +1112,16 @@ class optimizations_model : public model_base_crtp { { { { - vars__.push_back(sym65__[(1 - 1)][(2 - 1)]); + vars__.push_back(rvalue(x_matrix, cons_list(index_uni(1), cons_list(index_uni(2), nil_index_list())), "x_matrix")); } { { - vars__.push_back(sym65__[(2 - 1)][(2 - 1)]); + vars__.push_back(rvalue(x_matrix, cons_list(index_uni(2), cons_list(index_uni(2), nil_index_list())), "x_matrix")); } } { { - vars__.push_back(sym65__[(3 - 1)][(2 - 1)]); + vars__.push_back(rvalue(x_matrix, cons_list(index_uni(3), cons_list(index_uni(2), nil_index_list())), "x_matrix")); } } } @@ -1120,11 +1133,11 @@ class optimizations_model : public model_base_crtp { { { { - vars__.push_back(sym67__[(1 - 1)]); + vars__.push_back(x_vector[(1 - 1)]); } { { - vars__.push_back(sym67__[(2 - 1)]); + vars__.push_back(x_vector[(2 - 1)]); } } } @@ -1135,11 +1148,11 @@ class optimizations_model : public model_base_crtp { { { { - vars__.push_back(rvalue(sym64__, cons_list(index_uni(1), cons_list(index_uni(1), nil_index_list())), "sym64__")); + vars__.push_back(rvalue(sym65__, cons_list(index_uni(1), cons_list(index_uni(1), nil_index_list())), "sym65__")); } { { - vars__.push_back(rvalue(sym64__, cons_list(index_uni(2), cons_list(index_uni(1), nil_index_list())), "sym64__")); + vars__.push_back(rvalue(sym65__, cons_list(index_uni(2), cons_list(index_uni(1), nil_index_list())), "sym65__")); } } } @@ -1150,11 +1163,11 @@ class optimizations_model : public model_base_crtp { { { { - vars__.push_back(rvalue(sym64__, cons_list(index_uni(1), cons_list(index_uni(2), nil_index_list())), "sym64__")); + vars__.push_back(rvalue(sym65__, cons_list(index_uni(1), cons_list(index_uni(2), nil_index_list())), "sym65__")); } { { - vars__.push_back(rvalue(sym64__, cons_list(index_uni(2), cons_list(index_uni(2), nil_index_list())), "sym64__")); + vars__.push_back(rvalue(sym65__, cons_list(index_uni(2), cons_list(index_uni(2), nil_index_list())), "sym65__")); } } } @@ -1167,12 +1180,12 @@ class optimizations_model : public model_base_crtp { { return ; } - } else + } else ; if (logical_negation(emit_generated_quantities__)) { { return ; } - } else + } else ; } catch (const std::exception& e) { stan::lang::rethrow_located( std::runtime_error(std::string("inside write_array") + ": " + e.what()), locations_array__[current_statement__]); @@ -1189,25 +1202,24 @@ class optimizations_model : public model_base_crtp { vars__.reserve(num_params_r__); try { - double sym59__; - double sym58__; - double sym57__; - double sym56__; + int sym58__; + int sym57__; + int sym56__; int sym55__; int sym54__; int sym53__; int sym52__; int sym51__; - int sym50__; - int sym49__; - int sym48__; + double sym50__; + double sym49__; + double sym48__; double sym47__; double sym46__; double sym45__; double sym44__; double sym43__; double sym42__; - Eigen::Matrix sym41__; + double sym41__; int sym40__; int sym39__; int sym38__; @@ -1215,10 +1227,10 @@ class optimizations_model : public model_base_crtp { double theta; - sym49__ = context__.vals_r("theta")[(1 - 1)]; + sym52__ = context__.vals_r("theta")[(1 - 1)]; double phi; - sym48__ = context__.vals_r("phi")[(1 - 1)]; + sym51__ = context__.vals_r("phi")[(1 - 1)]; Eigen::Matrix x_matrix; x_matrix = Eigen::Matrix(3, 2); @@ -1348,8 +1360,8 @@ class optimizations_model : public model_base_crtp { } current_statement__ = 6; assign(x_cov, nil_index_list(), cov_matrix_free(x_cov), "assigning variable x_cov"); - vars__.push_back(sym49__); - vars__.push_back(sym48__); + vars__.push_back(sym52__); + vars__.push_back(sym51__); { { { @@ -1412,12 +1424,11 @@ class optimizations_model : public model_base_crtp { { { { - assign(sym41__, nil_index_list(), cov_matrix_free(x_cov), "assigning variable sym41__"); - vars__.push_back(rvalue(cov_matrix_free(sym41__), cons_list(index_uni(1), cons_list(index_uni(1), nil_index_list())), "FnUnconstrain__(sym41__, \"cov_matrix\")")); + vars__.push_back(rvalue(x_cov, cons_list(index_uni(1), cons_list(index_uni(1), nil_index_list())), "x_cov")); } { { - vars__.push_back(rvalue(cov_matrix_free(sym41__), cons_list(index_uni(2), cons_list(index_uni(1), nil_index_list())), "FnUnconstrain__(sym41__, \"cov_matrix\")")); + vars__.push_back(rvalue(x_cov, cons_list(index_uni(2), cons_list(index_uni(1), nil_index_list())), "x_cov")); } } } @@ -1428,13 +1439,11 @@ class optimizations_model : public model_base_crtp { { { { - assign(sym41__, nil_index_list(), cov_matrix_free( - x_cov), "assigning variable sym41__"); - vars__.push_back(rvalue(cov_matrix_free(sym41__), cons_list(index_uni(1), cons_list(index_uni(2), nil_index_list())), "FnUnconstrain__(sym41__, \"cov_matrix\")")); + vars__.push_back(rvalue(x_cov, cons_list(index_uni(1), cons_list(index_uni(2), nil_index_list())), "x_cov")); } { { - vars__.push_back(rvalue(cov_matrix_free(sym41__), cons_list(index_uni(2), cons_list(index_uni(2), nil_index_list())), "FnUnconstrain__(sym41__, \"cov_matrix\")")); + vars__.push_back(rvalue(x_cov, cons_list(index_uni(2), cons_list(index_uni(2), nil_index_list())), "x_cov")); } } } @@ -1490,22 +1499,22 @@ class optimizations_model : public model_base_crtp { param_names__.push_back(std::string() + "theta"); param_names__.push_back(std::string() + "phi"); - for (size_t sym114__ = 1; sym114__ <= 2; ++sym114__) { + for (size_t sym110__ = 1; sym110__ <= 2; ++sym110__) { { - for (size_t sym115__ = 1; sym115__ <= 3; ++sym115__) { + for (size_t sym111__ = 1; sym111__ <= 3; ++sym111__) { { - param_names__.push_back(std::string() + "x_matrix" + '.' + std::to_string(sym115__) + '.' + std::to_string(sym114__)); + param_names__.push_back(std::string() + "x_matrix" + '.' + std::to_string(sym111__) + '.' + std::to_string(sym110__)); }} }} - for (size_t sym114__ = 1; sym114__ <= 2; ++sym114__) { + for (size_t sym110__ = 1; sym110__ <= 2; ++sym110__) { { - param_names__.push_back(std::string() + "x_vector" + '.' + std::to_string(sym114__)); + param_names__.push_back(std::string() + "x_vector" + '.' + std::to_string(sym110__)); }} - for (size_t sym114__ = 1; sym114__ <= 2; ++sym114__) { + for (size_t sym110__ = 1; sym110__ <= 2; ++sym110__) { { - for (size_t sym115__ = 1; sym115__ <= 2; ++sym115__) { + for (size_t sym111__ = 1; sym111__ <= 2; ++sym111__) { { - param_names__.push_back(std::string() + "x_cov" + '.' + std::to_string(sym115__) + '.' + std::to_string(sym114__)); + param_names__.push_back(std::string() + "x_cov" + '.' + std::to_string(sym111__) + '.' + std::to_string(sym110__)); }} }} if (emit_transformed_parameters__) { @@ -1524,20 +1533,20 @@ class optimizations_model : public model_base_crtp { param_names__.push_back(std::string() + "theta"); param_names__.push_back(std::string() + "phi"); - for (size_t sym114__ = 1; sym114__ <= 2; ++sym114__) { + for (size_t sym110__ = 1; sym110__ <= 2; ++sym110__) { { - for (size_t sym115__ = 1; sym115__ <= 3; ++sym115__) { + for (size_t sym111__ = 1; sym111__ <= 3; ++sym111__) { { - param_names__.push_back(std::string() + "x_matrix" + '.' + std::to_string(sym115__) + '.' + std::to_string(sym114__)); + param_names__.push_back(std::string() + "x_matrix" + '.' + std::to_string(sym111__) + '.' + std::to_string(sym110__)); }} }} - for (size_t sym114__ = 1; sym114__ <= 2; ++sym114__) { + for (size_t sym110__ = 1; sym110__ <= 2; ++sym110__) { { - param_names__.push_back(std::string() + "x_vector" + '.' + std::to_string(sym114__)); + param_names__.push_back(std::string() + "x_vector" + '.' + std::to_string(sym110__)); }} - for (size_t sym114__ = 1; sym114__ <= 3; ++sym114__) { + for (size_t sym110__ = 1; sym110__ <= 3; ++sym110__) { { - param_names__.push_back(std::string() + "x_cov" + '.' + std::to_string(sym114__)); + param_names__.push_back(std::string() + "x_cov" + '.' + std::to_string(sym110__)); }} if (emit_transformed_parameters__) {