Use type inference for blocktype instead of runtime mapreduce#255
Merged
Use type inference for blocktype instead of runtime mapreduce#255
Conversation
The generic `blocktype(::AbstractArray)` previously used `mapreduce(typeof, promote_type, blocks(a))` which relied on aggressive const-propagation for type stability and failed on empty arrays. Replace with `eltype_inferred(blocks(a))` which uses static type parameters by default, with a `BlocksView` specialization that uses `promote_op` for a tighter result. Relax the `BlockedArray` `blocktype` test from `@constinferred` to a plain subtype check since the inferred type may be abstract or a Union depending on the parent array type. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #255 +/- ##
==========================================
+ Coverage 71.94% 71.99% +0.04%
==========================================
Files 36 36
Lines 2032 2032
==========================================
+ Hits 1462 1463 +1
+ Misses 570 569 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 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.
Summary
mapreduce(typeof, promote_type, blocks(a))inblocktype(::AbstractArray)witheltype_inferred(blocks(a)), which uses static type parameters by default.eltype_inferred(::BlocksView)specialization usingpromote_op(getindex, ...)for a tighter result than the abstracteltype.BlockedArrayblocktypetest from@constinferred ... <: SubArraytoblocktype(a) <: AbstractMatrix{elt}, since the inferred type depends on the parent array and may be abstract or a Union.The previous implementation relied on aggressive const-propagation that broke on Julia v1.12.6 x86_64 (JuliaLang/julia#57582 changed inference behavior). It also errored on empty arrays.
Test plan
test_basics.jlpasses locally (fresh subprocess, all 6 arraytype/eltype combos)🤖 Generated with Claude Code