示例#1
0
    def all_defaults(nengo_cls=None):
        """Look up all of the default values in the current context.

        Parameters
        ----------
        nengo_cls : class, optional
            If specified, only the defaults for a particular class will
            be returned. If not specified, the defaults for all configured
            classes will be returned.

        Returns
        -------
        str
        """
        lines = []
        if nengo_cls is None:
            all_configured = set()
            for config in Config.context:
                all_configured.update(key for key in config.params
                                      if inspect.isclass(key))
            lines.extend([Config.all_defaults(key) for key in all_configured])
        else:
            lines.append(f"Current defaults for {nengo_cls.__name__}:")
            for attr in dir(nengo_cls):
                desc = getattr(nengo_cls, attr)
                if is_param(desc) and desc.configurable:
                    val = Config.default(nengo_cls, attr)
                    lines.append(f"  {attr}: {val}")
        return "\n".join(lines)
示例#2
0
文件: config.py 项目: JolyZhang/nengo
 def __init__(self, configures):
     assert inspect.isclass(configures)
     self._configures = configures
     self._extraparams = {}
     self._default_params = tuple(
         attr for attr in dir(self._configures)
         if is_param(getattr(self._configures, attr)))
示例#3
0
 def __init__(self, configures):
     assert inspect.isclass(configures)
     self._configures = configures
     self._extra_params = {}
     self._default_params = tuple(
         attr for attr in dir(self._configures)
         if is_param(getattr(self._configures, attr)))
示例#4
0
文件: config.py 项目: JolyZhang/nengo
    def all_defaults(nengo_cls=None):
        """Look up all of the default values in the current context.

        Parameters
        ----------
        nengo_cls : class, optional
            If specified, only the defaults for a particular class will
            be returned. If not specified, the defaults for all configured
            classes will be returned.

        Returns
        -------
        str
        """
        lines = []
        if nengo_cls is None:
            all_configured = set()
            for config in Config.context:
                all_configured.update(key for key in config.params
                                      if inspect.isclass(key))
            lines.extend([Config.all_defaults(key) for key in all_configured])
        else:
            lines.append("Current defaults for %s:" % nengo_cls.__name__)
            for attr in dir(nengo_cls):
                desc = getattr(nengo_cls, attr)
                if is_param(desc) and desc.configurable:
                    val = Config.default(nengo_cls, attr)
                    lines.append("  %s: %s" % (attr, val))
        return "\n".join(lines)
示例#5
0
 def set_param(self, key, value):
     if not is_param(value):
         raise ConfigError(f"'{key}' is not a parameter")
     elif key in dir(self._configures):
         raise ConfigError(
             f"'{key}' is already a parameter in {self._configures.__name__}. "
             "Please choose a different name.")
     self._extra_params[key] = value
示例#6
0
文件: config.py 项目: tisana69/nengo
 def set_param(self, key, value):
     if not is_param(value):
         raise ConfigError("'%s' is not a parameter" % key)
     elif key in dir(self._configures):
         raise ConfigError("'%s' is already a parameter in %s. "
                           "Please choose a different name." %
                           (key, self._configures.__name__))
     self._extra_params[key] = value
示例#7
0
文件: config.py 项目: bopo/nengo
 def set_param(self, key, value):
     if not is_param(value):
         raise TypeError("%s is not a parameter" % key)
     elif key in dir(self._configures):
         raise ValueError("%s is already a parameter in %s. "
                          "Please choose a different name."
                          % (key, self._configures.__name__))
     self._extraparams[key] = value
示例#8
0
文件: base.py 项目: CaiZhongda/nengo
 def param_list(cls):
     """Returns a list of parameter names that can be set."""
     return (attr for attr in dir(cls) if is_param(getattr(cls, attr)))
示例#9
0
 def param_list(cls):
     """Returns a list of parameter names that can be set."""
     return (attr for attr in dir(cls) if is_param(getattr(cls, attr)))
示例#10
0
文件: config.py 项目: bopo/nengo
 def default_params(self):
     return (attr for attr in dir(self._configures)
             if is_param(getattr(self._configures, attr)))
示例#11
0
 def default_params(self):
     return (attr for attr in dir(self._configures)
             if is_param(getattr(self._configures, attr)))