@@ -63,6 +63,7 @@ domain(P::PlusOperator) = commondomain(P.ops)
63
63
64
64
_promote_eltypeof (As... ) = _promote_eltypeof (As)
65
65
_promote_eltypeof (As:: Union{Vector, Tuple} ) = mapreduce (eltype, promote_type, As)
66
+ _promote_eltypeof (As:: Vector{Operator{T}} ) where {T} = T
66
67
67
68
_extractops (A, :: Any ) = [A]
68
69
_extractops (A:: PlusOperator , :: typeof (+ )) = A. ops
@@ -265,38 +266,26 @@ end
265
266
266
267
267
268
268
- function promotetimes (opsin:: Vector{B} ,dsp) where B<: Operator
269
+ function promotetimes (opsin:: Vector{<:Operator} , dsp = domainspace (last (opsin)))
270
+
271
+ @assert length (opsin) > 1 " need at least 2 operators"
269
272
ops= Vector {Operator{_promote_eltypeof(opsin)}} (undef,0 )
273
+ sizehint! (ops, length (opsin))
270
274
271
275
for k= length (opsin): - 1 : 1
272
276
if ! isa (opsin[k],Conversion)
273
277
op= promotedomainspace (opsin[k],dsp)
274
- if op== ()
275
- # do nothing
276
- elseif isa (op,TimesOperator)
277
- for j= length (op. ops): - 1 : 1
278
- push! (ops,op. ops[j])
279
- end
280
- dsp= rangespace (op)
278
+ dsp= rangespace (op)
279
+ if isa (op,TimesOperator)
280
+ append! (ops, view (op. ops, reverse (axes (op. ops,1 ))))
281
281
else
282
282
push! (ops,op)
283
- dsp= rangespace (op)
284
283
end
285
284
end
286
285
end
287
- if isempty (ops)
288
- ConstantOperator (1.0 ,dsp)
289
- elseif length (ops)== 1
290
- first (ops)
291
- else
292
- TimesOperator (reverse! (ops)) # change order in TImesOperator if this is slow
293
- end
286
+ TimesOperator (reverse! (ops))
294
287
end
295
288
296
- promotetimes (opsin:: Vector{B} ) where {B<: Operator }= promotetimes (opsin,domainspace (last (opsin)))
297
-
298
-
299
-
300
289
domainspace (P:: TimesOperator )= domainspace (last (P. ops))
301
290
rangespace (P:: TimesOperator )= rangespace (first (P. ops))
302
291
@@ -490,7 +479,8 @@ function *(A::Operator,B::Operator)
490
479
elseif isconstop (B)
491
480
promotedomainspace (strictconvert (Number,B)* A,domainspace (B))
492
481
else
493
- promotetimes (Operator{_promote_eltypeof (A, B)}[_extractops (A, * ); _extractops (B, * )])
482
+ promotetimes ([_extractops (A, * ); _extractops (B, * )],
483
+ domainspace (B))
494
484
end
495
485
end
496
486
@@ -619,7 +609,7 @@ function promotedomainspace(P::TimesOperator,sp::Space,cursp::Space)
619
609
elseif length (P. ops)== 2
620
610
P. ops[1 ]* promotedomainspace (P. ops[end ],sp)
621
611
else
622
- promotetimes ([P. ops[1 : end - 1 ];promotedomainspace (P. ops[end ],sp)])
612
+ promotetimes ([P. ops[1 : end - 1 ];promotedomainspace (P. ops[end ],sp)], sp )
623
613
end
624
614
end
625
615
0 commit comments