extend --convert-elementwise-to-affine
to support ops with scalar operands
#769
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.
As originally pointed out in #143 and recently mentioned in #763, the
--convert-elementwise-to-affine
pass did not handle ops with "mixed" tensor/scalar operands, such aspolynomial.mul_scalar
.It turns out this was a much easier fix than anticipated, at least for
mul_scalar
asElementwiseMappable
does not (as I wrongly assumed) implySameOperandsAndResultType
. In fact, there was already a ToDo (#534) that suggested the three-character change necessary to make this work.However, this still does not work for
polynomial.ntt/intt
, asElementwiseMappable
does require all tensor operands to agree, and that wouldn't hold for a "tensorized" ntt/intt (cf. #143 (comment))With this change, any
ElementwiseMappable
operation with at least one tensor operand is converted into anaffine.for
, and tensor operands are replaced withtensor.extract
s, while scalar operands are left unmodified. This result is probably what one would expect (despite the semantics for this not being formally noted anywhere upstream, afaik), effectively "broadcasting" the scalar to the tensor operand(s).PS: I noticed the tests for this pass also had some mostly meaningless "expected output" "tests" in it from development so I used the opportunity to remove those.
Resolves #534
(Mostly, see #763 (comment)) Resolves #143