Skip to content

Commit

Permalink
Change argument type of PackedArray's constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
cschwan committed Sep 18, 2024
1 parent 3fac121 commit 3efc12b
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 32 deletions.
6 changes: 3 additions & 3 deletions pineappl/src/interpolation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ mod tests {
assert_approx_eq!(f64, node, ref_node, ulps = 4);
}

let mut array = crate::packed_array::PackedArray::<f64>::new(&[40, 50, 50]);
let mut array = crate::packed_array::PackedArray::<f64>::new(vec![40, 50, 50]);
let ntuples = [[100000.0, 0.25, 0.5], [1000.0, 0.5, 0.5]];
let weight = 1.0;

Expand Down Expand Up @@ -637,7 +637,7 @@ mod tests {
InterpMeth::Lagrange,
),
];
let mut array = crate::packed_array::PackedArray::<f64>::new(&[40, 50, 50]);
let mut array = crate::packed_array::PackedArray::<f64>::new(vec![40, 50, 50]);

let ntuple = [1000.0, 0.5, 0.5];
let weight = 0.0;
Expand Down Expand Up @@ -667,7 +667,7 @@ mod tests {
Map::ApplGridH0,
InterpMeth::Lagrange,
)];
let mut array = crate::packed_array::PackedArray::<f64>::new(&[1]);
let mut array = crate::packed_array::PackedArray::<f64>::new(vec![1]);

