Skip to content

Commit

Permalink
rust: Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhekhorn committed May 22, 2024
1 parent 5ea1440 commit 0518475
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
28 changes: 18 additions & 10 deletions crates/eko/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
//! Interface to the eko Python package.
use ekore;
use ekore::harmonics::cache::Cache;
use std::ffi::c_void;

mod mellin;

/// QCD intergration kernel inside quad.
///
/// # Safety
/// This is the connection from Python, so we don't know what is on the other side.
#[no_mangle]
pub unsafe extern "C" fn rust_quad_ker_qcd(u: f64, rargs: *mut c_void) -> f64 {
let args = *(rargs as *mut QuadQCDargs);
Expand All @@ -23,11 +25,11 @@ pub unsafe extern "C" fn rust_quad_ker_qcd(u: f64, rargs: *mut c_void) -> f64 {
&mut c,
args.nf,
);
for k in 0..args.order_qcd {
for l in 0..2 {
for m in 0..2 {
re.push(res[k][l][m].re);
im.push(res[k][l][m].im);
for gamma_s in res.iter().take(args.order_qcd) {
for col in gamma_s.iter().take(2) {
for el in col.iter().take(2) {
re.push(el.re);
im.push(el.im);
}
}
}
Expand All @@ -38,9 +40,9 @@ pub unsafe extern "C" fn rust_quad_ker_qcd(u: f64, rargs: *mut c_void) -> f64 {
&mut c,
args.nf,
);
for j in 0..args.order_qcd {
re.push(res[j].re);
im.push(res[j].im);
for el in res.iter().take(args.order_qcd) {
re.push(el.re);
im.push(el.im);
}
}
// pass on
Expand Down Expand Up @@ -127,7 +129,10 @@ pub struct QuadQCDargs {
pub is_threshold: bool,
}

/// empty placeholder function for python callback
/// Empty placeholder function for python callback.
///
/// # Safety
/// This is the connection back to Python, so we don't know what is on the other side.
pub unsafe extern "C" fn my_py(
_re_gamma: *const f64,
_im_gamma: *const f64,
Expand Down Expand Up @@ -161,6 +166,9 @@ pub unsafe extern "C" fn my_py(
///
/// This is required to make the arguments part of the API, otherwise it won't be added to the compiled
/// package (since it does not appear in the signature of `quad_ker_qcd`).
///
/// # Safety
/// This is the connection from and back to Python, so we don't know what is on the other side.
#[no_mangle]
pub unsafe extern "C" fn empty_qcd_args() -> QuadQCDargs {
QuadQCDargs {
Expand Down
4 changes: 2 additions & 2 deletions crates/ekore/src/harmonics/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ impl Cache {
pub fn get(&mut self, k: K) -> Complex<f64> {
let val = self.m.get(&k);
// already there?
if val.is_some() {
return *val.unwrap();
if let Some(value) = val {
return *value;
}
// compute new
let val = match k {
Expand Down
1 change: 1 addition & 0 deletions crates/ekore/src/harmonics/polygamma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use num::{complex::Complex, Zero};
use std::f64::consts::PI;

#[allow(clippy::excessive_precision, clippy::assign_op_pattern)]
/// Compute the polygamma functions $\psi_k(z)$.
///
/// Reimplementation of ``WPSIPG`` (C317) in [CERNlib](http://cernlib.web.cern.ch/cernlib/) given by [[KOLBIG1972221]][crate::bib::KOLBIG1972221].
Expand Down
2 changes: 1 addition & 1 deletion crates/ekore/src/harmonics/w1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ use crate::harmonics::polygamma::cern_polygamma;
/// $$S_1(N) = \sum\limits_{j=1}^N \frac 1 j = \psi_0(N+1)+\gamma_E$$
/// with $\psi_0(N)$ the digamma function and $\gamma_E$ the Euler-Mascheroni constant.
pub fn S1(N: Complex<f64>) -> Complex<f64> {
cern_polygamma(N + 1.0, 0) + 0.5772156649015328606065120
cern_polygamma(N + 1.0, 0) + 0.577_215_664_901_532_9
}

0 comments on commit 0518475

Please sign in to comment.