Skip to content

Commit

Permalink
remove and advice about rows redundancy
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Jan 9, 2024
1 parent 65711c2 commit c439ed9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
20 changes: 7 additions & 13 deletions src/algorithm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl FillContext for (&CodeSpan, &Inputs) {
}

pub(crate) fn shape_prefixes_match(a: &[usize], b: &[usize]) -> bool {
a.iter().zip(b.iter()).all(|(a, b)| a == b)
a.iter().zip(b).all(|(a, b)| a == b)
}

pub(crate) fn fill_array_shapes<A, B, C>(
Expand All @@ -153,16 +153,13 @@ where
return Ok(());
}
if a.row_count() == 1 && ctx.fill::<A>().is_err() {
let fixes = a
.shape
.iter()
let fixes = (a.shape.iter())
.take_while(|&&dim| dim == 1)
.count()
.min(a.shape.len())
.min(b.shape.len());
if (b.shape[fixes..].iter().rev())
.min(a.shape.len());
if (b.shape.iter().rev())
.zip(a.shape[fixes..].iter().rev())
.all(|(a, b)| a == b)
.all(|(b, a)| b == a)
{
a.shape.drain(..fixes);
for &dim in b.shape[..fixes].iter().rev() {
Expand All @@ -171,14 +168,11 @@ where
}
}
if b.row_count() == 1 && ctx.fill::<B>().is_err() {
let fixes = b
.shape
.iter()
let fixes = (b.shape.iter())
.take_while(|&&dim| dim == 1)
.count()
.min(a.shape.len())
.min(b.shape.len());
if (a.shape[fixes..].iter().rev())
if (a.shape.iter().rev())
.zip(b.shape[fixes..].iter().rev())
.all(|(a, b)| a == b)
{
Expand Down
3 changes: 2 additions & 1 deletion src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,7 @@ code:
}
Ok(())
}
#[allow(clippy::collapsible_match)]
fn modified(&mut self, modified: Modified, call: bool) -> UiuaResult {
let op_count = modified.code_operands().count();

Expand Down Expand Up @@ -1290,7 +1291,7 @@ code:
if let Modifier::Primitive(prim) = modified.modifier.value {
// Give advice about redundancy
match prim {
m @ (Primitive::Each | Primitive::Rows) => {
m @ Primitive::Each => {
if let [Sp {
value: Word::Primitive(prim),
span,
Expand Down

0 comments on commit c439ed9

Please sign in to comment.