Skip to content

Commit 43ac7c3

Browse files
Cleanup for #551
1 parent e92b696 commit 43ac7c3

File tree

1 file changed

+56
-58
lines changed

1 file changed

+56
-58
lines changed

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

Lines changed: 56 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -48,37 +48,37 @@ inline bool check_na(Rcomplex x) {
4848
}
4949

5050

51-
inline void incr(double& lhs, double rhs) {
52-
lhs += rhs;
51+
inline void incr(double* lhs, double rhs) {
52+
*lhs += rhs;
5353
}
5454

55-
inline void incr(int& lhs, int rhs) {
56-
lhs += rhs;
55+
inline void incr(int* lhs, int rhs) {
56+
*lhs += rhs;
5757
}
5858

59-
inline void incr(Rcomplex& lhs, const Rcomplex& rhs) {
60-
lhs.r += rhs.r;
61-
lhs.i += rhs.i;
59+
inline void incr(Rcomplex* lhs, const Rcomplex& rhs) {
60+
lhs->r += rhs.r;
61+
lhs->i += rhs.i;
6262
}
6363

6464

65-
inline void div(double& lhs, R_xlen_t rhs) {
66-
lhs /= rhs;
65+
inline void div(double* lhs, R_xlen_t rhs) {
66+
*lhs /= rhs;
6767
}
6868

69-
inline void div(Rcomplex& lhs, R_xlen_t rhs) {
70-
lhs.r /= rhs;
71-
lhs.i /= rhs;
69+
inline void div(Rcomplex* lhs, R_xlen_t rhs) {
70+
lhs->r /= rhs;
71+
lhs->i /= rhs;
7272
}
7373

7474

75-
inline void set_nan(double& x) {
76-
x = R_NaN;
75+
inline void set_nan(double* x) {
76+
*x = R_NaN;
7777
}
7878

79-
inline void set_nan(Rcomplex& x) {
80-
x.r = R_NaN;
81-
x.i = R_NaN;
79+
inline void set_nan(Rcomplex* x) {
80+
x->r = R_NaN;
81+
x->i = R_NaN;
8282
}
8383

8484

@@ -145,7 +145,7 @@ class RowSumsImpl :
145145

146146
for (j = 0; j < nc; j++) {
147147
for (i = 0; i < nr; i++) {
148-
detail::incr(res[i], ref(i, j));
148+
detail::incr(&res[i], ref(i, j));
149149
}
150150
}
151151

@@ -198,7 +198,7 @@ public:
198198
if (detail::check_na(ref(i, j))) { \
199199
na_flags[i].x |= 0x1; \
200200
} \
201-
detail::incr(res[i], ref(i, j)); \
201+
detail::incr(&res[i], ref(i, j)); \
202202
} \
203203
} \
204204
\
@@ -215,6 +215,7 @@ public:
215215
ROW_SUMS_IMPL_KEEPNA(LGLSXP)
216216
ROW_SUMS_IMPL_KEEPNA(INTSXP)
217217

218+
#undef ROW_SUMS_IMPL_KEEPNA
218219

219220
// RowSums
220221
// na.rm = TRUE
@@ -246,7 +247,7 @@ class RowSumsImpl<RTYPE, NA, T, true> :
246247
for (i = 0; i < nr; i++) {
247248
current = ref(i, j);
248249
if (!detail::check_na(current)) {
249-
detail::incr(res[i], current);
250+
detail::incr(&res[i], current);
250251
}
251252
}
252253
}
@@ -287,7 +288,7 @@ public:
287288
for (i = 0; i < nr; i++) { \
288289
current = ref(i, j); \
289290
if (!detail::check_na(current)) { \
290-
detail::incr(res[i], current); \
291+
detail::incr(&res[i], current); \
291292
} \
292293
} \
293294
} \
@@ -299,6 +300,7 @@ public:
299300
ROW_SUMS_IMPL_RMNA(LGLSXP)
300301
ROW_SUMS_IMPL_RMNA(INTSXP)
301302

303+
#undef ROW_SUMS_IMPL_RMNA
302304

303305
// RowSums
304306
// Input with template parameter NA = false
@@ -335,7 +337,7 @@ class ColSumsImpl :
335337

336338
for (j = 0; j < nc; j++) {
337339
for (i = 0; i < nr; i++) {
338-
detail::incr(res[j], ref(i, j));
340+
detail::incr(&res[j], ref(i, j));
339341
}
340342
}
341343

@@ -380,7 +382,7 @@ public:
380382
if (detail::check_na(ref(i, j))) { \
381383
na_flags[j].x |= 0x1; \
382384
} \
383-
detail::incr(res[j], ref(i, j)); \
385+
detail::incr(&res[j], ref(i, j)); \
384386
} \
385387
} \
386388
\
@@ -397,7 +399,8 @@ public:
397399
COL_SUMS_IMPL_KEEPNA(LGLSXP)
398400
COL_SUMS_IMPL_KEEPNA(INTSXP)
399401

400-
402+
#undef COL_SUMS_IMPL_KEEPNA
403+
401404
// ColSums
402405
// na.rm = TRUE
403406
// default input
@@ -428,7 +431,7 @@ class ColSumsImpl<RTYPE, NA, T, true> :
428431
for (i = 0; i < nr; i++) {
429432
current = ref(i, j);
430433
if (!detail::check_na(current)) {
431-
detail::incr(res[j], current);
434+
detail::incr(&res[j], current);
432435
}
433436
}
434437
}
@@ -469,7 +472,7 @@ public:
469472
for (i = 0; i < nr; i++) { \
470473
current = ref(i, j); \
471474
if (!detail::check_na(current)) { \
472-
detail::incr(res[j], current); \
475+
detail::incr(&res[j], current); \
473476
} \
474477
} \
475478
} \
@@ -481,6 +484,7 @@ public:
481484
COL_SUMS_IMPL_RMNA(LGLSXP)
482485
COL_SUMS_IMPL_RMNA(INTSXP)
483486

