Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 9 additions & 11 deletions onnxscript/function_libs/torch_lib/ops/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,18 @@
Rank = common_ops.Rank


@torch_op("aten::_local_scalar_dense")
def aten__local_scalar_dense(self: Union[FLOAT16, FLOAT, DOUBLE, BFLOAT16]) -> FLOAT:
@torch_op("aten::_local_scalar_dense", trace_only=True)
def aten__local_scalar_dense(self: TensorType) -> TensorType:
"""_local_scalar_dense(Tensor self) -> Scalar"""

# Return the first element in tensor as a scalar.
return op.Cast(op.Gather(op.Reshape(self, [-1]), 0), to=FLOAT.dtype)


@torch_op("aten::_local_scalar_dense")
def aten__local_scalar_dense_int(self: IntType) -> INT64:
"""_local_scalar_dense(Tensor self) -> Scalar"""

# Return the first element in tensor as a scalar.
return op.Cast(op.Gather(op.Reshape(self, [-1]), 0), to=INT64.dtype)
if self.dtype.is_floating_point():
dtype = ir.DataType.FLOAT

Check warning on line 70 in onnxscript/function_libs/torch_lib/ops/core.py

View check run for this annotation

Codecov / codecov/patch

onnxscript/function_libs/torch_lib/ops/core.py#L70

Added line #L70 was not covered by tests
elif self.dtype == ir.DataType.BOOL:
dtype = ir.DataType.BOOL

Check warning on line 72 in onnxscript/function_libs/torch_lib/ops/core.py

View check run for this annotation

Codecov / codecov/patch

onnxscript/function_libs/torch_lib/ops/core.py#L72

Added line #L72 was not covered by tests
else:
dtype = ir.DataType.INT64
return op.Cast(op.Gather(op.Reshape(self, [-1]), 0), to=dtype)

Check warning on line 75 in onnxscript/function_libs/torch_lib/ops/core.py

View check run for this annotation

Codecov / codecov/patch

onnxscript/function_libs/torch_lib/ops/core.py#L74-L75

Added lines #L74 - L75 were not covered by tests


@torch_op("aten::_log_softmax", trace_only=True)
Expand Down
2 changes: 1 addition & 1 deletion tests/function_libs/torch_lib/extra_opinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2308,7 +2308,7 @@ def __init__(self):
opinfo_core.OpInfo(
"ops.aten._local_scalar_dense",
aten_name="_local_scalar_dense",
dtypes=common_dtype.all_types(),
dtypes=common_dtype.all_types_and(torch.bool),
sample_inputs_func=sample_inputs__local_scalar_dense,
supports_out=False,
),
Expand Down
Loading