Skip to content

Commit e30c9c3

Browse files
authored
Precise axes in generic_mattrimul! (#1300)
This changes e.g. `axes(B,1)` to `axes(A,1)` in an expression like ```diff for j in axes(B,2) - for i in axes(B,1) + for i in axes(A,1) Cij = (unit ? oA : A[i,i]) * B[i,j] for k in i + 1:lastindex(B,1) Cij += A[i,k] * B[k,j] ``` While we obtain the correct result either way, since, firstly, triangular matrices are square, and secondly, the axes being multiplied must match, it's best to be precise here.
1 parent 0a84e1d commit e30c9c3

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/triangular.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,7 @@ function generic_trimatmul!(C::AbstractVecOrMat, uploc, isunitc, tfun::Function,
14021402
@inbounds if uploc == 'U'
14031403
if tfun === identity
14041404
for j in axes(B,2)
1405-
for i in axes(B,1)
1405+
for i in axes(A,1)
14061406
Cij = (unit ? oA : A[i,i]) * B[i,j]
14071407
for k in i + 1:lastindex(B,1)
14081408
Cij += A[i,k] * B[k,j]
@@ -1424,7 +1424,7 @@ function generic_trimatmul!(C::AbstractVecOrMat, uploc, isunitc, tfun::Function,
14241424
else # uploc == 'L'
14251425
if tfun === identity
14261426
for j in axes(B,2)
1427-
for i in reverse(axes(B,1))
1427+
for i in reverse(axes(A,1))
14281428
Cij = (unit ? oA : A[i,i]) * B[i,j]
14291429
for k in firstindex(B,1):i - 1
14301430
Cij += A[i,k] * B[k,j]
@@ -1434,7 +1434,7 @@ function generic_trimatmul!(C::AbstractVecOrMat, uploc, isunitc, tfun::Function,
14341434
end
14351435
else # tfun in (transpose, adjoint)
14361436
for j in axes(B,2)
1437-
for i in axes(B,1)
1437+
for i in axes(A,2)
14381438
Cij = (unit ? oA : tfun(A[i,i])) * B[i,j]
14391439
for k in i + 1:lastindex(B,1)
14401440
Cij += tfun(A[k,i]) * B[k,j]
@@ -1455,7 +1455,7 @@ function generic_trimatmul!(C::AbstractVecOrMat, uploc, isunitc, ::Function, xA:
14551455
unit = isunitc == 'U'
14561456
@inbounds if uploc == 'U'
14571457
for j in axes(B,2)
1458-
for i in axes(B,1)
1458+
for i in axes(A,1)
14591459
Cij = (unit ? oA : conj(A[i,i])) * B[i,j]
14601460
for k in i + 1:lastindex(B,1)
14611461
Cij += conj(A[i,k]) * B[k,j]
@@ -1465,7 +1465,7 @@ function generic_trimatmul!(C::AbstractVecOrMat, uploc, isunitc, ::Function, xA:
14651465
end
14661466
else # uploc == 'L'
14671467
for j in axes(B,2)
1468-
for i in reverse(axes(B,1))
1468+
for i in reverse(axes(A,1))
14691469
Cij = (unit ? oA : conj(A[i,i])) * B[i,j]
14701470
for k in firstindex(B,1):i - 1
14711471
Cij += conj(A[i,k]) * B[k,j]
@@ -1485,7 +1485,7 @@ function generic_mattrimul!(C::AbstractMatrix, uploc, isunitc, tfun::Function, A
14851485
@inbounds if uploc == 'U'
14861486
if tfun === identity
14871487
for i in axes(A,1)
1488-
for j in reverse(axes(A,2))
1488+
for j in reverse(axes(B,2))
14891489
Cij = A[i,j] * (unit ? oB : B[j,j])
14901490
for k in firstindex(A,2):j - 1
14911491
Cij += A[i,k] * B[k,j]
@@ -1495,7 +1495,7 @@ function generic_mattrimul!(C::AbstractMatrix, uploc, isunitc, tfun::Function, A
14951495
end
14961496
else # tfun in (transpose, adjoint)
14971497
for i in axes(A,1)
1498-
for j in axes(A,2)
1498+
for j in axes(B,1)
14991499
Cij = A[i,j] * (unit ? oB : tfun(B[j,j]))
15001500
for k in j + 1:lastindex(A,2)
15011501
Cij += A[i,k] * tfun(B[j,k])
@@ -1507,7 +1507,7 @@ function generic_mattrimul!(C::AbstractMatrix, uploc, isunitc, tfun::Function, A
15071507
else # uploc == 'L'
15081508
if tfun === identity
15091509
for i in axes(A,1)
1510-
for j in axes(A,2)
1510+
for j in axes(B,2)
15111511
Cij = A[i,j] * (unit ? oB : B[j,j])
15121512
for k in j + 1:lastindex(A,2)
15131513
Cij += A[i,k] * B[k,j]
@@ -1517,7 +1517,7 @@ function generic_mattrimul!(C::AbstractMatrix, uploc, isunitc, tfun::Function, A
15171517
end
15181518
else # tfun in (transpose, adjoint)
15191519
for i in axes(A,1)
1520-
for j in reverse(axes(A,2))
1520+
for j in reverse(axes(B,1))
15211521
Cij = A[i,j] * (unit ? oB : tfun(B[j,j]))
15221522
for k in firstindex(A,2):j - 1
15231523
Cij += A[i,k] * tfun(B[j,k])
@@ -1538,7 +1538,7 @@ function generic_mattrimul!(C::AbstractMatrix, uploc, isunitc, ::Function, A::Ab
15381538
unit = isunitc == 'U'
15391539
@inbounds if uploc == 'U'
15401540
for i in axes(A,1)
1541-
for j in reverse(axes(A,2))
1541+
for j in reverse(axes(B,2))
15421542
Cij = A[i,j] * (unit ? oB : conj(B[j,j]))
15431543
for k in firstindex(A,2):j - 1
15441544
Cij += A[i,k] * conj(B[k,j])
@@ -1548,7 +1548,7 @@ function generic_mattrimul!(C::AbstractMatrix, uploc, isunitc, ::Function, A::Ab
15481548
end
15491549
else # uploc == 'L'
15501550
for i in axes(A,1)
1551-
for j in axes(A,2)
1551+
for j in axes(B,2)
15521552
Cij = A[i,j] * (unit ? oB : conj(B[j,j]))
15531553
for k in j + 1:lastindex(A,2)
15541554
Cij += A[i,k] * conj(B[k,j])

0 commit comments

Comments
 (0)