487+
#undef COL_SUMS_IMPL_RMNA
484488

485489
// ColSums
486490
// Input with template parameter NA = false
@@ -520,12 +524,12 @@ class RowMeansImpl :
520524

521525
for (j = 0; j < nc; j++) {
522526
for (i = 0; i < nr; i++) {
523-
detail::incr(res[i], ref(i, j));
527+
detail::incr(&res[i], ref(i, j));
524528
}
525529
}
526530

527531
for (i = 0; i < nr; i++) {
528-
detail::div(res[i], nc);
532+
detail::div(&res[i], nc);
529533
}
530534

531535
return res;
@@ -569,13 +573,13 @@ public:
569573
if (detail::check_na(ref(i, j))) { \
570574
na_flags[i].x |= 0x1; \
571575
} \
572-
detail::incr(res[i], ref(i, j)); \
576+
detail::incr(&res[i], ref(i, j)); \
573577
} \
574578
} \
575579
\
576580
for (i = 0; i < nr; i++) { \
577581
if (!na_flags[i].x) { \
578-
detail::div(res[i], nc); \
582+
detail::div(&res[i], nc); \
579583
} else { \
580584
res[i] = NA_REAL; \
581585
} \
@@ -588,7 +592,8 @@ public:
588592
ROW_MEANS_IMPL_KEEPNA(LGLSXP)
589593
ROW_MEANS_IMPL_KEEPNA(INTSXP)
590594

591-
595+
#undef ROW_MEANS_IMPL_KEEPNA
596+
592597
// RowMeans
593598
// na.rm = TRUE
594599
// default input
@@ -621,17 +626,17 @@ class RowMeansImpl<RTYPE, NA, T, true> :
621626
for (i = 0; i < nr; i++) {
622627
current = ref(i, j);
623628
if (!detail::check_na(current)) {
624-
detail::incr(res[i], ref(i, j));
629+
detail::incr(&res[i], ref(i, j));
625630
++n_ok[i];
626631
}
627632
}
628633
}
629634

630635
for (i = 0; i < nr; i++) {
631636
if (n_ok[i]) {
632-
detail::div(res[i], n_ok[i]);
637+
detail::div(&res[i], n_ok[i]);
633638
} else {
634-
detail::set_nan(res[i]);
639+
detail::set_nan(&res[i]);
635640
}
636641
}
637642

@@ -670,17 +675,17 @@ public:
670675
for (j = 0; j < nc; j++) { \
671676
for (i = 0; i < nr; i++) { \
672677
if (!detail::check_na(ref(i, j))) { \
673-
detail::incr(res[i], ref(i, j)); \
678+
detail::incr(&res[i], ref(i, j)); \
674679
++n_ok[i]; \
675680
} \
676681
} \
677682
} \
678683
\
679684
for (i = 0; i < nr; i++) { \
680685
if (n_ok[i]) { \
681-
detail::div(res[i], n_ok[i]); \
686+
detail::div(&res[i], n_ok[i]); \
682687
} else { \
683-
detail::set_nan(res[i]); \
688+
detail::set_nan(&res[i]); \
684689
} \
685690
} \
686691
\
@@ -691,6 +696,7 @@ public:
691696
ROW_MEANS_IMPL_RMNA(LGLSXP)
692697
ROW_MEANS_IMPL_RMNA(INTSXP)
693698

