Skip to content

Copy wrapped transposes into destinations of any shape - #887

Merged
maleadt merged 1 commit into
mainfrom
tb/copyto-adjtrans
Dec 3, 2026
Merged

maleadt merged 1 commit into
mainfrom
tb/copyto-adjtrans

Conversation

@maleadt

@maleadt maleadt commented Dec 2, 2026

Copy link
Copy Markdown
Member

copyto!(dest, transpose(src)) forwarded to transpose!/adjoint!, which require dest to have the transposed shape of src. Base copies all of src in linear order into the leading elements of any large-enough dest, so a vector src hit a missing transpose_f! method and a larger dest threw DimensionMismatch. The in-place path is kept when the axes match; otherwise the wrapper is copied linearly with the generic copy kernel, after unaliasing it from dest.

Fixes #884

`copyto!(dest, transpose(src))` with GPU arrays always forwarded to
`transpose!`/`adjoint!`, which require `dest` to have the transposed shape
of `src`. Base instead copies all of `src` in linear order into the leading
elements of any large-enough `dest`, so a vector `src` (whose transpose is
a row) hit a missing `transpose_f!` method, and a larger matrix `dest`
threw a `DimensionMismatch`. Keep the in-place path when the axes match,
and otherwise copy the wrapper linearly with the generic copy kernel.

Fixes #884
@maleadt
maleadt merged commit 849c44f into main Dec 3, 2026
17 of 18 checks passed
@maleadt
maleadt deleted the tb/copyto-adjtrans branch December 3, 2026 05:36
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.

copyto!(dest, transpose(src)) on oneArray fails for empty vectors and for a larger matrix destination

1 participant