Skip to content

Commit

Permalink
fix(optimizer): tolerate overspecified partition_cut
Browse files Browse the repository at this point in the history
  • Loading branch information
rudy-6-4 committed Sep 25, 2023
1 parent c1aa78f commit 2228075
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl PartitionCut {
_ = lut_partition.insert((input_precision, OrderedFloat(*output_norm2)));
}
}
let mut p_cut : Vec<_> = lut_partition.iter().copied().collect();
let mut p_cut: Vec<_> = lut_partition.iter().copied().collect();
p_cut.sort_by(|a, b| a.partial_cmp(b).unwrap());
_ = p_cut.pop();
let p_cut = p_cut.iter().map(|(p, n)| (*p, n.into_inner())).collect();
Expand All @@ -192,6 +192,18 @@ impl PartitionCut {
}
}

pub fn delete_unused_cut(&self, used: &HashSet<PartitionIndex>) -> Self {
let mut p_cut = vec![];
for (i, &cut) in self.p_cut.iter().enumerate() {
if used.contains(&i) {
p_cut.push(cut);
}
}
Self {
p_cut,
rnorm2: self.rnorm2.clone(),
}
}
}

impl std::fmt::Display for PartitionCut {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ fn resolve_by_levelled_block(
.copied()
.collect();
let nb_partitions = present_partitions.len().max(1); // no tlu = no constraints
if p_cut.p_cut.len() + 1 != nb_partitions {
return resolve_by_levelled_block(
dag,
&p_cut.delete_unused_cut(&present_partitions),
default_partition,
);
}
if nb_partitions == 1 {
return only_1_partition(dag);
}
Expand Down

0 comments on commit 2228075

Please sign in to comment.