File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1087,21 +1087,34 @@ impl Channel {
10871087 } )
10881088 }
10891089
1090+ /// Finds the factor with the smallest absolute value in the channel and
1091+ /// divides all coefficients by this value.
1092+ ///
1093+ /// # Returns
1094+ ///
1095+ /// A tuple containing:
1096+ /// - the factored-out coefficient
1097+ /// - a new `Channel` with all coefficients divided by the factored value
1098+ ///
1099+ /// # Panics
1100+ ///
10901101 /// TODO
1102+ #[ must_use]
10911103 pub fn factor ( & self ) -> ( f64 , Self ) {
10921104 let factor = self
10931105 . entry
10941106 . iter ( )
1095- . map ( |( _, f) | f . abs ( ) )
1107+ . map ( |( _, f) | * f )
10961108 . min_by ( |a, b| {
1097- a. partial_cmp ( b)
1109+ a. abs ( )
1110+ . partial_cmp ( & b. abs ( ) )
10981111 // UNWRAP: if we can't compare the numbers the data structure is bugged
10991112 . unwrap ( )
11001113 } )
11011114 // UNWRAP: every `Channel` has at least one entry
11021115 . unwrap ( ) ;
11031116
1104- let new_channel = Channel :: new (
1117+ let new_channel = Self :: new (
11051118 self . entry
11061119 . iter ( )
11071120 . cloned ( )
Original file line number Diff line number Diff line change @@ -108,6 +108,12 @@ impl FkTable {
108108 & self . grid
109109 }
110110
111+ /// Returns a mutable reference to the [`Grid`] object for this `FkTable`.
112+ #[ must_use]
113+ pub fn grid_mut ( & mut self ) -> & mut Grid {
114+ & mut self . grid
115+ }
116+
111117 // TODO: when trying to convert the following function to `const` as per clippy's suggestion,
112118 // the compiler errors out with: 'the destructor for this type cannot be evaluated in constant
113119 // functions'
Original file line number Diff line number Diff line change @@ -1484,7 +1484,10 @@ impl Grid {
14841484 . collect ( ) ;
14851485 }
14861486
1487- /// TODO
1487+ /// Merges the factors of the channels into the subgrids to normalize channel coefficients.
1488+ ///
1489+ /// This method factors out the smallest absolute coefficient from each channel using
1490+ /// [`boc::Channel::factor`] and then scales the corresponding subgrids by these factors.
14881491 pub fn merge_channel_factors ( & mut self ) {
14891492 let ( factors, new_channels) : ( Vec < _ > , Vec < _ > ) =
14901493 self . channels ( ) . iter ( ) . map ( Channel :: factor) . unzip ( ) ;
Original file line number Diff line number Diff line change @@ -224,12 +224,18 @@ impl PyFkTable {
224224 /// ----------
225225 /// pid_basis: PyPidBasis
226226 /// PID basis of the resulting FK Table
227- pub fn rotate_pid_basis ( & mut self , pid_basis : PyPidBasis ) -> PyGrid {
228- let mut grid_mut = self . fk_table . grid ( ) . clone ( ) ;
229- grid_mut. rotate_pid_basis ( pid_basis. into ( ) ) ;
230- PyGrid {
231- grid : grid_mut. clone ( ) ,
232- }
227+ pub fn rotate_pid_basis ( & mut self , pid_basis : PyPidBasis ) {
228+ self . fk_table . grid_mut ( ) . rotate_pid_basis ( pid_basis. into ( ) ) ;
229+ }
230+
231+ /// Merge the factors of all the channels.
232+ pub fn merge_channel_factors ( & mut self ) {
233+ self . fk_table . grid_mut ( ) . merge_channel_factors ( ) ;
234+ }
235+
236+ /// Splits the grid such that each channel contains only a single tuple of PIDs.
237+ pub fn split_channels ( & mut self ) {
238+ self . fk_table . grid_mut ( ) . split_channels ( ) ;
233239 }
234240
235241 /// Write to file.
You can’t perform that action at this time.
0 commit comments