Skip to content

Commit 6e2de14

Browse files
authored
Remove bounds-checking in Bidiagonal rdiv! (#1281)
This improves performance ```julia julia> B = Bidiagonal(fill(10.0,400), fill(2.0,399), :L); julia> x = UpperTriangular(fill(400.0, size(B))); julia> @Btime $x/$B; 193.799 μs (3 allocations: 1.22 MiB) # nightly 163.389 μs (3 allocations: 1.22 MiB) # this PR ``` Also, seems to reduce TTFX slightly, but at the expense of allocations: ```julia julia> T = Bidiagonal(ones(4), ones(3), :U); TM = Matrix(T); x = UpperTriangular(TM); julia> @time x/T; 0.125422 seconds (104.07 k allocations: 5.261 MiB, 99.95% compilation time) # nightly 0.099386 seconds (113.82 k allocations: 5.748 MiB, 99.94% compilation time) # this PR ```
1 parent 84fd21b commit 6e2de14

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/bidiag.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,27 +1334,27 @@ function _rdiv!(C::AbstractMatrix, A::AbstractMatrix, B::Bidiagonal)
13341334
isnothing(zi) || throw(SingularException(zi))
13351335

13361336
if B.uplo == 'L'
1337-
diagB = B.dv[n]
1338-
for i in 1:m
1339-
C[i,n] = A[i,n] / diagB
1337+
diagB = @inbounds B.dv[n]
1338+
for i in axes(A,1)
1339+
@inbounds C[i,n] = A[i,n] / diagB
13401340
end
1341-
for j in n-1:-1:1
1342-
diagB = B.dv[j]
1343-
offdiagB = B.ev[j]
1344-
for i in 1:m
1345-
C[i,j] = (A[i,j] - C[i,j+1]*offdiagB)/diagB
1341+
for j in reverse(axes(A,2)[1:end-1]) # n-1:-1:1
1342+
diagB = @inbounds B.dv[j]
1343+
offdiagB = @inbounds B.ev[j]
1344+
for i in axes(A,1)
1345+
@inbounds C[i,j] = (A[i,j] - C[i,j+1]*offdiagB)/diagB
13461346
end
13471347
end
13481348
else
1349-
diagB = B.dv[1]
1350-
for i in 1:m
1351-
C[i,1] = A[i,1] / diagB
1349+
diagB = @inbounds B.dv[1]
1350+
for i in axes(A,1)
1351+
@inbounds C[i,1] = A[i,1] / diagB
13521352
end
1353-
for j in 2:n
1354-
diagB = B.dv[j]
1355-
offdiagB = B.ev[j-1]
1356-
for i = 1:m
1357-
C[i,j] = (A[i,j] - C[i,j-1]*offdiagB)/diagB
1353+
for j in axes(A,2)[2:end]
1354+
diagB = @inbounds B.dv[j]
1355+
offdiagB = @inbounds B.ev[j-1]
1356+
for i in axes(A,1)
1357+
@inbounds C[i,j] = (A[i,j] - C[i,j-1]*offdiagB)/diagB
13581358
end
13591359
end
13601360
end

0 commit comments

Comments
 (0)