Closed virgile-baudrot closed 3 years ago
First we need to get your code updated to get rid of all those macros! Can you push your latest code? then I can convert it and put in a PR. It will be so much easier to discuss after that.
For having multiple sub-populations in the grid, for intrinsicrate use a Tuple
. (but you might not even need to lock it like this)
struct DiscreteGrowthRate{R,W,GR<:Tuple,I}
intrinsicrate::GR
numberSupPop::I
end
With a Tuple
you can just map
over the populations and growth rates, and it will handle any number of sub populations making this generic to all similar problems:
@inline function applyrule(data, rule::DiscreteGrowthRate, pops, index)
map(pops, rule.intrinsicrate) do pop, ir
ir * pop * (1 - sum(pops) / rule.carrycap)
end
end
(map
with a Vector
is allocating and much slower, and can't be optimised the same way a Tuple
can be. We also need to return a Tuple
to be written back to the N separate grids, which just works using a Tuple
for intrinsicrate
)
Edit: you could get rid of the <:Tuple
limitation, then a single instrinsicrate would also work
Great. I just send a PR #64
Hi Raf,
this is an implementation of a discrete growth with 3 subpopulations (here sharing carying capacity) which work pretty well. If you have any idea to implement something generic for N populations:
A generic could potentially look like this:
EDIT: I edit typos