Commit 5165fd3
authored
Unwrap triangular matrices in broadcast (#1332)
In broadcasting over triangular matrices, we loop only over the stored
indices. For these indices, indexing into a triangular matrix is
equivalent to indexing into its parent. We may therefore replace an
`UpperOrLowerTriangular` matrix by its parent, which removes the branch
in `getindex`. This improves performance:
```julia
julia> L = LowerTriangular(zeros(600,600));
julia> L2 = copy(L);
julia> @Btime broadcast!(+, $L2, $L, $L);
161.176 μs (0 allocations: 0 bytes) # master
80.894 μs (0 allocations: 0 bytes) # this PR
```
This replacement is performed recursively on a `Broadcasted` object by
looping over its `args`, and non-triangular elements are left untouched.
Only `UpperOrLowerTriangular` matrices will be replaced by their
`parent`s.1 parent 9d26faf commit 5165fd3
File tree
3 files changed
+24
-6
lines changed- src
- test
3 files changed
+24
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
272 | 282 | | |
273 | 283 | | |
274 | 284 | | |
275 | 285 | | |
| 286 | + | |
276 | 287 | | |
277 | 288 | | |
278 | | - | |
| 289 | + | |
279 | 290 | | |
280 | 291 | | |
281 | 292 | | |
| |||
285 | 296 | | |
286 | 297 | | |
287 | 298 | | |
| 299 | + | |
288 | 300 | | |
289 | 301 | | |
290 | | - | |
| 302 | + | |
291 | 303 | | |
292 | 304 | | |
293 | 305 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
702 | 702 | | |
703 | 703 | | |
704 | 704 | | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
| 705 | + | |
| 706 | + | |
709 | 707 | | |
710 | 708 | | |
711 | 709 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
388 | 388 | | |
389 | 389 | | |
390 | 390 | | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
391 | 399 | | |
0 commit comments