Skip to content

Commit b5003d8

Browse files
author
dirmeier
committed
Externalized some neighbors.cpp code to own functions for readability
1 parent 1aef3bc commit b5003d8

File tree

5 files changed

+357
-206
lines changed

5 files changed

+357
-206
lines changed

src/RcppExports.cpp

Lines changed: 153 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,38 @@
1010
using namespace Rcpp;
1111

1212
// heat_diffusion_
13-
Eigen::MatrixXd heat_diffusion_(const Eigen::MatrixXd& v0, const Eigen::MatrixXd& W, const double t);
14-
static SEXP _diffusr_heat_diffusion__try(SEXP v0SEXP, SEXP WSEXP, SEXP tSEXP) {
15-
BEGIN_RCPP
16-
Rcpp::RObject rcpp_result_gen;
17-
Rcpp::traits::input_parameter< const Eigen::MatrixXd& >::type v0(v0SEXP);
18-
Rcpp::traits::input_parameter< const Eigen::MatrixXd& >::type W(WSEXP);
19-
Rcpp::traits::input_parameter< const double >::type t(tSEXP);
13+
Eigen::MatrixXd heat_diffusion_(const Eigen::MatrixXd& v0,
14+
const Eigen::MatrixXd& W,
15+
const double t);
16+
static SEXP _diffusr_heat_diffusion__try(SEXP v0SEXP, SEXP WSEXP, SEXP tSEXP)
17+
{
18+
BEGIN_RCPP
19+
Rcpp::RObject rcpp_result_gen;
20+
Rcpp::traits::input_parameter<const Eigen::MatrixXd&>::type v0(v0SEXP);
21+
Rcpp::traits::input_parameter<const Eigen::MatrixXd&>::type W(WSEXP);
22+
Rcpp::traits::input_parameter<const double>::type t(tSEXP);
2023
rcpp_result_gen = Rcpp::wrap(heat_diffusion_(v0, W, t));
2124
return rcpp_result_gen;
22-
END_RCPP_RETURN_ERROR
25+
END_RCPP_RETURN_ERROR
2326
}
24-
RcppExport SEXP _diffusr_heat_diffusion_(SEXP v0SEXP, SEXP WSEXP, SEXP tSEXP) {
27+
RcppExport SEXP _diffusr_heat_diffusion_(SEXP v0SEXP, SEXP WSEXP, SEXP tSEXP)
28+
{
2529
SEXP rcpp_result_gen;
2630
{
2731
Rcpp::RNGScope rcpp_rngScope_gen;
28-
rcpp_result_gen = PROTECT(_diffusr_heat_diffusion__try(v0SEXP, WSEXP, tSEXP));
32+
rcpp_result_gen =
33+
PROTECT(_diffusr_heat_diffusion__try(v0SEXP, WSEXP, tSEXP));
2934
}
30-
Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
31-
if (rcpp_isInterrupt_gen) {
35+
Rboolean rcpp_isInterrupt_gen =
36+
Rf_inherits(rcpp_result_gen, "interrupted-error");
37+
if (rcpp_isInterrupt_gen)
38+
{
3239
UNPROTECT(1);
3340
Rf_onintr();
3441
}
3542
Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
36-
if (rcpp_isError_gen) {
43+
if (rcpp_isError_gen)
44+
{
3745
SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
3846
UNPROTECT(1);
3947
Rf_error(CHAR(rcpp_msgSEXP_gen));
@@ -43,27 +51,32 @@ RcppExport SEXP _diffusr_heat_diffusion_(SEXP v0SEXP, SEXP WSEXP, SEXP tSEXP) {
4351
}
4452
// stoch_col_norm_
4553
Eigen::MatrixXd stoch_col_norm_(const Eigen::MatrixXd& W);
46-
static SEXP _diffusr_stoch_col_norm__try(SEXP WSEXP) {
47-
BEGIN_RCPP
48-
Rcpp::RObject rcpp_result_gen;
49-
Rcpp::traits::input_parameter< const Eigen::MatrixXd& >::type W(WSEXP);
54+
static SEXP _diffusr_stoch_col_norm__try(SEXP WSEXP)
55+
{
56+
BEGIN_RCPP
57+
Rcpp::RObject rcpp_result_gen;
58+
Rcpp::traits::input_parameter<const Eigen::MatrixXd&>::type W(WSEXP);
5059
rcpp_result_gen = Rcpp::wrap(stoch_col_norm_(W));
5160
return rcpp_result_gen;
52-
END_RCPP_RETURN_ERROR
61+
END_RCPP_RETURN_ERROR
5362
}
54-
RcppExport SEXP _diffusr_stoch_col_norm_(SEXP WSEXP) {
63+
RcppExport SEXP _diffusr_stoch_col_norm_(SEXP WSEXP)
64+
{
5565
SEXP rcpp_result_gen;
5666
{
5767
Rcpp::RNGScope rcpp_rngScope_gen;
5868
rcpp_result_gen = PROTECT(_diffusr_stoch_col_norm__try(WSEXP));
5969
}
60-
Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
61-
if (rcpp_isInterrupt_gen) {
70+
Rboolean rcpp_isInterrupt_gen =
71+
Rf_inherits(rcpp_result_gen, "interrupted-error");
72+
if (rcpp_isInterrupt_gen)
73+
{
6274
UNPROTECT(1);
6375
Rf_onintr();
6476
}
6577
Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
66-
if (rcpp_isError_gen) {
78+
if (rcpp_isError_gen)
79+
{
6780
SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
6881
UNPROTECT(1);
6982
Rf_error(CHAR(rcpp_msgSEXP_gen));
@@ -73,27 +86,32 @@ RcppExport SEXP _diffusr_stoch_col_norm_(SEXP WSEXP) {
7386
}
7487
// laplacian_
7588
Eigen::MatrixXd laplacian_(const Eigen::MatrixXd& W);
76-
static SEXP _diffusr_laplacian__try(SEXP WSEXP) {
77-
BEGIN_RCPP
78-
Rcpp::RObject rcpp_result_gen;
79-
Rcpp::traits::input_parameter< const Eigen::MatrixXd& >::type W(WSEXP);
89+
static SEXP _diffusr_laplacian__try(SEXP WSEXP)
90+
{
91+
BEGIN_RCPP
92+
Rcpp::RObject rcpp_result_gen;
93+
Rcpp::traits::input_parameter<const Eigen::MatrixXd&>::type W(WSEXP);
8094
rcpp_result_gen = Rcpp::wrap(laplacian_(W));
8195
return rcpp_result_gen;
82-
END_RCPP_RETURN_ERROR
96+
END_RCPP_RETURN_ERROR
8397
}
84-
RcppExport SEXP _diffusr_laplacian_(SEXP WSEXP) {
98+
RcppExport SEXP _diffusr_laplacian_(SEXP WSEXP)
99+
{
85100
SEXP rcpp_result_gen;
86101
{
87102
Rcpp::RNGScope rcpp_rngScope_gen;
88103
rcpp_result_gen = PROTECT(_diffusr_laplacian__try(WSEXP));
89104
}
90-
Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
91-
if (rcpp_isInterrupt_gen) {
105+
Rboolean rcpp_isInterrupt_gen =
106+
Rf_inherits(rcpp_result_gen, "interrupted-error");
107+
if (rcpp_isInterrupt_gen)
108+
{
92109
UNPROTECT(1);
93110
Rf_onintr();
94111
}
95112
Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
96-
if (rcpp_isError_gen) {
113+
if (rcpp_isError_gen)
114+
{
97115
SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
98116
UNPROTECT(1);
99117
Rf_error(CHAR(rcpp_msgSEXP_gen));
@@ -102,33 +120,55 @@ RcppExport SEXP _diffusr_laplacian_(SEXP WSEXP) {
102120
return rcpp_result_gen;
103121
}
104122
// mrwr_
105-
Eigen::MatrixXd mrwr_(const Eigen::MatrixXd& p0, const Eigen::MatrixXd& W, const double r, const double thresh, const int niter, const bool do_analytical);
106-
static SEXP _diffusr_mrwr__try(SEXP p0SEXP, SEXP WSEXP, SEXP rSEXP, SEXP threshSEXP, SEXP niterSEXP, SEXP do_analyticalSEXP) {
107-
BEGIN_RCPP
108-
Rcpp::RObject rcpp_result_gen;
109-
Rcpp::traits::input_parameter< const Eigen::MatrixXd& >::type p0(p0SEXP);
110-
Rcpp::traits::input_parameter< const Eigen::MatrixXd& >::type W(WSEXP);
111-
Rcpp::traits::input_parameter< const double >::type r(rSEXP);
112-
Rcpp::traits::input_parameter< const double >::type thresh(threshSEXP);
113-
Rcpp::traits::input_parameter< const int >::type niter(niterSEXP);
114-
Rcpp::traits::input_parameter< const bool >::type do_analytical(do_analyticalSEXP);
123+
Eigen::MatrixXd mrwr_(const Eigen::MatrixXd& p0,
124+
const Eigen::MatrixXd& W,
125+
const double r,
126+
const double thresh,
127+
const int niter,
128+
const bool do_analytical);
129+
static SEXP _diffusr_mrwr__try(SEXP p0SEXP,
130+
SEXP WSEXP,
131+
SEXP rSEXP,
132+
SEXP threshSEXP,
133+
SEXP niterSEXP,
134+
SEXP do_analyticalSEXP)
135+
{
136+
BEGIN_RCPP
137+
Rcpp::RObject rcpp_result_gen;
138+
Rcpp::traits::input_parameter<const Eigen::MatrixXd&>::type p0(p0SEXP);
139+
Rcpp::traits::input_parameter<const Eigen::MatrixXd&>::type W(WSEXP);
140+
Rcpp::traits::input_parameter<const double>::type r(rSEXP);
141+
Rcpp::traits::input_parameter<const double>::type thresh(threshSEXP);
142+
Rcpp::traits::input_parameter<const int>::type niter(niterSEXP);
143+
Rcpp::traits::input_parameter<const bool>::type do_analytical(
144+
do_analyticalSEXP);
115145
rcpp_result_gen = Rcpp::wrap(mrwr_(p0, W, r, thresh, niter, do_analytical));
116146
return rcpp_result_gen;
117-
END_RCPP_RETURN_ERROR
147+
END_RCPP_RETURN_ERROR
118148
}
119-
RcppExport SEXP _diffusr_mrwr_(SEXP p0SEXP, SEXP WSEXP, SEXP rSEXP, SEXP threshSEXP, SEXP niterSEXP, SEXP do_analyticalSEXP) {
149+
RcppExport SEXP _diffusr_mrwr_(SEXP p0SEXP,
150+
SEXP WSEXP,
151+
SEXP rSEXP,
152+
SEXP threshSEXP,
153+
SEXP niterSEXP,
154+
SEXP do_analyticalSEXP)
155+
{
120156
SEXP rcpp_result_gen;
121157
{
122158
Rcpp::RNGScope rcpp_rngScope_gen;
123-
rcpp_result_gen = PROTECT(_diffusr_mrwr__try(p0SEXP, WSEXP, rSEXP, threshSEXP, niterSEXP, do_analyticalSEXP));
159+
rcpp_result_gen = PROTECT(_diffusr_mrwr__try(
160+
p0SEXP, WSEXP, rSEXP, threshSEXP, niterSEXP, do_analyticalSEXP));
124161
}
125-
Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
126-
if (rcpp_isInterrupt_gen) {
162+
Rboolean rcpp_isInterrupt_gen =
163+
Rf_inherits(rcpp_result_gen, "interrupted-error");
164+
if (rcpp_isInterrupt_gen)
165+
{
127166
UNPROTECT(1);
128167
Rf_onintr();
129168
}
130169
Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
131-
if (rcpp_isError_gen) {
170+
if (rcpp_isError_gen)
171+
{
132172
SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
133173
UNPROTECT(1);
134174
Rf_error(CHAR(rcpp_msgSEXP_gen));
@@ -137,30 +177,39 @@ RcppExport SEXP _diffusr_mrwr_(SEXP p0SEXP, SEXP WSEXP, SEXP rSEXP, SEXP threshS
137177
return rcpp_result_gen;
138178
}
139179
// neighbors_
140-
Rcpp::List neighbors_(const Rcpp::IntegerVector& node_idxs, const Rcpp::NumericMatrix& W, const int k);
141-
static SEXP _diffusr_neighbors__try(SEXP node_idxsSEXP, SEXP WSEXP, SEXP kSEXP) {
142-
BEGIN_RCPP
180+
Rcpp::List neighbors_(const Rcpp::IntegerVector& node_idxs,
181+
const Rcpp::NumericMatrix& W,
182+
const int k);
183+
static SEXP _diffusr_neighbors__try(SEXP node_idxsSEXP, SEXP WSEXP, SEXP kSEXP)
184+
{
185+
BEGIN_RCPP
143186
Rcpp::RObject rcpp_result_gen;
144-
Rcpp::traits::input_parameter< const Rcpp::IntegerVector& >::type node_idxs(node_idxsSEXP);
145-
Rcpp::traits::input_parameter< const Rcpp::NumericMatrix& >::type W(WSEXP);
146-
Rcpp::traits::input_parameter< const int >::type k(kSEXP);
187+
Rcpp::traits::input_parameter<const Rcpp::IntegerVector&>::type node_idxs(
188+
node_idxsSEXP);
189+
Rcpp::traits::input_parameter<const Rcpp::NumericMatrix&>::type W(WSEXP);
190+
Rcpp::traits::input_parameter<const int>::type k(kSEXP);
147191
rcpp_result_gen = Rcpp::wrap(neighbors_(node_idxs, W, k));
148192
return rcpp_result_gen;
149-
END_RCPP_RETURN_ERROR
193+
END_RCPP_RETURN_ERROR
150194
}
151-
RcppExport SEXP _diffusr_neighbors_(SEXP node_idxsSEXP, SEXP WSEXP, SEXP kSEXP) {
195+
RcppExport SEXP _diffusr_neighbors_(SEXP node_idxsSEXP, SEXP WSEXP, SEXP kSEXP)
196+
{
152197
SEXP rcpp_result_gen;
153198
{
154199
Rcpp::RNGScope rcpp_rngScope_gen;
155-
rcpp_result_gen = PROTECT(_diffusr_neighbors__try(node_idxsSEXP, WSEXP, kSEXP));
200+
rcpp_result_gen =
201+
PROTECT(_diffusr_neighbors__try(node_idxsSEXP, WSEXP, kSEXP));
156202
}
157-
Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
158-
if (rcpp_isInterrupt_gen) {
203+
Rboolean rcpp_isInterrupt_gen =
204+
Rf_inherits(rcpp_result_gen, "interrupted-error");
205+
if (rcpp_isInterrupt_gen)
206+
{
159207
UNPROTECT(1);
160208
Rf_onintr();
161209
}
162210
Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
163-
if (rcpp_isError_gen) {
211+
if (rcpp_isError_gen)
212+
{
164213
SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
165214
UNPROTECT(1);
166215
Rf_error(CHAR(rcpp_msgSEXP_gen));
@@ -170,40 +219,62 @@ RcppExport SEXP _diffusr_neighbors_(SEXP node_idxsSEXP, SEXP WSEXP, SEXP kSEXP)
170219
}
171220

172221
// validate (ensure exported C++ functions exist before calling them)
173-
static int _diffusr_RcppExport_validate(const char* sig) {
222+
static int _diffusr_RcppExport_validate(const char* sig)
223+
{
174224
static std::set<std::string> signatures;
175-
if (signatures.empty()) {
176-
signatures.insert("Eigen::MatrixXd(*heat_diffusion_)(const Eigen::MatrixXd&,const Eigen::MatrixXd&,const double)");
177-
signatures.insert("Eigen::MatrixXd(*stoch_col_norm_)(const Eigen::MatrixXd&)");
178-
signatures.insert("Eigen::MatrixXd(*laplacian_)(const Eigen::MatrixXd&)");
179-
signatures.insert("Eigen::MatrixXd(*mrwr_)(const Eigen::MatrixXd&,const Eigen::MatrixXd&,const double,const double,const int,const bool)");
180-
signatures.insert("Rcpp::List(*neighbors_)(const Rcpp::IntegerVector&,const Rcpp::NumericMatrix&,const int)");
225+
if (signatures.empty())
226+
{
227+
signatures.insert("Eigen::MatrixXd(*heat_diffusion_)(const "
228+
"Eigen::MatrixXd&,const Eigen::MatrixXd&,const "
229+
"double)");
230+
signatures.insert(
231+
"Eigen::MatrixXd(*stoch_col_norm_)(const Eigen::MatrixXd&)");
232+
signatures.insert(
233+
"Eigen::MatrixXd(*laplacian_)(const Eigen::MatrixXd&)");
234+
signatures.insert("Eigen::MatrixXd(*mrwr_)(const "
235+
"Eigen::MatrixXd&,const Eigen::MatrixXd&,const "
236+
"double,const double,const int,const bool)");
237+
signatures.insert("Rcpp::List(*neighbors_)(const "
238+
"Rcpp::IntegerVector&,const "
239+
"Rcpp::NumericMatrix&,const int)");
181240
}
182241
return signatures.find(sig) != signatures.end();
183242
}
184243

185244
// registerCCallable (register entry points for exported C++ functions)
186-
RcppExport SEXP _diffusr_RcppExport_registerCCallable() {
187-
R_RegisterCCallable("diffusr", "_diffusr_heat_diffusion_", (DL_FUNC)_diffusr_heat_diffusion__try);
188-
R_RegisterCCallable("diffusr", "_diffusr_stoch_col_norm_", (DL_FUNC)_diffusr_stoch_col_norm__try);
189-
R_RegisterCCallable("diffusr", "_diffusr_laplacian_", (DL_FUNC)_diffusr_laplacian__try);
190-
R_RegisterCCallable("diffusr", "_diffusr_mrwr_", (DL_FUNC)_diffusr_mrwr__try);
191-
R_RegisterCCallable("diffusr", "_diffusr_neighbors_", (DL_FUNC)_diffusr_neighbors__try);
192-
R_RegisterCCallable("diffusr", "_diffusr_RcppExport_validate", (DL_FUNC)_diffusr_RcppExport_validate);
245+
RcppExport SEXP _diffusr_RcppExport_registerCCallable()
246+
{
247+
R_RegisterCCallable("diffusr",
248+
"_diffusr_heat_diffusion_",
249+
(DL_FUNC)_diffusr_heat_diffusion__try);
250+
R_RegisterCCallable("diffusr",
251+
"_diffusr_stoch_col_norm_",
252+
(DL_FUNC)_diffusr_stoch_col_norm__try);
253+
R_RegisterCCallable(
254+
"diffusr", "_diffusr_laplacian_", (DL_FUNC)_diffusr_laplacian__try);
255+
R_RegisterCCallable(
256+
"diffusr", "_diffusr_mrwr_", (DL_FUNC)_diffusr_mrwr__try);
257+
R_RegisterCCallable(
258+
"diffusr", "_diffusr_neighbors_", (DL_FUNC)_diffusr_neighbors__try);
259+
R_RegisterCCallable("diffusr",
260+
"_diffusr_RcppExport_validate",
261+
(DL_FUNC)_diffusr_RcppExport_validate);
193262
return R_NilValue;
194263
}
195264

196265
static const R_CallMethodDef CallEntries[] = {
197-
{"_diffusr_heat_diffusion_", (DL_FUNC) &_diffusr_heat_diffusion_, 3},
198-
{"_diffusr_stoch_col_norm_", (DL_FUNC) &_diffusr_stoch_col_norm_, 1},
199-
{"_diffusr_laplacian_", (DL_FUNC) &_diffusr_laplacian_, 1},
200-
{"_diffusr_mrwr_", (DL_FUNC) &_diffusr_mrwr_, 6},
201-
{"_diffusr_neighbors_", (DL_FUNC) &_diffusr_neighbors_, 3},
202-
{"_diffusr_RcppExport_registerCCallable", (DL_FUNC) &_diffusr_RcppExport_registerCCallable, 0},
203-
{NULL, NULL, 0}
204-
};
266+
{"_diffusr_heat_diffusion_", (DL_FUNC)&_diffusr_heat_diffusion_, 3},
267+
{"_diffusr_stoch_col_norm_", (DL_FUNC)&_diffusr_stoch_col_norm_, 1},
268+
{"_diffusr_laplacian_", (DL_FUNC)&_diffusr_laplacian_, 1},
269+
{"_diffusr_mrwr_", (DL_FUNC)&_diffusr_mrwr_, 6},
270+
{"_diffusr_neighbors_", (DL_FUNC)&_diffusr_neighbors_, 3},
271+
{"_diffusr_RcppExport_registerCCallable",
272+
(DL_FUNC)&_diffusr_RcppExport_registerCCallable,
273+
0},
274+
{NULL, NULL, 0}};
205275

206-
RcppExport void R_init_diffusr(DllInfo *dll) {
276+
RcppExport void R_init_diffusr(DllInfo* dll)
277+
{
207278
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
208279
R_useDynamicSymbols(dll, FALSE);
209280
}

0 commit comments

Comments
 (0)