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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use crate::RealType;
use ndarray::{Array2, ArrayView2};
pub trait ParticleContainerAccessor {
type FloatingPointType: RealType;
fn sources(&self) -> ArrayView2<Self::FloatingPointType>;
fn targets(&self) -> ArrayView2<Self::FloatingPointType>;
}
pub struct ParticleContainer<T: RealType> {
sources: Array2<T>,
targets: Array2<T>,
}
pub fn make_particle_container_owned<T: RealType>(
sources: Array2<T>,
targets: Array2<T>,
) -> ParticleContainer<T> {
ParticleContainer { sources, targets }
}
pub fn make_particle_container<'a, T: RealType>(
sources: ArrayView2<'a, T>,
targets: ArrayView2<'a, T>,
) -> ParticleContainerView<'a, T> {
ParticleContainerView { sources, targets }
}
pub struct ParticleContainerView<'a, T: RealType> {
sources: ArrayView2<'a, T>,
targets: ArrayView2<'a, T>,
}
impl<T: RealType> ParticleContainerAccessor for ParticleContainer<T> {
type FloatingPointType = T;
fn sources(&self) -> ArrayView2<Self::FloatingPointType> {
self.sources.view()
}
fn targets(&self) -> ArrayView2<Self::FloatingPointType> {
self.targets.view()
}
}
impl<'a, T: RealType> ParticleContainerAccessor for ParticleContainerView<'a, T> {
type FloatingPointType = T;
fn sources(&self) -> ArrayView2<Self::FloatingPointType> {
self.sources.view()
}
fn targets(&self) -> ArrayView2<Self::FloatingPointType> {
self.targets.view()
}
}