Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork219
row/col-Sums/Means and unit tests - for #549#551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -48,37 +48,37 @@ inline bool check_na(Rcomplex x) { | ||
| } | ||
| inline void incr(double* lhs, double rhs) { | ||
| *lhs += rhs; | ||
| } | ||
| inline void incr(int* lhs, int rhs) { | ||
| *lhs += rhs; | ||
| } | ||
| inline void incr(Rcomplex* lhs, const Rcomplex& rhs) { | ||
| lhs->r += rhs.r; | ||
| lhs->i += rhs.i; | ||
| } | ||
| inline void div(double* lhs, R_xlen_t rhs) { | ||
| *lhs /= rhs; | ||
| } | ||
| inline void div(Rcomplex* lhs, R_xlen_t rhs) { | ||
| lhs->r /= rhs; | ||
| lhs->i /= rhs; | ||
| } | ||
| inline void set_nan(double* x) { | ||
| *x = R_NaN; | ||
| } | ||
| inline void set_nan(Rcomplex* x) { | ||
| x->r = R_NaN; | ||
| x->i = R_NaN; | ||
| } | ||
| @@ -145,7 +145,7 @@ class RowSumsImpl : | ||
| for (j = 0; j < nc; j++) { | ||
| for (i = 0; i < nr; i++) { | ||
| detail::incr(&res[i], ref(i, j)); | ||
| } | ||
| } | ||
| @@ -198,7 +198,7 @@ public: | ||
| if (detail::check_na(ref(i, j))) { \ | ||
| na_flags[i].x |= 0x1; \ | ||
| } \ | ||
| detail::incr(&res[i], ref(i, j)); \ | ||
| } \ | ||
| } \ | ||
| \ | ||
| @@ -215,6 +215,7 @@ public: | ||
| ROW_SUMS_IMPL_KEEPNA(LGLSXP) | ||
| ROW_SUMS_IMPL_KEEPNA(INTSXP) | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Same | ||
| #undef ROW_SUMS_IMPL_KEEPNA | ||
| // RowSums | ||
| // na.rm = TRUE | ||
| @@ -246,7 +247,7 @@ class RowSumsImpl<RTYPE, NA, T, true> : | ||
| for (i = 0; i < nr; i++) { | ||
| current = ref(i, j); | ||
| if (!detail::check_na(current)) { | ||
| detail::incr(&res[i], current); | ||
| } | ||
| } | ||
| } | ||
| @@ -287,7 +288,7 @@ public: | ||
| for (i = 0; i < nr; i++) { \ | ||
| current = ref(i, j); \ | ||
| if (!detail::check_na(current)) { \ | ||
| detail::incr(&res[i], current); \ | ||
| } \ | ||
| } \ | ||
| } \ | ||
| @@ -299,6 +300,7 @@ public: | ||
| ROW_SUMS_IMPL_RMNA(LGLSXP) | ||
| ROW_SUMS_IMPL_RMNA(INTSXP) | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Let's | ||
| #undef ROW_SUMS_IMPL_RMNA | ||
| // RowSums | ||
| // Input with template parameter NA = false | ||
| @@ -335,7 +337,7 @@ class ColSumsImpl : | ||
| for (j = 0; j < nc; j++) { | ||
| for (i = 0; i < nr; i++) { | ||
| detail::incr(&res[j], ref(i, j)); | ||
| } | ||
| } | ||
| @@ -380,7 +382,7 @@ public: | ||
| if (detail::check_na(ref(i, j))) { \ | ||
| na_flags[j].x |= 0x1; \ | ||
| } \ | ||
| detail::incr(&res[j], ref(i, j)); \ | ||
| } \ | ||
| } \ | ||
| \ | ||
| @@ -397,7 +399,8 @@ public: | ||
| COL_SUMS_IMPL_KEEPNA(LGLSXP) | ||
| COL_SUMS_IMPL_KEEPNA(INTSXP) | ||
| #undef COL_SUMS_IMPL_KEEPNA | ||
| // ColSums | ||
| // na.rm = TRUE | ||
| // default input | ||
| @@ -428,7 +431,7 @@ class ColSumsImpl<RTYPE, NA, T, true> : | ||
| for (i = 0; i < nr; i++) { | ||
| current = ref(i, j); | ||
| if (!detail::check_na(current)) { | ||
| detail::incr(&res[j], current); | ||
| } | ||
| } | ||
| } | ||
| @@ -469,7 +472,7 @@ public: | ||
| for (i = 0; i < nr; i++) { \ | ||
| current = ref(i, j); \ | ||
| if (!detail::check_na(current)) { \ | ||
| detail::incr(&res[j], current); \ | ||
| } \ | ||
| } \ | ||
| } \ | ||
| @@ -481,6 +484,7 @@ public: | ||
| COL_SUMS_IMPL_RMNA(LGLSXP) | ||
| COL_SUMS_IMPL_RMNA(INTSXP) | ||
| #undef COL_SUMS_IMPL_RMNA | ||
| // ColSums | ||
| // Input with template parameter NA = false | ||
| @@ -520,12 +524,12 @@ class RowMeansImpl : | ||
| for (j = 0; j < nc; j++) { | ||
| for (i = 0; i < nr; i++) { | ||
| detail::incr(&res[i], ref(i, j)); | ||
| } | ||
| } | ||
| for (i = 0; i < nr; i++) { | ||
| detail::div(&res[i], nc); | ||
| } | ||
| return res; | ||
| @@ -569,13 +573,13 @@ public: | ||
| if (detail::check_na(ref(i, j))) { \ | ||
| na_flags[i].x |= 0x1; \ | ||
| } \ | ||
| detail::incr(&res[i], ref(i, j)); \ | ||
| } \ | ||
| } \ | ||
| \ | ||
| for (i = 0; i < nr; i++) { \ | ||
| if (!na_flags[i].x) { \ | ||
| detail::div(&res[i], nc); \ | ||
| } else { \ | ||
| res[i] = NA_REAL; \ | ||
| } \ | ||
| @@ -588,7 +592,8 @@ public: | ||
| ROW_MEANS_IMPL_KEEPNA(LGLSXP) | ||
| ROW_MEANS_IMPL_KEEPNA(INTSXP) | ||
| #undef ROW_MEANS_IMPL_KEEPNA | ||
| // RowMeans | ||
| // na.rm = TRUE | ||
| // default input | ||
| @@ -621,17 +626,17 @@ class RowMeansImpl<RTYPE, NA, T, true> : | ||
| for (i = 0; i < nr; i++) { | ||
| current = ref(i, j); | ||
| if (!detail::check_na(current)) { | ||
| detail::incr(&res[i], ref(i, j)); | ||
| ++n_ok[i]; | ||
| } | ||
| } | ||
| } | ||
| for (i = 0; i < nr; i++) { | ||
| if (n_ok[i]) { | ||
| detail::div(&res[i], n_ok[i]); | ||
| } else { | ||
| detail::set_nan(&res[i]); | ||
| } | ||
| } | ||
| @@ -670,17 +675,17 @@ public: | ||
| for (j = 0; j < nc; j++) { \ | ||
| for (i = 0; i < nr; i++) { \ | ||
| if (!detail::check_na(ref(i, j))) { \ | ||
| detail::incr(&res[i], ref(i, j)); \ | ||
| ++n_ok[i]; \ | ||
| } \ | ||
| } \ | ||
| } \ | ||
| \ | ||
| for (i = 0; i < nr; i++) { \ | ||
| if (n_ok[i]) { \ | ||
| detail::div(&res[i], n_ok[i]); \ | ||
| } else { \ | ||
| detail::set_nan(&res[i]); \ | ||
| } \ | ||
| } \ | ||
| \ | ||
| @@ -691,6 +696,7 @@ public: | ||
| ROW_MEANS_IMPL_RMNA(LGLSXP) | ||
| ROW_MEANS_IMPL_RMNA(INTSXP) | ||
| #undef ROW_MEANS_IMPL_RMNA | ||
| // RowMeans | ||
| // Input with template parameter NA = false | ||
| @@ -727,12 +733,12 @@ class ColMeansImpl : | ||
| for (j = 0; j < nc; j++) { | ||
| for (i = 0; i < nr; i++) { | ||
| detail::incr(&res[j], ref(i, j)); | ||
| } | ||
| } | ||
| for (j = 0; j < nc; j++) { | ||
| detail::div(&res[j], nr); | ||
| } | ||
| return res; | ||
| @@ -776,13 +782,13 @@ public: | ||
| if (detail::check_na(ref(i, j))) { \ | ||
| na_flags[j].x |= 0x1; \ | ||
| } \ | ||
| detail::incr(&res[j], ref(i, j)); \ | ||
| } \ | ||
| } \ | ||
| \ | ||
| for (j = 0; j < nc; j++) { \ | ||
| if (!na_flags[j].x) { \ | ||
| detail::div(&res[j], nr); \ | ||
| } else { \ | ||
| res[j] = NA_REAL; \ | ||
| } \ | ||
| @@ -795,6 +801,7 @@ public: | ||
| COL_MEANS_IMPL_KEEPNA(LGLSXP) | ||
| COL_MEANS_IMPL_KEEPNA(INTSXP) | ||
| #undef COL_MEANS_IMPL_KEEPNA | ||
| // ColMeans | ||
| // na.rm = TRUE | ||
| @@ -828,17 +835,17 @@ class ColMeansImpl<RTYPE, NA, T, true> : | ||
| for (i = 0; i < nr; i++) { | ||
| current = ref(i, j); | ||
| if (!detail::check_na(current)) { | ||
| detail::incr(&res[j], ref(i, j)); | ||
| ++n_ok[j]; | ||
| } | ||
| } | ||
| } | ||
| for (j = 0; j < nc; j++) { | ||
| if (n_ok[j]) { | ||
| detail::div(&res[j], n_ok[j]); | ||
| } else { | ||
| detail::set_nan(&res[j]); | ||
| } | ||
| } | ||
| @@ -877,17 +884,17 @@ public: | ||
| for (j = 0; j < nc; j++) { \ | ||
| for (i = 0; i < nr; i++) { \ | ||
| if (!detail::check_na(ref(i, j))) { \ | ||
| detail::incr(&res[j], ref(i, j)); \ | ||
| ++n_ok[j]; \ | ||
| } \ | ||
| } \ | ||
| } \ | ||
| \ | ||
| for (j = 0; j < nc; j++) { \ | ||
| if (n_ok[j]) { \ | ||
| detail::div(&res[j], n_ok[j]); \ | ||
| } else { \ | ||
| detail::set_nan(&res[j]); \ | ||
| } \ | ||
| } \ | ||
| \ | ||
| @@ -898,7 +905,8 @@ public: | ||
| COL_MEANS_IMPL_RMNA(LGLSXP) | ||
| COL_MEANS_IMPL_RMNA(INTSXP) | ||
| #undef COL_MEANS_IMPL_RMNA | ||
| // ColMeans | ||
| // Input with template parameter NA = false | ||
| // ColMeansImpl<..., NA_RM = false> | ||
| @@ -948,16 +956,6 @@ colMeans(const MatrixBase<RTYPE, NA, T>& x, bool na_rm = false) { | ||
| } | ||
| } // Rcpp | ||
| #endif // Rcpp__sugar__rowSums_h | ||