Skip to content

Commit 00e8737

Browse files
Minor changes to median.h
1 parent 8b2aa34 commit 00e8737

File tree

1 file changed

+9
-15
lines changed
  • inst/include/Rcpp/sugar/functions

1 file changed

+9
-15
lines changed

inst/include/Rcpp/sugar/functions/median.h

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class Median {
8888
public:
8989
typedef typename median_detail::result<RTYPE>::type result_type;
9090
typedef typename Rcpp::traits::storage_type<RTYPE>::type stored_type;
91-
enum { RTYPE2 = median_detail::result<RTYPE>::rtype };
91+
enum { RESULT_RTYPE = median_detail::result<RTYPE>::rtype };
9292
typedef T VECTOR;
9393

9494
private:
@@ -100,11 +100,11 @@ class Median {
100100

101101
operator result_type() {
102102
if (x.size() < 1) {
103-
return Rcpp::traits::get_na<RTYPE2>();
103+
return Rcpp::traits::get_na<RESULT_RTYPE>();
104104
}
105105

106106
if (Rcpp::any(Rcpp::is_na(x))) {
107-
return Rcpp::traits::get_na<RTYPE2>();
107+
return Rcpp::traits::get_na<RESULT_RTYPE>();
108108
}
109109

110110
R_xlen_t n = x.size() / 2;
@@ -126,7 +126,7 @@ class Median<RTYPE, NA, T, true> {
126126
public:
127127
typedef typename median_detail::result<RTYPE>::type result_type;
128128
typedef typename Rcpp::traits::storage_type<RTYPE>::type stored_type;
129-
enum { RTYPE2 = median_detail::result<RTYPE>::rtype };
129+
enum { RESULT_RTYPE = median_detail::result<RTYPE>::rtype };
130130
typedef T VECTOR;
131131

132132
private:
@@ -138,7 +138,7 @@ class Median<RTYPE, NA, T, true> {
138138

139139
operator result_type() {
140140
if (!x.size()) {
141-
return Rcpp::traits::get_na<RTYPE2>();
141+
return Rcpp::traits::get_na<RESULT_RTYPE>();
142142
}
143143

144144
R_xlen_t n = x.size() / 2;
@@ -160,7 +160,7 @@ class Median<RTYPE, false, T, NA_RM> {
160160
public:
161161
typedef typename median_detail::result<RTYPE>::type result_type;
162162
typedef typename Rcpp::traits::storage_type<RTYPE>::type stored_type;
163-
enum { RTYPE2 = median_detail::result<RTYPE>::rtype };
163+
enum { RESULT_RTYPE = median_detail::result<RTYPE>::rtype };
164164
typedef T VECTOR;
165165

166166
private:
@@ -172,7 +172,7 @@ class Median<RTYPE, false, T, NA_RM> {
172172

173173
operator result_type() {
174174
if (x.size() < 1) {
175-
return Rcpp::traits::get_na<RTYPE2>();
175+
return Rcpp::traits::get_na<RESULT_RTYPE>();
176176
}
177177

178178
R_xlen_t n = x.size() / 2;
@@ -281,14 +281,8 @@ class Median<STRSXP, false, T, true> {
281281
template <int RTYPE, bool NA, typename T>
282282
inline typename sugar::median_detail::result<RTYPE>::type
283283
median(const Rcpp::VectorBase<RTYPE, NA, T>& x, bool na_rm = false) {
284-
switch (static_cast<int>(na_rm)) {
285-
case 0:
286-
return sugar::Median<RTYPE, NA, T, false>(x);
287-
case 1:
288-
return sugar::Median<RTYPE, NA, T, true>(x);
289-
default:
290-
return Rcpp::traits::get_na<RTYPE>();
291-
}
284+
if (!na_rm) return sugar::Median<RTYPE, NA, T, false>(x);
285+
return sugar::Median<RTYPE, NA, T, true>(x);
292286
}
293287

294288
} // Rcpp

0 commit comments

Comments
 (0)