From 1bd403dad404f0bc6a89e7cd2ac0e5b042812920 Mon Sep 17 00:00:00 2001 From: Kai Schmidt Date: Wed, 12 Jun 2024 09:22:23 -0700 Subject: [PATCH] fix a bug with filled reduce table --- src/algorithm/reduce.rs | 4 ++++ src/algorithm/table.rs | 15 +++++++++++++-- tests/optimized.ua | 5 +++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/algorithm/reduce.rs b/src/algorithm/reduce.rs index 4867e589..86121a38 100644 --- a/src/algorithm/reduce.rs +++ b/src/algorithm/reduce.rs @@ -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) diff --git a/src/algorithm/table.rs b/src/algorithm/table.rs index 48c67c61..7bfad047 100644 --- a/src/algorithm/table.rs +++ b/src/algorithm/table.rs @@ -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), @@ -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() diff --git a/tests/optimized.ua b/tests/optimized.ua index 1986d20e..321730e8 100644 --- a/tests/optimized.ua +++ b/tests/optimized.ua @@ -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] []