← Back to Pull requests

Use the fast path for FixedSizeArrays #127

Closed
unknown closed this pull request without merging on Oct 17, 2026 18:17 UTC
View on GitHub
unknown unknown commented on Oct 13, 2026 12:26 UTC
Author

Fixes #126.

fast_materialize!, fast_materialize and fast_materialize_threaded used the fast path only for DefaultArrayStyle. FixedSizeArray defines its own FixedSizeArrayBroadcastStyle, but only so that broadcasting returns a FixedSizeArray, so @.. fell back to Base's materialize!, including the unalias checks.

Changes


  • The dispatch now checks the existing use_fast_broadcast(S) trait first. Within the fast path, any style S <: AbstractArrayStyle{0} is materialized to a scalar, matching Base's copy(::Broadcasted{<:AbstractArrayStyle{0}}). The scalar is computed once, via only(bc), or fill!(dst, bc[1]) in-place. _broadcasted's collapsing of nested 0-dim broadcasts uses the same rule.

  • - Before this change, that 0-dim branch was hard-coded to DefaultArrayStyle{0}, so use_fast_broadcast(DefaultArrayStyle{0}) is now true.
    - Styles that don't opt in (e.g. GPU arrays, which override copy for 0-dim broadcasts to avoid scalar indexing) still go through materialize/materialize!.
  • The new FixedSizeArraysExt opts in every FixedSizeArrayBroadcastStyle, including {0}. A 0-dim FixedSizeArray now behaves like a 0-dim Array under @... Previously it fell back to Base, which evaluates the broadcast once per destination element.

  • use_fast_broadcast now has a docstring.

  • Tests cover in-place and out-of-place use, threaded use, mixing with Arrays, matrices with transposed vectors, DimensionMismatch, and 0-dim broadcasts. The 0-dim tests check the result types and that the function is called once, for both Array and FixedSizeArray. The QA environment loads FixedSizeArrays so the new extension gets checked.

  • Version bumped to 1.5.0.
  • Behavior change: dynamic broadcasts with FixedSizeArrays (e.g. a 1×n FixedSizeMatrix against an m×n one) now throw DimensionMismatch, as they already do for Arrays.

    RecursiveArrayTools: use_fast_broadcast(DefaultArrayStyle{0}) was false to keep 0-dim broadcasts away from RecursiveArrayTools' FastBroadcast extension, which (like RecursiveArrayTools' broadcasting into a VectorOfArray in general) mishandles arguments with fewer dimensions than the VectorOfArray: SciML/RecursiveArrayTools.jl#680. @.. never passes 0-dim broadcasts to fast_materialize! (_broadcasted collapses them to a scalar first), so @.. voa = 3 * r with r = Ref(2.0) or r = fill(2.0) works on this branch, as on master. Only direct calls of the internal fast_materialize! with a 0-dim Broadcasted would now reach that bug.

    Benchmark


    This is the benchmark from #126, run without the manual opt-in (Julia 1.13.1, one thread):

    | eltype | n | Vector | FixedSizeVector |
    |---|---|---|---|
    | Float64 | 3 | 4.7 ns | 4.4 ns |
    | Float64 | 8 | 3.6 ns | 3.9 ns |
    | Float64 | 100 | 15.9 ns | 15.7 ns |
    | Dual{…,2} | 3 | 4.7 ns | 4.7 ns |
    | Dual{…,2} | 8 | 7.3 ns | 7.3 ns |
    | Dual{…,2} | 100 | 61.2 ns | 62.0 ns |

    Before this change, FixedSizeVector took 7.4–11.1 ns at n = 3 and 8.

    Core and QA tests pass locally.

    🤖 Generated with Claude Code

    Diff: 390 lines (+292 / -98) across 4 files Reviewer: oscardssmith Review duration: 6110m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 390 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.357
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #127"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 43.1% (MEDIUM) · Higher = larger blast radius
    43.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17% · Safe to merge
    17%