Compiling error


#1

Hi There,

I am getting this error when I run this stan model - https://github.com/nzgwynn/Amelia (amaliaRStan.R and model.stan):

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from filef0543d59b9ee.cpp:8:
In file included from /Users/gwynn/Library/R/3.3/library/StanHeaders/include/src/stan/model/model_header.hpp:4:
In file included from /Users/gwynn/Library/R/3.3/library/StanHeaders/include/stan/math.hpp:4:
In file included from /Users/gwynn/Library/R/3.3/library/StanHeaders/include/stan/math/rev/mat.hpp:4:
In file included from /Users/gwynn/Library/R/3.3/library/StanHeaders/include/stan/math/rev/core.hpp:12:
In file included from /Users/gwynn/Library/R/3.3/library/StanHeaders/include/stan/math/rev/core/gevv_vvv_vari.hpp:5:
In file included from /Users/gwynn/Library/R/3.3/library/StanHeaders/include/stan/math/rev/core/var.hpp:7:
In file included from /Users/gwynn/Library/R/3.3/library/BH/include/boost/math/tools/config.hpp:13:
In file included from /Users/gwynn/Library/R/3.3/library/BH/include/boost/config.hpp:39:
/Users/gwynn/Library/R/3.3/library/BH/include/boost/config/compil
In addition: Warning message:
running command ‘/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB filef0543d59b9ee.cpp 2> filef0543d59b9ee.cpp.err.txt’ had status 1

Also:

sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X El Capitan 10.11.5

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] rstan_2.15.1 StanHeaders_2.15.0-1 ggplot2_2.2.1

loaded via a namespace (and not attached):
[1] Rcpp_0.12.9 codetools_0.2-15 assertthat_0.1 grid_3.3.2 plyr_1.8.4
[6] gtable_0.2.0 stats4_3.3.2 scales_0.4.1 lazyeval_0.2.0 tools_3.3.2
[11] munsell_0.4.3 parallel_3.3.2 inline_0.3.14 colorspace_1.3-2 gridExtra_2.2.1
[16] tibble_1.2

Does anyone have any suggestions?

Thanks,
gwynn


#2

Are you able to succsessfuly run the below code? If not it’s likely an issue with your toolchain, in which case see config notes here.

