Skip to content

Commit

Permalink
Merge pull request #501 from SpeedyWeather/mk/ltm_bug
Browse files Browse the repository at this point in the history
LowerTriangularMatrix copyto! range bug
  • Loading branch information
milankl authored Mar 21, 2024
2 parents 4baf70f + a4c34cd commit d23f17d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/LowerTriangularMatrices/lower_triangular_matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
14 changes: 14 additions & 0 deletions test/lower_triangular_matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d23f17d

Please sign in to comment.