-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69cddd5
commit 58cdcd6
Showing
2 changed files
with
18 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,19 @@ | |
# Licensed under the MIT License. | ||
"""Common operators shared in the torchlib library.""" | ||
|
||
# mypy: disable-error-code="misc,arg-type,type-arg,valid-type,assignment,return-value" | ||
from typing import TYPE_CHECKING | ||
|
||
import onnxscript | ||
import onnxscript.values | ||
from onnxscript import BOOL, INT64 | ||
from onnxscript import BOOL, INT64, ir | ||
from onnxscript import opset18 as op | ||
from onnxscript.function_libs.torch_lib import _constants, tensor_typing | ||
from onnxscript.function_libs.torch_lib.tensor_typing import RealType | ||
from onnxscript.onnx_types import COMPLEX64, COMPLEX128, DOUBLE, FLOAT | ||
from onnxscript.onnx_types import COMPLEX64, COMPLEX128, DOUBLE, FLOAT, TensorType | ||
|
||
if TYPE_CHECKING: | ||
import onnx | ||
|
||
COMPLEX64_TYPE = COMPLEX64.dtype | ||
COMPLEX128_TYPE = COMPLEX128.dtype | ||
|
@@ -56,3 +62,10 @@ def cast_to(a: RealType, dtype: int) -> RealType: | |
result = op.Cast(a, to=dtype) | ||
|
||
return result | ||
|
||
|
||
def constant(array, dtype: int | onnx.TensorProto.DataType | ir.DataType) -> TensorType: | ||
Check failure Code scanning / lintrunner PYLINT/E0601 Error
Using variable 'onnx' before assignment (used-before-assignment)
See used-before-assignment. To disable, use # pylint: disable=used-before-assignment |
||
"""Utility for creating a constant tensor.""" | ||
return op.Constant( | ||
value=ir.serde.serialize_tensor(ir.tensor(array, dtype=ir.DataType(dtype))) | ||
) |
This file contains 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