Skip to content

Commit 36b679a

Browse files
committed
fix a crash in tuples
1 parent 548150b commit 36b679a

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

src/algorithm/tuples.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::collections::{hash_map::Entry, HashMap};
33
use ecow::EcoVec;
44

55
use crate::{
6-
get_ops, types::push_empty_rows_value, val_as_arr, Array, ArrayValue, Ops, Primitive, SigNode,
7-
Uiua, UiuaResult, Value,
6+
get_ops, grid_fmt::GridFmt, types::push_empty_rows_value, val_as_arr, Array, ArrayValue, Ops,
7+
Primitive, SigNode, Uiua, UiuaResult, Value,
88
};
99

1010
use super::{monadic::range, table::table_impl, validate_size};
@@ -256,6 +256,15 @@ fn tuple2(f: SigNode, env: &mut Uiua) -> UiuaResult {
256256
Array::new(shape, data).into()
257257
})
258258
}
259+
if xs.row_count() == 0 {
260+
env.push(if is_scalar {
261+
0.into()
262+
} else {
263+
xs.shape.insert(1, k);
264+
xs
265+
});
266+
return Ok(());
267+
}
259268
let scalar = xs.as_nat(env, "Tuples of scalar must be a natural number");
260269
xs = match &xs {
261270
Value::Num(a) => inner(a, k, f, is_scalar, scalar, env)?,
@@ -318,7 +327,10 @@ impl<T: ArrayValue> Array<T> {
318327
return Err(env.error("Combinatorial explosion"));
319328
}
320329
if combinations > usize::MAX as f64 {
321-
return Err(env.error(format!("{combinations} combinations would be too many")));
330+
return Err(env.error(format!(
331+
"{} combinations would be too many",
332+
combinations.grid_string(false)
333+
)));
322334
}
323335
shape[0] = combinations.round() as usize;
324336
shape.insert(1, k);
@@ -436,7 +448,10 @@ impl<T: ArrayValue> Array<T> {
436448
return Err(env.error("Combinatorial explosion"));
437449
}
438450
if permutations > usize::MAX as f64 {
439-
return Err(env.error(format!("{permutations} permutations would be too many")));
451+
return Err(env.error(format!(
452+
"{} permutations would be too many",
453+
permutations.grid_string(false)
454+
)));
440455
}
441456
shape[0] = permutations.round() as usize;
442457
shape.insert(1, k);

tests/optimized.ua

+12
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,18 @@ F ← ⬚10(/+◌1⊞(ׯ))
280280
⍤⤙≍ ⊃⧅<⧅(∘<) ¯1 ⇡4
281281
⍤⤙≍ ⊃(⧅≠3|⧅≠¯2) 5
282282
⍤⤙≍ 42 ⧅= ∞ 42
283+
⍤⤙≍ [0 3] △ ⧅≤ 3 °△[0]
284+
⍤⤙≍ [1 3] △ ⧅≤ 3 °△[1]
285+
⍤⤙≍ [4 3] △ ⧅≤ 3 °△[2]
286+
⍤⤙≍ [0 3 2] △ ⧅≤ 3 °△[0 2]
287+
⍤⤙≍ [1 3 2] △ ⧅≤ 3 °△[1 2]
288+
⍤⤙≍ [4 3 2] △ ⧅≤ 3 °△[2 2]
289+
⍤⤙≍ [0 3] △ ⧅(≤∘) 3 °△[0]
290+
⍤⤙≍ [1 3] △ ⧅(≤∘) 3 °△[1]
291+
⍤⤙≍ [4 3] △ ⧅(≤∘) 3 °△[2]
292+
⍤⤙≍ [0 3 2] △ ⧅(≤∘) 3 °△[0 2]
293+
⍤⤙≍ [1 3 2] △ ⧅(≤∘) 3 °△[1 2]
294+
⍤⤙≍ [4 3 2] △ ⧅(≤∘) 3 °△[2 2]
283295

284296
⍤⤙≍ ℂ5 0 ¯₄ 5
285297
⍤⤙≍ ℂ¯π 0 °¯₄ π

todo.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Uiua Todo
22

33
# 0.16
4+
- Site deploy action
45
- Optimize `sort` to be in-place by modifying rayon code
56
- Optimize `unsort`
67
- More rows optimizations

0 commit comments

Comments
 (0)