def set_options(kernel, *args, **kwargs): """Return a new kernel with the options given as keyword arguments, or from a string representation passed in as the first (and only) positional argument. See also :class:`Options`. """ if args and kwargs: raise TypeError("cannot pass both positional and keyword arguments") new_opt = kernel.options.copy() if kwargs: from loopy.options import _apply_legacy_map, Options kwargs = _apply_legacy_map(Options._legacy_options_map, kwargs) for key, val in kwargs.items(): if not hasattr(new_opt, key): raise ValueError("unknown option '%s'" % key) setattr(new_opt, key, val) else: if len(args) != 1: raise TypeError("exactly one positional argument is required if " "no keyword args are given") arg, = args from loopy.options import make_options new_opt.update(make_options(arg)) return kernel.copy(options=new_opt)
def set_options(kernel, *args, **kwargs): """Return a new kernel with the options given as keyword arguments, or from a string representation passed in as the first (and only) positional argument. See also :class:`Options`. """ if args and kwargs: raise TypeError("cannot pass both positional and keyword arguments") new_opt = kernel.options.copy() if kwargs: from loopy.options import _apply_legacy_map, Options kwargs = _apply_legacy_map(Options._legacy_options_map, kwargs) for key, val in six.iteritems(kwargs): if not hasattr(new_opt, key): raise ValueError("unknown option '%s'" % key) setattr(new_opt, key, val) else: if len(args) != 1: raise TypeError("exactly one positional argument is required if " "no keyword args are given") arg, = args from loopy.options import make_options new_opt.update(make_options(arg)) return kernel.copy(options=new_opt)