@@ -3,7 +3,7 @@ struct LinearCombination{T, As<:Tuple{Vararg{LinearMap}}, Ts<:Tuple} <: LinearMa
3
3
coeffs:: Ts
4
4
function LinearCombination {T, As, Ts} (maps:: As , coeffs:: Ts ) where {T, As, Ts}
5
5
N = length (maps)
6
- N == length (coeffs) || error (" Number of coefficients doesn't match number of terms " )
6
+ N == length (coeffs) || error (" number of coefficients doesn't match number of linear maps " )
7
7
sz = size (maps[1 ])
8
8
for n = 1 : N
9
9
size (maps[n]) == sz || throw (DimensionMismatch (" LinearCombination" ))
@@ -97,32 +97,41 @@ function A_mul_B!(y::AbstractVector, A::LinearCombination, x::AbstractVector)
97
97
# no size checking, will be done by individual maps
98
98
A_mul_B! (y, A. maps[1 ], x)
99
99
A. coeffs[1 ] == 1 || lmul! (A. coeffs[1 ], y)
100
- z = similar (y)
101
- for n= 2 : length (A. maps)
102
- A_mul_B! (z, A. maps[n], x)
103
- axpy! (A. coeffs[n], z, y)
100
+ l = length (A. maps)
101
+ if l> 1
102
+ z = similar (y)
103
+ for n= 2 : l
104
+ A_mul_B! (z, A. maps[n], x)
105
+ axpy! (A. coeffs[n], z, y)
106
+ end
104
107
end
105
108
return y
106
109
end
107
110
function At_mul_B! (y:: AbstractVector , A:: LinearCombination , x:: AbstractVector )
108
111
# no size checking, will be done by individual maps
109
112
At_mul_B! (y, A. maps[1 ], x)
110
113
A. coeffs[1 ] == 1 || lmul! (A. coeffs[1 ], y)
111
- z = similar (y)
112
- for n = 2 : length (A. maps)
113
- At_mul_B! (z, A. maps[n], x)
114
- axpy! (A. coeffs[n], z, y)
114
+ l = length (A. maps)
115
+ if l> 1
116
+ z = similar (y)
117
+ for n = 2 : l
118
+ At_mul_B! (z, A. maps[n], x)
119
+ axpy! (A. coeffs[n], z, y)
120
+ end
115
121
end
116
122
return y
117
123
end
118
124
function Ac_mul_B! (y:: AbstractVector , A:: LinearCombination , x:: AbstractVector )
119
125
# no size checking, will be done by individual maps
120
126
Ac_mul_B! (y, A. maps[1 ], x)
121
127
A. coeffs[1 ] == 1 || lmul! (conj (A. coeffs[1 ]), y)
122
- z = similar (y)
123
- for n= 2 : length (A. maps)
124
- Ac_mul_B! (z, A. maps[n], x)
125
- axpy! (conj (A. coeffs[n]), z, y)
128
+ l = length (A. maps)
129
+ if l> 1
130
+ z = similar (y)
131
+ for n= 2 : l
132
+ Ac_mul_B! (z, A. maps[n], x)
133
+ axpy! (conj (A. coeffs[n]), z, y)
134
+ end
126
135
end
127
136
return y
128
137
end
0 commit comments