Skip to content

Concatenate scalars with layout arrays via typed_vcat/typed_hcat - #286

Merged
dlfivefifty merged 2 commits into
masterfrom
scalar-layout-cat
Oct 11, 2026
Merged

dlfivefifty merged 2 commits into
masterfrom
scalar-layout-cat

Conversation

@dlfivefifty

Copy link
Copy Markdown
Member

[2; v] with v a layout array (e.g. BandedMatrix(1 => 1:∞)[band(1)] or view(A, 2:∞, 2)) dispatched to Base's generic cat, which never reaches the ArrayLayouts.typed_vcat(T, size, A...) hook. For infinite lazy arrays this hangs, because the result is allocated as a zeros(∞) cache and v is copied into it, whereas [[2]; v] already gives a lazy Vcat.

This PR adds Base.typed_vcat/Base.typed_hcat methods for one or two scalars followed by a LayoutVecOrMats, routing them through the existing hook. The finite fallback uses Base._cat_t when scalars are present (as Base does), so finite results are unchanged.

With InfiniteArrays, the following now all return a lazy Vcat instead of hanging: [2; v], [2; 3; v], vcat(2, v), [2; view(A, band(1))], [2; view(B, 2:∞, 2)], [2; cumsum(1:∞)], [2; (1:∞).^2], [2 view(B, 2:2, 2:∞)].

Merge after JuliaArrays/InfiniteArrays.jl#244: without it, [1; 2; zeros(Int,∞)] would become a Vcat rather than a CachedArray, failing an InfiniteArrays test. With both, the InfiniteArrays and LazyArrays test suites pass.

Not covered: mixed prefixes such as [1.0; 2:3; v] still take the generic path (as [[1]; [2]; v] already does).

🤖 Generated with Claude Code

…ped_hcat

[2; v] with v a layout array previously fell back to Base's generic cat,
which for infinite lazy arrays hangs trying to copy v. Route one or two
scalar prefixes through ArrayLayouts.typed_vcat/typed_hcat so packages
like InfiniteArrays can return a lazy Vcat/Hcat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.56%. Comparing base (0d4c00b) to head (f154ca8).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #286      +/-   ##
==========================================
+ Coverage   90.33%   90.56%   +0.23%     
==========================================
  Files          12       12              
  Lines        1987     2036      +49     
==========================================
+ Hits         1795     1844      +49     
  Misses        192      192              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dlfivefifty
dlfivefifty merged commit 1a42cba into master Oct 11, 2026
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant