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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
use crate::ode::types::OdeType;
#[derive(Debug, Default)]
pub struct CoefficientMap<Y: OdeType> {
inner: Vec<CoefficientPoint<Y>>,
}
impl<Y: OdeType> CoefficientMap<Y> {
#[inline]
pub fn with_capacity(capacity: usize) -> Self {
Self {
inner: Vec::with_capacity(capacity),
}
}
#[inline]
pub fn ks(&self) -> Ks<Y> {
Ks {
inner: self.inner.iter(),
}
}
#[inline]
pub fn ys(&self) -> Ks<Y> {
Ks {
inner: self.inner.iter(),
}
}
}
impl<Y: OdeType> std::ops::Deref for CoefficientMap<Y> {
type Target = Vec<CoefficientPoint<Y>>;
#[inline]
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl<Y: OdeType> std::ops::DerefMut for CoefficientMap<Y> {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl<Y: OdeType> IntoIterator for CoefficientMap<Y> {
type Item = CoefficientPoint<Y>;
type IntoIter = std::vec::IntoIter<CoefficientPoint<Y>>;
#[inline]
fn into_iter(self) -> Self::IntoIter {
self.inner.into_iter()
}
}
impl<'a, Y: OdeType> IntoIterator for &'a CoefficientMap<Y> {
type Item = &'a CoefficientPoint<Y>;
type IntoIter = std::slice::Iter<'a, CoefficientPoint<Y>>;
#[inline]
fn into_iter(self) -> Self::IntoIter {
self.inner.iter()
}
}
pub struct Ks<'a, Y: OdeType> {
inner: std::slice::Iter<'a, CoefficientPoint<Y>>,
}
impl<'a, Y: OdeType> Iterator for Ks<'a, Y> {
type Item = &'a Y;
#[inline]
fn next(&mut self) -> Option<&'a Y> {
self.inner.next().map(|coeff| &coeff.k)
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
self.inner.size_hint()
}
}
pub struct Ys<'a, Y: OdeType> {
inner: std::slice::Iter<'a, CoefficientPoint<Y>>,
}
impl<'a, Y: OdeType> Iterator for Ys<'a, Y> {
type Item = &'a Y;
#[inline]
fn next(&mut self) -> Option<&'a Y> {
self.inner.next().map(|coeff| &coeff.y)
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
self.inner.size_hint()
}
}
#[derive(Debug, Clone)]
pub struct CoefficientPoint<Y: OdeType> {
pub k: Y,
pub y: Y,
}
impl<Y: OdeType> CoefficientPoint<Y> {
#[inline]
pub fn new(k: Y, y: Y) -> Self {
Self { k, y }
}
}