Repository navigation
Specialize the sparse reducedim_init of maximum, minimum and extrema on f - #1104
Merged
Merged
Conversation
…ma` on `f` Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1104 +/- ##
=======================================
Coverage 94.83% 94.83%
=======================================
Files 16 16
Lines 10252 10252
=======================================
Hits 9722 9722
Misses 530 530 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
maximum,minimumandextremaalong a dimension of a sparse array spent about 16 µs per call looking up aninvokeat run time, however small the array.Before (minimum time per call, 4×3 matrix and length-4 vector)
After
On a 10000×10000 matrix with density 1e-3,
maximum(A; dims=1)goes from 347 µs to 320 µs and allocates 864 B less.sumalong a dimension is unchanged._reducedim_init_denseand the sparsereducedim_initmethods formax,minand_extrema_rfonly passfon, so Julia compiled them forf::Function. Theinvoke(Base.reducedim_init, Tuple{typeof(f), …})that seeds the result from the first slice then became a dynamic invoke. Base's unspecialized method behind it dispatchedisnan,isunordered,mapreduceandreducedim_initarrayat run time. Writingf::Fmakes the invoke static. The set of methods and their behaviour are unchanged.Left out: Base's
_mapreduce_dimdoes not specialize onfandopeither, so it dispatchesreducedim_initandmapreducedim!dynamically. A denseMatrixbehaves the same way.🤖 Generated with Claude Code