diff --git a/src/bidiag.jl b/src/bidiag.jl index 13439ff9..52f72086 100644 --- a/src/bidiag.jl +++ b/src/bidiag.jl @@ -1215,26 +1215,22 @@ function _dibimul!(C::Bidiagonal, A::Diagonal, B::Bidiagonal, _add) end function mul(A::UpperOrUnitUpperTriangular, B::Bidiagonal) - TS = promote_op(matprod, eltype(A), eltype(B)) - C = mul!(similar(A, TS, size(A)), A, B) + C = _mul(A, B) return B.uplo == 'U' ? UpperTriangular(C) : C end function mul(A::LowerOrUnitLowerTriangular, B::Bidiagonal) - TS = promote_op(matprod, eltype(A), eltype(B)) - C = mul!(similar(A, TS, size(A)), A, B) + C = _mul(A, B) return B.uplo == 'L' ? LowerTriangular(C) : C end function mul(A::Bidiagonal, B::UpperOrUnitUpperTriangular) - TS = promote_op(matprod, eltype(A), eltype(B)) - C = mul!(similar(B, TS, size(B)), A, B) + C = _mul(A, B) return A.uplo == 'U' ? UpperTriangular(C) : C end function mul(A::Bidiagonal, B::LowerOrUnitLowerTriangular) - TS = promote_op(matprod, eltype(A), eltype(B)) - C = mul!(similar(B, TS, size(B)), A, B) + C = _mul(A, B) return A.uplo == 'L' ? LowerTriangular(C) : C end diff --git a/src/matmul.jl b/src/matmul.jl index efb9d0fe..2b2f7d81 100644 --- a/src/matmul.jl +++ b/src/matmul.jl @@ -51,11 +51,13 @@ end # Matrix-vector multiplication function (*)(A::StridedMaybeAdjOrTransMat{T}, x::StridedVector{S}) where {T<:BlasFloat,S<:Real} + matmul_size_check(size(A), size(x)) TS = promote_op(matprod, T, S) y = isconcretetype(TS) ? convert(AbstractVector{TS}, x) : x mul!(similar(x, TS, size(A,1)), A, y) end function (*)(A::AbstractMatrix{T}, x::AbstractVector{S}) where {T,S} + matmul_size_check(size(A), size(x)) TS = promote_op(matprod, T, S) mul!(similar(x, TS, axes(A,1)), A, x) end @@ -113,7 +115,10 @@ julia> [1 1; 0 1] * [1 0; 1 1] """ (*)(A::AbstractMatrix, B::AbstractMatrix) = mul(A, B) # we add an extra level of indirection to avoid ambiguities in * -function mul(A::AbstractMatrix, B::AbstractMatrix) +# We also define the core functionality within _mul to reuse the code elsewhere +mul(A::AbstractMatrix, B::AbstractMatrix) = _mul(A, B) +function _mul(A::AbstractMatrix, B::AbstractMatrix) + matmul_size_check(size(A), size(B)) TS = promote_op(matprod, eltype(A), eltype(B)) mul!(matprod_dest(A, B, TS), A, B) end diff --git a/src/symmetric.jl b/src/symmetric.jl index 09819325..d063bb44 100644 --- a/src/symmetric.jl +++ b/src/symmetric.jl @@ -707,12 +707,14 @@ end mul(A::HermOrSym, B::HermOrSym) = A * copyto!(similar(parent(B)), B) # catch a few potential BLAS-cases function mul(A::HermOrSym{<:BlasFloat,<:StridedMatrix}, B::AdjOrTrans{<:BlasFloat,<:StridedMatrix}) + matmul_size_check(size(A), size(B)) T = promote_type(eltype(A), eltype(B)) mul!(similar(B, T, (size(A, 1), size(B, 2))), convert(AbstractMatrix{T}, A), copy_oftype(B, T)) # make sure the AdjOrTrans wrapper is resolved end function mul(A::AdjOrTrans{<:BlasFloat,<:StridedMatrix}, B::HermOrSym{<:BlasFloat,<:StridedMatrix}) + matmul_size_check(size(A), size(B)) T = promote_type(eltype(A), eltype(B)) mul!(similar(B, T, (size(A, 1), size(B, 2))), copy_oftype(A, T), # make sure the AdjOrTrans wrapper is resolved