We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3f29e18 commit 05d7c50Copy full SHA for 05d7c50
1 file changed
src/implementations/LinearAlgebra.jl
@@ -424,11 +424,14 @@ function operate(
424
# concrete. Bad things can happen if S or T is abstract and we pick the
425
# wrong type for C.
426
if !(isconcretetype(S) && isconcretetype(T))
427
- # We can't use A * B here, because this may StackOverflow via the chain:
428
- # *(A, B) -> mul(A, B) -> operate(*, A, B) -> *(A, B)
429
- # See MutableArithmetics.jl#336
430
- @assert axes(A, 2) == axes(B, 1)
431
- return [sum(A[i, j] * B[j] for j in axes(B, 1)) for i in axes(A, 1)]
+ if S <: AbstractMutable || T <: AbstractMutable
+ # We can't use A * B here, because this will StackOverflow via:
+ # *(A, B) -> mul(A, B) -> operate(*, A, B) -> *(A, B)
+ # See MutableArithmetics.jl#336
+ @assert axes(A, 2) == axes(B, 1)
432
+ return [sum(A[i, j] * B[j] for j in axes(B, 1)) for i in axes(A, 1)]
433
+ end
434
+ return A * B
435
end
436
C = undef_array(promote_array_mul(typeof(A), typeof(B)), axes(A, 1))
437
return operate_to!(C, *, A, B)
0 commit comments