Skip to content

Give a scalar the right shape in hcat(::Number, ::AbstractGPUArray) - #886

Merged
maleadt merged 1 commit into
mainfrom
tb/hcat-scalar
Dec 3, 2026
Merged

maleadt merged 1 commit into
mainfrom
tb/hcat-scalar

Conversation

@maleadt

@maleadt maleadt commented Dec 2, 2026

Copy link
Copy Markdown
Member

hcat(a::Number, b::AbstractGPUArray) turned the scalar into a column as tall as b. So hcat(1, AT(ones(2, 3))) returned a 2×4 array where Base throws a DimensionMismatch, and hcat(1, AT(ones(1, 2, 3))) threw where Base fills the scalar across the third dimension. In Base, a leading scalar in hcat/vcat is one element along the first dimension and along the concatenated one, and stretches along the others. The vcat method already did that; this makes hcat match.

Fixes #883

The scalar was made a column as tall as the other operand, so
`hcat(1, AT(ones(2, 3)))` returned a 2x4 array where Base throws a
DimensionMismatch, and `hcat(1, AT(ones(1, 2, 3)))` threw where Base
fills the scalar across the third dimension. Like Base (and the vcat
method next to it), make the scalar one element along the first two
dimensions and as long as the other operand along the rest.

Fixes #883
@maleadt
maleadt merged commit 55c4221 into main Dec 3, 2026
18 checks passed
@maleadt
maleadt deleted the tb/hcat-scalar branch December 3, 2026 05:35
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.

hcat of a scalar and a 2×0 matrix expands the scalar to two rows on oneArray

1 participant