-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #217 from schalkdaniel/add_arg_handlers
add handler
- Loading branch information
Showing
5 changed files
with
179 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
.handleRcpp_PolynomialBlearner = function (degree = 1, intercept = TRUE, ...) { | ||
|
||
nuisance = list(...) | ||
if (length(nuisance) > 0) { | ||
warning("Following arguments are ignored by the polynomial base-learner: ", paste(names(nuisance), collapse = ", ")) | ||
} | ||
params = list(degree = degree, intercept = intercept) | ||
|
||
return (params) | ||
} | ||
|
||
.handleRcpp_PSplineBlearner = function (degree = 3, n.knots = 20, penalty = 2, differences = 2, ...) { | ||
|
||
nuisance = list(...) | ||
if (length(nuisance) > 0) { | ||
warning("Following arguments are ignored by the spline base-learner: ", paste(names(nuisance), collapse = ", ")) | ||
} | ||
params = list(degree = degree, n.knots = n.knots, penalty = penalty, differences = differences) | ||
|
||
return (params) | ||
} | ||
|
||
.handleRcpp_CustomBlearner = function (instantiate.fun, train.fun, predict.fun, param.fun, ...) { | ||
|
||
nuisance = list(...) | ||
if (length(nuisance) > 0) { | ||
warning("Following arguments are ignored by the custom base-learner: ", paste(names(nuisance), collapse = ", ")) | ||
} | ||
params = list(instantiate.fun = instantiate.fun, train.fun = train.fun, predict.fun = predict.fun, param.fun = param.fun) | ||
|
||
return (params) | ||
} | ||
|
||
.handleRcpp_CustomCppBlearner = function (instantiate.ptr, train.ptr, predict.ptr, ...) { | ||
|
||
nuisance = list(...) | ||
if (length(nuisance) > 0) { | ||
warning("Following arguments are ignored by the custom cpp base-learner: ", paste(names(nuisance), collapse = ", ")) | ||
} | ||
params = list(instantiate.ptr = instantiate.ptr, train.ptr = train.ptr, predict.ptr = predict.ptr) | ||
|
||
return (params) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
library(Rcpp) | ||
library(inline) | ||
|
||
fx <- inline::cxxfunction(signature(), plugin="Rcpp", include=readLines("other/module_test.cpp")) | ||
|
||
## assumes fx_unif <- cxxfunction(...) ran | ||
unif_module <- Module("unif_module", getDynLib(fx)) | ||
Uniform <- unif_module$Uniform | ||
|
||
Uniform@fields | ||
|
||
u <- new(Uniform, 0, 10) | ||
u$draw(10L) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using namespace Rcpp; | ||
class Uniform { | ||
public: | ||
Uniform(double min_, double max_) : | ||
min(min_), max(max_) {} | ||
NumericVector draw(int n) const { | ||
RNGScope scope; | ||
return runif(n, min, max); | ||
} | ||
double min, max; | ||
double degree = 1; | ||
// Rcpp::List mylist = Rcpp::List::create(Rcpp::Named("degree") = 1, | ||
// Rcpp::Named("intercept") = TRUE); | ||
}; | ||
|
||
double uniformRange(Uniform* w) { | ||
return w->max - w->min; | ||
} | ||
|
||
double getDefaults () { | ||
return 1.1; | ||
} | ||
|
||
RCPP_MODULE(unif_module) { | ||
class_<Uniform>("Uniform") | ||
.constructor<double,double>() | ||
.field("min", &Uniform::min) | ||
.field("max", &Uniform::max) | ||
.field("degree", &Uniform::degree) | ||
.method("draw", &Uniform::draw) | ||
.method("range", &uniformRange) | ||
; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters