ginger/
lib.rs

1#![allow(non_snake_case)]
2
3pub mod aberth;
4pub mod horner;
5pub mod matrix2;
6pub mod rootfinding;
7pub mod vector2;
8pub mod vector2_ref;
9// pub mod robin;
10
11pub use crate::aberth::{aberth, aberth_mt, initial_aberth};
12pub use crate::matrix2::Matrix2;
13pub use crate::rootfinding::{
14    horner_eval, initial_autocorr, initial_guess, pbairstow_autocorr, pbairstow_autocorr_mt,
15    pbairstow_even, pbairstow_even_mt, Options,
16};
17pub use crate::vector2::Vector2;
18
19#[cfg(test)]
20mod tests {
21    use super::*;
22
23    #[test]
24    fn it_works() {
25        let a = Vector2::<f64>::new(1.2, 2.3);
26        a.scale(3.4);
27        a.unscale(3.4);
28        println!("{:?}", a.norm_sqr());
29        println!("{:?}", a.l1_norm());
30
31        let b = Vector2::<f64>::new(3.4, 4.5);
32        println!("{:?}", a + b);
33        println!("{:?}", a - b);
34
35        let mut a = Vector2::<f64>::new(4.2, 5.3);
36        a += b;
37        a -= b;
38        a *= 3.4;
39        a /= 3.4;
40        println!("{:?}", -a);
41        println!("{:?}", a * 3.4);
42        println!("{:?}", 3.4 * a);
43        println!("{:?}", a / 3.4);
44
45        let mm = Vector2::<Vector2<f64>>::new(a, b);
46        println!("{:?}", mm);
47
48        let mm = Matrix2::<f64>::new(a, b);
49        println!("{:?}", mm);
50
51        let b = Vector2::<i32>::new(42, 53);
52        println!("{:?}", b % 3);
53
54        let options = Options {
55            max_iters: 2000,
56            tolerance: 1e-14,
57            tol_ind: 1e-15,
58        };
59
60        let coeffs = vec![10.0, 34.0, 75.0, 94.0, 150.0, 94.0, 75.0, 34.0, 10.0];
61
62        let mut vrs = initial_guess(&coeffs);
63        let (niter, _found) = pbairstow_even(&coeffs, &mut vrs, &options);
64        println!("{niter}");
65
66        let mut vrs = initial_guess(&coeffs);
67        let (niter, _found) = pbairstow_even_mt(&coeffs, &mut vrs, &options);
68        println!("{niter}");
69
70        let mut vrs = initial_autocorr(&coeffs);
71        let (niter, _found) = pbairstow_autocorr(&coeffs, &mut vrs, &options);
72        println!("{niter}");
73
74        let mut vrs = initial_autocorr(&coeffs);
75        let (niter, _found) = pbairstow_autocorr_mt(&coeffs, &mut vrs, &options);
76        println!("{niter}");
77
78        let options = Options {
79            max_iters: 2000,
80            tolerance: 1e-12,
81            tol_ind: 1e-15,
82        };
83
84        let mut zs = initial_aberth(&coeffs);
85        let (niter, _found) = aberth(&coeffs, &mut zs, &options);
86        println!("{niter}");
87
88        let mut zs = initial_aberth(&coeffs);
89        let (niter, _found) = aberth_mt(&coeffs, &mut zs, &options);
90        println!("{niter}");
91    }
92}