Skip to content

Commit a9ce7d6

Browse files
committed
Run cargo fmt and cargo clippy
1 parent 551fe19 commit a9ce7d6

File tree

8 files changed

+93
-47
lines changed

8 files changed

+93
-47
lines changed

pineappl/src/boc.rs

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub enum Kinematics {
2626

2727
/// TODO
2828
#[repr(C)]
29-
#[derive(Clone, Deserialize, PartialEq, Serialize)]
29+
#[derive(Clone, Deserialize, Eq, PartialEq, Serialize)]
3030
pub enum ScaleFuncForm {
3131
/// TODO
3232
NoScale,
@@ -163,7 +163,7 @@ impl ScaleFuncForm {
163163
}
164164

165165
/// TODO
166-
#[derive(Clone, Deserialize, PartialEq, Serialize)]
166+
#[derive(Clone, Deserialize, Eq, PartialEq, Serialize)]
167167
pub struct Scales {
168168
/// TODO
169169
pub ren: ScaleFuncForm,
@@ -225,6 +225,7 @@ impl Bin {
225225
/// # Panics
226226
///
227227
/// TODO
228+
#[must_use]
228229
pub fn new(limits: Vec<(f64, f64)>, normalization: f64) -> Self {
229230
for limits in &limits {
230231
assert!(limits.1 >= limits.0);
@@ -237,21 +238,25 @@ impl Bin {
237238
}
238239

239240
/// TODO
241+
#[must_use]
240242
pub fn dimensions(&self) -> usize {
241243
self.limits.len()
242244
}
243245

244246
/// TODO
245-
pub fn normalization(&self) -> f64 {
247+
#[must_use]
248+
pub const fn normalization(&self) -> f64 {
246249
self.normalization
247250
}
248251

249252
/// TODO
253+
#[must_use]
250254
pub fn limits(&self) -> &[(f64, f64)] {
251255
&self.limits
252256
}
253257

254258
/// TODO
259+
#[must_use]
255260
pub fn partial_eq_with_ulps(&self, other: &Self, ulps: i64) -> bool {
256261
self.limits.iter().zip(other.limits()).all(|(&lhs, &rhs)| {
257262
approx_eq!(f64, lhs.0, rhs.0, ulps = ulps) && approx_eq!(f64, lhs.1, rhs.1, ulps = ulps)
@@ -267,6 +272,10 @@ pub struct BinsWithFillLimits {
267272
}
268273

269274
impl BinsWithFillLimits {
275+
/// TODO
276+
///
277+
/// # Errors
278+
///
270279
/// TODO
271280
pub fn new(bins: Vec<Bin>, fill_limits: Vec<f64>) -> Result<Self, ()> {
272281
// TODO: validate the bins
@@ -284,6 +293,10 @@ impl BinsWithFillLimits {
284293
Ok(Self { bins, fill_limits })
285294
}
286295

296+
/// TODO
297+
///
298+
/// # Errors
299+
///
287300
/// TODO
288301
pub fn from_fill_limits(fill_limits: Vec<f64>) -> Result<Self, ()> {
289302
let bins = fill_limits
@@ -294,6 +307,10 @@ impl BinsWithFillLimits {
294307
Self::new(bins, fill_limits)
295308
}
296309

310+
/// TODO
311+
///
312+
/// # Errors
313+
///
297314
/// TODO
298315
///
299316
/// # Panics
@@ -338,16 +355,19 @@ impl BinsWithFillLimits {
338355
}
339356

340357
/// TODO
358+
#[must_use]
341359
pub fn bins(&self) -> &[Bin] {
342360
&self.bins
343361
}
344362

345363
/// TODO
364+
#[must_use]
346365
pub fn len(&self) -> usize {
347366
self.bins.len()
348367
}
349368

350369
/// TODO
370+
#[must_use]
351371
pub fn dimensions(&self) -> usize {
352372
self.bins
353373
.first()
@@ -357,6 +377,7 @@ impl BinsWithFillLimits {
357377
}
358378

359379
/// TODO
380+
#[must_use]
360381
pub fn fill_index(&self, value: f64) -> Option<usize> {
361382
match self
362383
.fill_limits
@@ -371,6 +392,7 @@ impl BinsWithFillLimits {
371392
}
372393

373394
/// TODO
395+
#[must_use]
374396
pub fn fill_limits(&self) -> &[f64] {
375397
&self.fill_limits
376398
}
@@ -380,6 +402,10 @@ impl BinsWithFillLimits {
380402
self.bins.iter().map(Bin::normalization).collect()
381403
}
382404

405+
/// TODO
406+
///
407+
/// # Errors
408+
///
383409
/// TODO
384410
pub fn subset(&self, range: impl RangeBounds<usize>) -> Result<Self, ()> {
385411
let range_plus_one = (
@@ -417,6 +443,10 @@ impl BinsWithFillLimits {
417443
)
418444
}
419445

446+
/// TODO
447+
///
448+
/// # Errors
449+
///
420450
/// TODO
421451
// TODO: change range to `RangeBounds<usize>`
422452
pub fn merge(&self, range: Range<usize>) -> Result<Self, ()> {
@@ -435,11 +465,7 @@ impl BinsWithFillLimits {
435465
let mut fill_limits = self.fill_limits.clone();
436466
let dim = self.dimensions();
437467

438-
limits [range.start]
439-
[dim - 1]
440-
.1 = limits [range.end - 1]
441-
[dim - 1]
442-
.1;
468+
limits[range.start][dim - 1].1 = limits[range.end - 1][dim - 1].1;
443469
normalizations[range.start] += normalizations[range.start + 1..range.end]
444470
.iter()
445471
.sum::<f64>();
@@ -458,17 +484,20 @@ impl BinsWithFillLimits {
458484
)
459485
}
460486

487+
/// TODO
488+
///
489+
/// # Panics
490+
///
461491
/// TODO
462492
pub fn remove(&mut self, index: usize) -> Bin {
463-
if self.len() == 1 {
464-
panic!("TODO");
465-
}
493+
assert!(self.len() > 1);
466494

467495
self.fill_limits.pop().unwrap();
468496
self.bins.remove(index)
469497
}
470498

471499
/// TODO
500+
#[must_use]
472501
pub fn bins_partial_eq_with_ulps(&self, other: &Self, ulps: i64) -> bool {
473502
self.bins
474503
.iter()
@@ -623,10 +652,9 @@ impl FromStr for BinsWithFillLimits {
623652
normalizations.push(normalization);
624653
}
625654

626-
Ok(BinsWithFillLimits::from_limits_and_normalizations(limits, normalizations)
627-
// TODO: implement proper error handling
628-
.unwrap()
629-
)
655+
Ok(Self::from_limits_and_normalizations(limits, normalizations)
656+
// TODO: implement proper error handling
657+
.unwrap())
630658
}
631659
}
632660

pineappl/src/convolutions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ impl ConvType {
307307
}
308308

309309
/// TODO
310+
#[must_use]
310311
pub const fn is_pdf(&self) -> bool {
311312
matches!(self, Self::UnpolPDF | Self::PolPDF)
312313
}

pineappl/src/evolution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub struct OperatorSliceInfo {
6666
/// Particle ID basis for `FkTable`.
6767
pub pid_basis: PidBasis,
6868
/// Type of convolution which this operator evolves. This also determines whether [`fac0`]
69-
/// and ['fac1`] is a factorization ([`ConvType::UnpolPDF`] or [`ConvType::PolPDF`]) or a
69+
/// and [`fac1`] is a factorization ([`ConvType::UnpolPDF`] or [`ConvType::PolPDF`]) or a
7070
/// fragmentation ([`ConvType::UnpolFF`] or [`ConvType::PolFF`]) scale.
7171
pub conv_type: ConvType,
7272
}

pineappl/src/grid.rs

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use super::import_subgrid::ImportSubgridV1;
99
use super::interp_subgrid::InterpSubgridV1;
1010
use super::interpolation::Interp;
1111
use super::pids::PidBasis;
12+
use super::reference::Reference;
1213
use super::subgrid::{self, Subgrid, SubgridEnum};
1314
use super::v0;
1415
use bitflags::bitflags;
@@ -25,7 +26,6 @@ use std::io::{self, BufRead, BufReader, BufWriter, Read, Write};
2526
use std::ops::Range;
2627
use std::{iter, mem};
2728
use thiserror::Error;
28-
use super::reference::Reference;
2929

3030
const BIN_AXIS: Axis = Axis(1);
3131

@@ -502,7 +502,11 @@ impl Grid {
502502
/// When the given bins are non-consecutive, an error is returned.
503503
pub fn merge_bins(&mut self, range: Range<usize>) -> Result<(), GridError> {
504504
// check if the bins in `range` can be merged - if not return without changing `self`
505-
self.bwfl = self.bwfl().merge(range.clone()).unwrap();
505+
self.bwfl = self
506+
.bwfl()
507+
.merge(range.clone())
508+
// TODO: use proper error handling
509+
.unwrap_or_else(|_| unreachable!());
506510

507511
let (intermediate, right) = self.subgrids.view().split_at(BIN_AXIS, range.end);
508512
let (left, merge) = intermediate.split_at(BIN_AXIS, range.start);
@@ -522,7 +526,7 @@ impl Grid {
522526

523527
self.subgrids = ndarray::concatenate(BIN_AXIS, &[left, merged.view(), right])
524528
// UNWRAP: if this fails there's a bug
525-
.unwrap();
529+
.unwrap_or_else(|_| unreachable!());
526530

527531
Ok(())
528532
}
@@ -594,7 +598,7 @@ impl Grid {
594598
.collect(),
595599
)
596600
// TODO: do proper error handling
597-
.unwrap();
601+
.unwrap_or_else(|_| unreachable!());
598602
self.bwfl = new_bwfl;
599603
}
600604

@@ -668,9 +672,19 @@ impl Grid {
668672
let other_order = &other.orders[i];
669673
let other_entry = &other.channels[k];
670674

671-
let self_i = self.orders.iter().position(|x| x == other_order).unwrap();
675+
let self_i = self
676+
.orders
677+
.iter()
678+
.position(|x| x == other_order)
679+
// UNWRAP: we added the orders previously so we must find it
680+
.unwrap_or_else(|| unreachable!());
672681
let self_j = bin_indices[j];
673-
let self_k = self.channels.iter().position(|y| y == other_entry).unwrap();
682+
let self_k = self
683+
.channels
684+
.iter()
685+
.position(|y| y == other_entry)
686+
// UNWRAP: we added the channels previously so we must find it
687+
.unwrap_or_else(|| unreachable!());
674688

675689
if self.subgrids[[self_i, self_j, self_k]].is_empty() {
676690
mem::swap(&mut self.subgrids[[self_i, self_j, self_k]], subgrid);
@@ -798,6 +812,10 @@ impl Grid {
798812
self.subgrids.view_mut()
799813
}
800814

815+
/// TODO
816+
///
817+
/// # Errors
818+
///
801819
/// TODO
802820
pub fn set_bwfl(&mut self, bwfl: BinsWithFillLimits) -> Result<(), GridError> {
803821
if bwfl.len() != self.bwfl().len() {
@@ -814,7 +832,8 @@ impl Grid {
814832
}
815833

816834
/// TODO
817-
pub fn bwfl(&self) -> &BinsWithFillLimits {
835+
#[must_use]
836+
pub const fn bwfl(&self) -> &BinsWithFillLimits {
818837
&self.bwfl
819838
}
820839

@@ -1252,12 +1271,10 @@ impl Grid {
12521271
} else {
12531272
assert_approx_eq!(f64, fac0, info_0.fac0, ulps = 8);
12541273
}
1274+
} else if frg0 < 0.0 {
1275+
frg0 = info_0.fac0;
12551276
} else {
1256-
if frg0 < 0.0 {
1257-
frg0 = info_0.fac0;
1258-
} else {
1259-
assert_approx_eq!(f64, frg0, info_0.fac0, ulps = 8);
1260-
}
1277+
assert_approx_eq!(f64, frg0, info_0.fac0, ulps = 8);
12611278
}
12621279

12631280
for (index, info) in infos_rest.iter().enumerate() {
@@ -1287,12 +1304,10 @@ impl Grid {
12871304
} else {
12881305
assert_approx_eq!(f64, fac0, info.fac0, ulps = 8);
12891306
}
1307+
} else if frg0 < 0.0 {
1308+
frg0 = info.fac0;
12901309
} else {
1291-
if frg0 < 0.0 {
1292-
frg0 = info.fac0;
1293-
} else {
1294-
assert_approx_eq!(f64, frg0, info.fac0, ulps = 8);
1295-
}
1310+
assert_approx_eq!(f64, frg0, info.fac0, ulps = 8);
12961311
}
12971312
}
12981313

@@ -1352,12 +1367,10 @@ impl Grid {
13521367
};
13531368
let (frg, scale_values) = if frg0 < 0.0 {
13541369
(ScaleFuncForm::NoScale, vec![fac0])
1370+
} else if fac0 < 0.0 || approx_eq!(f64, fac0, frg0, ulps = 8) {
1371+
(ScaleFuncForm::Scale(0), vec![frg0])
13551372
} else {
1356-
if fac0 < 0.0 || approx_eq!(f64, fac0, frg0, ulps = 8) {
1357-
(ScaleFuncForm::Scale(0), vec![frg0])
1358-
} else {
1359-
(ScaleFuncForm::Scale(1), vec![fac0, frg0])
1360-
}
1373+
(ScaleFuncForm::Scale(1), vec![fac0, frg0])
13611374
};
13621375

13631376
let (subgrids, channels) = evolution::evolve_slice_with_many(

pineappl/src/interpolation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn lagrange_weights(i: usize, n: usize, u: f64) -> f64 {
6262

6363
/// TODO
6464
#[repr(C)]
65-
#[derive(Clone, Copy, Deserialize, PartialEq, Serialize)]
65+
#[derive(Clone, Copy, Deserialize, Eq, PartialEq, Serialize)]
6666
pub enum ReweightMeth {
6767
/// TODO
6868
ApplGridX,
@@ -72,7 +72,7 @@ pub enum ReweightMeth {
7272

7373
/// TODO
7474
#[repr(C)]
75-
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
75+
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
7676
pub enum Map {
7777
/// TODO
7878
ApplGridF2,
@@ -82,7 +82,7 @@ pub enum Map {
8282

8383
/// TODO
8484
#[repr(C)]
85-
#[derive(Clone, Copy, Deserialize, PartialEq, Serialize)]
85+
#[derive(Clone, Copy, Deserialize, Eq, PartialEq, Serialize)]
8686
pub enum InterpMeth {
8787
/// TODO
8888
Lagrange,

pineappl/src/subgrid.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,18 @@ pub enum SubgridEnum {
3535

3636
impl SubgridEnum {
3737
/// TODO
38-
pub fn merge(&mut self, other: &SubgridEnum, transpose: Option<(usize, usize)>) {
38+
pub fn merge(&mut self, other: &Self, transpose: Option<(usize, usize)>) {
3939
if other.is_empty() {
4040
return;
4141
}
42-
if let SubgridEnum::EmptySubgridV1(_) = self {
43-
if transpose.is_none() {*self = other.clone();} else {todo!();}
42+
if let Self::EmptySubgridV1(_) = self {
43+
if transpose.is_none() {
44+
*self = other.clone();
45+
} else {
46+
todo!();
47+
}
4448
} else {
45-
self.merge_impl(other, transpose);
49+
self.merge_impl(other, transpose);
4650
}
4751
}
4852
}

0 commit comments

Comments
 (0)