Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
fix sequential (#10554)
Browse files Browse the repository at this point in the history
  • Loading branch information
piiswrong authored Apr 15, 2018
1 parent 5d63151 commit 38b23ac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions python/mxnet/gluon/nn/basic_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __repr__(self):
modstr=modstr)

def __getitem__(self, key):
return self._children[str(key)]
return list(self._children.values())[key]

def __len__(self):
return len(self._children)
Expand Down Expand Up @@ -119,7 +119,7 @@ def __repr__(self):
modstr=modstr)

def __getitem__(self, key):
return self._children[str(key)]
return list(self._children.values())[key]

def __len__(self):
return len(self._children)
Expand Down
17 changes: 17 additions & 0 deletions tests/python/unittest/test_gluon.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,23 @@ def __init__(self, **kwargs):
model.collect_params()
assert len(w) == 0

def check_sequential(net):
dense1 = gluon.nn.Dense(10)
net.add(dense1)
dense2 = gluon.nn.Dense(10)
net.add(dense2)
dense3 = gluon.nn.Dense(10)
net.add(dense3)

assert net[1] is dense2
assert net[-1] is dense3
slc = net[1:3]
assert len(slc) == 2 and slc[0] is dense2 and slc[1] is dense3

@with_seed()
def test_sequential():
check_sequential(gluon.nn.Sequential())
check_sequential(gluon.nn.HybridSequential())

@with_seed()
def test_sequential_warning():
Expand Down

0 comments on commit 38b23ac

Please sign in to comment.