Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6c85cd3

Browse files
committedFeb 21, 2023
ENH: add array.view, test_numeric/TestBoolCmp
1 parent 2240211 commit 6c85cd3

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed
 

‎torch_np/_ndarray.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ def copy(self, order="C"):
159159
tensor = self._tensor.clone()
160160
return ndarray._from_tensor_and_base(tensor, None)
161161

162+
def view(self, dtype):
163+
# XXX: 1) make dtype_to_torch decorator understand positional args
164+
# 2) rid of .base and _from_tensor_and_base
165+
torch_dtype = _dtypes.dtype(dtype).torch_dtype
166+
tview = self._tensor.view(torch_dtype)
167+
return ndarray._from_tensor_and_base(tview, self)
168+
162169
def tolist(self):
163170
return self._tensor.tolist()
164171

‎torch_np/tests/numpy_tests/core/test_numeric.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,6 @@ def test_logical_and_or_xor(self):
453453
assert_array_equal(self.im ^ False, self.im)
454454

455455

456-
@pytest.mark.xfail(reason="TODO: needs fancy indexing")
457456
class TestBoolCmp:
458457
def setup_method(self):
459458
self.f = np.ones(256, dtype=np.float32)
@@ -515,6 +514,7 @@ def test_float(self):
515514
r3 = 0 != self.f[i:]
516515
assert_array_equal(r, r2)
517516
assert_array_equal(r, r3)
517+
518518
# check bool == 0x1
519519
assert_array_equal(r.view(np.int8), r.astype(np.int8))
520520
assert_array_equal(r2.view(np.int8), r2.astype(np.int8))
@@ -541,6 +541,7 @@ def test_double(self):
541541
r3 = 0 != self.d[i:]
542542
assert_array_equal(r, r2)
543543
assert_array_equal(r, r3)
544+
544545
# check bool == 0x1
545546
assert_array_equal(r.view(np.int8), r.astype(np.int8))
546547
assert_array_equal(r2.view(np.int8), r2.astype(np.int8))

0 commit comments

Comments
 (0)
Please sign in to comment.