Repository navigation
replace - #1072
Open
willow-ahrens wants to merge 2 commits into
Open
replace#1072willow-ahrens wants to merge 2 commits into
willow-ahrens wants to merge 2 commits into
Conversation
This branch has not been deployed
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.
fixes #992
adds a function
xp.replace(array, old, new)which replaces valueoldwith valuenewinarray. This function is helpful in sparse kernels. for example, after loading a graph matrix, one may wish to replace the zero value with infinity if they wish to then implement a shortest-paths operation: https://github.com/SparseArrayProgrammingSuite/SparseArrayProgrammingSuite/blob/33b2949b4c0e960df8818e94406ed5bd970cc76c/src/saps/util/adjacency.py#L63.The operation
sparse.where(A != old, A, np.inf)needs to allocate a boolean mask to perform this operation, but a fused replace would be a good moment to signal to sparse arrays that they should change fill values explicitly, and could give an opportunity to do so in O(1) time if the explicitly stored entries are already known not to be fill.This can also be a good way to fix exceptional values, like
NaN -> 0versusNaN -> Infhttps://github.com/SparseArrayProgrammingSuite/SparseArrayProgrammingSuite/blob/33b2949b4c0e960df8818e94406ed5bd970cc76c/src/saps/benchmarks/pcg.py#L1920