diff --git a/src/analysis_and_optimization/Monotone_framework.ml b/src/analysis_and_optimization/Monotone_framework.ml index b0fd6d492a..01be26f5a5 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,8 @@ 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..7ca636cd51 100644 --- a/src/analysis_and_optimization/Optimize.ml +++ b/src/analysis_and_optimization/Optimize.ml @@ -520,16 +520,15 @@ 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) -> - String.suffix f 3 = "_lp" || List.exists ~f:can_side_effect_expr 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) + || (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 @@ -541,6 +540,12 @@ 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 @@ -807,8 +812,13 @@ 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) diff --git a/src/analysis_and_optimization/Partial_evaluator.ml b/src/analysis_and_optimization/Partial_evaluator.ml index f0f37116e0..8fb5b1d43e 100644 --- a/src/analysis_and_optimization/Partial_evaluator.ml +++ b/src/analysis_and_optimization/Partial_evaluator.ml @@ -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 diff --git a/src/stan_math_backend/Stan_math_code_gen.ml b/src/stan_math_backend/Stan_math_code_gen.ml index f5a8cfa60a..2bde2ceac7 100644 --- a/src/stan_math_backend/Stan_math_code_gen.ml +++ b/src/stan_math_backend/Stan_math_code_gen.ml @@ -118,7 +118,13 @@ 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) ; + 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) ; pf ppf "@ " in let templates = diff --git a/src/stan_math_backend/Statement_gen.ml b/src/stan_math_backend/Statement_gen.ml index 6411cff876..f08fb5622b 100644 --- a/src/stan_math_backend/Statement_gen.ml +++ b/src/stan_math_backend/Statement_gen.ml @@ -151,7 +151,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/src/stanc/stanc.ml b/src/stanc/stanc.ml index 1f1b442c06..669cf866ee 100644 --- a/src/stanc/stanc.ml +++ b/src/stanc/stanc.ml @@ -20,9 +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_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 dump_opt_mir = ref false let output_file = ref "" let generate_data = ref false let warn_uninitialized = ref false @@ -56,12 +58,20 @@ let options = , " For debugging purposes: pretty-print the MIR." ) ; ( "--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." ) + , " 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_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" , 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." @@ -207,6 +217,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 ( @@ -214,6 +226,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 diff --git a/test/integration/bad/stanc.expected b/test/integration/bad/stanc.expected index 9e8fb86067..da819b4853 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 198, characters 14-54 -Called from file "src/stanc/stanc.ml", line 243, characters 9-16 +Called from file "src/stanc/stanc.ml", line 208, characters 14-54 +Called from file "src/stanc/stanc.ml", line 257, 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: diff --git a/test/integration/good/compiler-optimizations/cpp.expected b/test/integration/good/compiler-optimizations/cpp.expected index fe1353a952..8bbbe9222b 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__ = 87; - if (logical_gt(x, 342)) { - { - current_statement__ = 86; - return ; - } - } else - current_statement__ = 7; - lp_accum__.add(y); + try { + int sym34__; + int sym33__; + { + current_statement__ = 87; + if (logical_gt(x, 342)) { + { + current_statement__ = 86; + return ; + } + } else ; + current_statement__ = 7; + lp_accum__.add(y); + } } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); // Next line prevents compiler griping about no return @@ -201,19 +203,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__ = 11; - if (logical_gt(y, 2)) { - { - current_statement__ = 10; - return (y + 24); - } - } else - current_statement__ = 88; - return (y + 2); + try { + int sym37__; + int sym36__; + int sym35__; + { + current_statement__ = 11; + if (logical_gt(y, 2)) { + { + current_statement__ = 10; + return (y + 24); + } + } else ; + current_statement__ = 88; + return (y + 2); + } } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); // Next line prevents compiler griping about no return @@ -240,10 +244,12 @@ rfun_lp(T_lp__& lp__, T_lp_accum__& lp_accum__, std::ostream* pstream__) { (void) DUMMY_VAR__; // suppress unused var warning try { - current_statement__ = 55; - lp_accum__.add(2); - current_statement__ = 89; - return 24; + { + current_statement__ = 55; + lp_accum__.add(2); + current_statement__ = 89; + return 24; + } } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); // Next line prevents compiler griping about no return @@ -311,11 +317,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__; @@ -346,23 +348,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__ = 1; + theta = in__.scalar(); local_scalar_t__ phi; + current_statement__ = 2; + phi = in__.scalar(); Eigen::Matrix x_matrix; x_matrix = Eigen::Matrix(3, 2); + current_statement__ = 3; + x_matrix = in__.matrix(3, 2); Eigen::Matrix x_vector; x_vector = Eigen::Matrix(2); + current_statement__ = 4; + 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__ = 5; + x_cov_in__ = in__.vector(3); { double x; @@ -408,7 +422,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__) { @@ -457,22 +471,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__; @@ -508,7 +522,7 @@ class optimizations_model : public model_base_crtp { }} }} } - } else + } else ; { { { @@ -564,40 +578,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__ = 19; - for (size_t k = sym108__; k <= sym111__; ++k) { + for (size_t k = sym105__; k <= sym108__; ++k) { { current_statement__ = 19; 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__ = 19; - for (size_t k = sym108__; k <= sym111__; ++k) { + for (size_t k = sym105__; k <= sym108__; ++k) { { current_statement__ = 19; lp_accum__.add(53); }} } - } else + } else ; } } } @@ -605,190 +619,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__ = 19; - for (size_t k = sym106__; k <= sym110__; ++k) { + for (size_t k = sym103__; k <= sym107__; ++k) { { current_statement__ = 19; lp_accum__.add(53); }} } } else { - sym106__ = (2 + 1); + sym103__ = (2 + 1); } } current_statement__ = 20; - 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__ = 19; - for (size_t k = sym108__; k <= sym111__; ++k) { + for (size_t k = sym105__; k <= sym108__; ++k) { { current_statement__ = 19; 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__ = 19; - for (size_t k = sym106__; k <= sym110__; ++k) { + for (size_t k = sym103__; k <= sym107__; ++k) { { current_statement__ = 19; lp_accum__.add(53); }} } } else { - sym106__ = (3 + 1); + sym103__ = (3 + 1); } } current_statement__ = 20; - 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__ = 19; - for (size_t k = sym108__; k <= sym111__; ++k) { + for (size_t k = sym105__; k <= sym108__; ++k) { { current_statement__ = 19; 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__ = 19; - for (size_t k = sym106__; k <= sym110__; ++k) { + for (size_t k = sym103__; k <= sym107__; ++k) { { current_statement__ = 19; lp_accum__.add(53); }} } } else { - sym106__ = (4 + 1); + sym103__ = (4 + 1); } } current_statement__ = 20; - 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__ = 19; - for (size_t k = sym108__; k <= sym111__; ++k) { + for (size_t k = sym105__; k <= sym108__; ++k) { { current_statement__ = 19; 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__ = 19; - for (size_t k = sym106__; k <= sym110__; ++k) { + for (size_t k = sym103__; k <= sym107__; ++k) { { current_statement__ = 19; lp_accum__.add(53); }} } } else { - sym106__ = (5 + 1); + sym103__ = (5 + 1); } } current_statement__ = 20; - 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__ = 19; - for (size_t k = sym108__; k <= sym111__; ++k) { + for (size_t k = sym105__; k <= sym108__; ++k) { { current_statement__ = 19; lp_accum__.add(53); }} } - } else + } else ; }} } - } else + } else ; } } } @@ -801,7 +815,7 @@ class optimizations_model : public model_base_crtp { { break; } - } else + } else ; current_statement__ = 25; lp_accum__.add(2); }} @@ -813,7 +827,7 @@ class optimizations_model : public model_base_crtp { { continue; } - } else + } else ; current_statement__ = 30; lp_accum__.add(2); }} @@ -825,7 +839,7 @@ class optimizations_model : public model_base_crtp { { continue; } - } else + } else ; current_statement__ = 35; lp_accum__.add(2); }} @@ -986,11 +1000,11 @@ class optimizations_model : public model_base_crtp { { { - sym112__ = (sym113__ * 34); + sym109__ = (theta * 34); } } current_statement__ = 85; - lp_accum__.add(sym112__); + lp_accum__.add(sym109__); } } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); @@ -1020,9 +1034,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__; @@ -1033,57 +1044,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__ = 1; + theta = in__.scalar(); double phi; current_statement__ = 2; - 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__ = 3; + x_matrix = in__.matrix(3, 2); Eigen::Matrix x_vector; x_vector = Eigen::Matrix(2); - sym67__ = in__.vector(2); - x_vector = sym67__; + current_statement__ = 4; + 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__ = 5; + 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")); } } } @@ -1094,16 +1107,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")); } } } @@ -1115,11 +1128,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)]); } } } @@ -1130,11 +1143,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__")); } } } @@ -1145,11 +1158,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__")); } } } @@ -1162,12 +1175,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(e, locations_array__[current_statement__]); // Next line prevents compiler griping about no return @@ -1183,25 +1196,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__; @@ -1209,10 +1221,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); @@ -1342,8 +1354,8 @@ class optimizations_model : public model_base_crtp { } current_statement__ = 5; 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__); { { { @@ -1406,12 +1418,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")); } } } @@ -1422,13 +1433,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")); } } } @@ -1483,22 +1492,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__) { @@ -1517,20 +1526,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__) {