Skip to content

[torchlib] Simplify aten_trunc implementation #2057

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

Merged
merged 1 commit into from
Feb 14, 2025
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
7 changes: 2 additions & 5 deletions onnxscript/function_libs/torch_lib/ops/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8385,11 +8385,8 @@ def aten_triu_indices(row: int, col: int, offset: int = 0) -> TensorType:
@torch_op("aten::trunc")
def aten_trunc(self: TFloat) -> TFloat:
"""trunc(Tensor self) -> Tensor"""

# Reference https://github.com/onnx/onnx/issues/4588#issuecomment-1463970126
integer_parts = op.Floor(op.Abs(self))
is_negative = op.Less(self, 0.0)
return op.Where(is_negative, op.Neg(integer_parts), integer_parts)
# Reference https://github.com/onnx/onnx/issues/4588#issuecomment-2658170591
return op.Floor(op.Abs(self)) * op.Sign(self)


@torch_op("aten::type_as", trace_only=True)
Expand Down
Loading