Skip to content

Commit

Permalink
fix a bug in pervasive repeat and switch
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Jun 26, 2024
1 parent 768bf01 commit 0683040
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/algorithm/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub fn repeat(with_inverse: bool, env: &mut Uiua) -> UiuaResult {
let FixedRowsData {
mut rows,
row_count,
is_empty,
..
} = fixed_rows(Primitive::Repeat.format(), sig.outputs, args, env)?;

Expand Down Expand Up @@ -122,6 +123,9 @@ pub fn repeat(with_inverse: bool, env: &mut Uiua) -> UiuaResult {
// Collect output
for output in outputs.into_iter().rev() {
let mut new_value = Value::from_row_values(output, env)?;
if is_empty {
new_value.pop_row();
}
let mut new_shape = new_shape.clone();
new_shape.extend_from_slice(&new_value.shape()[1..]);
*new_value.shape_mut() = new_shape;
Expand Down
4 changes: 4 additions & 0 deletions src/algorithm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ pub fn switch(
let FixedRowsData {
mut rows,
row_count,
is_empty,
..
} = fixed_rows("switch", sig.outputs, args, env)?;
// Collect functions
Expand Down Expand Up @@ -572,6 +573,9 @@ pub fn switch(
// Collect output
for output in outputs.into_iter().rev() {
let mut new_value = Value::from_row_values(output, env)?;
if is_empty {
new_value.pop_row();
}
let mut new_shape = new_shape.clone();
new_shape.extend_from_slice(&new_value.shape()[1..]);
*new_value.shape_mut() = new_shape;
Expand Down

0 comments on commit 0683040

Please sign in to comment.