it doesn't make sense to have more than the 255'th derivative in a single direction
This commit is contained in:
parent
783d60b117
commit
938cf2de3b
2 changed files with 11 additions and 11 deletions
|
@ -19,29 +19,29 @@ struct PreHasseNode {
|
||||||
* split the derivation-vectors into levels (sum of their components)
|
* split the derivation-vectors into levels (sum of their components)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fn sum(drvs: &[u16]) -> usize {
|
fn sum(drvs: &[u8]) -> usize {
|
||||||
drvs.iter().copied().map(usize::from).sum::<usize>()
|
drvs.iter().copied().map(usize::from).sum::<usize>()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parents(drvs: &[u16]) -> impl Iterator<Item = Box<[u16]>> + '_ {
|
fn parents(drvs: &[u8]) -> impl Iterator<Item = Box<[u8]>> + '_ {
|
||||||
drvs.iter()
|
drvs.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter_map(|(n, i)| i.checked_sub(1).map(|i2| (n, i2)))
|
.filter_map(|(n, i)| i.checked_sub(1).map(|i2| (n, i2)))
|
||||||
.map(|(n, j)| {
|
.map(|(n, j)| {
|
||||||
let mut i2: Box<[u16]> = drvs.to_owned().into_boxed_slice();
|
let mut i2: Box<[u8]> = drvs.to_owned().into_boxed_slice();
|
||||||
i2[n] = j;
|
i2[n] = j;
|
||||||
i2
|
i2
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// calculate votes for each possible parent
|
/// calculate votes for each possible parent
|
||||||
fn calculate_votes(mut que: Vec<Box<[u16]>>) -> Vec<BTreeMap<Box<[u16]>, u16>> {
|
fn calculate_votes(mut que: Vec<Box<[u8]>>) -> Vec<BTreeMap<Box<[u8]>, u16>> {
|
||||||
assert!(que.len() <= usize::from(u16::MAX));
|
assert!(que.len() <= usize::from(u16::MAX));
|
||||||
|
|
||||||
// split que into levels
|
// split que into levels
|
||||||
let mut levels = core::iter::repeat_with(BTreeMap::new)
|
let mut levels = core::iter::repeat_with(BTreeMap::new)
|
||||||
.take(que.iter().map(|i| sum(&i[..])).max().map(|i| i.checked_add(1).unwrap()).unwrap_or(0))
|
.take(que.iter().map(|i| sum(&i[..])).max().map(|i| i.checked_add(1).unwrap()).unwrap_or(0))
|
||||||
.collect::<Vec<BTreeMap<Box<[u16]>, u16>>>();
|
.collect::<Vec<BTreeMap<Box<[u8]>, u16>>>();
|
||||||
|
|
||||||
for i in core::mem::replace(&mut que, Vec::new()) {
|
for i in core::mem::replace(&mut que, Vec::new()) {
|
||||||
let mut l = &mut levels[sum(&i[..])];
|
let mut l = &mut levels[sum(&i[..])];
|
||||||
|
|
|
@ -12,7 +12,7 @@ use yz_string_utils::StrLexerBase;
|
||||||
|
|
||||||
/// A reference to a PDE variable or derivative of such
|
/// A reference to a PDE variable or derivative of such
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct Link(pub u16, pub Box<[u16]>);
|
pub struct Link(pub u16, pub Box<[u8]>);
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum Expr<L> {
|
pub enum Expr<L> {
|
||||||
|
@ -167,7 +167,7 @@ impl ParseLink for Link {
|
||||||
if dr.is_empty() {
|
if dr.is_empty() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let dr = dr.parse::<u16>()?;
|
let dr = dr.parse::<u8>()?;
|
||||||
derivatives.push(dr);
|
derivatives.push(dr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,11 +259,11 @@ pub fn parse_expr_final<L: Clone + ParseLink>(slb: &mut StrLexerBase) -> Result<
|
||||||
```
|
```
|
||||||
%vs
|
%vs
|
||||||
# u_t + 0.11 u_x = 0
|
# u_t + 0.11 u_x = 0
|
||||||
0; prod(-0.11, 0_0_)
|
0; prod(-0.11, 0_1)
|
||||||
|
|
||||||
%mons
|
%mons
|
||||||
# monitor u @ 1 + sin(t)
|
# monitor u @ 1 + sin(t)
|
||||||
0_; sum(1.0, sin(.))
|
0_0; sum(1.0, sin(.))
|
||||||
```
|
```
|
||||||
|
|
||||||
# Syntax:
|
# Syntax:
|
||||||
|
@ -374,11 +374,11 @@ mod tests {
|
||||||
println!("{:?}", parse_system("
|
println!("{:?}", parse_system("
|
||||||
%vs
|
%vs
|
||||||
# u_t + 0.11 u_x = 0
|
# u_t + 0.11 u_x = 0
|
||||||
0; prod(-0.11, 0_0_)
|
0; prod(-0.11, 0_1_)
|
||||||
|
|
||||||
%mons
|
%mons
|
||||||
# monitor u @ 1 + sin(t)
|
# monitor u @ 1 + sin(t)
|
||||||
0_; sum(1.0, sin(.))
|
0_0; sum(1.0, sin(.))
|
||||||
").unwrap());
|
").unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue