1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use core::marker::PhantomData;

use necsim_core::{
    cogs::{Backup, MathsCore, RngCore, UniformlySampleableHabitat},
    landscape::Location,
};

use super::AntiTrespassingDispersalSampler;

#[allow(clippy::module_name_repetitions)]
#[derive(Debug)]
#[cfg_attr(feature = "cuda", derive(rust_cuda::lend::LendRustToCuda))]
#[cfg_attr(feature = "cuda", cuda(free = "M", free = "H", free = "G"))]
pub struct UniformAntiTrespassingDispersalSampler<
    M: MathsCore,
    H: UniformlySampleableHabitat<M, G>,
    G: RngCore<M>,
> {
    marker: PhantomData<(M, H, G)>,
}

impl<M: MathsCore, H: UniformlySampleableHabitat<M, G>, G: RngCore<M>> Default
    for UniformAntiTrespassingDispersalSampler<M, H, G>
{
    #[must_use]
    fn default() -> Self {
        Self {
            marker: PhantomData::<(M, H, G)>,
        }
    }
}

#[contract_trait]
impl<M: MathsCore, H: UniformlySampleableHabitat<M, G>, G: RngCore<M>> Backup
    for UniformAntiTrespassingDispersalSampler<M, H, G>
{
    unsafe fn backup_unchecked(&self) -> Self {
        Self {
            marker: PhantomData::<(M, H, G)>,
        }
    }
}

#[contract_trait]
impl<M: MathsCore, H: UniformlySampleableHabitat<M, G>, G: RngCore<M>>
    AntiTrespassingDispersalSampler<M, H, G> for UniformAntiTrespassingDispersalSampler<M, H, G>
{
    #[must_use]
    fn sample_anti_trespassing_dispersal_from_location(
        &self,
        _location: &Location,
        habitat: &H,
        rng: &mut G,
    ) -> Location {
        habitat.sample_habitable_indexed_location(rng).into()
    }
}