- cleanup

This commit is contained in:
w.pomp committed 2026-07-31 17:49:11 +02:00
1 parent f75f12db16
commit cc12a1a9b9
5 files changed
+253 -175

No files matched your search

+10 -28
View File
@@ -152,7 +152,7 @@ fn parzen(
enum Sampling {
Fixed(Vec<Vec<f64>>),
Random((usize, Vec<f64>, RefCell<Vec<Vec<f64>>>)),
Random((usize, Vec<f64>)),
}
impl Sampling {
@@ -161,25 +161,19 @@ impl Sampling {
}
fn random(n_samples: usize, shape: Vec<f64>) -> Self {
Self::Random((n_samples, shape, RefCell::new(Vec::new())))
Self::Random((n_samples, shape))
}
fn index(&self) -> Vec<Vec<f64>> {
match self {
Self::Fixed(index) => index.clone(),
Self::Random((n_samples, shape, cached)) => {
let mut cache = cached.borrow_mut();
if cache.is_empty() {
*cache = rand::rng()
.random_iter::<f64>()
.take(n_samples * shape.len())
.chunks(shape.len())
.into_iter()
.map(|c| c.zip_eq(shape.iter()).map(|(i, s)| i * s - 0.5).collect())
.collect();
}
cache.clone()
}
Self::Random((n_samples, shape)) => rand::rng()
.random_iter::<f64>()
.take(n_samples * shape.len())
.chunks(shape.len())
.into_iter()
.map(|c| c.zip_eq(shape.iter()).map(|(i, s)| i * s - 0.5).collect())
.collect(),
}
}
}
@@ -437,23 +431,11 @@ where
debug_assert!(metric.is_finite());
debug_assert!(dmetric.iter().all(|i| i.is_finite()));
// let alpha = 1.0;
// let dalpha = vec![0.0; dalpha.len()];
self.metric.replace(IntMut {
mu: mu.to_vec(),
metric,
derivative: dmetric.clone(),
});
// self.metric.replace(IntMut {
// mu: mu.to_vec(),
// metric: metric / alpha,
// derivative: dmetric
// .iter()
// .zip_eq(dalpha)
// .map(|(dm, da)| *dm / alpha + da * metric / (alpha * alpha))
// .collect(),
// });
}
Ok(())
}
@@ -778,7 +760,7 @@ mod tests {
let fixed = BSpline::<0, _>::new(a.view());
let moving = BSpline::<3, _>::new(b.view());
let mus = vec![0.0, 0.001];
let mus = [0.0, 0.001];
let mut npz = NpzWriter::new(File::create(
std::env::home_dir().unwrap().join("tmp/metric.npz"),
)?);