stan-dev / stan

Stan development repository. The master branch contains the current release. The develop branch contains the latest stable development. See the Developer Process Wiki for details.
https://mc-stan.org
BSD 3-Clause "New" or "Revised" License
2.61k stars 369 forks source link

complex_vector assigment matching-size check sometimes broken #3199

Closed nhuurre closed 1 year ago

nhuurre commented 1 year ago
transformed parameters {
    complex_vector[2] eigVals = eigenvalues([[1,2],[3,4]]);
}

This model compiles but running it fails with exception

Unrecoverable error evaluating the log probability at the initial value.
Exception: vector assign columns: assigning variable eigVals (1) and right hand side columns (2) must match in size 

But the variable sizes are correct. It even works when placed inside an array:

transformed parameters {
    array[1] complex_vector[2] eigVals = {eigenvalues([[1,2],[3,4]])};
}

Current Version:

v2.32.2

WardBrian commented 1 year ago

I think that the issue may actually be that eigenvalues has the wrong return type in the Math library. The type is given as Eigen::Matrix<complex_return_t<value_type_t<EigMat>>, 1, -1>, which is a row vector.

@syclik and I went back and forth in https://github.com/stan-dev/math/pull/2846/ about whether or not to have the return type be auto, and then missed the fact that I wrote down the wrong type when I did explicitly write it out... oops