Skip to content

Commit 234baad

Browse files
Add missing copy!(::AbstractMatrix, ::UniformScaling) method (#55970)
Hi everyone! First PR to Julia here. It was noticed in a Slack thread yesterday that `copy!(A, I)` doesn't work, but `copyto!(A, I)` does. This PR adds the missing method for `copy!(::AbstractMatrix, ::UniformScaling)`, which simply defers to `copyto!`, and corresponding tests. I added a `compat` notice for Julia 1.12. --------- Co-authored-by: Lilith Orion Hafner <[email protected]>
1 parent 77c5875 commit 234baad

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

stdlib/LinearAlgebra/src/uniformscaling.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,16 @@ function copyto!(A::Tridiagonal, J::UniformScaling)
403403
return A
404404
end
405405

406+
"""
407+
copy!(dest::AbstractMatrix, src::UniformScaling)
408+
409+
Copies a [`UniformScaling`](@ref) onto a matrix.
410+
411+
!!! compat "Julia 1.12"
412+
This method is available as of Julia 1.12.
413+
"""
414+
Base.copy!(A::AbstractMatrix, J::UniformScaling) = copyto!(A, J)
415+
406416
function cond(J::UniformScaling{T}) where T
407417
onereal = inv(one(real(J.λ)))
408418
return J.λ zero(T) ? onereal : oftype(onereal, Inf)

stdlib/LinearAlgebra/test/uniformscaling.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ let
226226
@test copyto!(B, J) ==zero(λ)]
227227
end
228228

229+
@testset "copy!" begin
230+
A = Matrix{Int}(undef, (3,3))
231+
@test copy!(A, I) == one(A)
232+
B = Matrix{ComplexF64}(undef, (1,2))
233+
@test copy!(B, J) ==zero(λ)]
234+
end
235+
229236
@testset "binary ops with vectors" begin
230237
v = complex.(randn(3), randn(3))
231238
# As shown in #20423@GitHub, vector acts like x1 matrix when participating in linear algebra

0 commit comments

Comments
 (0)