← Back to Pull requests

Let `map` and `map!` take several source arrays #130

Closed
unknown closed this pull request without merging on Oct 01, 2026 09:09 UTC
View on GitHub
unknown unknown commented on Sep 23, 2026 09:31 UTC
Author

AK.map! and AK.map now take several source arrays and call f with one element of each, as Base.map! does and as AK.mapreduce(f, op, A, B...) already allows (thrust's binary transform, which the README lists as the counterpart of map):

AK.map(+, a, b)
AK.map((x, y, z) -> x * y + z, a, b, c)
AK.map!(-, dst, a, b)
AK.map((i, x) -> x > 0.5f0 ? i : 0, 1:length(a), a)   # a range runs on the backend of `a`

The contract extends the single-source one:

  • the destination and every source have the same length (else an ArgumentError), and elements are matched in column-major order, so shapes may differ;

  • map allocates an array with the shape and eltype of the first source;

  • backend is resolved over the destination and all sources;

  • dst may be one of the sources, but must not otherwise share memory with them.
  • Arrays with the same axes are indexed together with eachindex(dst, srcs...), and the rest by position. This also fixes single-source map! from an array without fast linear indexing, such as view(A, 1:3, 2:5), into a destination of another shape. It used to index the destination with the source's Cartesian indices and threw a BoundsError.

    The first commit fixes foreachindex/foraxes (the launcher behind map!) for index collections that do not start at 1, such as eachindex of an OffsetArray. They mapped positions 1:n straight to indices[i], so a loop over 0:2 visited 1, 2 and 3. With @inbounds in the loop body, as the docs recommend, that wrote out of bounds.

    Performance on an RTX 5080, 2^26 Float32s:

    | | before | after |
    |---|---|---|
    | map!(f, y, x) | 651 μs | 650 μs |
    | map!(+, z, x, y) | n/a | 947 μs (z .= x .+ y: 947 μs) |
    | view → matrix (same axes) / view → vector (by position) | 653 μs / BoundsError | 652 μs / 654 μs |

    Tested on CPU (threads), CUDA, OpenCL (PoCL), AMDGPU, Metal and oneAPI.

    Diff: 237 lines (+177 / -60) across 2 files Reviewer: maleadt Review duration: 11498m
    All Vouch review confidence checks passed
    Residual risk 0.13 = Change Risk (0.37) × (1 − Review Confidence (0.64)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 237 lines diff across 2 files
    0.37
    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: 70%
    64%
    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.327
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #130"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 64% 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: 37.2% (MEDIUM) · Higher = larger blast radius
    37.2%
    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: 64% · Lower = rushed or shallow review
    64%
    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: 13.4% · Safe to merge
    13.4%