Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 74b18257 authored by GUILLEMOT Alexandre's avatar GUILLEMOT Alexandre
Browse files

remove paths as a generic type for the trait sep

parent 4d897ef9
Branches
Tags
No related merge requests found
...@@ -57,21 +57,23 @@ impl Symbol { ...@@ -57,21 +57,23 @@ impl Symbol {
} }
} }
pub trait Sep<Paths, R> { pub trait Sep<R> {
fn sep(&self, paths: &Paths, i: usize, j: usize, t: &R) -> Result<(Symbol, R)>; fn sep(&self, i: usize, j: usize, t: &R) -> Result<(Symbol, R)>;
} }
pub struct TrackOutputSeperator<CtxT> { pub struct TrackOutputSeperator<'a, CtxT, R, VecTm, MatC> {
types: PhantomData<CtxT>, types: PhantomData<CtxT>,
pub path: &'a Vec<Vec<MooreBox<R, VecTm, MatC>>>,
pub indices: Vec<usize>, pub indices: Vec<usize>,
pub projection: usize, pub projection: usize,
} }
impl<CtxT> TrackOutputSeperator<CtxT> { impl<'a, CtxT, R, VecTm, MatC> TrackOutputSeperator<'a, CtxT, R, VecTm, MatC> {
pub fn new(nstrands: usize, projection: usize) -> Self { pub fn new(projection: usize, path: &'a Vec<Vec<MooreBox<R, VecTm, MatC>>>) -> Self {
Self { Self {
types: PhantomData, types: PhantomData,
indices: (0..nstrands).map(|_| 0).collect(), path,
indices: (0..path.len()).map(|_| 0).collect(),
projection: projection, projection: projection,
} }
} }
...@@ -155,7 +157,7 @@ impl PartialOrd for Arb { ...@@ -155,7 +157,7 @@ impl PartialOrd for Arb {
} }
} }
impl<R, VecTm, MatC, CtxT> Sep<Vec<Vec<MooreBox<R, VecTm, MatC>>>, R> for TrackOutputSeperator<CtxT> impl<'a, CtxT, R, VecTm, MatC> Sep<R> for TrackOutputSeperator<'a, CtxT, R, VecTm, MatC>
where where
R: Clone + RealInterval + IntervalComparisons + One + Debug + From<f64> + Zero, R: Clone + RealInterval + IntervalComparisons + One + Debug + From<f64> + Zero,
for<'l, 'r> &'l R: PartialOrd + Sub<&'r R, Output = R> + Add<R, Output = R>, for<'l, 'r> &'l R: PartialOrd + Sub<&'r R, Output = R> + Add<R, Output = R>,
...@@ -170,11 +172,11 @@ where ...@@ -170,11 +172,11 @@ where
+ Debug, + Debug,
CtxT: PrecCtx, CtxT: PrecCtx,
{ {
fn sep(&self, paths: &Vec<Vec<MooreBox<R, VecTm, MatC>>>, i: usize, j: usize, t: &R) -> Result<(Symbol, R)> { fn sep(&self, i: usize, j: usize, t: &R) -> Result<(Symbol, R)> {
type C<VecTm> = <<VecTm as TaylorModel>::Coeffs as Vector>::T; type C<VecTm> = <<VecTm as TaylorModel>::Coeffs as Vector>::T;
let (k_i, t_i) = search_next_interval(self.indices[i], &paths[i], t); let (k_i, t_i) = search_next_interval(self.indices[i], &self.path[i], t);
let (k_j, t_j) = search_next_interval(self.indices[j], &paths[j], t); let (k_j, t_j) = search_next_interval(self.indices[j], &self.path[j], t);
//TODO: manage indices in the separator struct //TODO: manage indices in the separator struct
let t_res = if &t_i < &t_j { t_i } else { t_j }; let t_res = if &t_i < &t_j { t_i } else { t_j };
...@@ -193,21 +195,21 @@ where ...@@ -193,21 +195,21 @@ where
bail!("step size is {} which looks ridiculously small", auxi.diam()); bail!("step size is {} which looks ridiculously small", auxi.diam());
} }
let interval_i = &auxi - &paths[i][k_i].params; let interval_i = &auxi - &self.path[i][k_i].params;
let interval_j = &auxi - &paths[j][k_j].params; let interval_j = &auxi - &self.path[j][k_j].params;
let enclosure_i = paths[i][k_i] let enclosure_i = self.path[i][k_i]
.pt .pt
.coord .coord
.enclosure(&interval_i.intersection(&paths[i][k_i].pt.coord.domain()))[self.projection] .enclosure(&interval_i.intersection(&self.path[i][k_i].pt.coord.domain()))[self.projection]
.clone() .clone()
+ C::<VecTm>::square(paths[i][k_i].rad); + C::<VecTm>::square(self.path[i][k_i].rad);
let enclosure_j = paths[j][k_j] let enclosure_j = self.path[j][k_j]
.pt .pt
.coord .coord
.enclosure(&interval_j.intersection(&paths[j][k_j].pt.coord.domain()))[self.projection] .enclosure(&interval_j.intersection(&self.path[j][k_j].pt.coord.domain()))[self.projection]
.clone() .clone()
+ C::<VecTm>::square(paths[j][k_j].rad); + C::<VecTm>::square(self.path[j][k_j].rad);
if enclosure_i.real().interval_lt(&enclosure_j.real()) { if enclosure_i.real().interval_lt(&enclosure_j.real()) {
return Ok((Symbol::RealLower, t_res)); return Ok((Symbol::RealLower, t_res));
...@@ -244,10 +246,8 @@ pub mod tests { ...@@ -244,10 +246,8 @@ pub mod tests {
#[test] #[test]
fn test_1() { fn test_1() {
let path = PathBuf::from( let path =
"/home/aguillem/documents/travail/these/numerical_algebraic_geometry/braids/code/braid_group PathBuf::from("/home/aguillem/documents/travail/these/numerical_algebraic_geometry/braids/code/braid_group/tmp.json");
/tmp.json",
);
let mut conf = crate::cli::Configuration { let mut conf = crate::cli::Configuration {
path: Some(path), path: Some(path),
..Default::default() ..Default::default()
...@@ -261,13 +261,13 @@ pub mod tests { ...@@ -261,13 +261,13 @@ pub mod tests {
let j = 1; let j = 1;
let reds = track_from_conf_and_arith!(&conf, reckless); let reds = track_from_conf_and_arith!(&conf, reckless);
let separator: TrackOutputSeperator<FixedPrecCtx> = TrackOutputSeperator::new(reds.len(), 0); let separator: TrackOutputSeperator<'_, FixedPrecCtx, _, _, _> = TrackOutputSeperator::new(0, &reds);
let mut t = Rif::from(0.04057978317160819); let mut t = Rif::from(0.04057978317160819);
let mut s; let mut s;
let mut cpt = 0; let mut cpt = 0;
while t < Rif::from(0.04443077070344210) { while t < Rif::from(0.04443077070344210) {
(s, t) = separator.sep(&reds, i, j, &t).unwrap(); (s, t) = separator.sep(i, j, &t).unwrap();
dbg!(t); dbg!(t);
dbg!(s); dbg!(s);
cpt += 1; cpt += 1;
...@@ -292,13 +292,13 @@ pub mod tests { ...@@ -292,13 +292,13 @@ pub mod tests {
let reds = track_from_conf_and_arith!(&conf, reckless); let reds = track_from_conf_and_arith!(&conf, reckless);
let mut rng = rand::rng(); let mut rng = rand::rng();
let separator: TrackOutputSeperator<FixedPrecCtx> = TrackOutputSeperator::new(reds.len(), 0); let separator: TrackOutputSeperator<'_, FixedPrecCtx, _, _, _> = TrackOutputSeperator::new(0, &reds);
for i in 0..reds.len() { for i in 0..reds.len() {
for j in 0..i { for j in 0..i {
for _ in 0..10 { for _ in 0..10 {
let t = Rif::from(rng.random::<f64>()); let t = Rif::from(rng.random::<f64>());
assert!(&t <= &separator.sep(&reds, i, j, &t).unwrap().1); assert!(&t <= &separator.sep(i, j, &t).unwrap().1);
} }
} }
} }
...@@ -318,13 +318,13 @@ pub mod tests { ...@@ -318,13 +318,13 @@ pub mod tests {
let reds = track_from_conf_and_arith!(&conf, reckless); let reds = track_from_conf_and_arith!(&conf, reckless);
let mut rng = rand::rng(); let mut rng = rand::rng();
let separator: TrackOutputSeperator<FixedPrecCtx> = TrackOutputSeperator::new(reds.len(), 0); let separator: TrackOutputSeperator<'_, FixedPrecCtx, _, _, _> = TrackOutputSeperator::new(0, &reds);
for i in 0..reds.len() { for i in 0..reds.len() {
for j in 0..i { for j in 0..i {
for _ in 0..100 { for _ in 0..100 {
let t = Rif::from(rng.random::<f64>()); let t = Rif::from(rng.random::<f64>());
assert!(&t <= &separator.sep(&reds, i, j, &t).unwrap().1); assert!(&t <= &separator.sep(i, j, &t).unwrap().1);
} }
} }
} }
...@@ -344,13 +344,13 @@ pub mod tests { ...@@ -344,13 +344,13 @@ pub mod tests {
let reds = track_from_conf_and_arith!(&conf, arb); let reds = track_from_conf_and_arith!(&conf, arb);
let mut rng = rand::rng(); let mut rng = rand::rng();
let separator: TrackOutputSeperator<AdaptivePrecCtx> = TrackOutputSeperator::new(reds.len(), 0); let separator: TrackOutputSeperator<'_, AdaptivePrecCtx, _, _, _> = TrackOutputSeperator::new(0, &reds);
for i in 0..reds.len() { for i in 0..reds.len() {
for j in 0..i { for j in 0..i {
for _ in 0..100 { for _ in 0..100 {
let t = Arb::from(rng.random::<f64>()); let t = Arb::from(rng.random::<f64>());
assert!(&t <= &separator.sep(&reds, i, j, &t).unwrap().1); assert!(&t <= &separator.sep(i, j, &t).unwrap().1);
} }
} }
} }
...@@ -358,7 +358,7 @@ pub mod tests { ...@@ -358,7 +358,7 @@ pub mod tests {
#[test] #[test]
fn test_5() { fn test_5() {
let path = PathBuf::from("data/tmp.json"); let path = PathBuf::from("/home/aguillem/documents/travail/these/numerical_algebraic_geometry/braids/code/braid_group/tmp.json");
let mut conf = crate::cli::Configuration { let mut conf = crate::cli::Configuration {
path: Some(path), path: Some(path),
..Default::default() ..Default::default()
...@@ -372,13 +372,13 @@ pub mod tests { ...@@ -372,13 +372,13 @@ pub mod tests {
let j = 4; let j = 4;
let reds = track_from_conf_and_arith!(&conf, arb); let reds = track_from_conf_and_arith!(&conf, arb);
let separator: TrackOutputSeperator<AdaptivePrecCtx> = TrackOutputSeperator::new(reds.len(), 0); let separator: TrackOutputSeperator<'_, AdaptivePrecCtx, _, _, _> = TrackOutputSeperator::new(0, &reds);
let mut t = Arb::from(0.0); let mut t = Arb::from(0.0);
let mut s; let mut s;
let mut cpt = 0; let mut cpt = 0;
while t < Arb::from(1.0) { while t < Arb::from(1.0) {
(s, t) = separator.sep(&reds, i, j, &t).unwrap(); (s, t) = separator.sep(i, j, &t).unwrap();
dbg!(&t); dbg!(&t);
dbg!(&s); dbg!(&s);
cpt += 1; cpt += 1;
...@@ -389,7 +389,7 @@ pub mod tests { ...@@ -389,7 +389,7 @@ pub mod tests {
dbg!(reds[j].len()); dbg!(reds[j].len());
} }
#[test] // #[test]
fn test_6() { fn test_6() {
let path = PathBuf::from("data/1000_1.json"); let path = PathBuf::from("data/1000_1.json");
let mut conf = crate::cli::Configuration { let mut conf = crate::cli::Configuration {
...@@ -405,13 +405,13 @@ pub mod tests { ...@@ -405,13 +405,13 @@ pub mod tests {
let j = 415; let j = 415;
let reds = track_from_conf_and_arith!(&conf, legacy_arb_reckless); let reds = track_from_conf_and_arith!(&conf, legacy_arb_reckless);
let separator: TrackOutputSeperator<AdaptivePrecCtx> = TrackOutputSeperator::new(reds.len(), 0); let separator: TrackOutputSeperator<'_, AdaptivePrecCtx, _, _, _> = TrackOutputSeperator::new(0, &reds);
let mut t = Arb::zero(); let mut t = Arb::zero();
let mut s; let mut s;
let mut cpt = 0; let mut cpt = 0;
while &t < &Arb::one() { while &t < &Arb::one() {
(s, t) = separator.sep(&reds, i, j, &t).unwrap(); (s, t) = separator.sep(i, j, &t).unwrap();
dbg!(&t); dbg!(&t);
dbg!(&s); dbg!(&s);
cpt += 1; cpt += 1;
...@@ -436,12 +436,12 @@ pub mod tests { ...@@ -436,12 +436,12 @@ pub mod tests {
conf.arithmetic = Arithmetic::Reckless; conf.arithmetic = Arithmetic::Reckless;
let reds = track_from_conf_and_arith!(&conf, reckless); let reds = track_from_conf_and_arith!(&conf, reckless);
let separator: TrackOutputSeperator<FixedPrecCtx> = TrackOutputSeperator::new(reds.len(), 0); let separator: TrackOutputSeperator<'_, FixedPrecCtx, _, _, _> = TrackOutputSeperator::new(0, &reds);
let i = 3; let i = 3;
let j = 1; let j = 1;
let t = Rif::from(0.009330666825934752); let t = Rif::from(0.009330666825934752);
assert!(separator.sep(&reds, i, j, &t).is_err_and(|e| { assert!(separator.sep(i, j, &t).is_err_and(|e| {
println!("{}", e); println!("{}", e);
true true
})); }));
...@@ -461,13 +461,13 @@ pub mod tests { ...@@ -461,13 +461,13 @@ pub mod tests {
conf.arithmetic = Arithmetic::Arb; conf.arithmetic = Arithmetic::Arb;
let reds = track_from_conf_and_arith!(&conf, arb); let reds = track_from_conf_and_arith!(&conf, arb);
let separator: TrackOutputSeperator<AdaptivePrecCtx> = TrackOutputSeperator::new(reds.len(), 0); let separator: TrackOutputSeperator<'_, FixedPrecCtx, _, _, _> = TrackOutputSeperator::new(0, &reds);
let i = 3; let i = 3;
let j = 1; let j = 1;
let t = Arb::from(0.009330666825934752); let t = Arb::from(0.009330666825934752);
assert!(separator.sep(&reds, i, j, &t).is_err_and(|e| { assert!(separator.sep(i, j, &t).is_err_and(|e| {
println!("{}", e); println!("{}", e);
true true
})); }));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment