Skip to content

Commit b0d7ee4

Browse files
jishnubKristofferC
authored andcommitted
LazyString in DimensionMismatch error messages in broadcasting (#53975)
This reduces dynamic dispatch, and makes JET happier. Something similar is already used in line 523. (cherry picked from commit f7c7410)
1 parent 25c1c87 commit b0d7ee4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

base/broadcast.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,8 @@ function _bcs(shape::Tuple, newshape::Tuple)
517517
return (_bcs1(shape[1], newshape[1]), _bcs(tail(shape), tail(newshape))...)
518518
end
519519
# _bcs1 handles the logic for a single dimension
520-
_bcs1(a::Integer, b::Integer) = a == 1 ? b : (b == 1 ? a : (a == b ? a : throw(DimensionMismatch("arrays could not be broadcast to a common size; got a dimension with lengths $a and $b"))))
521-
_bcs1(a::Integer, b) = a == 1 ? b : (first(b) == 1 && last(b) == a ? b : throw(DimensionMismatch("arrays could not be broadcast to a common size; got a dimension with lengths $a and $(length(b))")))
520+
_bcs1(a::Integer, b::Integer) = a == 1 ? b : (b == 1 ? a : (a == b ? a : throw(DimensionMismatch(LazyString("arrays could not be broadcast to a common size; got a dimension with lengths ", a, " and ", b)))))
521+
_bcs1(a::Integer, b) = a == 1 ? b : (first(b) == 1 && last(b) == a ? b : throw(DimensionMismatch(LazyString("arrays could not be broadcast to a common size; got a dimension with lengths ", a, " and ", length(b)))))
522522
_bcs1(a, b::Integer) = _bcs1(b, a)
523523
_bcs1(a, b) = _bcsm(b, a) ? axistype(b, a) : _bcsm(a, b) ? axistype(a, b) : throw(DimensionMismatch(LazyString("arrays could not be broadcast to a common size: a has axes ", a, " and b has axes ", b)))
524524
# _bcsm tests whether the second index is consistent with the first
@@ -1057,7 +1057,7 @@ end
10571057

10581058

10591059
@noinline throwdm(axdest, axsrc) =
1060-
throw(DimensionMismatch("destination axes $axdest are not compatible with source axes $axsrc"))
1060+
throw(DimensionMismatch(LazyString("destination axes ", axdest, " are not compatible with source axes ", axsrc)))
10611061

10621062
function restart_copyto_nonleaf!(newdest, dest, bc, val, I, iter, state, count)
10631063
# Function barrier that makes the copying to newdest type stable

0 commit comments

Comments
 (0)