Skip to content

Commit

Permalink
fix under deshape 0
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Nov 30, 2024
1 parent 13847b5 commit eab2855
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/compile/invert/under.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,18 +686,26 @@ under!(DupPat, input, g_sig, inverse, asm, Prim(Dup, dup_span), {
});

under!(
(DeshapeSubPat, input, _, _, _),
(DeshapeSubPat, input, g_sig, inverse, asm),
ImplPrim(DeshapeSub(i), span),
{
Ok(if i == 0 {
let (before, after) = under_inverse(
&[Prim(Deshape, span), Prim(First, span)],
g_sig,
inverse,
asm,
)?;
(input, before, after)
} else {
let before = Node::from_iter([
Prim(Dup, span),
Prim(Shape, span),
PushUnder(1, span),
ImplPrim(DeshapeSub(i), span),
]);
let after = Node::from_iter([PopUnder(1, span), ImplPrim(UndoDeshape(Some(i)), span)]);
Ok((input, before, after))
}
(input, before, after)
})
);

under!(ReduceJoinPat, input, _, _, _, Reduce, span, [f], {
Expand Down
1 change: 1 addition & 0 deletions tests/under.ua
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
⍤⤙≍ □↯2_∞_4⇡24 ⍜♭₂□ ↯2_3_4⇡24
⍤⤙≍ ↯2_3≡□↯∞_4⇡24 ⍜♭₂≡□ ↯2_3_4⇡24
⍤⤙≍ ≡□↯2_3_4⇡24 ⍜♭₃≡□ ↯2_3_4⇡24
⍤⤙≍ [10_2 3_4] ⍜♭₀×₁₀ [1_2 3_4]

# Reshape
⍤⤙≍ 3_4_5_0_1_2 ⍜↯⇌ 2_3 ⇡6
Expand Down

0 comments on commit eab2855

Please sign in to comment.