Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eigen out of bounds access error with simple model #489

Closed
bbbales2 opened this issue Mar 25, 2020 · 3 comments · Fixed by #521 or #849
Closed

Eigen out of bounds access error with simple model #489

bbbales2 opened this issue Mar 25, 2020 · 3 comments · Fixed by #521 or #849
Labels
bug Something isn't working
Milestone

Comments

@bbbales2
Copy link
Member

Here is the model:

transformed data {
  vector[1] y = to_vector({ 1.0 });
}

parameters {
  real mu;
}

model {
  y[0] ~ normal(mu, 1.0);
}

If I build and run it:

./model sample

I get an Eigen out of bounds error and the program stops:

model: stan/lib/stan_math/lib/eigen_3.3.3/Eigen/src/Core/DenseCoeffsBase.h:162: Eigen::DenseCoeffsBase<type-parameter-0-0, 0>::CoeffReturnType Eigen::DenseCoeffsBase<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0>::operator[](Eigen::Index) const [Derived = Eigen::Matrix<double, -1, 1, 0, -1, 1>, Level = 0]: Assertion `index >= 0 && index < size()' failed.
Aborted (core dumped)

There should be some sort of Stan out of bounds access error I'm pretty sure. This is from cmdstan in develop. I assume this is a compiler thing, but maybe it is math somewhere. Can move the issue if that is the case.

@bob-carpenter
Copy link
Contributor

I think this may be related to the expression creating the vector. If you create an array without that expression logic, is there still a problem?

@bob-carpenter bob-carpenter added the bug Something isn't working label Mar 25, 2020
@bob-carpenter bob-carpenter added this to the 2.23.0 milestone Mar 25, 2020
@bbbales2
Copy link
Member Author

Same error with:

transformed data {
  vector[1] y;
  y[1] = 1.0;
}
...

And the error goes away with the statement:

y[1] ~ normal(mu, 1.0);

@bob-carpenter
Copy link
Contributor

Ah, I missed that the y[0] was indexing out of range. So definitely an error checking issue, not a construction of vectors issue. We need to catch the bad indexing to report an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants