Skip to content

Commit

Permalink
adjust to new C++ types
Browse files Browse the repository at this point in the history
  • Loading branch information
tnagler committed Aug 20, 2024
1 parent 8fcd852 commit c7808c0
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions inst/include/kde1d-wrappers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,40 @@

namespace kde1d {

inline std::string wrap_var_type(const VarType& type)
{
if (type == VarType::continuous) {
return "continuous";
} else if (type == VarType::discrete) {
return "discrete";
} else if (type == VarType::zero_inflated) {
return "zero-inflated";
} else {
throw std::invalid_argument("Invalid type");
}
}

inline VarType wrap_var_type(const std::string& type)
{
if (type == "continuous") {
return VarType::continuous;
} else if (type == "discrete") {
return VarType::discrete;
} else if (type == "zero-inflated") {
return VarType::zero_inflated;
} else {
throw std::invalid_argument("Invalid type");
}
}

inline Rcpp::List kde1d_wrap(const Kde1d& kde1d_cpp)
{
auto kde1d_r = Rcpp::List::create(
Rcpp::Named("grid_points") = kde1d_cpp.get_grid_points(),
Rcpp::Named("values") = kde1d_cpp.get_values(),
Rcpp::Named("xmin") = kde1d_cpp.get_xmin(),
Rcpp::Named("xmax") = kde1d_cpp.get_xmax(),
Rcpp::Named("type") = kde1d_cpp.get_type(),
Rcpp::Named("type") = wrap_var_type(kde1d_cpp.get_type()),
Rcpp::Named("bw") = kde1d_cpp.get_bandwidth(),
Rcpp::Named("mult") = kde1d_cpp.get_multiplier(),
Rcpp::Named("deg") = kde1d_cpp.get_degree(),
Expand All @@ -28,7 +54,8 @@ inline Kde1d kde1d_wrap(const Rcpp::List& kde1d_r)
{
auto grid = interp::InterpolationGrid(
kde1d_r["grid_points"], kde1d_r["values"], 0);
return Kde1d(grid, kde1d_r["xmin"], kde1d_r["xmax"], kde1d_r["type"],
return Kde1d(grid, kde1d_r["xmin"], kde1d_r["xmax"],
wrap_var_type(static_cast<std::string>(kde1d_r["type"])),
kde1d_r["prob0"]);
}

Expand Down

0 comments on commit c7808c0

Please sign in to comment.