Skip to content

Commit

Permalink
Refactor ConvolutionCache
Browse files Browse the repository at this point in the history
  • Loading branch information
cschwan committed Oct 22, 2024
1 parent a1fa114 commit 3a2372c
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 211 deletions.
42 changes: 28 additions & 14 deletions pineappl/src/boc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use float_cmp::approx_eq;
use itertools::Itertools;
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::cmp::Ordering;
use std::str::FromStr;
use thiserror::Error;
Expand Down Expand Up @@ -41,20 +42,27 @@ pub enum ScaleFuncForm {
impl ScaleFuncForm {
/// TODO
#[must_use]
pub fn calc(&self, node_values: &[Vec<f64>], kinematics: &[Kinematics]) -> Option<Vec<f64>> {
match self {
Self::NoScale => None,
&Self::Scale(index) => Some(if node_values.is_empty() {
// TODO: empty subgrid should have as many node values as dimensions
Vec::new()
} else {
node_values[kinematics
.iter()
.position(|&kin| kin == Kinematics::Scale(index))
// UNWRAP: this should be guaranteed by `Grid::new`
.unwrap()]
.clone()
}),
pub fn calc<'a>(
&self,
node_values: &'a [Vec<f64>],
kinematics: &[Kinematics],
) -> Cow<'a, [f64]> {
match self.clone() {
Self::NoScale => Cow::Borrowed(&[]),
Self::Scale(index) => {
if node_values.is_empty() {
// TODO: empty subgrid should have as many node values as dimensions
Cow::Borrowed(&[])
} else {
Cow::Borrowed(
&node_values[kinematics
.iter()
.position(|&kin| kin == Kinematics::Scale(index))
// UNWRAP: this should be guaranteed by `Grid::new`
.unwrap()],
)
}
}
Self::QuadraticSum(_, _) => todo!(),
}
}
Expand All @@ -71,6 +79,12 @@ pub struct Scales {
pub frg: ScaleFuncForm,
}

impl<'a> From<&'a Scales> for [&'a ScaleFuncForm; 3] {
fn from(scales: &'a Scales) -> [&'a ScaleFuncForm; 3] {
[&scales.ren, &scales.fac, &scales.frg]
}
}

impl Scales {
/// TODO
pub fn compatible_with(&self, kinematics: &[Kinematics]) -> bool {
Expand Down
Loading

0 comments on commit 3a2372c

Please sign in to comment.