699+
#undef ROW_MEANS_IMPL_RMNA
694700

695701
// RowMeans
696702
// Input with template parameter NA = false
@@ -727,12 +733,12 @@ class ColMeansImpl :
727733

728734
for (j = 0; j < nc; j++) {
729735
for (i = 0; i < nr; i++) {
730-
detail::incr(res[j], ref(i, j));
736+
detail::incr(&res[j], ref(i, j));
731737
}
732738
}
733739

734740
for (j = 0; j < nc; j++) {
735-
detail::div(res[j], nr);
741+
detail::div(&res[j], nr);
736742
}
737743

738744
return res;
@@ -776,13 +782,13 @@ public:
776782
if (detail::check_na(ref(i, j))) { \
777783
na_flags[j].x |= 0x1; \
778784
} \
779-
detail::incr(res[j], ref(i, j)); \
785+
detail::incr(&res[j], ref(i, j)); \
780786
} \
781787
} \
782788
\
783789
for (j = 0; j < nc; j++) { \
784790
if (!na_flags[j].x) { \
785-
detail::div(res[j], nr); \
791+
detail::div(&res[j], nr); \
786792
} else { \
787793
res[j] = NA_REAL; \
788794
} \
@@ -795,6 +801,7 @@ public:
795801
COL_MEANS_IMPL_KEEPNA(LGLSXP)
796802
COL_MEANS_IMPL_KEEPNA(INTSXP)
797803

804+
#undef COL_MEANS_IMPL_KEEPNA
798805

799806
// ColMeans
800807
// na.rm = TRUE
@@ -828,17 +835,17 @@ class ColMeansImpl<RTYPE, NA, T, true> :
828835
for (i = 0; i < nr; i++) {
829836
current = ref(i, j);
830837
if (!detail::check_na(current)) {
831-
detail::incr(res[j], ref(i, j));
838+
detail::incr(&res[j], ref(i, j));
832839
++n_ok[j];
833840
}
834841
}
835842
}
836843

837844
for (j = 0; j < nc; j++) {
838845
if (n_ok[j]) {
839-
detail::div(res[j], n_ok[j]);
846+
detail::div(&res[j], n_ok[j]);
840847
} else {
841-
detail::set_nan(res[j]);
848+
detail::set_nan(&res[j]);
842849
}
843850
}
844851

@@ -877,17 +884,17 @@ public:
877884
for (j = 0; j < nc; j++) { \
878885
for (i = 0; i < nr; i++) { \
879886
if (!detail::check_na(ref(i, j))) { \
880-
detail::incr(res[j], ref(i, j)); \
887+
detail::incr(&res[j], ref(i, j)); \
881888
++n_ok[j]; \
882889
} \
883890
} \
884891
} \
885892
\
886893
for (j = 0; j < nc; j++) { \
887894
if (n_ok[j]) { \
888-
detail::div(res[j], n_ok[j]); \
895+
detail::div(&res[j], n_ok[j]); \
889896
} else { \
890-
detail::set_nan(res[j]); \
897+
detail::set_nan(&res[j]); \
891898
} \
892899
} \
893900
\
@@ -898,7 +905,8 @@ public:
898905
COL_MEANS_IMPL_RMNA(LGLSXP)
899906
COL_MEANS_IMPL_RMNA(INTSXP)
900907

901-
908+
#undef COL_MEANS_IMPL_RMNA
909+
902910
// ColMeans
903911
// Input with template parameter NA = false
904912
// ColMeansImpl<..., NA_RM = false>
@@ -948,16 +956,6 @@ colMeans(const MatrixBase<RTYPE, NA, T>& x, bool na_rm = false) {
948956
}
949957

950958

951-
#undef ROW_SUMS_IMPL_KEEPNA
952-
#undef ROW_SUMS_IMPL_RMNA
953-
#undef COL_SUMS_IMPL_KEEPNA
954-
#undef COL_SUMS_IMPL_RMNA
955-
#undef ROW_MEANS_IMPL_KEEPNA
956-
#undef ROW_MEANS_IMPL_RMNA
957-
#undef COL_MEANS_IMPL_KEEPNA
958-
#undef COL_MEANS_IMPL_RMNA
959-
960-
961959
} // Rcpp
962960

963961
#endif // Rcpp__sugar__rowSums_h

0 commit comments

Comments
 (0)