fx <- inline::cxxfunction( signature(x = "integer", y = "numeric" ) , '
	return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
' )
fx( 2L, 5 ) # should be 10

#3

Yes!! I got 10:

fx <- inline::cxxfunction( signature(x = “integer”, y = “numeric” ) , ’

  • return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
  •                        ' )
    

fx( 2L, 5 )
[1] 10

Will check the link you suggested…

Just to be clear, I should follow the instructions under the Configuration heading which starts with:
“This subsection is optional in the sense that RStan should work without it. Nevertheless, the following is strongly recommended.” Yes???


#4

I went to the link and ran these two bits of coding:

dotR <- file.path(Sys.getenv(“HOME”), “.R”)
if (!file.exists(dotR)) dir.create(dotR)
M <- file.path(dotR, “Makevars”)
if (!file.exists(M)) file.create(M)
cat("\nCXXFLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function",
file = M, sep = “\n”, append = TRUE)

and:

cat("\nCC=clang", “CXX=clang++ -arch x86_64 -ftemplate-depth-256”,
file = M, sep = “\n”, append = TRUE)

In addition, I ran this:

cat(readLines(M), sep = “\n”)

CXXFLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function

CC=clang
CXX=clang++ -arch x86_64 -ftemplate-depth-256.

I reran the model and got these errors:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from filef054415fc37f.cpp:8:
In file included from /Users/gwynn/Library/R/3.3/library/StanHeaders/include/src/stan/model/model_header.hpp:4:
In file included from /Users/gwynn/Library/R/3.3/library/StanHeaders/include/stan/math.hpp:4:
In file included from /Users/gwynn/Library/R/3.3/library/StanHeaders/include/stan/math/rev/mat.hpp:4:
In file included from /Users/gwynn/Library/R/3.3/library/StanHeaders/include/stan/math/rev/core.hpp:12:
In file included from /Users/gwynn/Library/R/3.3/library/StanHeaders/include/stan/math/rev/core/gevv_vvv_vari.hpp:5:
In file included from /Users/gwynn/Library/R/3.3/library/StanHeaders/include/stan/math/rev/core/var.hpp:7:
In file included from /Users/gwynn/Library/R/3.3/library/BH/include/boost/math/tools/config.hpp:13:
In file included from /Users/gwynn/Library/R/3.3/library/BH/include/boost/config.hpp:39:
/Users/gwynn/Library/R/3.3/library/BH/include/boost/config/compil
In addition: Warning message:
running command ‘/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB filef054415fc37f.cpp 2> filef054415fc37f.cpp.err.txt’ had status 1

I have run other survival analysis models by DW Bester that used RStan, but can’t seem to find them to link them.


#5

This is a parser bug because the generated C++ code doesn’t compile. @Bob_Carpenter should be able to track it down.

file7f767d87af5.cpp:557:32: error: no matching function for call to 'like'
                lp_accum__.add(like<propto__>(get_base1(TDX,i,"TDX",1), beta, gamma, 0.90000000000000002, 0.80000000000000004, pstream__));
                               ^~~~~~~~~~~~~~
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/services/util/initialize.hpp:114:39: note: in instantiation of function template specialization 'model7f73886e2d2_model_namespace::model7f73886e2d2_model::log_prob<false, true, double>' requested here
            log_prob = model.template log_prob<false, true>
                                      ^
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/services/diagnose/diagnose.hpp:54:19: note: in instantiation of function template specialization 'stan::services::util::initialize<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >' requested here
          = util::initialize(model, init, rng, init_radius,
                  ^
/usr/local/lib/R/site-library/rstan/include/rstan/stan_fit.hpp:459:45: note: in instantiation of function template specialization 'stan::services::diagnose::diagnose<model7f73886e2d2_model_namespace::model7f73886e2d2_model>' requested here
    return_code = stan::services::diagnose::diagnose(model,
                                            ^
/usr/local/lib/R/site-library/rstan/include/rstan/stan_fit.hpp:1200:11: note: in instantiation of function template specialization 'rstan::(anonymous namespace)::command<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >' requested here
    ret = command(args, model_, holder, names_oi_tidx_,
          ^
file7f767d87af5.cpp:731:116: note: in instantiation of member function 'rstan::stan_fit<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >::call_sampler' requested here
            &rstan::stan_fit<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::ecuyer1988>::call_sampler)
                                                                                                                   ^
file7f767d87af5.cpp:296:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'T0__'
like(const Eigen::Matrix<T0__, Eigen::Dynamic,1>& TDX,
^
file7f767d87af5.cpp:557:32: error: no matching function for call to 'like'
                lp_accum__.add(like<propto__>(get_base1(TDX,i,"TDX",1), beta, gamma, 0.90000000000000002, 0.80000000000000004, pstream__));
                               ^~~~~~~~~~~~~~
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/model/log_prob_grad.hpp:44:28: note: in instantiation of function template specialization 'model7f73886e2d2_model_namespace::model7f73886e2d2_model::log_prob<true, true, stan::math::var>' requested here
          = model.template log_prob<propto, jacobian_adjust_transform>
                           ^
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/services/util/initialize.hpp:147:37: note: in instantiation of function template specialization 'stan::model::log_prob_grad<true, true, model7f73886e2d2_model_namespace::model7f73886e2d2_model>' requested here
            log_prob = stan::model::log_prob_grad<true, true>
                                    ^
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/services/diagnose/diagnose.hpp:54:19: note: in instantiation of function template specialization 'stan::services::util::initialize<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >' requested here
          = util::initialize(model, init, rng, init_radius,
                  ^
/usr/local/lib/R/site-library/rstan/include/rstan/stan_fit.hpp:459:45: note: in instantiation of function template specialization 'stan::services::diagnose::diagnose<model7f73886e2d2_model_namespace::model7f73886e2d2_model>' requested here
    return_code = stan::services::diagnose::diagnose(model,
                                            ^
/usr/local/lib/R/site-library/rstan/include/rstan/stan_fit.hpp:1200:11: note: in instantiation of function template specialization 'rstan::(anonymous namespace)::command<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >' requested here
    ret = command(args, model_, holder, names_oi_tidx_,
          ^
file7f767d87af5.cpp:731:116: note: in instantiation of member function 'rstan::stan_fit<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >::call_sampler' requested here
            &rstan::stan_fit<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::ecuyer1988>::call_sampler)
                                                                                                                   ^
file7f767d87af5.cpp:296:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'T0__'
like(const Eigen::Matrix<T0__, Eigen::Dynamic,1>& TDX,
^
In file included from file7f767d87af5.cpp:720:
In file included from /usr/local/lib/R/site-library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /usr/local/lib/R/site-library/rstan/include/rstan/stan_fit.hpp:35:
In file included from /usr/local/lib/R/site-library/StanHeaders/include/src/stan/services/diagnose/diagnose.hpp:10:
In file included from /usr/local/lib/R/site-library/StanHeaders/include/src/stan/model/test_gradients.hpp:6:
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/model/finite_diff_grad.hpp:46:21: error: no matching member function for call to 'log_prob'
          .template log_prob<propto,
          ~~~~~~~~~~^~~~~~~~~~~~~~~~
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/model/test_gradients.hpp:62:7: note: in instantiation of function template specialization 'stan::model::finite_diff_grad<false, true, model7f73886e2d2_model_namespace::model7f73886e2d2_model>' requested here
      finite_diff_grad<false, true, Model>(model, interrupt, params_r, params_i,
      ^
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/services/diagnose/diagnose.hpp:61:26: note: in instantiation of function template specialization 'stan::model::test_gradients<true, true, model7f73886e2d2_model_namespace::model7f73886e2d2_model>' requested here
          = stan::model::test_gradients<true, true>(model, cont_vector,
                         ^
/usr/local/lib/R/site-library/rstan/include/rstan/stan_fit.hpp:459:45: note: in instantiation of function template specialization 'stan::services::diagnose::diagnose<model7f73886e2d2_model_namespace::model7f73886e2d2_model>' requested here
    return_code = stan::services::diagnose::diagnose(model,
                                            ^
/usr/local/lib/R/site-library/rstan/include/rstan/stan_fit.hpp:1200:11: note: in instantiation of function template specialization 'rstan::(anonymous namespace)::command<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >' requested here
    ret = command(args, model_, holder, names_oi_tidx_,
          ^
file7f767d87af5.cpp:731:116: note: in instantiation of member function 'rstan::stan_fit<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >::call_sampler' requested here
            &rstan::stan_fit<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::ecuyer1988>::call_sampler)
                                                                                                                   ^
file7f767d87af5.cpp:507:9: note: candidate template ignored: substitution failure [with propto__ = false, jacobian__ = true, T__ = double]
    T__ log_prob(vector<T__>& params_r__,
        ^
file7f767d87af5.cpp:575:8: note: candidate function template not viable: requires at most 2 arguments, but 3 were provided
    T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
       ^
In file included from file7f767d87af5.cpp:720:
In file included from /usr/local/lib/R/site-library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /usr/local/lib/R/site-library/rstan/include/rstan/stan_fit.hpp:35:
In file included from /usr/local/lib/R/site-library/StanHeaders/include/src/stan/services/diagnose/diagnose.hpp:10:
In file included from /usr/local/lib/R/site-library/StanHeaders/include/src/stan/model/test_gradients.hpp:6:
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/model/finite_diff_grad.hpp:52:21: error: no matching member function for call to 'log_prob'
          .template log_prob<propto,
          ~~~~~~~~~~^~~~~~~~~~~~~~~~
file7f767d87af5.cpp:507:9: note: candidate template ignored: substitution failure [with propto__ = false, jacobian__ = true, T__ = double]
    T__ log_prob(vector<T__>& params_r__,
        ^
file7f767d87af5.cpp:575:8: note: candidate function template not viable: requires at most 2 arguments, but 3 were provided
    T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
       ^
file7f767d87af5.cpp:557:32: error: no matching function for call to 'like'
                lp_accum__.add(like<propto__>(get_base1(TDX,i,"TDX",1), beta, gamma, 0.90000000000000002, 0.80000000000000004, pstream__));
                               ^~~~~~~~~~~~~~
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/services/optimize/newton.hpp:61:31: note: in instantiation of function template specialization 'model7f73886e2d2_model_namespace::model7f73886e2d2_model::log_prob<false, false, double>' requested here
          lp = model.template log_prob<false, false>(cont_vector, disc_vector,
                              ^
/usr/local/lib/R/site-library/rstan/include/rstan/stan_fit.hpp:480:35: note: in instantiation of function template specialization 'stan::services::optimize::newton<model7f73886e2d2_model_namespace::model7f73886e2d2_model>' requested here
      = stan::services::optimize::newton(model, *init_context_ptr,
                                  ^
/usr/local/lib/R/site-library/rstan/include/rstan/stan_fit.hpp:1200:11: note: in instantiation of function template specialization 'rstan::(anonymous namespace)::command<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >' requested here
    ret = command(args, model_, holder, names_oi_tidx_,
          ^
file7f767d87af5.cpp:731:116: note: in instantiation of member function 'rstan::stan_fit<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >::call_sampler' requested here
            &rstan::stan_fit<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::ecuyer1988>::call_sampler)
                                                                                                                   ^
file7f767d87af5.cpp:296:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'T0__'
like(const Eigen::Matrix<T0__, Eigen::Dynamic,1>& TDX,
^
file7f767d87af5.cpp:557:32: error: no matching function for call to 'like'
                lp_accum__.add(like<propto__>(get_base1(TDX,i,"TDX",1), beta, gamma, 0.90000000000000002, 0.80000000000000004, pstream__));
                               ^~~~~~~~~~~~~~
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/model/log_prob_grad.hpp:44:28: note: in instantiation of function template specialization 'model7f73886e2d2_model_namespace::model7f73886e2d2_model::log_prob<true, false, stan::math::var>' requested here
          = model.template log_prob<propto, jacobian_adjust_transform>
                           ^
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/optimization/newton.hpp:66:31: note: in instantiation of function template specialization 'stan::model::log_prob_grad<true, false, model7f73886e2d2_model_namespace::model7f73886e2d2_model>' requested here
            f1 = stan::model::log_prob_grad<true, false>(model,
                              ^
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/services/optimize/newton.hpp:102:36: note: in instantiation of function template specialization 'stan::optimization::newton_step<model7f73886e2d2_model_namespace::model7f73886e2d2_model>' requested here
          lp = stan::optimization::newton_step(model, cont_vector, disc_vector);
                                   ^
/usr/local/lib/R/site-library/rstan/include/rstan/stan_fit.hpp:480:35: note: in instantiation of function template specialization 'stan::services::optimize::newton<model7f73886e2d2_model_namespace::model7f73886e2d2_model>' requested here
      = stan::services::optimize::newton(model, *init_context_ptr,
                                  ^
/usr/local/lib/R/site-library/rstan/include/rstan/stan_fit.hpp:1200:11: note: in instantiation of function template specialization 'rstan::(anonymous namespace)::command<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >' requested here
    ret = command(args, model_, holder, names_oi_tidx_,
          ^
file7f767d87af5.cpp:731:116: note: in instantiation of member function 'rstan::stan_fit<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >::call_sampler' requested here
            &rstan::stan_fit<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::ecuyer1988>::call_sampler)
                                                                                                                   ^
file7f767d87af5.cpp:296:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'T0__'
like(const Eigen::Matrix<T0__, Eigen::Dynamic,1>& TDX,
^
file7f767d87af5.cpp:582:14: error: no matching member function for call to 'log_prob'
      return log_prob<propto,jacobian,T_>(vec_params_r, vec_params_i, pstream);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/model/model_functional.hpp:23:11: note: in instantiation of function template specialization 'model7f73886e2d2_model_namespace::model7f73886e2d2_model::log_prob<true, true, stan::math::var>' requested here
          log_prob<true, true, T>(const_cast<Eigen::Matrix<T, -1, 1>& >(x), o);
          ^
/usr/local/lib/R/site-library/StanHeaders/include/stan/math/rev/mat/functor/gradient.hpp:51:22: note: in instantiation of function template specialization 'stan::model::model_functional<model7f73886e2d2_model_namespace::model7f73886e2d2_model>::operator()<stan::math::var>' requested here
        var fx_var = f(x_var);
                     ^
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/model/gradient.hpp:31:21: note: in instantiation of function template specialization 'stan::math::gradient<stan::model::model_functional<model7f73886e2d2_model_namespace::model7f73886e2d2_model> >' requested here
        stan::math::gradient(model_functional<M>(model, &ss), x, f, grad_f);
                    ^
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/mcmc/hmc/hamiltonians/base_hamiltonian.hpp:69:24: note: in instantiation of function template specialization 'stan::model::gradient<model7f73886e2d2_model_namespace::model7f73886e2d2_model>' requested here
          stan::model::gradient(model_, z.q, z.V, z.g, logger);
                       ^
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/mcmc/hmc/integrators/expl_leapfrog.hpp:27:21: note: in instantiation of member function 'stan::mcmc::base_hamiltonian<model7f73886e2d2_model_namespace::model7f73886e2d2_model, stan::mcmc::dense_e_point, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >::update_potential_gradient' requested here
        hamiltonian.update_potential_gradient(z, logger);
                    ^
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/mcmc/hmc/integrators/expl_leapfrog.hpp:14:7: note: (skipping 4 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)
      expl_leapfrog()
      ^
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/services/sample/hmc_nuts_dense_e.hpp:79:11: note: in instantiation of member function 'stan::mcmc::dense_e_nuts<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >::dense_e_nuts' requested here
          sampler(model, rng);
          ^
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/services/sample/hmc_nuts_dense_e.hpp:136:16: note: in instantiation of function template specialization 'stan::services::sample::hmc_nuts_dense_e<model7f73886e2d2_model_namespace::model7f73886e2d2_model>' requested here
        return hmc_nuts_dense_e(model, init, unit_e_metric,
               ^
/usr/local/lib/R/site-library/rstan/include/rstan/stan_fit.hpp:602:13: note: in instantiation of function template specialization 'stan::services::sample::hmc_nuts_dense_e<model7f73886e2d2_model_namespace::model7f73886e2d2_model>' requested here
          ::hmc_nuts_dense_e(model, *init_context_ptr,
            ^
/usr/local/lib/R/site-library/rstan/include/rstan/stan_fit.hpp:1200:11: note: in instantiation of function template specialization 'rstan::(anonymous namespace)::command<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >' requested here
    ret = command(args, model_, holder, names_oi_tidx_,
          ^
file7f767d87af5.cpp:731:116: note: in instantiation of member function 'rstan::stan_fit<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >::call_sampler' requested here
            &rstan::stan_fit<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::ecuyer1988>::call_sampler)
                                                                                                                   ^
file7f767d87af5.cpp:507:9: note: candidate template ignored: substitution failure [with propto__ = true, jacobian__ = true, T__ = stan::math::var]
    T__ log_prob(vector<T__>& params_r__,
        ^
file7f767d87af5.cpp:575:8: note: candidate function template not viable: requires at most 2 arguments, but 3 were provided
    T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
       ^
file7f767d87af5.cpp:582:14: error: no matching member function for call to 'log_prob'
      return log_prob<propto,jacobian,T_>(vec_params_r, vec_params_i, pstream);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/variational/advi.hpp:114:47: note: in instantiation of function template specialization 'model7f73886e2d2_model_namespace::model7f73886e2d2_model::log_prob<false, true, double>' requested here
            double log_prob = model_.template log_prob<false, true>(zeta, &ss);
                                              ^
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/variational/advi.hpp:200:23: note: in instantiation of member function 'stan::variational::advi<model7f73886e2d2_model_namespace::model7f73886e2d2_model, stan::variational::normal_fullrank, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >::calc_ELBO' requested here
          elbo_init = calc_ELBO(variational, logger);
                      ^
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/variational/advi.hpp:497:17: note: in instantiation of member function 'stan::variational::advi<model7f73886e2d2_model_namespace::model7f73886e2d2_model, stan::variational::normal_fullrank, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >::adapt_eta' requested here
          eta = adapt_eta(variational, adapt_iterations, logger);
                ^
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/services/experimental/advi/fullrank.hpp:85:20: note: in instantiation of member function 'stan::variational::advi<model7f73886e2d2_model_namespace::model7f73886e2d2_model, stan::variational::normal_fullrank, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >::run' requested here
          cmd_advi.run(eta, adapt_engaged, adapt_iterations,
                   ^
/usr/local/lib/R/site-library/rstan/include/rstan/stan_fit.hpp:871:9: note: in instantiation of function template specialization 'stan::services::experimental::advi::fullrank<model7f73886e2d2_model_namespace::model7f73886e2d2_model>' requested here
      ::fullrank(model, *init_context_ptr,
        ^
/usr/local/lib/R/site-library/rstan/include/rstan/stan_fit.hpp:1200:11: note: in instantiation of function template specialization 'rstan::(anonymous namespace)::command<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >' requested here
    ret = command(args, model_, holder, names_oi_tidx_,
          ^
file7f767d87af5.cpp:731:116: note: in instantiation of member function 'rstan::stan_fit<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >::call_sampler' requested here
            &rstan::stan_fit<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::ecuyer1988>::call_sampler)
                                                                                                                   ^
file7f767d87af5.cpp:507:9: note: candidate template ignored: substitution failure [with propto__ = false, jacobian__ = true, T__ = double]
    T__ log_prob(vector<T__>& params_r__,
        ^
file7f767d87af5.cpp:575:8: note: candidate function template not viable: requires at most 2 arguments, but 3 were provided
    T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
       ^
In file included from file7f767d87af5.cpp:720:
In file included from /usr/local/lib/R/site-library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /usr/local/lib/R/site-library/rstan/include/rstan/stan_fit.hpp:52:
In file included from /usr/local/lib/R/site-library/StanHeaders/include/src/stan/services/experimental/advi/fullrank.hpp:11:
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/variational/advi.hpp:114:47: error: no matching member function for call to 'log_prob'
            double log_prob = model_.template log_prob<false, true>(zeta, &ss);
                              ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/variational/advi.hpp:200:23: note: in instantiation of member function 'stan::variational::advi<model7f73886e2d2_model_namespace::model7f73886e2d2_model, stan::variational::normal_meanfield, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >::calc_ELBO' requested here
          elbo_init = calc_ELBO(variational, logger);
                      ^
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/variational/advi.hpp:497:17: note: in instantiation of member function 'stan::variational::advi<model7f73886e2d2_model_namespace::model7f73886e2d2_model, stan::variational::normal_meanfield, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >::adapt_eta' requested here
          eta = adapt_eta(variational, adapt_iterations, logger);
                ^
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/services/experimental/advi/meanfield.hpp:85:20: note: in instantiation of member function 'stan::variational::advi<model7f73886e2d2_model_namespace::model7f73886e2d2_model, stan::variational::normal_meanfield, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >::run' requested here
          cmd_advi.run(eta, adapt_engaged, adapt_iterations,
                   ^
/usr/local/lib/R/site-library/rstan/include/rstan/stan_fit.hpp:881:9: note: in instantiation of function template specialization 'stan::services::experimental::advi::meanfield<model7f73886e2d2_model_namespace::model7f73886e2d2_model>' requested here
      ::meanfield(model, *init_context_ptr,
        ^
/usr/local/lib/R/site-library/rstan/include/rstan/stan_fit.hpp:1200:11: note: in instantiation of function template specialization 'rstan::(anonymous namespace)::command<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >' requested here
    ret = command(args, model_, holder, names_oi_tidx_,
          ^
file7f767d87af5.cpp:731:116: note: in instantiation of member function 'rstan::stan_fit<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >::call_sampler' requested here
            &rstan::stan_fit<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::ecuyer1988>::call_sampler)
                                                                                                                   ^
file7f767d87af5.cpp:507:9: note: candidate template ignored: could not match 'vector' against 'Matrix'
    T__ log_prob(vector<T__>& params_r__,
        ^
file7f767d87af5.cpp:575:8: note: candidate template ignored: substitution failure [with propto = false, jacobian = true, T_ = double]
    T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
       ^
In file included from file7f767d87af5.cpp:720:
In file included from /usr/local/lib/R/site-library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /usr/local/lib/R/site-library/rstan/include/rstan/stan_fit.hpp:36:
In file included from /usr/local/lib/R/site-library/StanHeaders/include/src/stan/services/optimize/bfgs.hpp:11:
In file included from /usr/local/lib/R/site-library/StanHeaders/include/src/stan/optimization/bfgs.hpp:5:
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/model/log_prob_propto.hpp:45:28: error: no matching member function for call to 'log_prob'
          = model.template log_prob<true, jacobian_adjust_transform>
            ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/lib/R/site-library/rstan/include/rstan/stan_fit.hpp:1121:40: note: in instantiation of function template specialization 'stan::model::log_prob_propto<true, model7f73886e2d2_model_namespace::model7f73886e2d2_model>' requested here
        return Rcpp::wrap(stan::model::log_prob_propto<true>(model_, par_r, par_i, &rstan::io::rcout));
                                       ^
file7f767d87af5.cpp:749:116: note: in instantiation of member function 'rstan::stan_fit<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >::log_prob' requested here
            &rstan::stan_fit<model7f73886e2d2_model_namespace::model7f73886e2d2_model, boost::random::ecuyer1988>::log_prob)
                                                                                                                   ^
file7f767d87af5.cpp:507:9: note: candidate template ignored: substitution failure [with propto__ = true, jacobian__ = true, T__ = stan::math::var]
    T__ log_prob(vector<T__>& params_r__,
        ^
file7f767d87af5.cpp:575:8: note: candidate function template not viable: requires at most 2 arguments, but 3 were provided
    T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
       ^

#6

That’s definitely a bug. I’m not sure why it’s even parsing in Stan because you should need an _lpdf suffix on like in order to use the ~ notation. I’ll look into it.

I’m moving it to an issue for Stan:

By the way, you don’t have to declare functions before using unless they’re recursive. They have to be declared before they are used.


#7

The problem is in your model. If you change the line with ~ like(...) to read

    target += like(TDX[i], beta, gamma, 0.9, 0.8);

it compiles fine. I don’t know why it was accepting the syntax with ~ without failing and giving you a warning message. I’m going to change the issue filed on this to reflect what it should be and simplify the example.

If you want to use the ~ syntax, you need to use

    TDX[i] ~ like(beta, gamma, 0.9, 0.8);

and define like as like_lpdf. Adding the _lpdf suffix lets Stan know it’s intended to be used like a probability function, so it will make sure it has a real return type and generate all the necessary trimmings for densities in Stan. You can also just use the target += and use it like a function. The end result will be exactly the same.

Thanks for reporting.


#8

Hi Bob,

Thanks for your support, the model runs now.

I’m a bit confused though as I based my model on one by D.W. Bester: https://github.com/nzgwynn/Amelia/blob/master/mystanmodel.stan, that uses the ~ syntax but not _lpdf or target. I found an error in my coding as the vector TDX should have [3] and not [2] next to it, but don’t suspect that was the issue. I just think you should know, in case there is a bigger issue.

gwynn


#9

Thanks. The issue is that we should be requiring _lpdf or _lpmf as a suffix on any density or mass function used in sampling notation.

The link you sent uses _log, which is the deprecated syntax from earlier versions of Stan that we’re still supporting. Support for _log suffixes will probably go away in Stan 3 (no idea when it’ll land; we’re still in disagreement about basic interface organization).


#10

Ahhhhh… Thanks!


#11

models.stan (7.1 KB)

Hi, I’m receiving a similar error after updating to Xcode 9. I then tried updating my R and RStan versions, but I’m still seeing this error when I compile the attached model (that had no problem compiling prior to Xcode 9). The only thing I can think is I remember, previously I used to get a warning related to the multi_normal line at the end, but I’m not sure why this error is now appearing instead of the warning:

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! In file included from file72f16fa7330c.cpp:8:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/src/stan/model/model_header.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/core.hpp:12:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/core/gevv_vvv_vari.hpp:5:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/core/var.hpp:7:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/B
In addition: Warning message:
running command '/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file72f16fa7330c.cpp 2> file72f16fa7330c.cpp.err.txt' had status 1 

#12

If you scroll up through the error messages farther you will see what the problem is. Basically, on line 28, you have

sqrt_Omega_k_ = sqrt(fabs(Omega_k_));

which you need to change to

sqrt_Omega_k_ = sqrt(fabs(Omega_k_ + 0.0));

At any given point in time, about a third of the compilers / compiler versions have ambiguities resolving the versions of the basic functions in the C++ math library, so you often have to give it a hint as to how it should handle things.


#13

Thanks, Ben. After updating my Rstan and R, and doing this, the model compiles!