@@ -130,13 +130,16 @@ function exponential!(A::AbstractMatrix, expA, alg::MatrixFunctionViaTaylor)
130130 # Form a minimal set of powers of A up front and use them to sharpen the norm estimate
131131 # through the Al-Mohy–Higham quantities dₚ = ‖Aᵖ‖^(1/p).
132132 p₀ = min (convert (Int, get (alg. kwargs, :estimate_order , 4 )), m)
133- powers = Vector {typeof(A)} (undef, p₀)
134- powers[1 ] = A
135133 d = Vector {R} (undef, p₀)
136134 d[1 ] = LinearAlgebra. opnorm (A, 1 )
137135 iszero (d[1 ]) && return one! (expA)
136+
137+ powers = Vector {Base.promote_op(similar, typeof(A))} (undef, p₀)
138+ powers[1 ] = eltype (powers) === typeof (A) ? A : copyto! (similar (A), A)
139+
138140 for p in 2 : p₀
139- powers[p] = powers[p - 1 ] * A
141+ powers[p] = similar (powers[1 ])
142+ mul! (powers[p], powers[p - 1 ], powers[1 ])
140143 d[p] = LinearAlgebra. opnorm (powers[p], 1 )^ (1 / p)
141144 end
142145
@@ -152,8 +155,11 @@ function exponential!(A::AbstractMatrix, expA, alg::MatrixFunctionViaTaylor)
152155 end
153156 end
154157 # Extend from p₀ to `blocksize` powers (blocksize ≥ p₀ always, see taylor_order_and_squarings)
158+ sizehint! (powers, blocksize)
155159 for p in (p₀ + 1 ): blocksize
156- push! (powers, powers[p - 1 ] * powers[1 ])
160+ Pp = similar (powers[1 ])
161+ mul! (Pp, powers[p - 1 ], powers[1 ])
162+ push! (powers, Pp)
157163 end
158164
159165
0 commit comments