Skip to content

Commit 64cb033

Browse files
committed
add single element 1d tensor case
1 parent 596315b commit 64cb033

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

core/tests/dynamo/importer_basic_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,28 @@ def foo():
118118
opt_foo()
119119
print(opt_foo())
120120

121+
def testSingleElementTensor(self):
122+
"""
123+
Test whether single element tensors are properly converted to scalars
124+
"""
125+
126+
def foo():
127+
a = torch.tensor([0], dtype=torch.int32)
128+
b = torch.tensor([0], dtype=torch.int64)
129+
c = torch.tensor([0], dtype=torch.float32)
130+
d = torch.tensor([0], dtype=torch.float64)
131+
e = torch.tensor([0], dtype=torch.complex64)
132+
f = torch.tensor([0], dtype=torch.complex128)
133+
g = torch.tensor([0], dtype=torch.bool)
134+
h = torch.tensor([0], dtype=torch.uint8)
135+
i = torch.tensor([0], dtype=torch.int8)
136+
j = torch.tensor([0], dtype=torch.int16)
137+
return a[0], b[0], c[0], d[0], e[0], f[0], g[0], h[0], i[0], j[0]
138+
139+
140+
opt_foo = torch.compile(foo, backend=create_backend())
141+
opt_foo()
142+
121143
def testPromoteScalarTensor(self):
122144
"""
123145
Test whether scalar arguments are properly promoted to 0-rank Tensors for torch ops with no Scalar equivalent

0 commit comments

Comments
 (0)