@@ -9,6 +9,7 @@ use super::import_subgrid::ImportSubgridV1;
99use super :: interp_subgrid:: InterpSubgridV1 ;
1010use super :: interpolation:: Interp ;
1111use super :: pids:: PidBasis ;
12+ use super :: reference:: Reference ;
1213use super :: subgrid:: { self , Subgrid , SubgridEnum } ;
1314use super :: v0;
1415use bitflags:: bitflags;
@@ -25,7 +26,6 @@ use std::io::{self, BufRead, BufReader, BufWriter, Read, Write};
2526use std:: ops:: Range ;
2627use std:: { iter, mem} ;
2728use thiserror:: Error ;
28- use super :: reference:: Reference ;
2929
3030const 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 (
0 commit comments