FIMS  v0.11.0
Loading...
Searching...
No Matches
interface.hpp
Go to the documentation of this file.
1
9#ifndef FIMS_INTERFACE_HPP
10#define FIMS_INTERFACE_HPP
11
12/*
13 * @brief Interface file. Uses pre-processing macros
14 * to interface with multiple modeling platforms.
15 */
16
17// traits for interfacing with TMB
18
19#ifdef TMB_MODEL
20
21// use isnan macro in math.h instead of TMB's isnan for fixing the r-cmd-check
22// issue
23#include <math.h>
24
25#include "TMB/TMB.h"
26
27// define REPORT, ADREPORT, and SIMULATE
28// F is nullptr when the model is evaluated outside of a TMB call, e.g., by
29// get_output(), and then there is no TMB object to report or simulate into.
30#define FIMS_REPORT_F(name, F) \
31 if (isDouble<Type>::value && F != nullptr && \
32 F->current_parallel_region < static_cast<Type>(0)) { \
33 Rf_defineVar(Rf_install(#name), PROTECT(asSEXP(name)), F->report); \
34 UNPROTECT(1); \
35 }
36
37#define FIMS_REPORT_F_(name, obj, F) \
38 if (isDouble<Type>::value && F != nullptr && \
39 F->current_parallel_region < static_cast<Type>(0)) { \
40 Rf_defineVar(Rf_install(name), PROTECT(asSEXP(obj)), F->report); \
41 UNPROTECT(1); \
42 }
43
44#define ADREPORT_F(name, F) \
45 if (F != nullptr) F->reportvector.push(name, #name);
46
47template <typename Type>
48vector<Type> ADREPORTvector(vector<vector<Type> > x) {
49 int outer_dim = x.size();
50 int dim = 0;
51 for (int i = 0; i < outer_dim; i++) {
52 dim += x(i).size();
53 }
54 vector<Type> res(dim);
55 int idx = 0;
56 for (int i = 0; i < outer_dim; i++) {
57 int inner_dim = x(i).size();
58 for (int j = 0; j < inner_dim; j++) {
59 res(idx) = x(i)(j);
60 idx += 1;
61 }
62 }
63 return res;
64}
65
66#define FIMS_SIMULATE_F(F) \
67 if (isDouble<Type>::value && F != nullptr && F->do_simulate)
68
69#endif /* TMB_MODEL */
70
71#ifndef TMB_MODEL
75#define FIMS_SIMULATE_F(F)
79#define FIMS_REPORT_F(name, F)
83#define ADREPORT_F(name, F)
84#endif
85
86#endif /* FIMS_INTERFACE_HPP */
Include this file to extract declarations only.