stan-dev / stanc3

The Stan transpiler (from Stan to C++ and beyond).
BSD 3-Clause "New" or "Revised" License
140 stars 44 forks source link

model with declare/define for array of complex var fails to compile #1206

Closed mitzimorris closed 2 years ago

mitzimorris commented 2 years ago

Current Behavior:

CmdStanPy test model fails to compile with error:

ERROR    cmdstanpy:model.py:549 Stan program failed to compile:
WARNING  cmdstanpy:model.py:550 
--- Translating Stan model to C++ code ---
bin/stanc  --o=/Users/mitzi/github/stan-dev/cmdstanpy/test/data/complex_var.hpp /Users/mitzi/github/stan-dev/cmdstanpy/test/data/complex_var.stan
Syntax error in '/Users/mitzi/github/stan-dev/cmdstanpy/test/data/complex_var.stan', line 17, column 13 to column 20, parsing error:
   -------------------------------------------------
    15:    int a  = 1;
    16:    array[2,3,2] int ys = {{{3,0},{0,4}, {5,0}}, {{0,1}, {0,2}, {0,3}}};
    17:    array[2,3] complex zs = {{3,4i,5},{1i,2i,3i}};
                      ^
    18:    complex z = 3 + 4i;
    19:  
   -------------------------------------------------

Ill-formed phrase. Found L-value. This can be completed in many ways.
make: *** [make/program:47: /Users/mitzi/github/stan-dev/cmdstanpy/test/data/complex_var.hpp] Error 1

Command ['make', '/Users/mitzi/github/stan-dev/cmdstanpy/test/data/complex_var']
    error during processing No such file or directory
================================================================================== short test summary info ==================================================================================
FAILED test/test_sample.py::CmdStanMCMCTest::test_complex_output - ValueError: Unable to compile Stan model file: /Users/mitzi/github/stan-dev/cmdstanpy/test/data/complex_var.stan.

This test was added to CmdStanPy via PR https://github.com/stan-dev/cmdstanpy/pull/537

Expected Behavior:

Should compile

Model Code

transformed data {
   array[10] int<lower=0,upper=1> y = {0,1,0,0,0,0,0,0,0,1};
 }
 parameters {
   real<lower=0,upper=1> theta;
 }
 model {
   theta ~ beta(1,1);
   y ~ bernoulli(theta);
 }

 // model segment is just so that VB works

 generated quantities {
   int a  = 1;
   array[2,3,2] int ys = {{{3,0},{0,4}, {5,0}}, {{0,1}, {0,2}, {0,3}}};
   array[2,3] complex zs = {{3,4i,5},{1i,2i,3i}};
   complex z = 3 + 4i;

   array[2] int imag = {3,4};
 }

Environment:

MacOS 10.15.7 (Catalina) stanc3 e101bce (Unix) also fails for stanc3 distributed with 2.29.2

WardBrian commented 2 years ago

This model seems to compile on nightly: stancjs link

mitzimorris commented 2 years ago

OK, this is not the problem then - stanc definitely works. don't know where this error is coming from.