Skip to content
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

New function psum/pprod #4188

Closed
wants to merge 8 commits into from
Closed

New function psum/pprod #4188

wants to merge 8 commits into from

Conversation

2005m
Copy link
Contributor

@2005m 2005m commented Jan 20, 2020

closes #3467. Towards #3189

@2005m 2005m added this to the 1.12.9 milestone Jan 20, 2020
@2005m 2005m added the WIP label Jan 20, 2020
@codecov
Copy link

codecov bot commented Jan 20, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@cfed1c8). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #4188   +/-   ##
=========================================
  Coverage          ?   99.61%           
=========================================
  Files             ?       72           
  Lines             ?    14028           
  Branches          ?        0           
=========================================
  Hits              ?    13974           
  Misses            ?       54           
  Partials          ?        0
Impacted Files Coverage Δ
R/merge.R 100% <ø> (ø)
src/subset.c 100% <ø> (ø)
R/as.data.table.R 100% <ø> (ø)
src/assign.c 100% <ø> (ø)
src/fwriteR.c 100% <100%> (ø)
src/dogroups.c 100% <100%> (ø)
src/frank.c 100% <100%> (ø)
R/frank.R 100% <100%> (ø)
src/freadR.c 100% <100%> (ø)
src/fread.c 99.52% <100%> (ø)
... and 16 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cfed1c8...abbbfed. Read the comment docs.

src/fifelse.c Outdated
@@ -343,3 +343,161 @@ SEXP fcaseR(SEXP na, SEXP rho, SEXP args) {
UNPROTECT(nprotect);
return ans;
}

SEXP psumR(SEXP na, SEXP args) {
if (!IS_TRUE_OR_FALSE(na)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use 2 whitespace, you used 8. It is so much horizontal scrolling now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change all my c files. Thank you for letting me know.

@2005m 2005m removed the WIP label Jan 21, 2020
@2005m
Copy link
Contributor Author

2005m commented Jan 21, 2020

Please note that we can had lines for openmp. Happy to do it if you want. These functions are already fast from an absolute point of view and are close to + and * in timing (even sometimes faster which surprised me)

@2005m 2005m requested a review from mattdowle January 21, 2020 21:08
src/fifelse.c Outdated
}
SEXPTYPE anstype = TYPEOF(SEXPPTR_RO(args)[0]);
const int64_t len0 = xlength(SEXPPTR_RO(args)[0]);
if (anstype != INTSXP && anstype != REALSXP) {
error("Argument 1 is of type %s. Only integer and double types are supported.", type2char(anstype));
error(_("Argument 1 is of type %s. Only integer and double types are supported."), type2char(anstype));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for translation, better to use %d here as well, then only one message to translate instead of 2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry Michael, I did not understand what you mean.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

each unique item wrapped in _() will generate a message to be translated

one with Argument 1, another with Argument %d -- twice as much work for our translation team

vs using Argument %d for both, and hard-coding 1 to fill that in the former case; looks same to user, very similar in code, and easier for translators

src/fifelse.c Outdated
}
const int n=length(args);
if (n <= 1) {
error(_("Please supply at least 2 arguments. (%d argument supplied)"), n);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why error, instead of just returning x itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it odd to provide 1 argument. A sum operation needs at least 2 arguments. Does it make sense to you to only provide 1 argument?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's odd, but edge case like this can come up in dynamic scripting, where e.g. user is running

DT[ , do.call(psum, .SD), .SDcols = is.numeric]

and DT has a variable number of numeric columns depending on some other conditions in the script.

This way, the user can use the same code to cover the normal case when there are several normal columns, as well as the case when there only ends up being one such column.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok will change that later. Tks

src/fifelse.c Outdated
"If you wish to 'recycle' your argument, please use rep() to make this intent "
"clear to the readers of your code."), i+1, len1, len0);
}
if (type > anstype) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use typeorder for this, the ordering of the SEXPTYPEs doesn't necessarily reflect the coercion order. I guess it's fine for just int/double but later we may add other types

@2005m 2005m closed this Apr 8, 2020
@2005m 2005m deleted the psum branch April 8, 2020 13:22
@jangorecki jangorecki modified the milestones: 1.12.11, 1.12.9 May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add psum?
3 participants