fix: Optimize region transfer map

This commit is contained in:
Emilia Allison 2024-11-15 15:28:01 -06:00
parent ad3bbd3649
commit 04554f634b
Signed by: emilia
GPG Key ID: 05D5D1107E5100A1
1 changed files with 35 additions and 23 deletions

View File

@ -202,22 +202,30 @@ impl TransferRegion {
); );
let count = ( let count = (
// How many times can we replicate? // How many times can we replicate?
if il_dest.0.unsigned_abs() == 0 {
1
} else {
(1..) (1..)
.position(|n| { .position(|n| {
n * number_used_src_wells.0 * il_dest.0.unsigned_abs() (n * number_used_src_wells.0 * il_dest.0.unsigned_abs())
- il_dest.0.unsigned_abs() .saturating_sub(il_dest.0.unsigned_abs())
+ 1 + 1
> d_dims.0 > d_dims.0
}) })
.unwrap() as u8, .unwrap() as u8
},
if il_dest.1.unsigned_abs() == 0 {
1
} else {
(1..) (1..)
.position(|n| { .position(|n| {
n * number_used_src_wells.1 * il_dest.1.unsigned_abs() (n * number_used_src_wells.1 * il_dest.1.unsigned_abs())
- il_dest.1.unsigned_abs() .saturating_sub(il_dest.1.unsigned_abs())
+ 1 + 1
> d_dims.1 > d_dims.1
}) })
.unwrap() as u8, .unwrap() as u8
},
); );
let i = i let i = i
.saturating_sub(s_ul.row) .saturating_sub(s_ul.row)
@ -225,30 +233,34 @@ impl TransferRegion {
let j = j let j = j
.saturating_sub(s_ul.col) .saturating_sub(s_ul.col)
.saturating_div(il_source.1.unsigned_abs()); .saturating_div(il_source.1.unsigned_abs());
let checked_il_dest = (u8::max(il_dest.0.unsigned_abs(), 1u8),
u8::max(il_dest.1.unsigned_abs(), 1u8));
let row_modulus = number_used_src_wells.0 * checked_il_dest.0;
let column_modulus = number_used_src_wells.1 * checked_il_dest.1;
Some( Some(
possible_destination_wells possible_destination_wells
.into_iter() .into_iter()
.filter(|Well { row: x, .. }| { .filter(|Well { row: x, .. }| {
x.checked_sub(d_ul.row).unwrap() x.checked_sub(d_ul.row).unwrap()
% (number_used_src_wells.0 * il_dest.0.unsigned_abs()) // Counter along x % row_modulus // Counter along x
== (il_dest.0.unsigned_abs() *i) == (il_dest.0.unsigned_abs() *i)
% (number_used_src_wells.0 * il_dest.0.unsigned_abs()) % row_modulus
}) })
.filter(|Well { col: y, .. }| { .filter(|Well { col: y, .. }| {
y.checked_sub(d_ul.col).unwrap() y.checked_sub(d_ul.col).unwrap()
% (number_used_src_wells.1 * il_dest.1.unsigned_abs()) // Counter along u % column_modulus // Counter along u
== (il_dest.1.unsigned_abs() *j) == (il_dest.1.unsigned_abs() *j)
% (number_used_src_wells.1 * il_dest.1.unsigned_abs()) % column_modulus
}) })
.filter(|Well { row: x, col: y }| { .filter(|Well { row: x, col: y }| {
// How many times have we replicated? < How many are we allowed // How many times have we replicated? < How many are we allowed
// to replicate? // to replicate?
x.checked_sub(d_ul.row).unwrap().div_euclid( x.checked_sub(d_ul.row).unwrap().div_euclid(
number_used_src_wells.0 * il_dest.0.unsigned_abs(), row_modulus
) < count.0 ) < count.0
&& y.checked_sub(d_ul.col).unwrap().div_euclid( && y.checked_sub(d_ul.col).unwrap().div_euclid(
number_used_src_wells.1 * il_dest.1.unsigned_abs(), column_modulus
) < count.1 ) < count.1
}) })
.collect(), .collect(),