Skip to content

Commit

Permalink
rust: Expose g3
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhekhorn committed May 15, 2024
1 parent 003292a commit b0694d5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
5 changes: 4 additions & 1 deletion crates/ekore/src/harmonics/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use hashbrown::HashMap;
use num::{complex::Complex, Zero};

use crate::harmonics::{w1, w2, w3};
use crate::harmonics::{g_functions, w1, w2, w3};

#[cfg_attr(doc, katexit::katexit)]
/// List of available elements.
Expand All @@ -25,6 +25,8 @@ pub enum K {
S2mh,
/// $S_3((N-1)/2)$
S3mh,
/// $g_3(N)$
G3,
}

/// Hold all cached values.
Expand Down Expand Up @@ -61,6 +63,7 @@ impl Cache {
K::S1mh => w1::S1((self.n - 1.) / 2.),
K::S2mh => w2::S2((self.n - 1.) / 2.),
K::S3mh => w3::S3((self.n - 1.) / 2.),
K::G3 => g_functions::g3(self.n, self.get(K::S1)),
};
// insert
self.m.insert(k, val);
Expand Down
8 changes: 5 additions & 3 deletions crates/ekore/src/harmonics/g_functions.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Auxilary functions for harmonics sums of weight = 3,4.
use crate::constants::ZETA2;
use crate::harmonics::cache::recursive_harmonic_sum as s;
use num::{complex::Complex, Zero};
Expand All @@ -10,7 +12,7 @@ use num::{complex::Complex, Zero};
///
/// We use the name from [[MuselliPhD]][crate::bib::MuselliPhD], but not his implementation - rather we use the
/// Pegasus [[Vogt:2004ns]][crate::bib::Vogt2004ns] implementation.
pub fn mellin_g3(N: Complex<f64>, S1: Complex<f64>) -> Complex<f64> {
pub fn g3(N: Complex<f64>, S1: Complex<f64>) -> Complex<f64> {
const CS: [f64; 7] = [
1.0000e0, -0.9992e0, 0.9851e0, -0.9005e0, 0.6621e0, -0.3174e0, 0.0699e0,
];
Expand All @@ -24,7 +26,7 @@ pub fn mellin_g3(N: Complex<f64>, S1: Complex<f64>) -> Complex<f64> {

#[cfg(test)]
mod tests {
use crate::harmonics::g_functions::mellin_g3;
use crate::harmonics::g_functions::g3;
use crate::harmonics::w1;
use crate::{assert_approx_eq_cmplx, cmplx};
use num::complex::Complex;
Expand All @@ -42,7 +44,7 @@ mod tests {
let n = *it.1;
let s1 = w1::S1(n);
let refval = REFVALS[it.0];
let g3 = mellin_g3(n, s1);
let g3 = g3(n, s1);
assert_approx_eq_cmplx![f64, g3, refval, epsilon = 1e-6];
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/ekore/src/harmonics/w1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Harmonic sums of weight 1.
use num::complex::Complex;

use crate::harmonics::polygamma::cern_polygamma;
Expand Down
1 change: 1 addition & 0 deletions crates/ekore/src/harmonics/w2.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Harmonic sums of weight 2.
use num::complex::Complex;

use crate::constants::ZETA2;
Expand Down
1 change: 1 addition & 0 deletions crates/ekore/src/harmonics/w3.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Harmonic sums of weight 3.
use num::complex::Complex;

use crate::constants::ZETA3;
Expand Down

0 comments on commit b0694d5

Please sign in to comment.