Skip to content

Commit d03af2c

Browse files
Avoid FIRK AD residual collection allocation
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
1 parent fcc08ec commit d03af2c

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

  • lib/BoundaryValueDiffEqFIRK/src

lib/BoundaryValueDiffEqFIRK/src/firk.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,12 +1522,21 @@ end
15221522
resid, u, p, y, mesh, residual, cache, trait::NoDiffCacheNeeded, constraint
15231523
)
15241524
y_ = recursive_unflatten!(y, u)
1525-
resids = [r for r in residual[2:end]]
1525+
resids = view(residual, 2:lastindex(residual))
15261526
Φ!(resids, cache, y_, u, trait, constraint)
1527-
recursive_flatten!(resid, resids)
1527+
__firk_flatten_residuals!(resid, resids)
15281528
return nothing
15291529
end
15301530

1531+
@views function __firk_flatten_residuals!(y::AbstractVector, x)
1532+
i = 0
1533+
for xᵢ in x
1534+
copyto!(y[(i + 1):(i + length(xᵢ))], xᵢ)
1535+
i += length(xᵢ)
1536+
end
1537+
return y
1538+
end
1539+
15311540
@views function __firk_loss_collocation(u, p, y, mesh, residual, cache, trait)
15321541
y_ = recursive_unflatten!(y, u)
15331542
resids = Φ(cache, y_, u, trait)

0 commit comments

Comments
 (0)