QR reparametrization error

I am trying to fit a linear model with N=1344 observation ad a matrix of predictors (N=1344 * K=2).

here’s my model

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);
}

The compilation stage fails with 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 

any advice?

Ok, maybe it helps (I have drawn some notion of fortran77 from some lost corner of my memory). I replaced the line:

Q_ast = qr_Q(x)[, 1:K] * sqrt(N - 1);

with

Q_ast = qr_Q(x)[, 1:K] * sqrt(1.0*N - 1);

and now the model compiles.

1 Like

The quick fix is instead of

use sqrt(N - 1.0). That should get around the compiler error.


Can you help us out?

  • what operating system are you on?
  • what version of Stan / RStan are you using?
  • what’s your compiler?
  • what’s in your makefile?

Hopefully we can figure out why this is happening.

1 Like

@syclik Maybe should I write something in “next_manual, 2.18” in github?
I am working on linux

sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 17.10

Matrix products: default                                                                                                                                                                                                                                                       
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1                                                                                                                                                                                                                          
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                               
locale:                                                                                                                                                                                                                                                                        
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C                                                                                                                                                                                                                                   
 [3] LC_TIME=it_IT.UTF-8        LC_COLLATE=en_US.UTF-8                                                                                                                                                                                                                         
 [5] LC_MONETARY=it_IT.UTF-8    LC_MESSAGES=en_US.UTF-8                                                                                                                                                                                                                        
 [7] LC_PAPER=it_IT.UTF-8       LC_NAME=C                                                                                                                                                                                                                                      
 [9] LC_ADDRESS=C               LC_TELEPHONE=C                                                                                                                                                                                                                                 
[11] LC_MEASUREMENT=it_IT.UTF-8 LC_IDENTIFICATION=C                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                               
attached base packages:                                                                                                                                                                                                                                                        
[1] stats     graphics  grDevices utils     datasets  methods   base                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                               
other attached packages:                                                                                                                                                                                                                                                       
[1] rstan_2.17.3       StanHeaders_2.17.2 ggplot2_2.2.1                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                               
loaded via a namespace (and not attached):                                                                                                                                                                                                                                     
 [1] Rcpp_0.12.15     grid_3.4.2       plyr_1.8.4       gtable_0.2.0                                                                                                                                                                                                           
 [5] stats4_3.4.2     scales_0.5.0     pillar_1.1.0     rlang_0.1.6                                                                                                                                                                                                            
 [9] lazyeval_0.2.1   munsell_0.4.3    compiler_3.4.2   inline_0.3.14                                                                                                                                                                                                          
[13] colorspace_1.3-2 gridExtra_2.3    tibble_1.4.2

compiler is GNU C++
rstan installed as in: the installation guide

No, this is a bug. It should work. We’d want to fix it for the next version.

Thanks a lot for the help!

1 Like

Which version of g++? It may be a g++ bug that we’re pushing on.

We’ll do our best to write our code to accommodate broken compilers, but we’ve got to know the version so we can test it out.

@syclik I really appreciate what are you doing for the STAN user base!
Here’s what I am using:

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.2.0-8ubuntu3.2' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.2.0 (Ubuntu 7.2.0-8ubuntu3.2) 

Thanks! That helps a lot. I’ll put up an issue on the Stan repo. Hopefully we can track it down by the next release.

Just a heads up, we don’t do much testing against g++ 7.x. If you find more compiler errors, please reach out before spending too much time on it.

btw, what’s your GitHub handle?

my username is zottelef but sadly I have no business on github for a long time. :-(

Thanks! I just put up the issue here: https://github.com/stan-dev/stan/issues/2478

1 Like