Skip to content

aten_floor_divide_int may cause precision loss #2589

@wodesuck

Description

@wodesuck

Current implement will first cast inputs to float, do a true divide then floor. If inputs are big int64, it may case precision loss.

@torch_op("aten::floor_divide", trace_only=True)
def aten_floor_divide_int(self: TInt, other: TInt) -> TInt:
    """floor_divide(Tensor self, Tensor other) -> Tensor"""

    # TODO(justinchuby): This can be simplified if we can constrain the
    # inputs to be positive integers. Consider how we can embed constraints in the model.
    dtype = self.dtype
    self = op.Cast(self, to=FLOAT.dtype)
    other = op.Cast(other, to=FLOAT.dtype)
    result = op.Floor(op.Div(self, other))
    return op.Cast(result, to=dtype)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions