Why mul! does not work with a target that has more columns than the result?

I was surprised to find that mul! in

C = zeros(4,6); A = rand(4,3); B = rand(3,5);
mul!(C, A, B);

fails with

ERROR: DimensionMismatch: A has size (4,3), B has size (3,5), C has size (4, 6)

instead of proceeding by overwriting the correct columns of C.

Why?

You can do this with mul!(@view C[:, 1:5], A, B). Julia generally doesn’t like doing operations where the sizes don’t match.

Yeah, most of the time there’s a DimensionMismatch, that’s a bug that just got caught and pointed out, and not the intended behavior.

1 Like