Skip to content

Commit

Permalink
Corrected foreach_enumerate implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCan committed Dec 11, 2023
1 parent 9d8f4e5 commit b4493a2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/semidiscretization/semidiscretization_coupled.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,22 @@ end
@view u_ode[semi.u_indices[index]]
end

# Same as `foreach(enumerate(something))`, but without allocations.
#
# Note that compile times may increase if this is used with big tuples.
@inline foreach_enumerate(func, collection) = foreach_enumerate(func, collection, 1)
@inline foreach_enumerate(func, collection::Tuple{}, index) = nothing

@inline function foreach_enumerate(func, collection, index)
element = first(collection)
remaining_collection = Base.tail(collection)

func((index, element))

# Process remaining collection
foreach_enumerate(func, remaining_collection, index + 1)
end

# Recursive call of the RHS for the semidiscretizations using Lispy tuple programming
# to avoid type instability.
@inline function rhs!(u_ode, du_ode, t, semi, i, semi_, semi_tuple...)
Expand Down

0 comments on commit b4493a2

Please sign in to comment.