Nimble model compilation error: ‘T’ was not declared in this scope

8 views
Skip to first unread message

Chris Carleton

unread,
May 30, 2023, 7:37:57 AMMay 30
to nimble-users
Hi All,

I'm trying to write a nimble model using custom distributions. I get the following error :

```
...
Compiling
  [Note] This may take a minute.
  [Note] Use 'showCompilerOutput = TRUE' to see C++ compilation details.
Error: Failed to create the shared library. Run 'printErrors()' to see the compilation errors.
In addition: Warning messages:
1: variable 'T' has not been created yet.
2: variable 'T' has not been created yet.
> printErrors()
using C++ compiler: ‘g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0’
P_1_code_MID_1_nfCode.cpp: In function ‘double rcFun_R_GlobalEnv5(double, double, double, NimArr<2, double>&, int)’:
P_1_code_MID_1_nfCode.cpp:318:49: error: ‘T’ was not declared in this scope
  318 |  logProb = dnorm(Interm_27, ARG1_x_, Interm_28, T);
          |                                                                                           ^
P_1_code_MID_1_nfCode.cpp:323:50: error: ‘T’ was not declared in this scope
  323 |  logProb = dnorm(curve_mean, ARG1_x_, Interm_29, T);
          |                                                                                              ^
make: *** [/usr/lib/R/etc/Makeconf:200: P_1_code_MID_1_nfCode.o] Error 1
```

I have attached the code here. I've tried removing and re-installing the package, both from CRAN and GitHub directly. Any ideas would be greatly appreciated. The custom distribution and the related function for sampling from it are performing outside nimble as expected.

Sincerely,
Chris
nimble_help.R

Chris Carleton

unread,
May 30, 2023, 8:02:07 AMMay 30
to nimble-users
Hi Everyone again,

I just solved it. Sorry for the rapid emails. It was a dumb mistake, but I guess I'll post the solution here in case it helps someone else. For reasons not relevant here, I am calling dnorm from within the custom distribution and tried passing 'log = T'. But, that doesn't work (I don' think 'T' is defined in base c++ for booleans), which is why (I guess obviously to people with brains) the documentation uses "log = integer(0, default = 0)" instead in the examples. I've changed my function definition to "dnorm(..., log = 1)" and that seems to work.

Sheepishly,
Chris

Perry de Valpine

unread,
May 30, 2023, 11:01:40 AMMay 30
to Chris Carleton, nimble-users
Hi Chris,
Thanks for the message and follow-up! It's totally understandable and we are always looking for additional error-trapping we can do, so it is helpful to see this.
Perry


--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/9886ecaa-2be9-4681-a0fc-aaec4dccdc38n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages