Optimize complex multiplication where imaginary part of the first operand is zero#2501
Optimize complex multiplication where imaginary part of the first operand is zero#2501Antipath1 wants to merge 6 commits into
Conversation
… a complex and real number
a44e6de to
8c01bde
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2501 +/- ##
==========================================
- Coverage 25.47% 25.10% -0.38%
==========================================
Files 220 220
Lines 44609 44600 -9
==========================================
- Hits 11366 11197 -169
- Misses 33243 33403 +160 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
maybe you should make use of the PurelyRealResultAnalysis and PurelyImagResultAnalysis, so that this pattern can propagate further
Enzyme-JAX/src/enzyme_ad/jax/Utils.h
Lines 867 to 893 in 14b57c2
the way I would do is check if the the ops from the values you're checking (i.e. the ancestor ops to the stablehlo.multiply) actually contain such attributes, and run the pattern after the analysis.
…om multiply since the result is a real tensor anyway
…RealComplexMulSimplify pattern
|
Okay, I have addressed this for the case of multiplication for a purely real number and a complex number. I have not gotten around to the case of a purely Imaginary number with a complex number, but I think other than that, I have addressed your feedback. I had to edit two unrelated tests since using the pattern fired in two of the tests:
(cc @avik-pal: since you wrote these tests, could you double-check that my updates to the expected IR look right to you and tell me if I messed anything up there?) |
closes #1988
$(a + bi) \times (c + di)$ : If $b = 0$ , the expression simplifies:
$(a \cdot c - b \cdot d) + (c \cdot b + a \cdot d)i \implies (a \cdot c - 0 \cdot d) + (c \cdot 0 + a \cdot d)i = a \cdot c + a \cdot d \cdot i$
This PR adds a rewrite pattern for stablehlo.multiply to optimize complex multiplication when the imaginary component of the first operand is zero.Mathematical simplification:Given