Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make to_factorized_noisy work with sequential links #489

Merged
merged 4 commits into from
Jun 28, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix logic for replacing links in additional attrs
  • Loading branch information
toslunar committed Jun 26, 2019
commit bc038401b5d6e5a64f626be04d0367a51480f172
13 changes: 11 additions & 2 deletions chainerrl/links/noisy_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,14 @@ def _map_links(func, link):
children[i].name = str(i)

if isinstance(link, Sequence):
# assumes i-th layer corresponds with i-th child
link.layers[i] = new_child
_replace_unique_item(link.layers, child, new_child)
# Check chainer.Sequential if it exists.
sequential_class = getattr(chainer, 'Sequential', ())
if isinstance(link, sequential_class):
prabhatnagarajan marked this conversation as resolved.
Show resolved Hide resolved
_replace_unique_item(link._layers, child, new_child)


def _replace_unique_item(xs, old, new):
indices = [i for i, x in enumerate(xs) if x is old]
assert len(indices) == 1
xs[indices[0]] = new