code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
config_path = attributes.get('config_path')
tokens = {}
def build_config_key(value_def, config_key):
key = value_def.config_key or config_key
return '%s.%s' % (config_path, key) if config_path else key
def build_token(name, value_def):
confi... | def build_attributes(cls, attributes, namespace) | Return an attributes dictionary with ValueTokens replaced by a
property which returns the config value. | 3.724664 | 3.478972 | 1.070622 |
def cache_wrapper(func):
@functools.wraps(func)
def inner_wrapper(self, *args, **kwargs):
value = getattr(self, cache_name, UndefToken)
if value != UndefToken:
return value
ret = func(self, *args, **kwargs)
setattr(self, cache_nam... | def cache_as_field(cache_name) | Cache a functions return value as the field 'cache_name'. | 2.256817 | 2.271019 | 0.993746 |
value = proxy.namespace.get(proxy.config_key, proxy.default)
if value is UndefToken:
raise errors.ConfigurationError("%s is missing value for: %s" %
(proxy.namespace, proxy.config_key))
try:
return proxy.validator(value)
except errors.ValidationError as e:
raise... | def extract_value(proxy) | Given a value proxy type, Retrieve a value from a namespace, raising
exception if no value is found, or the value does not validate. | 3.730338 | 3.516491 | 1.060812 |
def reader(config_key, default=UndefToken, namespace=None):
config_namespace = config.get_namespace(namespace or reader_namespace)
return validator(_read_config(config_key, config_namespace, default))
return reader | def build_reader(validator, reader_namespace=config.DEFAULT) | A factory method for creating a custom config reader from a validation
function.
:param validator: a validation function which acceptance one argument (the
configuration value), and returns that value casted to
the appropriate type.
:param reader_namespace: the d... | 5.592813 | 6.53708 | 0.855552 |
names = configuration_namespaces.keys() if all_names else [name]
for name in names:
yield get_namespace(name) | def get_namespaces_from_names(name, all_names) | Return a generator which yields namespace objects. | 6.941687 | 5.105514 | 1.359645 |
if name not in configuration_namespaces:
configuration_namespaces[name] = ConfigNamespace(name)
return configuration_namespaces[name] | def get_namespace(name) | Return a :class:`ConfigNamespace` by name, creating the
namespace if it does not exist. | 4.074572 | 3.295712 | 1.236325 |
for namespace in get_namespaces_from_names(name, all_names):
for value_proxy in namespace.get_value_proxies():
value_proxy.reset() | def reload(name=DEFAULT, all_names=False) | Reload one or all :class:`ConfigNamespace`. Reload clears the cache of
:mod:`staticconf.schema` and :mod:`staticconf.getters`, allowing them to
pickup the latest values in the namespace.
Defaults to reloading just the DEFAULT namespace.
:param name: the name of the :class:`ConfigNamespace` to reload
... | 5.695298 | 10.150599 | 0.56108 |
for namespace in get_namespaces_from_names(name, all_names):
all(value_proxy.get_value() for value_proxy in namespace.get_value_proxies()) | def validate(name=DEFAULT, all_names=False) | Validate all registered keys after loading configuration.
Missing values or values which do not pass validation raise
:class:`staticconf.errors.ConfigurationError`. By default only validates
the `DEFAULT` namespace.
:param name: the namespace to validate
:type name: string
:param all_names: i... | 6.653617 | 7.73291 | 0.860429 |
duplicate_keys = set(base_conf) & set(config_data)
if not duplicate_keys:
return
msg = "Duplicate keys in config: %s" % duplicate_keys
if raise_error:
raise errors.ConfigurationError(msg)
log.info(msg)
return True | def has_duplicate_keys(config_data, base_conf, raise_error) | Compare two dictionaries for duplicate keys. if raise_error is True
then raise on exception, otherwise log return True. | 2.90595 | 2.637082 | 1.101957 |
def compare_func(filename):
try:
return os.path.getmtime(filename)
except OSError:
if err_logger is not None:
err_logger(filename)
return -1
return compare_func | def build_compare_func(err_logger=None) | Returns a compare_func that can be passed to MTimeComparator.
The returned compare_func first tries os.path.getmtime(filename),
then calls err_logger(filename) if that fails. If err_logger is None,
then it does nothing. err_logger is always called within the context of
an OSError raised by os.path.getm... | 2.713017 | 2.133706 | 1.271505 |
config_dict = {}
for dotted_key, value in self.get_config_values().items():
subkeys = dotted_key.split('.')
d = config_dict
for key in subkeys:
d = d.setdefault(key, value if key == subkeys[-1] else {})
return config_dict | def get_config_dict(self) | Reconstruct the nested structure of this object's configuration
and return it as a dict. | 3.227608 | 3.009708 | 1.072399 |
def format_desc(desc):
return "%s (Type: %s, Default: %s)\n%s" % (
desc.name,
desc.validator.__name__.replace('validate_', ''),
desc.default,
desc.help or '')
def format_namespace(key, desc_list):
... | def view_help(self) | Return a help message describing all the statically configured keys. | 4.1055 | 3.907318 | 1.050721 |
if (force or self.should_check) and self.file_modified():
return self.reload() | def reload_if_changed(self, force=False) | If the file(s) being watched by this object have changed,
their configuration will be loaded again using `config_loader`.
Otherwise this is a noop.
:param force: If True ignore the `min_interval` and proceed to
file modified comparisons. To force a reload use
:func:`rel... | 10.047168 | 10.602758 | 0.947599 |
watcher = ConfigurationWatcher(
build_loader_callable(loader_func, filename, namespace=namespace),
filename,
min_interval=min_interval,
reloader=ReloadCallbackChain(namespace=namespace),
comparators=comparators,
)
watcher.load_... | def load(
cls,
filename,
namespace,
loader_func,
min_interval=0,
comparators=None,
) | Create a new :class:`ConfigurationWatcher` and load the initial
configuration by calling `loader_func`.
:param filename: a filename or list of filenames to monitor for changes
:param namespace: the name of a namespace to use when loading
configuration. All config data ... | 6.22314 | 7.221387 | 0.861765 |
if isinstance(value, six.string_types):
msg = "Invalid iterable of type(%s): %s"
raise ValidationError(msg % (type(value), value))
try:
return iterable_type(value)
except TypeError:
raise ValidationError("Invalid iterable: %s" % (value)) | def _validate_iterable(iterable_type, value) | Convert the iterable to iterable_type, or raise a Configuration
exception. | 3.323351 | 3.270536 | 1.016149 |
def validate_list_of_type(value):
return [item_validator(item) for item in validate_list(value)]
return validate_list_of_type | def build_list_type_validator(item_validator) | Return a function which validates that the value is a list of items
which are validated using item_validator. | 3.400809 | 3.061677 | 1.110767 |
def validate_mapping(value):
return dict(item_validator(item) for item in validate_list(value))
return validate_mapping | def build_map_type_validator(item_validator) | Return a function which validates that the value is a mapping of
items. The function should return pairs of items that will be
passed to the `dict` constructor. | 5.218432 | 4.235464 | 1.23208 |
namespace.register_proxy(value_proxy)
config.config_help.add(
value_proxy.config_key, value_proxy.validator, value_proxy.default,
namespace.get_name(), help_text) | def register_value_proxy(namespace, value_proxy, help_text) | Register a value proxy with the namespace, and add the help_text. | 5.6459 | 5.176255 | 1.090731 |
def proxy_register(key_name, default=UndefToken, help=None, namespace=None):
name = namespace or getter_namespace or config.DEFAULT
namespace = config.get_namespace(name)
return proxy_factory.build(validator, namespace, key_name, default, help)
return proxy_register | def build_getter(validator, getter_namespace=None) | Create a getter function for retrieving values from the config cache.
Getters will default to the DEFAULT namespace. | 7.832561 | 7.403394 | 1.057969 |
proxy_attrs = validator, namespace, config_key, default
proxy_key = repr(proxy_attrs)
if proxy_key in self.proxies:
return self.proxies[proxy_key]
value_proxy = proxy.ValueProxy(*proxy_attrs)
register_value_proxy(namespace, value_proxy, help)
return ... | def build(self, validator, namespace, config_key, default, help) | Build or retrieve a ValueProxy from the attributes. Proxies are
keyed using a repr because default values can be mutable types. | 3.783701 | 2.861487 | 1.322285 |
A = 0.01 * niter
if bounds is not None:
bounds = np.asarray(bounds)
project = lambda x: np.clip(x, bounds[:, 0], bounds[:, 1])
if args is not None:
# freeze function arguments
def funcf(x, **kwargs):
return func(x, *args, **kwargs)
N = len(x0)
x = ... | def minimizeSPSA(func, x0, args=(), bounds=None, niter=100, paired=True,
a=1.0, alpha=0.602, c=1.0, gamma=0.101,
disp=False, callback=None) | Minimization of an objective function by a simultaneous perturbation
stochastic approximation algorithm.
This algorithm approximates the gradient of the function by finite differences
along stochastic directions Deltak. The elements of Deltak are drawn from
+- 1 with probability one half. The gradient ... | 2.940775 | 2.731941 | 1.076442 |
search = True
# check whether function is ascending or not
if ascending is None:
if errorcontrol:
testkwargs.update(dict(type_='smaller', force=True))
fa = func.test0(a, **testkwargs)
fb = func.test0(b, **testkwargs)
else:
fa = func(a) < 0... | def bisect(func, a, b, xtol=1e-6, errorcontrol=True,
testkwargs=dict(), outside='extrapolate',
ascending=None,
disp=False) | Find root by bysection search.
If the function evaluation is noisy then use `errorcontrol=True` for adaptive
sampling of the function during the bisection search.
Parameters
----------
func: callable
Function of which the root should be found. If `errorcontrol=True`
then the functi... | 3.27232 | 3.079255 | 1.062699 |
f1, f1se = self(x1)
f2, f2se = self(x2)
if self.paired:
fx1 = np.array(self.cache[tuple(x1)])
fx2 = np.array(self.cache[tuple(x2)])
diffse = np.std(fx1-fx2, ddof=1)/self.N**.5
return diffse
else:
return (f1se**2 + f2s... | def diffse(self, x1, x2) | Standard error of the difference between the function values at x1 and x2 | 3.636483 | 3.215087 | 1.131068 |
p[0] = Document(definitions=[Query(selections=p[1])] + p[2]) | def p_document_shorthand_with_fragments(self, p) | document : selection_set fragment_list | 12.119683 | 7.45759 | 1.625148 |
p[0] = self.operation_cls(p[1])(
selections=p[5],
name=p[2],
variable_definitions=p[3],
directives=p[4],
) | def p_operation_definition1(self, p) | operation_definition : operation_type name variable_definitions directives selection_set | 6.078919 | 3.551589 | 1.711605 |
p[0] = self.operation_cls(p[1])(
selections=p[4],
name=p[2],
variable_definitions=p[3],
) | def p_operation_definition2(self, p) | operation_definition : operation_type name variable_definitions selection_set | 7.40837 | 4.371741 | 1.694604 |
p[0] = self.operation_cls(p[1])(
selections=p[4],
name=p[2],
directives=p[3],
) | def p_operation_definition3(self, p) | operation_definition : operation_type name directives selection_set | 7.238729 | 4.544209 | 1.592957 |
p[0] = self.operation_cls(p[1])(selections=p[3], name=p[2]) | def p_operation_definition4(self, p) | operation_definition : operation_type name selection_set | 10.383045 | 6.241528 | 1.663542 |
p[0] = self.operation_cls(p[1])(
selections=p[4],
variable_definitions=p[2],
directives=p[3],
) | def p_operation_definition5(self, p) | operation_definition : operation_type variable_definitions directives selection_set | 7.639797 | 4.154393 | 1.838968 |
p[0] = self.operation_cls(p[1])(
selections=p[3],
variable_definitions=p[2],
) | def p_operation_definition6(self, p) | operation_definition : operation_type variable_definitions selection_set | 10.220458 | 5.330503 | 1.917353 |
p[0] = self.operation_cls(p[1])(
selections=p[3],
directives=p[2],
) | def p_operation_definition7(self, p) | operation_definition : operation_type directives selection_set | 10.980713 | 5.668335 | 1.937203 |
p[0] = Field(name=p[2], alias=p[1], arguments=p[3], directives=p[4],
selections=p[5]) | def p_field_all(self, p) | field : alias name arguments directives selection_set | 5.093054 | 2.889275 | 1.762744 |
p[0] = Field(name=p[1], arguments=p[2], directives=p[3],
selections=p[5]) | def p_field_optional1_1(self, p) | field : name arguments directives selection_set | 5.991436 | 3.06625 | 1.953995 |
p[0] = Field(name=p[2], alias=p[1], directives=p[3], selections=p[5]) | def p_field_optional1_2(self, p) | field : alias name directives selection_set | 5.488008 | 2.825881 | 1.942052 |
p[0] = Field(name=p[2], alias=p[1], arguments=p[3], selections=p[4]) | def p_field_optional1_3(self, p) | field : alias name arguments selection_set | 5.371235 | 2.684363 | 2.000935 |
p[0] = Field(name=p[2], alias=p[1], arguments=p[3], directives=p[4]) | def p_field_optional1_4(self, p) | field : alias name arguments directives | 5.091366 | 2.365402 | 2.152432 |
p[0] = Field(name=p[1], directives=p[2], selections=p[3]) | def p_field_optional2_1(self, p) | field : name directives selection_set | 6.141108 | 2.954524 | 2.078544 |
p[0] = Field(name=p[1], arguments=p[2], selections=p[3]) | def p_field_optional2_2(self, p) | field : name arguments selection_set | 6.13221 | 2.986051 | 2.053619 |
p[0] = Field(name=p[1], arguments=p[2], directives=p[3]) | def p_field_optional2_3(self, p) | field : name arguments directives | 5.581983 | 2.402966 | 2.322956 |
p[0] = Field(name=p[2], alias=p[1], selections=p[3]) | def p_field_optional2_4(self, p) | field : alias name selection_set | 6.147282 | 3.598474 | 1.708302 |
p[0] = Field(name=p[2], alias=p[1], directives=p[3]) | def p_field_optional2_5(self, p) | field : alias name directives | 5.856087 | 3.03358 | 1.930421 |
p[0] = Field(name=p[2], alias=p[1], arguments=p[3]) | def p_field_optional2_6(self, p) | field : alias name arguments | 5.437779 | 2.950944 | 1.842725 |
p[0] = FragmentDefinition(name=p[2], type_condition=p[4],
selections=p[6], directives=p[5]) | def p_fragment_definition1(self, p) | fragment_definition : FRAGMENT fragment_name ON type_condition directives selection_set | 6.179478 | 3.688479 | 1.675346 |
p[0] = FragmentDefinition(name=p[2], type_condition=p[4],
selections=p[5]) | def p_fragment_definition2(self, p) | fragment_definition : FRAGMENT fragment_name ON type_condition selection_set | 6.457779 | 4.237252 | 1.524049 |
p[0] = InlineFragment(type_condition=p[3], selections=p[5],
directives=p[4]) | def p_inline_fragment1(self, p) | inline_fragment : SPREAD ON type_condition directives selection_set | 4.786138 | 4.19785 | 1.14014 |
arguments = p[3] if len(p) == 4 else None
p[0] = Directive(name=p[2], arguments=arguments) | def p_directive(self, p) | directive : AT name arguments
| AT name | 3.697705 | 2.885276 | 1.281578 |
p[0] = VariableDefinition(name=p[2], type=p[4], default_value=p[5]) | def p_variable_definition1(self, p) | variable_definition : DOLLAR name COLON type default_value | 3.712757 | 2.431244 | 1.527102 |
obj = p[1].copy()
obj.update(p[2])
p[0] = obj | def p_object_field_list(self, p) | object_field_list : object_field_list object_field | 4.051494 | 3.495873 | 1.158936 |
obj = p[1].copy()
obj.update(p[2])
p[0] = obj | def p_const_object_field_list(self, p) | const_object_field_list : const_object_field_list const_object_field | 4.247465 | 4.788525 | 0.887009 |
return sorted(
triples,
key=lambda t: [
int(t) if t.isdigit() else t
for t in re.split(r'([0-9]+)', t.relation or '')
]
) | def alphanum_order(triples) | Sort a list of triples by relation name.
Embedded integers are sorted numerically, but otherwise the sorting
is alphabetic. | 3.580595 | 3.524677 | 1.015865 |
codec = cls(**kwargs)
return codec.decode(s) | def decode(s, cls=PENMANCodec, **kwargs) | Deserialize PENMAN-serialized *s* into its Graph object
Args:
s: a string containing a single PENMAN-serialized graph
cls: serialization codec class
kwargs: keyword arguments passed to the constructor of *cls*
Returns:
the Graph object described by *s*
Example:
>>> ... | 4.685117 | 17.946638 | 0.261058 |
codec = cls(**kwargs)
return codec.encode(g, top=top) | def encode(g, top=None, cls=PENMANCodec, **kwargs) | Serialize the graph *g* from *top* to PENMAN notation.
Args:
g: the Graph object
top: the node identifier for the top of the serialized graph; if
unset, the original top of *g* is used
cls: serialization codec class
kwargs: keyword arguments passed to the constructor of ... | 3.724328 | 12.543238 | 0.296919 |
decode = cls(**kwargs).iterdecode
if hasattr(source, 'read'):
return list(decode(source.read()))
else:
with open(source) as fh:
return list(decode(fh.read())) | def load(source, triples=False, cls=PENMANCodec, **kwargs) | Deserialize a list of PENMAN-encoded graphs from *source*.
Args:
source: a filename or file-like object to read from
triples: if True, read graphs as triples instead of as PENMAN
cls: serialization codec class
kwargs: keyword arguments passed to the constructor of *cls*
Returns:... | 3.651183 | 5.283999 | 0.690989 |
codec = cls(**kwargs)
return list(codec.iterdecode(string, triples=triples)) | def loads(string, triples=False, cls=PENMANCodec, **kwargs) | Deserialize a list of PENMAN-encoded graphs from *string*.
Args:
string: a string containing graph data
triples: if True, read graphs as triples instead of as PENMAN
cls: serialization codec class
kwargs: keyword arguments passed to the constructor of *cls*
Returns:
a li... | 4.58827 | 8.503858 | 0.539552 |
text = dumps(graphs, triples=triples, cls=cls, **kwargs)
if hasattr(file, 'write'):
print(text, file=file)
else:
with open(file, 'w') as fh:
print(text, file=fh) | def dump(graphs, file, triples=False, cls=PENMANCodec, **kwargs) | Serialize each graph in *graphs* to PENMAN and write to *file*.
Args:
graphs: an iterable of Graph objects
file: a filename or file-like object to write to
triples: if True, write graphs as triples instead of as PENMAN
cls: serialization codec class
kwargs: keyword arguments... | 2.073997 | 3.134442 | 0.66168 |
codec = cls(**kwargs)
strings = [codec.encode(g, triples=triples) for g in graphs]
return '\n\n'.join(strings) | def dumps(graphs, triples=False, cls=PENMANCodec, **kwargs) | Serialize each graph in *graphs* to the PENMAN format.
Args:
graphs: an iterable of Graph objects
triples: if True, write graphs as triples instead of as PENMAN
Returns:
the string of serialized graphs | 2.817769 | 3.812632 | 0.739061 |
try:
if triples:
span, data = self._decode_triple_conjunction(s)
else:
span, data = self._decode_penman_node(s)
except IndexError:
raise DecodeError(
'Unexpected end of string.', string=s, pos=len(s)
... | def decode(self, s, triples=False) | Deserialize PENMAN-notation string *s* into its Graph object.
Args:
s: a string containing a single PENMAN-serialized graph
triples: if True, treat *s* as a conjunction of logical triples
Returns:
the Graph object described by *s*
Example:
>>> co... | 5.46572 | 4.930243 | 1.108611 |
pos, strlen = 0, len(s)
while pos < strlen:
if s[pos] == '#':
while pos < strlen and s[pos] != '\n':
pos += 1
elif triples or s[pos] == '(':
try:
if triples:
span, data = self... | def iterdecode(self, s, triples=False) | Deserialize PENMAN-notation string *s* into its Graph objects.
Args:
s: a string containing zero or more PENMAN-serialized graphs
triples: if True, treat *s* as a conjunction of logical triples
Yields:
valid Graph objects described by *s*
Example:
... | 4.783756 | 4.541699 | 1.053297 |
if len(g.triples()) == 0:
raise EncodeError('Cannot encode empty graph.')
if triples:
return self._encode_triple_conjunction(g, top=top)
else:
return self._encode_penman(g, top=top) | def encode(self, g, top=None, triples=False) | Serialize the graph *g* from *top* to PENMAN notation.
Args:
g: the Graph object
top: the node identifier for the top of the serialized
graph; if unset, the original top of *g* is used
triples: if True, serialize as a conjunction of logical triples
Re... | 3.93571 | 4.166338 | 0.944645 |
relation = relation.replace(':', '', 1) # remove leading :
if self.is_relation_inverted(relation): # deinvert
source, target, inverted = rhs, lhs, True
relation = self.invert_relation(relation)
else:
source, target, inverted = lhs, rhs, False
... | def handle_triple(self, lhs, relation, rhs) | Process triples before they are added to the graph.
Note that *lhs* and *rhs* are as they originally appeared, and
may be inverted. Inversions are detected by
is_relation_inverted() and de-inverted by invert_relation().
By default, this function:
* removes initial colons on re... | 4.422327 | 2.929603 | 1.509531 |
inferred_top = triples[0][0] if triples else None
ts = []
for triple in triples:
if triple[0] == self.TOP_VAR and triple[1] == self.TOP_REL:
inferred_top = triple[2]
else:
ts.append(self.handle_triple(*triple))
top = self.h... | def triples_to_graph(self, triples, top=None) | Create a Graph from *triples* considering codec configuration.
The Graph class does not know about information in the codec,
so if Graph instantiation depends on special `TYPE_REL` or
`TOP_VAR` values, use this function instead of instantiating
a Graph object directly. This is also wher... | 3.56051 | 3.14936 | 1.13055 |
if top is None:
top = g.top
remaining = set(g.triples())
variables = g.variables()
store = defaultdict(lambda: ([], [])) # (preferred, dispreferred)
for t in g.triples():
if t.inverted:
store[t.target][0].append(t)
... | def _encode_penman(self, g, top=None) | Walk graph g and find a spanning dag, then serialize the result.
First, depth-first traversal of preferred orientations (whether
true or inverted) to create graph p.
If any triples remain, select the first remaining triple whose
source in the dispreferred orientation exists in p, where... | 3.619379 | 3.453126 | 1.048146 |
return (
relation in self._deinversions or
(relation.endswith('-of') and relation not in self._inversions)
) | def is_relation_inverted(self, relation) | Return True if *relation* is inverted. | 9.596279 | 9.26283 | 1.035999 |
if self.is_relation_inverted(relation):
rel = self._deinversions.get(relation, relation[:-3])
else:
rel = self._inversions.get(relation, relation + '-of')
if rel is None:
raise PenmanError(
'Cannot (de)invert {}; not allowed'.format(r... | def invert_relation(self, relation) | Invert or deinvert *relation*. | 7.037499 | 6.572441 | 1.070759 |
triplematch = lambda t: (
(source is None or source == t.source) and
(relation is None or relation == t.relation) and
(target is None or target == t.target)
)
return list(filter(triplematch, self._triples)) | def triples(self, source=None, relation=None, target=None) | Return triples filtered by their *source*, *relation*, or *target*. | 2.373604 | 2.10216 | 1.129126 |
edgematch = lambda e: (
(source is None or source == e.source) and
(relation is None or relation == e.relation) and
(target is None or target == e.target)
)
variables = self.variables()
edges = [t for t in self._triples if t.target in variable... | def edges(self, source=None, relation=None, target=None) | Return edges filtered by their *source*, *relation*, or *target*.
Edges don't include terminal triples (node types or attributes). | 3.184326 | 2.969057 | 1.072504 |
attrmatch = lambda a: (
(source is None or source == a.source) and
(relation is None or relation == a.relation) and
(target is None or target == a.target)
)
variables = self.variables()
attrs = [t for t in self.triples() if t.target not in var... | def attributes(self, source=None, relation=None, target=None) | Return attributes filtered by their *source*, *relation*, or *target*.
Attributes don't include triples where the target is a nonterminal. | 3.144437 | 2.822586 | 1.114027 |
entrancies = defaultdict(int)
entrancies[self.top] += 1 # implicit entrancy to top
for t in self.edges():
entrancies[t.target] += 1
return dict((v, cnt - 1) for v, cnt in entrancies.items() if cnt >= 2) | def reentrancies(self) | Return a mapping of variables to their re-entrancy count.
A re-entrancy is when more than one edge selects a node as its
target. These graphs are rooted, so the top node always has an
implicit entrancy. Only nodes with re-entrancies are reported,
and the count is only for the entrant ed... | 5.421016 | 3.98691 | 1.359703 |
if isinstance(inp, list):
return check_1d(np.array(inp))
if isinstance(inp, np.ndarray):
if inp.ndim == 1: # input is a vector
return inp | def check_1d(inp) | Check input to be a vector. Converts lists to np.ndarray.
Parameters
----------
inp : obj
Input vector
Returns
-------
numpy.ndarray or None
Input vector or None
Examples
--------
>>> check_1d([0, 1, 2, 3])
[0, 1, 2, 3]
>>> check_1d('test')
None | 2.573624 | 3.21917 | 0.799468 |
if isinstance(inp, list):
return check_2d(np.array(inp))
if isinstance(inp, (np.ndarray, np.matrixlib.defmatrix.matrix)):
if inp.ndim == 2: # input is a dense matrix
return inp
if sps.issparse(inp):
if inp.ndim == 2: # input is a sparse matrix
return inp | def check_2d(inp) | Check input to be a matrix. Converts lists of lists to np.ndarray.
Also allows the input to be a scipy sparse matrix.
Parameters
----------
inp : obj
Input matrix
Returns
-------
numpy.ndarray, scipy.sparse or None
Input matrix or None
Examples
--------
>>... | 2.660958 | 2.632364 | 1.010863 |
try:
import networkx as nx
if isinstance(G, nx.Graph):
if normalized:
return nx.normalized_laplacian_matrix(G)
else:
return nx.laplacian_matrix(G)
except ImportError:
pass
try:
import graph_tool.all as gt
if... | def graph_to_laplacian(G, normalized=True) | Converts a graph from popular Python packages to Laplacian representation.
Currently support NetworkX, graph_tool and igraph.
Parameters
----------
G : obj
Input graph
normalized : bool
Whether to use normalized Laplacian.
Normalized and unnormalized Laplacians capture ... | 1.636398 | 1.636392 | 1.000004 |
if sps.issparse(mat):
if np.all(mat.diagonal()>=0): # Check diagonal
if np.all((mat-sps.diags(mat.diagonal())).data <= 0): # Check off-diagonal elements
return mat
else:
if np.all(np.diag(mat)>=0): # Check diagonal
if np.all(mat - np.diag(mat) <= 0): ... | def mat_to_laplacian(mat, normalized) | Converts a sparse or dence adjacency matrix to Laplacian.
Parameters
----------
mat : obj
Input adjacency matrix. If it is a Laplacian matrix already, return it.
normalized : bool
Whether to use normalized Laplacian.
Normalized and unnormalized Laplacians capture different p... | 2.113818 | 2.288032 | 0.923859 |
nal = len(eigvals_lower)
nau = len(eigvals_upper)
if nv < nal + nau:
raise ValueError('Number of supplied eigenvalues ({0} lower and {1} upper) is higher than number of nodes ({2})!'.format(nal, nau, nv))
ret = np.zeros(nv)
ret[:nal] = eigvals_lower
ret[-nau:] = eigvals_upper
re... | def updown_linear_approx(eigvals_lower, eigvals_upper, nv) | Approximates Laplacian spectrum using upper and lower parts of the eigenspectrum.
Parameters
----------
eigvals_lower : numpy.ndarray
Lower part of the spectrum, sorted
eigvals_upper : numpy.ndarray
Upper part of the spectrum, sorted
nv : int
Total number of nodes (eigen... | 2.541917 | 2.577103 | 0.986347 |
do_full = True
n_lower = 150
n_upper = 150
nv = mat.shape[0]
if n_eivals == 'auto':
if mat.shape[0] > 1024:
do_full = False
if n_eivals == 'full':
do_full = True
if isinstance(n_eivals, int):
n_lower = n_upper = n_eivals
do_full = False
if... | def eigenvalues_auto(mat, n_eivals='auto') | Automatically computes the spectrum of a given Laplacian matrix.
Parameters
----------
mat : numpy.ndarray or scipy.sparse
Laplacian matrix
n_eivals : string or int or tuple
Number of eigenvalues to compute / use for approximation.
If string, we expect either 'full' or 'auto... | 2.024931 | 2.078526 | 0.974215 |
if kernel not in {'heat', 'wave'}:
raise AttributeError('Unirecognized kernel type: expected one of [\'heat\', \'wave\'], got {0}'.format(kernel))
if not isinstance(normalized_laplacian, bool):
raise AttributeError('Unknown Laplacian type: expected bool, got {0}'.format(normalized_laplacian... | def netlsd(inp, timescales=np.logspace(-2, 2, 250), kernel='heat', eigenvalues='auto', normalization='empty', normalized_laplacian=True) | Computes NetLSD signature from some given input, timescales, and normalization.
Accepts matrices, common Python graph libraries' graphs, or vectors of eigenvalues.
For precise definition, please refer to "NetLSD: Hearing the Shape of a Graph" by A. Tsitsulin, D. Mottin, P. Karras, A. Bronstein, E. Müller. Pub... | 2.360625 | 2.260608 | 1.044243 |
return netlsd(inp, timescales, 'heat', eigenvalues, normalization, normalized_laplacian) | def heat(inp, timescales=np.logspace(-2, 2, 250), eigenvalues='auto', normalization='empty', normalized_laplacian=True) | Computes heat kernel trace from some given input, timescales, and normalization.
Accepts matrices, common Python graph libraries' graphs, or vectors of eigenvalues.
For precise definition, please refer to "NetLSD: Hearing the Shape of a Graph" by A. Tsitsulin, D. Mottin, P. Karras, A. Bronstein, E. Müller. Pu... | 4.461063 | 6.716398 | 0.664205 |
return netlsd(inp, timescales, 'wave', eigenvalues, normalization, normalized_laplacian) | def wave(inp, timescales=np.linspace(0, 2*np.pi, 250), eigenvalues='auto', normalization='empty', normalized_laplacian=True) | Computes wave kernel trace from some given input, timescales, and normalization.
Accepts matrices, common Python graph libraries' graphs, or vectors of eigenvalues.
For precise definition, please refer to "NetLSD: Hearing the Shape of a Graph" by A. Tsitsulin, D. Mottin, P. Karras, A. Bronstein, E. Müller. Pu... | 4.915521 | 7.260052 | 0.677064 |
nv = eivals.shape[0]
hkt = np.zeros(timescales.shape)
for idx, t in enumerate(timescales):
hkt[idx] = np.sum(np.exp(-t * eivals))
if isinstance(normalization, np.ndarray):
return hkt / normalization
if normalization == 'empty' or normalization == True:
return hkt / nv
... | def _hkt(eivals, timescales, normalization, normalized_laplacian) | Computes heat kernel trace from given eigenvalues, timescales, and normalization.
For precise definition, please refer to "NetLSD: Hearing the Shape of a Graph" by A. Tsitsulin, D. Mottin, P. Karras, A. Bronstein, E. Müller. Published at KDD'18.
Parameters
----------
eivals : numpy.ndarray
... | 2.726385 | 2.478463 | 1.100031 |
nv = eivals.shape[0]
wkt = np.zeros(timescales.shape)
for idx, t in enumerate(timescales):
wkt[idx] = np.sum(np.exp(-1j * t * eivals))
if isinstance(normalization, np.ndarray):
return hkt / normalization
if normalization == 'empty' or normalization == True:
return wkt / ... | def _wkt(eivals, timescales, normalization, normalized_laplacian) | Computes wave kernel trace from given eigenvalues, timescales, and normalization.
For precise definition, please refer to "NetLSD: Hearing the Shape of a Graph" by A. Tsitsulin, D. Mottin, P. Karras, A. Bronstein, E. Müller. Published at KDD'18.
Parameters
----------
eivals : numpy.ndarray
... | 3.17992 | 2.885017 | 1.102219 |
self._len = 0
del self._maxes[:]
del self._lists[:]
del self._keys[:]
del self._index[:] | def clear(self) | Remove all the elements from the list. | 6.782635 | 5.629331 | 1.204874 |
_maxes = self._maxes
if not _maxes:
return
key = self._key(val)
pos = bisect_left(_maxes, key)
if pos == len(_maxes):
return
_keys = self._keys
_lists = self._lists
idx = bisect_left(_keys[pos], key)
len_keys =... | def discard(self, val) | Remove the first occurrence of *val*.
If *val* is not a member, does nothing. | 2.585753 | 2.568012 | 1.006909 |
_maxes = self._maxes
if not _maxes:
raise ValueError('{0} not in list'.format(repr(val)))
key = self._key(val)
pos = bisect_left(_maxes, key)
if pos == len(_maxes):
raise ValueError('{0} not in list'.format(repr(val)))
_keys = self._ke... | def remove(self, val) | Remove first occurrence of *val*.
Raises ValueError if *val* is not present. | 2.27189 | 2.197037 | 1.03407 |
_maxes, _lists, _keys, _index = self._maxes, self._lists, self._keys, self._index
keys_pos = _keys[pos]
lists_pos = _lists[pos]
del keys_pos[idx]
del lists_pos[idx]
self._len -= 1
len_keys_pos = len(keys_pos)
if len_keys_pos > self._half:
... | def _delete(self, pos, idx) | Delete the item at the given (pos, idx).
Combines lists that are less than half the load level.
Updates the index when the sublist length is more than half the load
level. This requires decrementing the nodes in a traversal from the leaf
node to the root. For an example traversal see s... | 2.675055 | 2.615276 | 1.022858 |
if not pos:
return idx
_index = self._index
if not len(_index):
self._build_index()
total = 0
# Increment pos to point in the index to len(self._lists[pos]).
pos += self._offset
# Iterate until reaching the root of the index ... | def _loc(self, pos, idx) | Convert an index pair (alpha, beta) into a single index that corresponds to
the position of the value in the sorted list.
Most queries require the index be built. Details of the index are
described in self._build_index.
Indexing requires traversing the tree from a leaf node to the root... | 7.741471 | 6.515013 | 1.188251 |
_len = self._len
if not _len:
return iter(())
start, stop, step = self._slice(slice(start, stop))
if start >= stop:
return iter(())
_pos = self._pos
min_pos, min_idx = _pos(start)
if stop == _len:
max_pos = len(se... | def islice(self, start=None, stop=None, reverse=False) | Returns an iterator that slices `self` from `start` to `stop` index,
inclusive and exclusive respectively.
When `reverse` is `True`, values are yielded from the iterator in
reverse order.
Both `start` and `stop` default to `None` which is automatically
inclusive of the beginnin... | 3.087944 | 3.213107 | 0.961046 |
minimum = self._key(minimum) if minimum is not None else None
maximum = self._key(maximum) if maximum is not None else None
return self.irange_key(
min_key=minimum, max_key=maximum,
inclusive=inclusive, reverse=reverse,
) | def irange(self, minimum=None, maximum=None, inclusive=(True, True),
reverse=False) | Create an iterator of values between `minimum` and `maximum`.
`inclusive` is a pair of booleans that indicates whether the minimum
and maximum ought to be included in the range, respectively. The
default is (True, True) such that the range is inclusive of both
minimum and maximum.
... | 2.621161 | 3.128609 | 0.837804 |
return self.__class__(self, key=self._key, load=self._load) | def copy(self) | Return a shallow copy of the sorted list. | 10.431229 | 7.609678 | 1.370785 |
_maxes, _lists, _keys = self._maxes, self._lists, self._keys
key = self._key(val)
if not _maxes:
_maxes.append(key)
_keys.append([key])
_lists.append([val])
self._len = 1
return
pos = len(_keys) - 1
if key <... | def append(self, val) | Append the element *val* to the list. Raises a ValueError if the *val*
would violate the sort order. | 3.040012 | 2.733178 | 1.112263 |
_maxes, _keys, _lists, _load = self._maxes, self._keys, self._lists, self._load
if not isinstance(values, list):
values = list(values)
keys = list(map(self._key, values))
if any(keys[pos - 1] > keys[pos]
for pos in range(1, len(keys))):
... | def extend(self, values) | Extend the list by appending all elements from the *values*. Raises a
ValueError if the sort order would be violated. | 3.169071 | 3.03143 | 1.045405 |
if (idx < 0 and -idx > self._len) or (idx >= self._len):
raise IndexError('pop index out of range')
pos, idx = self._pos(idx)
val = self._lists[pos][idx]
self._delete(pos, idx)
return val | def pop(self, idx=-1) | Remove and return item at *idx* (default last). Raises IndexError if
list is empty or index is out of range. Negative indices are supported,
as for slice indices. | 3.787951 | 3.765188 | 1.006045 |
@wraps(func)
def errfunc(*args, **kwargs):
raise NotImplementedError
if hexversion < 0x02070000:
return errfunc
else:
return func | def not26(func) | Function decorator for methods not implemented in Python 2.6. | 4.790541 | 3.428124 | 1.397423 |
return self.__class__(self._key, self._load, self._iteritems()) | def copy(self) | Return a shallow copy of the sorted dictionary. | 26.992952 | 15.250506 | 1.769971 |
if key in self:
self._list_remove(key)
return self._pop(key)
else:
if default is _NotGiven:
raise KeyError(key)
else:
return default | def pop(self, key, default=_NotGiven) | If *key* is in the dictionary, remove it and return its value,
else return *default*. If *default* is not given and *key* is not in
the dictionary, a KeyError is raised. | 2.868318 | 2.805253 | 1.022481 |
if not len(self):
raise KeyError('popitem(): dictionary is empty')
key = self._list_pop(-1 if last else 0)
value = self._pop(key)
return (key, value) | def popitem(self, last=True) | Remove and return a ``(key, value)`` pair from the dictionary. If
last=True (default) then remove the *greatest* `key` from the
diciontary. Else, remove the *least* key from the dictionary.
If the dictionary is empty, calling `popitem` raises a
KeyError`. | 3.791755 | 3.946121 | 0.960882 |
if key in self:
return self[key]
else:
self._setitem(key, default)
self._list_add(key)
return default | def setdefault(self, key, default=None) | If *key* is in the dictionary, return its value. If not, insert *key*
with a value of *default* and return *default*. *default* defaults to
``None``. | 3.722466 | 3.821306 | 0.974135 |
return self._list.index(value, start, stop) | def index(self, value, start=None, stop=None) | Return the smallest *k* such that `keysview[k] == value` and `start <= k
< end`. Raises `KeyError` if *value* is not present. *stop* defaults
to the end of the set. *start* defaults to the beginning. Negative
indexes are supported, as for slice indices. | 6.090889 | 8.367262 | 0.727943 |
if not self.ignore_self:
res = summary.summarize(muppy.get_objects())
else:
# If the user requested the data required to store summaries to be
# ignored in the summaries, we need to identify all objects which
# are related to each summary stored.
... | def create_summary(self) | Return a summary.
See also the notes on ignore_self in the class as well as the
initializer documentation. | 5.749729 | 5.560618 | 1.034009 |
res = None
if summary2 is None:
self.s1 = self.create_summary()
if summary1 is None:
res = summary.get_diff(self.s0, self.s1)
else:
res = summary.get_diff(summary1, self.s1)
self.s0 = self.s1
else:
... | def diff(self, summary1=None, summary2=None) | Compute diff between to summaries.
If no summary is provided, the diff from the last to the current
summary is used. If summary1 is provided the diff from summary1
to the current summary is used. If summary1 and summary2 are
provided, the diff between these two is used. | 2.946673 | 2.816021 | 1.046396 |
summary.print_(self.diff(summary1=summary1, summary2=summary2)) | def print_diff(self, summary1=None, summary2=None) | Compute diff between to summaries and print it.
If no summary is provided, the diff from the last to the current
summary is used. If summary1 is provided the diff from summary1
to the current summary is used. If summary1 and summary2 are
provided, the diff between these two is used. | 7.087651 | 8.308731 | 0.853037 |
def remove_ignore(objects, ignore=[]):
# remove all objects listed in the ignore list
res = []
for o in objects:
if not compat.object_in_list(o, ignore):
res.append(o)
return res
tmp = gc.get_objects()
... | def _get_objects(self, ignore=[]) | Get all currently existing objects.
XXX - ToDo: This method is a copy&paste from muppy.get_objects, but
some modifications are applied. Specifically, it allows to ignore
objects (which includes the current frame).
keyword arguments
ignore -- list of objects to ignore | 4.192653 | 4.068903 | 1.030414 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.