From 99d11d81a5efa5f0b90d9bd1ac99877b072ca04c Mon Sep 17 00:00:00 2001 From: WalterMadelim <143272683+WalterMadelim@users.noreply.github.com> Date: Sat, 10 May 2025 15:50:26 +0800 Subject: [PATCH 1/4] Update the docstring of ldiv! The existing two examples in docstring reads well respectively, but not in conjunction: In the above example it mutates Y, whereas in the lower example it mutates X. Hope that after revising it looks more clean and intelligible. --- src/LinearAlgebra.jl | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/LinearAlgebra.jl b/src/LinearAlgebra.jl index 7be8c25a..44740a8c 100644 --- a/src/LinearAlgebra.jl +++ b/src/LinearAlgebra.jl @@ -392,15 +392,13 @@ control over the factorization of `A`. # Examples ```jldoctest -julia> A = [1 2.2 4; 3.1 0.2 3; 4 1 2]; +julia> A, B = [1 2.2 4; 3.1 0.2 3; 4 1 2], [1, 2.5, 3]; -julia> X = [1; 2.5; 3]; +julia> Y = copy(B); -julia> Y = zero(X); +julia> ldiv!(Y, qr(A), B); # also try qr!(A) for the 2nd arg -julia> ldiv!(Y, qr(A), X); - -julia> Y ≈ A\\X +julia> Y ≈ A \ B true ``` """ @@ -424,15 +422,13 @@ control over the factorization of `A`. # Examples ```jldoctest -julia> A = [1 2.2 4; 3.1 0.2 3; 4 1 2]; - -julia> X = [1; 2.5; 3]; +julia> A, B = [1 2.2 4; 3.1 0.2 3; 4 1 2], [1, 2.5, 3]; -julia> Y = copy(X); +julia> B0 = copy(B); -julia> ldiv!(qr(A), X); +julia> ldiv!(lu(A), B); # also try lu!(A) for the 1st arg -julia> X ≈ A\\Y +julia> B ≈ A \ B0 true ``` """ From 97ee7d233d253d04abb8b0cfe368175f5a3cfe33 Mon Sep 17 00:00:00 2001 From: WalterMadelim <143272683+WalterMadelim@users.noreply.github.com> Date: Sat, 10 May 2025 16:02:40 +0800 Subject: [PATCH 2/4] Update the docstring of ldiv! --- src/LinearAlgebra.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/LinearAlgebra.jl b/src/LinearAlgebra.jl index 44740a8c..441ab85f 100644 --- a/src/LinearAlgebra.jl +++ b/src/LinearAlgebra.jl @@ -398,7 +398,7 @@ julia> Y = copy(B); julia> ldiv!(Y, qr(A), B); # also try qr!(A) for the 2nd arg -julia> Y ≈ A \ B +julia> Y ≈ A \\ B true ``` """ @@ -428,7 +428,7 @@ julia> B0 = copy(B); julia> ldiv!(lu(A), B); # also try lu!(A) for the 1st arg -julia> B ≈ A \ B0 +julia> B ≈ A \\ B0 true ``` """ From d947bcdc37df973ea0061ce24f022ad42d843c6d Mon Sep 17 00:00:00 2001 From: WalterMadelim <143272683+WalterMadelim@users.noreply.github.com> Date: Sat, 10 May 2025 18:55:05 +0800 Subject: [PATCH 3/4] Update docstring for ldiv! --- src/LinearAlgebra.jl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/LinearAlgebra.jl b/src/LinearAlgebra.jl index 441ab85f..4001f277 100644 --- a/src/LinearAlgebra.jl +++ b/src/LinearAlgebra.jl @@ -392,11 +392,13 @@ control over the factorization of `A`. # Examples ```jldoctest -julia> A, B = [1 2.2 4; 3.1 0.2 3; 4 1 2], [1, 2.5, 3]; +julia> A = [1 2.2 4; 3.1 0.2 3; 4 1 2]; + +julia> B = [1, 2.5, 3]; julia> Y = copy(B); -julia> ldiv!(Y, qr(A), B); # also try qr!(A) for the 2nd arg +julia> ldiv!(Y, qr(A), B); # you may also try qr!(A) to further reduce allocation julia> Y ≈ A \\ B true @@ -422,11 +424,13 @@ control over the factorization of `A`. # Examples ```jldoctest -julia> A, B = [1 2.2 4; 3.1 0.2 3; 4 1 2], [1, 2.5, 3]; +julia> A = [1 2.2 4; 3.1 0.2 3; 4 1 2]; + +julia> B = [1, 2.5, 3]; julia> B0 = copy(B); -julia> ldiv!(lu(A), B); # also try lu!(A) for the 1st arg +julia> ldiv!(lu(A), B); # you may also try lu!(A) to further reduce allocation julia> B ≈ A \\ B0 true From 0df47a53c7f02887d075b3fdd30bd8e8f42905ad Mon Sep 17 00:00:00 2001 From: WalterMadelim <143272683+WalterMadelim@users.noreply.github.com> Date: Sat, 10 May 2025 19:26:07 +0800 Subject: [PATCH 4/4] use similar --- src/LinearAlgebra.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/LinearAlgebra.jl b/src/LinearAlgebra.jl index 4001f277..bfeaa7e3 100644 --- a/src/LinearAlgebra.jl +++ b/src/LinearAlgebra.jl @@ -396,7 +396,7 @@ julia> A = [1 2.2 4; 3.1 0.2 3; 4 1 2]; julia> B = [1, 2.5, 3]; -julia> Y = copy(B); +julia> Y = similar(B); # use similar since there is no need to read from it julia> ldiv!(Y, qr(A), B); # you may also try qr!(A) to further reduce allocation @@ -428,7 +428,7 @@ julia> A = [1 2.2 4; 3.1 0.2 3; 4 1 2]; julia> B = [1, 2.5, 3]; -julia> B0 = copy(B); +julia> B0 = copy(B); # a backup copy to facilitate testing julia> ldiv!(lu(A), B); # you may also try lu!(A) to further reduce allocation