Skip to content

Commit 50ef837

Browse files
committed
Reuse in diagonal and bidiag
1 parent d9fc5ea commit 50ef837

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/matmul.jl

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,15 +408,24 @@ julia> lmul!(F.Q, B)
408408
"""
409409
lmul!(A, B)
410410

411-
_vec_or_mat_str(s::Tuple{Any}) = :vector
412-
_vec_or_mat_str(s::Tuple{Any,Any}) = :matrix
411+
_vec_or_mat_str(s::Tuple{Any}) = "vector"
412+
_vec_or_mat_str(s::Tuple{Any,Any}) = "matrix"
413413
@noinline function matmul_size_check(sizeA::Tuple{Integer,Vararg{Integer}}, sizeB::Tuple{Integer,Vararg{Integer}})
414414
strA = _vec_or_mat_str(sizeA)
415415
strB = _vec_or_mat_str(sizeB)
416416
szA2 = get(sizeA, 2, 1)
417+
B_size_len = length(sizeB) == 1 ? sizeB[1] : sizeB
418+
size_or_len_str_B = B_size_len isa Integer ? "length" : "size"
419+
dim_or_len_str_B = B_size_len isa Integer ? "length" : "first dimension"
420+
pos_str_A = (length(sizeA) == length(sizeB) ? "first " : "")*strA
421+
pos_str_B = (length(sizeA) == length(sizeB) ? "second " : "")*strB
417422
if szA2 != sizeB[1]
418423
throw(DimensionMismatch(
419-
lazy"incompatible dimensions for matrix multiplication: tried to multiply a $strA of size $sizeA with a $strB of size $sizeB.",
424+
LazyString(
425+
lazy"incompatible dimensions for matrix multiplication: ",
426+
lazy"tried to multiply a $strA of size $sizeA with a $strB of $size_or_len_str_B $B_size_len. ",
427+
lazy"The second dimension of the $pos_str_A: $szA2, does not match the $dim_or_len_str_B of the $pos_str_B: $(sizeB[1])."
428+
)
420429
)
421430
)
422431
end
@@ -425,16 +434,22 @@ end
425434
@noinline function matmul_size_check(sizeC::Tuple{Integer,Vararg{Integer}}, sizeA::Tuple{Integer,Vararg{Integer}}, sizeB::Tuple{Integer,Vararg{Integer}})
426435
strA = _vec_or_mat_str(sizeA)
427436
strB = _vec_or_mat_str(sizeB)
437+
strC = _vec_or_mat_str(sizeC)
428438
szB2 = get(sizeB, 2, 1)
429439
szC2 = get(sizeC, 2, 1)
430440
matmul_size_check(sizeA, sizeB)
431441
if sizeC[1] != sizeA[1] || szC2 != szB2
432-
destsize = length(sizeB) == length(sizeC) == 1 ? (sizeA[1],) : (sizeA[1], szB2)
442+
C_size_len = length(sizeC) == 1 ? sizeC[1] : sizeC
443+
size_or_len_str_C = C_size_len isa Integer ? "length" : "size"
444+
B_size_len = length(sizeB) == 1 ? sizeB[1] : sizeB
445+
size_or_len_str_B = B_size_len isa Integer ? "length" : "size"
446+
destsize = length(sizeB) == length(sizeC) == 1 ? sizeA[1] : (sizeA[1], szB2)
447+
size_or_len_str_dest = destsize isa Integer ? "length" : "size"
433448
throw(DimensionMismatch(
434449
LazyString(
435450
"incompatible destination size: ",
436-
lazy"the destination of size $sizeC is incomatible with the multiplication of a $strA of size $(sizeA) and a $strB of size $(sizeB). ",
437-
lazy"The destination must be of size $destsize."
451+
lazy"the destination $strC of $size_or_len_str_C $C_size_len is incomatible with the product of a $strA of size $sizeA and a $strB of $size_or_len_str_B $B_size_len. ",
452+
lazy"The destination must be of $size_or_len_str_dest $destsize."
438453
)
439454
)
440455
)

0 commit comments

Comments
 (0)