Skip to content

Commit

Permalink
templated scale.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
SymbolixAU committed Mar 29, 2021
1 parent 31672f5 commit 1236cbd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: colourvalues
Type: Package
Title: Assigns Colours to Values
Version: 0.3.7
Date: 2020-12-02
Version: 0.3.7001
Date: 2021-03-30
Authors@R: c(
person("David", "Cooley", ,"[email protected]", role = c("aut", "cre"))
)
Expand Down
17 changes: 11 additions & 6 deletions inst/include/colourvalues/scale/scale.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
namespace colourvalues {
namespace scale {

inline Rcpp::NumericVector minmax( Rcpp::NumericVector& x ) {
int n = x.size();
template< int RTYPE >
inline Rcpp::Vector< RTYPE > minmax( Rcpp::Vector< RTYPE >& x ) {
R_xlen_t n = x.size();

typedef typename Rcpp::traits::storage_type< RTYPE >::type T;

double min = 0;
double max = 0;
T min = 0;
T max = 0;
bool first_value = false;

for( int i = 0; i < n; i++) {
R_xlen_t i;
for( i = 0; i < n; i++) {

if( !ISNAN( x[i] ) ) {
if( !first_value ) {
Expand All @@ -29,11 +33,12 @@ namespace scale {
}
}
}
return Rcpp::NumericVector::create(min, max);
return Rcpp::Vector< RTYPE >::create( min, max );
}

// Always rescales to (0, 1)
// used for variables
// iff input is INTSXP; the output will be REALSXP
inline void rescale( Rcpp::NumericVector& x ) {
int n = x.size();

Expand Down

0 comments on commit 1236cbd

Please sign in to comment.