Skip to content

Commit 4ca30b9

Browse files
committed
remove though-box behavior for reverse, transpose, and rotate
1 parent 57fa7fa commit 4ca30b9

File tree

10 files changed

+22
-96
lines changed

10 files changed

+22
-96
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ This version is not yet released. If you are reading this on the website, then t
1414
- **Breaking Change** - [`under ⍜`](https://uiua.org/docs/under)[`shape △`](https://uiua.org/docs/shape) now tiles the original array to match the new shape instead of [`reshape ↯`](https://uiua.org/docs/reshape)ing
1515
- **Breaking Change** - [`dip ⊙`](https://uiua.org/docs/dip) and [`on ⟜`](https://uiua.org/docs/on) function packs no longer apply their modifier to the leftmost function
1616
- This change makes most usecases of these function packs cleaner, as `A⊙(B|C)` changes to `⊙(A|B|C)` and likewise for [`on ⟜`](https://uiua.org/docs/on)
17+
- **Breaking Change** - [`reverse ⇌`](https://uiua.org/docs/reverse), [`transpose ⍉`](https://uiua.org/docs/transpose), and [`rotate ↻`](https://uiua.org/docs/rotate) no longer work through boxes
18+
- This caused consistency issues and was rarely used anyway
1719
- **Breaking Change** - The FFI function API has been changed considerably, read more in the documentation for [`&ffi`](https://uiua.org/docs/&ffi), [`&memcpy`](https://uiua.org/docs/&memcpy), and [`&memset`](https://uiua.org/docs/&memset)
1820
- Add [`parse ⋕`](https://uiua.org/docs/parse) subscripts to parse strings in different bases
1921
- Allow for private [modules](https://uiua.org/tutorial/modules#private-scoped-modules), [imports](https://uiua.org/tutorial/modules#private-imports), and [data definitions](https://uiua.org/tutorial/datadefs#visibility)

parser/src/defs.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -602,9 +602,7 @@ primitive!(
602602
///
603603
/// ex: ⇌1_2_3_9
604604
/// ex: ⇌[1_2 3_4 5_6]
605-
/// [reverse] works through boxes.
606-
/// ex: ⇌ □[1 2 3]
607-
/// ex: ≡⇌ {1_2_3_4 5_6_7 8_9}
605+
/// ex: ⇌"Hello!"
608606
(1, Reverse, MonadicArray, ("reverse", '⇌')),
609607
/// Make an array 1-dimensional
610608
///
@@ -674,9 +672,6 @@ primitive!(
674672
///
675673
/// ex: ⍉.[1_2 3_4 5_6]
676674
/// ex: ⍉.[[1_2 3_4] [5_6 7_8]]
677-
/// [transpose] works through boxes.
678-
/// ex: ⍉ □[1_2_3 4_5_6]
679-
/// ex: ≡⍉ {[1_2 3_4] [1_2_3 4_5_6]}
680675
/// [un][transpose] transposes in the opposite direction.
681676
/// This is useful for arrays with rank `greater than``2`.
682677
/// ex: °⍉ .⊟.[1_2_3 4_5_6]
@@ -1184,10 +1179,6 @@ primitive!(
11841179
/// : ↻ 2 [1 2 3 4 5]
11851180
/// ex: ⬚0↻ 1_2 .↯4_5⇡20
11861181
///
1187-
/// [rotate] works through boxes.
1188-
/// ex: ↻1 □[1 2 3 4]
1189-
/// ex: ≡↻1 {1_2_3 4_5_6}
1190-
///
11911182
/// If the rotation amount is rank `2` or greater, multiple copies of the rotated array will be made, each rotated by a different row of the rotation amount.
11921183
/// ex: ↻ [[1] [2] [4]] [0 0 0 0 0 0 1]
11931184
/// : ↻ ≡¤1_2_4 [0 0 0 0 0 0 1]

src/algorithm/dyadic/mod.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99
borrow::Cow,
1010
cmp::Ordering,
1111
hash::{DefaultHasher, Hash, Hasher},
12-
iter::{once, repeat_n, repeat_with},
12+
iter::{once, repeat_n},
1313
mem::{replace, swap, take},
1414
};
1515

@@ -1084,15 +1084,6 @@ impl Value {
10841084
Value::Byte(b) => b.rotate_depth(by_ints()?, depth, forward, env)?,
10851085
Value::Complex(b) => b.rotate_depth(by_ints()?, depth, forward, env)?,
10861086
Value::Char(b) => b.rotate_depth(by_ints()?, depth, forward, env)?,
1087-
Value::Box(b) if b.rank() == depth => {
1088-
let row_shape: Shape = self.shape.iter().skip(depth).copied().collect();
1089-
for (rot, Boxed(val)) in repeat_with(|| self.row_shaped_slices(row_shape.clone()))
1090-
.flatten()
1091-
.zip(b.data.as_mut_slice())
1092-
{
1093-
rot.rotate_depth(val, 0, forward, env)?;
1094-
}
1095-
}
10961087
Value::Box(a) => a.rotate_depth(by_ints()?, depth, forward, env)?,
10971088
}
10981089
rotated.meta.take_sorted_flags();

src/algorithm/monadic/mod.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,13 +1108,7 @@ impl Value {
11081108
self.reverse_depth(0);
11091109
}
11101110
pub(crate) fn reverse_depth(&mut self, depth: usize) {
1111-
self.generic_mut_deep(
1112-
|a| a.reverse_depth(depth),
1113-
|a| a.reverse_depth(depth),
1114-
|a| a.reverse_depth(depth),
1115-
|a| a.reverse_depth(depth),
1116-
|a| a.reverse_depth(depth),
1117-
)
1111+
val_as_arr!(self, |arr| arr.reverse_depth(depth))
11181112
}
11191113
}
11201114

@@ -1169,13 +1163,7 @@ impl<T: ArrayValue> Array<T> {
11691163
impl Value {
11701164
/// Transpose the value
11711165
pub fn transpose(&mut self) {
1172-
self.generic_mut_deep(
1173-
Array::transpose,
1174-
Array::transpose,
1175-
Array::transpose,
1176-
Array::transpose,
1177-
Array::transpose,
1178-
)
1166+
val_as_arr!(self, |arr| arr.transpose());
11791167
}
11801168
pub(crate) fn transpose_depth(&mut self, depth: usize, amnt: i32) {
11811169
match self {

src/algorithm/zip.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -440,13 +440,10 @@ pub fn each(ops: Ops, env: &mut Uiua) -> UiuaResult {
440440

441441
pub(crate) fn each1(f: SigNode, mut xs: Value, env: &mut Uiua) -> UiuaResult {
442442
if let Some((f, ..)) = f_mon_fast_fn(&f.node, env) {
443-
let maybe_through_boxes = matches!(&xs, Value::Box(..));
444-
if !maybe_through_boxes {
445-
let rank = xs.rank();
446-
let val = f(xs, rank, env)?;
447-
env.push(val);
448-
return Ok(());
449-
}
443+
let rank = xs.rank();
444+
let val = f(xs, rank, env)?;
445+
env.push(val);
446+
return Ok(());
450447
}
451448
let outputs = f.sig.outputs();
452449
let mut new_values = multi_output(outputs, Vec::with_capacity(xs.shape.elements()));
@@ -653,21 +650,15 @@ pub fn rows1(f: SigNode, mut xs: Value, depth: usize, inv: bool, env: &mut Uiua)
653650
if !inv {
654651
if let Some((f, mut d)) = f_mon_fast_fn(&f.node, env) {
655652
d += depth;
656-
let maybe_through_boxes = matches!(&xs, Value::Box(arr) if arr.rank() <= d + 1);
657-
if !maybe_through_boxes {
658-
let val = f(xs, d + 1, env)?;
659-
env.push(val);
660-
return Ok(());
661-
}
653+
let val = f(xs, d + 1, env)?;
654+
env.push(val);
655+
return Ok(());
662656
} else if let Some((f, mut d)) = f_mon2_fast_fn(&f.node, env) {
663657
d += depth;
664-
let maybe_through_boxes = matches!(&xs, Value::Box(arr) if arr.rank() <= d + 1);
665-
if !maybe_through_boxes {
666-
let (xs, ys) = f(xs, d + 1, env)?;
667-
env.push(ys);
668-
env.push(xs);
669-
return Ok(());
670-
}
658+
let (xs, ys) = f(xs, d + 1, env)?;
659+
env.push(ys);
660+
env.push(xs);
661+
return Ok(());
671662
}
672663
}
673664
let outputs = f.sig.outputs();

src/value.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -443,28 +443,6 @@ impl Value {
443443
pub(crate) fn slice_rows(&self, start: usize, end: usize) -> Self {
444444
val_as_arr!(self, |arr| arr.slice_rows(start, end).into())
445445
}
446-
pub(crate) fn generic_mut_deep<T>(
447-
&mut self,
448-
n: impl FnOnce(&mut Array<f64>) -> T,
449-
b: impl FnOnce(&mut Array<u8>) -> T,
450-
co: impl FnOnce(&mut Array<Complex>) -> T,
451-
ch: impl FnOnce(&mut Array<char>) -> T,
452-
f: impl FnOnce(&mut Array<Boxed>) -> T,
453-
) -> T {
454-
match self {
455-
Self::Num(array) => n(array),
456-
Self::Byte(array) => b(array),
457-
Self::Complex(array) => co(array),
458-
Self::Char(array) => ch(array),
459-
Self::Box(array) => {
460-
if let Some(Boxed(value)) = array.as_scalar_mut() {
461-
value.generic_mut_deep(n, b, co, ch, f)
462-
} else {
463-
f(array)
464-
}
465-
}
466-
}
467-
}
468446
#[allow(clippy::too_many_arguments)]
469447
pub(crate) fn generic_bin_into<T, E>(
470448
self,

tests/box.ua

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,3 @@
4444

4545
⍤⤙≍ 5 ◇∘ □5
4646
⍤⤙≍ □5 °◇∘ 5
47-
48-
⍤⤙≍ {{5_6 7_8} {1_2 3_4}} ⇌ {{1_2 3_4} {5_6 7_8}}
49-
⍤⤙≍ {{3_4 1_2} {7_8 5_6}} ≡⍜°□⇌ {{1_2 3_4} {5_6 7_8}}
50-
⍤⤙≍ {{3_4 1_2} {7_8 5_6}} ≡⇌ {{1_2 3_4} {5_6 7_8}}
51-
⍤⤙≍ {{3_4 1_2} {7_8 5_6}} ≡⍜°□⇌♭ {{1_2 3_4} {5_6 7_8}}
52-
⍤⤙≍ {{3_4 1_2} {7_8 5_6}} ≡⇌♭ {{1_2 3_4} {5_6 7_8}}
53-
⍤⤙≍ {{3_4 1_2} {7_8 5_6}} ≡⍜°□⇌ {{1_2 3_4} {5_6 7_8}}
54-
⍤⤙≍ {{3_4 1_2} {7_8 5_6}} ≡⇌ {{1_2 3_4} {5_6 7_8}}
55-
56-
⍤⤙≍ {"olleh" "dlrow"} ≡⇌{"hello" "world"}
57-
⍤⤙≍ {"olleh" "dlrow"} ≡(⇌){"hello" "world"}
58-
⍤⤙≍ ¤{"olleh" "dlrow"} ≡₀⇌¤{"hello" "world"}
59-
⍤⤙≍ ¤{"olleh" "dlrow"} ≡₀(⇌)¤{"hello" "world"}
60-
61-
⍤⤙≍ □[2 3 1] ↻1 □[1 2 3]
62-
⍤⤙≍ {2_3_1 5_6_4} ≡↻1 {1_2_3 4_5_6}

tests/dyadic.ua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
⍤⤙≍ [] ↻1_1[]
6363
⍤⤙≍ °△0_0 ↻1°△0_0
6464
⍤⤙≍ ⊃≡↻⬚0≡↻ °⊏°△⊟.5
65-
⍤⤙≍ □[2 3 1] ↻1 □[1 2 3]
66-
⍤⤙≍ {↻1⇡4 ↻2⇡5} ↻ [1 2] {⇡4 ⇡5}
65+
⍤⤙≍ □[2 3 1] ↻1 □[1 2 3]
66+
⍤⤙≍ {↻1⇡4 ↻2⇡5} ↻ [1 2] {⇡4 ⇡5}
6767
⍤⤙≍ ↯3_3 1 /+♭₃ ↻°⊡ ⬚0↯3_3 1
6868
⍤⤙≍ ["abc" "bc " "c "] ⬚@ ↻≡¤°⊏ "abc"
6969
⍤⤙≍ ["abc" " ab" " a"] ⬚@ ⌝↻≡¤°⊏ "abc"

tests/monadic.ua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
⍤⤙≍ ⊃⍉°(⍉⍉⍉) ↯2_3_4_5⇡120
4646
⍤⤙≍ ⊃°⍉(⍉⍉⍉) ↯2_3_4_5⇡120
4747
⍤⤙≍ ⍉⍉⍉⍉ . ↯2_3_4_5⇡120
48-
⍤⤙≍ □[1_3 2_4] ⍉□[1_2 3_4]
49-
⍤⤙≍ {[1_3 2_4] [5_7 6_8]} ⍉{[1_2 3_4] [5_6 7_8]}
48+
⍤⤙≍ □[1_3 2_4] ⍉□[1_2 3_4]
49+
⍤⤙≍ {[1_3 2_4] [5_7 6_8]} ⍉{[1_2 3_4] [5_6 7_8]}
5050
⍤⤙≍ ⊃⍜⍉⇌⍜(⍉⍉⍉)⇌ [[1 2 3] [4 5 6] [7 8 9]]
5151

5252
# Subscripted length

todo.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Fix rename
77
- Fix goto references
88
- Sided `join`
9+
- Sided `box`
910
- `table` subscripts for rank selection
1011
- Mixed subscripts
1112
- `bracket`

0 commit comments

Comments
 (0)