/
interface.cpp
103 lines (96 loc) · 2.95 KB
/
interface.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* -*- compile-command: "R CMD INSTALL .." -*- */
#include "modelSelection.h"
#include "modelSelectionFwd.h"
#include "modelSelectionQuadratic.h"
#include "largestContinuousMinimum.h"
#include <R.h>
#include <R_ext/Rdynload.h>
void largestContinuousMinimum_interface
(int *n_data, double *cost_vec, double *size_vec, int *index_vec){
int status = largestContinuousMinimum
(*n_data, cost_vec, size_vec, index_vec);
if(status==ERROR_SIZES_MUST_BE_POSITIVE){
error("sizes must be positive");
}
if(status != 0){
error("error code %d", status);
}
}
void modelSelection_interface
(double *loss, double *complexity, int *n_models,
int *before, double *lambda
){
int status = modelSelection(loss, complexity, *n_models, before, lambda);
if(status == ERROR_LOSS_NOT_DECREASING){
error("loss not decreasing");
}
if(status == ERROR_COMPLEXITY_NOT_INCREASING){
error("complexity not increasing");
}
if(status != 0){
error("error code %d", status);
}
}
void modelSelectionFwd_interface
(double *loss_vec, double *complexity_vec, int *n_models,
int *selected_model_vec, double *selected_penalty_vec,
int *loop_eval_vec
){
int status = modelSelectionFwd
(loss_vec, complexity_vec, n_models,
selected_model_vec, selected_penalty_vec, loop_eval_vec);
if(status == ERROR_FWD_LOSS_NOT_DECREASING){
error("loss not decreasing");
}
if(status == ERROR_FWD_COMPLEXITY_NOT_INCREASING){
error("complexity not increasing");
}
if(status != 0){
error("error code %d", status);
}
}
void modelSelectionQuadratic_interface
(double *loss_vec, double *complexity_vec, int *n_models,
int *selected_model_vec, double *selected_penalty_vec
){
int status = modelSelectionQuadratic
(loss_vec, complexity_vec, n_models,
selected_model_vec, selected_penalty_vec);
if(status == ERROR_QUAD_LOSS_NOT_DECREASING){
error("loss not decreasing");
}
if(status == ERROR_QUAD_COMPLEXITY_NOT_INCREASING){
error("complexity not increasing");
}
if(status != 0){
error("error code %d", status);
}
}
R_CMethodDef cMethods[] = {
{"modelSelectionQuadratic_interface",
(DL_FUNC) &modelSelectionQuadratic_interface, 5
//,{REALSXP, REALSXP, INTSXP, INTSXP, REALSXP}
},
{"modelSelectionFwd_interface",
(DL_FUNC) &modelSelectionFwd_interface, 6
//,{REALSXP, REALSXP, INTSXP, INTSXP, REALSXP}
},
{"modelSelection_interface",
(DL_FUNC) &modelSelection_interface, 5
//,{REALSXP, REALSXP, INTSXP, INTSXP, REALSXP}
},
{"largestContinuousMinimum_interface",
(DL_FUNC) &largestContinuousMinimum_interface, 4
//,{INTSXP, REALSXP, REALSXP, INTSXP}
},
{NULL, NULL, 0}
};
extern "C" {
void R_init_penaltyLearning(DllInfo *info) {
R_registerRoutines(info, cMethods, NULL, NULL, NULL);
//R_useDynamicSymbols call says the DLL is not to be searched for
//entry points specified by character strings so .C etc calls will
//only find registered symbols.
R_useDynamicSymbols(info, FALSE);
}
}