Skip to content

Commit a855a37

Browse files
committed
BUG: fix out1, out2 logic in divmod
1 parent b8ba2ca commit a855a37

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

torch_np/_ufuncs.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,14 @@ def divmod(
128128
num_outs = sum(x is not None for x in [out1, out2])
129129
if num_outs == 1:
130130
raise ValueError("both out1 and out2 need to be provided")
131+
elif num_outs == 2:
132+
o1, o2 = out
133+
if o1 is not None or o2 is not None:
134+
raise TypeError(
135+
"cannot specify 'out' as both a positional and keyword argument"
136+
)
131137
else:
132138
out1, out2 = out
133-
if num_outs == 2:
134-
if out1 is not None or out2 is not None:
135-
raise TypeError(
136-
"cannot specify 'out' as both a positional and keyword argument"
137-
)
138139

139140
tensors = _ufunc_preprocess(
140141
(x1, x2), True, casting, order, dtype, subok, signature, extobj

torch_np/tests/test_basic.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,18 @@ def test_divmod_out_list(self):
475475
assert quot is out[0]
476476
assert rem is out[1]
477477

478+
@pytest.mark.xfail(reason="out1, out2 not implemented")
479+
def test_divmod_pos_only(self):
480+
x1 = [4, 5, 6]
481+
x2 = [2, 1, 2]
482+
483+
out1, out2 = w.empty_like(x1), w.empty_like(x1)
484+
485+
quot, rem = w.divmod(x1, x2, out1, out2)
486+
487+
assert quot is out1
488+
assert rem is out2
489+
478490
def test_divmod_no_out(self):
479491
# check that the out= machinery handles no out at all
480492
x1 = w.array([4, 5, 6])

0 commit comments

Comments
 (0)