@@ -59,7 +59,7 @@ LazySum(operators::AbstractOperator...) = LazySum(mapreduce(eltype, promote_type
5959LazySum () = throw (ArgumentError (" LazySum needs a basis, or at least one operator!" ))
6060
6161Base. copy (x:: LazySum ) = @samebases LazySum (x. basis_l, x. basis_r, copy (x. factors), copy .(x. operators))
62- Base. eltype (x:: LazySum ) = promote_type ( eltype (x . factors), mapreduce (eltype, promote_type, x. operators))
62+ Base. eltype (x:: LazySum ) = mapreduce (eltype, promote_type, x. operators; init = eltype (x . factors ))
6363
6464dense (op:: LazySum ) = length (op. operators) > 0 ? sum (op. factors .* dense .(op. operators)) : Operator (op. basis_l, op. basis_r, zeros (eltype (op. factors), length (op. basis_l), length (op. basis_r)))
6565SparseArrays. sparse (op:: LazySum ) = length (op. operators) > 0 ? sum (op. factors .* sparse .(op. operators)) : Operator (op. basis_l, op. basis_r, spzeros (eltype (op. factors), length (op. basis_l), length (op. basis_r)))
140140# Fast in-place multiplication
141141function mul! (result:: Ket{B1} ,a:: LazySum{B1,B2} ,b:: Ket{B2} ,alpha,beta) where {B1,B2}
142142 if length (a. operators) == 0
143+ _check_mul!_dim_compatibility (size (result), size (a), size (b))
143144 result. data .*= beta
144145 else
145146 mul! (result,a. operators[1 ],b,alpha* a. factors[1 ],beta)
152153
153154function mul! (result:: Bra{B2} ,a:: Bra{B1} ,b:: LazySum{B1,B2} ,alpha,beta) where {B1,B2}
154155 if length (b. operators) == 0
156+ _check_mul!_dim_compatibility (size (result), reverse (size (b)), size (a))
155157 result. data .*= beta
156158 else
157159 mul! (result,a,b. operators[1 ],alpha* b. factors[1 ],beta)
164166
165167function mul! (result:: Operator{B1,B3} ,a:: LazySum{B1,B2} ,b:: Operator{B2,B3} ,alpha,beta) where {B1,B2,B3}
166168 if length (a. operators) == 0
169+ _check_mul!_dim_compatibility (size (result), size (a), size (b))
167170 result. data .*= beta
168171 else
169172 mul! (result,a. operators[1 ],b,alpha* a. factors[1 ],beta)
@@ -175,6 +178,7 @@ function mul!(result::Operator{B1,B3},a::LazySum{B1,B2},b::Operator{B2,B3},alpha
175178end
176179function mul! (result:: Operator{B1,B3} ,a:: Operator{B1,B2} ,b:: LazySum{B2,B3} ,alpha,beta) where {B1,B2,B3}
177180 if length (b. operators) == 0
181+ _check_mul!_dim_compatibility (size (result), size (a), size (b))
178182 result. data .*= beta
179183 else
180184 mul! (result,a,b. operators[1 ],alpha* b. factors[1 ],beta)
0 commit comments