Skip to content

Commit 16a2b0d

Browse files
committed
Rename _has_matching_storage to _has_matching_zeros
1 parent 3ee4650 commit 16a2b0d

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

stdlib/LinearAlgebra/src/diagonal.jl

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,9 @@ end
405405
end
406406
out
407407
end
408-
_has_matching_storage(out::UpperOrUnitUpperTriangular, A::UpperOrUnitUpperTriangular) = true
409-
_has_matching_storage(out::LowerOrUnitLowerTriangular, A::LowerOrUnitLowerTriangular) = true
410-
_has_matching_storage(out, A) = false
408+
_has_matching_zeros(out::UpperOrUnitUpperTriangular, A::UpperOrUnitUpperTriangular) = true
409+
_has_matching_zeros(out::LowerOrUnitLowerTriangular, A::LowerOrUnitLowerTriangular) = true
410+
_has_matching_zeros(out, A) = false
411411
function _rowrange_tri_stored(B::UpperOrUnitUpperTriangular, col)
412412
isunit = B isa UnitUpperTriangular
413413
1:min(col-isunit, size(B,1))
@@ -416,31 +416,27 @@ function _rowrange_tri_stored(B::LowerOrUnitLowerTriangular, col)
416416
isunit = B isa UnitLowerTriangular
417417
col+isunit:size(B,1)
418418
end
419-
_rowrange_tri_nonstored(B::UpperOrUnitUpperTriangular, col) = col+1:size(B,1)
420-
_rowrange_tri_nonstored(B::LowerOrUnitLowerTriangular, col) = 1:col-1
419+
_rowrange_tri_zeros(B::UpperOrUnitUpperTriangular, col) = col+1:size(B,1)
420+
_rowrange_tri_zeros(B::LowerOrUnitLowerTriangular, col) = 1:col-1
421421
function __muldiag_nonzeroalpha!(out, D::Diagonal, B::UpperOrLowerTriangular, _add::MulAddMul)
422422
isunit = B isa UnitUpperOrUnitLowerTriangular
423-
out_maybeparent, B_maybeparent = _has_matching_storage(out, B) ? (parent(out), parent(B)) : (out, B)
423+
out_maybeparent, B_maybeparent = _has_matching_zeros(out, B) ? (parent(out), parent(B)) : (out, B)
424424
for j in axes(B, 2)
425425
# store the diagonal separately for unit triangular matrices
426426
if isunit
427427
@inbounds _modify!(_add, D.diag[j] * B[j,j], out, (j,j))
428428
end
429-
# indices of out corresponding to the stored indices of B
429+
# The indices of out corresponding to the stored indices of B
430430
rowrange = _rowrange_tri_stored(B, j)
431431
@inbounds @simd for i in rowrange
432432
_modify!(_add, D.diag[i] * B_maybeparent[i,j], out_maybeparent, (i,j))
433433
end
434-
# indices of out corresponding to the zeros of B
434+
# Fill the indices of out corresponding to the zeros of B
435435
# we only fill these if out and B don't have matching zeros
436-
if !_has_matching_storage(out, B)
437-
rowrange = _rowrange_tri_nonstored(B, j)
438-
if haszero(eltype(out))
439-
_rmul_or_fill!(@view(out[rowrange,j]), _add.beta)
440-
else
441-
@inbounds @simd for i in rowrange
442-
_modify!(_add, D.diag[i] * B[i,j], out, (i,j))
443-
end
436+
if !_has_matching_zeros(out, B)
437+
rowrange = _rowrange_tri_zeros(B, j)
438+
@inbounds @simd for i in rowrange
439+
_modify!(_add, D.diag[i] * B[i,j], out, (i,j))
444440
end
445441
end
446442
end
@@ -476,7 +472,7 @@ function __muldiag_nonzeroalpha!(out, A::UpperOrLowerTriangular, D::Diagonal, _a
476472
_add_aisone = MulAddMul{true,bis0,Bool,typeof(beta)}(true, beta)
477473
# if both A and out have the same upper/lower triangular structure,
478474
# we may directly read and write from the parents
479-
out_maybeparent, A_maybeparent = _has_matching_storage(out, A) ? (parent(out), parent(A)) : (out, A)
475+
out_maybeparent, A_maybeparent = _has_matching_zeros(out, A) ? (parent(out), parent(A)) : (out, A)
480476
for j in axes(A, 2)
481477
dja = _add(@inbounds D.diag[j])
482478
# store the diagonal separately for unit triangular matrices
@@ -488,16 +484,12 @@ function __muldiag_nonzeroalpha!(out, A::UpperOrLowerTriangular, D::Diagonal, _a
488484
@inbounds @simd for i in rowrange
489485
_modify!(_add_aisone, A_maybeparent[i,j] * dja, out_maybeparent, (i,j))
490486
end
491-
# indices of out corresponding to the zeros of A
487+
# Fill the indices of out corresponding to the zeros of A
492488
# we only fill these if out and A don't have matching zeros
493-
if !_has_matching_storage(out, A)
494-
rowrange = _rowrange_tri_nonstored(A, j)
495-
if haszero(eltype(out))
496-
_rmul_or_fill!(@view(out[rowrange,j]), _add.beta)
497-
else
498-
@inbounds @simd for i in rowrange
499-
_modify!(_add, A[i,j] * dja, out, (i,j))
500-
end
489+
if !_has_matching_zeros(out, A)
490+
rowrange = _rowrange_tri_zeros(A, j)
491+
@inbounds @simd for i in rowrange
492+
_modify!(_add, A[i,j] * dja, out, (i,j))
501493
end
502494
end
503495
end

0 commit comments

Comments
 (0)