Compare commits
1 Commits
main
...
single_thr
Author | SHA1 | Date | |
---|---|---|---|
3285ae0b74 |
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 44 KiB |
Binary file not shown.
Binary file not shown.
@ -32,6 +32,7 @@ pub struct Cache {
|
|||||||
HashMap<u64, Complex, nohash_hasher::BuildNoHashHasher<u64>>,
|
HashMap<u64, Complex, nohash_hasher::BuildNoHashHasher<u64>>,
|
||||||
nohash_hasher::BuildNoHashHasher<u32>,
|
nohash_hasher::BuildNoHashHasher<u32>,
|
||||||
>, // First key is n, second is s
|
>, // First key is n, second is s
|
||||||
|
pub tan_lut: HashMap<u64, f64, nohash_hasher::BuildNoHashHasher<u64>>
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub struct Cache {
|
// pub struct Cache {
|
||||||
@ -67,6 +68,7 @@ impl Cache {
|
|||||||
.collect(),
|
.collect(),
|
||||||
delta_lut: HashMap::with_hasher(Default::default()),
|
delta_lut: HashMap::with_hasher(Default::default()),
|
||||||
omnes_lut: HashMap::with_hasher(Default::default()),
|
omnes_lut: HashMap::with_hasher(Default::default()),
|
||||||
|
tan_lut: HashMap::with_hasher(Default::default()),
|
||||||
};
|
};
|
||||||
Ok(me)
|
Ok(me)
|
||||||
}
|
}
|
||||||
@ -86,6 +88,7 @@ impl Cache {
|
|||||||
.collect(),
|
.collect(),
|
||||||
delta_lut: HashMap::with_hasher(Default::default()),
|
delta_lut: HashMap::with_hasher(Default::default()),
|
||||||
omnes_lut: HashMap::with_hasher(Default::default()),
|
omnes_lut: HashMap::with_hasher(Default::default()),
|
||||||
|
tan_lut: HashMap::with_hasher(Default::default()),
|
||||||
};
|
};
|
||||||
Ok(me)
|
Ok(me)
|
||||||
}
|
}
|
||||||
@ -101,6 +104,21 @@ fn delta_mid_cutoff() -> f64 {
|
|||||||
delta(S_MID_CUTOFF)
|
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 {
|
fn atan_shift(x: f64) -> f64 {
|
||||||
let atan_std: f64 = x.atan();
|
let atan_std: f64 = x.atan();
|
||||||
if atan_std < 0.0 {
|
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 {
|
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))
|
(delta_with_lut(cache, sub) - delta_with_lut(cache, s))
|
||||||
/ (sub * (sub - s + Complex::new(0.0, EPSILON)) * s_tick.cos().powi(2))
|
/ (sub * (sub - s + Complex::new(0.0, EPSILON)) * s_tick.cos().powi(2))
|
||||||
}
|
}
|
||||||
@ -278,8 +296,8 @@ pub fn phi0_integrand(
|
|||||||
cutoff_factor: Complex,
|
cutoff_factor: Complex,
|
||||||
) -> f64 {
|
) -> f64 {
|
||||||
let sub = match (use_tan_phi0, use_xsub) {
|
let sub = match (use_tan_phi0, use_xsub) {
|
||||||
(true, true) => s_tick.tan().powi(2) + S0,
|
(true, true) => tan_with_lut(cache, s_tick).powi(2) + S0,
|
||||||
(true, false) => s_tick.tan(),
|
(true, false) => tan_with_lut(cache, s_tick),
|
||||||
(false, true) => s_tick.powi(2) + S0,
|
(false, true) => s_tick.powi(2) + S0,
|
||||||
(false, false) => s_tick,
|
(false, false) => s_tick,
|
||||||
};
|
};
|
||||||
|
@ -595,8 +595,9 @@ fn main() {
|
|||||||
// })
|
// })
|
||||||
// .collect();
|
// .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!("relative difference: {}", phi0 / calc::delta(10000.0) - 1.0);
|
||||||
|
println!("{:?}", app.calc_cache.tan_lut.len());
|
||||||
|
|
||||||
// eframe::run_native(
|
// eframe::run_native(
|
||||||
// "Omnes Calculator",
|
// "Omnes Calculator",
|
||||||
|
@ -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)
|
c = np.pi / (s * np.sqrt(s_0)) * np.log(cmath.polar(omnes(s))[0]**2)
|
||||||
|
|
||||||
if optimized == True:
|
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:
|
else:
|
||||||
integral = integral_gl(phi0_integrand, s, a, inf, n)
|
integral = integral_gl(phi0_integrand, s, a, inf, n)
|
||||||
return -s * np.sqrt(s-s_0) / (2*np.pi) * (integral - c)
|
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)
|
# print(time() - t0)
|
||||||
|
|
||||||
t0 = time()
|
t0 = time()
|
||||||
print(phi0(10000, n=100))
|
print(phi0(10000, n=15000) / delta(10000))
|
||||||
print(time() - t0)
|
print(time() - t0)
|
||||||
|
|
||||||
# ax.legend()
|
# ax.legend()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user