Skip to content

Commit 5604758

Browse files
committed
MAINT: IndexExpression into _funcs.py from _detail/_index_tricks.py
1 parent 03ed196 commit 5604758

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

torch_np/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from . import random
22
from ._binary_ufuncs import *
3-
from ._detail._index_tricks import *
43
from ._detail._util import AxisError, UFuncTypeError
54
from ._dtypes import *
65
from ._funcs import *

torch_np/_detail/_index_tricks.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

torch_np/_funcs.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,3 +1871,30 @@ def isscalar(a: ArrayLike):
18711871
if a is False:
18721872
return a
18731873
return a.numel() == 1
1874+
1875+
1876+
"""
1877+
Vendored objects from numpy.lib.index_tricks
1878+
"""
1879+
1880+
1881+
class IndexExpression:
1882+
"""
1883+
Written by Konrad Hinsen <[email protected]>
1884+
last revision: 1999-7-23
1885+
1886+
Cosmetic changes by T. Oliphant 2001
1887+
"""
1888+
1889+
def __init__(self, maketuple):
1890+
self.maketuple = maketuple
1891+
1892+
def __getitem__(self, item):
1893+
if self.maketuple and not isinstance(item, tuple):
1894+
return (item,)
1895+
else:
1896+
return item
1897+
1898+
1899+
index_exp = IndexExpression(maketuple=True)
1900+
s_ = IndexExpression(maketuple=False)

torch_np/tests/numpy_tests/lib/test_index_tricks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
)
1414

1515
from torch_np import diag_indices, diag_indices_from, fill_diagonal
16-
from torch_np._detail._index_tricks import index_exp, s_
16+
from torch_np import index_exp, s_
1717

1818

1919
@pytest.mark.xfail(reason='unravel_index not implemented')

0 commit comments

Comments
 (0)