Skip to content

Commit 974425c

Browse files
committed
Cherry-pick changes from jishnub/bidigamul_empty
1 parent 2c56cf8 commit 974425c

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

stdlib/LinearAlgebra/src/bidiag.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -535,12 +535,18 @@ function rmul!(B::Bidiagonal, D::Diagonal)
535535
end
536536

537537
@noinline function check_A_mul_B!_sizes((mC, nC)::NTuple{2,Integer}, (mA, nA)::NTuple{2,Integer}, (mB, nB)::NTuple{2,Integer})
538+
# check for matching sizes in one column of B and C
539+
check_A_mul_B!_sizes((mC,), (mA, nA), (mB,))
540+
# ensure that the number of columns in B and C match
541+
if nB != nC
542+
throw(DimensionMismatch(lazy"second dimension of output C, $nC, and second dimension of B, $nB, must match"))
543+
end
544+
end
545+
@noinline function check_A_mul_B!_sizes((mC,)::Tuple{Integer}, (mA, nA)::NTuple{2,Integer}, (mB,)::Tuple{Integer})
538546
if mA != mC
539547
throw(DimensionMismatch(lazy"first dimension of A, $mA, and first dimension of output C, $mC, must match"))
540548
elseif nA != mB
541549
throw(DimensionMismatch(lazy"second dimension of A, $nA, and first dimension of B, $mB, must match"))
542-
elseif nB != nC
543-
throw(DimensionMismatch(lazy"second dimension of output C, $nC, and second dimension of B, $nB, must match"))
544550
end
545551
end
546552

@@ -563,6 +569,7 @@ _mul!(C::AbstractMatrix, A::BiTriSym, B::TriSym, _add::MulAddMul) =
563569
_mul!(C::AbstractMatrix, A::BiTriSym, B::Bidiagonal, _add::MulAddMul) =
564570
_bibimul!(C, A, B, _add)
565571
function _bibimul!(C, A, B, _add)
572+
require_one_based_indexing(C)
566573
check_A_mul_B!_sizes(size(C), size(A), size(B))
567574
n = size(A,1)
568575
if n <= 3
@@ -733,14 +740,9 @@ end
733740

734741
function _mul!(C::AbstractVecOrMat, A::BiTriSym, B::AbstractVecOrMat, _add::MulAddMul)
735742
require_one_based_indexing(C, B)
743+
check_A_mul_B!_sizes(size(C), size(A), size(B))
736744
nA = size(A,1)
737745
nB = size(B,2)
738-
if !(size(C,1) == size(B,1) == nA)
739-
throw(DimensionMismatch(lazy"A has first dimension $nA, B has $(size(B,1)), C has $(size(C,1)) but all must match"))
740-
end
741-
if size(C,2) != nB
742-
throw(DimensionMismatch(lazy"A has second dimension $nA, B has $(size(B,2)), C has $(size(C,2)) but all must match"))
743-
end
744746
iszero(nA) && return C
745747
iszero(_add.alpha) && return _rmul_or_fill!(C, _add.beta)
746748
if nA <= 3

0 commit comments

Comments
 (0)