FIMS  v0.9.2
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.hpp>
26
27// define REPORT, ADREPORT, and SIMULATE
28#define FIMS_REPORT_F(name, F) \
29 if (isDouble<Type>::value && \
30 F->current_parallel_region < static_cast<Type>(0)) { \
31 Rf_defineVar(Rf_install(#name), PROTECT(asSEXP(name)), F->report); \
32 UNPROTECT(1); \
33 }
34
35#define FIMS_REPORT_F_(name, obj, F) \
36 if (isDouble<Type>::value && \
37 F->current_parallel_region < static_cast<Type>(0)) { \
38 Rf_defineVar(Rf_install(name), PROTECT(asSEXP(obj)), F->report); \
39 UNPROTECT(1); \
40 }
41
42#define ADREPORT_F(name, F) F->reportvector.push(name, #name);
43
44template <typename Type>
45vector<Type> ADREPORTvector(vector<vector<Type> > x) {
46 int outer_dim = x.size();
47 int dim = 0;
48 for (int i = 0; i < outer_dim; i++) {
49 dim += x(i).size();
50 }
51 vector<Type> res(dim);
52 int idx = 0;
53 for (int i = 0; i < outer_dim; i++) {
54 int inner_dim = x(i).size();
55 for (int j = 0; j < inner_dim; j++) {
56 res(idx) = x(i)(j);
57 idx += 1;
58 }
59 }
60 return res;
61}
62
63#define FIMS_SIMULATE_F(F) if (isDouble<Type>::value && F->do_simulate)
64
65#endif /* TMB_MODEL */
66
67#ifndef TMB_MODEL
71#define FIMS_SIMULATE_F(F)
75#define FIMS_REPORT_F(name, F)
79#define ADREPORT_F(name, F)
80#endif
81
82#endif /* FIMS_INTERFACE_HPP */