@@ -201,17 +201,39 @@ function get_S_coeffs(h, yᵢ, yᵢ₊₁, dyᵢ, dyᵢ₊₁, ymid, dymid)
201201end
202202
203203# S forward Interpolation
204+ function __firk_matvec! (y, A, b)
205+ length (y) == size (A, 1 ) ||
206+ throw (DimensionMismatch (" y has length $(length (y)) , but A has $(size (A, 1 )) rows" ))
207+ length (b) == size (A, 2 ) ||
208+ throw (DimensionMismatch (" b has length $(length (b)) , but A has $(size (A, 2 )) columns" ))
209+
210+ T = promote_type (eltype (y), eltype (A), eltype (b))
211+ for (y_index, row) in zip (eachindex (y), axes (A, 1 ))
212+ acc = zero (T)
213+ for (b_index, col) in zip (eachindex (b), axes (A, 2 ))
214+ @inbounds acc += A[row, col] * b[b_index]
215+ end
216+ @inbounds y[y_index] = acc
217+ end
218+ return y
219+ end
220+
221+ function __firk_matvec (A, b)
222+ y = similar (b, promote_type (eltype (A), eltype (b)), size (A, 1 ))
223+ return __firk_matvec! (y, A, b)
224+ end
225+
204226function S_interpolate! (y:: AbstractArray , t, coeffs)
205227 ts = [t^ (i - 1 ) for i in axes (coeffs, 2 )]
206- return y . = coeffs * ts
228+ return __firk_matvec! (y, coeffs, ts)
207229end
208230
209231function dS_interpolate! (dy:: AbstractArray , t, S_coeffs)
210- ts = zeros (size (S_coeffs, 2 ))
232+ ts = zeros (promote_type ( eltype (S_coeffs), typeof (t)), size (S_coeffs, 2 ))
211233 for i in 2 : size (S_coeffs, 2 )
212234 ts[i] = (i - 1 ) * t^ (i - 2 )
213235 end
214- return dy . = S_coeffs * ts
236+ return __firk_matvec! (dy, S_coeffs, ts)
215237end
216238
217239"""
577599end
578600
579601function get_q_coeffs (A, ki, h)
580- coeffs = A * ki
602+ coeffs = __firk_matvec (A, ki)
581603 for i in axes (coeffs, 1 )
582604 coeffs[i] = coeffs[i] / (h^ (i - 1 ))
583605 end
0 commit comments