Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug[next]: Fix gtfn code generation for negative literals #1511

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/gt4py/next/program_processors/codegens/gtfn/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def asfloat(value: str) -> str:
return value

def visit_Literal(self, node: gtfn_ir.Literal, **kwargs: Any) -> str:
# TODO(tehrengruber): isn't this wrong and int32 should be casted to an actual int32?
match pytype_to_cpptype(node.type):
case "float":
return self.asfloat(node.value) + "f"
Expand All @@ -111,7 +112,9 @@ def visit_Literal(self, node: gtfn_ir.Literal, **kwargs: Any) -> str:
IntegralConstant = as_fmt("{value}_c")

UnaryExpr = as_fmt("{op}({expr})")
BinaryExpr = as_fmt("({lhs}{op}{rhs})")
# add an extra space between the operators is needed such that `minus(1, -1)` does not get
# translated into `1--1`, but `1 - -1`
BinaryExpr = as_fmt("({lhs} {op} {rhs})")
TernaryExpr = as_fmt("({cond}?{true_expr}:{false_expr})")
CastExpr = as_fmt("static_cast<{new_dtype}>({obj_expr})")

Expand Down
Loading