Skip to content

Commit

Permalink
rust: Unify cmplx! macro call
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhekhorn committed Oct 11, 2024
1 parent d1b6c53 commit 7396c67
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,47 +63,47 @@ mod tests {

#[test]
fn number_conservation() {
const N: Complex<f64> = cmplx![1., 0.];
const N: Complex<f64> = cmplx!(1., 0.);
let mut c = Cache::new(N);
let me = gamma_ns(&mut c, NF);
assert_approx_eq_cmplx!(f64, me, Complex::zero(), epsilon = 1e-12);
}

#[test]
fn quark_momentum_conservation() {
const N: Complex<f64> = cmplx![2., 0.];
const N: Complex<f64> = cmplx!(2., 0.);
let mut c = Cache::new(N);
let me = gamma_ns(&mut c, NF) + gamma_gq(&mut c, NF);
assert_approx_eq_cmplx!(f64, me, Complex::zero(), epsilon = 1e-12);
}

#[test]
fn gluon_momentum_conservation() {
const N: Complex<f64> = cmplx![2., 0.];
const N: Complex<f64> = cmplx!(2., 0.);
let mut c = Cache::new(N);
let me = gamma_qg(&mut c, NF) + gamma_gg(&mut c, NF);
assert_approx_eq_cmplx!(f64, me, Complex::zero(), epsilon = 1e-12);
}

#[test]
fn gamma_qg_() {
const N: Complex<f64> = cmplx![1., 0.];
const N: Complex<f64> = cmplx!(1., 0.);
let mut c = Cache::new(N);
let me = gamma_qg(&mut c, NF);
assert_approx_eq_cmplx!(f64, me, cmplx!(-20. / 3., 0.), ulps = 32, epsilon = 1e-12);
}

#[test]
fn gamma_gq_() {
const N: Complex<f64> = cmplx![0., 1.];
const N: Complex<f64> = cmplx!(0., 1.);
let mut c = Cache::new(N);
let me = gamma_gq(&mut c, NF);
assert_approx_eq_cmplx!(f64, me, cmplx!(4. / 3.0, -4. / 3.0), ulps = 32);
}

#[test]
fn gamma_gg_() {
const N: Complex<f64> = cmplx![0., 1.];
const N: Complex<f64> = cmplx!(0., 1.);
let mut c = Cache::new(N);
let me = gamma_gg(&mut c, NF);
assert_approx_eq_cmplx!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub fn gamma_nsv(c: &mut Cache, nf: u8) -> Complex<f64> {
let B12 = -(S1 + 1.0 / (N + 1.0) + 1.0 / (N + 2.0)) / (N + 2.0);

let B1M = if N.im.abs() < 1.0e-5 && (N - 1.0).re.abs() < 1.0e-5 {
cmplx![-ZETA2, 0.]
cmplx!(-ZETA2, 0.)
} else {
-(S1 - 1.0 / N) / (N - 1.0)
};
Expand Down Expand Up @@ -435,7 +435,7 @@ mod tests {
#[test]
fn physical_constraints() {
// number conservation
let mut c = Cache::new(cmplx![1., 0.]);
let mut c = Cache::new(cmplx!(1., 0.));
assert_approx_eq_cmplx!(
f64,
gamma_nsv(&mut c, NF),
Expand All @@ -449,7 +449,7 @@ mod tests {
epsilon = 6e-7
);

let mut c = Cache::new(cmplx![2., 0.]);
let mut c = Cache::new(cmplx!(2., 0.));
let gS2 = gamma_singlet(&mut c, NF);
// gluon momentum conservation
assert_approx_eq_cmplx!(
Expand All @@ -469,7 +469,7 @@ mod tests {

#[test]
fn N2() {
let mut c = Cache::new(cmplx![2., 0.]);
let mut c = Cache::new(cmplx!(2., 0.));
assert_approx_eq_cmplx!(
f64,
gamma_nsv(&mut c, NF),
Expand Down
2 changes: 1 addition & 1 deletion crates/ekore/src/harmonics/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ mod tests {
#[test]
fn test_recursive_harmonic_sum() {
const SX: [fn(Complex<f64>) -> Complex<f64>; 4] = [w1::S1, w2::S2, w3::S3, w4::S4];
const NS: [Complex<f64>; 2] = [cmplx![1.0, 0.0], cmplx![2.34, 3.45]];
const NS: [Complex<f64>; 2] = [cmplx!(1.0, 0.0), cmplx!(2.34, 3.45)];
const ITERS: [usize; 2] = [1, 2];
for sit in SX.iter().enumerate() {
for nit in NS.iter().enumerate() {
Expand Down
10 changes: 5 additions & 5 deletions crates/ekore/src/harmonics/g_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ mod tests {

#[test]
fn test_mellin_g3() {
const NS: [Complex<f64>; 3] = [cmplx![1.0, 0.0], cmplx![2.0, 0.0], cmplx![1.0, 1.0]];
const NS: [Complex<f64>; 3] = [cmplx!(1.0, 0.0), cmplx!(2.0, 0.0), cmplx!(1.0, 1.0)];
// NIntegrate[x^({1, 2, 1 + I} - 1) PolyLog[2, x]/(1 + x), {x, 0, 1}]
const REFVALS: [Complex<f64>; 3] = [
cmplx![0.3888958462, 0.],
cmplx![0.2560382207, 0.],
cmplx![0.3049381491, -0.1589060625],
cmplx!(0.3888958462, 0.),
cmplx!(0.2560382207, 0.),
cmplx!(0.3049381491, -0.1589060625),
];
for it in NS.iter().enumerate() {
let n = *it.1;
let s1 = w1::S1(n);
let refval = REFVALS[it.0];
let g3 = g3(n, s1);
assert_approx_eq_cmplx![f64, g3, refval, epsilon = 1e-6];
assert_approx_eq_cmplx!(f64, g3, refval, epsilon = 1e-6);
}
}
}
108 changes: 54 additions & 54 deletions crates/ekore/src/harmonics/polygamma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,73 +127,73 @@ mod tests {
#[test]
fn fortran() {
const ZS: [Complex<f64>; 9] = [
cmplx![1.0, 0.],
cmplx![2.0, 0.],
cmplx![3.0, 0.],
cmplx![0., 1.],
cmplx![-1., 1.],
cmplx![-2., 1.],
cmplx![-1., 2.],
cmplx![-2., 2.],
cmplx![-3., 2.],
cmplx!(1.0, 0.),
cmplx!(2.0, 0.),
cmplx!(3.0, 0.),
cmplx!(0., 1.),
cmplx!(-1., 1.),
cmplx!(-2., 1.),
cmplx!(-1., 2.),
cmplx!(-2., 2.),
cmplx!(-3., 2.),
];
const KS: [usize; 5] = [0, 1, 2, 3, 4];

const FORTRAN_REF: [[Complex<f64>; 9]; 5] = [
[
cmplx![-0.5772156649015332, 0.],
cmplx![0.42278433509846636, 0.],
cmplx![0.9227843350984672, 0.],
cmplx![0.09465032062247669, 2.0766740474685816],
cmplx![0.5946503206224767, 2.5766740474685816],
cmplx![0.9946503206224772, 2.7766740474685814],
cmplx![0.9145915153739776, 2.2208072826422303],
cmplx![1.1645915153739772, 2.47080728264223],
cmplx![1.395360746143208, 2.624653436488384],
cmplx!(-0.5772156649015332, 0.),
cmplx!(0.42278433509846636, 0.),
cmplx!(0.9227843350984672, 0.),
cmplx!(0.09465032062247669, 2.0766740474685816),
cmplx!(0.5946503206224767, 2.5766740474685816),
cmplx!(0.9946503206224772, 2.7766740474685814),
cmplx!(0.9145915153739776, 2.2208072826422303),
cmplx!(1.1645915153739772, 2.47080728264223),
cmplx!(1.395360746143208, 2.624653436488384),
],
[
cmplx![1.6449340668482264, 0.],
cmplx![0.6449340668482264, 0.],
cmplx![0.3949340668482264, 0.],
cmplx![-0.5369999033772361, -0.7942335427593189],
cmplx![-0.5369999033772362, -0.2942335427593189],
cmplx![-0.4169999033772362, -0.13423354275931887],
cmplx![-0.24506883785905695, -0.3178255501472297],
cmplx![-0.24506883785905695, -0.19282555014722969],
cmplx![-0.21548303904248892, -0.12181963298746643],
cmplx!(1.6449340668482264, 0.),
cmplx!(0.6449340668482264, 0.),
cmplx!(0.3949340668482264, 0.),
cmplx!(-0.5369999033772361, -0.7942335427593189),
cmplx!(-0.5369999033772362, -0.2942335427593189),
cmplx!(-0.4169999033772362, -0.13423354275931887),
cmplx!(-0.24506883785905695, -0.3178255501472297),
cmplx!(-0.24506883785905695, -0.19282555014722969),
cmplx!(-0.21548303904248892, -0.12181963298746643),
],
[
cmplx![-2.404113806319188, 0.],
cmplx![-0.40411380631918853, 0.],
cmplx![-0.15411380631918858, 0.],
cmplx![0.3685529315879351, -1.233347149654934],
cmplx![-0.13144706841206477, -0.7333471496549337],
cmplx![-0.09944706841206462, -0.5573471496549336],
cmplx![0.03902435405364951, -0.15743252404131272],
cmplx![-0.02347564594635048, -0.09493252404131272],
cmplx![-0.031668636387861625, -0.053057239562477945],
cmplx!(-2.404113806319188, 0.),
cmplx!(-0.40411380631918853, 0.),
cmplx!(-0.15411380631918858, 0.),
cmplx!(0.3685529315879351, -1.233347149654934),
cmplx!(-0.13144706841206477, -0.7333471496549337),
cmplx!(-0.09944706841206462, -0.5573471496549336),
cmplx!(0.03902435405364951, -0.15743252404131272),
cmplx!(-0.02347564594635048, -0.09493252404131272),
cmplx!(-0.031668636387861625, -0.053057239562477945),
],
[
cmplx![6.49393940226683, 0.],
cmplx![0.49393940226682925, 0.],
cmplx![0.11893940226682913, 0.],
cmplx![4.4771255510465044, -0.31728657866196064],
cmplx![2.9771255510464925, -0.3172865786619599],
cmplx![2.909925551046492, -0.08688657866195917],
cmplx![0.12301766661068443, -0.05523068481179527],
cmplx![0.02926766661068438, -0.055230684811795216],
cmplx![0.004268541930176011, -0.03002148345329936],
cmplx!(6.49393940226683, 0.),
cmplx!(0.49393940226682925, 0.),
cmplx!(0.11893940226682913, 0.),
cmplx!(4.4771255510465044, -0.31728657866196064),
cmplx!(2.9771255510464925, -0.3172865786619599),
cmplx!(2.909925551046492, -0.08688657866195917),
cmplx!(0.12301766661068443, -0.05523068481179527),
cmplx!(0.02926766661068438, -0.055230684811795216),
cmplx!(0.004268541930176011, -0.03002148345329936),
],
[
cmplx![-24.88626612344089, 0.],
cmplx![-0.8862661234408784, 0.],
cmplx![-0.13626612344087824, 0.],
cmplx![3.2795081690440493, 21.41938794863803],
cmplx![0.2795081690440445, 18.419387948637894],
cmplx![-0.012331830955960252, 18.734267948637896],
cmplx![0.14223316576854003, 0.10023607930398608],
cmplx![0.04848316576854002, 0.006486079303986134],
cmplx![0.009893695996688708, 0.014372034600746361],
cmplx!(-24.88626612344089, 0.),
cmplx!(-0.8862661234408784, 0.),
cmplx!(-0.13626612344087824, 0.),
cmplx!(3.2795081690440493, 21.41938794863803),
cmplx!(0.2795081690440445, 18.419387948637894),
cmplx!(-0.012331830955960252, 18.734267948637896),
cmplx!(0.14223316576854003, 0.10023607930398608),
cmplx!(0.04848316576854002, 0.006486079303986134),
cmplx!(0.009893695996688708, 0.014372034600746361),
],
];
for kit in KS.iter().enumerate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn A_hg(c: &mut Cache, _nf: u8, L: f64) -> Complex<f64> {
///
/// Implements Eq. (B.6) of [\[Buza:1996wv\]](crate::bib::Buza1996wv).
pub fn A_gg(_c: &mut Cache, _nf: u8, L: f64) -> Complex<f64> {
cmplx![-2.0 / 3.0 * L, 0.]
cmplx!(-2.0 / 3.0 * L, 0.)
}

/// Compute the |NLO| singlet |OME|.
Expand Down Expand Up @@ -132,7 +132,7 @@ mod tests {
];

for n in 0..4 {
let N = cmplx![2. * (n as f64) + 2., 0.];
let N = cmplx!(2. * (n as f64) + 2., 0.);
let mut c = Cache::new(N);
let aS1 = A_singlet(&mut c, NF, L);
assert_approx_eq_cmplx!(f64, aS1[0][0], cmplx!(ref_val_gg[n], 0.), epsilon = 1e-6);
Expand Down

0 comments on commit 7396c67

Please sign in to comment.