* Parameters: Added _all_keys_() and _flatten_() methods.

Warning: These are expensive, and not for general use.
master
Wirawan Purwanto 12 years ago
parent 5a84a98b84
commit 6709679af9
  1. 30
      params/params_flat.py

@ -89,6 +89,8 @@ class Parameters(dict):
return dict.__contains__(self.ref(), key) return dict.__contains__(self.ref(), key)
def __getitem__(self, key): def __getitem__(self, key):
return dict.__getitem__(self.ref(), key) return dict.__getitem__(self.ref(), key)
def __iter__(self):
return dict.__iter__(self.ref())
def __init__(self, *_override_dicts_, **_opts_): def __init__(self, *_override_dicts_, **_opts_):
""" """
@ -251,6 +253,34 @@ class Parameters(dict):
return self[key] return self[key]
except KeyError: except KeyError:
return default return default
def _all_keys_(self, sort=True):
"""Returns a list of all keys containing in the parameter space.
Warning: This can be an expensive operation!"""
K = set()
_list_ = self.__dict__["_list_"]
for D in _list_:
try:
K.update(D.keys())
except:
K.update(D.ref().keys())
K_list = [ k for k in K ]
if sort:
K_list.sort()
return K_list
def _flatten_(self, sort=True):
"""Returns a flatten dict of all the (most overriding) key-value pairs
in the parameter space.
Warning: This can be an expensive operation!"""
K = dict()
_list_ = self.__dict__["_list_"]
for D in _list_[::-1]:
K.update([ (k,D[k]) for k in D ])
return K
def _update_(self, srcdict): def _update_(self, srcdict):
"""Updates the most overriding parameters with key-value pairs from """Updates the most overriding parameters with key-value pairs from
srcdict. srcdict.

Loading…
Cancel
Save