Skip to content

Commit

Permalink
add un shape
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Jun 16, 2024
1 parent 72de34d commit fc9d623
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This version is not yet released. If you are reading this on the website, then t
- [`keep ▽`](https://uiua.org/docs/keep) now works with non-integer scalar counts to scale an array
- [`join ⊂`](https://uiua.org/docs/join) will rank differences greater than 1 can now extend the smaller array
- [`un °`](https://uiua.org/docs/un) [`join ⊂`](https://uiua.org/docs/join) is now easier to combine with other inverses
- [`un °`](https://uiua.org/docs/un) [`shape △`](https://uiua.org/docs/shape) now generates an array with the given shape and incrementing elements
- Add the experimental [`fft`](https://uiua.org/docs/fft) function, which performs the Fast Fourier transform
- The inverse FFT is also supported via [`un °`](https://uiua.org/docs/un)
- Add the experimental [`astar`](https://uiua.org/docs/astar) modifier, which performs the A* pathfinding algorithm
Expand Down
1 change: 1 addition & 0 deletions site/src/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ fn all_uns() -> impl IntoView {
{ inverse_row_impl(view!(<code>"{…}"</code>), No, "", "°{:} {1 2_3}") }
{ inverse_row([Box], No, "No-op on non-scalars and non-boxes", "°□ □[1 2 3]") }
{ inverse_row([Reverse], No, "", "°⇌ [1 2 3 4]") }
{ inverse_row([Shape], No, "", "°△ [2 2 4]") }
{ inverse_row([Transpose], No, "", "°⍉ ↯2_3_2⇡12") }
{ inverse_row([Bits], No, "", "°⋯ [1 0 1]") }
{ inverse_row([Where], No, "", "°⊚ [1 4]") }
Expand Down
20 changes: 20 additions & 0 deletions src/algorithm/invert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ static INVERT_PATTERNS: &[&dyn InvertPattern] = {
&InvertPatternFn(invert_dup_pattern, "dup"),
&InvertPatternFn(invert_stack_swizzle_pattern, "stack swizzle"),
&InvertPatternFn(invert_select_pattern, "select"),
&InvertPatternFn(invert_shape_pattern, "shape"),
&pat!(Sqrt, (Dup, Mul)),
&pat!((Dup, Add), (2, Div)),
&([Dup, Mul], [Sqrt]),
Expand Down Expand Up @@ -917,6 +918,25 @@ fn invert_stack_swizzle_pattern<'a>(
Some((input, instrs))
}

fn invert_shape_pattern<'a>(
input: &'a [Instr],
comp: &mut Compiler,
) -> Option<(&'a [Instr], EcoVec<Instr>)> {
let [Instr::Prim(Primitive::Shape, span), input @ ..] = input else {
return None;
};
let mul = make_fn(eco_vec![Instr::Prim(Primitive::Mul, *span)], *span, comp)?;
let instrs = eco_vec![
Instr::Prim(Primitive::Dup, *span),
Instr::PushFunc(mul),
Instr::Prim(Primitive::Reduce, *span),
Instr::Prim(Primitive::Range, *span),
Instr::Prim(Primitive::Flip, *span),
Instr::Prim(Primitive::Reshape, *span),
];
Some((input, instrs))
}

fn invert_select_pattern<'a>(
input: &'a [Instr],
_: &mut Compiler,
Expand Down
2 changes: 1 addition & 1 deletion src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl Instr {
matches!(self, Self::PushSig(_) | Self::PopSig)
}
pub(crate) fn is_code(&self) -> bool {
!matches!(self, Self::NoInline)
!matches!(self, Self::NoInline | Self::TrackCaller)
}
}

Expand Down

0 comments on commit fc9d623

Please sign in to comment.