Skip to content

Use cpp median function instead of base R's - #7

Open
chinandrew wants to merge 3 commits into
martakarass:masterfrom
chinandrew:median_cpp
Open

chinandrew wants to merge 3 commits into
martakarass:masterfrom
chinandrew:median_cpp

Conversation

@chinandrew

@chinandrew chinandrew commented May 22, 2023

Copy link
Copy Markdown

Relatively minor change here that I just threw in because I introduced Rcpp elsewhere already. Probably not worth including if I'm honest but opening this PR just for completeness.

Profiled code. After the other optimizations that brought runs down <30s it made a bit more sense, but by itself when runs were 70-150s (depending on compute.template.idx) it doesn't do much:

Before:
median_before

After (before I updated the naming to camelcase):
median_after

@muschellij2

Copy link
Copy Markdown
Collaborator

Does this work fine with NAs/NaNs/etc? I think adding a test would help.

@chinandrew

Copy link
Copy Markdown
Author

Does this work fine with NAs/NaNs/etc? I think adding a test would help.

Yes for NA and NaN, tests with these cases have been added.

Where they don't agree is NULL/c(), since Rcpp doesn't expect the NULL type so it errors. We can add a check for this case if needed.

Though as I mention in the original description, I do think it's worth discussing if this change is even worth including at all. It's only a few % speedup but at the cost of some complexity, which I normally wouldn't advocate for unless there's a material difference between, say, a run taking 23 hours instead of 24.

@muschellij2

Copy link
Copy Markdown
Collaborator

After discussion with @chinandrew - probably close.

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.

2 participants