|
1 |
| -struct LinearCombination{T, As<:Tuple{Vararg{LinearMap}}} <: LinearMap{T} |
| 1 | +struct LinearCombination{T, As} <: LinearMap{T} |
2 | 2 | maps::As
|
3 | 3 | function LinearCombination{T, As}(maps::As) where {T, As}
|
4 | 4 | N = length(maps)
|
|
13 | 13 |
|
14 | 14 | LinearCombination{T}(maps::As) where {T, As} = LinearCombination{T, As}(maps)
|
15 | 15 |
|
| 16 | +function Base.show(io::IO, A::LinearCombination) |
| 17 | + write(io, "LinearMaps.LinearCombination(") |
| 18 | + n = length(A.maps) |
| 19 | + if get(io, :limit, true) && n > 10 |
| 20 | + s = 1:5 |
| 21 | + e = n-5:n |
| 22 | + if e[1]-s[end] > 1 |
| 23 | + write(io, "(") |
| 24 | + for i in s |
| 25 | + show(io, A.maps[i]) |
| 26 | + write(io, ", ") |
| 27 | + end |
| 28 | + write(io, "…") |
| 29 | + for i in e |
| 30 | + write(io, ", ") |
| 31 | + show(io, A.maps[i]) |
| 32 | + end |
| 33 | + write(io, ")") |
| 34 | + else |
| 35 | + show(io, A.maps) |
| 36 | + end |
| 37 | + else |
| 38 | + show(io, A.maps) |
| 39 | + end |
| 40 | + write(io, ")") |
| 41 | +end |
| 42 | + |
16 | 43 | MulStyle(A::LinearCombination) = MulStyle(A.maps...)
|
17 | 44 |
|
18 | 45 | # basic methods
|
@@ -81,6 +108,9 @@ for Atype in (AbstractVector, AbstractMatrix)
|
81 | 108 | end
|
82 | 109 | end
|
83 | 110 |
|
| 111 | +# For tuple-like storage of the maps (default), we recurse on the tail |
| 112 | +# of the tuple. |
| 113 | + |
84 | 114 | @inline _mul!(::FiveArg, y, A::LinearCombination, x, α::Number) =
|
85 | 115 | __mul!(y, Base.tail(A.maps), x, α, nothing)
|
86 | 116 | @inline function _mul!(::ThreeArg, y, A::LinearCombination, x, α::Number)
|
|
93 | 123 | @inline __mul!(y, A::Tuple{LinearMap}, x, α, z) = __mul!(y, first(A), x, α, z)
|
94 | 124 | @inline __mul!(y, A::LinearMap, x, α, z) = muladd!(MulStyle(A), y, A, x, α, z)
|
95 | 125 |
|
| 126 | +# For vector-like storage of the maps, we simply loop over the maps. |
| 127 | + |
| 128 | +@inline function _mul!(::FiveArg, y, A::LinearCombination{<:Any,<:AbstractVector}, x, α::Number) |
| 129 | + for i = 2:length(A.maps) |
| 130 | + mul!(y, A.maps[i], x, α, true) |
| 131 | + end |
| 132 | + y |
| 133 | +end |
| 134 | +@inline function _mul!(mulstyle::ThreeArg, y, A::LinearCombination{<:Any,<:AbstractVector}, x, α::Number) |
| 135 | + z = similar(y) |
| 136 | + for i = 2:length(A.maps) |
| 137 | + muladd!(mulstyle, y, A.maps[i], x, α, z) |
| 138 | + end |
| 139 | + y |
| 140 | +end |
| 141 | + |
96 | 142 | @inline muladd!(::FiveArg, y, A, x, α, _) = mul!(y, A, x, α, true)
|
97 | 143 | @inline function muladd!(::ThreeArg, y, A, x, α, z)
|
98 | 144 | mul!(z, A, x)
|
|
0 commit comments