[Builder] Add F64Type support and SinOp for math operations#548
Merged
chhzh123 merged 2 commits intocornell-zhang:mainfrom Feb 6, 2026
Merged
[Builder] Add F64Type support and SinOp for math operations#548chhzh123 merged 2 commits intocornell-zhang:mainfrom
chhzh123 merged 2 commits intocornell-zhang:mainfrom
Conversation
Add F64Type to the type check for scalar math operations so that float64 arguments are recognized alongside float32 and integer types. Also add math.SinOp to the supported operation map. These changes enable math operations (exp, log, sqrt, sin, cos, tan, etc.) to work with float64 types, and add sin() support for all float types. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends Allo’s IR builder to recognize float64 in scalar math op lowering and adds sin support via the MLIR math dialect, with new tests covering sin and other math/trig operations on float64.
Changes:
- Add
F64Typeto the scalar math-op type check inallo/ir/builder.py. - Add
"sin": math_d.SinOpto the scalar math operation map. - Add tests for
allo.sin()onfloat32/float64, plus additionalfloat64math/trig coverage.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
allo/ir/builder.py |
Expands scalar math-op lowering to accept f64 and adds sin lowering. |
tests/test_types.py |
Adds new regression tests for sin and other math/trig ops on float64. |
Comments suppressed due to low confidence (1)
allo/ir/builder.py:3126
opclscan beNonewhenfn_nameisn’t in the mapping, but this branch still unconditionally callsopcls(...), which will raise aTypeErrorinstead of the intended unsupported-function error. Add an explicit check foropcls is Noneand fall through to the later handling / raise a clearRuntimeErrorfor unsupported scalar math ops.
opcls = {
"exp": math_d.ExpOp,
"log": math_d.LogOp,
"log2": math_d.Log2Op,
"log10": math_d.Log10Op,
"sqrt": math_d.SqrtOp,
"sin": math_d.SinOp,
"cos": math_d.CosOp,
"tan": math_d.TanOp,
"tanh": math_d.TanhOp,
"power": math_d.PowFOp,
"abs": math_d.AbsIOp,
}.get(fn_name)
return opcls(
*[ASTTransformer.get_mlir_op_result(ctx, x) for x in new_args],
ip=ctx.get_ip(),
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add dtype assertions to float64 tests to ensure the pipeline does not silently downcast to float32. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4 tasks
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.
Summary
F64Typeto the type check for scalar math operations inbuilder.py, sofloat64arguments are recognized alongsidefloat32and integer typesmath.SinOpto the supported math operation map, enablingallo.sin()for all float typessin(float32 and float64) and float64 math/trig operationsSplit out from #287 per review feedback.
Test plan
test_sin_float32— verifiesallo.sin()works with float32 arraystest_sin_float64— verifiesallo.sin()works with float64 arraystest_float64_math_ops— verifiesallo.exp(),allo.log(),allo.sqrt()with float64test_float64_trig_ops— verifiesallo.sin(),allo.cos(),allo.tan()with float64🤖 Generated with Claude Code