ginger/
lib.rs

1#![allow(non_snake_case)]
2
3// pub mod spectral_fact;
4// pub mod robin;
5
6/**
7 * This module implements the Aberth method for finding the roots of a polynomial.
8 */
9pub mod aberth;
10
11/**
12 * This module implements Horner's method for polynomial evaluation.
13 */
14pub mod horner;
15
16/**
17 * This module implements a simple 2x2 matrix.
18 */
19pub mod matrix2;
20
21/**
22 * This module implements the Bairstow's method for finding the roots of a polynomial.
23 */
24pub mod rootfinding;
25
26/**
27 * This module implements the Leja ordering.
28 */
29pub mod leja_order;
30
31/**
32 * This module implements a simple 2D vector.
33 */
34pub mod vector2;
35
36/**
37 * This module implements a simple 2D vector reference.
38 */
39pub mod vector2_ref;
40
41pub use crate::aberth::{aberth, aberth_mt, initial_aberth};
42pub use crate::horner::{horner_eval_c, horner_eval_f};
43pub use crate::matrix2::Matrix2;
44pub use crate::rootfinding::{
45    initial_autocorr, initial_guess, pbairstow_autocorr, pbairstow_autocorr_mt, pbairstow_even,
46    pbairstow_even_mt, Options,
47};
48pub use crate::vector2::Vector2;
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn it_works() {
56        let a = Vector2::<f64>::new(1.2, 2.3);
57        a.scale(3.4);
58        a.unscale(3.4);
59        println!("{:?}", a.norm_sqr());
60        println!("{:?}", a.l1_norm());
61
62        let b = Vector2::<f64>::new(3.4, 4.5);
63        println!("{:?}", a + b);
64        println!("{:?}", a - b);
65
66        let mut a = Vector2::<f64>::new(4.2, 5.3);
67        a += b;
68        a -= b;
69        a *= 3.4;
70        a /= 3.4;
71        println!("{:?}", -a);
72        println!("{:?}", a * 3.4);
73        println!("{:?}", 3.4 * a);
74        println!("{:?}", a / 3.4);
75
76        let mm = Vector2::<Vector2<f64>>::new(a, b);
77        println!("{:?}", mm);
78
79        let mm = Matrix2::<f64>::new(a, b);
80        println!("{:?}", mm);
81
82        let b = Vector2::<i32>::new(42, 53);
83        println!("{:?}", b % 3);
84
85        let options = Options {
86            max_iters: 2000,
87            tolerance: 1e-14,
88            tol_ind: 1e-15,
89        };
90
91        let coeffs = vec![10.0, 34.0, 75.0, 94.0, 150.0, 94.0, 75.0, 34.0, 10.0];
92
93        let mut vrs = initial_guess(&coeffs);
94        let (niter, _found) = pbairstow_even(&coeffs, &mut vrs, &options);
95        println!("{niter}");
96
97        let mut vrs = initial_guess(&coeffs);
98        let (niter, _found) = pbairstow_even_mt(&coeffs, &mut vrs, &options);
99        println!("{niter}");
100
101        let mut vrs = initial_autocorr(&coeffs);
102        let (niter, _found) = pbairstow_autocorr(&coeffs, &mut vrs, &options);
103        println!("{niter}");
104
105        let mut vrs = initial_autocorr(&coeffs);
106        let (niter, _found) = pbairstow_autocorr_mt(&coeffs, &mut vrs, &options);
107        println!("{niter}");
108
109        let options = Options {
110            max_iters: 2000,
111            tolerance: 1e-12,
112            tol_ind: 1e-15,
113        };
114
115        let mut zs = initial_aberth(&coeffs);
116        let (niter, _found) = aberth(&coeffs, &mut zs, &options);
117        println!("{niter}");
118
119        let mut zs = initial_aberth(&coeffs);
120        let (niter, _found) = aberth_mt(&coeffs, &mut zs, &options);
121        println!("{niter}");
122    }
123}