Skip to content

Commit

Permalink
optimize /×⧈≍ as all same
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Dec 28, 2024
1 parent d2464e0 commit 07cbce7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/compile/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,16 @@ impl Optimization for AllSameOpt {
[ImplPrim(CountUnique, span), Push(val), Prim(Le, _), ..] if *val == 1 => {
Some((3, ImplPrim(AllSame, *span)))
}
[Mod(Stencil, stencil_args, span), Mod(Reduce, reduce_args, _), ..] => {
let ([stencil_f], [reduce_f]) = (stencil_args.as_slice(), reduce_args.as_slice())
else {
return None;
};
match (&stencil_f.node, &reduce_f.node) {
(Prim(Match, _), Prim(Mul, _)) => Some((2, ImplPrim(AllSame, *span))),
_ => None,
}
}
_ => None,
})
}
Expand Down
6 changes: 6 additions & 0 deletions tests/optimized.ua
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ F ← ⬚10(/+◌1⊞(ׯ))
⍤⤙≍ [≍∘⊸↻1] ⟜(◴[⊃(≤1⧻◴|≍⊸↻1|≍⊸(↻1))]) [1_2 1_2]
⍤⤙≍ [≍∘⊸↻1] ⟜(◴[⊃(≤1⧻◴|≍⊸↻1|≍⊸(↻1))]) [1_2 3_4]
⍤⤙≍ [≍∘⊸↻1] ⟜(◴[⊃(≤1⧻◴|≍⊸↻1|≍⊸(↻1))]) []
⍤⤙≍ ⊃(/×∘⧈≍|/×⧈≍) [1 2 3]
⍤⤙≍ ⊃(/×∘⧈≍|/×⧈≍) [1_2 3_4 5_6]
⍤⤙≍ ⊃(/×∘⧈≍|/×⧈≍) [1 1]
⍤⤙≍ ⊃(/×∘⧈≍|/×⧈≍) [1 0]
⍤⤙≍ ⊃(/×∘⧈≍|/×⧈≍) [1]
⍤⤙≍ ⊃(/×∘⧈≍|/×⧈≍) []

# Tuples
⍤⤙≍ ⊃⧅≠⧅(∘≠) 3 ⇡4
Expand Down

0 comments on commit 07cbce7

Please sign in to comment.