Skip to content

array-valued transform arguments#552

Merged
rok-cesnovar merged 4 commits into
stan-dev:masterfrom
nhuurre:array-valued-transform
Jun 17, 2020
Merged

array-valued transform arguments#552
rok-cesnovar merged 4 commits into
stan-dev:masterfrom
nhuurre:array-valued-transform

Conversation

@nhuurre
Copy link
Copy Markdown
Collaborator

@nhuurre nhuurre commented May 27, 2020

Fix #547
Non-scalar values are now allowed in lower, upper, offset and multiplier transforms if the value has the same type and size as the declared variable.

Note that container bounds check error messages have always been kind of bogus.

parameters {
  real p[5,5];
}
transformed parameters {
  real<lower=0> t[5,5] = p;
}
Rejecting initial value:
  Error evaluating the log probability at the initial value.
Exception: example_model_namespace::log_prob: t[sym1__, sym2__] is -0.574295,
  but must be greater than or equal to 0 (in 'example.stan', line 5, column 2 to column 27)

The opaque indexing is being fixed in math (stan-dev/math#1635) but it doesn't support array-valued bounds.

@bob-carpenter
Copy link
Copy Markdown
Member

I don't quite feel prepared to review the OCaml, but this is huge! We've been wanting to do this for ages.

We've been improving indexing into error messages every place we can, so that'll also be great if that can be fixed.

@rok-cesnovar
Copy link
Copy Markdown
Member

rok-cesnovar commented May 29, 2020

With develop cmdstan you can set this in make/local to test this PR:

STANC3_TEST_BIN_URL = https://jenkins.mc-stan.org/job/stanc3-test-binaries/106/artifact

I can review but would like some help testing if everything is fine in terms of modelling.

@rok-cesnovar
Copy link
Copy Markdown
Member

@nhuurre can you merge master in? I can review this today.

@wds15
Copy link
Copy Markdown

wds15 commented Jun 9, 2020

whow 10k lines of code!

Copy link
Copy Markdown
Member

@rok-cesnovar rok-cesnovar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good. I think the checks should go in the stan repo.

}

template <typename T>
void FnCheckShape__(const char* var_name, size_t depth,
Copy link
Copy Markdown
Member

@rok-cesnovar rok-cesnovar Jun 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move this functions to the stan-dev/stan repo? Not sure of the best location but I guess under /model/checks.hpp and then add that header to the model_header? They would probably have to be named more in the style of math / stan C++ conventions we use. So something like check_shape().

The other functions that dont depend on model specific should probably also go there but that is not this PRs fault and most of them can actually just be removed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was definitely being lazy. I think this actually belongs in the math library. FnCheckShape__ is a generalization of check_consistent_size. Alternatively it could be replaced by check_matching_dims if that recursed into arbitrary arrays.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with either of the proposed solutions.

Comment thread src/frontend/Semantic_error.ml Outdated
Copy link
Copy Markdown
Member

@rok-cesnovar rok-cesnovar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor thing then its good to go.

Comment thread src/frontend/Semantic_check.ml
@rok-cesnovar rok-cesnovar merged commit 1caabe7 into stan-dev:master Jun 17, 2020
@rok-cesnovar
Copy link
Copy Markdown
Member

Thanks!

@nhuurre nhuurre deleted the array-valued-transform branch June 17, 2020 09:55
@nhuurre
Copy link
Copy Markdown
Collaborator Author

nhuurre commented Jun 17, 2020

Hey, @rok-cesnovar ,just curious, why do you squash the history when merging these?
When I try to delete the branch locally git thinks it hasn't been merged.

@rok-cesnovar
Copy link
Copy Markdown
Member

No reason, its the default option I think.

@nhuurre
Copy link
Copy Markdown
Collaborator Author

nhuurre commented Jun 17, 2020

I don't think that's a good default. It doesn't matter for small fixes like this PR but optimization debugging was a sequence of small changes with associated explanations and now all of that is a single huge blob. Good luck figuring out which parts of the code those bullet points refer to.

@bob-carpenter
Copy link
Copy Markdown
Member

I don't think it is the default. At least it wasn't when I set things up. We had a long go around on this ages ago and decided to keep all the commit and merge history bubbles. If you are going to squash history, whatever you do, don't rewrite it on the origin (GitHub)---only collapse commits locally before pushing to origin.

@rok-cesnovar
Copy link
Copy Markdown
Member

rok-cesnovar commented Jun 17, 2020

stanc3 has these three options on:

Allow merge commits
Add all commits from the head branch to the base branch with a merge commit.

Allow squash merging
Combine all commits from the head branch into a single commit in the base branch.

Allow rebase merging
Add all commits from the head branch onto the base branch individually.

Should we just allow the first option then? I am fine with that.

@nhuurre
Copy link
Copy Markdown
Collaborator Author

nhuurre commented Jun 17, 2020

Yes, I think the first is the preferred action.

@rok-cesnovar
Copy link
Copy Markdown
Member

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vector valued transform arguments

4 participants