-
-
Notifications
You must be signed in to change notification settings - Fork 211
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
row/col-Sums/Means and unit tests - for #549 #551
Conversation
That looks like it is really nice work, once again. Thank so much! |
} | ||
|
||
|
||
inline void incr(double& lhs, double rhs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor style quip, but I think it's a preferable to receive arguments that will be mutated by pointer, rather than by reference -- it makes it more obvious at the call site whether a passed-in parameter might be mutated. For example,
do_something(x);
versus
do_something(&x);
In the first case, I think the expectation most would have is that do_something(x)
will not mutate x
, whereby it's more obvious that mutation might happen with do_something(&x)
.
The main downside is the fact that pointers can be NULL
while references can't, but I think the clarity in code makes up for that. I'll let others weigh on whether that change is worth making.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Kevin, especially in the case where by local idiom there is no
possibility of the pointer being NULL (which BTW would already be true if
you can pass a reference there).
On Sun, Sep 4, 2016 at 9:38 PM, Kevin Ushey notifications@github.com
wrote:
In inst/include/Rcpp/sugar/functions/rowSums.h
#551 (comment):+}
+
+inline bool check_na(Rboolean x) {
- return x == NA_LOGICAL;
+}
+inline bool check_na(SEXP x) {
- return x == NA_STRING;
+}
+inline bool check_na(Rcomplex x) {
- return ISNAN(x.r) || ISNAN(x.i);
+}
+inline void incr(double& lhs, double rhs) {
Minor style issue, but I think it's a preferable to receive arguments that
will be mutated by pointer, rather than by reference -- it makes it more
obvious at the call site whether a passed-in parameter might be mutated.
For example,do_something(x);
versus
do_something(&x);
In the first case, I think the expectation most would have is that
do_something(x) will not mutate x, whereby it's more obvious that
mutation might happen with do_something(&x).The main downside is the fact that pointers can be NULL while references
can't, but I think the clarity in code makes up for that. I'll let others
weigh on whether that change is worth making.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/RcppCore/Rcpp/pull/551/files/e92b69626da0e6f08f105e01e2f1ff63988da193#r77463324,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAGXx1FKiNKUquAVcJPoK1VR4pXRlPxMks5qm3KrgaJpZM4J0m43
.
No strong feelings on pointers (clearer as @kevinushey says) versus references (bettern 'modern' C++ ?). |
}; | ||
|
||
ROW_SUMS_IMPL_KEEPNA(LGLSXP) | ||
ROW_SUMS_IMPL_KEEPNA(INTSXP) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same #undef
here?
Barring some very minor stylistic suggestions, LGTM! |
Thanks @kevinushey . We'll see if @nathan-russell has time for a revision, else we can probably take it as is. |
Those are reasonable suggestions; thanks for reviewing everyone. |
As discussed in #549, this commit adds Sugar functions for
rowSums
,colSums
,rowMeans
, andcolMeans
, along with unit tests.