Skip to content

Commit

Permalink
Allow single dimension slices in mgrid and ogrid
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonwillard committed Aug 24, 2020
1 parent ea65b92 commit 7f1ab2a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/tensor/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6729,10 +6729,12 @@ def setup_method(self):

def test_mgrid_numpy_equiv(self):
nmgrid = (
[np.mgrid[0:1:0.1]],
np.mgrid[0:1:0.1, 1:10:1.0, 10:100:10.0],
np.mgrid[0:2:1, 1:10:1, 10:100:10],
)
tmgrid = (
[mgrid[0:1:0.1]],
mgrid[0:1:0.1, 1:10:1.0, 10:100:10.0],
mgrid[0:2:1, 1:10:1, 10:100:10],
)
Expand All @@ -6742,10 +6744,12 @@ def test_mgrid_numpy_equiv(self):

def test_ogrid_numpy_equiv(self):
nogrid = (
[np.ogrid[0:1:0.1]],
np.ogrid[0:1:0.1, 1:10:1.0, 10:100:10.0],
np.ogrid[0:2:1, 1:10:1, 10:100:10],
)
togrid = (
[ogrid[0:1:0.1]],
ogrid[0:1:0.1, 1:10:1.0, 10:100:10.0],
ogrid[0:2:1, 1:10:1, 10:100:10],
)
Expand Down
4 changes: 4 additions & 0 deletions theano/tensor/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5937,6 +5937,10 @@ def __init__(self, sparse=False):

def __getitem__(self, *args):

if isinstance(args[0], slice):
sl = args[0]
return arange(sl.start or 0, sl.stop, sl.step or 1)

ndim = len(args[0])
for sl in args[0]:
if isinstance(sl.step, python_complex):
Expand Down

0 comments on commit 7f1ab2a

Please sign in to comment.