diff --git a/bachelorarbeit/flamegraph.svg b/bachelorarbeit/flamegraph.svg index 5a996ad..01437c4 100644 --- a/bachelorarbeit/flamegraph.svg +++ b/bachelorarbeit/flamegraph.svg @@ -1,4 +1,4 @@ - \ No newline at end of file diff --git a/bachelorarbeit/perf.data b/bachelorarbeit/perf.data index f41c7bf..91554f7 100644 Binary files a/bachelorarbeit/perf.data and b/bachelorarbeit/perf.data differ diff --git a/bachelorarbeit/perf.data.old b/bachelorarbeit/perf.data.old deleted file mode 100644 index 2d12b9a..0000000 Binary files a/bachelorarbeit/perf.data.old and /dev/null differ diff --git a/bachelorarbeit/src/calc.rs b/bachelorarbeit/src/calc.rs index fdddbef..fcb6e11 100644 --- a/bachelorarbeit/src/calc.rs +++ b/bachelorarbeit/src/calc.rs @@ -32,6 +32,7 @@ pub struct Cache { HashMap>, nohash_hasher::BuildNoHashHasher, >, // First key is n, second is s + pub tan_lut: HashMap> } // pub struct Cache { @@ -67,6 +68,7 @@ impl Cache { .collect(), delta_lut: HashMap::with_hasher(Default::default()), omnes_lut: HashMap::with_hasher(Default::default()), + tan_lut: HashMap::with_hasher(Default::default()), }; Ok(me) } @@ -86,6 +88,7 @@ impl Cache { .collect(), delta_lut: HashMap::with_hasher(Default::default()), omnes_lut: HashMap::with_hasher(Default::default()), + tan_lut: HashMap::with_hasher(Default::default()), }; Ok(me) } @@ -101,6 +104,21 @@ fn delta_mid_cutoff() -> f64 { delta(S_MID_CUTOFF) } +fn tan_with_lut(cache: &mut Cache, s: f64) -> f64 { + // match cache.tan_lut.get(&s.to_bits()) { + // Some(val) => { + // println!("tan reused"); + // *val + // } + // None => { + // let val = s.tan(); + // cache.tan_lut.insert(s.to_bits(), val); + // val + // } + // } + s.tan() +} + fn atan_shift(x: f64) -> f64 { let atan_std: f64 = x.atan(); if atan_std < 0.0 { @@ -199,7 +217,7 @@ pub fn delta(s: f64) -> f64 { } pub fn omnes_integrand_tan(cache: &mut Cache, s_tick: f64, s: f64) -> Complex { - let sub = s_tick.tan(); + let sub = tan_with_lut(cache, s_tick); (delta_with_lut(cache, sub) - delta_with_lut(cache, s)) / (sub * (sub - s + Complex::new(0.0, EPSILON)) * s_tick.cos().powi(2)) } @@ -278,8 +296,8 @@ pub fn phi0_integrand( cutoff_factor: Complex, ) -> f64 { let sub = match (use_tan_phi0, use_xsub) { - (true, true) => s_tick.tan().powi(2) + S0, - (true, false) => s_tick.tan(), + (true, true) => tan_with_lut(cache, s_tick).powi(2) + S0, + (true, false) => tan_with_lut(cache, s_tick), (false, true) => s_tick.powi(2) + S0, (false, false) => s_tick, }; diff --git a/bachelorarbeit/src/main.rs b/bachelorarbeit/src/main.rs index 6612609..390cce4 100644 --- a/bachelorarbeit/src/main.rs +++ b/bachelorarbeit/src/main.rs @@ -595,8 +595,9 @@ fn main() { // }) // .collect(); - let phi0 = calc::phi0(&mut app.calc_cache, 10000.0, 10000, 10000, true, true, true, true, true, false, 0.0, 0.0); + let phi0 = calc::phi0(&mut app.calc_cache, 10000.0, 15000, 15000, true, true, true, true, true, false, 0.0, 0.0); println!("relative difference: {}", phi0 / calc::delta(10000.0) - 1.0); + println!("{:?}", app.calc_cache.tan_lut.len()); // eframe::run_native( // "Omnes Calculator", diff --git a/ersterTest.py b/ersterTest.py index 269cc1a..fb0f94f 100644 --- a/ersterTest.py +++ b/ersterTest.py @@ -195,7 +195,7 @@ def phi0(s, a=0, inf = 100000, optimized = True, n = gl_n_phi0): c = np.pi / (s * np.sqrt(s_0)) * np.log(cmath.polar(omnes(s))[0]**2) if optimized == True: - integral = integral_gl_tan_reparam(phi0_integrand, s, a, inf, n, False) + integral = integral_gl_tan_reparam(phi0_integrand, s, a, inf, n, True) else: integral = integral_gl(phi0_integrand, s, a, inf, n) return -s * np.sqrt(s-s_0) / (2*np.pi) * (integral - c) @@ -269,7 +269,7 @@ ax.plot(x, y_delta, label = r"$\delta$") # print(time() - t0) t0 = time() -print(phi0(10000, n=100)) +print(phi0(10000, n=15000) / delta(10000)) print(time() - t0) # ax.legend() @@ -277,4 +277,4 @@ print(time() - t0) # ax.grid(which='major', color='#A4A4A4', linewidth=1) # ax.grid(which='minor', color='#B5B5B5', linestyle=':', linewidth=0.5) # ax.minorticks_on() -# plt.show() \ No newline at end of file +# plt.show()