Skip to content

Commit

Permalink
fix dtw export
Browse files Browse the repository at this point in the history
  • Loading branch information
M3nin0 committed Mar 3, 2024
1 parent fcd03a3 commit f5cf45b
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
8 changes: 8 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ C_temp_iqr <- function(mtx) {
.Call(`_sits_C_temp_iqr`, mtx)
}

rlang_env_unlock <- function(env) {
invisible(.Call(`_sits_rlang_env_unlock`, env))
}

rlang_env_lock <- function(env) {
invisible(.Call(`_sits_rlang_env_lock`, env))
}

sample_points_inclusion <- function(polymatrix, n_sam_pol) {
.Call(`_sits_sample_points_inclusion`, polymatrix, n_sam_pol)
}
Expand Down
22 changes: 22 additions & 0 deletions R/api_som.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
#' @title Register custom distances in the `kohonen` package environment.
#' @name .som_register_custom_distances
#' @keywords internal
#' @noRd
#' @author Felipe Carlos, \email{efelipecarlos@@gmail.com}
#'
#' @description This function injects custom distance functions in the
#' environment of the `kohonen` package.
#'
.som_register_custom_distances <- function() {
kohonen_namespace <- base::asNamespace("kohonen")

# unlock the environment
rlang_env_unlock(kohonen_namespace)

# include custom distances in the environment
base::assign("dtw", dtw, envir = kohonen_namespace)

# lock the environment
rlang_env_lock(kohonen_namespace)
}

#' @title Label neurons
#' @name .som_label_neurons
#' @keywords internal
Expand Down
2 changes: 2 additions & 0 deletions R/sits_som.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ sits_som_map <- function(data,
distance = "euclidean",
som_radius = 2,
mode = "online") {
# register custom distances
.som_register_custom_distances()
# set caller to show in errors
.check_set_caller("sits_som_map")
# verifies if kohonen package is installed
Expand Down
22 changes: 22 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,26 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// rlang_env_unlock
void rlang_env_unlock(SEXPREC* env);
RcppExport SEXP _sits_rlang_env_unlock(SEXP envSEXP) {
BEGIN_RCPP
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< SEXPREC* >::type env(envSEXP);
rlang_env_unlock(env);
return R_NilValue;
END_RCPP
}
// rlang_env_lock
void rlang_env_lock(SEXPREC* env);
RcppExport SEXP _sits_rlang_env_lock(SEXP envSEXP) {
BEGIN_RCPP
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< SEXPREC* >::type env(envSEXP);
rlang_env_lock(env);
return R_NilValue;
END_RCPP
}
// sample_points_inclusion
NumericMatrix sample_points_inclusion(const NumericMatrix& polymatrix, const int n_sam_pol);
RcppExport SEXP _sits_sample_points_inclusion(SEXP polymatrixSEXP, SEXP n_sam_polSEXP) {
Expand Down Expand Up @@ -669,6 +689,8 @@ static const R_CallMethodDef CallEntries[] = {
{"_sits_C_temp_sqr", (DL_FUNC) &_sits_C_temp_sqr, 1},
{"_sits_C_temp_tqr", (DL_FUNC) &_sits_C_temp_tqr, 1},
{"_sits_C_temp_iqr", (DL_FUNC) &_sits_C_temp_iqr, 1},
{"_sits_rlang_env_unlock", (DL_FUNC) &_sits_rlang_env_unlock, 1},
{"_sits_rlang_env_lock", (DL_FUNC) &_sits_rlang_env_lock, 1},
{"_sits_sample_points_inclusion", (DL_FUNC) &_sits_sample_points_inclusion, 2},
{"_sits_sample_points_crossings", (DL_FUNC) &_sits_sample_points_crossings, 2},
{"_sits_sample_points_bin", (DL_FUNC) &_sits_sample_points_bin, 2},
Expand Down
20 changes: 20 additions & 0 deletions src/rlang.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <Rcpp.h>

using namespace Rcpp;

/*
* These functions were extracted from the `rlang` package to avoid extra
* dependencies.
*/
#define FRAME_LOCK_MASK (1 << 14)
#define UNLOCK_FRAME(e) SET_ENVFLAGS(e, ENVFLAGS(e) & (~FRAME_LOCK_MASK))

// [[Rcpp::export]]
void rlang_env_unlock(SEXPREC* env) {
UNLOCK_FRAME(env);
}

// [[Rcpp::export]]
void rlang_env_lock(SEXPREC* env) {
UNLOCK_FRAME(env);
}

0 comments on commit f5cf45b

Please sign in to comment.