Caffe2 - Python API
A deep learning, cross platform ML framework
nested_dict.py
1 # TODO: refactor nested_dict into common library with ATen
2 class nested_dict(object):
3  """
4  A nested dict is a dictionary with a parent. If key lookup fails,
5  it recursively continues into the parent. Writes always happen to
6  the top level dict.
7  """
8 
9  def __init__(self, base, parent):
10  self.base, self.parent = base, parent
11 
12  def __contains__(self, item):
13  return item in self.base or item in self.parent
14 
15  def __getitem__(self, x):
16  r = self.base.get(x)
17  if r is not None:
18  return r
19  return self.parent[x]