Skip to content

Commit 67c27ec

Browse files
Merge pull request #138 from baggepinnen/patch-1
reduce allocations by two_stage_method
2 parents d4e495e + 13e646d commit 67c27ec

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/two_stage_method.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function construct_t2(t,tpoints)
4747
end
4848
function construct_w(t,tpoints,h,kernel)
4949
W = @. calckernel((kernel,),(tpoints-t)/h)/h
50-
Matrix(Diagonal(W))
50+
Diagonal(W)
5151
end
5252
function construct_estimated_solution_and_derivative!(data,kernel,tpoints)
5353
_one = oneunit(first(data))
@@ -57,17 +57,22 @@ function construct_estimated_solution_and_derivative!(data,kernel,tpoints)
5757
n = length(tpoints)
5858
h = (n^(-1/5))*(n^(-3/35))*((log(n))^(-1/16))
5959

60+
Wd = similar(data, n, size(data,1))
61+
WT1 = similar(data, n, 2)
62+
WT2 = similar(data, n, 3)
6063
x = map(tpoints) do _t
6164
T1 = construct_t1(_t,tpoints)
6265
T2 = construct_t2(_t,tpoints)
6366
W = construct_w(_t,tpoints,h,kernel)
64-
e2'*inv(T2'*W*T2)T2'*W*data',e1'*inv(T1'*W*T1)*T1'*W*data'
67+
mul!(Wd,W,data')
68+
mul!(WT1,W,T1)
69+
mul!(WT2,W,T2)
70+
(e2'*((T2'*WT2)\T2'))*Wd,(e1'*((T1'*WT1)\T1'))*Wd
6571
end
6672
estimated_derivative = reduce(hcat,transpose.(first.(x)))
6773
estimated_solution = reduce(hcat,transpose.(last.(x)))
6874
estimated_derivative,estimated_solution
6975
end
70-
7176
function construct_iip_cost_function(f,du,preview_est_sol,preview_est_deriv,tpoints)
7277
function (p)
7378
_du = DiffEqBase.get_tmp(du,p)

0 commit comments

Comments
 (0)