From d458e03a8933b900c1227b66d673c6db0df51b3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Kl=C3=B6wer?= Date: Thu, 21 Mar 2024 13:37:44 -0400 Subject: [PATCH 1/2] LowerTriangularMatrix copyto! range bug --- src/LowerTriangularMatrices/lower_triangular_matrix.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LowerTriangularMatrices/lower_triangular_matrix.jl b/src/LowerTriangularMatrices/lower_triangular_matrix.jl index 5216541f9..61fc3a4aa 100644 --- a/src/LowerTriangularMatrices/lower_triangular_matrix.jl +++ b/src/LowerTriangularMatrices/lower_triangular_matrix.jl @@ -159,7 +159,7 @@ function Base.copyto!( L1::LowerTriangularMatrix{T}, # copy to L1 lmax, mmax = size(L1) # but the size of L1 to loop lm = 0 - @inbounds for m in 1:maximum(ms) + @inbounds for m in 1:mmax for l in m:lmax lm += 1 L1[lm] = (l in ls) && (m in ms) ? convert(T, L2[l, m]) : L1[lm] From a4c34cd4d3c43d46f6058f653a3cdffce139ee83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Kl=C3=B6wer?= Date: Thu, 21 Mar 2024 14:07:32 -0400 Subject: [PATCH 2/2] LTM copyto! with ranges, tests added --- test/lower_triangular_matrix.jl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/lower_triangular_matrix.jl b/test/lower_triangular_matrix.jl index 2680c7e36..3031f80e5 100644 --- a/test/lower_triangular_matrix.jl +++ b/test/lower_triangular_matrix.jl @@ -129,6 +129,20 @@ end copyto!(L2, L1) @test L2 == L2c + + # with ranges + L1 = zeros(LowerTriangularMatrix{NF}, 33, 32); + L2 = randn(LowerTriangularMatrix{NF}, 65, 64); + L2T = spectral_truncation(L2,(size(L1) .- 1)...) + + copyto!(L1, L2, 1:33, 1:32) # size of smaller matrix + @test L1 == L2T + + copyto!(L1, L2, 1:65, 1:64) # size of bigger matrix + @test L1 == L2T + + copyto!(L1, L2, 1:50, 1:50) # in between + @test L1 == L2T end end