let ntuple = [90.0_f64.powi(2)];
let weight = 1.0;
Expand Down
4 changes: 2 additions & 2 deletions pineappl/src/lagrange_subgrid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl LagrangeSubgridV2 {
#[must_use]
pub fn new(interps: &[Interp]) -> Self {
Self {
array: PackedArray::new(&interps.iter().map(Interp::nodes).collect::<Vec<_>>()),
array: PackedArray::new(interps.iter().map(Interp::nodes).collect()),
interps: interps.to_vec(),
static_q2: 0.0,
}
Expand Down Expand Up @@ -91,7 +91,7 @@ impl Subgrid for LagrangeSubgridV2 {
}

fn symmetrize(&mut self, a: usize, b: usize) {
let mut new_array = PackedArray::new(self.array.shape());
let mut new_array = PackedArray::new(self.array.shape().to_vec());

for (mut index, sigma) in self.array.indexed_iter3() {
// TODO: why not the other way around?
Expand Down
32 changes: 16 additions & 16 deletions pineappl/src/packed_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ pub struct PackedArray<T> {
impl<T: Copy + Default + PartialEq> PackedArray<T> {
/// Constructs a new and empty `PackedArray` of shape `shape`.
#[must_use]
pub fn new(shape: &[usize]) -> Self {
pub fn new(shape: Vec<usize>) -> Self {
Self {
entries: vec![],
start_indices: vec![],
lengths: vec![],
shape: shape.to_vec(),
shape,
}
}

Expand Down Expand Up @@ -158,7 +158,7 @@ impl<T: Copy + Default + PartialEq> PackedArray<T> {
pub fn from_ndarray(array: ArrayView3<T>, xstart: usize, xsize: usize) -> Self {
let shape = array.shape();

let mut result = Self::new(&[xsize, shape[1], shape[2]]);
let mut result = Self::new(vec![xsize, shape[1], shape[2]]);

for ((i, j, k), &entry) in array
.indexed_iter()
Expand Down Expand Up @@ -556,7 +556,7 @@ mod tests {

#[test]
fn index() {
let mut a = PackedArray::new(&[4, 2]);
let mut a = PackedArray::new(vec![4, 2]);

a[[0, 0]] = 1;
assert_eq!(a[[0, 0]], 1);
Expand Down Expand Up @@ -610,7 +610,7 @@ mod tests {

#[test]
fn iter() {
let mut a = PackedArray::new(&[6, 5]);
let mut a = PackedArray::new(vec![6, 5]);
a[[2, 2]] = 1;
a[[2, 4]] = 2;
a[[4, 1]] = 3;
Expand All @@ -630,7 +630,7 @@ mod tests {

#[test]
fn index_access() {
let mut array = PackedArray::new(&[40, 50, 50]);
let mut array = PackedArray::new(vec![40, 50, 50]);

// after creation the array must be empty
assert_eq!(array.overhead(), 0);
Expand Down Expand Up @@ -775,31 +775,31 @@ mod tests {
#[test]
#[should_panic(expected = "index [40, 0, 50] is out of bounds for array of shape [40, 50, 50]")]
fn index_mut_panic_dim0() {
let mut array = PackedArray::new(&[40, 50, 50]);
let mut array = PackedArray::new(vec![40, 50, 50]);

array[[40, 0, 50]] = 1.0;
}

#[test]
#[should_panic(expected = "index [0, 50, 0] is out of bounds for array of shape [40, 50, 50]")]
fn index_mut_panic_dim1() {
let mut array = PackedArray::new(&[40, 50, 50]);
let mut array = PackedArray::new(vec![40, 50, 50]);

array[[0, 50, 0]] = 1.0;
}

#[test]
#[should_panic(expected = "index [0, 0, 50] is out of bounds for array of shape [40, 50, 50]")]
fn index_mut_panic_dim2() {
let mut array = PackedArray::new(&[40, 50, 50]);
let mut array = PackedArray::new(vec![40, 50, 50]);

array[[0, 0, 50]] = 1.0;
}

#[test]
#[should_panic(expected = "entry at index [0, 0, 0] is implicitly set to the default value")]
fn index_panic_dim0_0() {
let mut array = PackedArray::new(&[40, 50, 50]);
let mut array = PackedArray::new(vec![40, 50, 50]);

array[[1, 0, 0]] = 1;

Expand All @@ -809,7 +809,7 @@ mod tests {
#[test]
#[should_panic(expected = "entry at index [2, 0, 0] is implicitly set to the default value")]
fn index_panic_dim0_1() {
let mut array = PackedArray::new(&[40, 50, 50]);
let mut array = PackedArray::new(vec![40, 50, 50]);

array[[1, 0, 0]] = 1;

Expand All @@ -819,7 +819,7 @@ mod tests {
#[test]
#[should_panic(expected = "index [1, 50, 0] is out of bounds for array of shape [40, 50, 50]")]
fn index_panic_dim1() {
let mut array = PackedArray::new(&[40, 50, 50]);
let mut array = PackedArray::new(vec![40, 50, 50]);

array[[1, 0, 0]] = 1;

Expand All @@ -829,7 +829,7 @@ mod tests {
#[test]
#[should_panic(expected = "entry at index [0, 0, 0] is implicitly set to the default value")]
fn index_panic_dim2_0() {
let mut array = PackedArray::new(&[40, 50, 50]);
let mut array = PackedArray::new(vec![40, 50, 50]);

array[[0, 0, 1]] = 1;

Expand All @@ -839,7 +839,7 @@ mod tests {
#[test]
#[should_panic(expected = "entry at index [0, 0, 2] is implicitly set to the default value")]
fn index_panic_dim2_1() {
let mut array = PackedArray::new(&[40, 50, 50]);
let mut array = PackedArray::new(vec![40, 50, 50]);

array[[0, 0, 1]] = 1;

Expand All @@ -848,7 +848,7 @@ mod tests {

#[test]
fn indexed_iter() {
let mut array = PackedArray::new(&[40, 50, 50]);
let mut array = PackedArray::new(vec![40, 50, 50]);

// check shape
assert_eq!(array.shape(), [40, 50, 50]);
Expand Down Expand Up @@ -904,7 +904,7 @@ mod tests {

#[test]
fn clear() {
let mut array = PackedArray::new(&[40, 50, 50]);
let mut array = PackedArray::new(vec![40, 50, 50]);

array[[3, 5, 1]] = 1;
array[[7, 8, 9]] = 2;
Expand Down
10 changes: 5 additions & 5 deletions pineappl/src/packed_subgrid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl Subgrid for PackedQ1X2SubgridV1 {
}

fn symmetrize(&mut self, a: usize, b: usize) {
let mut new_array = PackedArray::new(self.array.shape());
let mut new_array = PackedArray::new(self.array.shape().to_vec());

for (mut index, sigma) in self.array.indexed_iter3() {
// TODO: why not the other way around?
Expand Down Expand Up @@ -231,7 +231,7 @@ impl From<&SubgridEnum> for PackedQ1X2SubgridV1 {
let x1_grid = subgrid.x1_grid()[x1_range.clone()].to_vec();
let x2_grid = subgrid.x2_grid()[x2_range.clone()].to_vec();

let mut array = PackedArray::new(&[mu2_grid.len(), x1_grid.len(), x2_grid.len()]);
let mut array = PackedArray::new(vec![mu2_grid.len(), x1_grid.len(), x2_grid.len()]);

for (indices, value) in subgrid.indexed_iter() {
// if there's a static scale we want every value to be added to same grid point
Expand Down Expand Up @@ -266,7 +266,7 @@ mod tests {
#[should_panic(expected = "PackedQ1X2SubgridV1 doesn't support the fill operation")]
fn fill_packed_q1x2_subgrid_v1() {
let mut subgrid = PackedQ1X2SubgridV1::new(
PackedArray::new(&[0, 0, 0]),
PackedArray::new(vec![0, 0, 0]),
Vec::new(),
Vec::new(),
Vec::new(),
Expand All @@ -280,7 +280,7 @@ mod tests {
0.015625, 0.03125, 0.0625, 0.125, 0.1875, 0.25, 0.375, 0.5, 0.75, 1.0,
];
let mut grid1: SubgridEnum = PackedQ1X2SubgridV1::new(
PackedArray::new(&[1, 10, 10]),
PackedArray::new(vec![1, 10, 10]),
vec![Mu2 {
ren: 0.0,
fac: 0.0,
Expand Down Expand Up @@ -320,7 +320,7 @@ mod tests {

// create grid with transposed entries, but different q2
let mut grid2: SubgridEnum = PackedQ1X2SubgridV1::new(
PackedArray::new(&[1, 10, 10]),
PackedArray::new(vec![1, 10, 10]),
vec![Mu2 {
ren: 1.0,
fac: 1.0,
Expand Down
2 changes: 1 addition & 1 deletion pineappl/src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn read_uncompressed_v0(mut reader: impl BufRead) -> Result<Grid, GridError>
let x1_grid = subgrid.x1_grid().into_owned();
let x2_grid = subgrid.x2_grid().into_owned();
let mut array =
PackedArray::new(&[mu2_grid.len(), x1_grid.len(), x2_grid.len()]);
PackedArray::new(vec![mu2_grid.len(), x1_grid.len(), x2_grid.len()]);
for (index, v) in subgrid.indexed_iter() {
array[<[usize; 3]>::from(index)] = v;
}
Expand Down
2 changes: 1 addition & 1 deletion pineappl_cli/src/import/applgrid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ pub fn convert_applgrid(grid: Pin<&mut grid>, alpha: u32, dis_pid: i32) -> Resul
let matrix = unsafe { &*matrix };

let mut array =
PackedArray::new(&[mu2_values.len(), x1_values.len(), x2_values.len()]);
PackedArray::new(vec![mu2_values.len(), x1_values.len(), x2_values.len()]);

for itau in 0..mu2_values.len() {
for ix1 in 0..x1_values.len() {
Expand Down
4 changes: 2 additions & 2 deletions pineappl_cli/src/import/fastnlo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ fn convert_coeff_add_fix(
.collect();

let mut array =
PackedArray::new(&[mu2_values.len(), x1_values.len(), x2_values.len()]);
PackedArray::new(vec![mu2_values.len(), x1_values.len(), x2_values.len()]);

// TODO: figure out what the general case is supposed to be
assert_eq!(j, 0);
Expand Down Expand Up @@ -370,7 +370,7 @@ fn convert_coeff_add_flex(
let factor = rescale / table_as_add_base.GetNevt(obs.try_into().unwrap(), subproc);
let mut arrays =
vec![
PackedArray::new(&[mu2_values.len(), x1_values.len(), x2_values.len()]);
PackedArray::new(vec![mu2_values.len(), x1_values.len(), x2_values.len()]);
orders_len
];

Expand Down
4 changes: 2 additions & 2 deletions pineappl_cli/src/import/fktable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fn read_fktable(reader: impl BufRead, dis_pid: i32) -> Result<Grid> {

grid = Some(fktable);

arrays = iter::repeat(PackedArray::new(&[1, nx1, nx2]))
arrays = iter::repeat(PackedArray::new(vec![1, nx1, nx2]))
.take(flavor_mask.iter().filter(|&&value| value).count())
.collect();
}
Expand Down Expand Up @@ -225,7 +225,7 @@ fn read_fktable(reader: impl BufRead, dis_pid: i32) -> Result<Grid> {
.into();
}

arrays = iter::repeat(PackedArray::new(&[1, nx1, nx2]))
arrays = iter::repeat(PackedArray::new(vec![1, nx1, nx2]))
.take(flavor_mask.iter().filter(|&&value| value).count())
.collect();
last_bin = bin;
Expand Down

0 comments on commit 3efc12b

Please sign in to comment.