diff --git a/src/analysis_and_optimization/Mem_pattern.ml b/src/analysis_and_optimization/Mem_pattern.ml index 29e505c3fa..414db8ada6 100644 --- a/src/analysis_and_optimization/Mem_pattern.ml +++ b/src/analysis_and_optimization/Mem_pattern.ml @@ -17,7 +17,7 @@ let rec matrix_set Expr.Fixed.{pattern; meta= Expr.Typed.Meta.{type_; _} as meta if UnsizedType.contains_eigen_type type_ then union_recur exprs else Set.Poly.empty | TernaryIf (_, expr2, expr3) -> union_recur [expr2; expr3] - | Indexed (expr, _) -> matrix_set expr + | Indexed (expr, _) | Promotion (expr, _, _) -> matrix_set expr | EAnd (expr1, expr2) | EOr (expr1, expr2) -> union_recur [expr1; expr2] else Set.Poly.empty @@ -45,7 +45,7 @@ let is_nonzero_subset ~set ~subset = && not (Set.Poly.is_empty subset) (** - * Check an expression to count how many times we see a single index. + * Check an expression to count how many times we see a single index. * @param acc An accumulator from previous folds of multiple expressions. * @param pattern The expression patterns to match against *) @@ -62,6 +62,7 @@ let rec count_single_idx_exprs (acc : int) Expr.Fixed.{pattern; _} : int = acc + count_single_idx_exprs 0 idx_expr + List.fold_left ~init:0 ~f:count_single_idx indexed + | Promotion (expr, _, _) -> count_single_idx_exprs acc expr | EAnd (lhs, rhs) -> acc + count_single_idx_exprs 0 lhs + count_single_idx_exprs 0 rhs | EOr (lhs, rhs) -> @@ -72,9 +73,9 @@ let rec count_single_idx_exprs (acc : int) Expr.Fixed.{pattern; _} : int = (** * Check an Index to count how many times we see a single index. * @param acc An accumulator from previous folds of multiple expressions. - * @param idx An Index to match. For Single types this adds 1 to the - * acc. For Upfrom and MultiIndex types we check the inner expression - * for a Single index. All and Between cannot be Single cell access + * @param idx An Index to match. For Single types this adds 1 to the + * acc. For Upfrom and MultiIndex types we check the inner expression + * for a Single index. All and Between cannot be Single cell access * and so pass acc along. *) and count_single_idx (acc : int) (idx : Expr.Typed.Meta.t Expr.Fixed.t Index.t) @@ -84,13 +85,13 @@ and count_single_idx (acc : int) (idx : Expr.Typed.Meta.t Expr.Fixed.t Index.t) | Single _ -> acc + 1 (** - * Find indices on Matrix and Vector types that perform single + * Find indices on Matrix and Vector types that perform single * cell access. Returns true if it finds * a vector, row vector, matrix, or matrix with single cell access - * as well as an array of any of the above that is accessing the + * as well as an array of any of the above that is accessing the * inner matrix types cell. * @param ut An UnsizedType to match against. - * @param index This list is checked for Single cell access + * @param index This list is checked for Single cell access * either at the top level or within the `Index` types of the list. *) let rec is_uni_eigen_loop_indexing in_loop (ut : UnsizedType.t) @@ -122,7 +123,7 @@ let is_fun_soa_supported name exprs = * see the docs for `query_initial_demotable_funs`. * @param in_loop a boolean to signify if the expression exists inside * of a loop. If so, the names of matrix and vector like objects - * will be returned if the matrix or vector is accessed by single + * will be returned if the matrix or vector is accessed by single * cell indexing. *) let rec query_initial_demotable_expr (in_loop : bool) ~(acc : string Set.Poly.t) @@ -147,6 +148,7 @@ let rec query_initial_demotable_expr (in_loop : bool) ~(acc : string Set.Poly.t) Set.Poly.union acc index_demotes | Var (_ : string) | Lit ((_ : Expr.Fixed.Pattern.litType), (_ : string)) -> acc + | Promotion (expr, _, _) -> query_expr acc expr | TernaryIf (predicate, texpr, fexpr) -> let predicate_demotes = query_expr acc predicate in Set.Poly.union @@ -159,18 +161,18 @@ let rec query_initial_demotable_expr (in_loop : bool) ~(acc : string Set.Poly.t) Set.Poly.union (query_expr full_lhs_rhs lhs) (query_expr full_lhs_rhs rhs) (** - * Query a function to detect if it or any of its used + * Query a function to detect if it or any of its used * expression's objects or expressions should be demoted to AoS. * * The logic here demotes the expressions in a function to AoS if - * the function's inner expression returns has a meta type containing a matrix + * the function's inner expression returns has a meta type containing a matrix * and either of : * (1) The function is user defined and the UDFs inputs are matrices. * (2) The Stan math function cannot support AoS * @param in_loop A boolean to specify the logic of indexing expressions. See * `query_initial_demotable_expr` for an explanation of the logic. - * @param kind The function type, for StanLib functions we check if the - * function supports SoA and for UserDefined functions we always fail + * @param kind The function type, for StanLib functions we check if the + * function supports SoA and for UserDefined functions we always fail * and return back all of the names of the objects passed in expressions * to the UDF. * exprs The expression list passed to the functions. @@ -212,7 +214,8 @@ let rec is_any_soa_supported_expr match pattern with | FunApp (kind, (exprs : Expr.Typed.Meta.t Expr.Fixed.t list)) -> is_any_soa_supported_fun_expr kind exprs - | Indexed (expr, (_ : Typed.Meta.t Fixed.t Index.t list)) -> + | Indexed (expr, (_ : Typed.Meta.t Fixed.t Index.t list)) + |Promotion (expr, _, _) -> is_any_soa_supported_expr expr | Var (_ : string) | Lit ((_ : Expr.Fixed.Pattern.litType), (_ : string)) -> true @@ -248,7 +251,8 @@ let rec is_any_ad_real_data_matrix_expr match pattern with | FunApp (kind, (exprs : Expr.Typed.Meta.t Expr.Fixed.t list)) -> is_any_ad_real_data_matrix_expr_fun kind exprs - | Indexed (expr, _) -> is_any_ad_real_data_matrix_expr expr + | Indexed (expr, _) | Promotion (expr, _, _) -> + is_any_ad_real_data_matrix_expr expr | Var (_ : string) | Lit ((_ : Expr.Fixed.Pattern.litType), (_ : string)) -> false | TernaryIf (_, texpr, fexpr) -> @@ -303,15 +307,15 @@ and is_any_ad_real_data_matrix_expr_fun (kind : 'a Fun_kind.t) (** * Query to find the initial set of objects in statements that cannot be SoA. - * This is mostly recursive over expressions and statements, with the exception of + * This is mostly recursive over expressions and statements, with the exception of * functions and Assignments. * * For assignments: * We demote the LHS variable if any of the following are true: - * 1. None of the RHS's functions are able to accept SoA matrices + * 1. None of the RHS's functions are able to accept SoA matrices * and the rhs is not an internal compiler function. * 2. A single cell of the LHS is being assigned within a loop. - * 3. The top level expression on the RHS is a combination of only + * 3. The top level expression on the RHS is a combination of only * data matrices and scalar types. Operations on data matrix and * scalar values in Stan math will return a AoS matrix. We currently * have no way to tell Stan math to return a SoA matrix. @@ -408,11 +412,11 @@ let rec query_initial_demotable_stmt (in_loop : bool) (acc : string Set.Poly.t) (** Look through a statement to see whether the objects used in it need to be * modified from SoA to AoS. Returns the set of object names that need demoted * in a statement, if any. - * This function looks at Assignment statements, and returns back the + * This function looks at Assignment statements, and returns back the * set of top level object names given: - * 1. If the name of the lhs assignee is in the `aos_exits`, all the names + * 1. If the name of the lhs assignee is in the `aos_exits`, all the names * of the expressions with a type containing a matrix are returned. - * 2. If the names of the rhs objects containing matrix types are in the subset of + * 2. If the names of the rhs objects containing matrix types are in the subset of * aos_exits. * @param aos_exits A set of variables that can be demoted. * @param pattern The Stmt pattern to query. @@ -437,15 +441,15 @@ let query_demotable_stmt (aos_exits : string Set.Poly.t) (** * Modify a function and it's subexpressions from SoA <-> AoS and vice versa. - * This performs demotion for sub expressions recursively. The top level - * expression and it's sub expressions are demoted to SoA if - * 1. The names of the variables in the subexpressions returning + * This performs demotion for sub expressions recursively. The top level + * expression and it's sub expressions are demoted to SoA if + * 1. The names of the variables in the subexpressions returning * objects holding matrices are all in the modifiable set. * 2. The function does not support SoA * 3. The `force` argument is `true` - * @param force_demotion If true, forces an expression and it's sub-expressions + * @param force_demotion If true, forces an expression and it's sub-expressions * to be AoS. - * @param modifiable_set The set of names that are either demotable + * @param modifiable_set The set of names that are either demotable * to AoS or promotable to SoA. * @param kind A `Fun_kind.t` * @param exprs A list of expressions going into the function. @@ -474,7 +478,7 @@ let rec modify_kind ?force_demotion:(force = false) ( kind , List.map ~f:(modify_expr ~force_demotion:force modifiable_set) exprs ) -(** +(** * Modify an expression and it's subexpressions from SoA <-> AoS * and vice versa. The only real paths in the below is on the * functions and ternary expressions. @@ -482,7 +486,7 @@ let rec modify_kind ?force_demotion:(force = false) * The logic for functions is defined in `modify_kind`. * `TernaryIf` is forcefully demoted to AoS if the type of the expression * contains a matrix. - * @param force_demotion If true, forces an expression and it's sub-expressions + * @param force_demotion If true, forces an expression and it's sub-expressions * to be AoS. * @param modifiable_set The name of the variables whose * associated expressions we want to modify. @@ -519,11 +523,13 @@ and modify_expr_pattern ?force_demotion:(force = false) , List.map ~f:(Index.map (mod_expr ~force_demotion:force)) indexed ) | EAnd (lhs, rhs) -> EAnd (mod_expr lhs, mod_expr rhs) | EOr (lhs, rhs) -> EOr (mod_expr lhs, mod_expr rhs) + | Promotion (expr, type_, ad_level) -> + Promotion (mod_expr expr, type_, ad_level) | Var (_ : string) | Lit ((_ : Expr.Fixed.Pattern.litType), (_ : string)) -> pattern -(** -* Given a Set of strings containing the names of objects that can be +(** +* Given a Set of strings containing the names of objects that can be * modified from AoS <-> SoA and vice versa, modify them within the expression. * @param mem_pattern The memory pattern to change expressions to. * @param modifiable_set The name of the variables whose @@ -536,15 +542,15 @@ and modify_expr ?force_demotion:(force = false) pattern= modify_expr_pattern ~force_demotion:force modifiable_set pattern } (** -* Modify statement patterns in the MIR from AoS <-> SoA and vice versa +* Modify statement patterns in the MIR from AoS <-> SoA and vice versa * For `Decl` and `Assignment`'s reading in parameters, we demote to AoS * if the `decl_id` (or assign name) is in the modifiable set and * otherwise promote the statement to `SoA`. * For general `Assignment` statements, we check if the assignee is in * the demotable set. If so, we force demotion of all of the rhs expressions. * All other statements recurse over their statements and expressions. -* -* @param pattern The statement pattern to modify +* +* @param pattern The statement pattern to modify * @param modifiable_set The name of the variable we are searching for. *) let rec modify_stmt_pattern @@ -624,11 +630,11 @@ let rec modify_stmt_pattern | Skip | Break | Continue | Decl _ -> pattern (** -* Modify statement patterns in the MIR from AoS <-> SoA and vice versa -* @param mem_pattern A mem_pattern to modify expressions to. For the -* given memory pattern, this modifies +* Modify statement patterns in the MIR from AoS <-> SoA and vice versa +* @param mem_pattern A mem_pattern to modify expressions to. For the +* given memory pattern, this modifies * statement patterns and expressions to it. -* @param stmt The statement to modify. +* @param stmt The statement to modify. * @param modifiable_set The name of the variable we are searching for. *) and modify_stmt (Stmt.Fixed.{pattern; _} as stmt) diff --git a/src/analysis_and_optimization/Mir_utils.ml b/src/analysis_and_optimization/Mir_utils.ml index de0695d1e1..6b421228af 100644 --- a/src/analysis_and_optimization/Mir_utils.ml +++ b/src/analysis_and_optimization/Mir_utils.ml @@ -251,6 +251,7 @@ let rec expr_var_set Expr.Fixed.{pattern; meta} = | TernaryIf (expr1, expr2, expr3) -> union_recur [expr1; expr2; expr3] | Indexed (expr, ix) -> Set.Poly.union_list (expr_var_set expr :: List.map ix ~f:index_var_set) + | Promotion (expr, _, _) -> expr_var_set expr | EAnd (expr1, expr2) | EOr (expr1, expr2) -> union_recur [expr1; expr2] and index_var_set ix = @@ -369,6 +370,7 @@ let rec expr_depth Expr.Fixed.{pattern; _} = + max (expr_depth e) (Option.value ~default:0 (List.max_elt ~compare:compare_int (List.map ~f:idx_depth l)) ) + | Promotion (expr, _, _) -> 1 + expr_depth expr | EAnd (e1, e2) | EOr (e1, e2) -> 1 + Option.value ~default:0 @@ -413,6 +415,10 @@ let rec update_expr_ad_levels autodiffable_variables let e1 = update_expr_ad_levels autodiffable_variables e1 in let e2 = update_expr_ad_levels autodiffable_variables e2 in {pattern= EOr (e1, e2); meta= {e.meta with adlevel= ad_level_sup [e1; e2]}} + | Promotion (expr, ut, ad) -> + let expr' = update_expr_ad_levels autodiffable_variables expr in + { pattern= Promotion (expr', ut, ad) + ; meta= {e.meta with adlevel= ad_level_sup [expr']} } | Indexed (ixed, i_list) -> let ixed = update_expr_ad_levels autodiffable_variables ixed in let i_list = diff --git a/src/analysis_and_optimization/Monotone_framework.ml b/src/analysis_and_optimization/Monotone_framework.ml index ce7761f4c7..0d6c93e595 100644 --- a/src/analysis_and_optimization/Monotone_framework.ml +++ b/src/analysis_and_optimization/Monotone_framework.ml @@ -24,6 +24,7 @@ let print_mfp to_string (mfp : (int, 'a entry_exit) Map.Poly.t) let rec free_vars_expr (e : Expr.Typed.t) = match e.pattern with | Var x -> Set.Poly.singleton x + | Promotion (expr, _, _) -> free_vars_expr expr | Lit (_, _) -> Set.Poly.empty | FunApp (kind, l) -> free_vars_fnapp kind l | TernaryIf (e1, e2, e3) -> @@ -133,15 +134,15 @@ let reverse (type l) (module F : FLOWGRAPH with type labels = l) = with type labels = l ) (** Modify the end nodes of a flowgraph to depend on its inits - * To force the monotone framework to run until the program never changes - * this function modifies the input `Flowgraph` so that it's end nodes + * To force the monotone framework to run until the program never changes + * this function modifies the input `Flowgraph` so that it's end nodes * depend on it's initial nodes. The inits of the reverse flowgraph are used - * for this since we normally have both the forward and reverse flowgraphs + * for this since we normally have both the forward and reverse flowgraphs * available. - * @tparam l Type of the label for each flowgraph, most commonly an int + * @tparam l Type of the label for each flowgraph, most commonly an int * @param Flowgraph The flowgraph to modify - * @param RevFlowgraph The same flowgraph as `Flowgraph` but reversed. - * + * @param RevFlowgraph The same flowgraph as `Flowgraph` but reversed. + * *) let make_circular_flowgraph (type l) (module Flowgraph : FLOWGRAPH with type labels = l) @@ -544,6 +545,7 @@ let rec used_subexpressions_expr (e : Expr.Typed.t) = (Expr.Typed.Set.singleton e) ( match e.pattern with | Var _ | Lit (_, _) -> Expr.Typed.Set.empty + | Promotion (expr, _, _) -> used_subexpressions_expr expr | FunApp (k, l) -> Expr.Typed.Set.union_list (List.map ~f:used_subexpressions_expr (l @ Fun_kind.collect_exprs k)) @@ -1011,14 +1013,14 @@ let lazy_expressions_mfp let used_not_latest_expressions_mfp = Mf4.mfp () in (latest_expr, used_not_latest_expressions_mfp) -(** Run the minimal fixed point algorithm to deduce the smallest set of +(** Run the minimal fixed point algorithm to deduce the smallest set of * variables that satisfy a set of conditions. - * @param Flowgraph The set of nodes to analyze - * @param flowgraph_to_mir Map of nodes to their actual values in the MIR + * @param Flowgraph The set of nodes to analyze + * @param flowgraph_to_mir Map of nodes to their actual values in the MIR * @param initial_variables The set of variables to start in the set - * @param gen_variable Used in the transfer function to deduce variables + * @param gen_variable Used in the transfer function to deduce variables * that should be in the set - * + * *) let minimal_variables_mfp (module Circular_Fwd_Flowgraph : Monotone_framework_sigs.FLOWGRAPH diff --git a/src/analysis_and_optimization/Optimize.ml b/src/analysis_and_optimization/Optimize.ml index f28d4d5e06..91520a387e 100644 --- a/src/analysis_and_optimization/Optimize.ml +++ b/src/analysis_and_optimization/Optimize.ml @@ -224,6 +224,9 @@ let rec inline_function_expression propto adt fim (Expr.Fixed.{pattern; _} as e) match pattern with | Var _ -> ([], [], e) | Lit (_, _) -> ([], [], e) + | Promotion (expr, ut, ad) -> + let d, sl, expr' = inline_function_expression propto adt fim expr in + (d, sl, {e with pattern= Promotion (expr', ut, ad)}) | FunApp (kind, es) -> ( let d_list, s_list, es = inline_list (inline_function_expression propto adt fim) es in @@ -1030,8 +1033,8 @@ let block_fixing mir = (* TODO: add tests *) (* TODO: add pass to get rid of redundant declarations? *) -(** - * A generic optimization pass for finding a minimal set of variables that +(** + * A generic optimization pass for finding a minimal set of variables that * are generated by some circumstance, and then updating the MIR with that set. * @param gen_variables: the variables that must be added to the set at * the given statement diff --git a/src/analysis_and_optimization/Partial_evaluator.ml b/src/analysis_and_optimization/Partial_evaluator.ml index 73657b501d..9c42c35e32 100644 --- a/src/analysis_and_optimization/Partial_evaluator.ml +++ b/src/analysis_and_optimization/Partial_evaluator.ml @@ -93,6 +93,7 @@ let rec eval_expr ?(preserve_stability = false) (e : Expr.Typed.t) = pattern= ( match e.pattern with | Var _ | Lit (_, _) -> e.pattern + | Promotion (expr, ut, ad) -> Promotion (eval_expr expr, ut, ad) | FunApp (kind, l) -> ( let l = List.map ~f:(eval_expr ~preserve_stability) l in match kind with diff --git a/src/frontend/Ast.ml b/src/frontend/Ast.ml index 35fe0da197..fb19d5801f 100644 --- a/src/frontend/Ast.ml +++ b/src/frontend/Ast.ml @@ -44,6 +44,7 @@ type ('e, 'f) expression = | ImagNumeral of string | FunApp of 'f * identifier * 'e list | CondDistApp of 'f * identifier * 'e list + | Promotion of 'e * UnsizedType.t * UnsizedType.autodifftype (* GetLP is deprecated *) | GetLP | GetTarget @@ -250,9 +251,14 @@ type typed_program = typed_statement program [@@deriving sexp, compare, map] (** Forgetful function from typed to untyped expressions *) let rec untyped_expression_of_typed_expression ({expr; emeta} : typed_expression) : untyped_expression = - { expr= - map_expression untyped_expression_of_typed_expression (fun _ -> ()) expr - ; emeta= {loc= emeta.loc} } + match expr with + | Promotion (e, _, _) -> untyped_expression_of_typed_expression e + | _ -> + { expr= + map_expression untyped_expression_of_typed_expression + (fun _ -> ()) + expr + ; emeta= {loc= emeta.loc} } let rec untyped_lvalue_of_typed_lvalue ({lval; lmeta} : typed_lval) : untyped_lval = @@ -304,7 +310,11 @@ let rec id_of_lvalue {lval; _} = let rec get_loc_expr (e : untyped_expression) = match e.expr with - | TernaryIf (e, _, _) | BinOp (e, _, _) | PostfixOp (e, _) | Indexed (e, _) -> + | TernaryIf (e, _, _) + |BinOp (e, _, _) + |PostfixOp (e, _) + |Indexed (e, _) + |Promotion (e, _, _) -> get_loc_expr e | PrefixOp (_, e) | ArrayExpr (e :: _) | RowVectorExpr (e :: _) | Paren e -> e.emeta.loc.begin_loc diff --git a/src/frontend/Ast_to_Mir.ml b/src/frontend/Ast_to_Mir.ml index a57eca091a..8e6405d507 100644 --- a/src/frontend/Ast_to_Mir.ml +++ b/src/frontend/Ast_to_Mir.ml @@ -81,6 +81,7 @@ and trans_expr {Ast.expr; Ast.emeta} = FunApp (CompilerInternal FnMakeRowVec, trans_exprs eles) |> ewrap | Indexed (lhs, indices) -> Indexed (trans_expr lhs, List.map ~f:trans_idx indices) |> ewrap + | Promotion (e, ty, ad) -> Promotion (trans_expr e, ty, ad) |> ewrap and trans_idx = function | Ast.All -> All diff --git a/src/frontend/Canonicalize.ml b/src/frontend/Canonicalize.ml index c489072f5a..3feca5b429 100644 --- a/src/frontend/Canonicalize.ml +++ b/src/frontend/Canonicalize.ml @@ -162,7 +162,7 @@ let rec no_parens {expr; emeta} = | i -> map_index keep_parens i ) l ) ; emeta } - | ArrayExpr _ | RowVectorExpr _ | FunApp _ | CondDistApp _ -> + | ArrayExpr _ | RowVectorExpr _ | FunApp _ | CondDistApp _ | Promotion _ -> {expr= map_expression no_parens ident expr; emeta} and keep_parens {expr; emeta} = diff --git a/src/frontend/Pretty_printing.ml b/src/frontend/Pretty_printing.ml index ab3fc62891..9e01d419a4 100644 --- a/src/frontend/Pretty_printing.ml +++ b/src/frontend/Pretty_printing.ml @@ -272,6 +272,7 @@ and pp_expression ppf ({expr= e_content; emeta= {loc; _}} : untyped_expression) | ArrayExpr es -> pf ppf "{@[%a}@]" pp_list_of_expression (es, loc) | RowVectorExpr es -> pf ppf "[@[%a]@]" pp_list_of_expression (es, loc) | Paren e -> pf ppf "(%a)" pp_expression e + | Promotion (e, _, _) -> pp_expression ppf e | Indexed (e, l) -> ( match l with | [] -> pf ppf "%a" pp_expression e diff --git a/src/frontend/SignatureMismatch.ml b/src/frontend/SignatureMismatch.ml index c77856bd5a..bafb6903ff 100644 --- a/src/frontend/SignatureMismatch.ml +++ b/src/frontend/SignatureMismatch.ml @@ -110,37 +110,49 @@ let rec compare_errors e1 e2 = | SuffixMismatch _, _ | _, InputMismatch _ -> -1 | InputMismatch _, _ | _, SuffixMismatch _ -> 1 ) ) +type promotions = None | RealPromotion | ComplexPromotion + let rec check_same_type depth t1 t2 = - let wrap_func = Option.map ~f:(fun e -> TypeMismatch (t1, t2, Some e)) in + let wrap_func = Result.map_error ~f:(fun e -> TypeMismatch (t1, t2, Some e)) in match (t1, t2) with - | t1, t2 when t1 = t2 -> None - | UnsizedType.(UReal, UInt) when depth < 1 -> None + | t1, t2 when t1 = t2 -> Ok None + | UnsizedType.(UReal, UInt) when depth < 1 -> Ok RealPromotion + | UnsizedType.(UComplex, (UInt | UReal)) when depth < 1 -> Ok ComplexPromotion + (* Arrays: Try to recursively promote, but make sure the error is for these types, + not the recursive call *) + | UArray nt1, UArray nt2 -> + check_same_type depth nt1 nt2 + |> Result.map_error ~f:(function + | TypeMismatch _ -> TypeMismatch (t1, t2, None) + | e -> e ) | UFun (_, _, s1, _), UFun (_, _, s2, _) when Fun_kind.without_propto s1 <> Fun_kind.without_propto s2 -> - Some + Error (SuffixMismatch (Fun_kind.without_propto s1, Fun_kind.without_propto s2)) |> wrap_func | UFun (_, rt1, _, _), UFun (_, rt2, _, _) when rt1 <> rt2 -> - Some (ReturnTypeMismatch (rt1, rt2)) |> wrap_func - | UFun (l1, _, _, _), UFun (l2, _, _, _) -> - check_compatible_arguments (depth + 1) l2 l1 - |> Option.map ~f:(fun e -> InputMismatch e) - |> wrap_func - | t1, t2 -> Some (TypeMismatch (t1, t2, None)) + Error (ReturnTypeMismatch (rt1, rt2)) |> wrap_func + | UFun (l1, _, _, _), UFun (l2, _, _, _) -> ( + match check_compatible_arguments (depth + 1) l2 l1 with + | Ok _ -> Ok None + | Error e -> Error (InputMismatch e) |> wrap_func ) + | t1, t2 -> Error (TypeMismatch (t1, t2, None)) -and check_compatible_arguments depth args1 args2 = - match List.zip args1 args2 with +and check_compatible_arguments depth typs args2 : + (promotions list, function_mismatch) result = + match List.zip typs args2 with | List.Or_unequal_lengths.Unequal_lengths -> - Some (ArgNumMismatch (List.length args1, List.length args2)) + Error (ArgNumMismatch (List.length typs, List.length args2)) | Ok l -> - List.find_mapi l ~f:(fun i ((ad1, ut1), (ad2, ut2)) -> + List.mapi l ~f:(fun i ((ad1, ut1), (ad2, ut2)) -> match check_same_type depth ut1 ut2 with - | Some e -> Some (ArgError (i + 1, e)) - | None -> - if ad1 = ad2 then None + | Error e -> Error (ArgError (i + 1, e)) + | Ok p -> + if ad1 = ad2 then Ok p else if depth < 2 && UnsizedType.autodifftype_can_convert ad1 ad2 - then None - else Some (ArgError (i + 1, DataOnlyError)) ) + then Ok p + else Error (ArgError (i + 1, DataOnlyError)) ) + |> Result.all let check_compatible_arguments_mod_conv = check_compatible_arguments 0 let max_n_errors = 5 @@ -153,6 +165,20 @@ let extract_function_types f = Some (return, args, (fun x -> UserDefined x), mem) | _ -> None +let promote es promotions = + List.map2_exn es promotions ~f:(fun (exp : Ast.typed_expression) prom -> + let open UnsizedType in + let emeta = exp.emeta in + match prom with + | RealPromotion when is_int_type emeta.type_ -> + Ast. + { expr= Ast.Promotion (exp, UReal, emeta.ad_level) + ; emeta= {emeta with type_= promote_array emeta.type_ UReal} } + | ComplexPromotion when not (is_complex_type emeta.type_) -> + { expr= Promotion (exp, UComplex, emeta.ad_level) + ; emeta= {emeta with type_= promote_array emeta.type_ UComplex} } + | _ -> exp ) + let returntype env name args = (* NB: Variadic arguments are special-cased in the typechecker and not handled here *) let name = Utils.stdlib_distribution_name name in @@ -164,8 +190,8 @@ let returntype env name args = |> List.fold_until ~init:[] ~f:(fun errors (rt, tys, funkind_constructor, _) -> match check_compatible_arguments 0 tys args with - | None -> Stop (Ok (rt, funkind_constructor)) - | Some e -> Continue (((rt, tys), e) :: errors) ) + | Ok p -> Stop (Ok (rt, funkind_constructor, p)) + | Error e -> Continue (((rt, tys), e) :: errors) ) ~finish:(fun errors -> let errors = List.sort errors ~compare:(fun (_, e1) (_, e2) -> @@ -180,7 +206,7 @@ let check_variadic_args allow_lpdf mandatory_arg_tys mandatory_fun_arg_tys in let minimal_args = (UnsizedType.AutoDiffable, minimal_func_type) :: mandatory_arg_tys in - let wrap_err x = Some (minimal_args, ArgError (1, x)) in + let wrap_err x = Error (minimal_args, ArgError (1, x)) in match args with | ( _ , ( UnsizedType.UFun (fun_args, ReturnType return_type, suffix, _) as @@ -193,22 +219,22 @@ let check_variadic_args allow_lpdf mandatory_arg_tys mandatory_fun_arg_tys let suffix = Fun_kind.without_propto suffix in if suffix = FnPlain || (allow_lpdf && suffix = FnLpdf ()) then match check_compatible_arguments 1 mandatory mandatory_fun_arg_tys with - | Some x -> wrap_func_error (InputMismatch x) - | None -> ( + | Error x -> wrap_func_error (InputMismatch x) + | Ok _ -> ( match check_same_type 1 return_type fun_return with - | Some _ -> + | Error _ -> wrap_func_error (ReturnTypeMismatch (ReturnType fun_return, ReturnType return_type) ) - | None -> + | Ok _ -> let expected_args = ((UnsizedType.AutoDiffable, func_type) :: mandatory_arg_tys) @ variadic_arg_tys in check_compatible_arguments 0 expected_args args - |> Option.map ~f:(fun x -> (expected_args, x)) ) + |> Result.map_error ~f:(fun x -> (expected_args, x)) ) else wrap_func_error (SuffixMismatch (FnPlain, suffix)) | (_, x) :: _ -> TypeMismatch (minimal_func_type, x, None) |> wrap_err - | [] -> Some ([], ArgNumMismatch (List.length mandatory_arg_tys, 0)) + | [] -> Error ([], ArgNumMismatch (List.length mandatory_arg_tys, 0)) let pp_signature_mismatch ppf (name, arg_tys, (sigs, omitted)) = let open Fmt in diff --git a/src/frontend/SignatureMismatch.mli b/src/frontend/SignatureMismatch.mli index e2a7b1ffb5..0ee871fa11 100644 --- a/src/frontend/SignatureMismatch.mli +++ b/src/frontend/SignatureMismatch.mli @@ -19,16 +19,27 @@ type signature_error = (UnsizedType.returntype * (UnsizedType.autodifftype * UnsizedType.t) list) * function_mismatch +(** Indicate a promotion by the resulting type *) +type promotions = private None | RealPromotion | ComplexPromotion + val check_compatible_arguments_mod_conv : (UnsizedType.autodifftype * UnsizedType.t) list -> (UnsizedType.autodifftype * UnsizedType.t) list - -> function_mismatch option + -> (promotions list, function_mismatch) result + +val promote : + Ast.typed_expression list -> promotions list -> Ast.typed_expression list +(** Given a list of expressions (arguments) and a list of [promotions], + return a list of expressions which include the + [Promotion] expression as appropiate *) val returntype : Environment.t -> string -> (UnsizedType.autodifftype * UnsizedType.t) list - -> ( UnsizedType.returntype * (bool Middle.Fun_kind.suffix -> Ast.fun_kind) + -> ( UnsizedType.returntype + * (bool Middle.Fun_kind.suffix -> Ast.fun_kind) + * promotions list , signature_error list * bool ) result @@ -38,8 +49,9 @@ val check_variadic_args : -> (UnsizedType.autodifftype * UnsizedType.t) list -> UnsizedType.t -> (UnsizedType.autodifftype * UnsizedType.t) list - -> ((UnsizedType.autodifftype * UnsizedType.t) list * function_mismatch) - option + -> ( promotions list + , (UnsizedType.autodifftype * UnsizedType.t) list * function_mismatch ) + result val pp_signature_mismatch : Format.formatter diff --git a/src/frontend/Typechecker.ml b/src/frontend/Typechecker.ml index d5df6ee411..eda71a4dd5 100644 --- a/src/frontend/Typechecker.ml +++ b/src/frontend/Typechecker.ml @@ -158,15 +158,25 @@ let is_of_compatible_return_type rt1 srt2 = (* -- Expressions ------------------------------------------------- *) let check_ternary_if loc pe te fe = + let promote expr type_ ad_level = + if + (not (UnsizedType.equal expr.emeta.type_ type_)) + || UnsizedType.compare_autodifftype expr.emeta.ad_level ad_level <> 0 + then + { expr= Promotion (expr, UnsizedType.internal_scalar type_, ad_level) + ; emeta= {expr.emeta with type_; ad_level} } + else expr in match - (pe.emeta.type_, UnsizedType.common_type (te.emeta.type_, fe.emeta.type_)) + ( pe.emeta.type_ + , UnsizedType.common_type (te.emeta.type_, fe.emeta.type_) + , expr_ad_lub [pe; te; fe] ) with - | UInt, Some type_ when not (UnsizedType.is_fun_type type_) -> + | UInt, Some type_, ad_level when not (UnsizedType.is_fun_type type_) -> mk_typed_expression - ~expr:(TernaryIf (pe, te, fe)) - ~ad_level:(expr_ad_lub [pe; te; fe]) - ~type_ ~loc - | _, _ -> + ~expr: + (TernaryIf (pe, promote te type_ ad_level, promote fe type_ ad_level)) + ~ad_level ~type_ ~loc + | _, _, _ -> Semantic_error.illtyped_ternary_if loc pe.emeta.type_ te.emeta.type_ fe.emeta.type_ |> error @@ -425,14 +435,16 @@ let check_fn ~is_cond_dist loc tenv id es = |> error | _ (* a function *) -> ( match SignatureMismatch.returntype tenv id.name (get_arg_types es) with - | Ok (Void, _) -> + | Ok (Void, _, _) -> Semantic_error.returning_fn_expected_nonreturning_found loc id.name |> error - | Ok (ReturnType ut, fnk) -> + | Ok (ReturnType ut, fnk, promotions) -> mk_typed_expression ~expr: (mk_fun_app ~is_cond_dist - (fnk (Fun_kind.suffix_from_name id.name), id, es) ) + ( fnk (Fun_kind.suffix_from_name id.name) + , id + , SignatureMismatch.promote es promotions ) ) ~ad_level:(expr_ad_lub es) ~type_:ut ~loc | Error x -> es @@ -458,11 +470,13 @@ let check_reduce_sum ~is_cond_dist loc id es = SignatureMismatch.check_variadic_args true mandatory_args mandatory_fun_args UReal (get_arg_types es) with - | None -> + | Ok promotions -> mk_typed_expression - ~expr:(mk_fun_app ~is_cond_dist (StanLib FnPlain, id, es)) + ~expr: + (mk_fun_app ~is_cond_dist + (StanLib FnPlain, id, SignatureMismatch.promote es promotions) ) ~ad_level:(expr_ad_lub es) ~type_:UnsizedType.UReal ~loc - | Some (expected_args, err) -> + | Error (expected_args, err) -> Semantic_error.illtyped_reduce_sum loc id.name (List.map ~f:type_of_expr_typed es) expected_args err @@ -477,7 +491,7 @@ let check_reduce_sum ~is_cond_dist loc id es = let expected_args, err = SignatureMismatch.check_variadic_args true mandatory_args mandatory_fun_args UReal (get_arg_types es) - |> Option.value_exn in + |> Result.error |> Option.value_exn in Semantic_error.illtyped_reduce_sum_generic loc id.name (List.map ~f:type_of_expr_typed es) expected_args err @@ -498,12 +512,14 @@ let check_variadic_ode ~is_cond_dist loc id es = Stan_math_signatures.variadic_ode_mandatory_fun_args Stan_math_signatures.variadic_ode_fun_return_type (get_arg_types es) with - | None -> + | Ok promotions -> mk_typed_expression - ~expr:(mk_fun_app ~is_cond_dist (StanLib FnPlain, id, es)) + ~expr: + (mk_fun_app ~is_cond_dist + (StanLib FnPlain, id, SignatureMismatch.promote es promotions) ) ~ad_level:(expr_ad_lub es) ~type_:Stan_math_signatures.variadic_ode_return_type ~loc - | Some (expected_args, err) -> + | Error (expected_args, err) -> Semantic_error.illtyped_variadic_ode loc id.name (List.map ~f:type_of_expr_typed es) expected_args err @@ -657,6 +673,10 @@ and check_expression cf tenv ({emeta; expr} : Ast.untyped_expression) : es |> List.map ~f:ce |> check_funapp loc cf tenv ~is_cond_dist:false id | CondDistApp ((), id, es) -> es |> List.map ~f:ce |> check_funapp loc cf tenv ~is_cond_dist:true id + | Promotion (e, _, _) -> + (* Should never happen: promotions are produced during typechecking *) + Common.FatalError.fatal_error_msg + [%message "Promotion in untyped AST" (e : Ast.untyped_expression)] and check_expression_of_int_type cf tenv e name = let te = check_expression cf tenv e in @@ -699,11 +719,15 @@ let check_nrfn loc tenv id es = |> error | _ (* a function *) -> ( match SignatureMismatch.returntype tenv id.name (get_arg_types es) with - | Ok (Void, fnk) -> + | Ok (Void, fnk, promotions) -> mk_typed_statement - ~stmt:(NRFunApp (fnk (Fun_kind.suffix_from_name id.name), id, es)) + ~stmt: + (NRFunApp + ( fnk (Fun_kind.suffix_from_name id.name) + , id + , SignatureMismatch.promote es promotions ) ) ~return_type:NoReturnType ~loc - | Ok (ReturnType _, _) -> + | Ok (ReturnType _, _, _) -> Semantic_error.nonreturning_fn_expected_returning_found loc id.name |> error | Error x -> diff --git a/src/middle/Expr.ml b/src/middle/Expr.ml index efefa0d18f..b5fee8335b 100644 --- a/src/middle/Expr.ml +++ b/src/middle/Expr.ml @@ -17,6 +17,7 @@ module Fixed = struct | EAnd of 'a * 'a | EOr of 'a * 'a | Indexed of 'a * 'a Index.t list + | Promotion of 'a * UnsizedType.t * UnsizedType.autodifftype [@@deriving sexp, hash, map, compare, fold] let pp pp_e ppf = function @@ -42,6 +43,8 @@ module Fixed = struct indices | EAnd (l, r) -> Fmt.pf ppf "%a && %a" pp_e l pp_e r | EOr (l, r) -> Fmt.pf ppf "%a || %a" pp_e l pp_e r + | Promotion (from, ut, _) -> + Fmt.pf ppf "%a -> %a" pp_e from UnsizedType.pp ut include Foldable.Make (struct type nonrec 'a t = 'a t @@ -147,6 +150,8 @@ module Labelled = struct associate ~init:(associate ~init:(associate ~init:assocs e3) e2) e1 | Indexed (e, idxs) -> List.fold idxs ~init:(associate ~init:assocs e) ~f:associate_index + (* Not sure?*) + | Promotion (e1, _, _) -> associate ~init:assocs e1 and associate_index assocs = function | All -> assocs diff --git a/src/middle/Expr.mli b/src/middle/Expr.mli index e377247dcd..b3235131ee 100644 --- a/src/middle/Expr.mli +++ b/src/middle/Expr.mli @@ -15,6 +15,7 @@ module Fixed : sig | EAnd of 'a * 'a | EOr of 'a * 'a | Indexed of 'a * 'a Index.t list + | Promotion of 'a * UnsizedType.t * UnsizedType.autodifftype [@@deriving sexp, hash, compare] include Pattern.S with type 'a t := 'a t diff --git a/src/middle/Stan_math_signatures.ml b/src/middle/Stan_math_signatures.ml index a58cbe377b..98f4e23b86 100644 --- a/src/middle/Stan_math_signatures.ml +++ b/src/middle/Stan_math_signatures.ml @@ -340,6 +340,7 @@ let fst2 (a, _, _) = a let thrd (_, _, c) = c (* -- Querying stan_math_signatures -- *) +(* TODO: Remove/prefer to use SignatureMismatch instead of UnsizedType *) let stan_math_returntype (name : string) (args : fun_arg list) = let name = Utils.stdlib_distribution_name name in let namematches = Hashtbl.find_multi stan_math_signatures name in @@ -352,13 +353,12 @@ let stan_math_returntype (name : string) (args : fun_arg list) = | x when is_reduce_sum_fn x -> Some (UnsizedType.ReturnType UReal) | x when is_variadic_ode_fn x -> Some (UnsizedType.ReturnType (UArray UVector)) | _ -> - if List.length filteredmatches = 0 then None - (* Return the least return type in case there are multiple options (due to implicit UInt-UReal conversion), where UInt true | _ -> false +let rec promote_array ut scalar = + match (ut, scalar) with + | (UInt | UReal), (UReal | UComplex) -> scalar + | UArray ut2, _ -> UArray (promote_array ut2 scalar) + | _, _ -> ut + let rec is_int_type ut = match ut with UInt -> true | UArray ut -> is_int_type ut | _ -> false +let rec is_complex_type ut = + match ut with + | UComplex -> true + | UArray ut -> is_complex_type ut + | _ -> false + +let rec internal_scalar ut = + match ut with + | UVector | UMatrix | URowVector | UReal -> UReal + | UInt -> UInt + | UComplex -> UComplex + | UArray ut -> internal_scalar ut + | _ -> + Common.FatalError.fatal_error_msg + [%message "Tried to get scalar type of " (ut : t)] + let is_eigen_type ut = match ut with UVector | URowVector | UMatrix -> true | _ -> false diff --git a/src/stan_math_backend/Expression_gen.ml b/src/stan_math_backend/Expression_gen.ml index 1fddaf3704..a0c972da77 100644 --- a/src/stan_math_backend/Expression_gen.ml +++ b/src/stan_math_backend/Expression_gen.ml @@ -10,13 +10,6 @@ let stan_namespace_qualify f = if String.is_suffix ~suffix:"functor__" f || String.contains f ':' then f else "stan::math::" ^ f -(* return true if the types of the two expression are the same *) -let types_match e1 e2 = - UnsizedType.equal (Expr.Typed.type_of e1) (Expr.Typed.type_of e2) - && UnsizedType.compare_autodifftype (Expr.Typed.adlevel_of e1) - (Expr.Typed.adlevel_of e2) - = 0 - let is_stan_math f = ends_with "__" f || starts_with "stan::math::" f (* retun true if the type of the expression @@ -534,12 +527,17 @@ and pp_indexed_simple ppf (obj, idcs) = | idcs -> pf ppf "[%a]" (list ~sep:(const string "][") pp_expr) idcs ) (List.map ~f:idx_minus_one idcs) -and pp_expr ppf Expr.Fixed.({pattern; meta} as e) = +and pp_expr ppf Expr.Fixed.{pattern; meta} = match pattern with | Var s -> pf ppf "%s" s | Lit (Str, s) -> pf ppf "\"%s\"" (Cpp_str.escaped s) | Lit (Imaginary, s) -> pf ppf "stan::math::to_complex(0, %s)" s | Lit ((Real | Int), s) -> pf ppf "%s" s + | Promotion (expr, ut, ad) -> + if is_scalar expr && ut = UReal then pp_expr ppf expr + else + pf ppf "stan::math::promote_scalar<%a>(%a)" pp_unsizedtype_local + (ad, ut) pp_expr expr | FunApp ( StanLib (op, _, _) , [ { meta= {type_= URowVector; _} @@ -561,17 +559,12 @@ and pp_expr ppf Expr.Fixed.({pattern; meta} as e) = | EAnd (e1, e2) -> pp_logical_op ppf "&&" e1 e2 | EOr (e1, e2) -> pp_logical_op ppf "||" e1 e2 | TernaryIf (ec, et, ef) -> - let promoted ppf (t, e) = - pf ppf "stan::math::promote_scalar<%s>(%a)" - Expr.Typed.(local_scalar (type_of t) (adlevel_of t)) - pp_expr e in let tform ppf = pf ppf "(@[@,%a@ ?@ %a@ :@ %a@])" in let eval_pp ppf a = if UnsizedType.is_eigen_type meta.type_ then pf ppf "stan::math::eval(%a)" pp_expr a else pf ppf "%a" pp_expr a in - if types_match et ef then tform ppf pp_expr ec eval_pp et eval_pp ef - else tform ppf eval_pp ec promoted (e, et) promoted (e, ef) + tform ppf pp_expr ec eval_pp et eval_pp ef | Indexed (e, []) -> pp_expr ppf e | Indexed (e, idx) -> ( match e.pattern with diff --git a/test/integration/bad/algebra_solver/stanc.expected b/test/integration/bad/algebra_solver/stanc.expected index 818f7b7452..a74e781734 100644 --- a/test/integration/bad/algebra_solver/stanc.expected +++ b/test/integration/bad/algebra_solver/stanc.expected @@ -125,48 +125,6 @@ Available signatures: data real, data real) => vector where F2 = (vector, vector, data array[] real, data array[] int) => vector The 5th argument must be array[] int but got array[] real -(, vector, vector, data array[] real, data array[] int) => vector - Expected 5 arguments but found 8 arguments. - $ ../../../../../install/default/bin/stanc bad_newton_x_r_type.stan -Semantic error in 'bad_newton_x_r_type.stan', line 31, column 10 to column 69: - ------------------------------------------------- - 29: transformed parameters { - 30: vector[2] y_s_p; - 31: y_s_p = algebra_solver_newton(algebra_system, y, theta_p, x_r, x_i); - ^ - 32: } - 33: - ------------------------------------------------- - -Ill-typed arguments supplied to function 'algebra_solver_newton': -(, vector, vector, array[] int, array[] int) -where F1 = (vector, vector, array[] real, array[] int) => vector -Available signatures: -(, vector, vector, data array[] real, data array[] int) => vector -where F2 = (vector, vector, data array[] real, data array[] int) => vector - The fourth argument must be array[] real but got array[] int -(, vector, vector, data array[] real, data array[] int, data real, - data real, data real) => vector - Expected 8 arguments but found 5 arguments. - $ ../../../../../install/default/bin/stanc bad_newton_x_r_type_control.stan -Semantic error in 'bad_newton_x_r_type_control.stan', line 31, column 10 to column 85: - ------------------------------------------------- - 29: transformed parameters { - 30: vector[2] y_s_p; - 31: y_s_p = algebra_solver_newton(algebra_system, y, theta_p, x_r, x_i, 0.01, 0.01, 10); - ^ - 32: } - 33: - ------------------------------------------------- - -Ill-typed arguments supplied to function 'algebra_solver_newton': -(, vector, vector, array[] int, array[] int, real, real, int) -where F1 = (vector, vector, array[] real, array[] int) => vector -Available signatures: -(, vector, vector, data array[] real, data array[] int, data real, - data real, data real) => vector -where F2 = (vector, vector, data array[] real, data array[] int) => vector - The fourth argument must be array[] real but got array[] int (, vector, vector, data array[] real, data array[] int) => vector Expected 5 arguments but found 8 arguments. $ ../../../../../install/default/bin/stanc bad_newton_x_r_var_type.stan @@ -371,48 +329,6 @@ Available signatures: data real, data real) => vector where F2 = (vector, vector, data array[] real, data array[] int) => vector The 5th argument must be array[] int but got array[] real -(, vector, vector, data array[] real, data array[] int) => vector - Expected 5 arguments but found 8 arguments. - $ ../../../../../install/default/bin/stanc bad_x_r_type.stan -Semantic error in 'bad_x_r_type.stan', line 31, column 10 to column 62: - ------------------------------------------------- - 29: transformed parameters { - 30: vector[2] y_s_p; - 31: y_s_p = algebra_solver(algebra_system, y, theta_p, x_r, x_i); - ^ - 32: } - 33: - ------------------------------------------------- - -Ill-typed arguments supplied to function 'algebra_solver': -(, vector, vector, array[] int, array[] int) -where F1 = (vector, vector, array[] real, array[] int) => vector -Available signatures: -(, vector, vector, data array[] real, data array[] int) => vector -where F2 = (vector, vector, data array[] real, data array[] int) => vector - The fourth argument must be array[] real but got array[] int -(, vector, vector, data array[] real, data array[] int, data real, - data real, data real) => vector - Expected 8 arguments but found 5 arguments. - $ ../../../../../install/default/bin/stanc bad_x_r_type_control.stan -Semantic error in 'bad_x_r_type_control.stan', line 31, column 10 to column 78: - ------------------------------------------------- - 29: transformed parameters { - 30: vector[2] y_s_p; - 31: y_s_p = algebra_solver(algebra_system, y, theta_p, x_r, x_i, 0.01, 0.01, 10); - ^ - 32: } - 33: - ------------------------------------------------- - -Ill-typed arguments supplied to function 'algebra_solver': -(, vector, vector, array[] int, array[] int, real, real, int) -where F1 = (vector, vector, array[] real, array[] int) => vector -Available signatures: -(, vector, vector, data array[] real, data array[] int, data real, - data real, data real) => vector -where F2 = (vector, vector, data array[] real, data array[] int) => vector - The fourth argument must be array[] real but got array[] int (, vector, vector, data array[] real, data array[] int) => vector Expected 5 arguments but found 8 arguments. $ ../../../../../install/default/bin/stanc bad_x_r_var_type.stan diff --git a/test/integration/bad/lang/bad_promotion1.stan b/test/integration/bad/lang/bad_promotion1.stan new file mode 100644 index 0000000000..ec33f0758f --- /dev/null +++ b/test/integration/bad/lang/bad_promotion1.stan @@ -0,0 +1,10 @@ +functions { + void printer(array[] vector x){ + print(x); + } +} + +model { + array[3] int d = {1,2,3}; + printer(d); +} diff --git a/test/integration/bad/lang/bad_promotions2.stan b/test/integration/bad/lang/bad_promotions2.stan new file mode 100644 index 0000000000..fa6fb1a82e --- /dev/null +++ b/test/integration/bad/lang/bad_promotions2.stan @@ -0,0 +1,10 @@ +functions { + real nested(array[,] complex zs){ + return num_elements(zs); + } +} + +model { + array[3] int d = {1,2,3}; + print(nested(d)); +} diff --git a/test/integration/bad/lang/bad_promotions3.stan b/test/integration/bad/lang/bad_promotions3.stan new file mode 100644 index 0000000000..04ec73b416 --- /dev/null +++ b/test/integration/bad/lang/bad_promotions3.stan @@ -0,0 +1,10 @@ +functions { + void printer(array[] real x){ + print(x); + } +} + +model { + array[3] int d = {1,2,3}; + printer({d,d}); +} diff --git a/test/integration/bad/lang/bad_promotions4.stan b/test/integration/bad/lang/bad_promotions4.stan new file mode 100644 index 0000000000..13b8cacbdf --- /dev/null +++ b/test/integration/bad/lang/bad_promotions4.stan @@ -0,0 +1,10 @@ +functions { + void printer(array[] int x){ + print(x); + } +} + +model { + array[3] real d = {1,2.2,3}; + printer(d); +} diff --git a/test/integration/bad/lang/stanc.expected b/test/integration/bad/lang/stanc.expected index 29c4e05d1b..b89980184b 100644 --- a/test/integration/bad/lang/stanc.expected +++ b/test/integration/bad/lang/stanc.expected @@ -591,6 +591,66 @@ Syntax error in 'bad_periods_tparams.stan', line 2, column 7, lexing error: ------------------------------------------------- Invalid character found. + $ ../../../../../install/default/bin/stanc bad_promotion1.stan +Semantic error in 'bad_promotion1.stan', line 9, column 2 to column 13: + ------------------------------------------------- + 7: model { + 8: array[3] int d = {1,2,3}; + 9: printer(d); + ^ + 10: } + ------------------------------------------------- + +Ill-typed arguments supplied to function 'printer': +(array[] int) +Available signatures: +(array[] vector) => void + The first argument must be array[] vector but got array[] int + $ ../../../../../install/default/bin/stanc bad_promotions2.stan +Semantic error in 'bad_promotions2.stan', line 9, column 8 to column 17: + ------------------------------------------------- + 7: model { + 8: array[3] int d = {1,2,3}; + 9: print(nested(d)); + ^ + 10: } + ------------------------------------------------- + +Ill-typed arguments supplied to function 'nested': +(array[] int) +Available signatures: +(array[,] complex) => real + The first argument must be array[,] complex but got array[] int + $ ../../../../../install/default/bin/stanc bad_promotions3.stan +Semantic error in 'bad_promotions3.stan', line 9, column 2 to column 17: + ------------------------------------------------- + 7: model { + 8: array[3] int d = {1,2,3}; + 9: printer({d,d}); + ^ + 10: } + ------------------------------------------------- + +Ill-typed arguments supplied to function 'printer': +(array[,] int) +Available signatures: +(array[] real) => void + The first argument must be array[] real but got array[,] int + $ ../../../../../install/default/bin/stanc bad_promotions4.stan +Semantic error in 'bad_promotions4.stan', line 9, column 2 to column 13: + ------------------------------------------------- + 7: model { + 8: array[3] real d = {1,2.2,3}; + 9: printer(d); + ^ + 10: } + ------------------------------------------------- + +Ill-typed arguments supplied to function 'printer': +(array[] real) +Available signatures: +(array[] int) => void + The first argument must be array[] int but got array[] real $ ../../../../../install/default/bin/stanc good_all.stan Semantic error in 'good_all.stan', line 25, column 2 to column 8: ------------------------------------------------- diff --git a/test/integration/bad/stanc.expected b/test/integration/bad/stanc.expected index f36b8e593b..8dce127b30 100644 --- a/test/integration/bad/stanc.expected +++ b/test/integration/bad/stanc.expected @@ -1801,29 +1801,6 @@ Semantic error in 'prob-poisson_log-trunc-low.stan', line 11, column 2 to column ------------------------------------------------- Truncation is only defined if distribution has _lcdf and _lccdf functions implemented with appropriate signature. - $ ../../../../install/default/bin/stanc propto-bad1.stan -Semantic error in 'propto-bad1.stan', line 2, column 14 to column 37: - ------------------------------------------------- - 1: model { - 2: target += normal_lupdf(1| {0}, 1); - ^ - 3: } - ------------------------------------------------- - -Ill-typed arguments supplied to function 'normal_lupdf': -(int, array[] int, int) -Available signatures: -(real, real, real) => real - The second argument must be real but got array[] int -(real, real, array[] real) => real - The second argument must be real but got array[] int -(real, real, vector) => real - The second argument must be real but got array[] int -(real, real, row_vector) => real - The second argument must be real but got array[] int -(real, vector, real) => real - The second argument must be vector but got array[] int -(Additional signatures omitted) $ ../../../../install/default/bin/stanc real-pdf.stan Semantic error in 'real-pdf.stan', line 2, column 2 to line 4, column 3: ------------------------------------------------- diff --git a/test/integration/good/code-gen/complex_scalar.stan b/test/integration/good/code-gen/complex_scalar.stan index 763c6520ef..beb1c40aa0 100644 --- a/test/integration/good/code-gen/complex_scalar.stan +++ b/test/integration/good/code-gen/complex_scalar.stan @@ -47,7 +47,7 @@ transformed data { complex td_complex; array[2] complex td_complex_array; array[2, 3] complex td_complex_array_2d; - + td_complex = td_i; td_complex = td_r; td_complex = d_i; @@ -63,11 +63,11 @@ transformed data { td_complex = to_complex(1.1, 2); td_complex = to_complex(1, 2.2); td_complex = to_complex(1.1, 2.2); - + td_complex_array = d_complex_array; td_complex_array = {td_complex, 1, to_complex(2, 3)}; td_complex_array[1] = to_complex(5.1, 6); - + td_complex_array_2d = d_complex_array_2d; td_complex_array_2d = {{1, td_complex, 3}, {to_complex(), to_complex(1.1), to_complex(1, 2.1)}}; @@ -75,26 +75,26 @@ transformed data { td_complex_array_2d[1, 1] = 1; td_complex_array_2d[1] = td_complex_array; td_complex_array_2d[1] = {td_complex, to_complex(1, 2), 2.4}; - + for (td_j in 1 : 2) { for (td_k in 1 : 3) { td_complex_array_2d[td_j, td_k] = to_complex(1, 2.2); } } - + for (td_j in td_complex_array_2d) { for (td_k in td_j) { td_complex = td_k; } } - + td_r = get_real(td_complex); td_r = get_imag(td_complex); td_r = get_real(td_complex_array[1]); td_r = get_imag(td_complex_array[1]); td_r = get_real(td_complex_array_2d[1, 1]); td_r = get_imag(td_complex_array_2d[1, 1]); - + td_complex = foo(); td_r = foo1(td_complex); td_complex = foo2(td_r); @@ -118,7 +118,7 @@ transformed parameters { complex tp_complex; array[2] complex tp_complex_array; array[2, 3] complex tp_complex_array_2d; - + tp_complex = tp_r; tp_complex = d_i; tp_complex = d_r; @@ -136,12 +136,12 @@ transformed parameters { tp_complex = to_complex(1.1, 2); tp_complex = to_complex(1, 2.2); tp_complex = to_complex(1.1, 2.2); - + tp_complex_array = d_complex_array; tp_complex_array = p_complex_array; tp_complex_array = {tp_complex, 1, to_complex(2, 3)}; tp_complex_array[1] = to_complex(5.1, 6); - + tp_complex_array_2d = d_complex_array_2d; tp_complex_array_2d = p_complex_array_2d; tp_complex_array_2d = {{1, tp_complex, 3}, @@ -150,26 +150,26 @@ transformed parameters { tp_complex_array_2d[1, 1] = 1; tp_complex_array_2d[1] = tp_complex_array; tp_complex_array_2d[1] = {tp_complex, to_complex(1, 2), 2.4}; - + for (tp_j in 1 : 2) { for (tp_k in 1 : 3) { tp_complex_array_2d[tp_j, tp_k] = to_complex(1, 2.2); } } - + for (tp_j in tp_complex_array_2d) { for (tp_k in tp_j) { tp_complex = tp_k; } } - + tp_r = get_real(tp_complex); tp_r = get_imag(tp_complex); tp_r = get_real(tp_complex_array[1]); tp_r = get_imag(tp_complex_array[1]); tp_r = get_real(tp_complex_array_2d[1, 1]); tp_r = get_imag(tp_complex_array_2d[1, 1]); - + tp_complex = foo(); tp_r = foo1(tp_complex); tp_complex = foo2(tp_r); @@ -186,7 +186,7 @@ model { complex m_complex; array[2] complex m_complex_array; array[2, 3] complex m_complex_array_2d; - + abs(p_complex) ~ normal(0, 1); } generated quantities { @@ -195,7 +195,7 @@ generated quantities { complex gq_complex; array[2] complex gq_complex_array; array[2, 3] complex gq_complex_array_2d; - + gq_complex = gq_i; gq_complex = gq_r; gq_complex = d_i; @@ -214,12 +214,12 @@ generated quantities { gq_complex = to_complex(1.1, 2); gq_complex = to_complex(1, 2.2); gq_complex = to_complex(1.1, 2.2); - + gq_complex_array = d_complex_array; gq_complex_array = p_complex_array; gq_complex_array = {gq_complex, 1, to_complex(2, 3)}; gq_complex_array[1] = to_complex(5.1, 6); - + gq_complex_array_2d = d_complex_array_2d; gq_complex_array_2d = p_complex_array_2d; gq_complex_array_2d = {{1, gq_complex, 3}, @@ -228,26 +228,26 @@ generated quantities { gq_complex_array_2d[1, 1] = 1; gq_complex_array_2d[1] = gq_complex_array; gq_complex_array_2d[1] = {gq_complex, to_complex(1, 2), 2.4}; - + for (gq_j in 1 : 2) { for (gq_k in 1 : 3) { gq_complex_array_2d[gq_j, gq_k] = to_complex(1, 2.2); } } - + for (gq_j in gq_complex_array_2d) { for (gq_k in gq_j) { gq_complex = gq_k; } } - + gq_r = get_real(gq_complex); gq_r = get_imag(gq_complex); gq_r = get_real(gq_complex_array[1]); gq_r = get_imag(gq_complex_array[1]); gq_r = get_real(gq_complex_array_2d[1, 1]); gq_r = get_imag(gq_complex_array_2d[1, 1]); - + gq_complex = foo(); gq_r = foo1(gq_complex); gq_complex = foo2(gq_r); @@ -259,12 +259,12 @@ generated quantities { gq_r = foo8(gq_complex_array_2d); gq_complex_array_2d = foo9(gq_r); gq_complex_array_2d = foo10(gq_complex_array_2d); - + complex z = to_complex(1, 2); complex y = to_complex(3, 4); array[0] int i_arr; array[1] int i_arr_1; - + gq_complex = z + y; gq_complex = z + gq_r; gq_complex = gq_r + z; @@ -277,7 +277,7 @@ generated quantities { gq_complex = p_complex + p_r; gq_complex = d_complex + gq_i; gq_complex = gq_i + p_complex; - + gq_complex = z - y; gq_complex = z - gq_r; gq_complex = gq_r - z; @@ -290,7 +290,7 @@ generated quantities { gq_complex = p_complex - p_r; gq_complex = d_complex - gq_i; gq_complex = gq_i - p_complex; - + gq_complex = z * y; gq_complex = z * gq_r; gq_complex = gq_r * z; @@ -303,7 +303,7 @@ generated quantities { gq_complex = p_complex * p_r; gq_complex = d_complex * gq_i; gq_complex = gq_i * p_complex; - + gq_complex = z / y; gq_complex = z / gq_r; gq_complex = gq_r / z; @@ -316,7 +316,7 @@ generated quantities { gq_complex = p_complex / p_r; gq_complex = d_complex / gq_i; gq_complex = gq_i / p_complex; - + gq_complex = z ^ y; gq_complex = z ^ gq_r; gq_complex = gq_r ^ z; @@ -329,7 +329,7 @@ generated quantities { gq_complex = p_complex ^ p_r; gq_complex = d_complex ^ gq_i; gq_complex = gq_i ^ p_complex; - + gq_complex = -z; gq_complex = -gq_r; gq_complex = -gq_i; @@ -337,11 +337,11 @@ generated quantities { gq_complex = -d_r; gq_complex = -p_complex; gq_complex = -p_r; - + gq_complex = gq_i ? z : y; gq_complex = gq_i ? p_complex : z; gq_complex = gq_i ? d_complex : z; - + gq_i = (z == z); gq_i = (z == gq_r); gq_i = (z == gq_i); @@ -352,7 +352,7 @@ generated quantities { gq_i = (d_complex == d_r); gq_i = (p_r == d_complex); gq_i = (p_complex == d_r); - + gq_i = (z != z); gq_i = (z != gq_r); gq_i = (z != gq_i); @@ -363,86 +363,86 @@ generated quantities { gq_i = (d_complex != d_r); gq_i = (p_r != d_complex); gq_i = (p_complex != d_r); - + gq_r = abs(z); gq_r = abs(p_complex); gq_r = abs(d_complex); - + gq_complex = acos(z); gq_complex = acos(p_complex); gq_complex = acos(d_complex); - + gq_complex = acosh(z); gq_complex = acosh(p_complex); gq_complex = acosh(d_complex); - + gq_complex = asin(z); gq_complex = asin(p_complex); gq_complex = asin(d_complex); - + gq_complex = asinh(z); gq_complex = asinh(p_complex); gq_complex = asinh(d_complex); - + gq_complex = atan(z); gq_complex = atan(p_complex); gq_complex = atan(d_complex); - + gq_complex = atanh(z); gq_complex = atanh(p_complex); gq_complex = atanh(d_complex); - + gq_complex = conj(z); gq_complex = conj(p_complex); gq_complex = conj(d_complex); - + gq_complex = cos(z); gq_complex = cos(p_complex); gq_complex = cos(d_complex); - + gq_complex = cosh(z); gq_complex = cosh(p_complex); gq_complex = cosh(d_complex); - + i_arr = dims(z); i_arr = dims(p_complex); i_arr = dims(d_complex); i_arr_1 = dims(gq_complex_array); i_arr_1 = dims(p_complex_array); i_arr_1 = dims(d_complex_array); - + gq_complex = exp(z); gq_complex = exp(p_complex); gq_complex = exp(d_complex); - + gq_r = get_imag(z); gq_r = get_imag(p_complex); gq_r = get_imag(d_complex); - + gq_r = get_real(z); gq_r = get_real(p_complex); gq_r = get_real(d_complex); - + gq_complex_array = head(gq_complex_array, 1); gq_complex_array = head(p_complex_array, 1); gq_complex_array = head(d_complex_array, 1); - + gq_complex = log(z); gq_complex = log(p_complex); gq_complex = log(d_complex); - + gq_complex = log10(z); gq_complex = log10(p_complex); gq_complex = log10(d_complex); - + gq_r = norm(z); gq_r = norm(p_complex); gq_r = norm(d_complex); - + gq_i = num_elements(gq_complex_array); gq_i = num_elements(p_complex_array); gq_i = num_elements(d_complex_array); - + gq_complex = polar(gq_r, gq_r); gq_complex = polar(gq_i, gq_i); gq_complex = polar(gq_r, gq_i); @@ -450,7 +450,7 @@ generated quantities { gq_complex = polar(p_r, gq_r); gq_complex = polar(d_r, gq_r); gq_complex = polar(p_r, d_r); - + gq_complex = pow(z, gq_r); gq_complex = pow(z, gq_i); gq_complex = pow(z, z); @@ -466,43 +466,43 @@ generated quantities { gq_complex = pow(d_complex, z); gq_complex = pow(d_complex, d_complex); gq_complex = pow(d_complex, p_complex); - + gq_complex = proj(z); gq_complex = proj(p_complex); gq_complex = proj(d_complex); - + gq_complex_array = reverse(gq_complex_array); gq_complex_array = reverse(p_complex_array); gq_complex_array = reverse(d_complex_array); - + gq_complex = sin(z); gq_complex = sin(p_complex); gq_complex = sin(d_complex); - + gq_complex = sinh(z); gq_complex = sinh(p_complex); gq_complex = sinh(d_complex); - + gq_i = size(gq_complex_array); gq_i = size(p_complex_array); gq_i = size(d_complex_array); - + gq_complex = sqrt(z); gq_complex = sqrt(p_complex); gq_complex = sqrt(d_complex); - + gq_complex_array = tail(gq_complex_array, 1); gq_complex_array = tail(p_complex_array, 1); gq_complex_array = tail(d_complex_array, 1); - + gq_complex = tan(z); gq_complex = tan(p_complex); gq_complex = tan(d_complex); - + gq_complex = tanh(z); gq_complex = tanh(p_complex); gq_complex = tanh(d_complex); - + gq_complex = to_complex(); gq_complex = to_complex(gq_r, gq_r); gq_complex = to_complex(gq_i, gq_i); @@ -515,11 +515,10 @@ generated quantities { gq_complex = to_complex(d_r, gq_r); gq_complex = to_complex(p_r); gq_complex = to_complex(d_r); - + // test imaginary literal complex zi = 1 + 3.14i; zi = zi * 0i; complex yi = to_complex(0, 1.1) + to_complex(0.0, 2.2) + to_complex(); real x = get_real(3i - 40e-3i); } - diff --git a/test/integration/good/code-gen/conditional_expression_types.stan b/test/integration/good/code-gen/conditional_expression_types.stan deleted file mode 100644 index be754f46ac..0000000000 --- a/test/integration/good/code-gen/conditional_expression_types.stan +++ /dev/null @@ -1,7 +0,0 @@ -parameters { - vector[2] a; - vector[2] b; -} -transformed parameters { - vector[2] c = sum(a) > 1 ? 2*a+b : 2*a; -} diff --git a/test/integration/good/code-gen/cpp.expected b/test/integration/good/code-gen/cpp.expected index 76bdf9d656..8c9b9706af 100644 --- a/test/integration/good/code-gen/cpp.expected +++ b/test/integration/good/code-gen/cpp.expected @@ -3631,499 +3631,397 @@ stan::math::profile_map& get_stan_profile_data() { - $ ../../../../../install/default/bin/stanc --print-cpp conditional_expression_types.stan + $ ../../../../../install/default/bin/stanc --print-cpp cpp-reserved-words.stan // Code generated by %%NAME%% %%VERSION%% #include -namespace conditional_expression_types_model_namespace { +namespace cpp_reserved_words_model_namespace { using stan::model::model_base_crtp; using namespace stan::math; stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = +static constexpr std::array locations_array__ = {" (found before start of program)", - " (in 'conditional_expression_types.stan', line 2, column 2 to column 14)", - " (in 'conditional_expression_types.stan', line 3, column 2 to column 14)", - " (in 'conditional_expression_types.stan', line 6, column 2 to column 41)"}; + " (in 'cpp-reserved-words.stan', line 33, column 2 to column 16)", + " (in 'cpp-reserved-words.stan', line 34, column 2 to column 13)", + " (in 'cpp-reserved-words.stan', line 35, column 2 to column 14)", + " (in 'cpp-reserved-words.stan', line 36, column 2 to column 12)", + " (in 'cpp-reserved-words.stan', line 37, column 2 to column 14)", + " (in 'cpp-reserved-words.stan', line 38, column 2 to column 12)", + " (in 'cpp-reserved-words.stan', line 39, column 2 to column 15)", + " (in 'cpp-reserved-words.stan', line 40, column 2 to column 17)", + " (in 'cpp-reserved-words.stan', line 41, column 2 to column 11)", + " (in 'cpp-reserved-words.stan', line 42, column 2 to column 16)", + " (in 'cpp-reserved-words.stan', line 43, column 2 to column 11)", + " (in 'cpp-reserved-words.stan', line 44, column 2 to column 14)", + " (in 'cpp-reserved-words.stan', line 45, column 2 to column 15)", + " (in 'cpp-reserved-words.stan', line 46, column 2 to column 16)", + " (in 'cpp-reserved-words.stan', line 47, column 2 to column 10)", + " (in 'cpp-reserved-words.stan', line 69, column 2 to column 13)", + " (in 'cpp-reserved-words.stan', line 70, column 2 to column 11)", + " (in 'cpp-reserved-words.stan', line 71, column 2 to column 14)", + " (in 'cpp-reserved-words.stan', line 72, column 2 to column 16)", + " (in 'cpp-reserved-words.stan', line 73, column 2 to column 13)", + " (in 'cpp-reserved-words.stan', line 74, column 2 to column 16)", + " (in 'cpp-reserved-words.stan', line 75, column 2 to column 13)", + " (in 'cpp-reserved-words.stan', line 76, column 2 to column 15)", + " (in 'cpp-reserved-words.stan', line 77, column 2 to column 16)", + " (in 'cpp-reserved-words.stan', line 78, column 2 to column 15)", + " (in 'cpp-reserved-words.stan', line 79, column 2 to column 11)", + " (in 'cpp-reserved-words.stan', line 80, column 2 to column 14)", + " (in 'cpp-reserved-words.stan', line 81, column 2 to column 12)", + " (in 'cpp-reserved-words.stan', line 82, column 2 to column 18)", + " (in 'cpp-reserved-words.stan', line 83, column 2 to column 18)", + " (in 'cpp-reserved-words.stan', line 84, column 2 to column 18)", + " (in 'cpp-reserved-words.stan', line 85, column 2 to column 23)", + " (in 'cpp-reserved-words.stan', line 86, column 2 to column 23)", + " (in 'cpp-reserved-words.stan', line 87, column 2 to column 23)", + " (in 'cpp-reserved-words.stan', line 51, column 2 to column 13)", + " (in 'cpp-reserved-words.stan', line 52, column 2 to column 15)", + " (in 'cpp-reserved-words.stan', line 53, column 2 to column 17)", + " (in 'cpp-reserved-words.stan', line 54, column 2 to column 14)", + " (in 'cpp-reserved-words.stan', line 55, column 2 to column 16)", + " (in 'cpp-reserved-words.stan', line 56, column 2 to column 24)", + " (in 'cpp-reserved-words.stan', line 57, column 2 to column 13)", + " (in 'cpp-reserved-words.stan', line 58, column 2 to column 14)", + " (in 'cpp-reserved-words.stan', line 59, column 2 to column 14)", + " (in 'cpp-reserved-words.stan', line 60, column 2 to column 21)", + " (in 'cpp-reserved-words.stan', line 61, column 2 to column 19)", + " (in 'cpp-reserved-words.stan', line 62, column 2 to column 14)", + " (in 'cpp-reserved-words.stan', line 63, column 2 to column 16)", + " (in 'cpp-reserved-words.stan', line 64, column 2 to column 12)", + " (in 'cpp-reserved-words.stan', line 65, column 2 to column 20)", + " (in 'cpp-reserved-words.stan', line 18, column 2 to column 13)", + " (in 'cpp-reserved-words.stan', line 19, column 2 to column 13)", + " (in 'cpp-reserved-words.stan', line 20, column 2 to column 13)", + " (in 'cpp-reserved-words.stan', line 21, column 2 to column 17)", + " (in 'cpp-reserved-words.stan', line 22, column 2 to column 18)", + " (in 'cpp-reserved-words.stan', line 23, column 2 to column 16)", + " (in 'cpp-reserved-words.stan', line 24, column 2 to column 15)", + " (in 'cpp-reserved-words.stan', line 25, column 2 to column 14)", + " (in 'cpp-reserved-words.stan', line 26, column 2 to column 10)", + " (in 'cpp-reserved-words.stan', line 27, column 2 to column 14)", + " (in 'cpp-reserved-words.stan', line 28, column 2 to column 20)", + " (in 'cpp-reserved-words.stan', line 29, column 2 to column 12)", + " (in 'cpp-reserved-words.stan', line 2, column 23 to column 25)", + " (in 'cpp-reserved-words.stan', line 3, column 24 to column 26)", + " (in 'cpp-reserved-words.stan', line 4, column 26 to column 28)", + " (in 'cpp-reserved-words.stan', line 5, column 30 to column 32)", + " (in 'cpp-reserved-words.stan', line 6, column 24 to column 26)", + " (in 'cpp-reserved-words.stan', line 7, column 28 to column 30)", + " (in 'cpp-reserved-words.stan', line 8, column 14 to column 16)", + " (in 'cpp-reserved-words.stan', line 9, column 13 to column 15)", + " (in 'cpp-reserved-words.stan', line 10, column 13 to column 15)", + " (in 'cpp-reserved-words.stan', line 11, column 14 to column 16)", + " (in 'cpp-reserved-words.stan', line 12, column 13 to column 15)", + " (in 'cpp-reserved-words.stan', line 13, column 17 to column 19)", + " (in 'cpp-reserved-words.stan', line 14, column 17 to column 19)"}; +void +_stan_alignas(const int& _stan_asm, std::ostream* pstream__) { + using local_scalar_t__ = double; + int current_statement__ = 0; + static constexpr bool propto__ = true; + (void) propto__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + (void) DUMMY_VAR__; // suppress unused var warning + try { + + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + +} -class conditional_expression_types_model final : public model_base_crtp { +struct _stan_alignas_functor__ { +void +operator()(const int& _stan_asm, std::ostream* pstream__) const +{ +return _stan_alignas(_stan_asm, pstream__); +} +}; - private: - - - - public: - ~conditional_expression_types_model() { } +void +_stan_alignof(const int& _stan_char, std::ostream* pstream__) { + using local_scalar_t__ = double; + int current_statement__ = 0; + static constexpr bool propto__ = true; + (void) propto__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + (void) DUMMY_VAR__; // suppress unused var warning + try { + + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } - inline std::string model_name() const final { return "conditional_expression_types_model"; } +} - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = %%NAME%%3 %%VERSION%%", "stancflags = --print-cpp"}; +struct _stan_alignof_functor__ { +void +operator()(const int& _stan_char, std::ostream* pstream__) const +{ +return _stan_alignof(_stan_char, pstream__); +} +}; + +void +_stan_and(const int& _stan_STAN_MAJOR, std::ostream* pstream__) { + using local_scalar_t__ = double; + int current_statement__ = 0; + static constexpr bool propto__ = true; + (void) propto__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + (void) DUMMY_VAR__; // suppress unused var warning + try { + + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); } - - conditional_expression_types_model(stan::io::var_context& context__, - unsigned int random_seed__ = 0, - std::ostream* pstream__ = nullptr) : model_base_crtp(0) { - int current_statement__ = 0; - using local_scalar_t__ = double ; - boost::ecuyer1988 base_rng__ = - stan::services::util::create_rng(random_seed__, 0); - (void) base_rng__; // suppress unused var warning - static constexpr const char* function__ = "conditional_expression_types_model_namespace::conditional_expression_types_model"; - (void) function__; // suppress unused var warning - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - num_params_r__ = 2 + 2; +} + +struct _stan_and_functor__ { +void +operator()(const int& _stan_STAN_MAJOR, std::ostream* pstream__) const +{ +return _stan_and(_stan_STAN_MAJOR, pstream__); +} +}; + +template +void +_stan_and_eq(const T0__& _stan_STAN_MINOR, std::ostream* pstream__) { + using local_scalar_t__ = stan::promote_args_t; + int current_statement__ = 0; + static constexpr bool propto__ = true; + (void) propto__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + (void) DUMMY_VAR__; // suppress unused var warning + try { + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t log_prob_impl(VecR& params_r__, - VecI& params_i__, - std::ostream* pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - static constexpr const char* function__ = "conditional_expression_types_model_namespace::log_prob"; - (void) function__; // suppress unused var warning +} + +struct _stan_and_eq_functor__ { +template +void +operator()(const T0__& _stan_STAN_MINOR, std::ostream* pstream__) const +{ +return _stan_and_eq(_stan_STAN_MINOR, pstream__); +} +}; + +template +void +_stan_asm(const T0__& _stan_class_arg__, std::ostream* pstream__) { + using local_scalar_t__ = stan::promote_args_t>; + int current_statement__ = 0; + const auto& _stan_class = stan::math::to_ref(_stan_class_arg__); + static constexpr bool propto__ = true; + (void) propto__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + (void) DUMMY_VAR__; // suppress unused var warning + try { - try { - Eigen::Matrix a = - Eigen::Matrix::Constant(2, DUMMY_VAR__); - current_statement__ = 1; - a = in__.template read>(2); - Eigen::Matrix b = - Eigen::Matrix::Constant(2, DUMMY_VAR__); - current_statement__ = 2; - b = in__.template read>(2); - Eigen::Matrix c = - Eigen::Matrix::Constant(2, DUMMY_VAR__); - current_statement__ = 3; - stan::model::assign(c, - (stan::math::logical_gt(stan::math::sum(a), 1) ? - stan::math::eval(stan::math::add(stan::math::multiply(2, a), b)) : - stan::math::eval(stan::math::multiply(2, a))), - "assigning variable c"); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } // log_prob_impl() + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + +} + +struct _stan_asm_functor__ { +template +void +operator()(const T0__& _stan_class, std::ostream* pstream__) const +{ +return _stan_asm(_stan_class, pstream__); +} +}; + +void +_stan_bitand(const int& _stan_constexpr, std::ostream* pstream__) { + using local_scalar_t__ = double; + int current_statement__ = 0; + static constexpr bool propto__ = true; + (void) propto__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + (void) DUMMY_VAR__; // suppress unused var warning + try { - template * = nullptr, - stan::require_vector_like_vt* = nullptr, - stan::require_std_vector_vt* = nullptr> - inline void write_array_impl(RNG& base_rng__, VecR& params_r__, - VecI& params_i__, VecVar& vars__, - const bool emit_transformed_parameters__ = true, - const bool emit_generated_quantities__ = true, - std::ostream* pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - static constexpr bool propto__ = true; - (void) propto__; - double lp__ = 0.0; - (void) lp__; // dummy to suppress unused var warning - int current_statement__ = 0; - stan::math::accumulator lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - constexpr bool jacobian__ = false; - (void) DUMMY_VAR__; // suppress unused var warning - static constexpr const char* function__ = "conditional_expression_types_model_namespace::write_array"; - (void) function__; // suppress unused var warning - - try { - Eigen::Matrix a = - Eigen::Matrix::Constant(2, - std::numeric_limits::quiet_NaN()); - current_statement__ = 1; - a = in__.template read>(2); - Eigen::Matrix b = - Eigen::Matrix::Constant(2, - std::numeric_limits::quiet_NaN()); - current_statement__ = 2; - b = in__.template read>(2); - Eigen::Matrix c = - Eigen::Matrix::Constant(2, - std::numeric_limits::quiet_NaN()); - out__.write(a); - out__.write(b); - if (stan::math::logical_negation((stan::math::primitive_value( - emit_transformed_parameters__) || stan::math::primitive_value( - emit_generated_quantities__)))) { - return ; - } - current_statement__ = 3; - stan::model::assign(c, - (stan::math::logical_gt(stan::math::sum(a), 1) ? - stan::math::eval(stan::math::add(stan::math::multiply(2, a), b)) : - stan::math::eval(stan::math::multiply(2, a))), - "assigning variable c"); - if (emit_transformed_parameters__) { - out__.write(c); - } - if (stan::math::logical_negation(emit_generated_quantities__)) { - return ; - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } // write_array_impl() - - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline void transform_inits_impl(VecVar& params_r__, VecI& params_i__, - VecVar& vars__, - std::ostream* pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - Eigen::Matrix a = - Eigen::Matrix::Constant(2, DUMMY_VAR__); - for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { - stan::model::assign(a, in__.read(), - "assigning variable a", stan::model::index_uni(sym1__)); - } - out__.write(a); - Eigen::Matrix b = - Eigen::Matrix::Constant(2, DUMMY_VAR__); - for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { - stan::model::assign(b, in__.read(), - "assigning variable b", stan::model::index_uni(sym1__)); - } - out__.write(b); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } // transform_inits_impl() - - inline void get_param_names(std::vector& names__) const { + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + +} + +struct _stan_bitand_functor__ { +void +operator()(const int& _stan_constexpr, std::ostream* pstream__) const +{ +return _stan_bitand(_stan_constexpr, pstream__); +} +}; + +void +_stan_bitor(std::ostream* pstream__) { + using local_scalar_t__ = double; + int current_statement__ = 0; + static constexpr bool propto__ = true; + (void) propto__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + (void) DUMMY_VAR__; // suppress unused var warning + try { - names__ = std::vector{"a", "b", "c"}; + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + +} + +struct _stan_bitor_functor__ { +void +operator()(std::ostream* pstream__) const +{ +return _stan_bitor(pstream__); +} +}; + +void +_stan_bool(std::ostream* pstream__) { + using local_scalar_t__ = double; + int current_statement__ = 0; + static constexpr bool propto__ = true; + (void) propto__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + (void) DUMMY_VAR__; // suppress unused var warning + try { - } // get_param_names() + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + +} + +struct _stan_bool_functor__ { +void +operator()(std::ostream* pstream__) const +{ +return _stan_bool(pstream__); +} +}; + +void +_stan_case(std::ostream* pstream__) { + using local_scalar_t__ = double; + int current_statement__ = 0; + static constexpr bool propto__ = true; + (void) propto__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + (void) DUMMY_VAR__; // suppress unused var warning + try { - inline void get_dims(std::vector>& dimss__) const { + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + +} + +struct _stan_case_functor__ { +void +operator()(std::ostream* pstream__) const +{ +return _stan_case(pstream__); +} +}; + +void +_stan_catch(std::ostream* pstream__) { + using local_scalar_t__ = double; + int current_statement__ = 0; + static constexpr bool propto__ = true; + (void) propto__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + (void) DUMMY_VAR__; // suppress unused var warning + try { - dimss__ = std::vector>{std::vector{ - static_cast(2) - }, - std::vector{static_cast(2)}, - std::vector{static_cast(2)}}; + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + +} + +struct _stan_catch_functor__ { +void +operator()(std::ostream* pstream__) const +{ +return _stan_catch(pstream__); +} +}; + +void +_stan_char(std::ostream* pstream__) { + using local_scalar_t__ = double; + int current_statement__ = 0; + static constexpr bool propto__ = true; + (void) propto__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + (void) DUMMY_VAR__; // suppress unused var warning + try { - } // get_dims() + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + +} + +struct _stan_char_functor__ { +void +operator()(std::ostream* pstream__) const +{ +return _stan_char(pstream__); +} +}; + +void +_stan_char16_t(std::ostream* pstream__) { + using local_scalar_t__ = double; + int current_statement__ = 0; + static constexpr bool propto__ = true; + (void) propto__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + (void) DUMMY_VAR__; // suppress unused var warning + try { - inline void constrained_param_names( - std::vector& param_names__, - bool emit_transformed_parameters__ = true, - bool emit_generated_quantities__ = true) const - final { - - for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { - { - param_names__.emplace_back(std::string() + "a" + '.' + std::to_string(sym1__)); - } - } - for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { - { - param_names__.emplace_back(std::string() + "b" + '.' + std::to_string(sym1__)); - } - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { - { - param_names__.emplace_back(std::string() + "c" + '.' + std::to_string(sym1__)); - } - } - } - - if (emit_generated_quantities__) { - - } - - } // constrained_param_names() - - inline void unconstrained_param_names( - std::vector& param_names__, - bool emit_transformed_parameters__ = true, - bool emit_generated_quantities__ = true) const - final { - - for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { - { - param_names__.emplace_back(std::string() + "a" + '.' + std::to_string(sym1__)); - } - } - for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { - { - param_names__.emplace_back(std::string() + "b" + '.' + std::to_string(sym1__)); - } - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { - { - param_names__.emplace_back(std::string() + "c" + '.' + std::to_string(sym1__)); - } - } - } - - if (emit_generated_quantities__) { - - } - - } // unconstrained_param_names() - - inline std::string get_constrained_sizedtypes() const { - - return std::string("[{\"name\":\"a\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(2) + "},\"block\":\"parameters\"},{\"name\":\"b\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(2) + "},\"block\":\"parameters\"},{\"name\":\"c\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(2) + "},\"block\":\"transformed_parameters\"}]"); - - } // get_constrained_sizedtypes() - - inline std::string get_unconstrained_sizedtypes() const { - - return std::string("[{\"name\":\"a\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(2) + "},\"block\":\"parameters\"},{\"name\":\"b\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(2) + "},\"block\":\"parameters\"},{\"name\":\"c\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(2) + "},\"block\":\"transformed_parameters\"}]"); - - } // get_unconstrained_sizedtypes() - - - // Begin method overload boilerplate - template - inline void write_array(RNG& base_rng, - Eigen::Matrix& params_r, - Eigen::Matrix& vars, - const bool emit_transformed_parameters = true, - const bool emit_generated_quantities = true, - std::ostream* pstream = nullptr) const { - const size_t num_params__ = - (2 + 2); - const size_t num_transformed = 2; - const size_t num_gen_quantities = 0; - std::vector vars_vec(num_params__ - + (emit_transformed_parameters * num_transformed) - + (emit_generated_quantities * num_gen_quantities)); - std::vector params_i; - write_array_impl(base_rng, params_r, params_i, vars_vec, - emit_transformed_parameters, emit_generated_quantities, pstream); - vars = Eigen::Map>( - vars_vec.data(), vars_vec.size()); - } - - template - inline void write_array(RNG& base_rng, std::vector& params_r, - std::vector& params_i, - std::vector& vars, - bool emit_transformed_parameters = true, - bool emit_generated_quantities = true, - std::ostream* pstream = nullptr) const { - const size_t num_params__ = - (2 + 2); - const size_t num_transformed = 2; - const size_t num_gen_quantities = 0; - vars.resize(num_params__ - + (emit_transformed_parameters * num_transformed) - + (emit_generated_quantities * num_gen_quantities)); - write_array_impl(base_rng, params_r, params_i, vars, emit_transformed_parameters, emit_generated_quantities, pstream); - } - - template - inline T_ log_prob(Eigen::Matrix& params_r, - std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - - template - inline T__ log_prob(std::vector& params_r, - std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - - - inline void transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, - std::ostream* pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits(context, params_i, params_r_vec, pstream); - params_r = Eigen::Map>( - params_r_vec.data(), params_r_vec.size()); - } - - inline void transform_inits(const stan::io::var_context& context, - std::vector& params_i, - std::vector& vars, - std::ostream* pstream__ = nullptr) const { - constexpr std::array names__{"a", "b"}; - const std::array constrain_param_sizes__{2, 2}; - const auto num_constrained_params__ = std::accumulate( - constrain_param_sizes__.begin(), constrain_param_sizes__.end(), 0); - - std::vector params_r_flat__(num_constrained_params__); - Eigen::Index size_iter__ = 0; - Eigen::Index flat_iter__ = 0; - for (auto&& param_name__ : names__) { - const auto param_vec__ = context.vals_r(param_name__); - for (Eigen::Index i = 0; i < constrain_param_sizes__[size_iter__]; ++i) { - params_r_flat__[flat_iter__] = param_vec__[i]; - ++flat_iter__; - } - ++size_iter__; - } - vars.resize(num_params_r__); - transform_inits_impl(params_r_flat__, params_i, vars, pstream__); - } // transform_inits() - -}; -} - -using stan_model = conditional_expression_types_model_namespace::conditional_expression_types_model; - -#ifndef USING_R - -// Boilerplate -stan::model::model_base& new_model( - stan::io::var_context& data_context, - unsigned int seed, - std::ostream* msg_stream) { - stan_model* m = new stan_model(data_context, seed, msg_stream); - return *m; -} - -stan::math::profile_map& get_stan_profile_data() { - return conditional_expression_types_model_namespace::profiles__; -} - -#endif - - - - $ ../../../../../install/default/bin/stanc --print-cpp cpp-reserved-words.stan - -// Code generated by %%NAME%% %%VERSION%% -#include -namespace cpp_reserved_words_model_namespace { - -using stan::model::model_base_crtp; -using namespace stan::math; - - -stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = -{" (found before start of program)", - " (in 'cpp-reserved-words.stan', line 33, column 2 to column 16)", - " (in 'cpp-reserved-words.stan', line 34, column 2 to column 13)", - " (in 'cpp-reserved-words.stan', line 35, column 2 to column 14)", - " (in 'cpp-reserved-words.stan', line 36, column 2 to column 12)", - " (in 'cpp-reserved-words.stan', line 37, column 2 to column 14)", - " (in 'cpp-reserved-words.stan', line 38, column 2 to column 12)", - " (in 'cpp-reserved-words.stan', line 39, column 2 to column 15)", - " (in 'cpp-reserved-words.stan', line 40, column 2 to column 17)", - " (in 'cpp-reserved-words.stan', line 41, column 2 to column 11)", - " (in 'cpp-reserved-words.stan', line 42, column 2 to column 16)", - " (in 'cpp-reserved-words.stan', line 43, column 2 to column 11)", - " (in 'cpp-reserved-words.stan', line 44, column 2 to column 14)", - " (in 'cpp-reserved-words.stan', line 45, column 2 to column 15)", - " (in 'cpp-reserved-words.stan', line 46, column 2 to column 16)", - " (in 'cpp-reserved-words.stan', line 47, column 2 to column 10)", - " (in 'cpp-reserved-words.stan', line 69, column 2 to column 13)", - " (in 'cpp-reserved-words.stan', line 70, column 2 to column 11)", - " (in 'cpp-reserved-words.stan', line 71, column 2 to column 14)", - " (in 'cpp-reserved-words.stan', line 72, column 2 to column 16)", - " (in 'cpp-reserved-words.stan', line 73, column 2 to column 13)", - " (in 'cpp-reserved-words.stan', line 74, column 2 to column 16)", - " (in 'cpp-reserved-words.stan', line 75, column 2 to column 13)", - " (in 'cpp-reserved-words.stan', line 76, column 2 to column 15)", - " (in 'cpp-reserved-words.stan', line 77, column 2 to column 16)", - " (in 'cpp-reserved-words.stan', line 78, column 2 to column 15)", - " (in 'cpp-reserved-words.stan', line 79, column 2 to column 11)", - " (in 'cpp-reserved-words.stan', line 80, column 2 to column 14)", - " (in 'cpp-reserved-words.stan', line 81, column 2 to column 12)", - " (in 'cpp-reserved-words.stan', line 82, column 2 to column 18)", - " (in 'cpp-reserved-words.stan', line 83, column 2 to column 18)", - " (in 'cpp-reserved-words.stan', line 84, column 2 to column 18)", - " (in 'cpp-reserved-words.stan', line 85, column 2 to column 23)", - " (in 'cpp-reserved-words.stan', line 86, column 2 to column 23)", - " (in 'cpp-reserved-words.stan', line 87, column 2 to column 23)", - " (in 'cpp-reserved-words.stan', line 51, column 2 to column 13)", - " (in 'cpp-reserved-words.stan', line 52, column 2 to column 15)", - " (in 'cpp-reserved-words.stan', line 53, column 2 to column 17)", - " (in 'cpp-reserved-words.stan', line 54, column 2 to column 14)", - " (in 'cpp-reserved-words.stan', line 55, column 2 to column 16)", - " (in 'cpp-reserved-words.stan', line 56, column 2 to column 24)", - " (in 'cpp-reserved-words.stan', line 57, column 2 to column 13)", - " (in 'cpp-reserved-words.stan', line 58, column 2 to column 14)", - " (in 'cpp-reserved-words.stan', line 59, column 2 to column 14)", - " (in 'cpp-reserved-words.stan', line 60, column 2 to column 21)", - " (in 'cpp-reserved-words.stan', line 61, column 2 to column 19)", - " (in 'cpp-reserved-words.stan', line 62, column 2 to column 14)", - " (in 'cpp-reserved-words.stan', line 63, column 2 to column 16)", - " (in 'cpp-reserved-words.stan', line 64, column 2 to column 12)", - " (in 'cpp-reserved-words.stan', line 65, column 2 to column 20)", - " (in 'cpp-reserved-words.stan', line 18, column 2 to column 13)", - " (in 'cpp-reserved-words.stan', line 19, column 2 to column 13)", - " (in 'cpp-reserved-words.stan', line 20, column 2 to column 13)", - " (in 'cpp-reserved-words.stan', line 21, column 2 to column 17)", - " (in 'cpp-reserved-words.stan', line 22, column 2 to column 18)", - " (in 'cpp-reserved-words.stan', line 23, column 2 to column 16)", - " (in 'cpp-reserved-words.stan', line 24, column 2 to column 15)", - " (in 'cpp-reserved-words.stan', line 25, column 2 to column 14)", - " (in 'cpp-reserved-words.stan', line 26, column 2 to column 10)", - " (in 'cpp-reserved-words.stan', line 27, column 2 to column 14)", - " (in 'cpp-reserved-words.stan', line 28, column 2 to column 20)", - " (in 'cpp-reserved-words.stan', line 29, column 2 to column 12)", - " (in 'cpp-reserved-words.stan', line 2, column 23 to column 25)", - " (in 'cpp-reserved-words.stan', line 3, column 24 to column 26)", - " (in 'cpp-reserved-words.stan', line 4, column 26 to column 28)", - " (in 'cpp-reserved-words.stan', line 5, column 30 to column 32)", - " (in 'cpp-reserved-words.stan', line 6, column 24 to column 26)", - " (in 'cpp-reserved-words.stan', line 7, column 28 to column 30)", - " (in 'cpp-reserved-words.stan', line 8, column 14 to column 16)", - " (in 'cpp-reserved-words.stan', line 9, column 13 to column 15)", - " (in 'cpp-reserved-words.stan', line 10, column 13 to column 15)", - " (in 'cpp-reserved-words.stan', line 11, column 14 to column 16)", - " (in 'cpp-reserved-words.stan', line 12, column 13 to column 15)", - " (in 'cpp-reserved-words.stan', line 13, column 17 to column 19)", - " (in 'cpp-reserved-words.stan', line 14, column 17 to column 19)"}; - - -void -_stan_alignas(const int& _stan_asm, std::ostream* pstream__) { - using local_scalar_t__ = double; - int current_statement__ = 0; - static constexpr bool propto__ = true; - (void) propto__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - try { + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + +} + +struct _stan_char16_t_functor__ { +void +operator()(std::ostream* pstream__) const +{ +return _stan_char16_t(pstream__); +} +}; + +void +_stan_char32_t(std::ostream* pstream__) { + using local_scalar_t__ = double; + int current_statement__ = 0; + static constexpr bool propto__ = true; + (void) propto__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + (void) DUMMY_VAR__; // suppress unused var warning + try { } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); @@ -4131,470 +4029,177 @@ _stan_alignas(const int& _stan_asm, std::ostream* pstream__) { } -struct _stan_alignas_functor__ { +struct _stan_char32_t_functor__ { void -operator()(const int& _stan_asm, std::ostream* pstream__) const +operator()(std::ostream* pstream__) const { -return _stan_alignas(_stan_asm, pstream__); +return _stan_char32_t(pstream__); } }; -void -_stan_alignof(const int& _stan_char, std::ostream* pstream__) { - using local_scalar_t__ = double; - int current_statement__ = 0; - static constexpr bool propto__ = true; - (void) propto__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - try { - - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - -} - -struct _stan_alignof_functor__ { -void -operator()(const int& _stan_char, std::ostream* pstream__) const -{ -return _stan_alignof(_stan_char, pstream__); -} -}; +class cpp_reserved_words_model final : public model_base_crtp { -void -_stan_and(const int& _stan_STAN_MAJOR, std::ostream* pstream__) { - using local_scalar_t__ = double; - int current_statement__ = 0; - static constexpr bool propto__ = true; - (void) propto__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - try { - - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } + private: + double _stan_class; + double _stan_compl; + double _stan_const; + double _stan_constexpr; + double _stan_const_cast; + double _stan_decltype; + double _stan_default; + double _stan_delete; + double _stan_do; + double _stan_double; + double _stan_dynamic_cast; + double _stan_enum; -} - -struct _stan_and_functor__ { -void -operator()(const int& _stan_STAN_MAJOR, std::ostream* pstream__) const -{ -return _stan_and(_stan_STAN_MAJOR, pstream__); -} -}; - -template -void -_stan_and_eq(const T0__& _stan_STAN_MINOR, std::ostream* pstream__) { - using local_scalar_t__ = stan::promote_args_t; - int current_statement__ = 0; - static constexpr bool propto__ = true; - (void) propto__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - try { - - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } + + public: + ~cpp_reserved_words_model() { } -} - -struct _stan_and_eq_functor__ { -template -void -operator()(const T0__& _stan_STAN_MINOR, std::ostream* pstream__) const -{ -return _stan_and_eq(_stan_STAN_MINOR, pstream__); -} -}; + inline std::string model_name() const final { return "cpp_reserved_words_model"; } -template -void -_stan_asm(const T0__& _stan_class_arg__, std::ostream* pstream__) { - using local_scalar_t__ = stan::promote_args_t>; - int current_statement__ = 0; - const auto& _stan_class = stan::math::to_ref(_stan_class_arg__); - static constexpr bool propto__ = true; - (void) propto__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - try { - - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = %%NAME%%3 %%VERSION%%", "stancflags = --print-cpp"}; } -} - -struct _stan_asm_functor__ { -template -void -operator()(const T0__& _stan_class, std::ostream* pstream__) const -{ -return _stan_asm(_stan_class, pstream__); -} -}; - -void -_stan_bitand(const int& _stan_constexpr, std::ostream* pstream__) { - using local_scalar_t__ = double; - int current_statement__ = 0; - static constexpr bool propto__ = true; - (void) propto__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - try { + + cpp_reserved_words_model(stan::io::var_context& context__, + unsigned int random_seed__ = 0, + std::ostream* pstream__ = nullptr) : model_base_crtp(0) { + int current_statement__ = 0; + using local_scalar_t__ = double ; + boost::ecuyer1988 base_rng__ = + stan::services::util::create_rng(random_seed__, 0); + (void) base_rng__; // suppress unused var warning + static constexpr const char* function__ = "cpp_reserved_words_model_namespace::cpp_reserved_words_model"; + (void) function__; // suppress unused var warning + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + (void) DUMMY_VAR__; // suppress unused var warning + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + current_statement__ = 50; + context__.validate_dims("data initialization","class","double", + std::vector{}); + _stan_class = std::numeric_limits::quiet_NaN(); + + + current_statement__ = 50; + _stan_class = context__.vals_r("class")[(1 - 1)]; + current_statement__ = 51; + context__.validate_dims("data initialization","compl","double", + std::vector{}); + _stan_compl = std::numeric_limits::quiet_NaN(); + + + current_statement__ = 51; + _stan_compl = context__.vals_r("compl")[(1 - 1)]; + current_statement__ = 52; + context__.validate_dims("data initialization","const","double", + std::vector{}); + _stan_const = std::numeric_limits::quiet_NaN(); + + + current_statement__ = 52; + _stan_const = context__.vals_r("const")[(1 - 1)]; + current_statement__ = 53; + context__.validate_dims("data initialization","constexpr","double", + std::vector{}); + _stan_constexpr = std::numeric_limits::quiet_NaN(); + + + current_statement__ = 53; + _stan_constexpr = context__.vals_r("constexpr")[(1 - 1)]; + current_statement__ = 54; + context__.validate_dims("data initialization","const_cast","double", + std::vector{}); + _stan_const_cast = std::numeric_limits::quiet_NaN(); + + + current_statement__ = 54; + _stan_const_cast = context__.vals_r("const_cast")[(1 - 1)]; + current_statement__ = 55; + context__.validate_dims("data initialization","decltype","double", + std::vector{}); + _stan_decltype = std::numeric_limits::quiet_NaN(); + + + current_statement__ = 55; + _stan_decltype = context__.vals_r("decltype")[(1 - 1)]; + current_statement__ = 56; + context__.validate_dims("data initialization","default","double", + std::vector{}); + _stan_default = std::numeric_limits::quiet_NaN(); + + + current_statement__ = 56; + _stan_default = context__.vals_r("default")[(1 - 1)]; + current_statement__ = 57; + context__.validate_dims("data initialization","delete","double", + std::vector{}); + _stan_delete = std::numeric_limits::quiet_NaN(); + + + current_statement__ = 57; + _stan_delete = context__.vals_r("delete")[(1 - 1)]; + current_statement__ = 58; + context__.validate_dims("data initialization","do","double", + std::vector{}); + _stan_do = std::numeric_limits::quiet_NaN(); + + + current_statement__ = 58; + _stan_do = context__.vals_r("do")[(1 - 1)]; + current_statement__ = 59; + context__.validate_dims("data initialization","double","double", + std::vector{}); + _stan_double = std::numeric_limits::quiet_NaN(); + + + current_statement__ = 59; + _stan_double = context__.vals_r("double")[(1 - 1)]; + current_statement__ = 60; + context__.validate_dims("data initialization","dynamic_cast","double", + std::vector{}); + _stan_dynamic_cast = std::numeric_limits::quiet_NaN(); + + + current_statement__ = 60; + _stan_dynamic_cast = context__.vals_r("dynamic_cast")[(1 - 1)]; + current_statement__ = 61; + context__.validate_dims("data initialization","enum","double", + std::vector{}); + _stan_enum = std::numeric_limits::quiet_NaN(); + + + current_statement__ = 61; + _stan_enum = context__.vals_r("enum")[(1 - 1)]; + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + num_params_r__ = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + + 1 + 1 + 1; - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); } -} - -struct _stan_bitand_functor__ { -void -operator()(const int& _stan_constexpr, std::ostream* pstream__) const -{ -return _stan_bitand(_stan_constexpr, pstream__); -} -}; - -void -_stan_bitor(std::ostream* pstream__) { - using local_scalar_t__ = double; - int current_statement__ = 0; - static constexpr bool propto__ = true; - (void) propto__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - try { - - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - -} - -struct _stan_bitor_functor__ { -void -operator()(std::ostream* pstream__) const -{ -return _stan_bitor(pstream__); -} -}; - -void -_stan_bool(std::ostream* pstream__) { - using local_scalar_t__ = double; - int current_statement__ = 0; - static constexpr bool propto__ = true; - (void) propto__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - try { - - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - -} - -struct _stan_bool_functor__ { -void -operator()(std::ostream* pstream__) const -{ -return _stan_bool(pstream__); -} -}; - -void -_stan_case(std::ostream* pstream__) { - using local_scalar_t__ = double; - int current_statement__ = 0; - static constexpr bool propto__ = true; - (void) propto__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - try { - - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - -} - -struct _stan_case_functor__ { -void -operator()(std::ostream* pstream__) const -{ -return _stan_case(pstream__); -} -}; - -void -_stan_catch(std::ostream* pstream__) { - using local_scalar_t__ = double; - int current_statement__ = 0; - static constexpr bool propto__ = true; - (void) propto__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - try { - - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - -} - -struct _stan_catch_functor__ { -void -operator()(std::ostream* pstream__) const -{ -return _stan_catch(pstream__); -} -}; - -void -_stan_char(std::ostream* pstream__) { - using local_scalar_t__ = double; - int current_statement__ = 0; - static constexpr bool propto__ = true; - (void) propto__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - try { - - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - -} - -struct _stan_char_functor__ { -void -operator()(std::ostream* pstream__) const -{ -return _stan_char(pstream__); -} -}; - -void -_stan_char16_t(std::ostream* pstream__) { - using local_scalar_t__ = double; - int current_statement__ = 0; - static constexpr bool propto__ = true; - (void) propto__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - try { - - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - -} - -struct _stan_char16_t_functor__ { -void -operator()(std::ostream* pstream__) const -{ -return _stan_char16_t(pstream__); -} -}; - -void -_stan_char32_t(std::ostream* pstream__) { - using local_scalar_t__ = double; - int current_statement__ = 0; - static constexpr bool propto__ = true; - (void) propto__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - try { - - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - -} - -struct _stan_char32_t_functor__ { -void -operator()(std::ostream* pstream__) const -{ -return _stan_char32_t(pstream__); -} -}; - -class cpp_reserved_words_model final : public model_base_crtp { - - private: - double _stan_class; - double _stan_compl; - double _stan_const; - double _stan_constexpr; - double _stan_const_cast; - double _stan_decltype; - double _stan_default; - double _stan_delete; - double _stan_do; - double _stan_double; - double _stan_dynamic_cast; - double _stan_enum; - - - public: - ~cpp_reserved_words_model() { } - - inline std::string model_name() const final { return "cpp_reserved_words_model"; } - - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = %%NAME%%3 %%VERSION%%", "stancflags = --print-cpp"}; - } - - - cpp_reserved_words_model(stan::io::var_context& context__, - unsigned int random_seed__ = 0, - std::ostream* pstream__ = nullptr) : model_base_crtp(0) { + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t log_prob_impl(VecR& params_r__, + VecI& params_i__, + std::ostream* pstream__ = nullptr) const { + using T__ = stan::scalar_type_t; + using local_scalar_t__ = T__; + T__ lp__(0.0); + stan::math::accumulator lp_accum__; + stan::io::deserializer in__(params_r__, params_i__); int current_statement__ = 0; - using local_scalar_t__ = double ; - boost::ecuyer1988 base_rng__ = - stan::services::util::create_rng(random_seed__, 0); - (void) base_rng__; // suppress unused var warning - static constexpr const char* function__ = "cpp_reserved_words_model_namespace::cpp_reserved_words_model"; - (void) function__; // suppress unused var warning local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); (void) DUMMY_VAR__; // suppress unused var warning - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - current_statement__ = 50; - context__.validate_dims("data initialization","class","double", - std::vector{}); - _stan_class = std::numeric_limits::quiet_NaN(); - - - current_statement__ = 50; - _stan_class = context__.vals_r("class")[(1 - 1)]; - current_statement__ = 51; - context__.validate_dims("data initialization","compl","double", - std::vector{}); - _stan_compl = std::numeric_limits::quiet_NaN(); - - - current_statement__ = 51; - _stan_compl = context__.vals_r("compl")[(1 - 1)]; - current_statement__ = 52; - context__.validate_dims("data initialization","const","double", - std::vector{}); - _stan_const = std::numeric_limits::quiet_NaN(); - - - current_statement__ = 52; - _stan_const = context__.vals_r("const")[(1 - 1)]; - current_statement__ = 53; - context__.validate_dims("data initialization","constexpr","double", - std::vector{}); - _stan_constexpr = std::numeric_limits::quiet_NaN(); - - - current_statement__ = 53; - _stan_constexpr = context__.vals_r("constexpr")[(1 - 1)]; - current_statement__ = 54; - context__.validate_dims("data initialization","const_cast","double", - std::vector{}); - _stan_const_cast = std::numeric_limits::quiet_NaN(); - - - current_statement__ = 54; - _stan_const_cast = context__.vals_r("const_cast")[(1 - 1)]; - current_statement__ = 55; - context__.validate_dims("data initialization","decltype","double", - std::vector{}); - _stan_decltype = std::numeric_limits::quiet_NaN(); - - - current_statement__ = 55; - _stan_decltype = context__.vals_r("decltype")[(1 - 1)]; - current_statement__ = 56; - context__.validate_dims("data initialization","default","double", - std::vector{}); - _stan_default = std::numeric_limits::quiet_NaN(); - - - current_statement__ = 56; - _stan_default = context__.vals_r("default")[(1 - 1)]; - current_statement__ = 57; - context__.validate_dims("data initialization","delete","double", - std::vector{}); - _stan_delete = std::numeric_limits::quiet_NaN(); - - - current_statement__ = 57; - _stan_delete = context__.vals_r("delete")[(1 - 1)]; - current_statement__ = 58; - context__.validate_dims("data initialization","do","double", - std::vector{}); - _stan_do = std::numeric_limits::quiet_NaN(); - - - current_statement__ = 58; - _stan_do = context__.vals_r("do")[(1 - 1)]; - current_statement__ = 59; - context__.validate_dims("data initialization","double","double", - std::vector{}); - _stan_double = std::numeric_limits::quiet_NaN(); - - - current_statement__ = 59; - _stan_double = context__.vals_r("double")[(1 - 1)]; - current_statement__ = 60; - context__.validate_dims("data initialization","dynamic_cast","double", - std::vector{}); - _stan_dynamic_cast = std::numeric_limits::quiet_NaN(); - - - current_statement__ = 60; - _stan_dynamic_cast = context__.vals_r("dynamic_cast")[(1 - 1)]; - current_statement__ = 61; - context__.validate_dims("data initialization","enum","double", - std::vector{}); - _stan_enum = std::numeric_limits::quiet_NaN(); - - - current_statement__ = 61; - _stan_enum = context__.vals_r("enum")[(1 - 1)]; - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - num_params_r__ = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + - 1 + 1 + 1; - - } - - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t log_prob_impl(VecR& params_r__, - VecI& params_i__, - std::ostream* pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - static constexpr const char* function__ = "cpp_reserved_words_model_namespace::log_prob"; - (void) function__; // suppress unused var warning - + static constexpr const char* function__ = "cpp_reserved_words_model_namespace::log_prob"; + (void) function__; // suppress unused var warning + try { local_scalar_t__ _stan_explicit = DUMMY_VAR__; current_statement__ = 1; @@ -23159,60 +22764,587 @@ class optimize_glm_model final : public model_base_crtp { local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); constexpr bool jacobian__ = false; (void) DUMMY_VAR__; // suppress unused var warning - static constexpr const char* function__ = "optimize_glm_model_namespace::write_array"; + static constexpr const char* function__ = "optimize_glm_model_namespace::write_array"; + (void) function__; // suppress unused var warning + + try { + Eigen::Matrix alpha_v = + Eigen::Matrix::Constant(k, + std::numeric_limits::quiet_NaN()); + current_statement__ = 1; + alpha_v = in__.template read>(k); + Eigen::Matrix beta = + Eigen::Matrix::Constant(k, + std::numeric_limits::quiet_NaN()); + current_statement__ = 2; + beta = in__.template read>(k); + Eigen::Matrix cuts = + Eigen::Matrix::Constant(k, + std::numeric_limits::quiet_NaN()); + current_statement__ = 3; + cuts = in__.template read>(k); + double sigma = std::numeric_limits::quiet_NaN(); + current_statement__ = 4; + sigma = in__.template read_constrain_lb( + 0, lp__); + double alpha = std::numeric_limits::quiet_NaN(); + current_statement__ = 5; + alpha = in__.template read(); + double phi = std::numeric_limits::quiet_NaN(); + current_statement__ = 6; + phi = in__.template read(); + Eigen::Matrix X_p = + Eigen::Matrix::Constant(n, k, + std::numeric_limits::quiet_NaN()); + current_statement__ = 7; + X_p = in__.template read>(n, k); + Eigen::Matrix beta_m = + Eigen::Matrix::Constant(n, k, + std::numeric_limits::quiet_NaN()); + current_statement__ = 8; + beta_m = in__.template read>(n, + k); + Eigen::Matrix X_rv_p = + Eigen::Matrix::Constant(n, + std::numeric_limits::quiet_NaN()); + current_statement__ = 9; + X_rv_p = in__.template read>(n); + out__.write(alpha_v); + out__.write(beta); + out__.write(cuts); + out__.write(sigma); + out__.write(alpha); + out__.write(phi); + out__.write(X_p); + out__.write(beta_m); + out__.write(X_rv_p); + if (stan::math::logical_negation((stan::math::primitive_value( + emit_transformed_parameters__) || stan::math::primitive_value( + emit_generated_quantities__)))) { + return ; + } + if (stan::math::logical_negation(emit_generated_quantities__)) { + return ; + } + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } // write_array_impl() + + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline void transform_inits_impl(VecVar& params_r__, VecI& params_i__, + VecVar& vars__, + std::ostream* pstream__ = nullptr) const { + using local_scalar_t__ = double; + stan::io::deserializer in__(params_r__, params_i__); + stan::io::serializer out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + Eigen::Matrix alpha_v = + Eigen::Matrix::Constant(k, DUMMY_VAR__); + for (int sym1__ = 1; sym1__ <= k; ++sym1__) { + stan::model::assign(alpha_v, in__.read(), + "assigning variable alpha_v", stan::model::index_uni(sym1__)); + } + out__.write(alpha_v); + Eigen::Matrix beta = + Eigen::Matrix::Constant(k, DUMMY_VAR__); + for (int sym1__ = 1; sym1__ <= k; ++sym1__) { + stan::model::assign(beta, in__.read(), + "assigning variable beta", stan::model::index_uni(sym1__)); + } + out__.write(beta); + Eigen::Matrix cuts = + Eigen::Matrix::Constant(k, DUMMY_VAR__); + for (int sym1__ = 1; sym1__ <= k; ++sym1__) { + stan::model::assign(cuts, in__.read(), + "assigning variable cuts", stan::model::index_uni(sym1__)); + } + out__.write(cuts); + local_scalar_t__ sigma = DUMMY_VAR__; + sigma = in__.read(); + out__.write_free_lb(0, sigma); + local_scalar_t__ alpha = DUMMY_VAR__; + alpha = in__.read(); + out__.write(alpha); + local_scalar_t__ phi = DUMMY_VAR__; + phi = in__.read(); + out__.write(phi); + Eigen::Matrix X_p = + Eigen::Matrix::Constant(n, k, DUMMY_VAR__); + for (int sym1__ = 1; sym1__ <= k; ++sym1__) { + for (int sym2__ = 1; sym2__ <= n; ++sym2__) { + stan::model::assign(X_p, in__.read(), + "assigning variable X_p", stan::model::index_uni(sym2__), + stan::model::index_uni(sym1__)); + } + } + out__.write(X_p); + Eigen::Matrix beta_m = + Eigen::Matrix::Constant(n, k, DUMMY_VAR__); + for (int sym1__ = 1; sym1__ <= k; ++sym1__) { + for (int sym2__ = 1; sym2__ <= n; ++sym2__) { + stan::model::assign(beta_m, in__.read(), + "assigning variable beta_m", stan::model::index_uni(sym2__), + stan::model::index_uni(sym1__)); + } + } + out__.write(beta_m); + Eigen::Matrix X_rv_p = + Eigen::Matrix::Constant(n, DUMMY_VAR__); + for (int sym1__ = 1; sym1__ <= n; ++sym1__) { + stan::model::assign(X_rv_p, in__.read(), + "assigning variable X_rv_p", stan::model::index_uni(sym1__)); + } + out__.write(X_rv_p); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } // transform_inits_impl() + + inline void get_param_names(std::vector& names__) const { + + names__ = std::vector{"alpha_v", "beta", "cuts", "sigma", + "alpha", "phi", "X_p", "beta_m", "X_rv_p"}; + + } // get_param_names() + + inline void get_dims(std::vector>& dimss__) const { + + dimss__ = std::vector>{std::vector{ + static_cast(k) + }, + std::vector{static_cast(k)}, + std::vector{static_cast(k)}, std::vector{ + }, std::vector{}, std::vector{}, + std::vector{static_cast(n), static_cast(k)}, + std::vector{static_cast(n), static_cast(k)}, + std::vector{static_cast(n)}}; + + } // get_dims() + + inline void constrained_param_names( + std::vector& param_names__, + bool emit_transformed_parameters__ = true, + bool emit_generated_quantities__ = true) const + final { + + for (int sym1__ = 1; sym1__ <= k; ++sym1__) { + { + param_names__.emplace_back(std::string() + "alpha_v" + '.' + std::to_string(sym1__)); + } + } + for (int sym1__ = 1; sym1__ <= k; ++sym1__) { + { + param_names__.emplace_back(std::string() + "beta" + '.' + std::to_string(sym1__)); + } + } + for (int sym1__ = 1; sym1__ <= k; ++sym1__) { + { + param_names__.emplace_back(std::string() + "cuts" + '.' + std::to_string(sym1__)); + } + } + param_names__.emplace_back(std::string() + "sigma"); + param_names__.emplace_back(std::string() + "alpha"); + param_names__.emplace_back(std::string() + "phi"); + for (int sym1__ = 1; sym1__ <= k; ++sym1__) { + { + for (int sym2__ = 1; sym2__ <= n; ++sym2__) { + { + param_names__.emplace_back(std::string() + "X_p" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } + } + } + for (int sym1__ = 1; sym1__ <= k; ++sym1__) { + { + for (int sym2__ = 1; sym2__ <= n; ++sym2__) { + { + param_names__.emplace_back(std::string() + "beta_m" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } + } + } + for (int sym1__ = 1; sym1__ <= n; ++sym1__) { + { + param_names__.emplace_back(std::string() + "X_rv_p" + '.' + std::to_string(sym1__)); + } + } + if (emit_transformed_parameters__) { + + } + + if (emit_generated_quantities__) { + + } + + } // constrained_param_names() + + inline void unconstrained_param_names( + std::vector& param_names__, + bool emit_transformed_parameters__ = true, + bool emit_generated_quantities__ = true) const + final { + + for (int sym1__ = 1; sym1__ <= k; ++sym1__) { + { + param_names__.emplace_back(std::string() + "alpha_v" + '.' + std::to_string(sym1__)); + } + } + for (int sym1__ = 1; sym1__ <= k; ++sym1__) { + { + param_names__.emplace_back(std::string() + "beta" + '.' + std::to_string(sym1__)); + } + } + for (int sym1__ = 1; sym1__ <= k; ++sym1__) { + { + param_names__.emplace_back(std::string() + "cuts" + '.' + std::to_string(sym1__)); + } + } + param_names__.emplace_back(std::string() + "sigma"); + param_names__.emplace_back(std::string() + "alpha"); + param_names__.emplace_back(std::string() + "phi"); + for (int sym1__ = 1; sym1__ <= k; ++sym1__) { + { + for (int sym2__ = 1; sym2__ <= n; ++sym2__) { + { + param_names__.emplace_back(std::string() + "X_p" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } + } + } + for (int sym1__ = 1; sym1__ <= k; ++sym1__) { + { + for (int sym2__ = 1; sym2__ <= n; ++sym2__) { + { + param_names__.emplace_back(std::string() + "beta_m" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } + } + } + for (int sym1__ = 1; sym1__ <= n; ++sym1__) { + { + param_names__.emplace_back(std::string() + "X_rv_p" + '.' + std::to_string(sym1__)); + } + } + if (emit_transformed_parameters__) { + + } + + if (emit_generated_quantities__) { + + } + + } // unconstrained_param_names() + + inline std::string get_constrained_sizedtypes() const { + + return std::string("[{\"name\":\"alpha_v\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"cuts\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"X_p\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(n) + ",\"cols\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"beta_m\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(n) + ",\"cols\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"X_rv_p\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n) + "},\"block\":\"parameters\"}]"); + + } // get_constrained_sizedtypes() + + inline std::string get_unconstrained_sizedtypes() const { + + return std::string("[{\"name\":\"alpha_v\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"cuts\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"X_p\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(n) + ",\"cols\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"beta_m\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(n) + ",\"cols\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"X_rv_p\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n) + "},\"block\":\"parameters\"}]"); + + } // get_unconstrained_sizedtypes() + + + // Begin method overload boilerplate + template + inline void write_array(RNG& base_rng, + Eigen::Matrix& params_r, + Eigen::Matrix& vars, + const bool emit_transformed_parameters = true, + const bool emit_generated_quantities = true, + std::ostream* pstream = nullptr) const { + const size_t num_params__ = + ((((((((k + k) + k) + 1) + 1) + 1) + (n * k)) + (n * k)) + n); + const size_t num_transformed = 0; + const size_t num_gen_quantities = 0; + std::vector vars_vec(num_params__ + + (emit_transformed_parameters * num_transformed) + + (emit_generated_quantities * num_gen_quantities)); + std::vector params_i; + write_array_impl(base_rng, params_r, params_i, vars_vec, + emit_transformed_parameters, emit_generated_quantities, pstream); + vars = Eigen::Map>( + vars_vec.data(), vars_vec.size()); + } + + template + inline void write_array(RNG& base_rng, std::vector& params_r, + std::vector& params_i, + std::vector& vars, + bool emit_transformed_parameters = true, + bool emit_generated_quantities = true, + std::ostream* pstream = nullptr) const { + const size_t num_params__ = + ((((((((k + k) + k) + 1) + 1) + 1) + (n * k)) + (n * k)) + n); + const size_t num_transformed = 0; + const size_t num_gen_quantities = 0; + vars.resize(num_params__ + + (emit_transformed_parameters * num_transformed) + + (emit_generated_quantities * num_gen_quantities)); + write_array_impl(base_rng, params_r, params_i, vars, emit_transformed_parameters, emit_generated_quantities, pstream); + } + + template + inline T_ log_prob(Eigen::Matrix& params_r, + std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + + template + inline T__ log_prob(std::vector& params_r, + std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + + + inline void transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, + std::ostream* pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits(context, params_i, params_r_vec, pstream); + params_r = Eigen::Map>( + params_r_vec.data(), params_r_vec.size()); + } + + inline void transform_inits(const stan::io::var_context& context, + std::vector& params_i, + std::vector& vars, + std::ostream* pstream__ = nullptr) const { + constexpr std::array names__{"alpha_v", "beta", "cuts", + "sigma", "alpha", "phi", "X_p", "beta_m", "X_rv_p"}; + const std::array constrain_param_sizes__{k, k, + k, 1, 1, 1, (n * k), (n * k), n}; + const auto num_constrained_params__ = std::accumulate( + constrain_param_sizes__.begin(), constrain_param_sizes__.end(), 0); + + std::vector params_r_flat__(num_constrained_params__); + Eigen::Index size_iter__ = 0; + Eigen::Index flat_iter__ = 0; + for (auto&& param_name__ : names__) { + const auto param_vec__ = context.vals_r(param_name__); + for (Eigen::Index i = 0; i < constrain_param_sizes__[size_iter__]; ++i) { + params_r_flat__[flat_iter__] = param_vec__[i]; + ++flat_iter__; + } + ++size_iter__; + } + vars.resize(num_params_r__); + transform_inits_impl(params_r_flat__, params_i, vars, pstream__); + } // transform_inits() + +}; +} +using stan_model = optimize_glm_model_namespace::optimize_glm_model; + +#ifndef USING_R + +// Boilerplate +stan::model::model_base& new_model( + stan::io::var_context& data_context, + unsigned int seed, + std::ostream* msg_stream) { + stan_model* m = new stan_model(data_context, seed, msg_stream); + return *m; +} + +stan::math::profile_map& get_stan_profile_data() { + return optimize_glm_model_namespace::profiles__; +} + +#endif + + + + $ ../../../../../install/default/bin/stanc --print-cpp param-constraint.stan + +// Code generated by %%NAME%% %%VERSION%% +#include +namespace param_constraint_model_namespace { + +using stan::model::model_base_crtp; +using namespace stan::math; + + +stan::math::profile_map profiles__; +static constexpr std::array locations_array__ = +{" (found before start of program)", + " (in 'param-constraint.stan', line 6, column 2 to column 44)", + " (in 'param-constraint.stan', line 7, column 2 to column 40)", + " (in 'param-constraint.stan', line 2, column 2 to column 9)", + " (in 'param-constraint.stan', line 3, column 2 to column 9)", + " (in 'param-constraint.stan', line 6, column 8 to column 10)", + " (in 'param-constraint.stan', line 7, column 33 to column 35)"}; + + + +class param_constraint_model final : public model_base_crtp { + + private: + int nt; + int NS; + + + public: + ~param_constraint_model() { } + + inline std::string model_name() const final { return "param_constraint_model"; } + + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = %%NAME%%3 %%VERSION%%", "stancflags = --print-cpp"}; + } + + + param_constraint_model(stan::io::var_context& context__, + unsigned int random_seed__ = 0, + std::ostream* pstream__ = nullptr) : model_base_crtp(0) { + int current_statement__ = 0; + using local_scalar_t__ = double ; + boost::ecuyer1988 base_rng__ = + stan::services::util::create_rng(random_seed__, 0); + (void) base_rng__; // suppress unused var warning + static constexpr const char* function__ = "param_constraint_model_namespace::param_constraint_model"; + (void) function__; // suppress unused var warning + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + (void) DUMMY_VAR__; // suppress unused var warning + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + current_statement__ = 3; + context__.validate_dims("data initialization","nt","int", + std::vector{}); + nt = std::numeric_limits::min(); + + + current_statement__ = 3; + nt = context__.vals_i("nt")[(1 - 1)]; + current_statement__ = 4; + context__.validate_dims("data initialization","NS","int", + std::vector{}); + NS = std::numeric_limits::min(); + + + current_statement__ = 4; + NS = context__.vals_i("NS")[(1 - 1)]; + current_statement__ = 5; + stan::math::validate_non_negative_index("L_Omega", "nt", nt); + current_statement__ = 6; + stan::math::validate_non_negative_index("z1", "NS", NS); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + num_params_r__ = (nt * ((2 * (2 - 1)) / 2)) + NS; + + } + + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t log_prob_impl(VecR& params_r__, + VecI& params_i__, + std::ostream* pstream__ = nullptr) const { + using T__ = stan::scalar_type_t; + using local_scalar_t__ = T__; + T__ lp__(0.0); + stan::math::accumulator lp_accum__; + stan::io::deserializer in__(params_r__, params_i__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + (void) DUMMY_VAR__; // suppress unused var warning + static constexpr const char* function__ = "param_constraint_model_namespace::log_prob"; + (void) function__; // suppress unused var warning + + try { + std::vector> L_Omega = + std::vector>(nt, + Eigen::Matrix::Constant(2, 2, + DUMMY_VAR__)); + current_statement__ = 1; + L_Omega = in__.template read_constrain_cholesky_factor_corr< + std::vector>, + jacobian__>(lp__, nt, 2); + Eigen::Matrix z1 = + Eigen::Matrix::Constant(NS, DUMMY_VAR__); + current_statement__ = 2; + z1 = in__.template read_constrain_lb< + Eigen::Matrix, jacobian__>( + stan::model::rvalue(L_Omega, "L_Omega", + stan::model::index_uni(1), stan::model::index_uni(1), + stan::model::index_uni(2)), lp__, NS); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + lp_accum__.add(lp__); + return lp_accum__.sum(); + } // log_prob_impl() + + template * = nullptr, + stan::require_vector_like_vt* = nullptr, + stan::require_std_vector_vt* = nullptr> + inline void write_array_impl(RNG& base_rng__, VecR& params_r__, + VecI& params_i__, VecVar& vars__, + const bool emit_transformed_parameters__ = true, + const bool emit_generated_quantities__ = true, + std::ostream* pstream__ = nullptr) const { + using local_scalar_t__ = double; + stan::io::deserializer in__(params_r__, params_i__); + stan::io::serializer out__(vars__); + static constexpr bool propto__ = true; + (void) propto__; + double lp__ = 0.0; + (void) lp__; // dummy to suppress unused var warning + int current_statement__ = 0; + stan::math::accumulator lp_accum__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + constexpr bool jacobian__ = false; + (void) DUMMY_VAR__; // suppress unused var warning + static constexpr const char* function__ = "param_constraint_model_namespace::write_array"; (void) function__; // suppress unused var warning try { - Eigen::Matrix alpha_v = - Eigen::Matrix::Constant(k, - std::numeric_limits::quiet_NaN()); + std::vector> L_Omega = + std::vector>(nt, + Eigen::Matrix::Constant(2, 2, + std::numeric_limits::quiet_NaN())); current_statement__ = 1; - alpha_v = in__.template read>(k); - Eigen::Matrix beta = - Eigen::Matrix::Constant(k, + L_Omega = in__.template read_constrain_cholesky_factor_corr< + std::vector>, + jacobian__>(lp__, nt, 2); + Eigen::Matrix z1 = + Eigen::Matrix::Constant(NS, std::numeric_limits::quiet_NaN()); current_statement__ = 2; - beta = in__.template read>(k); - Eigen::Matrix cuts = - Eigen::Matrix::Constant(k, - std::numeric_limits::quiet_NaN()); - current_statement__ = 3; - cuts = in__.template read>(k); - double sigma = std::numeric_limits::quiet_NaN(); - current_statement__ = 4; - sigma = in__.template read_constrain_lb( - 0, lp__); - double alpha = std::numeric_limits::quiet_NaN(); - current_statement__ = 5; - alpha = in__.template read(); - double phi = std::numeric_limits::quiet_NaN(); - current_statement__ = 6; - phi = in__.template read(); - Eigen::Matrix X_p = - Eigen::Matrix::Constant(n, k, - std::numeric_limits::quiet_NaN()); - current_statement__ = 7; - X_p = in__.template read>(n, k); - Eigen::Matrix beta_m = - Eigen::Matrix::Constant(n, k, - std::numeric_limits::quiet_NaN()); - current_statement__ = 8; - beta_m = in__.template read>(n, - k); - Eigen::Matrix X_rv_p = - Eigen::Matrix::Constant(n, - std::numeric_limits::quiet_NaN()); - current_statement__ = 9; - X_rv_p = in__.template read>(n); - out__.write(alpha_v); - out__.write(beta); - out__.write(cuts); - out__.write(sigma); - out__.write(alpha); - out__.write(phi); - out__.write(X_p); - out__.write(beta_m); - out__.write(X_rv_p); + z1 = in__.template read_constrain_lb< + Eigen::Matrix, jacobian__>( + stan::model::rvalue(L_Omega, "L_Omega", + stan::model::index_uni(1), stan::model::index_uni(1), + stan::model::index_uni(2)), lp__, NS); + for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { + for (int sym2__ = 1; sym2__ <= 2; ++sym2__) { + for (int sym3__ = 1; sym3__ <= nt; ++sym3__) { + out__.write( + stan::model::rvalue(L_Omega, "L_Omega", + stan::model::index_uni(sym3__), + stan::model::index_uni(sym2__), + stan::model::index_uni(sym1__))); + } + } + } + out__.write(z1); if (stan::math::logical_negation((stan::math::primitive_value( emit_transformed_parameters__) || stan::math::primitive_value( emit_generated_quantities__)))) { @@ -23241,63 +23373,31 @@ class optimize_glm_model final : public model_base_crtp { try { int pos__ = std::numeric_limits::min(); pos__ = 1; - Eigen::Matrix alpha_v = - Eigen::Matrix::Constant(k, DUMMY_VAR__); - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - stan::model::assign(alpha_v, in__.read(), - "assigning variable alpha_v", stan::model::index_uni(sym1__)); - } - out__.write(alpha_v); - Eigen::Matrix beta = - Eigen::Matrix::Constant(k, DUMMY_VAR__); - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - stan::model::assign(beta, in__.read(), - "assigning variable beta", stan::model::index_uni(sym1__)); - } - out__.write(beta); - Eigen::Matrix cuts = - Eigen::Matrix::Constant(k, DUMMY_VAR__); - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - stan::model::assign(cuts, in__.read(), - "assigning variable cuts", stan::model::index_uni(sym1__)); - } - out__.write(cuts); - local_scalar_t__ sigma = DUMMY_VAR__; - sigma = in__.read(); - out__.write_free_lb(0, sigma); - local_scalar_t__ alpha = DUMMY_VAR__; - alpha = in__.read(); - out__.write(alpha); - local_scalar_t__ phi = DUMMY_VAR__; - phi = in__.read(); - out__.write(phi); - Eigen::Matrix X_p = - Eigen::Matrix::Constant(n, k, DUMMY_VAR__); - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - for (int sym2__ = 1; sym2__ <= n; ++sym2__) { - stan::model::assign(X_p, in__.read(), - "assigning variable X_p", stan::model::index_uni(sym2__), - stan::model::index_uni(sym1__)); - } - } - out__.write(X_p); - Eigen::Matrix beta_m = - Eigen::Matrix::Constant(n, k, DUMMY_VAR__); - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - for (int sym2__ = 1; sym2__ <= n; ++sym2__) { - stan::model::assign(beta_m, in__.read(), - "assigning variable beta_m", stan::model::index_uni(sym2__), - stan::model::index_uni(sym1__)); + std::vector> L_Omega = + std::vector>(nt, + Eigen::Matrix::Constant(2, 2, + DUMMY_VAR__)); + for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { + for (int sym2__ = 1; sym2__ <= 2; ++sym2__) { + for (int sym3__ = 1; sym3__ <= nt; ++sym3__) { + stan::model::assign(L_Omega, in__.read(), + "assigning variable L_Omega", stan::model::index_uni(sym3__), + stan::model::index_uni(sym2__), + stan::model::index_uni(sym1__)); + } } } - out__.write(beta_m); - Eigen::Matrix X_rv_p = - Eigen::Matrix::Constant(n, DUMMY_VAR__); - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - stan::model::assign(X_rv_p, in__.read(), - "assigning variable X_rv_p", stan::model::index_uni(sym1__)); + out__.write_free_cholesky_factor_corr(L_Omega); + Eigen::Matrix z1 = + Eigen::Matrix::Constant(NS, DUMMY_VAR__); + for (int sym1__ = 1; sym1__ <= NS; ++sym1__) { + stan::model::assign(z1, in__.read(), + "assigning variable z1", stan::model::index_uni(sym1__)); } - out__.write(X_rv_p); + out__.write_free_lb( + stan::model::rvalue(L_Omega, "L_Omega", + stan::model::index_uni(1), stan::model::index_uni(1), + stan::model::index_uni(2)), z1); } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); } @@ -23305,22 +23405,20 @@ class optimize_glm_model final : public model_base_crtp { inline void get_param_names(std::vector& names__) const { - names__ = std::vector{"alpha_v", "beta", "cuts", "sigma", - "alpha", "phi", "X_p", "beta_m", "X_rv_p"}; + names__ = std::vector{"L_Omega", "z1"}; } // get_param_names() inline void get_dims(std::vector>& dimss__) const { dimss__ = std::vector>{std::vector{ - static_cast(k) + static_cast(nt) + , + static_cast(2) + , + static_cast(2) }, - std::vector{static_cast(k)}, - std::vector{static_cast(k)}, std::vector{ - }, std::vector{}, std::vector{}, - std::vector{static_cast(n), static_cast(k)}, - std::vector{static_cast(n), static_cast(k)}, - std::vector{static_cast(n)}}; + std::vector{static_cast(NS)}}; } // get_dims() @@ -23330,45 +23428,22 @@ class optimize_glm_model final : public model_base_crtp { bool emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - { - param_names__.emplace_back(std::string() + "alpha_v" + '.' + std::to_string(sym1__)); - } - } - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - { - param_names__.emplace_back(std::string() + "beta" + '.' + std::to_string(sym1__)); - } - } - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - { - param_names__.emplace_back(std::string() + "cuts" + '.' + std::to_string(sym1__)); - } - } - param_names__.emplace_back(std::string() + "sigma"); - param_names__.emplace_back(std::string() + "alpha"); - param_names__.emplace_back(std::string() + "phi"); - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= n; ++sym2__) { - { - param_names__.emplace_back(std::string() + "X_p" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - } - } - } - } - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { + for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { { - for (int sym2__ = 1; sym2__ <= n; ++sym2__) { + for (int sym2__ = 1; sym2__ <= 2; ++sym2__) { { - param_names__.emplace_back(std::string() + "beta_m" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + for (int sym3__ = 1; sym3__ <= nt; ++sym3__) { + { + param_names__.emplace_back(std::string() + "L_Omega" + '.' + std::to_string(sym3__) + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } } } } } - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { + for (int sym1__ = 1; sym1__ <= NS; ++sym1__) { { - param_names__.emplace_back(std::string() + "X_rv_p" + '.' + std::to_string(sym1__)); + param_names__.emplace_back(std::string() + "z1" + '.' + std::to_string(sym1__)); } } if (emit_transformed_parameters__) { @@ -23387,45 +23462,18 @@ class optimize_glm_model final : public model_base_crtp { bool emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - { - param_names__.emplace_back(std::string() + "alpha_v" + '.' + std::to_string(sym1__)); - } - } - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - { - param_names__.emplace_back(std::string() + "beta" + '.' + std::to_string(sym1__)); - } - } - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - { - param_names__.emplace_back(std::string() + "cuts" + '.' + std::to_string(sym1__)); - } - } - param_names__.emplace_back(std::string() + "sigma"); - param_names__.emplace_back(std::string() + "alpha"); - param_names__.emplace_back(std::string() + "phi"); - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= n; ++sym2__) { - { - param_names__.emplace_back(std::string() + "X_p" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - } - } - } - } - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { + for (int sym1__ = 1; sym1__ <= ((2 * (2 - 1)) / 2); ++sym1__) { { - for (int sym2__ = 1; sym2__ <= n; ++sym2__) { + for (int sym2__ = 1; sym2__ <= nt; ++sym2__) { { - param_names__.emplace_back(std::string() + "beta_m" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + param_names__.emplace_back(std::string() + "L_Omega" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); } } } } - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { + for (int sym1__ = 1; sym1__ <= NS; ++sym1__) { { - param_names__.emplace_back(std::string() + "X_rv_p" + '.' + std::to_string(sym1__)); + param_names__.emplace_back(std::string() + "z1" + '.' + std::to_string(sym1__)); } } if (emit_transformed_parameters__) { @@ -23440,13 +23488,13 @@ class optimize_glm_model final : public model_base_crtp { inline std::string get_constrained_sizedtypes() const { - return std::string("[{\"name\":\"alpha_v\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"cuts\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"X_p\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(n) + ",\"cols\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"beta_m\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(n) + ",\"cols\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"X_rv_p\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n) + "},\"block\":\"parameters\"}]"); + return std::string("[{\"name\":\"L_Omega\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(nt) + ",\"element_type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(2) + ",\"cols\":" + std::to_string(2) + "}},\"block\":\"parameters\"},{\"name\":\"z1\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(NS) + "},\"block\":\"parameters\"}]"); } // get_constrained_sizedtypes() inline std::string get_unconstrained_sizedtypes() const { - return std::string("[{\"name\":\"alpha_v\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"cuts\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"X_p\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(n) + ",\"cols\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"beta_m\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(n) + ",\"cols\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"X_rv_p\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n) + "},\"block\":\"parameters\"}]"); + return std::string("[{\"name\":\"L_Omega\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(nt) + ",\"element_type\":{\"name\":\"vector\",\"length\":" + std::to_string(((2 * (2 - 1)) / 2)) + "}},\"block\":\"parameters\"},{\"name\":\"z1\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(NS) + "},\"block\":\"parameters\"}]"); } // get_unconstrained_sizedtypes() @@ -23460,7 +23508,7 @@ class optimize_glm_model final : public model_base_crtp { const bool emit_generated_quantities = true, std::ostream* pstream = nullptr) const { const size_t num_params__ = - ((((((((k + k) + k) + 1) + 1) + 1) + (n * k)) + (n * k)) + n); + (((nt * 2) * 2) + NS); const size_t num_transformed = 0; const size_t num_gen_quantities = 0; std::vector vars_vec(num_params__ @@ -23481,7 +23529,7 @@ class optimize_glm_model final : public model_base_crtp { bool emit_generated_quantities = true, std::ostream* pstream = nullptr) const { const size_t num_params__ = - ((((((((k + k) + k) + 1) + 1) + 1) + (n * k)) + (n * k)) + n); + (((nt * 2) * 2) + NS); const size_t num_transformed = 0; const size_t num_gen_quantities = 0; vars.resize(num_params__ @@ -23519,10 +23567,9 @@ class optimize_glm_model final : public model_base_crtp { std::vector& params_i, std::vector& vars, std::ostream* pstream__ = nullptr) const { - constexpr std::array names__{"alpha_v", "beta", "cuts", - "sigma", "alpha", "phi", "X_p", "beta_m", "X_rv_p"}; - const std::array constrain_param_sizes__{k, k, - k, 1, 1, 1, (n * k), (n * k), n}; + constexpr std::array names__{"L_Omega", "z1"}; + const std::array constrain_param_sizes__{(nt * 2 * 2), + NS}; const auto num_constrained_params__ = std::accumulate( constrain_param_sizes__.begin(), constrain_param_sizes__.end(), 0); @@ -23543,7 +23590,7 @@ class optimize_glm_model final : public model_base_crtp { }; } -using stan_model = optimize_glm_model_namespace::optimize_glm_model; +using stan_model = param_constraint_model_namespace::param_constraint_model; #ifndef USING_R @@ -23557,91 +23604,76 @@ stan::model::model_base& new_model( } stan::math::profile_map& get_stan_profile_data() { - return optimize_glm_model_namespace::profiles__; + return param_constraint_model_namespace::profiles__; } #endif - $ ../../../../../install/default/bin/stanc --print-cpp param-constraint.stan + $ ../../../../../install/default/bin/stanc --print-cpp print_unicode.stan // Code generated by %%NAME%% %%VERSION%% #include -namespace param_constraint_model_namespace { +namespace print_unicode_model_namespace { using stan::model::model_base_crtp; using namespace stan::math; stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = +static constexpr std::array locations_array__ = {" (found before start of program)", - " (in 'param-constraint.stan', line 6, column 2 to column 44)", - " (in 'param-constraint.stan', line 7, column 2 to column 40)", - " (in 'param-constraint.stan', line 2, column 2 to column 9)", - " (in 'param-constraint.stan', line 3, column 2 to column 9)", - " (in 'param-constraint.stan', line 6, column 8 to column 10)", - " (in 'param-constraint.stan', line 7, column 33 to column 35)"}; + " (in 'print_unicode.stan', line 2, column 2 to column 24)", + " (in 'print_unicode.stan', line 3, column 2 to column 23)"}; -class param_constraint_model final : public model_base_crtp { +class print_unicode_model final : public model_base_crtp { private: - int nt; - int NS; + public: - ~param_constraint_model() { } + ~print_unicode_model() { } - inline std::string model_name() const final { return "param_constraint_model"; } + inline std::string model_name() const final { return "print_unicode_model"; } inline std::vector model_compile_info() const noexcept { return std::vector{"stanc_version = %%NAME%%3 %%VERSION%%", "stancflags = --print-cpp"}; } - param_constraint_model(stan::io::var_context& context__, - unsigned int random_seed__ = 0, - std::ostream* pstream__ = nullptr) : model_base_crtp(0) { + print_unicode_model(stan::io::var_context& context__, + unsigned int random_seed__ = 0, + std::ostream* pstream__ = nullptr) : model_base_crtp(0) { int current_statement__ = 0; using local_scalar_t__ = double ; boost::ecuyer1988 base_rng__ = stan::services::util::create_rng(random_seed__, 0); (void) base_rng__; // suppress unused var warning - static constexpr const char* function__ = "param_constraint_model_namespace::param_constraint_model"; + static constexpr const char* function__ = "print_unicode_model_namespace::print_unicode_model"; (void) function__; // suppress unused var warning local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); (void) DUMMY_VAR__; // suppress unused var warning try { int pos__ = std::numeric_limits::min(); pos__ = 1; - current_statement__ = 3; - context__.validate_dims("data initialization","nt","int", - std::vector{}); - nt = std::numeric_limits::min(); - - - current_statement__ = 3; - nt = context__.vals_i("nt")[(1 - 1)]; - current_statement__ = 4; - context__.validate_dims("data initialization","NS","int", - std::vector{}); - NS = std::numeric_limits::min(); - - - current_statement__ = 4; - NS = context__.vals_i("NS")[(1 - 1)]; - current_statement__ = 5; - stan::math::validate_non_negative_index("L_Omega", "nt", nt); - current_statement__ = 6; - stan::math::validate_non_negative_index("z1", "NS", NS); + current_statement__ = 1; + if (pstream__) { + stan::math::stan_print(pstream__, "test: \320\211\360\237\230\203"); + stan::math::stan_print(pstream__, "\n"); + } + current_statement__ = 2; + if (pstream__) { + stan::math::stan_print(pstream__, "\316\273 \316\262 \316\266 \317\200"); + stan::math::stan_print(pstream__, "\n"); + } } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); } - num_params_r__ = (nt * ((2 * (2 - 1)) / 2)) + NS; + num_params_r__ = 0U; } @@ -23659,26 +23691,11 @@ class param_constraint_model final : public model_base_crtp::quiet_NaN()); (void) DUMMY_VAR__; // suppress unused var warning - static constexpr const char* function__ = "param_constraint_model_namespace::log_prob"; + static constexpr const char* function__ = "print_unicode_model_namespace::log_prob"; (void) function__; // suppress unused var warning try { - std::vector> L_Omega = - std::vector>(nt, - Eigen::Matrix::Constant(2, 2, - DUMMY_VAR__)); - current_statement__ = 1; - L_Omega = in__.template read_constrain_cholesky_factor_corr< - std::vector>, - jacobian__>(lp__, nt, 2); - Eigen::Matrix z1 = - Eigen::Matrix::Constant(NS, DUMMY_VAR__); - current_statement__ = 2; - z1 = in__.template read_constrain_lb< - Eigen::Matrix, jacobian__>( - stan::model::rvalue(L_Omega, "L_Omega", - stan::model::index_uni(1), stan::model::index_uni(1), - stan::model::index_uni(2)), lp__, NS); + } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); } @@ -23707,39 +23724,10 @@ class param_constraint_model final : public model_base_crtp::quiet_NaN()); constexpr bool jacobian__ = false; (void) DUMMY_VAR__; // suppress unused var warning - static constexpr const char* function__ = "param_constraint_model_namespace::write_array"; + static constexpr const char* function__ = "print_unicode_model_namespace::write_array"; (void) function__; // suppress unused var warning try { - std::vector> L_Omega = - std::vector>(nt, - Eigen::Matrix::Constant(2, 2, - std::numeric_limits::quiet_NaN())); - current_statement__ = 1; - L_Omega = in__.template read_constrain_cholesky_factor_corr< - std::vector>, - jacobian__>(lp__, nt, 2); - Eigen::Matrix z1 = - Eigen::Matrix::Constant(NS, - std::numeric_limits::quiet_NaN()); - current_statement__ = 2; - z1 = in__.template read_constrain_lb< - Eigen::Matrix, jacobian__>( - stan::model::rvalue(L_Omega, "L_Omega", - stan::model::index_uni(1), stan::model::index_uni(1), - stan::model::index_uni(2)), lp__, NS); - for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { - for (int sym2__ = 1; sym2__ <= 2; ++sym2__) { - for (int sym3__ = 1; sym3__ <= nt; ++sym3__) { - out__.write( - stan::model::rvalue(L_Omega, "L_Omega", - stan::model::index_uni(sym3__), - stan::model::index_uni(sym2__), - stan::model::index_uni(sym1__))); - } - } - } - out__.write(z1); if (stan::math::logical_negation((stan::math::primitive_value( emit_transformed_parameters__) || stan::math::primitive_value( emit_generated_quantities__)))) { @@ -23768,31 +23756,6 @@ class param_constraint_model final : public model_base_crtp::min(); pos__ = 1; - std::vector> L_Omega = - std::vector>(nt, - Eigen::Matrix::Constant(2, 2, - DUMMY_VAR__)); - for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { - for (int sym2__ = 1; sym2__ <= 2; ++sym2__) { - for (int sym3__ = 1; sym3__ <= nt; ++sym3__) { - stan::model::assign(L_Omega, in__.read(), - "assigning variable L_Omega", stan::model::index_uni(sym3__), - stan::model::index_uni(sym2__), - stan::model::index_uni(sym1__)); - } - } - } - out__.write_free_cholesky_factor_corr(L_Omega); - Eigen::Matrix z1 = - Eigen::Matrix::Constant(NS, DUMMY_VAR__); - for (int sym1__ = 1; sym1__ <= NS; ++sym1__) { - stan::model::assign(z1, in__.read(), - "assigning variable z1", stan::model::index_uni(sym1__)); - } - out__.write_free_lb( - stan::model::rvalue(L_Omega, "L_Omega", - stan::model::index_uni(1), stan::model::index_uni(1), - stan::model::index_uni(2)), z1); } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); } @@ -23800,20 +23763,13 @@ class param_constraint_model final : public model_base_crtp& names__) const { - names__ = std::vector{"L_Omega", "z1"}; + names__ = std::vector{}; } // get_param_names() inline void get_dims(std::vector>& dimss__) const { - dimss__ = std::vector>{std::vector{ - static_cast(nt) - , - static_cast(2) - , - static_cast(2) - }, - std::vector{static_cast(NS)}}; + dimss__ = std::vector>{}; } // get_dims() @@ -23823,24 +23779,7 @@ class param_constraint_model final : public model_base_crtp vars_vec(num_params__ @@ -23923,8 +23848,7 @@ class param_constraint_model final : public model_base_crtp& params_i, std::vector& vars, std::ostream* pstream__ = nullptr) const { - constexpr std::array names__{"L_Omega", "z1"}; - const std::array constrain_param_sizes__{(nt * 2 * 2), - NS}; + constexpr std::array names__{}; + const std::array constrain_param_sizes__{}; const auto num_constrained_params__ = std::accumulate( constrain_param_sizes__.begin(), constrain_param_sizes__.end(), 0); @@ -23985,7 +23908,7 @@ class param_constraint_model final : public model_base_crtp -namespace print_unicode_model_namespace { +namespace promotion_model_namespace { using stan::model::model_base_crtp; using namespace stan::math; stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = +static constexpr std::array locations_array__ = {" (found before start of program)", - " (in 'print_unicode.stan', line 2, column 2 to column 24)", - " (in 'print_unicode.stan', line 3, column 2 to column 23)"}; + " (in 'promotion.stan', line 12, column 3 to column 14)", + " (in 'promotion.stan', line 13, column 3 to column 25)", + " (in 'promotion.stan', line 14, column 3 to column 31)", + " (in 'promotion.stan', line 15, column 3 to column 20)", + " (in 'promotion.stan', line 3, column 5 to column 14)", + " (in 'promotion.stan', line 2, column 28 to line 4, column 4)", + " (in 'promotion.stan', line 7, column 5 to column 18)", + " (in 'promotion.stan', line 6, column 28 to line 8, column 4)"}; + + +template +std::complex> +ident(const std::complex& x, std::ostream* pstream__) { + using local_scalar_t__ = stan::promote_args_t; + int current_statement__ = 0; + static constexpr bool propto__ = true; + (void) propto__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + (void) DUMMY_VAR__; // suppress unused var warning + try { + current_statement__ = 5; + return x; + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + +} +struct ident_functor__ { +template +std::complex> +operator()(const std::complex& x, std::ostream* pstream__) const +{ +return ident(x, pstream__); +} +}; +template +stan::promote_args_t +foo(const std::vector& zs, std::ostream* pstream__) { + using local_scalar_t__ = stan::promote_args_t; + int current_statement__ = 0; + static constexpr bool propto__ = true; + (void) propto__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + (void) DUMMY_VAR__; // suppress unused var warning + try { + current_statement__ = 7; + return stan::model::rvalue(zs, "zs", stan::model::index_uni(0)); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + +} -class print_unicode_model final : public model_base_crtp { +struct foo_functor__ { +template +stan::promote_args_t +operator()(const std::vector& zs, std::ostream* pstream__) const +{ +return foo(zs, pstream__); +} +}; + +class promotion_model final : public model_base_crtp { private: public: - ~print_unicode_model() { } + ~promotion_model() { } - inline std::string model_name() const final { return "print_unicode_model"; } + inline std::string model_name() const final { return "promotion_model"; } inline std::vector model_compile_info() const noexcept { return std::vector{"stanc_version = %%NAME%%3 %%VERSION%%", "stancflags = --print-cpp"}; } - print_unicode_model(stan::io::var_context& context__, - unsigned int random_seed__ = 0, - std::ostream* pstream__ = nullptr) : model_base_crtp(0) { + promotion_model(stan::io::var_context& context__, + unsigned int random_seed__ = 0, + std::ostream* pstream__ = nullptr) : model_base_crtp(0) { int current_statement__ = 0; using local_scalar_t__ = double ; boost::ecuyer1988 base_rng__ = stan::services::util::create_rng(random_seed__, 0); (void) base_rng__; // suppress unused var warning - static constexpr const char* function__ = "print_unicode_model_namespace::print_unicode_model"; + static constexpr const char* function__ = "promotion_model_namespace::promotion_model"; (void) function__; // suppress unused var warning local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); (void) DUMMY_VAR__; // suppress unused var warning try { int pos__ = std::numeric_limits::min(); pos__ = 1; - current_statement__ = 1; - if (pstream__) { - stan::math::stan_print(pstream__, "test: \320\211\360\237\230\203"); - stan::math::stan_print(pstream__, "\n"); - } - current_statement__ = 2; - if (pstream__) { - stan::math::stan_print(pstream__, "\316\273 \316\262 \316\266 \317\200"); - stan::math::stan_print(pstream__, "\n"); - } } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); } @@ -24086,7 +24058,7 @@ class print_unicode_model final : public model_base_crtp { int current_statement__ = 0; local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); (void) DUMMY_VAR__; // suppress unused var warning - static constexpr const char* function__ = "print_unicode_model_namespace::log_prob"; + static constexpr const char* function__ = "promotion_model_namespace::log_prob"; (void) function__; // suppress unused var warning try { @@ -24119,7 +24091,7 @@ class print_unicode_model final : public model_base_crtp { local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); constexpr bool jacobian__ = false; (void) DUMMY_VAR__; // suppress unused var warning - static constexpr const char* function__ = "print_unicode_model_namespace::write_array"; + static constexpr const char* function__ = "promotion_model_namespace::write_array"; (void) function__; // suppress unused var warning try { @@ -24131,6 +24103,28 @@ class print_unicode_model final : public model_base_crtp { if (stan::math::logical_negation(emit_generated_quantities__)) { return ; } + double z = std::numeric_limits::quiet_NaN(); + current_statement__ = 1; + z = 1; + std::complex zi = + std::complex(std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN()); + current_statement__ = 2; + stan::model::assign(zi, + ident(stan::math::promote_scalar>(z), pstream__), + "assigning variable zi"); + std::vector zs = + std::vector(4, std::numeric_limits::min()); + current_statement__ = 3; + stan::model::assign(zs, std::vector{1, 2, 3, 4}, + "assigning variable zs"); + double x = std::numeric_limits::quiet_NaN(); + current_statement__ = 4; + x = foo(stan::math::promote_scalar(zs), pstream__); + out__.write(z); + out__.write(zi); + out__.write(zs); + out__.write(x); } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); } @@ -24158,13 +24152,16 @@ class print_unicode_model final : public model_base_crtp { inline void get_param_names(std::vector& names__) const { - names__ = std::vector{}; + names__ = std::vector{"z", "zi", "zs", "x"}; } // get_param_names() inline void get_dims(std::vector>& dimss__) const { - dimss__ = std::vector>{}; + dimss__ = std::vector>{std::vector{}, + std::vector{static_cast(2)}, + std::vector{static_cast(4)}, std::vector{ + }}; } // get_dims() @@ -24180,7 +24177,15 @@ class print_unicode_model final : public model_base_crtp { } if (emit_generated_quantities__) { - + param_names__.emplace_back(std::string() + "z"); + param_names__.emplace_back(std::string() + "zi" + '.' + "real"); + param_names__.emplace_back(std::string() + "zi" + '.' + "imag"); + for (int sym1__ = 1; sym1__ <= 4; ++sym1__) { + { + param_names__.emplace_back(std::string() + "zs" + '.' + std::to_string(sym1__)); + } + } + param_names__.emplace_back(std::string() + "x"); } } // constrained_param_names() @@ -24197,20 +24202,28 @@ class print_unicode_model final : public model_base_crtp { } if (emit_generated_quantities__) { - + param_names__.emplace_back(std::string() + "z"); + param_names__.emplace_back(std::string() + "zi" + '.' + "real"); + param_names__.emplace_back(std::string() + "zi" + '.' + "imag"); + for (int sym1__ = 1; sym1__ <= 4; ++sym1__) { + { + param_names__.emplace_back(std::string() + "zs" + '.' + std::to_string(sym1__)); + } + } + param_names__.emplace_back(std::string() + "x"); } } // unconstrained_param_names() inline std::string get_constrained_sizedtypes() const { - return std::string("[]"); + return std::string("[{\"name\":\"z\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"zi\",\"type\":{\"name\":\"complex\"},\"block\":\"generated_quantities\"},{\"name\":\"zs\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(4) + ",\"element_type\":{\"name\":\"int\"}},\"block\":\"generated_quantities\"},{\"name\":\"x\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); } // get_constrained_sizedtypes() inline std::string get_unconstrained_sizedtypes() const { - return std::string("[]"); + return std::string("[{\"name\":\"z\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"zi\",\"type\":{\"name\":\"complex\"},\"block\":\"generated_quantities\"},{\"name\":\"zs\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(4) + ",\"element_type\":{\"name\":\"int\"}},\"block\":\"generated_quantities\"},{\"name\":\"x\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); } // get_unconstrained_sizedtypes() @@ -24225,7 +24238,8 @@ class print_unicode_model final : public model_base_crtp { std::ostream* pstream = nullptr) const { const size_t num_params__ = 0; const size_t num_transformed = 0; - const size_t num_gen_quantities = 0; + const size_t num_gen_quantities = + (((1 + 2) + 4) + 1); std::vector vars_vec(num_params__ + (emit_transformed_parameters * num_transformed) + (emit_generated_quantities * num_gen_quantities)); @@ -24245,7 +24259,8 @@ class print_unicode_model final : public model_base_crtp { std::ostream* pstream = nullptr) const { const size_t num_params__ = 0; const size_t num_transformed = 0; - const size_t num_gen_quantities = 0; + const size_t num_gen_quantities = + (((1 + 2) + 4) + 1); vars.resize(num_params__ + (emit_transformed_parameters * num_transformed) + (emit_generated_quantities * num_gen_quantities)); @@ -24303,7 +24318,7 @@ class print_unicode_model final : public model_base_crtp { }; } -using stan_model = print_unicode_model_namespace::print_unicode_model; +using stan_model = promotion_model_namespace::promotion_model; #ifndef USING_R @@ -24317,7 +24332,7 @@ stan::model::model_base& new_model( } stan::math::profile_map& get_stan_profile_data() { - return print_unicode_model_namespace::profiles__; + return promotion_model_namespace::profiles__; } #endif diff --git a/test/integration/good/code-gen/expressions/cpp.expected b/test/integration/good/code-gen/expressions/cpp.expected index f2fcba0d8c..a4c2652bb8 100644 --- a/test/integration/good/code-gen/expressions/cpp.expected +++ b/test/integration/good/code-gen/expressions/cpp.expected @@ -500,3 +500,504 @@ stan::math::profile_map& get_stan_profile_data() { + $ ../../../../../../install/default/bin/stanc --print-cpp ternary_if.stan + +// Code generated by %%NAME%% %%VERSION%% +#include +namespace ternary_if_model_namespace { + +using stan::model::model_base_crtp; +using namespace stan::math; + + +stan::math::profile_map profiles__; +static constexpr std::array locations_array__ = +{" (found before start of program)", + " (in 'ternary_if.stan', line 5, column 2 to column 14)", + " (in 'ternary_if.stan', line 6, column 2 to column 14)", + " (in 'ternary_if.stan', line 7, column 2 to column 9)", + " (in 'ternary_if.stan', line 8, column 2 to column 13)", + " (in 'ternary_if.stan', line 11, column 2 to column 73)", + " (in 'ternary_if.stan', line 12, column 2 to column 41)", + " (in 'ternary_if.stan', line 14, column 2 to column 25)", + " (in 'ternary_if.stan', line 17, column 4 to column 27)", + " (in 'ternary_if.stan', line 18, column 4 to column 20)", + " (in 'ternary_if.stan', line 2, column 2 to column 9)"}; + + + +class ternary_if_model final : public model_base_crtp { + + private: + double y; + + + public: + ~ternary_if_model() { } + + inline std::string model_name() const final { return "ternary_if_model"; } + + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = %%NAME%%3 %%VERSION%%", "stancflags = --print-cpp"}; + } + + + ternary_if_model(stan::io::var_context& context__, + unsigned int random_seed__ = 0, + std::ostream* pstream__ = nullptr) : model_base_crtp(0) { + int current_statement__ = 0; + using local_scalar_t__ = double ; + boost::ecuyer1988 base_rng__ = + stan::services::util::create_rng(random_seed__, 0); + (void) base_rng__; // suppress unused var warning + static constexpr const char* function__ = "ternary_if_model_namespace::ternary_if_model"; + (void) function__; // suppress unused var warning + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + (void) DUMMY_VAR__; // suppress unused var warning + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + current_statement__ = 10; + context__.validate_dims("data initialization","y","double", + std::vector{}); + y = std::numeric_limits::quiet_NaN(); + + + current_statement__ = 10; + y = context__.vals_r("y")[(1 - 1)]; + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + num_params_r__ = 2 + 2 + 1 + 2; + + } + + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t log_prob_impl(VecR& params_r__, + VecI& params_i__, + std::ostream* pstream__ = nullptr) const { + using T__ = stan::scalar_type_t; + using local_scalar_t__ = T__; + T__ lp__(0.0); + stan::math::accumulator lp_accum__; + stan::io::deserializer in__(params_r__, params_i__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + (void) DUMMY_VAR__; // suppress unused var warning + static constexpr const char* function__ = "ternary_if_model_namespace::log_prob"; + (void) function__; // suppress unused var warning + + try { + Eigen::Matrix a = + Eigen::Matrix::Constant(2, DUMMY_VAR__); + current_statement__ = 1; + a = in__.template read>(2); + Eigen::Matrix b = + Eigen::Matrix::Constant(2, DUMMY_VAR__); + current_statement__ = 2; + b = in__.template read>(2); + local_scalar_t__ r = DUMMY_VAR__; + current_statement__ = 3; + r = in__.template read(); + std::complex zp = + std::complex(DUMMY_VAR__, DUMMY_VAR__); + current_statement__ = 4; + zp = in__.template read>(); + Eigen::Matrix c = + Eigen::Matrix::Constant(2, DUMMY_VAR__); + current_statement__ = 5; + stan::model::assign(c, + (stan::math::logical_gt(stan::math::sum(a), 1) ? + stan::math::eval(stan::math::add(stan::math::multiply(2.0, a), b)) + : stan::math::eval(stan::math::multiply(2.0, a))), + "assigning variable c"); + Eigen::Matrix d = + Eigen::Matrix::Constant(2, DUMMY_VAR__); + current_statement__ = 6; + stan::model::assign(d, + (stan::math::logical_gt(stan::math::sum(a), 1) ? + stan::math::eval(stan::math::add(stan::math::multiply(2, a), b)) : + stan::math::eval(stan::math::multiply(2, a))), + "assigning variable d"); + std::complex z = + std::complex(DUMMY_VAR__, DUMMY_VAR__); + current_statement__ = 7; + stan::model::assign(z, + (1 ? stan::math::to_complex(0, 3) : + stan::math::promote_scalar>(2)), + "assigning variable z"); + { + std::complex z2 = + std::complex(DUMMY_VAR__, DUMMY_VAR__); + current_statement__ = 8; + z2 = (1 ? r : 2); + current_statement__ = 9; + stan::model::assign(z2, + (1 ? stan::math::promote_scalar>(0) + : zp), "assigning variable z2"); + } + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + lp_accum__.add(lp__); + return lp_accum__.sum(); + } // log_prob_impl() + + template * = nullptr, + stan::require_vector_like_vt* = nullptr, + stan::require_std_vector_vt* = nullptr> + inline void write_array_impl(RNG& base_rng__, VecR& params_r__, + VecI& params_i__, VecVar& vars__, + const bool emit_transformed_parameters__ = true, + const bool emit_generated_quantities__ = true, + std::ostream* pstream__ = nullptr) const { + using local_scalar_t__ = double; + stan::io::deserializer in__(params_r__, params_i__); + stan::io::serializer out__(vars__); + static constexpr bool propto__ = true; + (void) propto__; + double lp__ = 0.0; + (void) lp__; // dummy to suppress unused var warning + int current_statement__ = 0; + stan::math::accumulator lp_accum__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + constexpr bool jacobian__ = false; + (void) DUMMY_VAR__; // suppress unused var warning + static constexpr const char* function__ = "ternary_if_model_namespace::write_array"; + (void) function__; // suppress unused var warning + + try { + Eigen::Matrix a = + Eigen::Matrix::Constant(2, + std::numeric_limits::quiet_NaN()); + current_statement__ = 1; + a = in__.template read>(2); + Eigen::Matrix b = + Eigen::Matrix::Constant(2, + std::numeric_limits::quiet_NaN()); + current_statement__ = 2; + b = in__.template read>(2); + double r = std::numeric_limits::quiet_NaN(); + current_statement__ = 3; + r = in__.template read(); + std::complex zp = + std::complex(std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN()); + current_statement__ = 4; + zp = in__.template read>(); + Eigen::Matrix c = + Eigen::Matrix::Constant(2, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix d = + Eigen::Matrix::Constant(2, + std::numeric_limits::quiet_NaN()); + std::complex z = + std::complex(std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN()); + out__.write(a); + out__.write(b); + out__.write(r); + out__.write(zp); + if (stan::math::logical_negation((stan::math::primitive_value( + emit_transformed_parameters__) || stan::math::primitive_value( + emit_generated_quantities__)))) { + return ; + } + current_statement__ = 5; + stan::model::assign(c, + (stan::math::logical_gt(stan::math::sum(a), 1) ? + stan::math::eval(stan::math::add(stan::math::multiply(2.0, a), b)) + : stan::math::eval(stan::math::multiply(2.0, a))), + "assigning variable c"); + current_statement__ = 6; + stan::model::assign(d, + (stan::math::logical_gt(stan::math::sum(a), 1) ? + stan::math::eval(stan::math::add(stan::math::multiply(2, a), b)) : + stan::math::eval(stan::math::multiply(2, a))), + "assigning variable d"); + current_statement__ = 7; + stan::model::assign(z, + (1 ? stan::math::to_complex(0, 3) : + stan::math::promote_scalar>(2)), + "assigning variable z"); + if (emit_transformed_parameters__) { + out__.write(c); + out__.write(d); + out__.write(z); + } + if (stan::math::logical_negation(emit_generated_quantities__)) { + return ; + } + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } // write_array_impl() + + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline void transform_inits_impl(VecVar& params_r__, VecI& params_i__, + VecVar& vars__, + std::ostream* pstream__ = nullptr) const { + using local_scalar_t__ = double; + stan::io::deserializer in__(params_r__, params_i__); + stan::io::serializer out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + Eigen::Matrix a = + Eigen::Matrix::Constant(2, DUMMY_VAR__); + for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { + stan::model::assign(a, in__.read(), + "assigning variable a", stan::model::index_uni(sym1__)); + } + out__.write(a); + Eigen::Matrix b = + Eigen::Matrix::Constant(2, DUMMY_VAR__); + for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { + stan::model::assign(b, in__.read(), + "assigning variable b", stan::model::index_uni(sym1__)); + } + out__.write(b); + local_scalar_t__ r = DUMMY_VAR__; + r = in__.read(); + out__.write(r); + std::complex zp = + std::complex(DUMMY_VAR__, DUMMY_VAR__); + stan::model::assign(zp, in__.read(), + "assigning variable zp"); + out__.write(zp); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } // transform_inits_impl() + + inline void get_param_names(std::vector& names__) const { + + names__ = std::vector{"a", "b", "r", "zp", "c", "d", "z"}; + + } // get_param_names() + + inline void get_dims(std::vector>& dimss__) const { + + dimss__ = std::vector>{std::vector{ + static_cast(2) + }, + std::vector{static_cast(2)}, std::vector{ + }, std::vector{static_cast(2)}, + std::vector{static_cast(2)}, + std::vector{static_cast(2)}, + std::vector{static_cast(2)}}; + + } // get_dims() + + inline void constrained_param_names( + std::vector& param_names__, + bool emit_transformed_parameters__ = true, + bool emit_generated_quantities__ = true) const + final { + + for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { + { + param_names__.emplace_back(std::string() + "a" + '.' + std::to_string(sym1__)); + } + } + for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { + { + param_names__.emplace_back(std::string() + "b" + '.' + std::to_string(sym1__)); + } + } + param_names__.emplace_back(std::string() + "r"); + param_names__.emplace_back(std::string() + "zp" + '.' + "real"); + param_names__.emplace_back(std::string() + "zp" + '.' + "imag"); + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { + { + param_names__.emplace_back(std::string() + "c" + '.' + std::to_string(sym1__)); + } + } + for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { + { + param_names__.emplace_back(std::string() + "d" + '.' + std::to_string(sym1__)); + } + } + param_names__.emplace_back(std::string() + "z" + '.' + "real"); + param_names__.emplace_back(std::string() + "z" + '.' + "imag"); + } + + if (emit_generated_quantities__) { + + } + + } // constrained_param_names() + + inline void unconstrained_param_names( + std::vector& param_names__, + bool emit_transformed_parameters__ = true, + bool emit_generated_quantities__ = true) const + final { + + for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { + { + param_names__.emplace_back(std::string() + "a" + '.' + std::to_string(sym1__)); + } + } + for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { + { + param_names__.emplace_back(std::string() + "b" + '.' + std::to_string(sym1__)); + } + } + param_names__.emplace_back(std::string() + "r"); + param_names__.emplace_back(std::string() + "zp" + '.' + "real"); + param_names__.emplace_back(std::string() + "zp" + '.' + "imag"); + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { + { + param_names__.emplace_back(std::string() + "c" + '.' + std::to_string(sym1__)); + } + } + for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { + { + param_names__.emplace_back(std::string() + "d" + '.' + std::to_string(sym1__)); + } + } + param_names__.emplace_back(std::string() + "z" + '.' + "real"); + param_names__.emplace_back(std::string() + "z" + '.' + "imag"); + } + + if (emit_generated_quantities__) { + + } + + } // unconstrained_param_names() + + inline std::string get_constrained_sizedtypes() const { + + return std::string("[{\"name\":\"a\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(2) + "},\"block\":\"parameters\"},{\"name\":\"b\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(2) + "},\"block\":\"parameters\"},{\"name\":\"r\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"zp\",\"type\":{\"name\":\"complex\"},\"block\":\"parameters\"},{\"name\":\"c\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(2) + "},\"block\":\"transformed_parameters\"},{\"name\":\"d\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(2) + "},\"block\":\"transformed_parameters\"},{\"name\":\"z\",\"type\":{\"name\":\"complex\"},\"block\":\"transformed_parameters\"}]"); + + } // get_constrained_sizedtypes() + + inline std::string get_unconstrained_sizedtypes() const { + + return std::string("[{\"name\":\"a\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(2) + "},\"block\":\"parameters\"},{\"name\":\"b\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(2) + "},\"block\":\"parameters\"},{\"name\":\"r\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"zp\",\"type\":{\"name\":\"complex\"},\"block\":\"parameters\"},{\"name\":\"c\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(2) + "},\"block\":\"transformed_parameters\"},{\"name\":\"d\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(2) + "},\"block\":\"transformed_parameters\"},{\"name\":\"z\",\"type\":{\"name\":\"complex\"},\"block\":\"transformed_parameters\"}]"); + + } // get_unconstrained_sizedtypes() + + + // Begin method overload boilerplate + template + inline void write_array(RNG& base_rng, + Eigen::Matrix& params_r, + Eigen::Matrix& vars, + const bool emit_transformed_parameters = true, + const bool emit_generated_quantities = true, + std::ostream* pstream = nullptr) const { + const size_t num_params__ = + (((2 + 2) + 1) + 2); + const size_t num_transformed = ((2 + 2) + 2); + const size_t num_gen_quantities = 0; + std::vector vars_vec(num_params__ + + (emit_transformed_parameters * num_transformed) + + (emit_generated_quantities * num_gen_quantities)); + std::vector params_i; + write_array_impl(base_rng, params_r, params_i, vars_vec, + emit_transformed_parameters, emit_generated_quantities, pstream); + vars = Eigen::Map>( + vars_vec.data(), vars_vec.size()); + } + + template + inline void write_array(RNG& base_rng, std::vector& params_r, + std::vector& params_i, + std::vector& vars, + bool emit_transformed_parameters = true, + bool emit_generated_quantities = true, + std::ostream* pstream = nullptr) const { + const size_t num_params__ = + (((2 + 2) + 1) + 2); + const size_t num_transformed = ((2 + 2) + 2); + const size_t num_gen_quantities = 0; + vars.resize(num_params__ + + (emit_transformed_parameters * num_transformed) + + (emit_generated_quantities * num_gen_quantities)); + write_array_impl(base_rng, params_r, params_i, vars, emit_transformed_parameters, emit_generated_quantities, pstream); + } + + template + inline T_ log_prob(Eigen::Matrix& params_r, + std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + + template + inline T__ log_prob(std::vector& params_r, + std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + + + inline void transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, + std::ostream* pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits(context, params_i, params_r_vec, pstream); + params_r = Eigen::Map>( + params_r_vec.data(), params_r_vec.size()); + } + + inline void transform_inits(const stan::io::var_context& context, + std::vector& params_i, + std::vector& vars, + std::ostream* pstream__ = nullptr) const { + constexpr std::array names__{"a", "b", "r", "zp"}; + const std::array constrain_param_sizes__{2, 2, 1, 2}; + const auto num_constrained_params__ = std::accumulate( + constrain_param_sizes__.begin(), constrain_param_sizes__.end(), 0); + + std::vector params_r_flat__(num_constrained_params__); + Eigen::Index size_iter__ = 0; + Eigen::Index flat_iter__ = 0; + for (auto&& param_name__ : names__) { + const auto param_vec__ = context.vals_r(param_name__); + for (Eigen::Index i = 0; i < constrain_param_sizes__[size_iter__]; ++i) { + params_r_flat__[flat_iter__] = param_vec__[i]; + ++flat_iter__; + } + ++size_iter__; + } + vars.resize(num_params_r__); + transform_inits_impl(params_r_flat__, params_i, vars, pstream__); + } // transform_inits() + +}; +} +using stan_model = ternary_if_model_namespace::ternary_if_model; + +#ifndef USING_R + +// Boilerplate +stan::model::model_base& new_model( + stan::io::var_context& data_context, + unsigned int seed, + std::ostream* msg_stream) { + stan_model* m = new stan_model(data_context, seed, msg_stream); + return *m; +} + +stan::math::profile_map& get_stan_profile_data() { + return ternary_if_model_namespace::profiles__; +} + +#endif + + + diff --git a/test/integration/good/code-gen/expressions/ternary_if.stan b/test/integration/good/code-gen/expressions/ternary_if.stan new file mode 100644 index 0000000000..2cccf08c67 --- /dev/null +++ b/test/integration/good/code-gen/expressions/ternary_if.stan @@ -0,0 +1,19 @@ +data { + real y; +} +parameters { + vector[2] a; + vector[2] b; + real r; + complex zp; +} +transformed parameters { + vector[2] c = sum(a) > 1 ? add(multiply(2.0, a), b) : multiply(2.0, a); + vector[2] d = sum(a) > 1 ? 2*a+b : 2*a; + + complex z = 1 ? 3i : 2; +} +model { + complex z2 = 1 ? r : 2; + z2 = 1 ? 0 : zp; +} diff --git a/test/integration/good/code-gen/mir.expected b/test/integration/good/code-gen/mir.expected index 22281a5f2b..735716c9d5 100644 --- a/test/integration/good/code-gen/mir.expected +++ b/test/integration/good/code-gen/mir.expected @@ -251,10 +251,18 @@ (((pattern (Var u)) (meta ((type_ UReal) (loc ) (adlevel AutoDiffable)))) - ((pattern (Lit Int 0)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) - ((pattern (Lit Int 1)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly))))))) + ((pattern + (Promotion + ((pattern (Lit Int 0)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) + ((pattern + (Promotion + ((pattern (Lit Int 1)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly))))))) (meta ((type_ UReal) (loc ) (adlevel AutoDiffable)))))) (meta )) ((pattern @@ -4450,8 +4458,12 @@ (FunApp (StanLib diag_matrix FnPlain AoS) (((pattern (FunApp (StanLib rep_vector FnPlain AoS) - (((pattern (Lit Int 1)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + (((pattern + (Promotion + ((pattern (Lit Int 1)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) ((pattern (FunApp (StanLib rows FnPlain AoS) (((pattern (Var td_cfcov_54)) @@ -4466,8 +4478,12 @@ (FunApp (StanLib diag_matrix FnPlain AoS) (((pattern (FunApp (StanLib rep_vector FnPlain AoS) - (((pattern (Lit Int 1)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + (((pattern + (Promotion + ((pattern (Lit Int 1)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) ((pattern (FunApp (StanLib rows FnPlain AoS) (((pattern (Var td_cfcov_33)) @@ -8092,8 +8108,12 @@ (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) ((pattern (Lit Real 0.01)) (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) - ((pattern (Lit Int 10)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly))))))) + ((pattern + (Promotion + ((pattern (Lit Int 10)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly))))))) (meta ((type_ UVector) (loc ) (adlevel AutoDiffable)))))) (meta )) ((pattern @@ -8120,8 +8140,12 @@ (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) ((pattern (Lit Real 0.01)) (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) - ((pattern (Lit Int 10)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly))))))) + ((pattern + (Promotion + ((pattern (Lit Int 10)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly))))))) (meta ((type_ UVector) (loc ) (adlevel AutoDiffable)))))) (meta )) ((pattern @@ -8170,8 +8194,12 @@ (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) ((pattern (Lit Real 0.01)) (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) - ((pattern (Lit Int 10)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly))))))) + ((pattern + (Promotion + ((pattern (Lit Int 10)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly))))))) (meta ((type_ UVector) (loc ) (adlevel AutoDiffable)))))) (meta )) ((pattern @@ -8220,8 +8248,12 @@ (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) ((pattern (Lit Real 0.01)) (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) - ((pattern (Lit Int 10)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly))))))) + ((pattern + (Promotion + ((pattern (Lit Int 10)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly))))))) (meta ((type_ UVector) (loc ) (adlevel AutoDiffable)))))) (meta )) ((pattern @@ -9927,8 +9959,12 @@ (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) ((pattern (Lit Real 0.01)) (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) - ((pattern (Lit Int 10)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly))))))) + ((pattern + (Promotion + ((pattern (Lit Int 10)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly))))))) (meta ((type_ UVector) (loc ) (adlevel AutoDiffable)))))) (meta )) ((pattern @@ -9955,8 +9991,12 @@ (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) ((pattern (Lit Real 0.01)) (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) - ((pattern (Lit Int 10)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly))))))) + ((pattern + (Promotion + ((pattern (Lit Int 10)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly))))))) (meta ((type_ UVector) (loc ) (adlevel AutoDiffable)))))) (meta )) ((pattern @@ -10005,8 +10045,12 @@ (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) ((pattern (Lit Real 0.01)) (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) - ((pattern (Lit Int 10)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly))))))) + ((pattern + (Promotion + ((pattern (Lit Int 10)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly))))))) (meta ((type_ UVector) (loc ) (adlevel AutoDiffable)))))) (meta )) ((pattern @@ -10055,8 +10099,12 @@ (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) ((pattern (Lit Real 0.01)) (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) - ((pattern (Lit Int 10)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly))))))) + ((pattern + (Promotion + ((pattern (Lit Int 10)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly))))))) (meta ((type_ UVector) (loc ) (adlevel AutoDiffable)))))) (meta )) ((pattern diff --git a/test/integration/good/code-gen/profiling/transformed_mir.expected b/test/integration/good/code-gen/profiling/transformed_mir.expected index 3a3a96917a..06069d7312 100644 --- a/test/integration/good/code-gen/profiling/transformed_mir.expected +++ b/test/integration/good/code-gen/profiling/transformed_mir.expected @@ -406,9 +406,15 @@ ((type_ UVector) (loc ) (adlevel DataOnly)))) ((pattern (FunApp (StanLib rep_vector FnPlain AoS) - (((pattern (Lit Int 0)) + (((pattern + (Promotion + ((pattern (Lit Int 0)) + (meta + ((type_ UInt) (loc ) + (adlevel DataOnly)))) + UReal DataOnly)) (meta - ((type_ UInt) (loc ) (adlevel DataOnly)))) + ((type_ UReal) (loc ) (adlevel DataOnly)))) ((pattern (Var N)) (meta ((type_ UInt) (loc ) (adlevel DataOnly))))))) diff --git a/test/integration/good/code-gen/promotion.stan b/test/integration/good/code-gen/promotion.stan new file mode 100644 index 0000000000..e846b78652 --- /dev/null +++ b/test/integration/good/code-gen/promotion.stan @@ -0,0 +1,16 @@ +functions { + complex ident (complex x){ + return x; + } + + real foo(array[] real zs){ + return zs[0]; + } +} + +generated quantities { + real z = 1; + complex zi = ident(z); + array[4] int zs = {1,2,3,4}; + real x = foo(zs); +} diff --git a/test/integration/good/code-gen/transformed_mir.expected b/test/integration/good/code-gen/transformed_mir.expected index 11d5b52109..d3505b9f4a 100644 --- a/test/integration/good/code-gen/transformed_mir.expected +++ b/test/integration/good/code-gen/transformed_mir.expected @@ -254,10 +254,18 @@ (((pattern (Var u)) (meta ((type_ UReal) (loc ) (adlevel AutoDiffable)))) - ((pattern (Lit Int 0)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) - ((pattern (Lit Int 1)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly))))))) + ((pattern + (Promotion + ((pattern (Lit Int 0)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) + ((pattern + (Promotion + ((pattern (Lit Int 1)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly))))))) (meta ((type_ UReal) (loc ) (adlevel AutoDiffable)))))) (meta )) ((pattern @@ -7857,8 +7865,12 @@ (FunApp (StanLib diag_matrix FnPlain AoS) (((pattern (FunApp (StanLib rep_vector FnPlain AoS) - (((pattern (Lit Int 1)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + (((pattern + (Promotion + ((pattern (Lit Int 1)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) ((pattern (FunApp (StanLib rows FnPlain AoS) (((pattern (Var td_cfcov_54)) @@ -7873,8 +7885,12 @@ (FunApp (StanLib diag_matrix FnPlain AoS) (((pattern (FunApp (StanLib rep_vector FnPlain AoS) - (((pattern (Lit Int 1)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + (((pattern + (Promotion + ((pattern (Lit Int 1)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) ((pattern (FunApp (StanLib rows FnPlain AoS) (((pattern (Var td_cfcov_33)) @@ -11899,8 +11915,12 @@ (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) ((pattern (Lit Real 0.01)) (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) - ((pattern (Lit Int 10)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly))))))) + ((pattern + (Promotion + ((pattern (Lit Int 10)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly))))))) (meta ((type_ UVector) (loc ) (adlevel AutoDiffable)))))) (meta )) ((pattern @@ -11927,8 +11947,12 @@ (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) ((pattern (Lit Real 0.01)) (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) - ((pattern (Lit Int 10)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly))))))) + ((pattern + (Promotion + ((pattern (Lit Int 10)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly))))))) (meta ((type_ UVector) (loc ) (adlevel AutoDiffable)))))) (meta )) ((pattern @@ -11977,8 +12001,12 @@ (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) ((pattern (Lit Real 0.01)) (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) - ((pattern (Lit Int 10)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly))))))) + ((pattern + (Promotion + ((pattern (Lit Int 10)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly))))))) (meta ((type_ UVector) (loc ) (adlevel AutoDiffable)))))) (meta )) ((pattern @@ -12027,8 +12055,12 @@ (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) ((pattern (Lit Real 0.01)) (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) - ((pattern (Lit Int 10)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly))))))) + ((pattern + (Promotion + ((pattern (Lit Int 10)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly))))))) (meta ((type_ UVector) (loc ) (adlevel AutoDiffable)))))) (meta )) ((pattern @@ -15176,8 +15208,12 @@ (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) ((pattern (Lit Real 0.01)) (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) - ((pattern (Lit Int 10)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly))))))) + ((pattern + (Promotion + ((pattern (Lit Int 10)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly))))))) (meta ((type_ UVector) (loc ) (adlevel AutoDiffable)))))) (meta )) ((pattern @@ -15204,8 +15240,12 @@ (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) ((pattern (Lit Real 0.01)) (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) - ((pattern (Lit Int 10)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly))))))) + ((pattern + (Promotion + ((pattern (Lit Int 10)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly))))))) (meta ((type_ UVector) (loc ) (adlevel AutoDiffable)))))) (meta )) ((pattern @@ -15254,8 +15294,12 @@ (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) ((pattern (Lit Real 0.01)) (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) - ((pattern (Lit Int 10)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly))))))) + ((pattern + (Promotion + ((pattern (Lit Int 10)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly))))))) (meta ((type_ UVector) (loc ) (adlevel AutoDiffable)))))) (meta )) ((pattern @@ -15304,8 +15348,12 @@ (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) ((pattern (Lit Real 0.01)) (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) - ((pattern (Lit Int 10)) - (meta ((type_ UInt) (loc ) (adlevel DataOnly))))))) + ((pattern + (Promotion + ((pattern (Lit Int 10)) + (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) + UReal DataOnly)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly))))))) (meta ((type_ UVector) (loc ) (adlevel AutoDiffable)))))) (meta )) ((pattern diff --git a/test/integration/good/compiler-optimizations/cpp.expected b/test/integration/good/compiler-optimizations/cpp.expected index fa6a977c0c..255faaa59d 100644 --- a/test/integration/good/compiler-optimizations/cpp.expected +++ b/test/integration/good/compiler-optimizations/cpp.expected @@ -25392,6 +25392,8 @@ static constexpr std::array locations_array__ = " (in 'optimizations.stan', line 23, column 4 to column 23)", " (in 'optimizations.stan', line 24, column 4 to column 24)", " (in 'optimizations.stan', line 27, column 4 to column 11)", + " (in 'optimizations.stan', line 4, column 10 to column 17)", + " (in 'optimizations.stan', line 3, column 8 to line 4, column 17)", " (in 'optimizations.stan', line 5, column 8 to column 20)", " (in 'optimizations.stan', line 2, column 33 to line 6, column 5)", " (in 'optimizations.stan', line 9, column 8 to line 10, column 26)", @@ -25473,8 +25475,6 @@ static constexpr std::array locations_array__ = " (in 'optimizations.stan', line 146, column 6 to column 28)", " (in 'optimizations.stan', line 145, column 4 to line 146, column 28)", " (in 'optimizations.stan', line 147, column 4 to column 23)", - " (in 'optimizations.stan', line 4, column 10 to column 17)", - " (in 'optimizations.stan', line 3, column 8 to line 4, column 17)", " (in 'optimizations.stan', line 10, column 12 to column 26)", " (in 'optimizations.stan', line 11, column 8 to column 21)", " (in 'optimizations.stan', line 16, column 8 to column 18)"}; @@ -25492,12 +25492,12 @@ nrfun_lp(const T0__& x, const int& y, T_lp__& lp__, T_lp_accum__& lp_accum__, try { int lcm_sym35__; { - current_statement__ = 89; + current_statement__ = 8; if (stan::math::logical_gt(x, 342)) { - current_statement__ = 88; + current_statement__ = 7; return ; } - current_statement__ = 7; + current_statement__ = 9; lp_accum__.add(y); } } catch (const std::exception& e) { @@ -25530,7 +25530,7 @@ rfun(const int& y, std::ostream* pstream__) { int lcm_sym37__; int lcm_sym36__; { - current_statement__ = 9; + current_statement__ = 11; if (stan::math::logical_gt(y, 2)) { current_statement__ = 90; return (y + 24); @@ -25561,7 +25561,7 @@ rfun_lp(T_lp__& lp__, T_lp_accum__& lp_accum__, std::ostream* pstream__) { (void) DUMMY_VAR__; // suppress unused var warning try { { - current_statement__ = 59; + current_statement__ = 61; lp_accum__.add(2); current_statement__ = 92; return 24; @@ -25637,7 +25637,9 @@ class optimizations_model final : public model_base_crtp { (void) function__; // suppress unused var warning try { - double lcm_sym54__; + double lcm_sym56__; + int lcm_sym55__; + int lcm_sym54__; int lcm_sym53__; int lcm_sym52__; int lcm_sym51__; @@ -25680,7 +25682,11 @@ class optimizations_model final : public model_base_crtp { double x = std::numeric_limits::quiet_NaN(); int inline_sym1__ = std::numeric_limits::min(); for (int inline_sym2__ = 1; inline_sym2__ <= 1; ++inline_sym2__) { - current_statement__ = 7; + current_statement__ = 8; + if (stan::math::logical_gt(4, 342)) { + break; + } + current_statement__ = 9; lp_accum__.add(3); } int inline_sym3__; @@ -25708,7 +25714,7 @@ class optimizations_model final : public model_base_crtp { break; } if (inline_sym6__) { - current_statement__ = 11; + current_statement__ = 13; if (pstream__) { stan::math::stan_print(pstream__, "a"); stan::math::stan_print(pstream__, "\n"); @@ -25751,23 +25757,27 @@ class optimizations_model final : public model_base_crtp { int inline_sym18__ = std::numeric_limits::min(); for (int inline_sym19__ = 1; inline_sym19__ <= 1; ++inline_sym19__) { - current_statement__ = 7; + current_statement__ = 8; + if (stan::math::logical_gt(34, 342)) { + break; + } + current_statement__ = 9; lp_accum__.add(3); } } int inline_sym13__ = std::numeric_limits::min(); - lcm_sym50__ = (inline_sym9__ + 1); + lcm_sym52__ = (inline_sym9__ + 1); for (int inline_sym14__ = 1; inline_sym14__ <= 1; ++inline_sym14__) { { inline_sym12__ = 29; - lcm_sym50__ = (inline_sym9__ + 1); + lcm_sym52__ = (inline_sym9__ + 1); break; } inline_sym12__ = 7; - lcm_sym50__ = (inline_sym9__ + 1); + lcm_sym52__ = (inline_sym9__ + 1); break; } - for (int i = lcm_sym50__; i <= inline_sym12__; ++i) { + for (int i = lcm_sym52__; i <= inline_sym12__; ++i) { { int inline_sym15__; int inline_sym16__ = std::numeric_limits::min(); @@ -25784,7 +25794,11 @@ class optimizations_model final : public model_base_crtp { int inline_sym18__ = std::numeric_limits::min(); for (int inline_sym19__ = 1; inline_sym19__ <= 1; ++inline_sym19__) { - current_statement__ = 7; + current_statement__ = 8; + if (stan::math::logical_gt(34, 342)) { + break; + } + current_statement__ = 9; lp_accum__.add(3); } } @@ -25801,81 +25815,81 @@ class optimizations_model final : public model_base_crtp { } } { - current_statement__ = 13; + current_statement__ = 15; lp_accum__.add(53); { - current_statement__ = 13; + current_statement__ = 15; lp_accum__.add(53); } { - current_statement__ = 13; + current_statement__ = 15; lp_accum__.add(53); } { - current_statement__ = 13; + current_statement__ = 15; lp_accum__.add(53); } { - current_statement__ = 13; + current_statement__ = 15; lp_accum__.add(53); } } { { { - current_statement__ = 15; + current_statement__ = 17; lp_accum__.add(53); { - current_statement__ = 15; + current_statement__ = 17; lp_accum__.add(53); } } { - lcm_sym53__ = (2 * 2); - if (stan::math::logical_gte(lcm_sym53__, 2)) { - lcm_sym51__ = (2 + 1); + lcm_sym55__ = (2 * 2); + if (stan::math::logical_gte(lcm_sym55__, 2)) { + lcm_sym53__ = (2 + 1); lp_accum__.add(53); - for (int k = lcm_sym51__; k <= lcm_sym53__; ++k) { - current_statement__ = 15; + for (int k = lcm_sym53__; k <= lcm_sym55__; ++k) { + current_statement__ = 17; lp_accum__.add(53); } } } { - lcm_sym53__ = (3 * 2); - if (stan::math::logical_gte(lcm_sym53__, 3)) { - lcm_sym51__ = (3 + 1); + lcm_sym55__ = (3 * 2); + if (stan::math::logical_gte(lcm_sym55__, 3)) { + lcm_sym53__ = (3 + 1); lp_accum__.add(53); - for (int k = lcm_sym51__; k <= lcm_sym53__; ++k) { - current_statement__ = 15; + for (int k = lcm_sym53__; k <= lcm_sym55__; ++k) { + current_statement__ = 17; lp_accum__.add(53); } } } } { - lcm_sym49__ = (2 + 2); - if (stan::math::logical_gte(lcm_sym49__, 2)) { - lcm_sym52__ = (2 * 2); - if (stan::math::logical_gte(lcm_sym52__, 2)) { + lcm_sym51__ = (2 + 2); + if (stan::math::logical_gte(lcm_sym51__, 2)) { + lcm_sym54__ = (2 * 2); + if (stan::math::logical_gte(lcm_sym54__, 2)) { { - lcm_sym48__ = (2 + 1); + lcm_sym50__ = (2 + 1); lp_accum__.add(53); - for (int k = lcm_sym48__; k <= lcm_sym52__; ++k) { - current_statement__ = 15; + for (int k = lcm_sym50__; k <= lcm_sym54__; ++k) { + current_statement__ = 17; lp_accum__.add(53); } } } else { - lcm_sym48__ = (2 + 1); + lcm_sym50__ = (2 + 1); } - for (int j = lcm_sym48__; j <= lcm_sym49__; ++j) { - lcm_sym53__ = (j * 2); - if (stan::math::logical_gte(lcm_sym53__, j)) { - lcm_sym51__ = (j + 1); + for (int j = lcm_sym50__; j <= lcm_sym51__; ++j) { + lcm_sym55__ = (j * 2); + if (stan::math::logical_gte(lcm_sym55__, j)) { + lcm_sym53__ = (j + 1); lp_accum__.add(53); - for (int k = lcm_sym51__; k <= lcm_sym53__; ++k) { - current_statement__ = 15; + for (int k = lcm_sym53__; k <= lcm_sym55__; ++k) { + current_statement__ = 17; lp_accum__.add(53); } } @@ -25883,28 +25897,28 @@ class optimizations_model final : public model_base_crtp { } } { - lcm_sym49__ = (3 + 2); - if (stan::math::logical_gte(lcm_sym49__, 3)) { - lcm_sym52__ = (3 * 2); - if (stan::math::logical_gte(lcm_sym52__, 3)) { + lcm_sym51__ = (3 + 2); + if (stan::math::logical_gte(lcm_sym51__, 3)) { + lcm_sym54__ = (3 * 2); + if (stan::math::logical_gte(lcm_sym54__, 3)) { { - lcm_sym48__ = (3 + 1); + lcm_sym50__ = (3 + 1); lp_accum__.add(53); - for (int k = lcm_sym48__; k <= lcm_sym52__; ++k) { - current_statement__ = 15; + for (int k = lcm_sym50__; k <= lcm_sym54__; ++k) { + current_statement__ = 17; lp_accum__.add(53); } } } else { - lcm_sym48__ = (3 + 1); + lcm_sym50__ = (3 + 1); } - for (int j = lcm_sym48__; j <= lcm_sym49__; ++j) { - lcm_sym53__ = (j * 2); - if (stan::math::logical_gte(lcm_sym53__, j)) { - lcm_sym51__ = (j + 1); + for (int j = lcm_sym50__; j <= lcm_sym51__; ++j) { + lcm_sym55__ = (j * 2); + if (stan::math::logical_gte(lcm_sym55__, j)) { + lcm_sym53__ = (j + 1); lp_accum__.add(53); - for (int k = lcm_sym51__; k <= lcm_sym53__; ++k) { - current_statement__ = 15; + for (int k = lcm_sym53__; k <= lcm_sym55__; ++k) { + current_statement__ = 17; lp_accum__.add(53); } } @@ -25912,28 +25926,28 @@ class optimizations_model final : public model_base_crtp { } } { - lcm_sym49__ = (4 + 2); - if (stan::math::logical_gte(lcm_sym49__, 4)) { - lcm_sym52__ = (4 * 2); - if (stan::math::logical_gte(lcm_sym52__, 4)) { + lcm_sym51__ = (4 + 2); + if (stan::math::logical_gte(lcm_sym51__, 4)) { + lcm_sym54__ = (4 * 2); + if (stan::math::logical_gte(lcm_sym54__, 4)) { { - lcm_sym48__ = (4 + 1); + lcm_sym50__ = (4 + 1); lp_accum__.add(53); - for (int k = lcm_sym48__; k <= lcm_sym52__; ++k) { - current_statement__ = 15; + for (int k = lcm_sym50__; k <= lcm_sym54__; ++k) { + current_statement__ = 17; lp_accum__.add(53); } } } else { - lcm_sym48__ = (4 + 1); + lcm_sym50__ = (4 + 1); } - for (int j = lcm_sym48__; j <= lcm_sym49__; ++j) { - lcm_sym53__ = (j * 2); - if (stan::math::logical_gte(lcm_sym53__, j)) { - lcm_sym51__ = (j + 1); + for (int j = lcm_sym50__; j <= lcm_sym51__; ++j) { + lcm_sym55__ = (j * 2); + if (stan::math::logical_gte(lcm_sym55__, j)) { + lcm_sym53__ = (j + 1); lp_accum__.add(53); - for (int k = lcm_sym51__; k <= lcm_sym53__; ++k) { - current_statement__ = 15; + for (int k = lcm_sym53__; k <= lcm_sym55__; ++k) { + current_statement__ = 17; lp_accum__.add(53); } } @@ -25941,28 +25955,28 @@ class optimizations_model final : public model_base_crtp { } } { - lcm_sym49__ = (5 + 2); - if (stan::math::logical_gte(lcm_sym49__, 5)) { - lcm_sym52__ = (5 * 2); - if (stan::math::logical_gte(lcm_sym52__, 5)) { + lcm_sym51__ = (5 + 2); + if (stan::math::logical_gte(lcm_sym51__, 5)) { + lcm_sym54__ = (5 * 2); + if (stan::math::logical_gte(lcm_sym54__, 5)) { { - lcm_sym48__ = (5 + 1); + lcm_sym50__ = (5 + 1); lp_accum__.add(53); - for (int k = lcm_sym48__; k <= lcm_sym52__; ++k) { - current_statement__ = 15; + for (int k = lcm_sym50__; k <= lcm_sym54__; ++k) { + current_statement__ = 17; lp_accum__.add(53); } } } else { - lcm_sym48__ = (5 + 1); + lcm_sym50__ = (5 + 1); } - for (int j = lcm_sym48__; j <= lcm_sym49__; ++j) { - lcm_sym53__ = (j * 2); - if (stan::math::logical_gte(lcm_sym53__, j)) { - lcm_sym51__ = (j + 1); + for (int j = lcm_sym50__; j <= lcm_sym51__; ++j) { + lcm_sym55__ = (j * 2); + if (stan::math::logical_gte(lcm_sym55__, j)) { + lcm_sym53__ = (j + 1); lp_accum__.add(53); - for (int k = lcm_sym51__; k <= lcm_sym53__; ++k) { - current_statement__ = 15; + for (int k = lcm_sym53__; k <= lcm_sym55__; ++k) { + current_statement__ = 17; lp_accum__.add(53); } } @@ -25970,100 +25984,100 @@ class optimizations_model final : public model_base_crtp { } } } - current_statement__ = 23; + current_statement__ = 25; for (int i = 1; i <= 5; ++i) { - current_statement__ = 20; + current_statement__ = 22; if (stan::math::logical_gt(i, 4)) { break; } - current_statement__ = 21; + current_statement__ = 23; lp_accum__.add(2); } - current_statement__ = 28; + current_statement__ = 30; for (int i = 1; i <= 5; ++i) { - current_statement__ = 25; + current_statement__ = 27; if (stan::math::logical_gt(i, 4)) { continue; } - current_statement__ = 26; + current_statement__ = 28; lp_accum__.add(2); } - current_statement__ = 33; + current_statement__ = 35; for (int i = 1; i <= 5; ++i) { - current_statement__ = 30; + current_statement__ = 32; if (stan::math::logical_gt(i, 4)) { continue; } - current_statement__ = 31; + current_statement__ = 33; lp_accum__.add(2); } - current_statement__ = 34; + current_statement__ = 36; x = 3; - current_statement__ = 35; - lp_accum__.add(3); current_statement__ = 37; + lp_accum__.add(3); + current_statement__ = 39; if (stan::math::logical_gt(theta, 2)) { - current_statement__ = 36; + current_statement__ = 38; x = 2; } - current_statement__ = 38; + current_statement__ = 40; lp_accum__.add(x); - current_statement__ = 39; + current_statement__ = 41; lp_accum__.add(247); - current_statement__ = 40; + current_statement__ = 42; x = 576; - current_statement__ = 41; + current_statement__ = 43; lp_accum__.add(576); lcm_sym47__ = stan::math::logical_gt(theta, 46); if (lcm_sym47__) { - current_statement__ = 42; + current_statement__ = 44; x = 5880; } - current_statement__ = 43; + current_statement__ = 45; lp_accum__.add(x); double z; - current_statement__ = 45; + current_statement__ = 47; z = x; - current_statement__ = 46; - lp_accum__.add(x); current_statement__ = 48; + lp_accum__.add(x); + current_statement__ = 50; if (lcm_sym47__) { - current_statement__ = 47; + current_statement__ = 49; z = x; } - current_statement__ = 49; + current_statement__ = 51; lp_accum__.add(z); - current_statement__ = 50; + current_statement__ = 52; lp_accum__.add(2); { double y = std::numeric_limits::quiet_NaN(); - current_statement__ = 52; + current_statement__ = 54; lp_accum__.add(24); } { double y = std::numeric_limits::quiet_NaN(); - current_statement__ = 55; + current_statement__ = 57; lp_accum__.add(245); } { - current_statement__ = 57; + current_statement__ = 59; lp_accum__.add(2); } int inline_sym20__; int inline_sym21__ = std::numeric_limits::min(); for (int inline_sym22__ = 1; inline_sym22__ <= 1; ++inline_sym22__) { - current_statement__ = 59; + current_statement__ = 61; lp_accum__.add(2); break; } - current_statement__ = 61; + current_statement__ = 63; while (576) { break; } int inline_sym23__; int inline_sym24__ = std::numeric_limits::min(); for (int inline_sym25__ = 1; inline_sym25__ <= 1; ++inline_sym25__) { - current_statement__ = 59; + current_statement__ = 61; lp_accum__.add(2); inline_sym23__ = 24; break; @@ -26074,20 +26088,20 @@ class optimizations_model final : public model_base_crtp { } int inline_sym24__ = std::numeric_limits::min(); for (int inline_sym25__ = 1; inline_sym25__ <= 1; ++inline_sym25__) { - current_statement__ = 59; + current_statement__ = 61; lp_accum__.add(2); inline_sym23__ = 24; break; } } - current_statement__ = 64; - for (int i = 31; i <= 225; ++i) { continue;} current_statement__ = 66; + for (int i = 31; i <= 225; ++i) { continue;} + current_statement__ = 68; for (int i = 31; i <= 225; ++i) { break;} int inline_sym26__; int inline_sym27__ = std::numeric_limits::min(); for (int inline_sym28__ = 1; inline_sym28__ <= 1; ++inline_sym28__) { - current_statement__ = 59; + current_statement__ = 61; lp_accum__.add(2); inline_sym26__ = 24; break; @@ -26096,7 +26110,7 @@ class optimizations_model final : public model_base_crtp { int inline_sym29__; int inline_sym30__ = std::numeric_limits::min(); for (int inline_sym31__ = 1; inline_sym31__ <= 1; ++inline_sym31__) { - current_statement__ = 59; + current_statement__ = 61; lp_accum__.add(2); inline_sym29__ = 24; break; @@ -26105,25 +26119,25 @@ class optimizations_model final : public model_base_crtp { int inline_sym32__; int inline_sym33__ = std::numeric_limits::min(); for (int inline_sym34__ = 1; inline_sym34__ <= 1; ++inline_sym34__) { - current_statement__ = 59; + current_statement__ = 61; lp_accum__.add(2); break; } { - current_statement__ = 69; + current_statement__ = 71; lp_accum__.add(1); - current_statement__ = 70; + current_statement__ = 72; lp_accum__.add(24); } { { - current_statement__ = 72; + current_statement__ = 74; lp_accum__.add(1); } } double temp = std::numeric_limits::quiet_NaN(); { - current_statement__ = 76; + current_statement__ = 78; if (pstream__) { stan::math::stan_print(pstream__, "hello"); stan::math::stan_print(pstream__, "\n"); @@ -26131,28 +26145,28 @@ class optimizations_model final : public model_base_crtp { } double temp2 = std::numeric_limits::quiet_NaN(); { - current_statement__ = 79; + current_statement__ = 81; lp_accum__.add(4); - current_statement__ = 80; + current_statement__ = 82; lp_accum__.add(6); { - current_statement__ = 79; + current_statement__ = 81; lp_accum__.add(4); - current_statement__ = 80; + current_statement__ = 82; lp_accum__.add(6); } } double dataonlyvar; - current_statement__ = 82; + current_statement__ = 84; dataonlyvar = 3; - current_statement__ = 83; + current_statement__ = 85; lp_accum__.add(dataonlyvar); local_scalar_t__ paramvar; { - current_statement__ = 85; + current_statement__ = 87; paramvar = (theta * 34); } - current_statement__ = 87; + current_statement__ = 89; lp_accum__.add(paramvar); } } catch (const std::exception& e) { @@ -26351,25 +26365,25 @@ class optimizations_model final : public model_base_crtp { param_names__.emplace_back(std::string() + "theta"); param_names__.emplace_back(std::string() + "phi"); - for (int sym55__ = 1; sym55__ <= 2; ++sym55__) { + for (int sym57__ = 1; sym57__ <= 2; ++sym57__) { { - for (int sym56__ = 1; sym56__ <= 3; ++sym56__) { + for (int sym58__ = 1; sym58__ <= 3; ++sym58__) { { - param_names__.emplace_back(std::string() + "x_matrix" + '.' + std::to_string(sym56__) + '.' + std::to_string(sym55__)); + param_names__.emplace_back(std::string() + "x_matrix" + '.' + std::to_string(sym58__) + '.' + std::to_string(sym57__)); } } } } - for (int sym55__ = 1; sym55__ <= 2; ++sym55__) { + for (int sym57__ = 1; sym57__ <= 2; ++sym57__) { { - param_names__.emplace_back(std::string() + "x_vector" + '.' + std::to_string(sym55__)); + param_names__.emplace_back(std::string() + "x_vector" + '.' + std::to_string(sym57__)); } } - for (int sym55__ = 1; sym55__ <= 2; ++sym55__) { + for (int sym57__ = 1; sym57__ <= 2; ++sym57__) { { - for (int sym56__ = 1; sym56__ <= 2; ++sym56__) { + for (int sym58__ = 1; sym58__ <= 2; ++sym58__) { { - param_names__.emplace_back(std::string() + "x_cov" + '.' + std::to_string(sym56__) + '.' + std::to_string(sym55__)); + param_names__.emplace_back(std::string() + "x_cov" + '.' + std::to_string(sym58__) + '.' + std::to_string(sym57__)); } } } @@ -26392,23 +26406,23 @@ class optimizations_model final : public model_base_crtp { param_names__.emplace_back(std::string() + "theta"); param_names__.emplace_back(std::string() + "phi"); - for (int sym55__ = 1; sym55__ <= 2; ++sym55__) { + for (int sym57__ = 1; sym57__ <= 2; ++sym57__) { { - for (int sym56__ = 1; sym56__ <= 3; ++sym56__) { + for (int sym58__ = 1; sym58__ <= 3; ++sym58__) { { - param_names__.emplace_back(std::string() + "x_matrix" + '.' + std::to_string(sym56__) + '.' + std::to_string(sym55__)); + param_names__.emplace_back(std::string() + "x_matrix" + '.' + std::to_string(sym58__) + '.' + std::to_string(sym57__)); } } } } - for (int sym55__ = 1; sym55__ <= 2; ++sym55__) { + for (int sym57__ = 1; sym57__ <= 2; ++sym57__) { { - param_names__.emplace_back(std::string() + "x_vector" + '.' + std::to_string(sym55__)); + param_names__.emplace_back(std::string() + "x_vector" + '.' + std::to_string(sym57__)); } } - for (int sym55__ = 1; sym55__ <= 3; ++sym55__) { + for (int sym57__ = 1; sym57__ <= 3; ++sym57__) { { - param_names__.emplace_back(std::string() + "x_cov" + '.' + std::to_string(sym55__)); + param_names__.emplace_back(std::string() + "x_cov" + '.' + std::to_string(sym57__)); } } if (emit_transformed_parameters__) { diff --git a/test/integration/good/compiler-optimizations/mem_patterns/cpp.expected b/test/integration/good/compiler-optimizations/mem_patterns/cpp.expected index 07a37ee0ec..ff70b8f5b0 100644 --- a/test/integration/good/compiler-optimizations/mem_patterns/cpp.expected +++ b/test/integration/good/compiler-optimizations/mem_patterns/cpp.expected @@ -4976,11 +4976,8 @@ class reductions_allowed_model final : public model_base_crtp(data_r) - : - stan::math::promote_scalar( - stan::math::sum(soa_x))); + tp_real_from_soa = (stan::math::logical_gt(5, 0) ? data_r : + stan::math::sum(soa_x)); Eigen::Matrix tp_matrix_aos_from_mix = Eigen::Matrix::Constant(5, 10, DUMMY_VAR__); @@ -5064,11 +5061,8 @@ class reductions_allowed_model final : public model_base_crtp(data_r) - : - stan::math::promote_scalar( - stan::math::sum(soa_x))); + tp_real_from_soa = (stan::math::logical_gt(5, 0) ? data_r : + stan::math::sum(soa_x)); current_statement__ = 5; stan::model::assign(tp_matrix_aos_from_mix, (stan::math::logical_gt(stan::math::sum(soa_x), 0) ? diff --git a/test/integration/good/compiler-optimizations/mem_patterns/transformed_mir.expected b/test/integration/good/compiler-optimizations/mem_patterns/transformed_mir.expected index 5e90b49a37..e85f9c1909 100644 --- a/test/integration/good/compiler-optimizations/mem_patterns/transformed_mir.expected +++ b/test/integration/good/compiler-optimizations/mem_patterns/transformed_mir.expected @@ -11165,8 +11165,12 @@ ((pattern (Lit Int 0)) (meta ((type_ UInt) (loc ) (adlevel DataOnly))))))) (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) - ((pattern (Var data_r)) - (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) + ((pattern + (Promotion + ((pattern (Var data_r)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) + UReal AutoDiffable)) + (meta ((type_ UReal) (loc ) (adlevel AutoDiffable)))) ((pattern (FunApp (StanLib sum FnPlain SoA) (((pattern (Var soa_x)) @@ -11400,8 +11404,12 @@ ((pattern (Lit Int 0)) (meta ((type_ UInt) (loc ) (adlevel DataOnly))))))) (meta ((type_ UInt) (loc ) (adlevel DataOnly)))) - ((pattern (Var data_r)) - (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) + ((pattern + (Promotion + ((pattern (Var data_r)) + (meta ((type_ UReal) (loc ) (adlevel DataOnly)))) + UReal AutoDiffable)) + (meta ((type_ UReal) (loc ) (adlevel AutoDiffable)))) ((pattern (FunApp (StanLib sum FnPlain AoS) (((pattern (Var soa_x)) diff --git a/test/integration/good/parser-generator/complex_scalar.stan b/test/integration/good/lang/good_complex.stan similarity index 99% rename from test/integration/good/parser-generator/complex_scalar.stan rename to test/integration/good/lang/good_complex.stan index 9e81d0281e..f199d53e4c 100644 --- a/test/integration/good/parser-generator/complex_scalar.stan +++ b/test/integration/good/lang/good_complex.stan @@ -91,11 +91,10 @@ generated quantities { gq_r = foo5(gq_complex_array); gq_complex_array = foo6(gq_r); gq_complex_array = foo7(gq_complex_array); - + // test imaginary literal complex zi = 1 + 3.14i; zi = zi * 0i; complex yi = to_complex(0, 1.1) + to_complex(0.0, 2.2) + to_complex(); real x = get_real(3i - 40e-3i); } - diff --git a/test/integration/good/lang/pretty.expected b/test/integration/good/lang/pretty.expected index 1f1e762fc5..146485a015 100644 --- a/test/integration/good/lang/pretty.expected +++ b/test/integration/good/lang/pretty.expected @@ -1,3 +1,105 @@ + $ ../../../../../install/default/bin/stanc --auto-format good_complex.stan +functions { + complex foo() { + return to_complex(); + } + real foo1(complex z) { + return 1.0; + } + complex foo2(real r) { + return to_complex(r); + } + complex foo3(complex z) { + return z; + } + array[] complex foo4() { + return {to_complex(), to_complex()}; + } + real foo5(array[] complex z) { + return 1.0; + } + array[] complex foo6(real r) { + return {to_complex(r), to_complex(r, r)}; + } + array[] complex foo7(array[] complex z) { + return z; + } +} +data { + int N; + complex d_complex; + array[N] complex d_complex_array; + array[N, 2] complex d_complex_array_2d; + array[N, 2, 3] complex d_complex_array_3d; +} +transformed data { + complex td_complex = d_complex; + td_complex = 1; + td_complex = to_complex(1, 2); + array[N] complex td_complex_array = d_complex_array; + array[2, 3] complex td_complex_array_2d; + array[2, 3, 4] complex td_complex_array_3d; + for (td_i in 1 : 2) { + for (td_j in 1 : 3) { + for (td_k in 1 : 4) { + td_complex_array_3d[td_i, td_j, td_k] = to_complex(1, 2.2); + } + } + } + real td_r = get_real(td_complex); + real td_i = get_imag(td_complex); +} +parameters { + complex p_complex; + array[N] complex p_complex_array; + array[N, 2] complex p_complex_array_2d; + array[N, 2, 3] complex p_complex_array_3d; +} +transformed parameters { + complex tp_complex = p_complex; + tp_complex = 1; + tp_complex = to_complex(1, 2); + array[N] complex tp_complex_array = p_complex_array; + array[2, 3] complex tp_complex_array_2d; + array[2, 3, 4] complex tp_complex_array_3d; + for (tp_i in 1 : 2) { + for (tp_j in 1 : 3) { + for (tp_k in 1 : 4) { + tp_complex_array_3d[tp_i, tp_j, tp_k] = to_complex(1, 2.2); + } + } + } + real tp_r = get_real(tp_complex); + real tp_i = get_imag(tp_complex); +} +model { + abs(p_complex) ~ normal(0, 1); +} +generated quantities { + complex gq_complex; + array[2] complex gq_complex_array; + array[2, 3] complex gq_complex_array_2d = {{1, 2, 3}, + {to_complex(), to_complex( + 1.1), to_complex(1, 2.1)}}; + array[2, 3, 4] complex gq_complex_array_3d; + gq_complex = 3; + gq_complex_array[1] = to_complex(5.1, 6); + gq_complex = foo(); + real gq_r = foo1(gq_complex); + gq_complex = foo2(gq_r); + gq_complex = foo3(gq_complex); + gq_complex_array = foo4(); + gq_r = foo5(gq_complex_array); + gq_complex_array = foo6(gq_r); + gq_complex_array = foo7(gq_complex_array); + + // test imaginary literal + complex zi = 1 + 3.14i; + zi = zi * 0i; + complex yi = to_complex(0, 1.1) + to_complex(0.0, 2.2) + to_complex(); + real x = get_real(3i - 40e-3i); +} + $ ../../../../../install/default/bin/stanc --auto-format good_const.stan transformed data { real y; diff --git a/test/integration/good/parser-generator/pretty.expected b/test/integration/good/parser-generator/pretty.expected index ea51d2262e..691a4fa816 100644 --- a/test/integration/good/parser-generator/pretty.expected +++ b/test/integration/good/parser-generator/pretty.expected @@ -60,108 +60,6 @@ transformed parameters { cholesky_factor_cov[3] cfcov_33; } - $ ../../../../../install/default/bin/stanc --auto-format complex_scalar.stan -functions { - complex foo() { - return to_complex(); - } - real foo1(complex z) { - return 1.0; - } - complex foo2(real r) { - return to_complex(r); - } - complex foo3(complex z) { - return z; - } - array[] complex foo4() { - return {to_complex(), to_complex()}; - } - real foo5(array[] complex z) { - return 1.0; - } - array[] complex foo6(real r) { - return {to_complex(r), to_complex(r, r)}; - } - array[] complex foo7(array[] complex z) { - return z; - } -} -data { - int N; - complex d_complex; - array[N] complex d_complex_array; - array[N, 2] complex d_complex_array_2d; - array[N, 2, 3] complex d_complex_array_3d; -} -transformed data { - complex td_complex = d_complex; - td_complex = 1; - td_complex = to_complex(1, 2); - array[N] complex td_complex_array = d_complex_array; - array[2, 3] complex td_complex_array_2d; - array[2, 3, 4] complex td_complex_array_3d; - for (td_i in 1 : 2) { - for (td_j in 1 : 3) { - for (td_k in 1 : 4) { - td_complex_array_3d[td_i, td_j, td_k] = to_complex(1, 2.2); - } - } - } - real td_r = get_real(td_complex); - real td_i = get_imag(td_complex); -} -parameters { - complex p_complex; - array[N] complex p_complex_array; - array[N, 2] complex p_complex_array_2d; - array[N, 2, 3] complex p_complex_array_3d; -} -transformed parameters { - complex tp_complex = p_complex; - tp_complex = 1; - tp_complex = to_complex(1, 2); - array[N] complex tp_complex_array = p_complex_array; - array[2, 3] complex tp_complex_array_2d; - array[2, 3, 4] complex tp_complex_array_3d; - for (tp_i in 1 : 2) { - for (tp_j in 1 : 3) { - for (tp_k in 1 : 4) { - tp_complex_array_3d[tp_i, tp_j, tp_k] = to_complex(1, 2.2); - } - } - } - real tp_r = get_real(tp_complex); - real tp_i = get_imag(tp_complex); -} -model { - abs(p_complex) ~ normal(0, 1); -} -generated quantities { - complex gq_complex; - array[2] complex gq_complex_array; - array[2, 3] complex gq_complex_array_2d = {{1, 2, 3}, - {to_complex(), to_complex( - 1.1), to_complex(1, 2.1)}}; - array[2, 3, 4] complex gq_complex_array_3d; - gq_complex = 3; - gq_complex_array[1] = to_complex(5.1, 6); - gq_complex = foo(); - real gq_r = foo1(gq_complex); - gq_complex = foo2(gq_r); - gq_complex = foo3(gq_complex); - gq_complex_array = foo4(); - gq_r = foo5(gq_complex_array); - gq_complex_array = foo6(gq_r); - gq_complex_array = foo7(gq_complex_array); - - // test imaginary literal - complex zi = 1 + 3.14i; - zi = zi * 0i; - complex yi = to_complex(0, 1.1) + to_complex(0.0, 2.2) + to_complex(); - real x = get_real(3i - 40e-3i); -} - $ ../../../../../install/default/bin/stanc --auto-format data_qualifier_scope_xformed_data.stan functions { vector target_(vector y, vector theta, array[] real x_r, array[] int x_i) { diff --git a/test/integration/good/promotion/array_promotion.stan b/test/integration/good/promotion/array_promotion.stan new file mode 100644 index 0000000000..76f14a78de --- /dev/null +++ b/test/integration/good/promotion/array_promotion.stan @@ -0,0 +1,30 @@ +functions { + void printer(array[] real x){ + print(x); + } + + void data_printer(data array[] real x){ + print(x[0]); + } + real nested(array[,] complex zs){ + return num_elements(zs); + } +} + +data { + int N; + array[N] int xs; +} + +transformed parameters { + array[2,2] real zs = {{2,3},{7,0.5}}; +} + +model { + array[3] int d = {1,2,3}; + printer(d); + data_printer(xs); + printer(xs); + print(nested({d,d})); + print(nested(zs)); +} diff --git a/test/integration/good/promotion/complex_functions.stan b/test/integration/good/promotion/complex_functions.stan new file mode 100644 index 0000000000..c0ee4cf0c4 --- /dev/null +++ b/test/integration/good/promotion/complex_functions.stan @@ -0,0 +1,32 @@ +functions { + void promote_complex_array(array[] complex zs){ + print(zs[0]); + } +} + +generated quantities { + real x = norm(1); + x = norm(1.5); + x = norm(3i); + + real y = abs(4+3i); + y = arg(4+1i); + y = arg(2.5); + y = arg(1); + + complex z; + z = conj(4.1+7i); + z = conj(4.1); + z = conj(0); + + z = proj(4.1+7i); + z = proj(4.1); + z = proj(0); + + z = polar(1.5,0.5); + z = polar(2,3); + + array[3] int xs = {1,2,3}; + promote_complex_array(xs); + +} diff --git a/test/integration/good/promotion/dune b/test/integration/good/promotion/dune new file mode 100644 index 0000000000..856a7fccef --- /dev/null +++ b/test/integration/good/promotion/dune @@ -0,0 +1 @@ +(include ../dune) diff --git a/test/integration/bad/algebra_solver/bad_newton_x_r_type.stan b/test/integration/good/promotion/newton_x_r_type.stan similarity index 100% rename from test/integration/bad/algebra_solver/bad_newton_x_r_type.stan rename to test/integration/good/promotion/newton_x_r_type.stan diff --git a/test/integration/bad/algebra_solver/bad_newton_x_r_type_control.stan b/test/integration/good/promotion/newton_x_r_type_control.stan similarity index 100% rename from test/integration/bad/algebra_solver/bad_newton_x_r_type_control.stan rename to test/integration/good/promotion/newton_x_r_type_control.stan diff --git a/test/integration/good/promotion/pretty.expected b/test/integration/good/promotion/pretty.expected new file mode 100644 index 0000000000..db28e9ec4d --- /dev/null +++ b/test/integration/good/promotion/pretty.expected @@ -0,0 +1,188 @@ + $ ../../../../../install/default/bin/stanc --auto-format array_promotion.stan +functions { + void printer(array[] real x) { + print(x); + } + + void data_printer(data array[] real x) { + print(x[0]); + } + real nested(array[,] complex zs) { + return num_elements(zs); + } +} +data { + int N; + array[N] int xs; +} +transformed parameters { + array[2, 2] real zs = {{2, 3}, {7, 0.5}}; +} +model { + array[3] int d = {1, 2, 3}; + printer(d); + data_printer(xs); + printer(xs); + print(nested({d, d})); + print(nested(zs)); +} + + $ ../../../../../install/default/bin/stanc --auto-format complex_functions.stan +functions { + void promote_complex_array(array[] complex zs) { + print(zs[0]); + } +} +generated quantities { + real x = norm(1); + x = norm(1.5); + x = norm(3i); + + real y = abs(4 + 3i); + y = arg(4 + 1i); + y = arg(2.5); + y = arg(1); + + complex z; + z = conj(4.1 + 7i); + z = conj(4.1); + z = conj(0); + + z = proj(4.1 + 7i); + z = proj(4.1); + z = proj(0); + + z = polar(1.5, 0.5); + z = polar(2, 3); + + array[3] int xs = {1, 2, 3}; + promote_complex_array(xs); +} + + $ ../../../../../install/default/bin/stanc --auto-format newton_x_r_type.stan +functions { + vector algebra_system(vector y, vector theta, array[] real x_r, + array[] int x_i) { + vector[2] f_y; + f_y[1] = y[1] - theta[1]; + f_y[2] = y[2] - theta[2]; + return f_y; + } +} +data { + +} +transformed data { + vector[2] y; + array[0] int x_r; + array[0] int x_i; +} +parameters { + vector[2] theta_p; + real dummy_parameter; +} +transformed parameters { + vector[2] y_s_p; + y_s_p = algebra_solver_newton(algebra_system, y, theta_p, x_r, x_i); +} +model { + dummy_parameter ~ normal(0, 1); +} + + $ ../../../../../install/default/bin/stanc --auto-format newton_x_r_type_control.stan +functions { + vector algebra_system(vector y, vector theta, array[] real x_r, + array[] int x_i) { + vector[2] f_y; + f_y[1] = y[1] - theta[1]; + f_y[2] = y[2] - theta[2]; + return f_y; + } +} +data { + +} +transformed data { + vector[2] y; + array[0] int x_r; + array[0] int x_i; +} +parameters { + vector[2] theta_p; + real dummy_parameter; +} +transformed parameters { + vector[2] y_s_p; + y_s_p = algebra_solver_newton(algebra_system, y, theta_p, x_r, x_i, 0.01, + 0.01, 10); +} +model { + dummy_parameter ~ normal(0, 1); +} + + $ ../../../../../install/default/bin/stanc --auto-format propto.stan +model { + target += normal_lupdf(1 | {0}, 1); +} + + $ ../../../../../install/default/bin/stanc --auto-format x_r_type.stan +functions { + vector algebra_system(vector y, vector theta, array[] real x_r, + array[] int x_i) { + vector[2] f_y; + f_y[1] = y[1] - theta[1]; + f_y[2] = y[2] - theta[2]; + return f_y; + } +} +data { + +} +transformed data { + vector[2] y; + array[0] int x_r; + array[0] int x_i; +} +parameters { + vector[2] theta_p; + real dummy_parameter; +} +transformed parameters { + vector[2] y_s_p; + y_s_p = algebra_solver(algebra_system, y, theta_p, x_r, x_i); +} +model { + dummy_parameter ~ normal(0, 1); +} + + $ ../../../../../install/default/bin/stanc --auto-format x_r_type_control.stan +functions { + vector algebra_system(vector y, vector theta, array[] real x_r, + array[] int x_i) { + vector[2] f_y; + f_y[1] = y[1] - theta[1]; + f_y[2] = y[2] - theta[2]; + return f_y; + } +} +data { + +} +transformed data { + vector[2] y; + array[0] int x_r; + array[0] int x_i; +} +parameters { + vector[2] theta_p; + real dummy_parameter; +} +transformed parameters { + vector[2] y_s_p; + y_s_p = algebra_solver(algebra_system, y, theta_p, x_r, x_i, 0.01, 0.01, + 10); +} +model { + dummy_parameter ~ normal(0, 1); +} + diff --git a/test/integration/bad/propto-bad1.stan b/test/integration/good/promotion/propto.stan similarity index 100% rename from test/integration/bad/propto-bad1.stan rename to test/integration/good/promotion/propto.stan diff --git a/test/integration/bad/algebra_solver/bad_x_r_type.stan b/test/integration/good/promotion/x_r_type.stan similarity index 100% rename from test/integration/bad/algebra_solver/bad_x_r_type.stan rename to test/integration/good/promotion/x_r_type.stan diff --git a/test/integration/bad/algebra_solver/bad_x_r_type_control.stan b/test/integration/good/promotion/x_r_type_control.stan similarity index 100% rename from test/integration/bad/algebra_solver/bad_x_r_type_control.stan rename to test/integration/good/promotion/x_r_type_control.stan diff --git a/test/unit/Optimize.ml b/test/unit/Optimize.ml index a28ebf98a8..44fb0dcf7c 100644 --- a/test/unit/Optimize.ml +++ b/test/unit/Optimize.ml @@ -1964,7 +1964,7 @@ let%expect_test "partial evaluation" = int i; FnPrint__(3); FnPrint__((i + 3)); - FnPrint__(log1m(i)); + FnPrint__(log((1 - i) -> real)); } } } @@ -2360,7 +2360,7 @@ model { target += sqrt(34.); target += sqrt(34.); target += variance(x_vector); - target += sqrt2(); + target += sqrt(2 -> real); target += squared_distance(x_vector, y_vector); target += trace(x_matrix); target += trace_gen_quad_form(x_matrix, z_matrix, y_matrix);