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

**URL:** <https://discourse.julialang.org/t/why-mul-does-not-work-with-a-target-that-has-more-columns-than-the-result/99531>\
**Category:** Performance\
**Tags:** linearalgebra\
**Created:** [May 28, 2023, 9:02pm UTC](https://discourse.julialang.org/t/why-mul-does-not-work-with-a-target-that-has-more-columns-than-the-result/99531 "2023-05-28T21:02:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pitsianis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pitsianis/32/26588_2.png) [@pitsianis](https://discourse.julialang.org/u/pitsianis)\
**Post date:** [May 28, 2023, 9:02pm UTC](https://discourse.julialang.org/t/why-mul-does-not-work-with-a-target-that-has-more-columns-than-the-result/99531/1 "2023-05-28T21:02:43Z")

</div>

I was surprised to find that `mul!` in

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

```

fails with

```julia-repl
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?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [May 28, 2023, 9:19pm UTC](https://discourse.julialang.org/t/why-mul-does-not-work-with-a-target-that-has-more-columns-than-the-result/99531/2 "2023-05-28T21:19:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [May 28, 2023, 11:35pm UTC](https://discourse.julialang.org/t/why-mul-does-not-work-with-a-target-that-has-more-columns-than-the-result/99531/3 "2023-05-28T23:35:17Z")

</div>

> [@Oscar\_Smith](#):
>
> 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.
