FIMS  v0.8.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// use isnan macro in math.h instead of TMB's isnan for fixing the r-cmd-check
21// issue
22#include <math.h>
23
24#include <TMB.hpp>
25
26// define REPORT, ADREPORT, and SIMULATE
27#define FIMS_REPORT_F(name, F) \
28 if (isDouble<Type>::value && \
29 F->current_parallel_region < static_cast<Type>(0)) { \
30 Rf_defineVar(Rf_install(#name), PROTECT(asSEXP(name)), F->report); \
31 UNPROTECT(1); \
32 }
33
34#define FIMS_REPORT_F_(name, obj, F) \
35 if (isDouble<Type>::value && \
36 F->current_parallel_region < static_cast<Type>(0)) { \
37 Rf_defineVar(Rf_install(name), PROTECT(asSEXP(obj)), F->report); \
38 UNPROTECT(1); \
39 }
40
41#define ADREPORT_F(name, F) F->reportvector.push(name, #name);
42
43template <typename Type>
44vector<Type> ADREPORTvector(vector<vector<Type> > x) {
45 int outer_dim = x.size();
46 int dim = 0;
47 for (int i = 0; i < outer_dim; i++) {
48 dim += x(i).size();
49 }
50 vector<Type> res(dim);
51 int idx = 0;
52 for (int i = 0; i < outer_dim; i++) {
53 int inner_dim = x(i).size();
54 for (int j = 0; j < inner_dim; j++) {
55 res(idx) = x(i)(j);
56 idx += 1;
57 }
58 }
59 return res;
60}
61
62#define FIMS_SIMULATE_F(F) if (isDouble<Type>::value && F->do_simulate)
63
64#endif /* TMB_MODEL */
65
66#ifndef TMB_MODEL
70#define FIMS_SIMULATE_F(F)
74#define FIMS_REPORT_F(name, F)
78#define ADREPORT_F(name, F)
79#endif
80
81#endif /* FIMS_INTERFACE_HPP */