stan-dev/stanc3

[BUG] `transform_inits` code for complex numbers is incorrect.

WardBrian opened this issue · 0 comments

transform_inits_impl generates z = in__.read<local_scalar_t__>(); to read in a complex number z, but this should be z = in__.read<std::complex<local_scalar_t__>>();

The result is that z has a 0 imaginary component and subsequent parameters are read in from the wrong part of the buffer.

I have a partial fix (for scalars) in a branch https://github.com/stan-dev/stanc3/tree/fix/deserializer-read-containers. Containers requires some additional logic in one of the overloads of transform_inits

Model Code

Model which exhibits the issue
parameters {
   complex_vector[2] z ;//= [1+2i,3+4i]';
}
model {
   print(z);
}
{"z":[[1,2], [3,4]]}
./test_model sample num_warmup=1 num_samples=1 init=params.json

prints [(1,0),(3,0)]

Environment:

Stan 2.31.0