Commit 6d37861
authored
Implement wrapped-SMatrix + UniformScaling (#1332)
## Context
`UniformScaling` operations on structured wrappers backed by
`StaticMatrix` were falling back to generic `LinearAlgebra` methods.
That path uses mutable copies, which caused type leakage from
`SMatrix`-backed wrappers to `MMatrix`-backed wrappers. In some cases
(for example `I - Symmetric(SMatrix(...))`), it could also fail due to
mutation of immutable storage.
I don't think there is an easy way to solve this problem in general due
to how these operations are defined in base, so instead I've just
written some appropriate wrappers.
## What this changes
This PR adds `UniformScaling` specialisations for structured wrappers
over `StaticMatrix` in `src/linalg.jl`:
- `Symmetric`
- `Hermitian`
- `UpperTriangular`
- `LowerTriangular`
- `UnitUpperTriangular` (result type `UpperTriangular`)
- `UnitLowerTriangular` (result type `LowerTriangular`)
I only implement methods for `A + J` and `J - A` for brevity, with
`uniformscaling.jl:L156` handling the reverse argument orders.
I include a special case for the some of Hermitian + complex
UniformScaling which removes the wrapper to be type stable, consistent
with base LinearAlgebra.jl.
## Tests
I've extended `test/linalg.jl` (`Interaction with UniformScaling`) to
cover all of the cases mentioned.1 parent 58bf1e1 commit 6d37861
3 files changed
Lines changed: 94 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
43 | 87 | | |
44 | 88 | | |
45 | 89 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
110 | 159 | | |
111 | 160 | | |
112 | 161 | | |
| |||
0 commit comments