From e75d9a2f2c40d9574ab5ec282c2f03fdf32fd40c Mon Sep 17 00:00:00 2001 From: Davis Vaughan Date: Fri, 23 Aug 2024 13:46:34 -0400 Subject: [PATCH] Avoid implicit conversion from `sexp` to `double` --- src/create_connectivity.cpp | 2 +- src/distances.cpp | 4 ++-- src/generate_superpixels.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/create_connectivity.cpp b/src/create_connectivity.cpp index c7ff826..ebee87d 100644 --- a/src/create_connectivity.cpp +++ b/src/create_connectivity.cpp @@ -137,7 +137,7 @@ void Slic::create_connectivity(doubles_matrix<> vals, cpp11::function avg_fun_fu new_centers_vals[c_id][nval] = mean(new_c_id_centers_vals[nval]); } else if (avg_fun_name.empty()){ // use user-defined function - new_centers_vals[c_id][nval] = avg_fun_fun(new_c_id_centers_vals[nval]); + new_centers_vals[c_id][nval] = cpp11::as_cpp(avg_fun_fun(new_c_id_centers_vals[nval])); } } } diff --git a/src/distances.cpp b/src/distances.cpp index f6a41c8..5e7d8af 100644 --- a/src/distances.cpp +++ b/src/distances.cpp @@ -15,7 +15,7 @@ double get_vals_dist(vector& values1, vector& values2, } else if (dist_name != ""){ return custom_distance(values1, values2, dist_name); } else { - return dist_fun(values1, values2); + return cpp11::as_cpp(dist_fun(values1, values2)); } } @@ -125,5 +125,5 @@ double custom_distance(vector& values1, vector& values2, std::st double p = NA_REAL; bool testNA = false; std::string unit = "log2"; - return single_distance(values1, values2, dist_name, p, testNA, unit); + return cpp11::as_cpp(single_distance(values1, values2, dist_name, p, testNA, unit)); } diff --git a/src/generate_superpixels.cpp b/src/generate_superpixels.cpp index 84beb72..2878ece 100644 --- a/src/generate_superpixels.cpp +++ b/src/generate_superpixels.cpp @@ -106,7 +106,7 @@ void Slic::generate_superpixels(integers mat, doubles_matrix<> vals, double step } else if (avg_fun_name == "mean2"){ centers_vals[c_id][nval] = mean(centers_vals_c_id[nval]); } else if (avg_fun_name.empty()){ - centers_vals[c_id][nval] = avg_fun_fun(centers_vals_c_id[nval]); + centers_vals[c_id][nval] = cpp11::as_cpp(avg_fun_fun(centers_vals_c_id[nval])); } } }