Skip to content

Commit

Permalink
Merge pull request #2430 from stan-dev/bugfix/2416-qualify-local-xfor…
Browse files Browse the repository at this point in the history
…med-data-vars-as-data

Bugfix/2416 qualify local xformed data vars as data
  • Loading branch information
mitzimorris authored Nov 18, 2017
2 parents 660ef06 + e8079ff commit 7e6903c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/stan/lang/ast/fun/has_var_vis_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace stan {
bool has_var_vis::operator()(const variable& e) const {
scope var_scope = var_map_.get_scope(e.name_);
return var_scope.par_or_tpar()
|| (var_scope.is_local() && !e.type_.base_type_.is_int_type());
|| (var_scope.local_allows_var() && !e.type_.base_type_.is_int_type());
}

bool has_var_vis::operator()(const fun& e) const {
Expand Down
10 changes: 10 additions & 0 deletions src/stan/lang/ast/scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ namespace stan {
*/
bool is_local() const;

/**
* Flags local scopes which permit parameter variables.
* Allows local blocks in functions, transfromed parameter,
* and model blocks; disallows local blocks in transformed data
* and generated quantities program blocks.
*
* @return true for local parameter origin block types
*/
bool local_allows_var() const;

/**
* Flags scopes where parameter variables are declared,
* i.e., top-level of parameter or transformed parameter block.
Expand Down
6 changes: 6 additions & 0 deletions src/stan/lang/ast/scope_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ namespace stan {
return is_local_;
}

bool scope::local_allows_var() const {
return is_local_
&& program_block_ != transformed_data_origin
&& program_block_ != derived_origin;
}

bool scope::par_or_tpar() const {
return !is_local_
&& (program_block_ == parameter_origin
Expand Down
2 changes: 1 addition & 1 deletion src/stan/lang/ast/sigs/function_arg_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace stan {
/**
* Return true if the `expr_type` of the specified
* `function_arg_type` is not equal to the
* `expr_type` of this `function_arg_type</
* `expr_type` of this `function_arg_type`.
* Ignore status of bool `data_only_`.
*
* @param fa_type other function argument type.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
functions {
vector target(vector y, vector theta, real[] x_r, int[] x_i) {
vector[2] deltas;
deltas[1] = y[1] - theta[1] - x_r[1];
return deltas;
}
}

transformed data {
vector[1] td_y;
{
vector[1] td_y_guess = [1]';
vector[1] td_theta = [1]';
real td_x_r[0] = {1.0};
int td_x_i[0];
td_y = algebra_solver(target, td_y_guess, td_theta, td_x_r, td_x_i);
}
}
generated quantities {
vector[1] gq_y;
{
vector[1] gq_y_guess = [1]';
vector[1] gq_theta = [1]';
real gq_x_r[0] = {1.0};
int gq_x_i[0];
gq_y = algebra_solver(target, gq_y_guess, gq_theta, gq_x_r, gq_x_i);
}
}

0 comments on commit 7e6903c

Please sign in to comment.