Skip to content

Commit

Permalink
Merge pull request #10 from stscl/dev
Browse files Browse the repository at this point in the history
make rcmd check clean
  • Loading branch information
SpatLyu authored Dec 17, 2024
2 parents d8b8f9f + 3a5953e commit 8f4b6f5
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 59 deletions.
16 changes: 8 additions & 8 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

IC_SSH <- function(d, s, bin_method) {
.Call(`_sshicm_IC_SSH`, d, s, bin_method)
RcppINSSH <- function(d, s) {
.Call(`_sshicm_RcppINSSH`, d, s)
}

IC_SSHICM <- function(d, s, seed, permutation_number, bin_method = "Sturges") {
.Call(`_sshicm_IC_SSHICM`, d, s, seed, permutation_number, bin_method)
RcppINSSHICM <- function(d, s, seed, permutation_number) {
.Call(`_sshicm_RcppINSSHICM`, d, s, seed, permutation_number)
}

IN_SSH <- function(d, s) {
.Call(`_sshicm_IN_SSH`, d, s)
RcppICSSH <- function(d, s, bin_method = "Sturges") {
.Call(`_sshicm_RcppICSSH`, d, s, bin_method)
}

IN_SSHICM <- function(d, s, seed, permutation_number) {
.Call(`_sshicm_IN_SSHICM`, d, s, seed, permutation_number)
RcppICSSHICM <- function(d, s, seed, permutation_number, bin_method = "Sturges") {
.Call(`_sshicm_RcppICSSHICM`, d, s, seed, permutation_number, bin_method)
}

6 changes: 2 additions & 4 deletions R/sshic.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
#' @export
#'
#' @examples
#' \donttest{
#' # This code may take a bit longer to execute:
#' baltim = sf::read_sf(system.file("extdata/baltim.gpkg",package = "sshicm"))
#' sshic(baltim$PRICE,baltim$DWELL)
#' }
#'
sshic = \(d, s, seed = 42, permutation_number = 999, bin_method = "Sturges") {
s = as.integer(as.factor(s))
res = IC_SSHICM(d,s,seed,permutation_number,bin_method)
res = RcppICSSHICM(d,s,seed,permutation_number,bin_method)
names(res) = c("Ic","Pv")
return(res)
}
2 changes: 1 addition & 1 deletion R/sshicm.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' @export
#'
#' @examples
#' \donttest{
#' \dontrun{
#' # This code may take a bit longer to execute:
#' baltim = sf::read_sf(system.file("extdata/baltim.gpkg",package = "sshicm"))
#' sshicm(PRICE ~ .,baltim,type = "IC")
Expand Down
6 changes: 2 additions & 4 deletions R/sshin.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
#' @export
#'
#' @examples
#' \donttest{
#' # This code may take a bit longer to execute:
#' cinc = sf::read_sf(system.file("extdata/cinc.gpkg",package = "sshicm"))
#' sshin(cinc$THEFT_D,cinc$MALE)
#' }
#'
sshin = \(d, s, seed = 42, permutation_number = 999) {
d = as.integer(as.factor(d))
s = as.integer(as.factor(s))
res = IN_SSHICM(d,s,seed,permutation_number)
res = RcppINSSHICM(d,s,seed,permutation_number)
names(res) = c("In","Pv")
return(res)
}
4 changes: 1 addition & 3 deletions man/sshic.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/sshicm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions man/sshin.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/IC_SSH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// [[Rcpp::depends(RcppThread)]]

// Compute IC_SSH
// [[Rcpp::export]]
double IC_SSH(const std::vector<double>& d,
const std::vector<int>& s,
const std::string& bin_method) {
Expand Down Expand Up @@ -52,7 +51,6 @@ double IC_SSH(const std::vector<double>& d,
}

// IC_SSHICM: Parallel computation of IC_SSH over permutations, returning IC value and p-value
// [[Rcpp::export]]
std::vector<double> IC_SSHICM(const std::vector<double>& d,
const std::vector<int>& s,
unsigned int seed,
Expand Down
27 changes: 27 additions & 0 deletions src/IC_SSH.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef IC_SSH_H
#define IC_SSH_H

#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <random>
#include <cmath>
#include <algorithm>
#include <stdexcept>
#include <numeric>
#include "HistogramDensityEst.h"
#include "RelEntropy.h"
#include <RcppThread.h>

double IC_SSH(const std::vector<double>& d,
const std::vector<int>& s,
const std::string& bin_method);

std::vector<double> IC_SSHICM(const std::vector<double>& d,
const std::vector<int>& s,
unsigned int seed,
int permutation_number,
const std::string& bin_method = "Sturges");

#endif // IC_SSH_H
2 changes: 0 additions & 2 deletions src/IN_SSH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ double ComputeConditionalEntropy(const std::map<int, double>& marginal_probabili
}

// Function to compute IN_SSH
// [[Rcpp::export]]
double IN_SSH(const std::vector<int>& d, const std::vector<int>& s) {
if (d.size() != s.size()) {
throw std::invalid_argument("Vectors d and s must have the same length.");
Expand Down Expand Up @@ -120,7 +119,6 @@ double IN_SSH(const std::vector<int>& d, const std::vector<int>& s) {
}

// IN_SSHICM: Parallel computation of IN_SSH over permutations, returning IN_SSH value and p-value
// [[Rcpp::export]]
std::vector<double> IN_SSHICM(const std::vector<int>& d,
const std::vector<int>& s,
unsigned int seed,
Expand Down
22 changes: 22 additions & 0 deletions src/IN_SSH.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef IN_SSH_H
#define IN_SSH_H

#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <random>
#include <stdexcept>
#include <RcppThread.h>

double IN_SSH(const std::vector<int>& d,
const std::vector<int>& s);

std::vector<double> IN_SSHICM(const std::vector<int>& d,
const std::vector<int>& s,
unsigned int seed,
int permutation_number);

#endif // IN_SSH_H
60 changes: 30 additions & 30 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,66 +11,66 @@ Rcpp::Rostream<true>& Rcpp::Rcout = Rcpp::Rcpp_cout_get();
Rcpp::Rostream<false>& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
#endif

// IC_SSH
double IC_SSH(const std::vector<double>& d, const std::vector<int>& s, const std::string& bin_method);
RcppExport SEXP _sshicm_IC_SSH(SEXP dSEXP, SEXP sSEXP, SEXP bin_methodSEXP) {
// RcppINSSH
double RcppINSSH(Rcpp::IntegerVector d, Rcpp::IntegerVector s);
RcppExport SEXP _sshicm_RcppINSSH(SEXP dSEXP, SEXP sSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const std::vector<double>& >::type d(dSEXP);
Rcpp::traits::input_parameter< const std::vector<int>& >::type s(sSEXP);
Rcpp::traits::input_parameter< const std::string& >::type bin_method(bin_methodSEXP);
rcpp_result_gen = Rcpp::wrap(IC_SSH(d, s, bin_method));
Rcpp::traits::input_parameter< Rcpp::IntegerVector >::type d(dSEXP);
Rcpp::traits::input_parameter< Rcpp::IntegerVector >::type s(sSEXP);
rcpp_result_gen = Rcpp::wrap(RcppINSSH(d, s));
return rcpp_result_gen;
END_RCPP
}
// IC_SSHICM
std::vector<double> IC_SSHICM(const std::vector<double>& d, const std::vector<int>& s, unsigned int seed, int permutation_number, const std::string& bin_method);
RcppExport SEXP _sshicm_IC_SSHICM(SEXP dSEXP, SEXP sSEXP, SEXP seedSEXP, SEXP permutation_numberSEXP, SEXP bin_methodSEXP) {
// RcppINSSHICM
Rcpp::NumericVector RcppINSSHICM(Rcpp::IntegerVector d, Rcpp::IntegerVector s, unsigned int seed, int permutation_number);
RcppExport SEXP _sshicm_RcppINSSHICM(SEXP dSEXP, SEXP sSEXP, SEXP seedSEXP, SEXP permutation_numberSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const std::vector<double>& >::type d(dSEXP);
Rcpp::traits::input_parameter< const std::vector<int>& >::type s(sSEXP);
Rcpp::traits::input_parameter< Rcpp::IntegerVector >::type d(dSEXP);
Rcpp::traits::input_parameter< Rcpp::IntegerVector >::type s(sSEXP);
Rcpp::traits::input_parameter< unsigned int >::type seed(seedSEXP);
Rcpp::traits::input_parameter< int >::type permutation_number(permutation_numberSEXP);
Rcpp::traits::input_parameter< const std::string& >::type bin_method(bin_methodSEXP);
rcpp_result_gen = Rcpp::wrap(IC_SSHICM(d, s, seed, permutation_number, bin_method));
rcpp_result_gen = Rcpp::wrap(RcppINSSHICM(d, s, seed, permutation_number));
return rcpp_result_gen;
END_RCPP
}
// IN_SSH
double IN_SSH(const std::vector<int>& d, const std::vector<int>& s);
RcppExport SEXP _sshicm_IN_SSH(SEXP dSEXP, SEXP sSEXP) {
// RcppICSSH
double RcppICSSH(Rcpp::NumericVector d, Rcpp::IntegerVector s, std::string bin_method);
RcppExport SEXP _sshicm_RcppICSSH(SEXP dSEXP, SEXP sSEXP, SEXP bin_methodSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const std::vector<int>& >::type d(dSEXP);
Rcpp::traits::input_parameter< const std::vector<int>& >::type s(sSEXP);
rcpp_result_gen = Rcpp::wrap(IN_SSH(d, s));
Rcpp::traits::input_parameter< Rcpp::NumericVector >::type d(dSEXP);
Rcpp::traits::input_parameter< Rcpp::IntegerVector >::type s(sSEXP);
Rcpp::traits::input_parameter< std::string >::type bin_method(bin_methodSEXP);
rcpp_result_gen = Rcpp::wrap(RcppICSSH(d, s, bin_method));
return rcpp_result_gen;
END_RCPP
}
// IN_SSHICM
std::vector<double> IN_SSHICM(const std::vector<int>& d, const std::vector<int>& s, unsigned int seed, int permutation_number);
RcppExport SEXP _sshicm_IN_SSHICM(SEXP dSEXP, SEXP sSEXP, SEXP seedSEXP, SEXP permutation_numberSEXP) {
// RcppICSSHICM
Rcpp::NumericVector RcppICSSHICM(Rcpp::NumericVector d, Rcpp::IntegerVector s, unsigned int seed, int permutation_number, std::string bin_method);
RcppExport SEXP _sshicm_RcppICSSHICM(SEXP dSEXP, SEXP sSEXP, SEXP seedSEXP, SEXP permutation_numberSEXP, SEXP bin_methodSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const std::vector<int>& >::type d(dSEXP);
Rcpp::traits::input_parameter< const std::vector<int>& >::type s(sSEXP);
Rcpp::traits::input_parameter< Rcpp::NumericVector >::type d(dSEXP);
Rcpp::traits::input_parameter< Rcpp::IntegerVector >::type s(sSEXP);
Rcpp::traits::input_parameter< unsigned int >::type seed(seedSEXP);
Rcpp::traits::input_parameter< int >::type permutation_number(permutation_numberSEXP);
rcpp_result_gen = Rcpp::wrap(IN_SSHICM(d, s, seed, permutation_number));
Rcpp::traits::input_parameter< std::string >::type bin_method(bin_methodSEXP);
rcpp_result_gen = Rcpp::wrap(RcppICSSHICM(d, s, seed, permutation_number, bin_method));
return rcpp_result_gen;
END_RCPP
}

static const R_CallMethodDef CallEntries[] = {
{"_sshicm_IC_SSH", (DL_FUNC) &_sshicm_IC_SSH, 3},
{"_sshicm_IC_SSHICM", (DL_FUNC) &_sshicm_IC_SSHICM, 5},
{"_sshicm_IN_SSH", (DL_FUNC) &_sshicm_IN_SSH, 2},
{"_sshicm_IN_SSHICM", (DL_FUNC) &_sshicm_IN_SSHICM, 4},
{"_sshicm_RcppINSSH", (DL_FUNC) &_sshicm_RcppINSSH, 2},
{"_sshicm_RcppINSSHICM", (DL_FUNC) &_sshicm_RcppINSSHICM, 4},
{"_sshicm_RcppICSSH", (DL_FUNC) &_sshicm_RcppICSSH, 3},
{"_sshicm_RcppICSSHICM", (DL_FUNC) &_sshicm_RcppICSSHICM, 5},
{NULL, NULL, 0}
};

Expand Down
73 changes: 73 additions & 0 deletions src/RcppWrapperExp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include <vector>
#include "IN_SSH.h"
#include "IC_SSH.h"
#include <Rcpp.h>

// Rcpp wrapper for IN_SSH
// [[Rcpp::export]]
double RcppINSSH(Rcpp::IntegerVector d, Rcpp::IntegerVector s) {
// Convert Rcpp::IntegerVector to std::vector<int>
std::vector<int> d_std = Rcpp::as<std::vector<int>>(d);
std::vector<int> s_std = Rcpp::as<std::vector<int>>(s);

// Call the IN_SSH function
double result = IN_SSH(d_std, s_std);

// Return the result as a double
return result;
}

// Rcpp wrapper for IN_SSHICM
// [[Rcpp::export]]
Rcpp::NumericVector RcppINSSHICM(Rcpp::IntegerVector d,
Rcpp::IntegerVector s,
unsigned int seed,
int permutation_number) {
// Convert Rcpp::IntegerVector to std::vector<int>
std::vector<int> d_std = Rcpp::as<std::vector<int>>(d);
std::vector<int> s_std = Rcpp::as<std::vector<int>>(s);

// Call the IN_SSHICM function
std::vector<double> result = IN_SSHICM(d_std, s_std, seed, permutation_number);

// Convert the std::vector<double> result to Rcpp::NumericVector
return Rcpp::wrap(result);
}

// Rcpp wrapper for IC_SSH
// [[Rcpp::export]]
double RcppICSSH(Rcpp::NumericVector d,
Rcpp::IntegerVector s,
std::string bin_method = "Sturges") {
// Convert Rcpp::NumericVector to std::vector<double>
std::vector<double> d_std = Rcpp::as<std::vector<double>>(d);

// Convert Rcpp::IntegerVector to std::vector<int>
std::vector<int> s_std = Rcpp::as<std::vector<int>>(s);

// Call the IC_SSH function
double result = IC_SSH(d_std, s_std, bin_method);

// Return the result as a double
return result;
}

// Rcpp wrapper for IC_SSHICM
// [[Rcpp::export]]
Rcpp::NumericVector RcppICSSHICM(Rcpp::NumericVector d,
Rcpp::IntegerVector s,
unsigned int seed,
int permutation_number,
std::string bin_method = "Sturges") {
// Convert Rcpp::NumericVector to std::vector<double>
std::vector<double> d_std = Rcpp::as<std::vector<double>>(d);

// Convert Rcpp::IntegerVector to std::vector<int>
std::vector<int> s_std = Rcpp::as<std::vector<int>>(s);

// Call the IC_SSHICM function
std::vector<double> result = IC_SSHICM(d_std, s_std, seed, permutation_number, bin_method);

// Convert the std::vector<double> result to Rcpp::NumericVector
return Rcpp::wrap(result);
}

0 comments on commit 8f4b6f5

Please sign in to comment.