add support for complex tensor types in getConstantAttr#2790
Open
mofeing wants to merge 19 commits intoEnzymeAD:mainfrom
Open
add support for complex tensor types in getConstantAttr#2790mofeing wants to merge 19 commits intoEnzymeAD:mainfrom
getConstantAttr#2790mofeing wants to merge 19 commits intoEnzymeAD:mainfrom
Conversation
This was referenced Apr 15, 2026
wsmoses
approved these changes
Apr 28, 2026
wsmoses
approved these changes
May 6, 2026
c45359c to
8628eee
Compare
getConstantAttrgetConstantAttr
wsmoses
reviewed
May 8, 2026
| ArrayRef<APFloat>(values)); | ||
| } else if (auto CET = dyn_cast<ComplexType>(T.getElementType())) { | ||
| auto ET = cast<FloatType>(CET.getElementType()); | ||
| std::complex<APFloat> values[] = { |
Member
There was a problem hiding this comment.
you need to use mlir::Complex not std::complex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
diff rules that use
HLOConstantFPin Enzyme-JAX are broken for complex numbers, due tomlir::enzyme::getConstantAttrnot being able to handle them.for example, the diff rule of
stablehlo.rsqrtis defined as the following:which works for real numbers. but for complex numbers, like the following example,
it errors:
we haven't checked this because we don't test complex numbers on diff rules that do not have a specific behaviour for them (i.e.
SelectIfComplex).this pr adds support for complex numbers in
getConstantAttr. the current semantics is to create aComplexAttror aDenseElementsAttrwithComplexTypeeltype with the givenvalueas the real part. not sure if we want to write a way to set the imaginary part.