Skip to content

Commit 581917b

Browse files
committed
Vendor s_ and index_exp
1 parent 5afc0e7 commit 581917b

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

torch_np/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from ._wrapper import * # isort: skip # XXX: currently this prevents circular imports
22
from . import random
33
from ._binary_ufuncs import *
4+
from ._detail._index_tricks import *
45
from ._detail._util import AxisError, UFuncTypeError
56
from ._dtypes import *
67
from ._getlimits import errstate, finfo, iinfo
@@ -16,8 +17,5 @@
1617
nan = float("nan")
1718
from math import pi # isort: skip
1819

19-
from numpy import s_ # isort: skip
20-
from numpy import index_exp # isort: skip
21-
2220
False_ = asarray(False, bool_)
2321
True_ = asarray(True, bool_)

torch_np/_detail/_index_tricks.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Vendored objects from numpy.lib.index_tricks
3+
"""
4+
__all__ = ["index_exp", "s_"]
5+
6+
7+
class IndexExpression:
8+
"""
9+
Written by Konrad Hinsen <[email protected]>
10+
last revision: 1999-7-23
11+
12+
Cosmetic changes by T. Oliphant 2001
13+
"""
14+
15+
def __init__(self, maketuple):
16+
self.maketuple = maketuple
17+
18+
def __getitem__(self, item):
19+
if self.maketuple and not isinstance(item, tuple):
20+
return (item,)
21+
else:
22+
return item
23+
24+
25+
index_exp = IndexExpression(maketuple=True)
26+
s_ = IndexExpression(maketuple=False)

0 commit comments

Comments
 (0)