Commit c64c328
authored
Size check in 2-argument
This PR adds a size check in the 2-argument `mul`, so that now the
destination array is allocated only if the sizes of the arguments are
compatible with matrix multiplication. This means that we don't allocate
in case of an error anymore.
The performance for small-matrix multiplication seems largely similar
(it's comparable to
#1310, and seems
identical within the noise limit):
```julia
julia> A = [1 2; 3 4];
julia> @Btime $A * $A;
42.304 ns (2 allocations: 112 bytes) # before this PR
44.203 ns (2 allocations: 112 bytes) # this PR
```
We also redirect the generic `mul` to `_mul` now, which is the function
that defines the multiplication code. This allows us to reuse the `_mul`
definition elsewhere without having to repeat code. Currently, this is
mainly necessary in the `Bidiagonal`-triangular multiplications.mul (#1315)3 files changed
+12
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1261 | 1261 | | |
1262 | 1262 | | |
1263 | 1263 | | |
1264 | | - | |
1265 | | - | |
| 1264 | + | |
1266 | 1265 | | |
1267 | 1266 | | |
1268 | 1267 | | |
1269 | 1268 | | |
1270 | | - | |
1271 | | - | |
| 1269 | + | |
1272 | 1270 | | |
1273 | 1271 | | |
1274 | 1272 | | |
1275 | 1273 | | |
1276 | | - | |
1277 | | - | |
| 1274 | + | |
1278 | 1275 | | |
1279 | 1276 | | |
1280 | 1277 | | |
1281 | 1278 | | |
1282 | | - | |
1283 | | - | |
| 1279 | + | |
1284 | 1280 | | |
1285 | 1281 | | |
1286 | 1282 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| 60 | + | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
| |||
113 | 115 | | |
114 | 116 | | |
115 | 117 | | |
116 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
117 | 122 | | |
118 | 123 | | |
119 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
710 | 710 | | |
711 | 711 | | |
712 | 712 | | |
| 713 | + | |
713 | 714 | | |
714 | 715 | | |
715 | 716 | | |
716 | 717 | | |
717 | 718 | | |
718 | 719 | | |
| 720 | + | |
719 | 721 | | |
720 | 722 | | |
721 | 723 | | |
| |||
0 commit comments