Skip to content

Commit 94d36d1

Browse files
committed
optimize scan inequalities
1 parent cf35be3 commit 94d36d1

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

site/src/other.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub fn Optimizations() -> impl IntoView {
189189
</tr>
190190
<tr><th><Prim prim=Table/></th> <td>"✔"</td> <td>"✔"</td> <td>"✔"</td> <td>"✔"</td> <td>"✔"</td></tr>
191191
<tr><th><Prim prim=Reduce/></th> <td>"✔"</td> <td></td> <td></td> <td>"✔"</td> <td></td></tr>
192-
<tr><th><Prim prim=Scan/></th> <td>"✔"</td> <td>"✔"</td> <td></td> <td></td> <td></td></tr>
192+
<tr><th><Prim prim=Scan/></th> <td>"✔"</td> <td>"✔"</td> <td>"✔"</td> <td></td> <td></td></tr>
193193
</table>
194194

195195
<p>"The pattern "<Prims prims=[Reduce]/><code>"F"</code><Prims prims=[Table]/><code>"G"</code>" is optimized to use much less memory and run much faster than the naive implementation. This only occurs when both functions have signature "<code>"|2.1"</code>". Rather than creating the entire table and then reducing it, each reduced row is generated as it is needed."</p>

src/algorithm/reduce.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,10 @@ pub fn scan(ops: Ops, env: &mut Uiua) -> UiuaResult {
784784
let mut arr = match prim {
785785
Primitive::Eq => fast_scan(nums, |a, b| is_eq::num_num(a, b) as f64),
786786
Primitive::Ne => fast_scan(nums, |a, b| is_ne::num_num(a, b) as f64),
787+
Primitive::Lt => fast_scan(nums, |a, b| other_is_lt::num_num(a, b) as f64),
788+
Primitive::Le => fast_scan(nums, |a, b| other_is_le::num_num(a, b) as f64),
789+
Primitive::Gt => fast_scan(nums, |a, b| other_is_gt::num_num(a, b) as f64),
790+
Primitive::Ge => fast_scan(nums, |a, b| other_is_ge::num_num(a, b) as f64),
787791
Primitive::Add => fast_scan(nums, add::num_num),
788792
Primitive::Sub if flipped => fast_scan(nums, flip(sub::num_num)),
789793
Primitive::Sub => fast_scan(nums, sub::num_num),
@@ -824,6 +828,10 @@ pub fn scan(ops: Ops, env: &mut Uiua) -> UiuaResult {
824828
let mut val: Value = match prim {
825829
Primitive::Eq => fast_scan(bytes, is_eq::generic).into(),
826830
Primitive::Ne => fast_scan(bytes, is_ne::generic).into(),
831+
Primitive::Lt => fast_scan(bytes, other_is_lt::generic).into(),
832+
Primitive::Le => fast_scan(bytes, other_is_le::generic).into(),
833+
Primitive::Gt => fast_scan(bytes, other_is_gt::generic).into(),
834+
Primitive::Ge => fast_scan(bytes, other_is_ge::generic).into(),
827835
Primitive::Add => fast_scan::<f64>(bytes.convert(), add::num_num).into(),
828836
Primitive::Sub if flipped => {
829837
fast_scan::<f64>(bytes.convert(), flip(sub::num_num)).into()

0 commit comments

Comments
 (0)