Skip to content

Commit

Permalink
fix a bug with filled reduce table
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Jun 12, 2024
1 parent dd367ee commit 1bd403d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/algorithm/reduce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ use super::{fixed_rows, FixedRowsData};
pub fn reduce(depth: usize, env: &mut Uiua) -> UiuaResult {
crate::profile_function!();
let f = env.pop_function()?;
reduce_impl(f, depth, env)
}

pub(crate) fn reduce_impl(f: Function, depth: usize, env: &mut Uiua) -> UiuaResult {
let xs = env.pop(1)?;
match (f.as_flipped_primitive(&env.asm), xs) {
(Some((Primitive::Join, false)), mut xs)
Expand Down
15 changes: 13 additions & 2 deletions src/algorithm/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ use crate::{
Array, ArrayValue, Complex, ImplPrimitive, Instr, Primitive, Shape, Uiua, UiuaResult,
};

use super::{loops::flip, multi_output, validate_size};
use super::{loops::flip, multi_output, reduce::reduce_impl, validate_size};

pub fn table(env: &mut Uiua) -> UiuaResult {
crate::profile_function!();
let f = env.pop_function()?;
table_impl(f, env)
}

fn table_impl(f: Function, env: &mut Uiua) -> UiuaResult {
crate::profile_function!();
let sig = f.signature();
match sig.args {
0 => env.call(f),
Expand Down Expand Up @@ -575,6 +579,13 @@ fn generic_reduce_table(
ys: Value,
env: &mut Uiua,
) -> UiuaResult {
if env.value_fill().is_some() {
env.push(ys);
env.push(xs);
table_impl(g, env)?;
return reduce_impl(f, 0, env);
}

let mut xs = xs.into_rows();
let mut acc = xs
.next()
Expand Down
5 changes: 5 additions & 0 deletions tests/optimized.ua
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,8 @@ F ← ⬚10(/+∘⊞(ׯ))
⍤⟜≍: [7 4 1] F [1 2] [1 2 3]
⍤⟜≍: [10 10 10] F [] [1 2 3]
⍤⟜≍: [] F [1 2] []

F ← ⬚10(/+◌1⊞(ׯ))
⍤⟜≍: [7 4 1] F [1 2] [1 2 3]
⍤⟜≍: [10 10 10] F [] [1 2 3]
⍤⟜≍: [] F [1 2] []

0 comments on commit 1bd403d

Please sign in to comment.