more efficient partial regen loop
This commit is contained in:
parent
76876eefac
commit
82ef9c24a6
12
Cargo.lock
generated
12
Cargo.lock
generated
@ -2340,6 +2340,17 @@ version = "0.2.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04"
|
checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unzip-n"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c2e7e85a0596447f0f2ac090e16bc4c516c6fe91771fb0c0ccf7fa3dae896b9c"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "url"
|
name = "url"
|
||||||
version = "2.2.2"
|
version = "2.2.2"
|
||||||
@ -2787,6 +2798,7 @@ dependencies = [
|
|||||||
"tracing",
|
"tracing",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
"tracing-wasm",
|
"tracing-wasm",
|
||||||
|
"unzip-n",
|
||||||
"uuid 1.0.0",
|
"uuid 1.0.0",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
|
|||||||
@ -57,6 +57,7 @@ uuid = { version = "1", features = ["v4", "fast-rng", "js"] }
|
|||||||
bincode = "1.3"
|
bincode = "1.3"
|
||||||
serde = "1"
|
serde = "1"
|
||||||
byte-unit = { version = "4", default-features = false }
|
byte-unit = { version = "4", default-features = false }
|
||||||
|
unzip-n = "0.1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
benchmarks = { path = "./benchmarks" }
|
benchmarks = { path = "./benchmarks" }
|
||||||
|
|||||||
@ -15,6 +15,7 @@ use std::{
|
|||||||
fmt::{self, Debug},
|
fmt::{self, Debug},
|
||||||
intrinsics::assume,
|
intrinsics::assume,
|
||||||
};
|
};
|
||||||
|
use unzip_n::unzip_n;
|
||||||
|
|
||||||
#[cfg(threading)]
|
#[cfg(threading)]
|
||||||
use rayon::iter::ParallelIterator;
|
use rayon::iter::ParallelIterator;
|
||||||
@ -307,25 +308,38 @@ impl FunctionEntry {
|
|||||||
let x_data_1: Vec<f64> = self.back_data.iter().map(|ele| ele.x).collect::<Vec<f64>>();
|
let x_data_1: Vec<f64> = self.back_data.iter().map(|ele| ele.x).collect::<Vec<f64>>();
|
||||||
let x_data: SteppedVector = x_data_1.as_slice().into();
|
let x_data: SteppedVector = x_data_1.as_slice().into();
|
||||||
|
|
||||||
let (back_data, derivative_data_1): (Vec<Value>, Vec<Option<Value>>) =
|
let do_nth_derivative = self.nth_derviative && self.nth_derivative_data.is_some();
|
||||||
dyn_iter(&resolution_iter)
|
|
||||||
.map(|x| {
|
let nth_derivative_data = self.nth_derivative_data.as_ref();
|
||||||
if let Some(i) = x_data.get_index(x) {
|
unzip_n!(3);
|
||||||
(
|
let (back_data, derivative_data_1, new_nth_derivative_data): (
|
||||||
self.back_data[i],
|
Vec<Value>,
|
||||||
derivative_required.then(|| self.derivative_data[i]),
|
Vec<Option<Value>>,
|
||||||
)
|
Vec<Option<Value>>,
|
||||||
} else {
|
) = dyn_iter(&resolution_iter)
|
||||||
(
|
.map(|x| {
|
||||||
Value::new(*x, self.function.get(*x)),
|
if let Some(i) = x_data.get_index(x) {
|
||||||
derivative_required
|
return (
|
||||||
.then(|| Value::new(*x, self.function.get_derivative_1(*x))),
|
self.back_data[i],
|
||||||
)
|
derivative_required.then(|| self.derivative_data[i]),
|
||||||
}
|
do_nth_derivative.then(|| unsafe {
|
||||||
})
|
nth_derivative_data.map(|data| data[i]).unwrap_unchecked()
|
||||||
.collect::<Vec<(Value, Option<Value>)>>()
|
}),
|
||||||
.into_iter()
|
);
|
||||||
.unzip();
|
} else {
|
||||||
|
return (
|
||||||
|
Value::new(*x, self.function.get(*x)),
|
||||||
|
derivative_required
|
||||||
|
.then(|| Value::new(*x, self.function.get_derivative_1(*x))),
|
||||||
|
do_nth_derivative.then(|| {
|
||||||
|
Value::new(*x, self.function.get_nth_derivative(self.curr_nth, *x))
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect::<Vec<(Value, Option<Value>, Option<Value>)>>()
|
||||||
|
.into_iter()
|
||||||
|
.unzip_n_vec();
|
||||||
|
|
||||||
debug_assert_eq!(back_data.len(), settings.plot_width + 1);
|
debug_assert_eq!(back_data.len(), settings.plot_width + 1);
|
||||||
debug_assert_eq!(derivative_data_1.len(), settings.plot_width + 1);
|
debug_assert_eq!(derivative_data_1.len(), settings.plot_width + 1);
|
||||||
@ -342,20 +356,13 @@ impl FunctionEntry {
|
|||||||
self.invalidate_derivative();
|
self.invalidate_derivative();
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.nth_derviative && let Some(nth_derivative_data) = &self.nth_derivative_data {
|
if do_nth_derivative {
|
||||||
let new_nth_derivative_data: Vec<Value> = dyn_iter(&resolution_iter)
|
self.nth_derivative_data = Some(
|
||||||
.map(|x| {
|
new_nth_derivative_data
|
||||||
if let Some(i) = x_data.get_index(x) {
|
.into_iter()
|
||||||
(*nth_derivative_data)[i]
|
.map(|c| unsafe { c.unwrap_unchecked() })
|
||||||
} else {
|
.collect(),
|
||||||
Value::new(*x, self.function.get_nth_derivative(self.curr_nth, *x))
|
);
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
debug_assert_eq!(new_nth_derivative_data.len(), settings.plot_width + 1);
|
|
||||||
|
|
||||||
self.nth_derivative_data = Some(new_nth_derivative_data);
|
|
||||||
} else {
|
} else {
|
||||||
self.invalidate_nth();
|
self.invalidate_nth();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user