-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
996f1bc
commit 320e6a0
Showing
4 changed files
with
71 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Load configs and download index file | ||
use anyhow::Result; | ||
use partons::configs::Configs; | ||
|
||
fn main() -> Result<()> { | ||
let cfg = Configs::load()?; | ||
|
||
let mut source = cfg.sources[0].clone(); | ||
source.register_cache(cfg.data_path()?); | ||
let index = source.index()?; | ||
|
||
// display the first element, if non-empty | ||
for set in ["NNPDF40_nnlo_as_01180"] { | ||
//, "MSHT20nnlo_as118", "CT18NNLO"] { | ||
let header = index.get(set)?; | ||
let mut set = source.set(&header)?; | ||
println!("{set:#?}"); | ||
let grid0 = set.member(0)?; | ||
println!("{grid0}"); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,29 @@ | ||
//! Interpolation block | ||
use std::collections::HashMap; | ||
|
||
use anyhow::{anyhow, Result}; | ||
use ndarray::{Array1, Array3}; | ||
use anyhow::Result; | ||
use ndarray::{Array1, Array2}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct Block { | ||
pub pids: Array1<i32>, | ||
pub xgrid: Array1<f64>, | ||
pub mu2grid: Array1<f64>, | ||
pub(crate) values: Array3<f64>, | ||
pid_map: HashMap<i32, usize>, | ||
pub struct Block1 { | ||
pub coords: Array1<f64>, | ||
pub(crate) values: Array1<f64>, | ||
} | ||
|
||
impl Block { | ||
pub(crate) fn new( | ||
pids: Array1<i32>, | ||
xgrid: Array1<f64>, | ||
mu2grid: Array1<f64>, | ||
values: Array3<f64>, | ||
) -> Self { | ||
assert_eq!(values.shape(), &[pids.len(), xgrid.len(), mu2grid.len()]); | ||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct Block2 { | ||
pub coords: (Array1<f64>, Array1<f64>), | ||
pub(crate) values: Array2<f64>, | ||
} | ||
|
||
let pid_map = pids.iter().enumerate().map(|(i, v)| (*v, i)).collect(); | ||
impl Block2 { | ||
pub(crate) fn new(coords: (Array1<f64>, Array1<f64>), values: Array2<f64>) -> Self { | ||
assert_eq!(values.shape(), &[coords.0.len(), coords.1.len()]); | ||
|
||
Self { | ||
pids, | ||
xgrid, | ||
mu2grid, | ||
values, | ||
pid_map, | ||
} | ||
} | ||
|
||
pub(crate) fn pid_index(&self, pid: i32) -> Result<usize> { | ||
self.pid_map | ||
.get(&pid) | ||
.ok_or(anyhow!("PID '{}' not found", pid)) | ||
.map(|idx| *idx) | ||
Self { coords, values } | ||
} | ||
|
||
// TODO: delegate interpolation to ndinterp | ||
pub(crate) fn interp(&self, pid: i32, x: f64, mu2: f64) -> Result<f64> { | ||
// determine interpolation slice | ||
let slice = self.pid_index(pid)?; | ||
|
||
let idx = self | ||
.xgrid | ||
.iter() | ||
.enumerate() | ||
.filter(|(_, y)| y > &&x) | ||
.next() | ||
.unwrap() | ||
.0; | ||
let idmu = self | ||
.mu2grid | ||
.iter() | ||
.enumerate() | ||
.filter(|(_, nu2)| nu2 > &&mu2) | ||
.next() | ||
.unwrap() | ||
.0; | ||
|
||
return Ok(self.values[[slice, idx, idmu]]); | ||
pub(crate) fn interp(&self, x1: f64, x2: f64) -> Result<f64> { | ||
return Ok(self.values[[0, 0]]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters