← Back to Pull requests

Treat `PtrArray` as CPU storage #629

Closed
unknown closed this pull request without merging on Nov 19, 2026 19:11 UTC
View on GitHub
unknown unknown commented on Nov 19, 2026 10:45 UTC
Author

Temporaries from TensorOperations' ManualAllocator are PtrArrays, which are not in CPUStorage = Union{Array, Memory}. Their recoupling workspace in fusion-tree transformations with real coefficients and complex data (e.g. SU(2), ComplexF64) therefore misses the BLAS.gemm! method of _recouple!, and mul! on the reshaped view of the reinterpreted buffer falls back to LinearAlgebra._generic_matmatmul!.

This adds PtrArray to CPUStorage. Its only use on main is that _recouple! method, whose body only reinterprets the buffer and passes pointers to BLAS. PtrArrays.jl becomes a direct dependency, with the compat bound of TensorOperations, which already depends on it. The grouped subblock kernel of #597 dispatches on the same CPUStorage, so once rebased it also applies to PtrArray-backed tensors. Measured on #597's head with PtrArray added there (an SU(2) PEPS CTMRG corner contraction, D = 7, χ = 49): ManualAllocator 0.085 s → 0.043 s with the _recouple! method alone, 0.010 s with both, against 0.012 s for a BufferAllocator.

Found in QuantumKitHub/PEPSKit.jl#482, where using a ManualAllocator gave a significant slowdown due to the BLAS.gemm! miss in the recouplings.

<details>
<summary>Reproducer</summary>

using TensorKit, TensorOperations
V = SU2Space(0 => 4, 1 // 2 => 4, 1 => 3, 3 // 2 => 2)
t = randn(ComplexF64, V ⊗ V ⊗ V ← V ⊗ V)
p = ((3, 1, 5), (2, 4))
ref = permute(t, p)
for allocator in (TensorOperations.DefaultAllocator(), TensorOperations.ManualAllocator())
    times = map(_ -> @elapsed(permute(t, p; allocator)), 1:2)
    println(rpad(nameof(typeof(allocator)), 17), round.(times; digits = 3), " s, ≈ default: ", permute(t, p; allocator) ≈ ref)
end

main:

DefaultAllocator [0.02, 0.009] s, ≈ default: true
ManualAllocator  [8.684, 0.029] s, ≈ default: true

This PR:
DefaultAllocator [0.021, 0.009] s, ≈ default: true
ManualAllocator  [5.52, 0.006] s, ≈ default: true

Julia 1.12.7, TensorOperations 5.8.4, 1 Julia thread, 8 BLAS threads; the first call includes compilation.
</details>

🤖 Generated with Claude Code

Diff: 272 lines (+204 / -68) across 3 files Reviewer: kshyatt Review duration: 505m
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 272 lines diff across 3 files
0.39
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.336
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #629"
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: 39.5% (MEDIUM) · Higher = larger blast radius
39.5%
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: 15.6% · Safe to merge
15.6%