{"action":"created","issue":{"url":"https://api.github.com/repos/nimble-dev/nimble/issues/736","repository_url":"https://api.github.com/repos/nimble-dev/nimble","labels_url":"https://api.github.com/repos/nimble-dev/nimble/issues/736/labels{/name}","comments_url":"https://api.github.com/repos/nimble-dev/nimble/issues/736/comments","events_url":"https://api.github.com/repos/nimble-dev/nimble/issues/736/events","html_url":"https://github.com/nimble-dev/nimble/issues/736","id":328773070,"node_id":"MDU6SXNzdWUzMjg3NzMwNzA=","number":736,"title":"problem with using mcmc$run within another nimbleFunction","user":{"login":"paciorek","id":2501598,"node_id":"MDQ6VXNlcjI1MDE1OTg=","avatar_url":"https://avatars2.githubusercontent.com/u/2501598?v=4","gravatar_id":"","url":"https://api.github.com/users/paciorek","html_url":"https://github.com/paciorek","followers_url":"https://api.github.com/users/paciorek/followers","following_url":"https://api.github.com/users/paciorek/following{/other_user}","gists_url":"https://api.github.com/users/paciorek/gists{/gist_id}","starred_url":"https://api.github.com/users/paciorek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paciorek/subscriptions","organizations_url":"https://api.github.com/users/paciorek/orgs","repos_url":"https://api.github.com/users/paciorek/repos","events_url":"https://api.github.com/users/paciorek/events{/privacy}","received_events_url":"https://api.github.com/users/paciorek/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2018-06-02T20:04:19Z","updated_at":"2018-06-06T22:00:01Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"I'm trying to run an MCMC in the run function of another nimbleFunction but there is some sort of type issue with the samplerExecutionOrder argument. @perrydv any thoughts?\r\n\r\n```\r\nsamples <- matrix(rep(1,8), nrow=2, ncol=4)\r\ncolnames(samples) <- c('a[1]','a[2]','b[1]','b[2]')\r\n\r\nlittersCode <- nimbleCode({\r\n  for (i in 1:G) {\r\n     for (j in 1:N) {\r\n        # likelihood (data model)\r\n        r[i,j] ~ dbin(p[i,j], n[i,j])\r\n        # latent process (random effects)\r\n        p[i,j] ~ dbeta(a[i], b[i]) \r\n     }\r\n     # prior for hyperparameters\r\n     a[i] ~ dgamma(1, .001)\r\n     b[i] ~ dgamma(1, .001)\r\n   }\r\n})\r\n\r\n## @knitr litters-model\r\n\r\nG <- 2\r\nN <- 16\r\nn <- matrix(c(13, 12, 12, 11, 9, 10, \r\n              9, 9, 8, 11, 8, 10, 13, 10, 12, 9, 10, 9, 10, 5, 9, 9, 13, \r\n              7, 5, 10, 7, 6, 10, 10, 10, 7), nrow = 2)\r\nr <- matrix(c(13, 12, 12, 11, 9, 10, 9, 9, 8, 10, 8, 9, \r\n     12, 9, 11, 8, 9, 8, 9, 4, 8, 7, 11, 4, 4, 5, 5, 3, 7, 3, 7, 0), \r\n     nrow = 2)\r\n              \r\nlittersConsts <- list(G = G, N = N, n = n)\r\nlittersData <- list(r = r)\r\nlittersInits <- list( a = c(2, 2), b=c(2, 2) )\r\n\r\nlittersModel <- nimbleModel(littersCode, \r\n          data = littersData, constants = littersConsts, inits = littersInits)\r\ncLittersModel <- compileNimble(littersModel)\r\n\r\n\r\nmargSampler <- nimbleFunction(\r\n            setup = function(full_model, samples, target) {\r\n                  ## setup MCMC only for integrated-over nodes\r\n                  conf <- configureMCMC(full_model, nodes = target)\r\n                  margModelVars <- full_model$getVarNames(nodes = dimnames(samples)[[2]])\r\n                  \r\n                  ## create MCMC object and modelValues for full model\r\n                  mcmc <- buildMCMC(conf)\r\n                  new_mv = modelValues(full_model, m = 1)\r\n            }, run = function(samples = double(2)) {\r\n                  nIts <- dim(samples)[1]\r\n                  resize(new_mv, nIts)\r\n\r\n                  ## sample integrated-over nodes once per thinned iteration of original MCMC\r\n                  for(i in 1:nIts) {\r\n                      values(full_model, margModelVars) <<- samples[i, ]\r\n                      mcmc$run(1, reset = FALSE, progressBar = FALSE)\r\n                      copy(full_model, new_mv, row = i)\r\n                  }\r\n            })\r\n                 \r\nrMargSampler <- margSampler(littersModel, samples, 'p')\r\ncMargSampler <- compileNimble(rMargSampler, project = littersModel, showCompilerOutput=T)\r\n```\r\n\r\nCompiler error is below. In the generated C++, we have:\r\n\r\nInterm95 (i.e., the samplerExecutionOrder argument) is a double that is set to -1 based on the defaults, whereas the MCMC run signature is\r\n\r\nvoid  run ( int ARG1_niter_, bool ARG2_reset_, bool ARG3_simulateAll_, bool ARG4_time_, bool ARG5_progressBar_, int ARG6_thin_, int ARG7_thin2_, NimArr<1, int> & ARG8_samplerExecutionOrder_ );\r\n\r\n```\r\ng++ -std=gnu++11 -I/usr/share/R/include -DNDEBUG -DR_NO_REMAP   -DEIGEN_MPL2_ONLY=1 -I\"/accounts/gen/vis/paciorek/R/x86_64-pc-linux-gnu-library/3.4/nimble/include\" -Wno-misleading-indentation -Wno-ignored-attributes -Wno-deprecated-declarations     -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c P_3_nfRefClass_R_GlobalEnv48.cpp -o P_3_nfRefClass_R_GlobalEnv48.o\r\nP_3_nfRefClass_R_GlobalEnv48.cpp: In member function ‘void nfRefClass_R_GlobalEnv48::run(NimArr<2, double>&)’:\r\nP_3_nfRefClass_R_GlobalEnv48.cpp:698:76: error: invalid initialization of non-const reference of type ‘NimArr<1, int>&’ from an rvalue of type ‘NimArr<1, int>’\r\n  (*mcmc).run(1, false, false, false, false, Interm_93, Interm_94, Interm_95);\r\n                                                                            ^\r\nIn file included from /accounts/gen/vis/paciorek/R/x86_64-pc-linux-gnu-library/3.4/nimble/include/nimble/RcppNimbleUtils.h:25:0,\r\n                 from /accounts/gen/vis/paciorek/R/x86_64-pc-linux-gnu-library/3.4/nimble/include/nimble/NamedObjects.h:28,\r\n                 from /accounts/gen/vis/paciorek/R/x86_64-pc-linux-gnu-library/3.4/nimble/include/nimble/EigenTypedefs.h:26,\r\n                 from P_3_nfRefClass_R_GlobalEnv48.cpp:6:\r\n/accounts/gen/vis/paciorek/R/x86_64-pc-linux-gnu-library/3.4/nimble/include/nimble/NimArr.h:276:3: note:   after user-defined conversion: NimArr<1, T>::NimArr(int) [with T = int]\r\n   NimArr<1, T>(int is1) : NimArrBase<T>() { setSize(is1); }\r\n   ^\r\nP_3_nfRefClass_R_GlobalEnv48.cpp:332:7: note:   initializing argument 8 of ‘void MCMC::run(int, bool, bool, bool, bool, int, int, NimArr<1, int>&)’\r\n void  MCMC::run ( int ARG1_niter_, bool ARG2_reset_, bool ARG3_simulateAll_, bool ARG4_time_, bool ARG5_progressBar_, int ARG6_thin_, int ARG7_thin2_, NimArr<1, int> \r\n```\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/nimble-dev/nimble/issues/comments/395227904","html_url":"https://github.com/nimble-dev/nimble/issues/736#issuecomment-395227904","issue_url":"https://api.github.com/repos/nimble-dev/nimble/issues/736","id":395227904,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NTIyNzkwNA==","user":{"login":"paciorek","id":2501598,"node_id":"MDQ6VXNlcjI1MDE1OTg=","avatar_url":"https://avatars2.githubusercontent.com/u/2501598?v=4","gravatar_id":"","url":"https://api.github.com/users/paciorek","html_url":"https://github.com/paciorek","followers_url":"https://api.github.com/users/paciorek/followers","following_url":"https://api.github.com/users/paciorek/following{/other_user}","gists_url":"https://api.github.com/users/paciorek/gists{/gist_id}","starred_url":"https://api.github.com/users/paciorek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paciorek/subscriptions","organizations_url":"https://api.github.com/users/paciorek/orgs","repos_url":"https://api.github.com/users/paciorek/repos","events_url":"https://api.github.com/users/paciorek/events{/privacy}","received_events_url":"https://api.github.com/users/paciorek/received_events","type":"User","site_admin":false},"created_at":"2018-06-06T22:00:01Z","updated_at":"2018-06-06T22:00:01Z","author_association":"CONTRIBUTOR","body":"Perfect, thanks much @danielturek "}}
{"actor":{"display_login":"paciorek"}}