Cannot use complex variable type

Hi All,

I am unable to use variable types complex, complex_vector or complex_matrix. When I try to define a variable with complex type by typing, e.g.,

complex z = -1.1 + 2.3i;

the error message that shows up is “Variable “complex” does not exist”.

Any ideas what I’m missing? I am using cmdstanr 0.6.1, with CmdStan version 2.32.2. My R version is 4.1.3.

Thanks a lot!

1 Like

I don’t see why that wouldn’t work with CmdStan 2.32.2. Can you share the full Stan program? Or better yet a minimal reproducible example (simple program that yields this error)? What you have should work but maybe the error is due to the context in which you’re declaring it, but it’s hard to say without seeing the rest of the code.

Hi jonah,

Thanks for your response! I think I’ve figured out what the problem was: the error only shows up in my R editor while I’m writing the Stan program, but when I try to compile, the Stan program compiles properly. So I can use complex numbers just fine, it’s just a bit annoying that “complex” doesn’t seem to be recognised by the editor so that syntax highlighting is a bit wonky.

On a related note – is there a function to compute the inverse of a complex matrix? I’ve looked through the documentation and there is an operator / to do B / A, which does B * inverse(A), but what I need is either just inverse(B) or inverse(B) * A.

There is not yet a function to do that in our math library, see Complex support for more linear algebra functions · Issue #2699 · stan-dev/math · GitHub