Repository navigation
Rewrite the scalar arithmetic functions in C - #147
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The four scalar arithmetic functions (
sparse_addition_scalar(),sparse_subtraction_scalar(),sparse_multiplication_scalar()andsparse_division_scalar()) now do their work in C instead of building a new sparse vector from R vectors. The R wrappers keep the cheap shortcuts (NA, identity values, the denseval = 0division result from #146) and then call one shared C routine with an operation tag.On this machine a call on a small sparse vector goes from about 10 us to about 1.5 us. With one million stored doubles, addition goes from 9.8 ms to 2.6 ms, multiplication from 6.2 ms to 3.4 ms and division from 6.2 ms to 3.0 ms. Integer vectors improve less, 6.2 ms to 4.6 ms for addition.
I compared the old and new code over a grid of 1368 inputs and values, and every case where the old code succeeded gives the same result. The intended differences, all noted in
NEWS.md:NAwith the usual "NAs produced by integer overflow" warning, as dense integer vectors do, instead of an error. An overflowing default value still errors.sparse_division_scalar()now errors for sparse logical input, instead of silently accepting it.InforNaN, or aNaNdefault) still error, with clearer messages.valstill works on sparse integer vectors when every result is a whole number, and errors otherwise.Multiplying by 0 keeps stored
NAvalues in C too, so the fix from #145 is not undone. The test added there fails against the earlier version of this C code.Closes #88.