stan: "call of overloaded ‘sqrt(int)’ is ambiguous" using g++ 7.2.0
Summary:
A valid Stan program is failing to C++ compile on Linux using g++ 7.2.0.
This is failing from RStan, so we need to see if it’s a Stan problem or an RStan problem.
(Originally reported by @zottelef on Discourse: http://discourse.mc-stan.org/t/qr-reparametrization-error/3426/9)
Description:
This program generates C++ code and then fails to compile.
data {
int<lower=0> N;
int<lower=0> K; //number of fixed effects
matrix[N, K] x;
vector[N] y;
}
transformed data {
matrix[N, K] Q_ast;
Q_ast = qr_Q(x)[, 1:K] * sqrt(N - 1);
}
parameters {
real alpha; //intercept
vector[K] theta;
real<lower=0> sigma;
}
model {
y ~ normal(Q_ast * theta + alpha, sigma);
}
Reproducible Steps:
We need to determine if this is an RStan or a Stan problem. This error was reported using:
- OS: linux
- compiler: g++ 7.2.0
- interface: rstan 2.17.3 run from R 3.4.3
Current Output:
The relevant part of the compiler error is:
error: call of overloaded ‘sqrt(int)’ is ambiguous
stan::math::assign(Q_ast, multiply(stan::model::rvalue(qr_Q(x), stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_min_max(1, K), stan::model::nil_index_list())), "qr_Q(x)"),sqrt((N - 1))));
Here’s the rest of the reported compiler error:
file25053f4922a5.cpp:130:240: error: call of overloaded ‘sqrt(int)’ is ambiguous
stan::math::assign(Q_ast, multiply(stan::model::rvalue(qr_Q(x), stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_min_max(1, K), stan::model::nil_index_list())), "qr_Q(x)"),sqrt((N - 1))));
...
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! file25053f4922a5.cpp: In member function ‘void model250526cfdfd_climateTAVG_namespace::model250526cfdfd_climateTAVG::ctor_body(stan::io::var_context&, unsigned int, std::ostream*)’:
file25053f4922a5.cpp:130:240: error: call of overloaded ‘sqrt(int)’ is ambiguous
stan::math::assign(Q_ast, multiply(stan::model::rvalue(qr_Q(x), stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_min_max(1, K), stan::model::nil_index_list())), "qr_Q(x)"),sqrt((N - 1))));
^
In file included from /usr/include/features.h:419:0,
from /usr/include/x86_64-linux-gnu/bits/libc-header-start.h:33,
from /usr/include/stdint.h:
In addition: Warning message:
running command '/usr/lib/R/bin/R CMD SHLIB file25053f4922a5.cpp 2> file25053f4922a5.cpp.err.txt' had status 1
Expected Output:
No error.
Current Version:
v2.17.1
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 19 (16 by maintainers)
Thank you!