You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Stan crashes (segfaults?) if a data tuple containing a vector gets "deconstructed", "reconstructed" in nested functions without data annotations which also take parameter arguments and then the values of the vector get accessed. #1534
While working around stan-dev/math#3041, I've encountered the above issue.
My workaround for reduce_sum's inability to take tuple arguments was to first "deconstruct" (flatten) them before passing them to reduce_sum, and then to "reconstruct" (restore the old non-flat structure) them before passing them to the original function.
This however lead to segfaults. The following is AFAICT a minimal reproducer:
functions {
void do_something_reconstruct_deconstruct(tuple(array[] int, vector) combined, real x){
do_something_reconstruct(combined.1, combined.2, x);
}
void do_something_reconstruct(array[] int indices, vector mem, real x){
do_something((indices, mem), x);
}
void do_something(tuple(array[] int, vector) combined, real x){
print(combined.1); // This is fineprint(size(combined.2)); // This is fineprint(combined); // This crashes// print(combined.2); // This crashes// print(sum(combined.2)); // This crashes
}
}
transformed data {
int n =2;
array[n] int indices =rep_array(0, n);
vector[n] mem =rep_vector(0., n);
tuple(array[n] int, vector[n]) combined = (indices, mem);
print(combined);
do_something_reconstruct_deconstruct(combined, 1.);
}
parameters {
real x;
}
model {
x ~std_normal();
print(2);
// This is fine
do_something_reconstruct_deconstruct(combined, 1.);
print(3);
// This is fine
do_something_reconstruct_deconstruct(combined, 1.);
print(4);
// This crashes
do_something_reconstruct_deconstruct(combined, x);
print(5);
// This crashes
do_something_reconstruct_deconstruct(combined, x);
}