nwo stringlengths 5 106 | sha stringlengths 40 40 | path stringlengths 4 174 | language stringclasses 1
value | identifier stringlengths 1 140 | parameters stringlengths 0 87.7k | argument_list stringclasses 1
value | return_statement stringlengths 0 426k | docstring stringlengths 0 64.3k | docstring_summary stringlengths 0 26.3k | docstring_tokens list | function stringlengths 18 4.83M | function_tokens list | url stringlengths 83 304 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Yonv1943/Python | ecce2153892093d7a13686e4cbfd6b323cb59de8 | ElegantRL/Beta/elegantrl/AgentZoo/ElegantRL-PER/net.py | python | CriticTwin.__init__ | (self, mid_dim, state_dim, action_dim, if_use_dn=False) | Not need to use both SpectralNorm and TwinCritic
I choose TwinCritc instead of SpectralNorm,
because SpectralNorm is conflict with soft target update,
if is_spectral_norm:
self.net1[1] = nn.utils.spectral_norm(self.dec_q1[1])
self.net2[1] = nn.utils.spectral_norm(self.dec_q2[1]) | Not need to use both SpectralNorm and TwinCritic
I choose TwinCritc instead of SpectralNorm,
because SpectralNorm is conflict with soft target update, | [
"Not",
"need",
"to",
"use",
"both",
"SpectralNorm",
"and",
"TwinCritic",
"I",
"choose",
"TwinCritc",
"instead",
"of",
"SpectralNorm",
"because",
"SpectralNorm",
"is",
"conflict",
"with",
"soft",
"target",
"update"
] | def __init__(self, mid_dim, state_dim, action_dim, if_use_dn=False):
super().__init__()
if if_use_dn: # use DenseNet (DenseNet has both shallow and deep linear layer)
nn_dense = DenseNet(mid_dim)
lay_dim = nn_dense.out_dim
self.net_sa = nn.Sequential(nn.Linear(state_dim + action_dim, mid_dim), nn.ReLU(),
nn_dense, ) # state-action value function
else: # use a simple network for actor. Deeper network does not mean better performance in RL.
lay_dim = mid_dim
self.net_sa = nn.Sequential(nn.Linear(state_dim + action_dim, mid_dim), nn.ReLU(),
nn.Linear(mid_dim, lay_dim), nn.ReLU(),
nn.Linear(mid_dim, lay_dim), nn.Hardswish())
self.net_q1 = nn.Linear(lay_dim, 1)
self.net_q2 = nn.Linear(lay_dim, 1)
layer_norm(self.net_q1, std=0.1)
layer_norm(self.net_q2, std=0.1)
'''Not need to use both SpectralNorm and TwinCritic
I choose TwinCritc instead of SpectralNorm,
because SpectralNorm is conflict with soft target update,
if is_spectral_norm:
self.net1[1] = nn.utils.spectral_norm(self.dec_q1[1])
self.net2[1] = nn.utils.spectral_norm(self.dec_q2[1])
''' | [
"def",
"__init__",
"(",
"self",
",",
"mid_dim",
",",
"state_dim",
",",
"action_dim",
",",
"if_use_dn",
"=",
"False",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
")",
"if",
"if_use_dn",
":",
"# use DenseNet (DenseNet has both shallow and deep linear layer)",... | https://github.com/Yonv1943/Python/blob/ecce2153892093d7a13686e4cbfd6b323cb59de8/ElegantRL/Beta/elegantrl/AgentZoo/ElegantRL-PER/net.py#L267-L293 | ||
martsberger/django-pivot | be6efdea5bb009d6ccc697b3c62d7e539e9fee7f | django_pivot/histogram.py | python | multi_histogram | (queryset, column, bins, slice_on, choices) | return _zero_fill(qs, bins, field_values) | Returns a table of histograms, one for each unique value of field in queryset.
:param queryset: A Queryet, Model, or Manager
:param column: The column we are aggregating into a histogram
:param bins: An ordered iterable of left endpoints of the bins. Must have at least two elements.
The endpoints must be a convertible to strings by force_text
:param slice_on: A field of the queryset that we are slicing the histograms on
:return: A ValuesQuerySet | Returns a table of histograms, one for each unique value of field in queryset. | [
"Returns",
"a",
"table",
"of",
"histograms",
"one",
"for",
"each",
"unique",
"value",
"of",
"field",
"in",
"queryset",
"."
] | def multi_histogram(queryset, column, bins, slice_on, choices):
"""
Returns a table of histograms, one for each unique value of field in queryset.
:param queryset: A Queryet, Model, or Manager
:param column: The column we are aggregating into a histogram
:param bins: An ordered iterable of left endpoints of the bins. Must have at least two elements.
The endpoints must be a convertible to strings by force_text
:param slice_on: A field of the queryset that we are slicing the histograms on
:return: A ValuesQuerySet
"""
queryset = _get_queryset(queryset)
field_values = get_column_values(queryset, slice_on, choices)
bins = [force_text(bin) for bin in bins]
whens = tuple(
between_include_start(column, bins[k], bins[k+1], Value(force_text(bins[k])))
for k in range(len(bins) - 1)
) + (
When(Q(**{column + '__gte': bins[-1]}), Value(force_text(bins[-1]))),
)
ordering_whens = tuple(
between_include_start(column, bins[k], bins[k + 1], Value(k))
for k in range(len(bins) - 1)
) + (
When(Q(**{column + '__gte': bins[-1]}), Value(len(bins) - 1)),
)
bin_annotation = {
'bin': Case(*whens, output_field=CharField()),
'order': Case(*ordering_whens, output_field=IntegerField())
}
histogram_annotation = {
display_value: Count(Case(When(Q(**{slice_on: field_value}), then=1), output_field=IntegerField()))
for field_value, display_value in field_values
}
qs = queryset.annotate(**bin_annotation).order_by('order').values('bin').filter(bin__isnull=False).annotate(**histogram_annotation)
return _zero_fill(qs, bins, field_values) | [
"def",
"multi_histogram",
"(",
"queryset",
",",
"column",
",",
"bins",
",",
"slice_on",
",",
"choices",
")",
":",
"queryset",
"=",
"_get_queryset",
"(",
"queryset",
")",
"field_values",
"=",
"get_column_values",
"(",
"queryset",
",",
"slice_on",
",",
"choices"... | https://github.com/martsberger/django-pivot/blob/be6efdea5bb009d6ccc697b3c62d7e539e9fee7f/django_pivot/histogram.py#L37-L80 | |
deepdrive/deepdrive | 11adb9480ffeba832231e15eb545ec9aba1f7d65 | vendor/openai/baselines/common/math_util.py | python | explained_variance | (ypred,y) | return np.nan if vary==0 else 1 - np.var(y-ypred)/vary | Computes fraction of variance that ypred explains about y.
Returns 1 - Var[y-ypred] / Var[y]
interpretation:
ev=0 => might as well have predicted zero
ev=1 => perfect prediction
ev<0 => worse than just predicting zero | Computes fraction of variance that ypred explains about y.
Returns 1 - Var[y-ypred] / Var[y] | [
"Computes",
"fraction",
"of",
"variance",
"that",
"ypred",
"explains",
"about",
"y",
".",
"Returns",
"1",
"-",
"Var",
"[",
"y",
"-",
"ypred",
"]",
"/",
"Var",
"[",
"y",
"]"
] | def explained_variance(ypred,y):
"""
Computes fraction of variance that ypred explains about y.
Returns 1 - Var[y-ypred] / Var[y]
interpretation:
ev=0 => might as well have predicted zero
ev=1 => perfect prediction
ev<0 => worse than just predicting zero
"""
assert y.ndim == 1 and ypred.ndim == 1
vary = np.var(y)
return np.nan if vary==0 else 1 - np.var(y-ypred)/vary | [
"def",
"explained_variance",
"(",
"ypred",
",",
"y",
")",
":",
"assert",
"y",
".",
"ndim",
"==",
"1",
"and",
"ypred",
".",
"ndim",
"==",
"1",
"vary",
"=",
"np",
".",
"var",
"(",
"y",
")",
"return",
"np",
".",
"nan",
"if",
"vary",
"==",
"0",
"el... | https://github.com/deepdrive/deepdrive/blob/11adb9480ffeba832231e15eb545ec9aba1f7d65/vendor/openai/baselines/common/math_util.py#L25-L38 | |
home-assistant/core | 265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1 | homeassistant/components/aemet/sensor.py | python | AemetForecastSensor.__init__ | (
self,
name,
unique_id,
weather_coordinator: WeatherUpdateCoordinator,
forecast_mode,
description: SensorEntityDescription,
) | Initialize the sensor. | Initialize the sensor. | [
"Initialize",
"the",
"sensor",
"."
] | def __init__(
self,
name,
unique_id,
weather_coordinator: WeatherUpdateCoordinator,
forecast_mode,
description: SensorEntityDescription,
):
"""Initialize the sensor."""
super().__init__(
name=name,
unique_id=f"{unique_id}-{description.key}",
coordinator=weather_coordinator,
description=description,
)
self._forecast_mode = forecast_mode
self._attr_entity_registry_enabled_default = (
self._forecast_mode == FORECAST_MODE_DAILY
) | [
"def",
"__init__",
"(",
"self",
",",
"name",
",",
"unique_id",
",",
"weather_coordinator",
":",
"WeatherUpdateCoordinator",
",",
"forecast_mode",
",",
"description",
":",
"SensorEntityDescription",
",",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"name",
... | https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/aemet/sensor.py#L113-L131 | ||
yuanxiaosc/BERT-for-Sequence-Labeling-and-Text-Classification | 2a6d2f9c732a362458030643e131540e7d1cdcca | bert/run_squad.py | python | model_fn_builder | (bert_config, init_checkpoint, learning_rate,
num_train_steps, num_warmup_steps, use_tpu,
use_one_hot_embeddings) | return model_fn | Returns `model_fn` closure for TPUEstimator. | Returns `model_fn` closure for TPUEstimator. | [
"Returns",
"model_fn",
"closure",
"for",
"TPUEstimator",
"."
] | def model_fn_builder(bert_config, init_checkpoint, learning_rate,
num_train_steps, num_warmup_steps, use_tpu,
use_one_hot_embeddings):
"""Returns `model_fn` closure for TPUEstimator."""
def model_fn(features, labels, mode, params): # pylint: disable=unused-argument
"""The `model_fn` for TPUEstimator."""
tf.logging.info("*** Features ***")
for name in sorted(features.keys()):
tf.logging.info(" name = %s, shape = %s" % (name, features[name].shape))
unique_ids = features["unique_ids"]
input_ids = features["input_ids"]
input_mask = features["input_mask"]
segment_ids = features["segment_ids"]
is_training = (mode == tf.estimator.ModeKeys.TRAIN)
(start_logits, end_logits) = create_model(
bert_config=bert_config,
is_training=is_training,
input_ids=input_ids,
input_mask=input_mask,
segment_ids=segment_ids,
use_one_hot_embeddings=use_one_hot_embeddings)
tvars = tf.trainable_variables()
initialized_variable_names = {}
scaffold_fn = None
if init_checkpoint:
(assignment_map, initialized_variable_names
) = modeling.get_assignment_map_from_checkpoint(tvars, init_checkpoint)
if use_tpu:
def tpu_scaffold():
tf.train.init_from_checkpoint(init_checkpoint, assignment_map)
return tf.train.Scaffold()
scaffold_fn = tpu_scaffold
else:
tf.train.init_from_checkpoint(init_checkpoint, assignment_map)
tf.logging.info("**** Trainable Variables ****")
for var in tvars:
init_string = ""
if var.name in initialized_variable_names:
init_string = ", *INIT_FROM_CKPT*"
tf.logging.info(" name = %s, shape = %s%s", var.name, var.shape,
init_string)
output_spec = None
if mode == tf.estimator.ModeKeys.TRAIN:
seq_length = modeling.get_shape_list(input_ids)[1]
def compute_loss(logits, positions):
one_hot_positions = tf.one_hot(
positions, depth=seq_length, dtype=tf.float32)
log_probs = tf.nn.log_softmax(logits, axis=-1)
loss = -tf.reduce_mean(
tf.reduce_sum(one_hot_positions * log_probs, axis=-1))
return loss
start_positions = features["start_positions"]
end_positions = features["end_positions"]
start_loss = compute_loss(start_logits, start_positions)
end_loss = compute_loss(end_logits, end_positions)
total_loss = (start_loss + end_loss) / 2.0
train_op = optimization.create_optimizer(
total_loss, learning_rate, num_train_steps, num_warmup_steps, use_tpu)
output_spec = tf.contrib.tpu.TPUEstimatorSpec(
mode=mode,
loss=total_loss,
train_op=train_op,
scaffold_fn=scaffold_fn)
elif mode == tf.estimator.ModeKeys.PREDICT:
predictions = {
"unique_ids": unique_ids,
"start_logits": start_logits,
"end_logits": end_logits,
}
output_spec = tf.contrib.tpu.TPUEstimatorSpec(
mode=mode, predictions=predictions, scaffold_fn=scaffold_fn)
else:
raise ValueError(
"Only TRAIN and PREDICT modes are supported: %s" % (mode))
return output_spec
return model_fn | [
"def",
"model_fn_builder",
"(",
"bert_config",
",",
"init_checkpoint",
",",
"learning_rate",
",",
"num_train_steps",
",",
"num_warmup_steps",
",",
"use_tpu",
",",
"use_one_hot_embeddings",
")",
":",
"def",
"model_fn",
"(",
"features",
",",
"labels",
",",
"mode",
"... | https://github.com/yuanxiaosc/BERT-for-Sequence-Labeling-and-Text-Classification/blob/2a6d2f9c732a362458030643e131540e7d1cdcca/bert/run_squad.py#L590-L684 | |
tensorflow/lingvo | ce10019243d954c3c3ebe739f7589b5eebfdf907 | lingvo/jax/optimizers.py | python | sharded_sgd | (learning_rate_fn: optax.Schedule, momentum: Optional[float],
nesterov: bool) | return ShardedGradientTransformation(
init=count_init_fn,
update=update_fn,
init_partition_spec=count_init_partition_spec_fn) | A canonical Stochastic Gradient Descent optimiser that supports spmd ...
sharding.
This implements stochastic gradient descent. It also includes support for
momentum, and nesterov acceleration, as these are standard practice when
using stochastic gradient descent to train deep neural networks.
References:
Sutskever et al, 2013: http://proceedings.mlr.press/v28/sutskever13.pdf
Args:
learning_rate_fn: a callable that given the current training step, returns
the learning rate to apply.
momentum: (default `None`), the `decay` rate used by the momentum term, when
it is set to `None`, then momentum is not used at all.
nesterov (default `False`): whether nesterov momentum is used.
Returns:
A `ShardedGradientTransformation`. | A canonical Stochastic Gradient Descent optimiser that supports spmd ... | [
"A",
"canonical",
"Stochastic",
"Gradient",
"Descent",
"optimiser",
"that",
"supports",
"spmd",
"..."
] | def sharded_sgd(learning_rate_fn: optax.Schedule, momentum: Optional[float],
nesterov: bool) -> ShardedGradientTransformation:
"""A canonical Stochastic Gradient Descent optimiser that supports spmd ...
sharding.
This implements stochastic gradient descent. It also includes support for
momentum, and nesterov acceleration, as these are standard practice when
using stochastic gradient descent to train deep neural networks.
References:
Sutskever et al, 2013: http://proceedings.mlr.press/v28/sutskever13.pdf
Args:
learning_rate_fn: a callable that given the current training step, returns
the learning rate to apply.
momentum: (default `None`), the `decay` rate used by the momentum term, when
it is set to `None`, then momentum is not used at all.
nesterov (default `False`): whether nesterov momentum is used.
Returns:
A `ShardedGradientTransformation`.
"""
# TODO(yonghui): support momentum.
assert momentum is None
del nesterov
def update_fn(updates, state, params=None):
del params
step_size = -1.0 * learning_rate_fn(state.count)
updates = jax.tree_map(lambda g: jnp.array(step_size, dtype=g.dtype) * g,
updates)
updated_states = NestedMap(count=state.count + jnp.array(1, jnp.int32))
return updates, updated_states
return ShardedGradientTransformation(
init=count_init_fn,
update=update_fn,
init_partition_spec=count_init_partition_spec_fn) | [
"def",
"sharded_sgd",
"(",
"learning_rate_fn",
":",
"optax",
".",
"Schedule",
",",
"momentum",
":",
"Optional",
"[",
"float",
"]",
",",
"nesterov",
":",
"bool",
")",
"->",
"ShardedGradientTransformation",
":",
"# TODO(yonghui): support momentum.",
"assert",
"momentu... | https://github.com/tensorflow/lingvo/blob/ce10019243d954c3c3ebe739f7589b5eebfdf907/lingvo/jax/optimizers.py#L88-L126 | |
duo-labs/py_webauthn | fe97b9841328aa84559bd2a282c07d20145845c1 | webauthn/helpers/decode_credential_public_key.py | python | decode_credential_public_key | (
key: bytes,
) | Decode a CBOR-encoded public key and turn it into a data structure.
Supports OKP, EC2, and RSA public keys | Decode a CBOR-encoded public key and turn it into a data structure. | [
"Decode",
"a",
"CBOR",
"-",
"encoded",
"public",
"key",
"and",
"turn",
"it",
"into",
"a",
"data",
"structure",
"."
] | def decode_credential_public_key(
key: bytes,
) -> Union[DecodedOKPPublicKey, DecodedEC2PublicKey, DecodedRSAPublicKey]:
"""
Decode a CBOR-encoded public key and turn it into a data structure.
Supports OKP, EC2, and RSA public keys
"""
# Occassionally we might be given a public key in an "uncompressed" format,
# typically from older U2F security keys. As per the FIDO spec this is indicated by
# a leading 0x04 "uncompressed point compression method" format byte. In that case
# we need to fill in some blanks to turn it into a full EC2 key for signature
# verification
#
# See https://fidoalliance.org/specs/fido-v2.0-id-20180227/fido-registry-v2.0-id-20180227.html#public-key-representation-formats
if key[0] == 0x04:
return DecodedEC2PublicKey(
kty=COSEKTY.EC2,
alg=COSEAlgorithmIdentifier.ECDSA_SHA_256,
crv=COSECRV.P256,
x=key[1:33],
y=key[33:65],
)
decoded_key: dict = decoder.loads(key)
kty = decoded_key[COSEKey.KTY]
alg = decoded_key[COSEKey.ALG]
if not kty:
raise InvalidPublicKeyStructure("Credential public key missing kty")
if not alg:
raise InvalidPublicKeyStructure("Credential public key missing alg")
if kty == COSEKTY.OKP:
crv = decoded_key[COSEKey.CRV]
x = decoded_key[COSEKey.X]
if not crv:
raise InvalidPublicKeyStructure("OKP credential public key missing crv")
if not x:
raise InvalidPublicKeyStructure("OKP credential public key missing x")
return DecodedOKPPublicKey(
kty=kty,
alg=alg,
crv=crv,
x=x,
)
elif kty == COSEKTY.EC2:
crv = decoded_key[COSEKey.CRV]
x = decoded_key[COSEKey.X]
y = decoded_key[COSEKey.Y]
if not crv:
raise InvalidPublicKeyStructure("EC2 credential public key missing crv")
if not x:
raise InvalidPublicKeyStructure("EC2 credential public key missing x")
if not y:
raise InvalidPublicKeyStructure("EC2 credential public key missing y")
return DecodedEC2PublicKey(
kty=kty,
alg=alg,
crv=crv,
x=x,
y=y,
)
elif kty == COSEKTY.RSA:
n = decoded_key[COSEKey.N]
e = decoded_key[COSEKey.E]
if not n:
raise InvalidPublicKeyStructure("RSA credential public key missing n")
if not e:
raise InvalidPublicKeyStructure("RSA credential public key missing e")
return DecodedRSAPublicKey(
kty=kty,
alg=alg,
n=n,
e=e,
)
raise UnsupportedPublicKeyType(f'Unsupported credential public key type "{kty}"') | [
"def",
"decode_credential_public_key",
"(",
"key",
":",
"bytes",
",",
")",
"->",
"Union",
"[",
"DecodedOKPPublicKey",
",",
"DecodedEC2PublicKey",
",",
"DecodedRSAPublicKey",
"]",
":",
"# Occassionally we might be given a public key in an \"uncompressed\" format,",
"# typically ... | https://github.com/duo-labs/py_webauthn/blob/fe97b9841328aa84559bd2a282c07d20145845c1/webauthn/helpers/decode_credential_public_key.py#L35-L119 | ||
IJDykeman/wangTiles | 7c1ee2095ebdf7f72bce07d94c6484915d5cae8b | experimental_code/tiles_3d/venv/lib/python2.7/site-packages/pip/req.py | python | parse_editable | (editable_req, default_vcs=None) | return package, url, options | Parses svn+http://blahblah@rev#egg=Foobar into a requirement
(Foobar) and a URL | Parses svn+http://blahblah | [
"Parses",
"svn",
"+",
"http",
":",
"//",
"blahblah"
] | def parse_editable(editable_req, default_vcs=None):
"""Parses svn+http://blahblah@rev#egg=Foobar into a requirement
(Foobar) and a URL"""
url = editable_req
extras = None
# If a file path is specified with extras, strip off the extras.
m = re.match(r'^(.+)(\[[^\]]+\])$', url)
if m:
url_no_extras = m.group(1)
extras = m.group(2)
else:
url_no_extras = url
if os.path.isdir(url_no_extras):
if not os.path.exists(os.path.join(url_no_extras, 'setup.py')):
raise InstallationError("Directory %r is not installable. File 'setup.py' not found." % url_no_extras)
# Treating it as code that has already been checked out
url_no_extras = path_to_url(url_no_extras)
if url_no_extras.lower().startswith('file:'):
if extras:
return None, url_no_extras, pkg_resources.Requirement.parse('__placeholder__' + extras).extras
else:
return None, url_no_extras, None
for version_control in vcs:
if url.lower().startswith('%s:' % version_control):
url = '%s+%s' % (version_control, url)
break
if '+' not in url:
if default_vcs:
url = default_vcs + '+' + url
else:
raise InstallationError(
'%s should either be a path to a local project or a VCS url beginning with svn+, git+, hg+, or bzr+' % editable_req)
vc_type = url.split('+', 1)[0].lower()
if not vcs.get_backend(vc_type):
error_message = 'For --editable=%s only ' % editable_req + \
', '.join([backend.name + '+URL' for backend in vcs.backends]) + \
' is currently supported'
raise InstallationError(error_message)
try:
options = _build_editable_options(editable_req)
except Exception:
message = sys.exc_info()[1]
raise InstallationError(
'--editable=%s error in editable options:%s' % (editable_req, message))
if not options or 'egg' not in options:
req = _build_req_from_url(editable_req)
if not req:
raise InstallationError('--editable=%s is not the right format; it must have #egg=Package' % editable_req)
else:
req = options['egg']
package = _strip_postfix(req)
return package, url, options | [
"def",
"parse_editable",
"(",
"editable_req",
",",
"default_vcs",
"=",
"None",
")",
":",
"url",
"=",
"editable_req",
"extras",
"=",
"None",
"# If a file path is specified with extras, strip off the extras.",
"m",
"=",
"re",
".",
"match",
"(",
"r'^(.+)(\\[[^\\]]+\\])$'",... | https://github.com/IJDykeman/wangTiles/blob/7c1ee2095ebdf7f72bce07d94c6484915d5cae8b/experimental_code/tiles_3d/venv/lib/python2.7/site-packages/pip/req.py#L1676-L1738 | |
yangxue0827/R-DFPN_FPN_Tensorflow | fa69b1c176fc5eb9835e9ac46663c81a4bf7e6ce | libs/rotation/r_minibatch.py | python | r_get_minibatch | (roidb, num_classes) | return blobs | Given a roidb, construct a minibatch sampled from it. | Given a roidb, construct a minibatch sampled from it. | [
"Given",
"a",
"roidb",
"construct",
"a",
"minibatch",
"sampled",
"from",
"it",
"."
] | def r_get_minibatch(roidb, num_classes):
bbox_para_num = 5
"""Given a roidb, construct a minibatch sampled from it."""
num_images = len(roidb)
# Sample random scales to use for each image in this batch
random_scale_inds = npr.randint(0, high=len(cfg.TRAIN.SCALES),
size=num_images)
assert(cfg.TRAIN.BATCH_SIZE % num_images == 0), \
'num_images ({}) must divide BATCH_SIZE ({})'. \
format(num_images, cfg.TRAIN.BATCH_SIZE)
rois_per_image = cfg.TRAIN.BATCH_SIZE / num_images
fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image)
# Get the input image blob, formatted for caffe
im_blob, im_scales = _get_image_blob(roidb, random_scale_inds)
blobs = {'data': im_blob}
# bbox: [ctr_x, ctr_y, height, width, angle]
if cfg.TRAIN.HAS_RPN:
assert len(im_scales) == 1, "Single batch only"
assert len(roidb) == 1, "Single batch only"
# gt boxes: (ctr_x, ctr_y, height, width, angle, cls)
gt_inds = np.where(roidb[0]['gt_classes'] != 0)[0]
gt_boxes = np.empty((len(gt_inds), bbox_para_num + 1), dtype=np.float32) # D initial the gt_scales
gt_boxes[:, 0:bbox_para_num] = roidb[0]['boxes'][gt_inds, :]
gt_boxes[:, 0:bbox_para_num-1] = gt_boxes[:, 0:bbox_para_num-1] * im_scales[0] # D
gt_boxes[:, bbox_para_num] = roidb[0]['gt_classes'][gt_inds] # D
blobs['gt_boxes'] = gt_boxes
#im_info[height, width, scale]
blobs['im_info'] = np.array(
[[im_blob.shape[2], im_blob.shape[3], im_scales[0]]],
dtype=np.float32)
# next not use
#####################################################################################################
else: # not using RPN
# Now, build the region of interest and label blobs
rois_blob = np.zeros((0, bbox_para_num + 1), dtype=np.float32) # D
labels_blob = np.zeros((0), dtype=np.float32)
bbox_targets_blob = np.zeros((0, bbox_para_num * num_classes), dtype=np.float32)
bbox_inside_blob = np.zeros(bbox_targets_blob.shape, dtype=np.float32)
# all_overlaps = []
for im_i in xrange(num_images):
labels, overlaps, im_rois, bbox_targets, bbox_inside_weights \
= _sample_rois(roidb[im_i], fg_rois_per_image, rois_per_image,
num_classes)
# Add to RoIs blob
rois = _project_im_rois(im_rois, im_scales[im_i])
batch_ind = im_i * np.ones((rois.shape[0], 1))
rois_blob_this_image = np.hstack((batch_ind, rois))
rois_blob = np.vstack((rois_blob, rois_blob_this_image))
# Add to labels, bbox targets, and bbox loss blobs
labels_blob = np.hstack((labels_blob, labels))
bbox_targets_blob = np.vstack((bbox_targets_blob, bbox_targets))
bbox_inside_blob = np.vstack((bbox_inside_blob, bbox_inside_weights))
# all_overlaps = np.hstack((all_overlaps, overlaps))
# For debug visualizations
# _vis_minibatch(im_blob, rois_blob, labels_blob, all_overlaps)
blobs['rois'] = rois_blob
blobs['labels'] = labels_blob
if cfg.TRAIN.BBOX_REG:
blobs['bbox_targets'] = bbox_targets_blob
blobs['bbox_inside_weights'] = bbox_inside_blob
blobs['bbox_outside_weights'] = \
np.array(bbox_inside_blob > 0).astype(np.float32)
return blobs | [
"def",
"r_get_minibatch",
"(",
"roidb",
",",
"num_classes",
")",
":",
"bbox_para_num",
"=",
"5",
"num_images",
"=",
"len",
"(",
"roidb",
")",
"# Sample random scales to use for each image in this batch",
"random_scale_inds",
"=",
"npr",
".",
"randint",
"(",
"0",
","... | https://github.com/yangxue0827/R-DFPN_FPN_Tensorflow/blob/fa69b1c176fc5eb9835e9ac46663c81a4bf7e6ce/libs/rotation/r_minibatch.py#L188-L268 | |
bruderstein/PythonScript | df9f7071ddf3a079e3a301b9b53a6dc78cf1208f | PythonLib/min/_pyio.py | python | BufferedRWPair.readinto | (self, b) | return self.reader.readinto(b) | [] | def readinto(self, b):
return self.reader.readinto(b) | [
"def",
"readinto",
"(",
"self",
",",
"b",
")",
":",
"return",
"self",
".",
"reader",
".",
"readinto",
"(",
"b",
")"
] | https://github.com/bruderstein/PythonScript/blob/df9f7071ddf3a079e3a301b9b53a6dc78cf1208f/PythonLib/min/_pyio.py#L1388-L1389 | |||
materialsproject/pymatgen | 8128f3062a334a2edd240e4062b5b9bdd1ae6f58 | pymatgen/analysis/structure_matcher.py | python | OccupancyComparator.are_equal | (self, sp1, sp2) | return set(sp1.element_composition.values()) == set(sp2.element_composition.values()) | Args:
sp1: First species. A dict of {specie/element: amt} as per the
definition in Site and PeriodicSite.
sp2: Second species. A dict of {specie/element: amt} as per the
definition in Site and PeriodicSite.
Returns:
True if sets of occupancies (amt) are equal on both sites. | Args:
sp1: First species. A dict of {specie/element: amt} as per the
definition in Site and PeriodicSite.
sp2: Second species. A dict of {specie/element: amt} as per the
definition in Site and PeriodicSite. | [
"Args",
":",
"sp1",
":",
"First",
"species",
".",
"A",
"dict",
"of",
"{",
"specie",
"/",
"element",
":",
"amt",
"}",
"as",
"per",
"the",
"definition",
"in",
"Site",
"and",
"PeriodicSite",
".",
"sp2",
":",
"Second",
"species",
".",
"A",
"dict",
"of",
... | def are_equal(self, sp1, sp2):
"""
Args:
sp1: First species. A dict of {specie/element: amt} as per the
definition in Site and PeriodicSite.
sp2: Second species. A dict of {specie/element: amt} as per the
definition in Site and PeriodicSite.
Returns:
True if sets of occupancies (amt) are equal on both sites.
"""
return set(sp1.element_composition.values()) == set(sp2.element_composition.values()) | [
"def",
"are_equal",
"(",
"self",
",",
"sp1",
",",
"sp2",
")",
":",
"return",
"set",
"(",
"sp1",
".",
"element_composition",
".",
"values",
"(",
")",
")",
"==",
"set",
"(",
"sp2",
".",
"element_composition",
".",
"values",
"(",
")",
")"
] | https://github.com/materialsproject/pymatgen/blob/8128f3062a334a2edd240e4062b5b9bdd1ae6f58/pymatgen/analysis/structure_matcher.py#L277-L288 | |
snuspl/parallax | 83791254ccd5d7a55213687a8dff4c2e04372694 | parallax/parallax/examples/nmt/scripts/rouge.py | python | _split_into_words | (sentences) | return list(itertools.chain(*[_.split(" ") for _ in sentences])) | Splits multiple sentences into words and flattens the result | Splits multiple sentences into words and flattens the result | [
"Splits",
"multiple",
"sentences",
"into",
"words",
"and",
"flattens",
"the",
"result"
] | def _split_into_words(sentences):
"""Splits multiple sentences into words and flattens the result"""
return list(itertools.chain(*[_.split(" ") for _ in sentences])) | [
"def",
"_split_into_words",
"(",
"sentences",
")",
":",
"return",
"list",
"(",
"itertools",
".",
"chain",
"(",
"*",
"[",
"_",
".",
"split",
"(",
"\" \"",
")",
"for",
"_",
"in",
"sentences",
"]",
")",
")"
] | https://github.com/snuspl/parallax/blob/83791254ccd5d7a55213687a8dff4c2e04372694/parallax/parallax/examples/nmt/scripts/rouge.py#L37-L39 | |
vim-scripts/UltiSnips | 5f88199e373a7eea4644b8dc1ff433688e8f2ebd | pythonx/UltiSnips/snippet/source/file/_base.py | python | SnippetFileSource._parse_snippets | (self, ft, filename) | Parse the 'filename' for the given 'ft' and watch it for changes in
the future. | Parse the 'filename' for the given 'ft' and watch it for changes in
the future. | [
"Parse",
"the",
"filename",
"for",
"the",
"given",
"ft",
"and",
"watch",
"it",
"for",
"changes",
"in",
"the",
"future",
"."
] | def _parse_snippets(self, ft, filename):
"""Parse the 'filename' for the given 'ft' and watch it for changes in
the future."""
self._file_hashes[filename] = _hash_file(filename)
file_data = compatibility.open_ascii_file(filename, 'r').read()
for event, data in self._parse_snippet_file(file_data, filename):
if event == 'error':
msg, line_index = data
filename = _vim.eval("""fnamemodify(%s, ":~:.")""" %
_vim.escape(filename))
raise SnippetSyntaxError(filename, line_index, msg)
elif event == 'clearsnippets':
priority, triggers = data
self._snippets[ft].clear_snippets(priority, triggers)
elif event == 'extends':
# TODO(sirver): extends information is more global
# than one snippet source.
filetypes, = data
self.update_extends(ft, filetypes)
elif event == 'snippet':
snippet, = data
self._snippets[ft].add_snippet(snippet)
else:
assert False, 'Unhandled %s: %r' % (event, data) | [
"def",
"_parse_snippets",
"(",
"self",
",",
"ft",
",",
"filename",
")",
":",
"self",
".",
"_file_hashes",
"[",
"filename",
"]",
"=",
"_hash_file",
"(",
"filename",
")",
"file_data",
"=",
"compatibility",
".",
"open_ascii_file",
"(",
"filename",
",",
"'r'",
... | https://github.com/vim-scripts/UltiSnips/blob/5f88199e373a7eea4644b8dc1ff433688e8f2ebd/pythonx/UltiSnips/snippet/source/file/_base.py#L89-L112 | ||
ntalekt/homeassistant | 8fb6da881564430a3324125ddc2bd43cb7c8680f | custom_components/hacs/api/hacs_config.py | python | hacs_config | (_hass, connection, msg) | Handle get media player cover command. | Handle get media player cover command. | [
"Handle",
"get",
"media",
"player",
"cover",
"command",
"."
] | async def hacs_config(_hass, connection, msg):
"""Handle get media player cover command."""
hacs = get_hacs()
config = hacs.configuration
content = {}
content["frontend_mode"] = config.frontend_mode
content["frontend_compact"] = config.frontend_compact
content["onboarding_done"] = config.onboarding_done
content["version"] = hacs.version
content["frontend_expected"] = hacs.frontend.version_expected
content["frontend_running"] = hacs.frontend.version_running
content["dev"] = config.dev
content["debug"] = config.debug
content["country"] = config.country
content["experimental"] = config.experimental
content["categories"] = hacs.common.categories
connection.send_message(websocket_api.result_message(msg["id"], content)) | [
"async",
"def",
"hacs_config",
"(",
"_hass",
",",
"connection",
",",
"msg",
")",
":",
"hacs",
"=",
"get_hacs",
"(",
")",
"config",
"=",
"hacs",
".",
"configuration",
"content",
"=",
"{",
"}",
"content",
"[",
"\"frontend_mode\"",
"]",
"=",
"config",
".",
... | https://github.com/ntalekt/homeassistant/blob/8fb6da881564430a3324125ddc2bd43cb7c8680f/custom_components/hacs/api/hacs_config.py#L10-L28 | ||
InsaneLife/dssm | 1d32e137654e03994f7ba6cfde52e1d47601027c | model/bert/modeling.py | python | BertModel.get_sequence_output | (self) | return self.sequence_output | Gets final hidden layer of encoder.
Returns:
float Tensor of shape [batch_size, seq_length, hidden_size] corresponding
to the final hidden of the transformer encoder. | Gets final hidden layer of encoder.
Returns:
float Tensor of shape [batch_size, seq_length, hidden_size] corresponding
to the final hidden of the transformer encoder. | [
"Gets",
"final",
"hidden",
"layer",
"of",
"encoder",
".",
"Returns",
":",
"float",
"Tensor",
"of",
"shape",
"[",
"batch_size",
"seq_length",
"hidden_size",
"]",
"corresponding",
"to",
"the",
"final",
"hidden",
"of",
"the",
"transformer",
"encoder",
"."
] | def get_sequence_output(self):
"""Gets final hidden layer of encoder.
Returns:
float Tensor of shape [batch_size, seq_length, hidden_size] corresponding
to the final hidden of the transformer encoder.
"""
return self.sequence_output | [
"def",
"get_sequence_output",
"(",
"self",
")",
":",
"return",
"self",
".",
"sequence_output"
] | https://github.com/InsaneLife/dssm/blob/1d32e137654e03994f7ba6cfde52e1d47601027c/model/bert/modeling.py#L230-L236 | |
flipkart-incubator/RTA | 1559ae0f0087ec2371264ed6dd562c17dabebb84 | rta.py | python | Scan.wp_scan | (self, parent) | Launch WpScan if the techstack used is wordpress. | Launch WpScan if the techstack used is wordpress. | [
"Launch",
"WpScan",
"if",
"the",
"techstack",
"used",
"is",
"wordpress",
"."
] | def wp_scan(self, parent):
"""
Launch WpScan if the techstack used is wordpress.
"""
collection = self.dbname['wpscan']
collection_tech = self.dbname['tech_stack']
count = self.dbname.collection.count()
# collection.create_index('domain', unique=True)
flag = True
for item in collection_tech.find({'parent': parent}):
message = ""
if 'wordpress' in str(item['tech_stack']).lower():
if flag:
message = "[+] *Wpscan report*: (" + item['domain'] + ")\n"
flag = False
result = self.wpscan.scan(item['domain'], parent)
data = {'id': count+1, 'domain': item['domain'], 'time': datetime.now()}
data['version'] = result['version']['number']
message += "Version: `" + data['version'] + "`\n"
data['vulnerabilities'] = []
data['plugins'] = {}
message += "Wordpress core vulnerabilities: \n```\n"
for value in result['version']['vulnerabilities']:
data['vulnerabilities'].append(value['title'])
message += value['title'] + "\n"
message += "```\nPlugins: \n"
for key, value in result['plugins'].iteritems():
if message[-1] != "\n":
message += "```"
message += "\n" + key + ": \n```"
for vuln in value['vulnerabilities']:
message += "\n"
try:
data['plugins'][key].append(vuln['title'])
except:
data['plugins'][key] = []
data['plugins'][key].append(vuln['title'])
message += vuln['title']
# Push the above data to DB
message += "\n```"
print(self.W + message)
self.slack.notify_slack(message)
dataid = collection.insert(data)
count += 1 | [
"def",
"wp_scan",
"(",
"self",
",",
"parent",
")",
":",
"collection",
"=",
"self",
".",
"dbname",
"[",
"'wpscan'",
"]",
"collection_tech",
"=",
"self",
".",
"dbname",
"[",
"'tech_stack'",
"]",
"count",
"=",
"self",
".",
"dbname",
".",
"collection",
".",
... | https://github.com/flipkart-incubator/RTA/blob/1559ae0f0087ec2371264ed6dd562c17dabebb84/rta.py#L309-L362 | ||
Supervisor/supervisor | 7de6215c9677d1418e7f0a72e7065c1fa69174d4 | supervisor/rpcinterface.py | python | SupervisorNamespaceRPCInterface.addProcessGroup | (self, name) | Update the config for a running process from config file.
@param string name name of process group to add
@return boolean result true if successful | Update the config for a running process from config file. | [
"Update",
"the",
"config",
"for",
"a",
"running",
"process",
"from",
"config",
"file",
"."
] | def addProcessGroup(self, name):
""" Update the config for a running process from config file.
@param string name name of process group to add
@return boolean result true if successful
"""
self._update('addProcessGroup')
for config in self.supervisord.options.process_group_configs:
if config.name == name:
result = self.supervisord.add_process_group(config)
if not result:
raise RPCError(Faults.ALREADY_ADDED, name)
return True
raise RPCError(Faults.BAD_NAME, name) | [
"def",
"addProcessGroup",
"(",
"self",
",",
"name",
")",
":",
"self",
".",
"_update",
"(",
"'addProcessGroup'",
")",
"for",
"config",
"in",
"self",
".",
"supervisord",
".",
"options",
".",
"process_group_configs",
":",
"if",
"config",
".",
"name",
"==",
"n... | https://github.com/Supervisor/supervisor/blob/7de6215c9677d1418e7f0a72e7065c1fa69174d4/supervisor/rpcinterface.py#L201-L215 | ||
perone/Pyevolve | 589b6a9b92ed1fd9ef00987bf4bfe807c4a7b7e0 | pyevolve/GTree.py | python | buildGTreeGrow | (depth, value_callback, max_siblings, max_depth) | return n | Random generates a Tree structure using the value_callback
for data generation and the method "Grow"
:param depth: the initial depth, zero
:param value_callback: the function which generates the random
values for nodes
:param max_siblings: the maximum number of sisters of a node
:param max_depth: the maximum depth of the tree
:rtype: the root node of created tree | Random generates a Tree structure using the value_callback
for data generation and the method "Grow" | [
"Random",
"generates",
"a",
"Tree",
"structure",
"using",
"the",
"value_callback",
"for",
"data",
"generation",
"and",
"the",
"method",
"Grow"
] | def buildGTreeGrow(depth, value_callback, max_siblings, max_depth):
""" Random generates a Tree structure using the value_callback
for data generation and the method "Grow"
:param depth: the initial depth, zero
:param value_callback: the function which generates the random
values for nodes
:param max_siblings: the maximum number of sisters of a node
:param max_depth: the maximum depth of the tree
:rtype: the root node of created tree
"""
random_value = value_callback()
n = GTreeNode(random_value)
if depth == max_depth:
return n
for i in xrange(random.randint(0, abs(max_siblings))):
child = buildGTreeGrow(depth + 1, value_callback, max_siblings, max_depth)
child.setParent(n)
n.addChild(child)
return n | [
"def",
"buildGTreeGrow",
"(",
"depth",
",",
"value_callback",
",",
"max_siblings",
",",
"max_depth",
")",
":",
"random_value",
"=",
"value_callback",
"(",
")",
"n",
"=",
"GTreeNode",
"(",
"random_value",
")",
"if",
"depth",
"==",
"max_depth",
":",
"return",
... | https://github.com/perone/Pyevolve/blob/589b6a9b92ed1fd9ef00987bf4bfe807c4a7b7e0/pyevolve/GTree.py#L169-L192 | |
JiYou/openstack | 8607dd488bde0905044b303eb6e52bdea6806923 | chap19/monitor/monitor/monitor/openstack/common/timeutils.py | python | normalize_time | (timestamp) | return timestamp.replace(tzinfo=None) - offset | Normalize time in arbitrary timezone to UTC naive object | Normalize time in arbitrary timezone to UTC naive object | [
"Normalize",
"time",
"in",
"arbitrary",
"timezone",
"to",
"UTC",
"naive",
"object"
] | def normalize_time(timestamp):
"""Normalize time in arbitrary timezone to UTC naive object"""
offset = timestamp.utcoffset()
if offset is None:
return timestamp
return timestamp.replace(tzinfo=None) - offset | [
"def",
"normalize_time",
"(",
"timestamp",
")",
":",
"offset",
"=",
"timestamp",
".",
"utcoffset",
"(",
")",
"if",
"offset",
"is",
"None",
":",
"return",
"timestamp",
"return",
"timestamp",
".",
"replace",
"(",
"tzinfo",
"=",
"None",
")",
"-",
"offset"
] | https://github.com/JiYou/openstack/blob/8607dd488bde0905044b303eb6e52bdea6806923/chap19/monitor/monitor/monitor/openstack/common/timeutils.py#L68-L73 | |
pytroll/satpy | 09e51f932048f98cce7919a4ff8bd2ec01e1ae98 | satpy/readers/mviri_l1b_fiduceo_nc.py | python | DatasetWrapper.__getitem__ | (self, item) | return ds | Get a variable from the dataset. | Get a variable from the dataset. | [
"Get",
"a",
"variable",
"from",
"the",
"dataset",
"."
] | def __getitem__(self, item):
"""Get a variable from the dataset."""
ds = self.nc[item]
if self._should_dims_be_renamed(ds):
ds = self._rename_dims(ds)
elif self._coordinates_not_assigned(ds):
ds = self._reassign_coords(ds)
self._cleanup_attrs(ds)
return ds | [
"def",
"__getitem__",
"(",
"self",
",",
"item",
")",
":",
"ds",
"=",
"self",
".",
"nc",
"[",
"item",
"]",
"if",
"self",
".",
"_should_dims_be_renamed",
"(",
"ds",
")",
":",
"ds",
"=",
"self",
".",
"_rename_dims",
"(",
"ds",
")",
"elif",
"self",
"."... | https://github.com/pytroll/satpy/blob/09e51f932048f98cce7919a4ff8bd2ec01e1ae98/satpy/readers/mviri_l1b_fiduceo_nc.py#L465-L473 | |
NervanaSystems/ngraph-python | ac032c83c7152b615a9ad129d54d350f9d6a2986 | ngraph/op_graph/comm_nodes.py | python | GatherRecvOp.hetr_axes | (self, axes, parallel_axis) | return arg_axes | Override hetr_axes function to ensure GatherRecvOp has the full length
of the parallel_axis rather that parallel_axis.length//num_devices. | Override hetr_axes function to ensure GatherRecvOp has the full length
of the parallel_axis rather that parallel_axis.length//num_devices. | [
"Override",
"hetr_axes",
"function",
"to",
"ensure",
"GatherRecvOp",
"has",
"the",
"full",
"length",
"of",
"the",
"parallel_axis",
"rather",
"that",
"parallel_axis",
".",
"length",
"//",
"num_devices",
"."
] | def hetr_axes(self, axes, parallel_axis):
"""
Override hetr_axes function to ensure GatherRecvOp has the full length
of the parallel_axis rather that parallel_axis.length//num_devices.
"""
arg_axes = super(GatherRecvOp, self).hetr_axes(axes, parallel_axis)
if parallel_axis in axes and \
arg_axes.find_by_name(parallel_axis.name).lengths[0] != parallel_axis.length:
arg_axes = make_axes([parallel_axis if a == parallel_axis else a for a in arg_axes])
return arg_axes | [
"def",
"hetr_axes",
"(",
"self",
",",
"axes",
",",
"parallel_axis",
")",
":",
"arg_axes",
"=",
"super",
"(",
"GatherRecvOp",
",",
"self",
")",
".",
"hetr_axes",
"(",
"axes",
",",
"parallel_axis",
")",
"if",
"parallel_axis",
"in",
"axes",
"and",
"arg_axes",... | https://github.com/NervanaSystems/ngraph-python/blob/ac032c83c7152b615a9ad129d54d350f9d6a2986/ngraph/op_graph/comm_nodes.py#L279-L288 | |
robotlearn/pyrobolearn | 9cd7c060723fda7d2779fa255ac998c2c82b8436 | pyrobolearn/utils/parsers/robots/data_structures.py | python | Light.specular | (self) | return self.material.specular | Return the light specular color. | Return the light specular color. | [
"Return",
"the",
"light",
"specular",
"color",
"."
] | def specular(self):
"""Return the light specular color."""
return self.material.specular | [
"def",
"specular",
"(",
"self",
")",
":",
"return",
"self",
".",
"material",
".",
"specular"
] | https://github.com/robotlearn/pyrobolearn/blob/9cd7c060723fda7d2779fa255ac998c2c82b8436/pyrobolearn/utils/parsers/robots/data_structures.py#L677-L679 | |
securesystemslab/zippy | ff0e84ac99442c2c55fe1d285332cfd4e185e089 | zippy/benchmarks/src/benchmarks/sympy/sympy/ntheory/modular.py | python | solve_congruence | (*remainder_modulus_pairs, **hint) | Compute the integer ``n`` that has the residual ``ai`` when it is
divided by ``mi`` where the ``ai`` and ``mi`` are given as pairs to
this function: ((a1, m1), (a2, m2), ...). If there is no solution,
return None. Otherwise return ``n`` and its modulus.
The ``mi`` values need not be co-prime. If it is known that the moduli are
not co-prime then the hint ``check`` can be set to False (default=True) and
the check for a quicker solution via crt() (valid when the moduli are
co-prime) will be skipped.
If the hint ``symmetric`` is True (default is False), the value of ``n``
will be within 1/2 of the modulus, possibly negative.
Examples
========
>>> from sympy.ntheory.modular import solve_congruence
What number is 2 mod 3, 3 mod 5 and 2 mod 7?
>>> solve_congruence((2, 3), (3, 5), (2, 7))
(23, 105)
>>> [23 % m for m in [3, 5, 7]]
[2, 3, 2]
If you prefer to work with all remainder in one list and
all moduli in another, send the arguments like this:
>>> solve_congruence(*zip((2, 3, 2), (3, 5, 7)))
(23, 105)
The moduli need not be co-prime; in this case there may or
may not be a solution:
>>> solve_congruence((2, 3), (4, 6)) is None
True
>>> solve_congruence((2, 3), (5, 6))
(5, 6)
The symmetric flag will make the result be within 1/2 of the modulus:
>>> solve_congruence((2, 3), (5, 6), symmetric=True)
(-1, 6)
See Also
========
crt : high level routine implementing the Chinese Remainder Theorem | Compute the integer ``n`` that has the residual ``ai`` when it is
divided by ``mi`` where the ``ai`` and ``mi`` are given as pairs to
this function: ((a1, m1), (a2, m2), ...). If there is no solution,
return None. Otherwise return ``n`` and its modulus. | [
"Compute",
"the",
"integer",
"n",
"that",
"has",
"the",
"residual",
"ai",
"when",
"it",
"is",
"divided",
"by",
"mi",
"where",
"the",
"ai",
"and",
"mi",
"are",
"given",
"as",
"pairs",
"to",
"this",
"function",
":",
"((",
"a1",
"m1",
")",
"(",
"a2",
... | def solve_congruence(*remainder_modulus_pairs, **hint):
"""Compute the integer ``n`` that has the residual ``ai`` when it is
divided by ``mi`` where the ``ai`` and ``mi`` are given as pairs to
this function: ((a1, m1), (a2, m2), ...). If there is no solution,
return None. Otherwise return ``n`` and its modulus.
The ``mi`` values need not be co-prime. If it is known that the moduli are
not co-prime then the hint ``check`` can be set to False (default=True) and
the check for a quicker solution via crt() (valid when the moduli are
co-prime) will be skipped.
If the hint ``symmetric`` is True (default is False), the value of ``n``
will be within 1/2 of the modulus, possibly negative.
Examples
========
>>> from sympy.ntheory.modular import solve_congruence
What number is 2 mod 3, 3 mod 5 and 2 mod 7?
>>> solve_congruence((2, 3), (3, 5), (2, 7))
(23, 105)
>>> [23 % m for m in [3, 5, 7]]
[2, 3, 2]
If you prefer to work with all remainder in one list and
all moduli in another, send the arguments like this:
>>> solve_congruence(*zip((2, 3, 2), (3, 5, 7)))
(23, 105)
The moduli need not be co-prime; in this case there may or
may not be a solution:
>>> solve_congruence((2, 3), (4, 6)) is None
True
>>> solve_congruence((2, 3), (5, 6))
(5, 6)
The symmetric flag will make the result be within 1/2 of the modulus:
>>> solve_congruence((2, 3), (5, 6), symmetric=True)
(-1, 6)
See Also
========
crt : high level routine implementing the Chinese Remainder Theorem
"""
def combine(c1, c2):
"""Return the tuple (a, m) which satisfies the requirement
that n = a + i*m satisfy n = a1 + j*m1 and n = a2 = k*m2.
References
==========
- http://en.wikipedia.org/wiki/Method_of_successive_substitution
"""
a1, m1 = c1
a2, m2 = c2
a, b, c = m1, a2 - a1, m2
g = reduce(igcd, [a, b, c])
a, b, c = [i//g for i in [a, b, c]]
if a != 1:
inv_a, _, g = igcdex(a, c)
if g != 1:
return None
b *= inv_a
a, m = a1 + m1*b, m1*c
return a, m
rm = remainder_modulus_pairs
symmetric = hint.get('symmetric', False)
if hint.get('check', True):
rm = [(as_int(r), as_int(m)) for r, m in rm]
# ignore redundant pairs but raise an error otherwise; also
# make sure that a unique set of bases is sent to gf_crt if
# they are all prime.
#
# The routine will work out less-trivial violations and
# return None, e.g. for the pairs (1,3) and (14,42) there
# is no answer because 14 mod 42 (having a gcd of 14) implies
# (14/2) mod (42/2), (14/7) mod (42/7) and (14/14) mod (42/14)
# which, being 0 mod 3, is inconsistent with 1 mod 3. But to
# preprocess the input beyond checking of another pair with 42
# or 3 as the modulus (for this example) is not necessary.
uniq = {}
for r, m in rm:
r %= m
if m in uniq:
if r != uniq[m]:
return None
continue
uniq[m] = r
rm = [(r, m) for m, r in uniq.items()]
del uniq
# if the moduli are co-prime, the crt will be significantly faster;
# checking all pairs for being co-prime gets to be slow but a prime
# test is a good trade-off
if all(isprime(m) for r, m in rm):
r, m = list(zip(*rm))
return crt(m, r, symmetric=symmetric, check=False)
rv = (0, 1)
for rmi in rm:
rv = combine(rv, rmi)
if rv is None:
break
n, m = rv
n = n % m
else:
if symmetric:
return symmetric_residue(n, m), m
return n, m | [
"def",
"solve_congruence",
"(",
"*",
"remainder_modulus_pairs",
",",
"*",
"*",
"hint",
")",
":",
"def",
"combine",
"(",
"c1",
",",
"c2",
")",
":",
"\"\"\"Return the tuple (a, m) which satisfies the requirement\n that n = a + i*m satisfy n = a1 + j*m1 and n = a2 = k*m2.\n... | https://github.com/securesystemslab/zippy/blob/ff0e84ac99442c2c55fe1d285332cfd4e185e089/zippy/benchmarks/src/benchmarks/sympy/sympy/ntheory/modular.py#L133-L252 | ||
shadowmoose/RedditDownloader | ffe38afbee64e094fe80de2267ea049401bfb2f2 | redditdownloader/static/settings.py | python | remove_source | (source, save_after=True) | Removes the given Source from the list of sources, and resaves (if set). | Removes the given Source from the list of sources, and resaves (if set). | [
"Removes",
"the",
"given",
"Source",
"from",
"the",
"list",
"of",
"sources",
"and",
"resaves",
"(",
"if",
"set",
")",
"."
] | def remove_source(source, save_after=True):
""" Removes the given Source from the list of sources, and resaves (if set). """
new_sources = [s for s in get_sources() if s.get_alias() != source.get_alias()]
put('sources', [s.to_obj() for s in new_sources], save_after=save_after) | [
"def",
"remove_source",
"(",
"source",
",",
"save_after",
"=",
"True",
")",
":",
"new_sources",
"=",
"[",
"s",
"for",
"s",
"in",
"get_sources",
"(",
")",
"if",
"s",
".",
"get_alias",
"(",
")",
"!=",
"source",
".",
"get_alias",
"(",
")",
"]",
"put",
... | https://github.com/shadowmoose/RedditDownloader/blob/ffe38afbee64e094fe80de2267ea049401bfb2f2/redditdownloader/static/settings.py#L143-L146 | ||
Arachnid/bloggart | ba2b60417102fe14a77b1bcd809b9b801d3a96e2 | lib/xsrfutil.py | python | generate_token | (key, user_id, path="", when=None) | return token | Generates a URL-safe token for the given user, action, time tuple.
Args:
key: secret key to use.
user_id: the user ID of the authenticated user.
path: The path the token should be valid for.
when: the time in seconds since the epoch at which the user was
authorized for this action. If not set the current time is used.
Returns:
A string XSRF protection token. | Generates a URL-safe token for the given user, action, time tuple. | [
"Generates",
"a",
"URL",
"-",
"safe",
"token",
"for",
"the",
"given",
"user",
"action",
"time",
"tuple",
"."
] | def generate_token(key, user_id, path="", when=None):
"""Generates a URL-safe token for the given user, action, time tuple.
Args:
key: secret key to use.
user_id: the user ID of the authenticated user.
path: The path the token should be valid for.
when: the time in seconds since the epoch at which the user was
authorized for this action. If not set the current time is used.
Returns:
A string XSRF protection token.
"""
when = when or int(time.time())
digester = hmac.new(str(key))
digester.update(str(user_id))
digester.update(DELIMITER)
digester.update(str(path))
digester.update(DELIMITER)
digester.update(str(when))
digest = digester.digest()
token = base64.urlsafe_b64encode('%s%s%d' % (digest,
DELIMITER,
when))
return token | [
"def",
"generate_token",
"(",
"key",
",",
"user_id",
",",
"path",
"=",
"\"\"",
",",
"when",
"=",
"None",
")",
":",
"when",
"=",
"when",
"or",
"int",
"(",
"time",
".",
"time",
"(",
")",
")",
"digester",
"=",
"hmac",
".",
"new",
"(",
"str",
"(",
... | https://github.com/Arachnid/bloggart/blob/ba2b60417102fe14a77b1bcd809b9b801d3a96e2/lib/xsrfutil.py#L46-L71 | |
deanishe/alfred-vpn-manager | f5d0dd1433ea69b1517d4866a12b1118097057b9 | src/workflow/web.py | python | Response.save_to_path | (self, filepath) | Save retrieved data to file at ``filepath``.
.. versionadded: 1.9.6
:param filepath: Path to save retrieved data. | Save retrieved data to file at ``filepath``. | [
"Save",
"retrieved",
"data",
"to",
"file",
"at",
"filepath",
"."
] | def save_to_path(self, filepath):
"""Save retrieved data to file at ``filepath``.
.. versionadded: 1.9.6
:param filepath: Path to save retrieved data.
"""
filepath = os.path.abspath(filepath)
dirname = os.path.dirname(filepath)
if not os.path.exists(dirname):
os.makedirs(dirname)
self.stream = True
with open(filepath, 'wb') as fileobj:
for data in self.iter_content():
fileobj.write(data) | [
"def",
"save_to_path",
"(",
"self",
",",
"filepath",
")",
":",
"filepath",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"filepath",
")",
"dirname",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"filepath",
")",
"if",
"not",
"os",
".",
"path",
".",
"... | https://github.com/deanishe/alfred-vpn-manager/blob/f5d0dd1433ea69b1517d4866a12b1118097057b9/src/workflow/web.py#L388-L405 | ||
pymeasure/pymeasure | b4d888e9ead85ef7f7af0031f2dbb44c9ce1825e | pymeasure/instruments/keithley/keithley2400.py | python | Keithley2400.auto_range_source | (self) | Configures the source to use an automatic range. | Configures the source to use an automatic range. | [
"Configures",
"the",
"source",
"to",
"use",
"an",
"automatic",
"range",
"."
] | def auto_range_source(self):
""" Configures the source to use an automatic range.
"""
if self.source_mode == 'current':
self.write(":SOUR:CURR:RANG:AUTO 1")
else:
self.write(":SOUR:VOLT:RANG:AUTO 1") | [
"def",
"auto_range_source",
"(",
"self",
")",
":",
"if",
"self",
".",
"source_mode",
"==",
"'current'",
":",
"self",
".",
"write",
"(",
"\":SOUR:CURR:RANG:AUTO 1\"",
")",
"else",
":",
"self",
".",
"write",
"(",
"\":SOUR:VOLT:RANG:AUTO 1\"",
")"
] | https://github.com/pymeasure/pymeasure/blob/b4d888e9ead85ef7f7af0031f2dbb44c9ce1825e/pymeasure/instruments/keithley/keithley2400.py#L436-L442 | ||
ym2011/POC-EXP | 206b22d3a6b2a172359678df33bbc5b2ad04b6c3 | windows/SYNfulKnock/scapy-2.3.1/scapy/contrib/gsm_um.py | python | systemInformationType5 | () | return packet | SYSTEM INFORMATION TYPE 5 Section 9.1.37 | SYSTEM INFORMATION TYPE 5 Section 9.1.37 | [
"SYSTEM",
"INFORMATION",
"TYPE",
"5",
"Section",
"9",
".",
"1",
".",
"37"
] | def systemInformationType5():
"""SYSTEM INFORMATION TYPE 5 Section 9.1.37"""
a = L2PseudoLength(l2pLength=0x12)
b = TpPd(pd=0x6)
c = MessageType(mesType=0x35) # 000110101
d = NeighbourCellsDescription()
packet = a / b / c / d
return packet | [
"def",
"systemInformationType5",
"(",
")",
":",
"a",
"=",
"L2PseudoLength",
"(",
"l2pLength",
"=",
"0x12",
")",
"b",
"=",
"TpPd",
"(",
"pd",
"=",
"0x6",
")",
"c",
"=",
"MessageType",
"(",
"mesType",
"=",
"0x35",
")",
"# 000110101",
"d",
"=",
"Neighbour... | https://github.com/ym2011/POC-EXP/blob/206b22d3a6b2a172359678df33bbc5b2ad04b6c3/windows/SYNfulKnock/scapy-2.3.1/scapy/contrib/gsm_um.py#L1081-L1088 | |
hyperledger/aries-cloudagent-python | 2f36776e99f6053ae92eed8123b5b1b2e891c02a | aries_cloudagent/storage/in_memory.py | python | InMemoryStorage.find_all_records | (
self,
type_filter: str,
tag_query: Mapping = None,
options: Mapping = None,
) | return results | Retrieve all records matching a particular type filter and tag query. | Retrieve all records matching a particular type filter and tag query. | [
"Retrieve",
"all",
"records",
"matching",
"a",
"particular",
"type",
"filter",
"and",
"tag",
"query",
"."
] | async def find_all_records(
self,
type_filter: str,
tag_query: Mapping = None,
options: Mapping = None,
):
"""Retrieve all records matching a particular type filter and tag query."""
results = []
for record in self.profile.records.values():
if record.type == type_filter and tag_query_match(record.tags, tag_query):
results.append(record)
return results | [
"async",
"def",
"find_all_records",
"(",
"self",
",",
"type_filter",
":",
"str",
",",
"tag_query",
":",
"Mapping",
"=",
"None",
",",
"options",
":",
"Mapping",
"=",
"None",
",",
")",
":",
"results",
"=",
"[",
"]",
"for",
"record",
"in",
"self",
".",
... | https://github.com/hyperledger/aries-cloudagent-python/blob/2f36776e99f6053ae92eed8123b5b1b2e891c02a/aries_cloudagent/storage/in_memory.py#L111-L122 | |
rytilahti/python-miio | b6e53dd16fac77915426e7592e2528b78ef65190 | miio/airhumidifier.py | python | AirHumidifierStatus.child_lock | (self) | return self.data["child_lock"] == "on" | Return True if child lock is on. | Return True if child lock is on. | [
"Return",
"True",
"if",
"child",
"lock",
"is",
"on",
"."
] | def child_lock(self) -> bool:
"""Return True if child lock is on."""
return self.data["child_lock"] == "on" | [
"def",
"child_lock",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"data",
"[",
"\"child_lock\"",
"]",
"==",
"\"on\""
] | https://github.com/rytilahti/python-miio/blob/b6e53dd16fac77915426e7592e2528b78ef65190/miio/airhumidifier.py#L130-L132 | |
miracle2k/k8s-snapshots | 9dbb5fc3a99c847f696d35549ff751f994585012 | k8s_snapshots/backends/google.py | python | get_gcloud | (ctx, version: str= 'v1') | return compute | Get a configured Google Compute API Client instance.
Note that the Google API Client is not threadsafe. Cache the instance locally
if you want to avoid OAuth overhead between calls.
Parameters
----------
version
Compute API version | Get a configured Google Compute API Client instance. | [
"Get",
"a",
"configured",
"Google",
"Compute",
"API",
"Client",
"instance",
"."
] | def get_gcloud(ctx, version: str= 'v1'):
"""
Get a configured Google Compute API Client instance.
Note that the Google API Client is not threadsafe. Cache the instance locally
if you want to avoid OAuth overhead between calls.
Parameters
----------
version
Compute API version
"""
SCOPES = 'https://www.googleapis.com/auth/compute'
credentials = None
if ctx.config.get('gcloud_credentials_file'):
credentials = ServiceAccountCredentials.from_json_keyfile_name(
ctx.config.get('gcloud_credentials_file'),
scopes=SCOPES)
if ctx.config.get('google_application_credentials'):
keyfile = json.loads(ctx.config.get('google_application_credentials'))
credentials = ServiceAccountCredentials.from_json_keyfile_dict(
keyfile, scopes=SCOPES)
if not credentials:
credentials = GoogleCredentials.get_application_default()
if not credentials:
raise RuntimeError("Auth for Google Cloud was not configured")
compute = discovery.build(
'compute',
version,
credentials=credentials,
# https://github.com/google/google-api-python-client/issues/299#issuecomment-268915510
cache_discovery=False
)
return compute | [
"def",
"get_gcloud",
"(",
"ctx",
",",
"version",
":",
"str",
"=",
"'v1'",
")",
":",
"SCOPES",
"=",
"'https://www.googleapis.com/auth/compute'",
"credentials",
"=",
"None",
"if",
"ctx",
".",
"config",
".",
"get",
"(",
"'gcloud_credentials_file'",
")",
":",
"cre... | https://github.com/miracle2k/k8s-snapshots/blob/9dbb5fc3a99c847f696d35549ff751f994585012/k8s_snapshots/backends/google.py#L354-L392 | |
fwenzel/django-sha2 | f4519bf0cc9b1dd7a7d78394fa4aec4504bc86e9 | django_sha2/hashers.py | python | BcryptHMACCombinedPasswordVerifier._hmac_create | (self, password, shared_key) | return hmac_value | Create HMAC value based on pwd | Create HMAC value based on pwd | [
"Create",
"HMAC",
"value",
"based",
"on",
"pwd"
] | def _hmac_create(self, password, shared_key):
"""Create HMAC value based on pwd"""
hmac_value = base64.b64encode(hmac.new(
smart_str(shared_key),
smart_str(password),
hashlib.sha512).digest())
return hmac_value | [
"def",
"_hmac_create",
"(",
"self",
",",
"password",
",",
"shared_key",
")",
":",
"hmac_value",
"=",
"base64",
".",
"b64encode",
"(",
"hmac",
".",
"new",
"(",
"smart_str",
"(",
"shared_key",
")",
",",
"smart_str",
"(",
"password",
")",
",",
"hashlib",
".... | https://github.com/fwenzel/django-sha2/blob/f4519bf0cc9b1dd7a7d78394fa4aec4504bc86e9/django_sha2/hashers.py#L104-L110 | |
wwqgtxx/wwqLyParse | 33136508e52821babd9294fdecffbdf02d73a6fc | wwqLyParse/lib/aiohttp_lib/aiohttp/web_urldispatcher.py | python | UrlDispatcher.add_post | (self, path: str, handler: _WebHandler,
**kwargs: Any) | return self.add_route(hdrs.METH_POST, path, handler, **kwargs) | Shortcut for add_route with method POST | Shortcut for add_route with method POST | [
"Shortcut",
"for",
"add_route",
"with",
"method",
"POST"
] | def add_post(self, path: str, handler: _WebHandler,
**kwargs: Any) -> AbstractRoute:
"""
Shortcut for add_route with method POST
"""
return self.add_route(hdrs.METH_POST, path, handler, **kwargs) | [
"def",
"add_post",
"(",
"self",
",",
"path",
":",
"str",
",",
"handler",
":",
"_WebHandler",
",",
"*",
"*",
"kwargs",
":",
"Any",
")",
"->",
"AbstractRoute",
":",
"return",
"self",
".",
"add_route",
"(",
"hdrs",
".",
"METH_POST",
",",
"path",
",",
"h... | https://github.com/wwqgtxx/wwqLyParse/blob/33136508e52821babd9294fdecffbdf02d73a6fc/wwqLyParse/lib/aiohttp_lib/aiohttp/web_urldispatcher.py#L1067-L1072 | |
Tautulli/Tautulli | 2410eb33805aaac4bd1c5dad0f71e4f15afaf742 | lib/urllib3/contrib/pyopenssl.py | python | _verify_callback | (cnx, x509, err_no, err_depth, return_code) | return err_no == 0 | [] | def _verify_callback(cnx, x509, err_no, err_depth, return_code):
return err_no == 0 | [
"def",
"_verify_callback",
"(",
"cnx",
",",
"x509",
",",
"err_no",
",",
"err_depth",
",",
"return_code",
")",
":",
"return",
"err_no",
"==",
"0"
] | https://github.com/Tautulli/Tautulli/blob/2410eb33805aaac4bd1c5dad0f71e4f15afaf742/lib/urllib3/contrib/pyopenssl.py#L510-L511 | |||
NordicSemiconductor/pc-nrfutil | d08e742128f2a3dac522601bc6b9f9b2b63952df | nordicsemi/thread/ncp_flasher.py | python | NCPFlasher.verify | (self, path) | return self.call_cmd(args) | [] | def verify(self, path):
args = ['--verify', path]
return self.call_cmd(args) | [
"def",
"verify",
"(",
"self",
",",
"path",
")",
":",
"args",
"=",
"[",
"'--verify'",
",",
"path",
"]",
"return",
"self",
".",
"call_cmd",
"(",
"args",
")"
] | https://github.com/NordicSemiconductor/pc-nrfutil/blob/d08e742128f2a3dac522601bc6b9f9b2b63952df/nordicsemi/thread/ncp_flasher.py#L50-L52 | |||
huggingface/transformers | 623b4f7c63f60cce917677ee704d6c93ee960b4b | examples/research_projects/longform-qa/eli5_utils.py | python | embed_passages_for_retrieval | (passages, tokenizer, qa_embedder, max_length=128, device="cuda:0") | return a_reps.numpy() | [] | def embed_passages_for_retrieval(passages, tokenizer, qa_embedder, max_length=128, device="cuda:0"):
a_toks = tokenizer(passages, max_length=max_length, padding="max_length", truncation=True)
a_ids, a_mask = (
torch.LongTensor(a_toks["input_ids"]).to(device),
torch.LongTensor(a_toks["attention_mask"]).to(device),
)
with torch.no_grad():
a_reps = qa_embedder.embed_answers(a_ids, a_mask).cpu().type(torch.float)
return a_reps.numpy() | [
"def",
"embed_passages_for_retrieval",
"(",
"passages",
",",
"tokenizer",
",",
"qa_embedder",
",",
"max_length",
"=",
"128",
",",
"device",
"=",
"\"cuda:0\"",
")",
":",
"a_toks",
"=",
"tokenizer",
"(",
"passages",
",",
"max_length",
"=",
"max_length",
",",
"pa... | https://github.com/huggingface/transformers/blob/623b4f7c63f60cce917677ee704d6c93ee960b4b/examples/research_projects/longform-qa/eli5_utils.py#L568-L576 | |||
CGATOxford/cgat | 326aad4694bdfae8ddc194171bb5d73911243947 | obsolete/pipeline_vitaminD.py | python | runBioProspector | ( infiles, outfile ) | run bioprospector for motif discovery.
Bioprospector is run on only the top 10% of peaks. | run bioprospector for motif discovery. | [
"run",
"bioprospector",
"for",
"motif",
"discovery",
"."
] | def runBioProspector( infiles, outfile ):
'''run bioprospector for motif discovery.
Bioprospector is run on only the top 10% of peaks.
'''
to_cluster = True
# only use new nodes, as /bin/csh is not installed
# on the old ones.
job_options = "-l mem_free=8000M"
tmpfasta = P.getTempFilename( "." )
track = outfile[:-len(".bioprospector")]
nseq = writeSequencesForIntervals( track,
tmpfasta,
full = True,
masker = "dust",
proportion = 0.10 )
statement = '''
%(motifs_execbioprospector)s -i %(tmpfasta)s %(motifs_bioprospector_options)s -o %(outfile)s > %(outfile)s.log
'''
P.run()
os.unlink( tmpfasta ) | [
"def",
"runBioProspector",
"(",
"infiles",
",",
"outfile",
")",
":",
"to_cluster",
"=",
"True",
"# only use new nodes, as /bin/csh is not installed",
"# on the old ones.",
"job_options",
"=",
"\"-l mem_free=8000M\"",
"tmpfasta",
"=",
"P",
".",
"getTempFilename",
"(",
"\".... | https://github.com/CGATOxford/cgat/blob/326aad4694bdfae8ddc194171bb5d73911243947/obsolete/pipeline_vitaminD.py#L3724-L3748 | ||
dib-lab/khmer | fb65d21eaedf0d397d49ae3debc578897f9d6eb4 | khmer/_version.py | python | git_get_keywords | (versionfile_abs) | return keywords | Extract version information from the given file. | Extract version information from the given file. | [
"Extract",
"version",
"information",
"from",
"the",
"given",
"file",
"."
] | def git_get_keywords(versionfile_abs):
"""Extract version information from the given file."""
# the code embedded in _version.py can just fetch the value of these
# keywords. When used from setup.py, we don't want to import _version.py,
# so we do it with a regexp instead. This function is not used from
# _version.py.
keywords = {}
try:
f = open(versionfile_abs, "r")
for line in f.readlines():
if line.strip().startswith("git_refnames ="):
mo = re.search(r'=\s*"(.*)"', line)
if mo:
keywords["refnames"] = mo.group(1)
if line.strip().startswith("git_full ="):
mo = re.search(r'=\s*"(.*)"', line)
if mo:
keywords["full"] = mo.group(1)
if line.strip().startswith("git_date ="):
mo = re.search(r'=\s*"(.*)"', line)
if mo:
keywords["date"] = mo.group(1)
f.close()
except EnvironmentError:
pass
return keywords | [
"def",
"git_get_keywords",
"(",
"versionfile_abs",
")",
":",
"# the code embedded in _version.py can just fetch the value of these",
"# keywords. When used from setup.py, we don't want to import _version.py,",
"# so we do it with a regexp instead. This function is not used from",
"# _version.py.",... | https://github.com/dib-lab/khmer/blob/fb65d21eaedf0d397d49ae3debc578897f9d6eb4/khmer/_version.py#L133-L158 | |
fake-name/ReadableWebProxy | ed5c7abe38706acc2684a1e6cd80242a03c5f010 | WebMirror/management/rss_parser_funcs/feed_parse_extractSkinnarviksbergetWordpressCom.py | python | extractSkinnarviksbergetWordpressCom | (item) | return False | Parser for 'skinnarviksberget.wordpress.com' | Parser for 'skinnarviksberget.wordpress.com' | [
"Parser",
"for",
"skinnarviksberget",
".",
"wordpress",
".",
"com"
] | def extractSkinnarviksbergetWordpressCom(item):
'''
Parser for 'skinnarviksberget.wordpress.com'
'''
vol, chp, frag, postfix = extractVolChapterFragmentPostfix(item['title'])
if not (chp or vol) or "preview" in item['title'].lower():
return None
if item['tags'] == ['未分类']:
titlemap = [
('Sinister Ex-Girlfriend', 'Sinister Ex-Girlfriend', 'translated'),
('Tensei Shoujo no Rirekisho', 'Tensei Shoujo no Rirekisho', 'translated'),
('Master of Dungeon', 'Master of Dungeon', 'oel'),
('Handsome Friend', 'Handsome Friend', 'translated'),
('Strategy to Capture Men', 'Strategy to Capture Men', 'translated'),
('before the divorce', 'before the divorce', 'translated'),
]
for titlecomponent, name, tl_type in titlemap:
if titlecomponent.lower() in item['title'].lower():
return buildReleaseMessageWithType(item, name, vol, chp, frag=frag, postfix=postfix, tl_type=tl_type)
tagmap = [
('handsome friend', 'handsome friend', 'translated'),
('before the divorce', 'before the divorce', 'translated'),
('stcm', 'Strategy to Capture Men', 'translated'),
('PRC', 'PRC', 'translated'),
('Loiterous', 'Loiterous', 'oel'),
]
for tagname, name, tl_type in tagmap:
if tagname in item['tags']:
return buildReleaseMessageWithType(item, name, vol, chp, frag=frag, postfix=postfix, tl_type=tl_type)
return False | [
"def",
"extractSkinnarviksbergetWordpressCom",
"(",
"item",
")",
":",
"vol",
",",
"chp",
",",
"frag",
",",
"postfix",
"=",
"extractVolChapterFragmentPostfix",
"(",
"item",
"[",
"'title'",
"]",
")",
"if",
"not",
"(",
"chp",
"or",
"vol",
")",
"or",
"\"preview\... | https://github.com/fake-name/ReadableWebProxy/blob/ed5c7abe38706acc2684a1e6cd80242a03c5f010/WebMirror/management/rss_parser_funcs/feed_parse_extractSkinnarviksbergetWordpressCom.py#L1-L38 | |
ArunMichaelDsouza/tensorflow-image-detection | cbc4afd9bb9dfe26e6a2a6fa8a823bf556aa2367 | retrain.py | python | add_input_distortions | (flip_left_right, random_crop, random_scale,
random_brightness) | return jpeg_data, distort_result | Creates the operations to apply the specified distortions.
During training it can help to improve the results if we run the images
through simple distortions like crops, scales, and flips. These reflect the
kind of variations we expect in the real world, and so can help train the
model to cope with natural data more effectively. Here we take the supplied
parameters and construct a network of operations to apply them to an image.
Cropping
~~~~~~~~
Cropping is done by placing a bounding box at a random position in the full
image. The cropping parameter controls the size of that box relative to the
input image. If it's zero, then the box is the same size as the input and no
cropping is performed. If the value is 50%, then the crop box will be half the
width and height of the input. In a diagram it looks like this:
< width >
+---------------------+
| |
| width - crop% |
| < > |
| +------+ |
| | | |
| | | |
| | | |
| +------+ |
| |
| |
+---------------------+
Scaling
~~~~~~~
Scaling is a lot like cropping, except that the bounding box is always
centered and its size varies randomly within the given range. For example if
the scale percentage is zero, then the bounding box is the same size as the
input and no scaling is applied. If it's 50%, then the bounding box will be in
a random range between half the width and height and full size.
Args:
flip_left_right: Boolean whether to randomly mirror images horizontally.
random_crop: Integer percentage setting the total margin used around the
crop box.
random_scale: Integer percentage of how much to vary the scale by.
random_brightness: Integer range to randomly multiply the pixel values by.
graph.
Returns:
The jpeg input layer and the distorted result tensor. | Creates the operations to apply the specified distortions. | [
"Creates",
"the",
"operations",
"to",
"apply",
"the",
"specified",
"distortions",
"."
] | def add_input_distortions(flip_left_right, random_crop, random_scale,
random_brightness):
"""Creates the operations to apply the specified distortions.
During training it can help to improve the results if we run the images
through simple distortions like crops, scales, and flips. These reflect the
kind of variations we expect in the real world, and so can help train the
model to cope with natural data more effectively. Here we take the supplied
parameters and construct a network of operations to apply them to an image.
Cropping
~~~~~~~~
Cropping is done by placing a bounding box at a random position in the full
image. The cropping parameter controls the size of that box relative to the
input image. If it's zero, then the box is the same size as the input and no
cropping is performed. If the value is 50%, then the crop box will be half the
width and height of the input. In a diagram it looks like this:
< width >
+---------------------+
| |
| width - crop% |
| < > |
| +------+ |
| | | |
| | | |
| | | |
| +------+ |
| |
| |
+---------------------+
Scaling
~~~~~~~
Scaling is a lot like cropping, except that the bounding box is always
centered and its size varies randomly within the given range. For example if
the scale percentage is zero, then the bounding box is the same size as the
input and no scaling is applied. If it's 50%, then the bounding box will be in
a random range between half the width and height and full size.
Args:
flip_left_right: Boolean whether to randomly mirror images horizontally.
random_crop: Integer percentage setting the total margin used around the
crop box.
random_scale: Integer percentage of how much to vary the scale by.
random_brightness: Integer range to randomly multiply the pixel values by.
graph.
Returns:
The jpeg input layer and the distorted result tensor.
"""
jpeg_data = tf.placeholder(tf.string, name='DistortJPGInput')
decoded_image = tf.image.decode_jpeg(jpeg_data, channels=MODEL_INPUT_DEPTH)
decoded_image_as_float = tf.cast(decoded_image, dtype=tf.float32)
decoded_image_4d = tf.expand_dims(decoded_image_as_float, 0)
margin_scale = 1.0 + (random_crop / 100.0)
resize_scale = 1.0 + (random_scale / 100.0)
margin_scale_value = tf.constant(margin_scale)
resize_scale_value = tf.random_uniform(tensor_shape.scalar(),
minval=1.0,
maxval=resize_scale)
scale_value = tf.multiply(margin_scale_value, resize_scale_value)
precrop_width = tf.multiply(scale_value, MODEL_INPUT_WIDTH)
precrop_height = tf.multiply(scale_value, MODEL_INPUT_HEIGHT)
precrop_shape = tf.stack([precrop_height, precrop_width])
precrop_shape_as_int = tf.cast(precrop_shape, dtype=tf.int32)
precropped_image = tf.image.resize_bilinear(decoded_image_4d,
precrop_shape_as_int)
precropped_image_3d = tf.squeeze(precropped_image, squeeze_dims=[0])
cropped_image = tf.random_crop(precropped_image_3d,
[MODEL_INPUT_HEIGHT, MODEL_INPUT_WIDTH,
MODEL_INPUT_DEPTH])
if flip_left_right:
flipped_image = tf.image.random_flip_left_right(cropped_image)
else:
flipped_image = cropped_image
brightness_min = 1.0 - (random_brightness / 100.0)
brightness_max = 1.0 + (random_brightness / 100.0)
brightness_value = tf.random_uniform(tensor_shape.scalar(),
minval=brightness_min,
maxval=brightness_max)
brightened_image = tf.multiply(flipped_image, brightness_value)
distort_result = tf.expand_dims(brightened_image, 0, name='DistortResult')
return jpeg_data, distort_result | [
"def",
"add_input_distortions",
"(",
"flip_left_right",
",",
"random_crop",
",",
"random_scale",
",",
"random_brightness",
")",
":",
"jpeg_data",
"=",
"tf",
".",
"placeholder",
"(",
"tf",
".",
"string",
",",
"name",
"=",
"'DistortJPGInput'",
")",
"decoded_image",
... | https://github.com/ArunMichaelDsouza/tensorflow-image-detection/blob/cbc4afd9bb9dfe26e6a2a6fa8a823bf556aa2367/retrain.py#L614-L700 | |
yahoo/open_nsfw | a4e13931465f4380742545932657eeea0a10aa48 | classify_nsfw.py | python | caffe_preprocess_and_compute | (pimg, caffe_transformer=None, caffe_net=None,
output_layers=None) | Run a Caffe network on an input image after preprocessing it to prepare
it for Caffe.
:param PIL.Image pimg:
PIL image to be input into Caffe.
:param caffe.Net caffe_net:
A Caffe network with which to process pimg afrer preprocessing.
:param list output_layers:
A list of the names of the layers from caffe_net whose outputs are to
to be returned. If this is None, the default outputs for the network
are returned.
:return:
Returns the requested outputs from the Caffe net. | Run a Caffe network on an input image after preprocessing it to prepare
it for Caffe.
:param PIL.Image pimg:
PIL image to be input into Caffe.
:param caffe.Net caffe_net:
A Caffe network with which to process pimg afrer preprocessing.
:param list output_layers:
A list of the names of the layers from caffe_net whose outputs are to
to be returned. If this is None, the default outputs for the network
are returned.
:return:
Returns the requested outputs from the Caffe net. | [
"Run",
"a",
"Caffe",
"network",
"on",
"an",
"input",
"image",
"after",
"preprocessing",
"it",
"to",
"prepare",
"it",
"for",
"Caffe",
".",
":",
"param",
"PIL",
".",
"Image",
"pimg",
":",
"PIL",
"image",
"to",
"be",
"input",
"into",
"Caffe",
".",
":",
... | def caffe_preprocess_and_compute(pimg, caffe_transformer=None, caffe_net=None,
output_layers=None):
"""
Run a Caffe network on an input image after preprocessing it to prepare
it for Caffe.
:param PIL.Image pimg:
PIL image to be input into Caffe.
:param caffe.Net caffe_net:
A Caffe network with which to process pimg afrer preprocessing.
:param list output_layers:
A list of the names of the layers from caffe_net whose outputs are to
to be returned. If this is None, the default outputs for the network
are returned.
:return:
Returns the requested outputs from the Caffe net.
"""
if caffe_net is not None:
# Grab the default output names if none were requested specifically.
if output_layers is None:
output_layers = caffe_net.outputs
img_data_rs = resize_image(pimg, sz=(256, 256))
image = caffe.io.load_image(StringIO(img_data_rs))
H, W, _ = image.shape
_, _, h, w = caffe_net.blobs['data'].data.shape
h_off = max((H - h) / 2, 0)
w_off = max((W - w) / 2, 0)
crop = image[h_off:h_off + h, w_off:w_off + w, :]
transformed_image = caffe_transformer.preprocess('data', crop)
transformed_image.shape = (1,) + transformed_image.shape
input_name = caffe_net.inputs[0]
all_outputs = caffe_net.forward_all(blobs=output_layers,
**{input_name: transformed_image})
outputs = all_outputs[output_layers[0]][0].astype(float)
return outputs
else:
return [] | [
"def",
"caffe_preprocess_and_compute",
"(",
"pimg",
",",
"caffe_transformer",
"=",
"None",
",",
"caffe_net",
"=",
"None",
",",
"output_layers",
"=",
"None",
")",
":",
"if",
"caffe_net",
"is",
"not",
"None",
":",
"# Grab the default output names if none were requested ... | https://github.com/yahoo/open_nsfw/blob/a4e13931465f4380742545932657eeea0a10aa48/classify_nsfw.py#L40-L80 | ||
sagemath/sage | f9b2db94f675ff16963ccdefba4f1a3393b3fe0d | src/sage/functions/other.py | python | Function_cases._print_latex_ | (self, l, **kwargs) | return str[:-2] + r"\end{cases}" | r"""
EXAMPLES::
sage: ex = cases([(x==0, pi), (True, 0)]); ex
cases(((x == 0, pi), (1, 0)))
sage: latex(ex)
\begin{cases}{\pi} & {x = 0}\\{0} & {1}\end{cases}
TESTS:
Verify that :trac:`25624` is fixed::
sage: L = latex(cases([(x == 0, 0), (1, 1)]))
sage: L
\begin{cases}{0} & {x = 0}\\{1} & {1}\end{cases} | r"""
EXAMPLES:: | [
"r",
"EXAMPLES",
"::"
] | def _print_latex_(self, l, **kwargs):
r"""
EXAMPLES::
sage: ex = cases([(x==0, pi), (True, 0)]); ex
cases(((x == 0, pi), (1, 0)))
sage: latex(ex)
\begin{cases}{\pi} & {x = 0}\\{0} & {1}\end{cases}
TESTS:
Verify that :trac:`25624` is fixed::
sage: L = latex(cases([(x == 0, 0), (1, 1)]))
sage: L
\begin{cases}{0} & {x = 0}\\{1} & {1}\end{cases}
"""
if not isinstance(l, (list, tuple)):
raise ValueError("cases() argument must be a list")
str = r"\begin{cases}"
for pair in l:
left = None
if (isinstance(pair, tuple)):
right,left = pair
else:
right = pair
str += r"{%s} & {%s}\\" % (latex(left), latex(right))
return str[:-2] + r"\end{cases}" | [
"def",
"_print_latex_",
"(",
"self",
",",
"l",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"isinstance",
"(",
"l",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"raise",
"ValueError",
"(",
"\"cases() argument must be a list\"",
")",
"str",
"=",
"r... | https://github.com/sagemath/sage/blob/f9b2db94f675ff16963ccdefba4f1a3393b3fe0d/src/sage/functions/other.py#L2007-L2034 | |
andresriancho/w3af | cd22e5252243a87aaa6d0ddea47cf58dacfe00a9 | w3af/plugins/attack/xpath.py | python | IsErrorResponse.__reduce__ | (self) | return self.__class__, (self.vuln_obj, None, self.use_difflib) | @see: Shell.__reduce__ to understand why this is required. | [] | def __reduce__(self):
"""
@see: Shell.__reduce__ to understand why this is required.
"""
return self.__class__, (self.vuln_obj, None, self.use_difflib) | [
"def",
"__reduce__",
"(",
"self",
")",
":",
"return",
"self",
".",
"__class__",
",",
"(",
"self",
".",
"vuln_obj",
",",
"None",
",",
"self",
".",
"use_difflib",
")"
] | https://github.com/andresriancho/w3af/blob/cd22e5252243a87aaa6d0ddea47cf58dacfe00a9/w3af/plugins/attack/xpath.py#L476-L480 | ||
log2timeline/plaso | fe2e316b8c76a0141760c0f2f181d84acb83abc2 | plaso/formatters/interface.py | python | ConditionalEventFormatter.GetMessageShort | (self, event_values) | return short_message_string | Determines the short message.
Args:
event_values (dict[str, object]): event values.
Returns:
str: short message. | Determines the short message. | [
"Determines",
"the",
"short",
"message",
"."
] | def GetMessageShort(self, event_values):
"""Determines the short message.
Args:
event_values (dict[str, object]): event values.
Returns:
str: short message.
"""
if not self._format_string_pieces_map:
self._CreateFormatStringMaps()
if (self._format_string_short_pieces and
self._format_string_short_pieces != ['']):
format_string_pieces = self._format_string_short_pieces
format_string_pieces_map = self._format_string_short_pieces_map
else:
format_string_pieces = self._format_string_pieces
format_string_pieces_map = self._format_string_pieces_map
short_message_string = self._ConditionalFormatMessage(
format_string_pieces, format_string_pieces_map, event_values)
# Truncate the short message string if necessary.
if len(short_message_string) > 80:
short_message_string = '{0:s}...'.format(short_message_string[:77])
return short_message_string | [
"def",
"GetMessageShort",
"(",
"self",
",",
"event_values",
")",
":",
"if",
"not",
"self",
".",
"_format_string_pieces_map",
":",
"self",
".",
"_CreateFormatStringMaps",
"(",
")",
"if",
"(",
"self",
".",
"_format_string_short_pieces",
"and",
"self",
".",
"_forma... | https://github.com/log2timeline/plaso/blob/fe2e316b8c76a0141760c0f2f181d84acb83abc2/plaso/formatters/interface.py#L558-L585 | |
omz/PythonistaAppTemplate | f560f93f8876d82a21d108977f90583df08d55af | PythonistaAppTemplate/PythonistaKit.framework/pylib/site-packages/html2text.py | python | google_list_style | (style) | return 'ol' | finds out whether this is an ordered or unordered list | finds out whether this is an ordered or unordered list | [
"finds",
"out",
"whether",
"this",
"is",
"an",
"ordered",
"or",
"unordered",
"list"
] | def google_list_style(style):
"""finds out whether this is an ordered or unordered list"""
if 'list-style-type' in style:
list_style = style['list-style-type']
if list_style in ['disc', 'circle', 'square', 'none']:
return 'ul'
return 'ol' | [
"def",
"google_list_style",
"(",
"style",
")",
":",
"if",
"'list-style-type'",
"in",
"style",
":",
"list_style",
"=",
"style",
"[",
"'list-style-type'",
"]",
"if",
"list_style",
"in",
"[",
"'disc'",
",",
"'circle'",
",",
"'square'",
",",
"'none'",
"]",
":",
... | https://github.com/omz/PythonistaAppTemplate/blob/f560f93f8876d82a21d108977f90583df08d55af/PythonistaAppTemplate/PythonistaKit.framework/pylib/site-packages/html2text.py#L150-L156 | |
holzschu/Carnets | 44effb10ddfc6aa5c8b0687582a724ba82c6b547 | Library/lib/python3.7/site-packages/sympy/matrices/common.py | python | MatrixProperties.is_symbolic | (self) | return self._eval_is_symbolic() | Checks if any elements contain Symbols.
Examples
========
>>> from sympy.matrices import Matrix
>>> from sympy.abc import x, y
>>> M = Matrix([[x, y], [1, 0]])
>>> M.is_symbolic()
True | Checks if any elements contain Symbols. | [
"Checks",
"if",
"any",
"elements",
"contain",
"Symbols",
"."
] | def is_symbolic(self):
"""Checks if any elements contain Symbols.
Examples
========
>>> from sympy.matrices import Matrix
>>> from sympy.abc import x, y
>>> M = Matrix([[x, y], [1, 0]])
>>> M.is_symbolic()
True
"""
return self._eval_is_symbolic() | [
"def",
"is_symbolic",
"(",
"self",
")",
":",
"return",
"self",
".",
"_eval_is_symbolic",
"(",
")"
] | https://github.com/holzschu/Carnets/blob/44effb10ddfc6aa5c8b0687582a724ba82c6b547/Library/lib/python3.7/site-packages/sympy/matrices/common.py#L1467-L1480 | |
tribe29/checkmk | 6260f2512e159e311f426e16b84b19d0b8e9ad0c | cmk/gui/plugins/openapi/restful_objects/decorators.py | python | _verify_parameters | (
path: str,
path_schema: Optional[Type[Schema]],
) | Verifies matching of parameters to the placeholders used in an URL-Template
This works both ways, ensuring that no parameter is supplied which is then not used and that
each template-variable in the URL-template has a corresponding parameter supplied,
either globally or locally.
Args:
path:
The URL-Template, for eample: '/user/{username}'
path_schema:
A marshmallow schema which is used for path parameter validation.
Examples:
In case of success, this function will return nothing.
>>> class Params(Schema):
... bar = fields.String()
>>> _verify_parameters('/foo/{bar}', Params)
>>> _verify_parameters('/foo', None)
Yet, when problems are found, ValueErrors are raised.
>>> _verify_parameters('/foo', Params)
Traceback (most recent call last):
...
ValueError: Params {'bar'} not used in path /foo. Found params: set()
>>> _verify_parameters('/foo/{bar}', None)
Traceback (most recent call last):
...
ValueError: Params {'bar'} of path /foo/{bar} were not given in schema parameters set()
Returns:
Nothing.
Raises:
ValueError in case of a mismatch. | Verifies matching of parameters to the placeholders used in an URL-Template | [
"Verifies",
"matching",
"of",
"parameters",
"to",
"the",
"placeholders",
"used",
"in",
"an",
"URL",
"-",
"Template"
] | def _verify_parameters(
path: str,
path_schema: Optional[Type[Schema]],
):
"""Verifies matching of parameters to the placeholders used in an URL-Template
This works both ways, ensuring that no parameter is supplied which is then not used and that
each template-variable in the URL-template has a corresponding parameter supplied,
either globally or locally.
Args:
path:
The URL-Template, for eample: '/user/{username}'
path_schema:
A marshmallow schema which is used for path parameter validation.
Examples:
In case of success, this function will return nothing.
>>> class Params(Schema):
... bar = fields.String()
>>> _verify_parameters('/foo/{bar}', Params)
>>> _verify_parameters('/foo', None)
Yet, when problems are found, ValueErrors are raised.
>>> _verify_parameters('/foo', Params)
Traceback (most recent call last):
...
ValueError: Params {'bar'} not used in path /foo. Found params: set()
>>> _verify_parameters('/foo/{bar}', None)
Traceback (most recent call last):
...
ValueError: Params {'bar'} of path /foo/{bar} were not given in schema parameters set()
Returns:
Nothing.
Raises:
ValueError in case of a mismatch.
"""
if path_schema is None:
schema_params = set()
else:
schema = path_schema()
schema_params = set(schema.declared_fields.keys())
path_params = set(path_parameters(path))
missing_in_schema = path_params - schema_params
missing_in_path = schema_params - path_params
if missing_in_schema:
raise ValueError(
f"Params {missing_in_schema!r} of path {path} were not given in schema parameters "
f"{schema_params!r}"
)
if missing_in_path:
raise ValueError(
f"Params {missing_in_path!r} not used in path {path}. " f"Found params: {path_params!r}"
) | [
"def",
"_verify_parameters",
"(",
"path",
":",
"str",
",",
"path_schema",
":",
"Optional",
"[",
"Type",
"[",
"Schema",
"]",
"]",
",",
")",
":",
"if",
"path_schema",
"is",
"None",
":",
"schema_params",
"=",
"set",
"(",
")",
"else",
":",
"schema",
"=",
... | https://github.com/tribe29/checkmk/blob/6260f2512e159e311f426e16b84b19d0b8e9ad0c/cmk/gui/plugins/openapi/restful_objects/decorators.py#L900-L965 | ||
python-telegram-bot/python-telegram-bot | ade1529986f5b6d394a65372d6a27045a70725b2 | telegram/ext/picklepersistence.py | python | PicklePersistence.update_chat_data | (self, chat_id: int, data: CD) | Will update the chat_data and depending on :attr:`on_flush` save the pickle file.
Args:
chat_id (:obj:`int`): The chat the data might have been changed for.
data (:class:`telegram.ext.utils.types.CD`): The
:attr:`telegram.ext.Dispatcher.chat_data` ``[chat_id]``. | Will update the chat_data and depending on :attr:`on_flush` save the pickle file. | [
"Will",
"update",
"the",
"chat_data",
"and",
"depending",
"on",
":",
"attr",
":",
"on_flush",
"save",
"the",
"pickle",
"file",
"."
] | def update_chat_data(self, chat_id: int, data: CD) -> None:
"""Will update the chat_data and depending on :attr:`on_flush` save the pickle file.
Args:
chat_id (:obj:`int`): The chat the data might have been changed for.
data (:class:`telegram.ext.utils.types.CD`): The
:attr:`telegram.ext.Dispatcher.chat_data` ``[chat_id]``.
"""
if self.chat_data is None:
self.chat_data = defaultdict(self.context_types.chat_data)
if self.chat_data.get(chat_id) == data:
return
self.chat_data[chat_id] = data
if not self.on_flush:
if not self.single_file:
filename = f"{self.filename}_chat_data"
self._dump_file(filename, self.chat_data)
else:
self._dump_singlefile() | [
"def",
"update_chat_data",
"(",
"self",
",",
"chat_id",
":",
"int",
",",
"data",
":",
"CD",
")",
"->",
"None",
":",
"if",
"self",
".",
"chat_data",
"is",
"None",
":",
"self",
".",
"chat_data",
"=",
"defaultdict",
"(",
"self",
".",
"context_types",
".",... | https://github.com/python-telegram-bot/python-telegram-bot/blob/ade1529986f5b6d394a65372d6a27045a70725b2/telegram/ext/picklepersistence.py#L364-L382 | ||
llSourcell/AI_Artist | 3038c06c2e389b9c919c881c9a169efe2fd7810e | lib/python2.7/site-packages/pip/baseparser.py | python | ConfigOptionParser._update_defaults | (self, defaults) | return defaults | Updates the given defaults with values from the config files and
the environ. Does a little special handling for certain types of
options (lists). | Updates the given defaults with values from the config files and
the environ. Does a little special handling for certain types of
options (lists). | [
"Updates",
"the",
"given",
"defaults",
"with",
"values",
"from",
"the",
"config",
"files",
"and",
"the",
"environ",
".",
"Does",
"a",
"little",
"special",
"handling",
"for",
"certain",
"types",
"of",
"options",
"(",
"lists",
")",
"."
] | def _update_defaults(self, defaults):
"""Updates the given defaults with values from the config files and
the environ. Does a little special handling for certain types of
options (lists)."""
# Then go and look for the other sources of configuration:
config = {}
# 1. config files
for section in ('global', self.name):
config.update(
self.normalize_keys(self.get_config_section(section))
)
# 2. environmental variables
if not self.isolated:
config.update(self.normalize_keys(self.get_environ_vars()))
# Accumulate complex default state.
self.values = optparse.Values(self.defaults)
late_eval = set()
# Then set the options with those values
for key, val in config.items():
# ignore empty values
if not val:
continue
option = self.get_option(key)
# Ignore options not present in this parser. E.g. non-globals put
# in [global] by users that want them to apply to all applicable
# commands.
if option is None:
continue
if option.action in ('store_true', 'store_false', 'count'):
val = strtobool(val)
elif option.action == 'append':
val = val.split()
val = [self.check_default(option, key, v) for v in val]
elif option.action == 'callback':
late_eval.add(option.dest)
opt_str = option.get_opt_string()
val = option.convert_value(opt_str, val)
# From take_action
args = option.callback_args or ()
kwargs = option.callback_kwargs or {}
option.callback(option, opt_str, val, self, *args, **kwargs)
else:
val = self.check_default(option, key, val)
defaults[option.dest] = val
for key in late_eval:
defaults[key] = getattr(self.values, key)
self.values = None
return defaults | [
"def",
"_update_defaults",
"(",
"self",
",",
"defaults",
")",
":",
"# Then go and look for the other sources of configuration:",
"config",
"=",
"{",
"}",
"# 1. config files",
"for",
"section",
"in",
"(",
"'global'",
",",
"self",
".",
"name",
")",
":",
"config",
".... | https://github.com/llSourcell/AI_Artist/blob/3038c06c2e389b9c919c881c9a169efe2fd7810e/lib/python2.7/site-packages/pip/baseparser.py#L198-L249 | |
simetenn/uncertainpy | ffb2400289743066265b9a8561cdf3b72e478a28 | src/uncertainpy/plotting/plot_uncertainty.py | python | PlotUncertainty.plot_all_sensitivities | (self) | Plot the results for all model/features, with all sensitivities.
Raises
------
ValueError
If a Datafile is not loaded. | Plot the results for all model/features, with all sensitivities. | [
"Plot",
"the",
"results",
"for",
"all",
"model",
"/",
"features",
"with",
"all",
"sensitivities",
"."
] | def plot_all_sensitivities(self):
"""
Plot the results for all model/features, with all sensitivities.
Raises
------
ValueError
If a Datafile is not loaded.
"""
if self.data is None:
raise ValueError("Datafile must be loaded.")
self.plot_all(sensitivity="first")
for feature in self.data:
if self.data.ndim(feature) == 1:
self.sensitivity_1d(feature=feature, sensitivity="total")
self.sensitivity_1d_combined(feature=feature, sensitivity="total")
self.sensitivity_1d_grid(feature=feature, sensitivity="total")
self.features_0d(sensitivity="total")
self.average_sensitivity_all(sensitivity="total")
self.average_sensitivity_grid(sensitivity="total") | [
"def",
"plot_all_sensitivities",
"(",
"self",
")",
":",
"if",
"self",
".",
"data",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"Datafile must be loaded.\"",
")",
"self",
".",
"plot_all",
"(",
"sensitivity",
"=",
"\"first\"",
")",
"for",
"feature",
"in",
... | https://github.com/simetenn/uncertainpy/blob/ffb2400289743066265b9a8561cdf3b72e478a28/src/uncertainpy/plotting/plot_uncertainty.py#L1722-L1745 | ||
timonwong/OmniMarkupPreviewer | 21921ac7a99d2b5924a2219b33679a5b53621392 | OmniMarkupLib/Renderers/libs/python3/docutils/utils/math/math2html.py | python | MacroFunction.completemacro | (self, macro) | Complete the macro with the parameters read. | Complete the macro with the parameters read. | [
"Complete",
"the",
"macro",
"with",
"the",
"parameters",
"read",
"."
] | def completemacro(self, macro):
"Complete the macro with the parameters read."
self.contents = [macro.instantiate()]
replaced = [False] * len(self.values)
for parameter in self.searchall(MacroParameter):
index = parameter.number - 1
if index >= len(self.values):
Trace.error('Macro parameter index out of bounds: ' + str(index))
return
replaced[index] = True
parameter.contents = [self.values[index].clone()]
for index in range(len(self.values)):
if not replaced[index]:
self.addfilter(index, self.values[index]) | [
"def",
"completemacro",
"(",
"self",
",",
"macro",
")",
":",
"self",
".",
"contents",
"=",
"[",
"macro",
".",
"instantiate",
"(",
")",
"]",
"replaced",
"=",
"[",
"False",
"]",
"*",
"len",
"(",
"self",
".",
"values",
")",
"for",
"parameter",
"in",
"... | https://github.com/timonwong/OmniMarkupPreviewer/blob/21921ac7a99d2b5924a2219b33679a5b53621392/OmniMarkupLib/Renderers/libs/python3/docutils/utils/math/math2html.py#L5189-L5202 | ||
makerbot/ReplicatorG | d6f2b07785a5a5f1e172fb87cb4303b17c575d5d | skein_engines/skeinforge-47/skeinforge_application/skeinforge_plugins/craft_plugins/fill.py | python | isSharpCorner | ( beginComplex, centerComplex, endComplex ) | return euclidean.getDotProduct( centerBeginComplex, centerEndComplex ) > 0.9 | Determine if the three complex points form a sharp corner. | Determine if the three complex points form a sharp corner. | [
"Determine",
"if",
"the",
"three",
"complex",
"points",
"form",
"a",
"sharp",
"corner",
"."
] | def isSharpCorner( beginComplex, centerComplex, endComplex ):
'Determine if the three complex points form a sharp corner.'
centerBeginComplex = beginComplex - centerComplex
centerEndComplex = endComplex - centerComplex
centerBeginLength = abs( centerBeginComplex )
centerEndLength = abs( centerEndComplex )
if centerBeginLength <= 0.0 or centerEndLength <= 0.0:
return False
centerBeginComplex /= centerBeginLength
centerEndComplex /= centerEndLength
return euclidean.getDotProduct( centerBeginComplex, centerEndComplex ) > 0.9 | [
"def",
"isSharpCorner",
"(",
"beginComplex",
",",
"centerComplex",
",",
"endComplex",
")",
":",
"centerBeginComplex",
"=",
"beginComplex",
"-",
"centerComplex",
"centerEndComplex",
"=",
"endComplex",
"-",
"centerComplex",
"centerBeginLength",
"=",
"abs",
"(",
"centerB... | https://github.com/makerbot/ReplicatorG/blob/d6f2b07785a5a5f1e172fb87cb4303b17c575d5d/skein_engines/skeinforge-47/skeinforge_application/skeinforge_plugins/craft_plugins/fill.py#L674-L684 | |
microsoft/unilm | 65f15af2a307ebb64cfb25adf54375b002e6fe8d | xtune/src/transformers/data/processors/xglue.py | python | NcProcessor.get_labels | (self) | return ['foodanddrink', 'sports', 'news', 'entertainment', 'health', 'video', 'finance', 'travel', 'lifestyle',
'autos'] | See base class. | See base class. | [
"See",
"base",
"class",
"."
] | def get_labels(self):
"""See base class."""
return ['foodanddrink', 'sports', 'news', 'entertainment', 'health', 'video', 'finance', 'travel', 'lifestyle',
'autos'] | [
"def",
"get_labels",
"(",
"self",
")",
":",
"return",
"[",
"'foodanddrink'",
",",
"'sports'",
",",
"'news'",
",",
"'entertainment'",
",",
"'health'",
",",
"'video'",
",",
"'finance'",
",",
"'travel'",
",",
"'lifestyle'",
",",
"'autos'",
"]"
] | https://github.com/microsoft/unilm/blob/65f15af2a307ebb64cfb25adf54375b002e6fe8d/xtune/src/transformers/data/processors/xglue.py#L850-L853 | |
pwnieexpress/pwn_plug_sources | 1a23324f5dc2c3de20f9c810269b6a29b2758cad | src/metagoofil/downloader.py | python | downloader.down | (self) | [] | def down(self):
if os.path.exists(self.dir+"/"+self.filename):
pass
else:
try:
urllib.urlretrieve(self.url,self.dir+"/"+self.filename)
except:
print "Error downloading " + self.url
self.filename="" | [
"def",
"down",
"(",
"self",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"dir",
"+",
"\"/\"",
"+",
"self",
".",
"filename",
")",
":",
"pass",
"else",
":",
"try",
":",
"urllib",
".",
"urlretrieve",
"(",
"self",
".",
"url",
... | https://github.com/pwnieexpress/pwn_plug_sources/blob/1a23324f5dc2c3de20f9c810269b6a29b2758cad/src/metagoofil/downloader.py#L9-L17 | ||||
IronLanguages/ironpython3 | 7a7bb2a872eeab0d1009fc8a6e24dca43f65b693 | Src/StdLib/Lib/mailbox.py | python | Mailbox.__delitem__ | (self, key) | [] | def __delitem__(self, key):
self.remove(key) | [
"def",
"__delitem__",
"(",
"self",
",",
"key",
")",
":",
"self",
".",
"remove",
"(",
"key",
")"
] | https://github.com/IronLanguages/ironpython3/blob/7a7bb2a872eeab0d1009fc8a6e24dca43f65b693/Src/StdLib/Lib/mailbox.py#L48-L49 | ||||
jgagneastro/coffeegrindsize | 22661ebd21831dba4cf32bfc6ba59fe3d49f879c | App/dist/coffeegrindsize.app/Contents/Resources/lib/python3.7/pandas/core/indexing.py | python | _iLocIndexer._validate_integer | (self, key, axis) | Check that 'key' is a valid position in the desired axis.
Parameters
----------
key : int
Requested position
axis : int
Desired axis
Returns
-------
None
Raises
------
IndexError
If 'key' is not a valid position in axis 'axis' | Check that 'key' is a valid position in the desired axis. | [
"Check",
"that",
"key",
"is",
"a",
"valid",
"position",
"in",
"the",
"desired",
"axis",
"."
] | def _validate_integer(self, key, axis):
"""
Check that 'key' is a valid position in the desired axis.
Parameters
----------
key : int
Requested position
axis : int
Desired axis
Returns
-------
None
Raises
------
IndexError
If 'key' is not a valid position in axis 'axis'
"""
len_axis = len(self.obj._get_axis(axis))
if key >= len_axis or key < -len_axis:
raise IndexError("single positional indexer is out-of-bounds") | [
"def",
"_validate_integer",
"(",
"self",
",",
"key",
",",
"axis",
")",
":",
"len_axis",
"=",
"len",
"(",
"self",
".",
"obj",
".",
"_get_axis",
"(",
"axis",
")",
")",
"if",
"key",
">=",
"len_axis",
"or",
"key",
"<",
"-",
"len_axis",
":",
"raise",
"I... | https://github.com/jgagneastro/coffeegrindsize/blob/22661ebd21831dba4cf32bfc6ba59fe3d49f879c/App/dist/coffeegrindsize.app/Contents/Resources/lib/python3.7/pandas/core/indexing.py#L2116-L2139 | ||
svpcom/wifibroadcast | 51251b8c484b8c4f548aa3bbb1633e0edbb605dc | telemetry/mavlink.py | python | MAVLink.orbit_execution_status_send | (self, time_usec, radius, frame, x, y, z, force_mavlink1=False) | return self.send(self.orbit_execution_status_encode(time_usec, radius, frame, x, y, z), force_mavlink1=force_mavlink1) | Vehicle status report that is sent out while orbit execution is in
progress (see MAV_CMD_DO_ORBIT).
time_usec : Timestamp (UNIX Epoch time or time since system boot). The receiving end can infer timestamp format (since 1.1.1970 or since system boot) by checking for the magnitude of the number. [us] (type:uint64_t)
radius : Radius of the orbit circle. Positive values orbit clockwise, negative values orbit counter-clockwise. [m] (type:float)
frame : The coordinate system of the fields: x, y, z. (type:uint8_t, values:MAV_FRAME)
x : X coordinate of center point. Coordinate system depends on frame field: local = x position in meters * 1e4, global = latitude in degrees * 1e7. (type:int32_t)
y : Y coordinate of center point. Coordinate system depends on frame field: local = x position in meters * 1e4, global = latitude in degrees * 1e7. (type:int32_t)
z : Altitude of center point. Coordinate system depends on frame field. [m] (type:float) | Vehicle status report that is sent out while orbit execution is in
progress (see MAV_CMD_DO_ORBIT). | [
"Vehicle",
"status",
"report",
"that",
"is",
"sent",
"out",
"while",
"orbit",
"execution",
"is",
"in",
"progress",
"(",
"see",
"MAV_CMD_DO_ORBIT",
")",
"."
] | def orbit_execution_status_send(self, time_usec, radius, frame, x, y, z, force_mavlink1=False):
'''
Vehicle status report that is sent out while orbit execution is in
progress (see MAV_CMD_DO_ORBIT).
time_usec : Timestamp (UNIX Epoch time or time since system boot). The receiving end can infer timestamp format (since 1.1.1970 or since system boot) by checking for the magnitude of the number. [us] (type:uint64_t)
radius : Radius of the orbit circle. Positive values orbit clockwise, negative values orbit counter-clockwise. [m] (type:float)
frame : The coordinate system of the fields: x, y, z. (type:uint8_t, values:MAV_FRAME)
x : X coordinate of center point. Coordinate system depends on frame field: local = x position in meters * 1e4, global = latitude in degrees * 1e7. (type:int32_t)
y : Y coordinate of center point. Coordinate system depends on frame field: local = x position in meters * 1e4, global = latitude in degrees * 1e7. (type:int32_t)
z : Altitude of center point. Coordinate system depends on frame field. [m] (type:float)
'''
return self.send(self.orbit_execution_status_encode(time_usec, radius, frame, x, y, z), force_mavlink1=force_mavlink1) | [
"def",
"orbit_execution_status_send",
"(",
"self",
",",
"time_usec",
",",
"radius",
",",
"frame",
",",
"x",
",",
"y",
",",
"z",
",",
"force_mavlink1",
"=",
"False",
")",
":",
"return",
"self",
".",
"send",
"(",
"self",
".",
"orbit_execution_status_encode",
... | https://github.com/svpcom/wifibroadcast/blob/51251b8c484b8c4f548aa3bbb1633e0edbb605dc/telemetry/mavlink.py#L29124-L29137 | |
RaRe-Technologies/gensim | 8b8203d8df354673732dff635283494a33d0d422 | gensim/similarities/termsim.py | python | _normalize_sparse_corpus | (corpus, matrix, normalization) | return normalized_corpus | Normalize a sparse corpus after a change of basis.
Parameters
----------
corpus : MxN :class:`scipy.sparse.csc_matrix`
A sparse corpus.
matrix : NxN :class:`scipy.sparse.csc_matrix`
A change-of-basis matrix.
normalization : {True, False, 'maintain'}
Whether the vector will be L2-normalized (True; corresponds to the soft
cosine measure), maintain its L2-norm during the change of basis
('maintain'; corresponds to query expansion with partial membership),
or kept as-is (False; corresponds to query expansion).
Returns
-------
normalized_corpus : :class:`scipy.sparse.csc_matrix`
The normalized sparse corpus. | Normalize a sparse corpus after a change of basis. | [
"Normalize",
"a",
"sparse",
"corpus",
"after",
"a",
"change",
"of",
"basis",
"."
] | def _normalize_sparse_corpus(corpus, matrix, normalization):
"""Normalize a sparse corpus after a change of basis.
Parameters
----------
corpus : MxN :class:`scipy.sparse.csc_matrix`
A sparse corpus.
matrix : NxN :class:`scipy.sparse.csc_matrix`
A change-of-basis matrix.
normalization : {True, False, 'maintain'}
Whether the vector will be L2-normalized (True; corresponds to the soft
cosine measure), maintain its L2-norm during the change of basis
('maintain'; corresponds to query expansion with partial membership),
or kept as-is (False; corresponds to query expansion).
Returns
-------
normalized_corpus : :class:`scipy.sparse.csc_matrix`
The normalized sparse corpus.
"""
if not normalization:
return corpus
# use the following equality: np.diag(A.T.dot(B).dot(A)) == A.T.dot(B).multiply(A.T).sum(axis=1).T
corpus_norm = corpus.T.dot(matrix).multiply(corpus.T).sum(axis=1).T
assert corpus_norm.min() >= 0.0, NON_NEGATIVE_NORM_ASSERTION_MESSAGE
if normalization == 'maintain':
corpus_norm /= corpus.T.multiply(corpus.T).sum(axis=1).T
corpus_norm = np.sqrt(corpus_norm)
normalized_corpus = corpus.multiply(sparse.csr_matrix(1.0 / corpus_norm))
normalized_corpus[normalized_corpus == np.inf] = 0 # account for division by zero
return normalized_corpus | [
"def",
"_normalize_sparse_corpus",
"(",
"corpus",
",",
"matrix",
",",
"normalization",
")",
":",
"if",
"not",
"normalization",
":",
"return",
"corpus",
"# use the following equality: np.diag(A.T.dot(B).dot(A)) == A.T.dot(B).multiply(A.T).sum(axis=1).T",
"corpus_norm",
"=",
"cor... | https://github.com/RaRe-Technologies/gensim/blob/8b8203d8df354673732dff635283494a33d0d422/gensim/similarities/termsim.py#L387-L420 | |
paramiko/paramiko | 88f35a537428e430f7f26eee8026715e357b55d6 | paramiko/util.py | python | lookup_ssh_host_config | (hostname, config) | return config.lookup(hostname) | Provided only as a backward-compatible wrapper around `.SSHConfig`. | Provided only as a backward-compatible wrapper around `.SSHConfig`. | [
"Provided",
"only",
"as",
"a",
"backward",
"-",
"compatible",
"wrapper",
"around",
".",
"SSHConfig",
"."
] | def lookup_ssh_host_config(hostname, config):
"""
Provided only as a backward-compatible wrapper around `.SSHConfig`.
"""
return config.lookup(hostname) | [
"def",
"lookup_ssh_host_config",
"(",
"hostname",
",",
"config",
")",
":",
"return",
"config",
".",
"lookup",
"(",
"hostname",
")"
] | https://github.com/paramiko/paramiko/blob/88f35a537428e430f7f26eee8026715e357b55d6/paramiko/util.py#L206-L210 | |
haiwen/seafile-docker | 2d2461d4c8cab3458ec9832611c419d47506c300 | scripts_8.0/setup-seafile-mysql.py | python | InvalidParams.__init__ | (self, msg) | [] | def __init__(self, msg):
Exception.__init__(self)
self.msg = msg | [
"def",
"__init__",
"(",
"self",
",",
"msg",
")",
":",
"Exception",
".",
"__init__",
"(",
"self",
")",
"self",
".",
"msg",
"=",
"msg"
] | https://github.com/haiwen/seafile-docker/blob/2d2461d4c8cab3458ec9832611c419d47506c300/scripts_8.0/setup-seafile-mysql.py#L289-L291 | ||||
tomplus/kubernetes_asyncio | f028cc793e3a2c519be6a52a49fb77ff0b014c9b | kubernetes_asyncio/client/models/v1_pod_list.py | python | V1PodList.to_str | (self) | return pprint.pformat(self.to_dict()) | Returns the string representation of the model | Returns the string representation of the model | [
"Returns",
"the",
"string",
"representation",
"of",
"the",
"model"
] | def to_str(self):
"""Returns the string representation of the model"""
return pprint.pformat(self.to_dict()) | [
"def",
"to_str",
"(",
"self",
")",
":",
"return",
"pprint",
".",
"pformat",
"(",
"self",
".",
"to_dict",
"(",
")",
")"
] | https://github.com/tomplus/kubernetes_asyncio/blob/f028cc793e3a2c519be6a52a49fb77ff0b014c9b/kubernetes_asyncio/client/models/v1_pod_list.py#L185-L187 | |
KalleHallden/AutoTimer | 2d954216700c4930baa154e28dbddc34609af7ce | env/lib/python2.7/site-packages/objc/_properties.py | python | set_proxy.symmetric_difference_update | (self, other) | [] | def symmetric_difference_update(self, other):
# NOTE: This method does not call the corresponding method
# of the wrapped set to ensure that we generate the right
# notifications.
if self._ro:
raise ValueError("Property '%s' is read-only"%(self._name,))
other = set(other)
to_add = set()
to_remove = set()
for o in other:
if o in self:
to_remove.add(o)
else:
to_add.add(o)
self._parent.willChangeValueForKey_withSetMutation_usingObjects_(
self._name,
NSKeyValueMinusSetMutation,
to_remove
)
try:
self._wrapped.difference_update(to_remove)
finally:
self._parent.didChangeValueForKey_withSetMutation_usingObjects_(
self._name,
NSKeyValueMinusSetMutation,
to_remove
)
self._parent.willChangeValueForKey_withSetMutation_usingObjects_(
self._name,
NSKeyValueUnionSetMutation,
to_add
)
try:
self._wrapped.update(to_add)
finally:
self._parent.didChangeValueForKey_withSetMutation_usingObjects_(
self._name,
NSKeyValueUnionSetMutation,
to_add
) | [
"def",
"symmetric_difference_update",
"(",
"self",
",",
"other",
")",
":",
"# NOTE: This method does not call the corresponding method",
"# of the wrapped set to ensure that we generate the right",
"# notifications.",
"if",
"self",
".",
"_ro",
":",
"raise",
"ValueError",
"(",
"... | https://github.com/KalleHallden/AutoTimer/blob/2d954216700c4930baa154e28dbddc34609af7ce/env/lib/python2.7/site-packages/objc/_properties.py#L919-L964 | ||||
entropy1337/infernal-twin | 10995cd03312e39a48ade0f114ebb0ae3a711bb8 | Modules/build/pillow/PIL/Image.py | python | Image.rotate | (self, angle, resample=NEAREST, expand=0) | return self._new(self.im.rotate(angle, resample)) | Returns a rotated copy of this image. This method returns a
copy of this image, rotated the given number of degrees counter
clockwise around its centre.
:param angle: In degrees counter clockwise.
:param resample: An optional resampling filter. This can be
one of :py:attr:`PIL.Image.NEAREST` (use nearest neighbour),
:py:attr:`PIL.Image.BILINEAR` (linear interpolation in a 2x2
environment), or :py:attr:`PIL.Image.BICUBIC`
(cubic spline interpolation in a 4x4 environment).
If omitted, or if the image has mode "1" or "P", it is
set :py:attr:`PIL.Image.NEAREST`.
:param expand: Optional expansion flag. If true, expands the output
image to make it large enough to hold the entire rotated image.
If false or omitted, make the output image the same size as the
input image.
:returns: An :py:class:`~PIL.Image.Image` object. | Returns a rotated copy of this image. This method returns a
copy of this image, rotated the given number of degrees counter
clockwise around its centre. | [
"Returns",
"a",
"rotated",
"copy",
"of",
"this",
"image",
".",
"This",
"method",
"returns",
"a",
"copy",
"of",
"this",
"image",
"rotated",
"the",
"given",
"number",
"of",
"degrees",
"counter",
"clockwise",
"around",
"its",
"centre",
"."
] | def rotate(self, angle, resample=NEAREST, expand=0):
"""
Returns a rotated copy of this image. This method returns a
copy of this image, rotated the given number of degrees counter
clockwise around its centre.
:param angle: In degrees counter clockwise.
:param resample: An optional resampling filter. This can be
one of :py:attr:`PIL.Image.NEAREST` (use nearest neighbour),
:py:attr:`PIL.Image.BILINEAR` (linear interpolation in a 2x2
environment), or :py:attr:`PIL.Image.BICUBIC`
(cubic spline interpolation in a 4x4 environment).
If omitted, or if the image has mode "1" or "P", it is
set :py:attr:`PIL.Image.NEAREST`.
:param expand: Optional expansion flag. If true, expands the output
image to make it large enough to hold the entire rotated image.
If false or omitted, make the output image the same size as the
input image.
:returns: An :py:class:`~PIL.Image.Image` object.
"""
if expand:
import math
angle = -angle * math.pi / 180
matrix = [
math.cos(angle), math.sin(angle), 0.0,
-math.sin(angle), math.cos(angle), 0.0
]
def transform(x, y, matrix=matrix):
(a, b, c, d, e, f) = matrix
return a*x + b*y + c, d*x + e*y + f
# calculate output size
w, h = self.size
xx = []
yy = []
for x, y in ((0, 0), (w, 0), (w, h), (0, h)):
x, y = transform(x, y)
xx.append(x)
yy.append(y)
w = int(math.ceil(max(xx)) - math.floor(min(xx)))
h = int(math.ceil(max(yy)) - math.floor(min(yy)))
# adjust center
x, y = transform(w / 2.0, h / 2.0)
matrix[2] = self.size[0] / 2.0 - x
matrix[5] = self.size[1] / 2.0 - y
return self.transform((w, h), AFFINE, matrix, resample)
if resample not in (NEAREST, BILINEAR, BICUBIC):
raise ValueError("unknown resampling filter")
self.load()
if self.mode in ("1", "P"):
resample = NEAREST
return self._new(self.im.rotate(angle, resample)) | [
"def",
"rotate",
"(",
"self",
",",
"angle",
",",
"resample",
"=",
"NEAREST",
",",
"expand",
"=",
"0",
")",
":",
"if",
"expand",
":",
"import",
"math",
"angle",
"=",
"-",
"angle",
"*",
"math",
".",
"pi",
"/",
"180",
"matrix",
"=",
"[",
"math",
"."... | https://github.com/entropy1337/infernal-twin/blob/10995cd03312e39a48ade0f114ebb0ae3a711bb8/Modules/build/pillow/PIL/Image.py#L1571-L1630 | |
django/channels | 6af1bc3ab45f55e3f47d0d1d059d5db0a18a9581 | channels/generic/websocket.py | python | AsyncWebsocketConsumer.websocket_receive | (self, message) | Called when a WebSocket frame is received. Decodes it and passes it
to receive(). | Called when a WebSocket frame is received. Decodes it and passes it
to receive(). | [
"Called",
"when",
"a",
"WebSocket",
"frame",
"is",
"received",
".",
"Decodes",
"it",
"and",
"passes",
"it",
"to",
"receive",
"()",
"."
] | async def websocket_receive(self, message):
"""
Called when a WebSocket frame is received. Decodes it and passes it
to receive().
"""
if "text" in message:
await self.receive(text_data=message["text"])
else:
await self.receive(bytes_data=message["bytes"]) | [
"async",
"def",
"websocket_receive",
"(",
"self",
",",
"message",
")",
":",
"if",
"\"text\"",
"in",
"message",
":",
"await",
"self",
".",
"receive",
"(",
"text_data",
"=",
"message",
"[",
"\"text\"",
"]",
")",
"else",
":",
"await",
"self",
".",
"receive"... | https://github.com/django/channels/blob/6af1bc3ab45f55e3f47d0d1d059d5db0a18a9581/channels/generic/websocket.py#L188-L196 | ||
fake-name/ReadableWebProxy | ed5c7abe38706acc2684a1e6cd80242a03c5f010 | WebMirror/management/rss_parser_funcs/feed_parse_extractImemotranslationsCom.py | python | extractImemotranslationsCom | (item) | return False | Parser for 'imemotranslations.com' | Parser for 'imemotranslations.com' | [
"Parser",
"for",
"imemotranslations",
".",
"com"
] | def extractImemotranslationsCom(item):
'''
Parser for 'imemotranslations.com'
'''
vol, chp, frag, postfix = extractVolChapterFragmentPostfix(item['title'])
if not (chp or vol) or "preview" in item['title'].lower():
return None
tagmap = [
('Hone to Issho', 'Hone to Issho no Isekai Seikatsu', 'translated'),
('PRC', 'PRC', 'translated'),
('Loiterous', 'Loiterous', 'oel'),
]
for tagname, name, tl_type in tagmap:
if tagname in item['tags']:
return buildReleaseMessageWithType(item, name, vol, chp, frag=frag, postfix=postfix, tl_type=tl_type)
return False | [
"def",
"extractImemotranslationsCom",
"(",
"item",
")",
":",
"vol",
",",
"chp",
",",
"frag",
",",
"postfix",
"=",
"extractVolChapterFragmentPostfix",
"(",
"item",
"[",
"'title'",
"]",
")",
"if",
"not",
"(",
"chp",
"or",
"vol",
")",
"or",
"\"preview\"",
"in... | https://github.com/fake-name/ReadableWebProxy/blob/ed5c7abe38706acc2684a1e6cd80242a03c5f010/WebMirror/management/rss_parser_funcs/feed_parse_extractImemotranslationsCom.py#L1-L21 | |
chribsen/simple-machine-learning-examples | dc94e52a4cebdc8bb959ff88b81ff8cfeca25022 | venv/lib/python2.7/site-packages/pandas/core/groupby.py | python | Grouper._get_grouper | (self, obj) | return self.binner, self.grouper, self.obj | Parameters
----------
obj : the subject object
Returns
-------
a tuple of binner, grouper, obj (possibly sorted) | Parameters
----------
obj : the subject object | [
"Parameters",
"----------",
"obj",
":",
"the",
"subject",
"object"
] | def _get_grouper(self, obj):
"""
Parameters
----------
obj : the subject object
Returns
-------
a tuple of binner, grouper, obj (possibly sorted)
"""
self._set_grouper(obj)
self.grouper, exclusions, self.obj = _get_grouper(self.obj, [self.key],
axis=self.axis,
level=self.level,
sort=self.sort)
return self.binner, self.grouper, self.obj | [
"def",
"_get_grouper",
"(",
"self",
",",
"obj",
")",
":",
"self",
".",
"_set_grouper",
"(",
"obj",
")",
"self",
".",
"grouper",
",",
"exclusions",
",",
"self",
".",
"obj",
"=",
"_get_grouper",
"(",
"self",
".",
"obj",
",",
"[",
"self",
".",
"key",
... | https://github.com/chribsen/simple-machine-learning-examples/blob/dc94e52a4cebdc8bb959ff88b81ff8cfeca25022/venv/lib/python2.7/site-packages/pandas/core/groupby.py#L234-L250 | |
home-assistant/core | 265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1 | homeassistant/helpers/entity_registry.py | python | EntityRegistry.async_clear_area_id | (self, area_id: str) | Clear area id from registry entries. | Clear area id from registry entries. | [
"Clear",
"area",
"id",
"from",
"registry",
"entries",
"."
] | def async_clear_area_id(self, area_id: str) -> None:
"""Clear area id from registry entries."""
for entity_id, entry in self.entities.items():
if area_id == entry.area_id:
self.async_update_entity(entity_id, area_id=None) | [
"def",
"async_clear_area_id",
"(",
"self",
",",
"area_id",
":",
"str",
")",
"->",
"None",
":",
"for",
"entity_id",
",",
"entry",
"in",
"self",
".",
"entities",
".",
"items",
"(",
")",
":",
"if",
"area_id",
"==",
"entry",
".",
"area_id",
":",
"self",
... | https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/helpers/entity_registry.py#L656-L660 | ||
twilio/twilio-python | 6e1e811ea57a1edfadd5161ace87397c563f6915 | twilio/rest/preview/wireless/rate_plan.py | python | RatePlanPage.get_instance | (self, payload) | return RatePlanInstance(self._version, payload, ) | Build an instance of RatePlanInstance
:param dict payload: Payload response from the API
:returns: twilio.rest.preview.wireless.rate_plan.RatePlanInstance
:rtype: twilio.rest.preview.wireless.rate_plan.RatePlanInstance | Build an instance of RatePlanInstance | [
"Build",
"an",
"instance",
"of",
"RatePlanInstance"
] | def get_instance(self, payload):
"""
Build an instance of RatePlanInstance
:param dict payload: Payload response from the API
:returns: twilio.rest.preview.wireless.rate_plan.RatePlanInstance
:rtype: twilio.rest.preview.wireless.rate_plan.RatePlanInstance
"""
return RatePlanInstance(self._version, payload, ) | [
"def",
"get_instance",
"(",
"self",
",",
"payload",
")",
":",
"return",
"RatePlanInstance",
"(",
"self",
".",
"_version",
",",
"payload",
",",
")"
] | https://github.com/twilio/twilio-python/blob/6e1e811ea57a1edfadd5161ace87397c563f6915/twilio/rest/preview/wireless/rate_plan.py#L207-L216 | |
adobe/ops-cli | 2384257c4199b3ff37e366f48b4dfce3ac282524 | src/ops/terraform/terraform_cmd_generator.py | python | TerraformCommandGenerator.set_current_working_dir | (self) | [] | def set_current_working_dir(self):
os.chdir(self.root_dir) | [
"def",
"set_current_working_dir",
"(",
"self",
")",
":",
"os",
".",
"chdir",
"(",
"self",
".",
"root_dir",
")"
] | https://github.com/adobe/ops-cli/blob/2384257c4199b3ff37e366f48b4dfce3ac282524/src/ops/terraform/terraform_cmd_generator.py#L501-L502 | ||||
rembo10/headphones | b3199605be1ebc83a7a8feab6b1e99b64014187c | lib/feedparser.py | python | _MicroformatsParser.normalize | (self, s) | return re.sub(r'\s+', ' ', s).strip() | [] | def normalize(self, s):
return re.sub(r'\s+', ' ', s).strip() | [
"def",
"normalize",
"(",
"self",
",",
"s",
")",
":",
"return",
"re",
".",
"sub",
"(",
"r'\\s+'",
",",
"' '",
",",
"s",
")",
".",
"strip",
"(",
")"
] | https://github.com/rembo10/headphones/blob/b3199605be1ebc83a7a8feab6b1e99b64014187c/lib/feedparser.py#L2052-L2053 | |||
kuri65536/python-for-android | 26402a08fc46b09ef94e8d7a6bbc3a54ff9d0891 | python3-alpha/python-libs/gdata/apps/emailsettings/data.py | python | EmailSettingsSendAsAlias.__init__ | (self, uri=None, name=None, address=None, reply_to=None,
make_default=None, *args, **kwargs) | Constructs a new EmailSettingsSendAsAlias object with the given
arguments.
Args:
uri: string (optional) The uri f this object for HTTP requests.
name: string (optional) The name that will appear in the "From" field
for this user.
address: string (optional) The email address that appears as the
origination address for emails sent by this user.
reply_to: string (optional) The address to be used as the reply-to
address in email sent using the alias.
make_default: Boolean (optional) Whether or not this alias should
become the default alias for this user.
args: The other parameters to pass to gdata.entry.GDEntry constructor.
kwargs: The other parameters to pass to gdata.entry.GDEntry constructor. | Constructs a new EmailSettingsSendAsAlias object with the given
arguments. | [
"Constructs",
"a",
"new",
"EmailSettingsSendAsAlias",
"object",
"with",
"the",
"given",
"arguments",
"."
] | def __init__(self, uri=None, name=None, address=None, reply_to=None,
make_default=None, *args, **kwargs):
"""Constructs a new EmailSettingsSendAsAlias object with the given
arguments.
Args:
uri: string (optional) The uri f this object for HTTP requests.
name: string (optional) The name that will appear in the "From" field
for this user.
address: string (optional) The email address that appears as the
origination address for emails sent by this user.
reply_to: string (optional) The address to be used as the reply-to
address in email sent using the alias.
make_default: Boolean (optional) Whether or not this alias should
become the default alias for this user.
args: The other parameters to pass to gdata.entry.GDEntry constructor.
kwargs: The other parameters to pass to gdata.entry.GDEntry constructor.
"""
super(EmailSettingsSendAsAlias, self).__init__(*args, **kwargs)
if uri:
self.uri = uri
if name:
self.name = name
if address:
self.address = address
if reply_to:
self.reply_to = reply_to
if make_default is not None:
self.make_default = str(make_default) | [
"def",
"__init__",
"(",
"self",
",",
"uri",
"=",
"None",
",",
"name",
"=",
"None",
",",
"address",
"=",
"None",
",",
"reply_to",
"=",
"None",
",",
"make_default",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"super",
"(",
"Em... | https://github.com/kuri65536/python-for-android/blob/26402a08fc46b09ef94e8d7a6bbc3a54ff9d0891/python3-alpha/python-libs/gdata/apps/emailsettings/data.py#L529-L557 | ||
twilio/twilio-python | 6e1e811ea57a1edfadd5161ace87397c563f6915 | twilio/rest/chat/v2/credential.py | python | CredentialInstance.update | (self, friendly_name=values.unset, certificate=values.unset,
private_key=values.unset, sandbox=values.unset, api_key=values.unset,
secret=values.unset) | return self._proxy.update(
friendly_name=friendly_name,
certificate=certificate,
private_key=private_key,
sandbox=sandbox,
api_key=api_key,
secret=secret,
) | Update the CredentialInstance
:param unicode friendly_name: A string to describe the resource
:param unicode certificate: [APN only] The URL encoded representation of the certificate
:param unicode private_key: [APN only] The URL encoded representation of the private key
:param bool sandbox: [APN only] Whether to send the credential to sandbox APNs
:param unicode api_key: [GCM only] The API key for the project that was obtained from the Google Developer console for your GCM Service application credential
:param unicode secret: [FCM only] The Server key of your project from Firebase console
:returns: The updated CredentialInstance
:rtype: twilio.rest.chat.v2.credential.CredentialInstance | Update the CredentialInstance | [
"Update",
"the",
"CredentialInstance"
] | def update(self, friendly_name=values.unset, certificate=values.unset,
private_key=values.unset, sandbox=values.unset, api_key=values.unset,
secret=values.unset):
"""
Update the CredentialInstance
:param unicode friendly_name: A string to describe the resource
:param unicode certificate: [APN only] The URL encoded representation of the certificate
:param unicode private_key: [APN only] The URL encoded representation of the private key
:param bool sandbox: [APN only] Whether to send the credential to sandbox APNs
:param unicode api_key: [GCM only] The API key for the project that was obtained from the Google Developer console for your GCM Service application credential
:param unicode secret: [FCM only] The Server key of your project from Firebase console
:returns: The updated CredentialInstance
:rtype: twilio.rest.chat.v2.credential.CredentialInstance
"""
return self._proxy.update(
friendly_name=friendly_name,
certificate=certificate,
private_key=private_key,
sandbox=sandbox,
api_key=api_key,
secret=secret,
) | [
"def",
"update",
"(",
"self",
",",
"friendly_name",
"=",
"values",
".",
"unset",
",",
"certificate",
"=",
"values",
".",
"unset",
",",
"private_key",
"=",
"values",
".",
"unset",
",",
"sandbox",
"=",
"values",
".",
"unset",
",",
"api_key",
"=",
"values",... | https://github.com/twilio/twilio-python/blob/6e1e811ea57a1edfadd5161ace87397c563f6915/twilio/rest/chat/v2/credential.py#L408-L431 | |
cylc/cylc-flow | 5ec221143476c7c616c156b74158edfbcd83794a | cylc/flow/network/publisher.py | python | WorkflowPublisher.__init__ | (self, workflow, context=None, barrier=None,
threaded=True, daemon=False) | [] | def __init__(self, workflow, context=None, barrier=None,
threaded=True, daemon=False):
super().__init__(zmq.PUB, bind=True, context=context,
barrier=barrier, threaded=threaded, daemon=daemon)
self.workflow = workflow
self.topics = set() | [
"def",
"__init__",
"(",
"self",
",",
"workflow",
",",
"context",
"=",
"None",
",",
"barrier",
"=",
"None",
",",
"threaded",
"=",
"True",
",",
"daemon",
"=",
"False",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"zmq",
".",
"PUB",
",",
"bind",... | https://github.com/cylc/cylc-flow/blob/5ec221143476c7c616c156b74158edfbcd83794a/cylc/flow/network/publisher.py#L53-L58 | ||||
caiiiac/Machine-Learning-with-Python | 1a26c4467da41ca4ebc3d5bd789ea942ef79422f | MachineLearning/venv/lib/python3.5/site-packages/scipy/optimize/nonlin.py | python | LowRankMatrix.restart_reduce | (self, rank) | Reduce the rank of the matrix by dropping all vectors. | Reduce the rank of the matrix by dropping all vectors. | [
"Reduce",
"the",
"rank",
"of",
"the",
"matrix",
"by",
"dropping",
"all",
"vectors",
"."
] | def restart_reduce(self, rank):
"""
Reduce the rank of the matrix by dropping all vectors.
"""
if self.collapsed is not None:
return
assert rank > 0
if len(self.cs) > rank:
del self.cs[:]
del self.ds[:] | [
"def",
"restart_reduce",
"(",
"self",
",",
"rank",
")",
":",
"if",
"self",
".",
"collapsed",
"is",
"not",
"None",
":",
"return",
"assert",
"rank",
">",
"0",
"if",
"len",
"(",
"self",
".",
"cs",
")",
">",
"rank",
":",
"del",
"self",
".",
"cs",
"["... | https://github.com/caiiiac/Machine-Learning-with-Python/blob/1a26c4467da41ca4ebc3d5bd789ea942ef79422f/MachineLearning/venv/lib/python3.5/site-packages/scipy/optimize/nonlin.py#L798-L807 | ||
mrkipling/maraschino | c6be9286937783ae01df2d6d8cebfc8b2734a7d7 | lib/sqlalchemy/sql/expression.py | python | extract | (field, expr) | return _Extract(field, expr) | Return the clause ``extract(field FROM expr)``. | Return the clause ``extract(field FROM expr)``. | [
"Return",
"the",
"clause",
"extract",
"(",
"field",
"FROM",
"expr",
")",
"."
] | def extract(field, expr):
"""Return the clause ``extract(field FROM expr)``."""
return _Extract(field, expr) | [
"def",
"extract",
"(",
"field",
",",
"expr",
")",
":",
"return",
"_Extract",
"(",
"field",
",",
"expr",
")"
] | https://github.com/mrkipling/maraschino/blob/c6be9286937783ae01df2d6d8cebfc8b2734a7d7/lib/sqlalchemy/sql/expression.py#L623-L626 | |
buildbot/buildbot | b9c558217c72e4c2463eedc7ec6d56736f7b01a8 | master/buildbot/util/__init__.py | python | flattened_iterator | (l, types=(list, tuple)) | Generator for a list/tuple that potentially contains nested/lists/tuples of arbitrary nesting
that returns every individual non-list/tuple element. In other words,
# [(5, 6, [8, 3]), 2, [2, 1, (3, 4)]] will yield 5, 6, 8, 3, 2, 2, 1, 3, 4
This is safe to call on something not a list/tuple - the original input is yielded. | Generator for a list/tuple that potentially contains nested/lists/tuples of arbitrary nesting
that returns every individual non-list/tuple element. In other words,
# [(5, 6, [8, 3]), 2, [2, 1, (3, 4)]] will yield 5, 6, 8, 3, 2, 2, 1, 3, 4 | [
"Generator",
"for",
"a",
"list",
"/",
"tuple",
"that",
"potentially",
"contains",
"nested",
"/",
"lists",
"/",
"tuples",
"of",
"arbitrary",
"nesting",
"that",
"returns",
"every",
"individual",
"non",
"-",
"list",
"/",
"tuple",
"element",
".",
"In",
"other",
... | def flattened_iterator(l, types=(list, tuple)):
"""
Generator for a list/tuple that potentially contains nested/lists/tuples of arbitrary nesting
that returns every individual non-list/tuple element. In other words,
# [(5, 6, [8, 3]), 2, [2, 1, (3, 4)]] will yield 5, 6, 8, 3, 2, 2, 1, 3, 4
This is safe to call on something not a list/tuple - the original input is yielded.
"""
if not isinstance(l, types):
yield l
return
for element in l:
for sub_element in flattened_iterator(element, types):
yield sub_element | [
"def",
"flattened_iterator",
"(",
"l",
",",
"types",
"=",
"(",
"list",
",",
"tuple",
")",
")",
":",
"if",
"not",
"isinstance",
"(",
"l",
",",
"types",
")",
":",
"yield",
"l",
"return",
"for",
"element",
"in",
"l",
":",
"for",
"sub_element",
"in",
"... | https://github.com/buildbot/buildbot/blob/b9c558217c72e4c2463eedc7ec6d56736f7b01a8/master/buildbot/util/__init__.py#L60-L74 | ||
spyder-ide/spyder | 55da47c032dfcf519600f67f8b30eab467f965e7 | spyder/plugins/workingdirectory/plugin.py | python | WorkingDirectory.load_history | (self, workdir=None) | return history | Load history from a text file located in Spyder configuration folder
or use `workdir` if there are no directories saved yet.
Parameters
----------
workdir: str
The working directory to return. Default is None. | Load history from a text file located in Spyder configuration folder
or use `workdir` if there are no directories saved yet. | [
"Load",
"history",
"from",
"a",
"text",
"file",
"located",
"in",
"Spyder",
"configuration",
"folder",
"or",
"use",
"workdir",
"if",
"there",
"are",
"no",
"directories",
"saved",
"yet",
"."
] | def load_history(self, workdir=None):
"""
Load history from a text file located in Spyder configuration folder
or use `workdir` if there are no directories saved yet.
Parameters
----------
workdir: str
The working directory to return. Default is None.
"""
if osp.isfile(self.LOG_PATH):
history, _ = encoding.readlines(self.LOG_PATH)
history = [name for name in history if osp.isdir(name)]
else:
if workdir is None:
workdir = self.get_workdir()
history = [workdir]
return history | [
"def",
"load_history",
"(",
"self",
",",
"workdir",
"=",
"None",
")",
":",
"if",
"osp",
".",
"isfile",
"(",
"self",
".",
"LOG_PATH",
")",
":",
"history",
",",
"_",
"=",
"encoding",
".",
"readlines",
"(",
"self",
".",
"LOG_PATH",
")",
"history",
"=",
... | https://github.com/spyder-ide/spyder/blob/55da47c032dfcf519600f67f8b30eab467f965e7/spyder/plugins/workingdirectory/plugin.py#L190-L209 | |
mystor/git-revise | c06c8003870c776376e5f7bc4dd9f4dc97714b7c | gitrevise/odb.py | python | Signature.signing_key | (self) | return match.group("signing_key").strip() | user name <email> | user name <email> | [
"user",
"name",
"<email",
">"
] | def signing_key(self) -> bytes:
"""user name <email>"""
match = self.sig_re.fullmatch(self)
assert match, "invalid signature"
return match.group("signing_key").strip() | [
"def",
"signing_key",
"(",
"self",
")",
"->",
"bytes",
":",
"match",
"=",
"self",
".",
"sig_re",
".",
"fullmatch",
"(",
"self",
")",
"assert",
"match",
",",
"\"invalid signature\"",
"return",
"match",
".",
"group",
"(",
"\"signing_key\"",
")",
".",
"strip"... | https://github.com/mystor/git-revise/blob/c06c8003870c776376e5f7bc4dd9f4dc97714b7c/gitrevise/odb.py#L118-L122 | |
theotherp/nzbhydra | 4b03d7f769384b97dfc60dade4806c0fc987514e | libs/threading.py | python | _BoundedSemaphore.release | (self) | Release a semaphore, incrementing the internal counter by one.
When the counter is zero on entry and another thread is waiting for it
to become larger than zero again, wake up that thread.
If the number of releases exceeds the number of acquires,
raise a ValueError. | Release a semaphore, incrementing the internal counter by one. | [
"Release",
"a",
"semaphore",
"incrementing",
"the",
"internal",
"counter",
"by",
"one",
"."
] | def release(self):
"""Release a semaphore, incrementing the internal counter by one.
When the counter is zero on entry and another thread is waiting for it
to become larger than zero again, wake up that thread.
If the number of releases exceeds the number of acquires,
raise a ValueError.
"""
with self._Semaphore__cond:
if self._Semaphore__value >= self._initial_value:
raise ValueError("Semaphore released too many times")
self._Semaphore__value += 1
self._Semaphore__cond.notify() | [
"def",
"release",
"(",
"self",
")",
":",
"with",
"self",
".",
"_Semaphore__cond",
":",
"if",
"self",
".",
"_Semaphore__value",
">=",
"self",
".",
"_initial_value",
":",
"raise",
"ValueError",
"(",
"\"Semaphore released too many times\"",
")",
"self",
".",
"_Sema... | https://github.com/theotherp/nzbhydra/blob/4b03d7f769384b97dfc60dade4806c0fc987514e/libs/threading.py#L525-L539 | ||
tensorflow/lingvo | ce10019243d954c3c3ebe739f7589b5eebfdf907 | lingvo/jax/optimizers.py | python | _ShardedAdamHelper.bias_corrected_decay | (self, step: JTensor, decay: float) | return decay * (1. - jnp.power(decay, t - 1.)) / (1. - jnp.power(decay, t)) | Incorporates bias correction into decay.
Please see section 7.1 in https://arxiv.org/pdf/1804.04235.pdf for the
derivation of the formulas below. With bias-corrected decay, we can simply
do
m_{t} = decay1 * m_{t-1} + (1 - decay1) * g
v_{t} = decay2 * v_{t-1} + (1 - decay2) * g ^ 2
without further bias correction.
Args:
step: current step, 0-based.
decay: the raw decay. As t -> infinity, bias corrected decay converges to
this value.
Returns:
Bias corrected decay. | Incorporates bias correction into decay. | [
"Incorporates",
"bias",
"correction",
"into",
"decay",
"."
] | def bias_corrected_decay(self, step: JTensor, decay: float) -> JTensor:
"""Incorporates bias correction into decay.
Please see section 7.1 in https://arxiv.org/pdf/1804.04235.pdf for the
derivation of the formulas below. With bias-corrected decay, we can simply
do
m_{t} = decay1 * m_{t-1} + (1 - decay1) * g
v_{t} = decay2 * v_{t-1} + (1 - decay2) * g ^ 2
without further bias correction.
Args:
step: current step, 0-based.
decay: the raw decay. As t -> infinity, bias corrected decay converges to
this value.
Returns:
Bias corrected decay.
"""
t = step.astype(jnp.float32) + 1.
return decay * (1. - jnp.power(decay, t - 1.)) / (1. - jnp.power(decay, t)) | [
"def",
"bias_corrected_decay",
"(",
"self",
",",
"step",
":",
"JTensor",
",",
"decay",
":",
"float",
")",
"->",
"JTensor",
":",
"t",
"=",
"step",
".",
"astype",
"(",
"jnp",
".",
"float32",
")",
"+",
"1.",
"return",
"decay",
"*",
"(",
"1.",
"-",
"jn... | https://github.com/tensorflow/lingvo/blob/ce10019243d954c3c3ebe739f7589b5eebfdf907/lingvo/jax/optimizers.py#L159-L180 | |
cloudera/hue | 23f02102d4547c17c32bd5ea0eb24e9eadd657a4 | desktop/core/ext-py/boto-2.46.1/boto/route53/zone.py | python | Zone.add_a | (self, name, value, ttl=None, identifier=None, comment="") | return self.add_record(resource_type='A',
name=name,
value=value,
ttl=ttl,
identifier=identifier,
comment=comment) | Add a new A record to this Zone. See _new_record for
parameter documentation. Returns a Status object. | Add a new A record to this Zone. See _new_record for
parameter documentation. Returns a Status object. | [
"Add",
"a",
"new",
"A",
"record",
"to",
"this",
"Zone",
".",
"See",
"_new_record",
"for",
"parameter",
"documentation",
".",
"Returns",
"a",
"Status",
"object",
"."
] | def add_a(self, name, value, ttl=None, identifier=None, comment=""):
"""
Add a new A record to this Zone. See _new_record for
parameter documentation. Returns a Status object.
"""
ttl = ttl or default_ttl
name = self.route53connection._make_qualified(name)
return self.add_record(resource_type='A',
name=name,
value=value,
ttl=ttl,
identifier=identifier,
comment=comment) | [
"def",
"add_a",
"(",
"self",
",",
"name",
",",
"value",
",",
"ttl",
"=",
"None",
",",
"identifier",
"=",
"None",
",",
"comment",
"=",
"\"\"",
")",
":",
"ttl",
"=",
"ttl",
"or",
"default_ttl",
"name",
"=",
"self",
".",
"route53connection",
".",
"_make... | https://github.com/cloudera/hue/blob/23f02102d4547c17c32bd5ea0eb24e9eadd657a4/desktop/core/ext-py/boto-2.46.1/boto/route53/zone.py#L173-L185 | |
kubernetes-client/python | 47b9da9de2d02b2b7a34fbe05afb44afd130d73a | kubernetes/client/models/v1_delete_options.py | python | V1DeleteOptions.api_version | (self) | return self._api_version | Gets the api_version of this V1DeleteOptions. # noqa: E501
APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources # noqa: E501
:return: The api_version of this V1DeleteOptions. # noqa: E501
:rtype: str | Gets the api_version of this V1DeleteOptions. # noqa: E501 | [
"Gets",
"the",
"api_version",
"of",
"this",
"V1DeleteOptions",
".",
"#",
"noqa",
":",
"E501"
] | def api_version(self):
"""Gets the api_version of this V1DeleteOptions. # noqa: E501
APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources # noqa: E501
:return: The api_version of this V1DeleteOptions. # noqa: E501
:rtype: str
"""
return self._api_version | [
"def",
"api_version",
"(",
"self",
")",
":",
"return",
"self",
".",
"_api_version"
] | https://github.com/kubernetes-client/python/blob/47b9da9de2d02b2b7a34fbe05afb44afd130d73a/kubernetes/client/models/v1_delete_options.py#L86-L94 | |
SteveDoyle2/pyNastran | eda651ac2d4883d95a34951f8a002ff94f642a1a | pyNastran/bdf/cards/aero/aero.py | python | AELINK.cross_reference | (self, model: BDF) | We're simply going to validate the labels | We're simply going to validate the labels | [
"We",
"re",
"simply",
"going",
"to",
"validate",
"the",
"labels"
] | def cross_reference(self, model: BDF) -> None:
"""We're simply going to validate the labels"""
sid_ref = model.trims[self.aelink_id]
independent_label_ref = model.AESurf(self.label, msg=f'which is required by {str(self)}') | [
"def",
"cross_reference",
"(",
"self",
",",
"model",
":",
"BDF",
")",
"->",
"None",
":",
"sid_ref",
"=",
"model",
".",
"trims",
"[",
"self",
".",
"aelink_id",
"]",
"independent_label_ref",
"=",
"model",
".",
"AESurf",
"(",
"self",
".",
"label",
",",
"m... | https://github.com/SteveDoyle2/pyNastran/blob/eda651ac2d4883d95a34951f8a002ff94f642a1a/pyNastran/bdf/cards/aero/aero.py#L554-L557 | ||
openshift/openshift-tools | 1188778e728a6e4781acf728123e5b356380fe6f | openshift/installer/vendored/openshift-ansible-3.9.40/roles/lib_vendored_deps/library/oc_pvc.py | python | Yedit.get_curr_value | (invalue, val_type) | return curr_value | return the current value | return the current value | [
"return",
"the",
"current",
"value"
] | def get_curr_value(invalue, val_type):
'''return the current value'''
if invalue is None:
return None
curr_value = invalue
if val_type == 'yaml':
try:
# AUDIT:maybe-no-member makes sense due to different yaml libraries
# pylint: disable=maybe-no-member
curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader)
except AttributeError:
curr_value = yaml.safe_load(invalue)
elif val_type == 'json':
curr_value = json.loads(invalue)
return curr_value | [
"def",
"get_curr_value",
"(",
"invalue",
",",
"val_type",
")",
":",
"if",
"invalue",
"is",
"None",
":",
"return",
"None",
"curr_value",
"=",
"invalue",
"if",
"val_type",
"==",
"'yaml'",
":",
"try",
":",
"# AUDIT:maybe-no-member makes sense due to different yaml libr... | https://github.com/openshift/openshift-tools/blob/1188778e728a6e4781acf728123e5b356380fe6f/openshift/installer/vendored/openshift-ansible-3.9.40/roles/lib_vendored_deps/library/oc_pvc.py#L671-L687 | |
omz/PythonistaAppTemplate | f560f93f8876d82a21d108977f90583df08d55af | PythonistaAppTemplate/PythonistaKit.framework/pylib_ext/numpy/matlib.py | python | empty | (shape, dtype=None, order='C') | return ndarray.__new__(matrix, shape, dtype, order=order) | Return a new matrix of given shape and type, without initializing entries.
Parameters
----------
shape : int or tuple of int
Shape of the empty matrix.
dtype : data-type, optional
Desired output data-type.
order : {'C', 'F'}, optional
Whether to store multi-dimensional data in C (row-major) or
Fortran (column-major) order in memory.
See Also
--------
empty_like, zeros
Notes
-----
`empty`, unlike `zeros`, does not set the matrix values to zero,
and may therefore be marginally faster. On the other hand, it requires
the user to manually set all the values in the array, and should be
used with caution.
Examples
--------
>>> import numpy.matlib
>>> np.matlib.empty((2, 2)) # filled with random data
matrix([[ 6.76425276e-320, 9.79033856e-307],
[ 7.39337286e-309, 3.22135945e-309]]) #random
>>> np.matlib.empty((2, 2), dtype=int)
matrix([[ 6600475, 0],
[ 6586976, 22740995]]) #random | Return a new matrix of given shape and type, without initializing entries. | [
"Return",
"a",
"new",
"matrix",
"of",
"given",
"shape",
"and",
"type",
"without",
"initializing",
"entries",
"."
] | def empty(shape, dtype=None, order='C'):
"""
Return a new matrix of given shape and type, without initializing entries.
Parameters
----------
shape : int or tuple of int
Shape of the empty matrix.
dtype : data-type, optional
Desired output data-type.
order : {'C', 'F'}, optional
Whether to store multi-dimensional data in C (row-major) or
Fortran (column-major) order in memory.
See Also
--------
empty_like, zeros
Notes
-----
`empty`, unlike `zeros`, does not set the matrix values to zero,
and may therefore be marginally faster. On the other hand, it requires
the user to manually set all the values in the array, and should be
used with caution.
Examples
--------
>>> import numpy.matlib
>>> np.matlib.empty((2, 2)) # filled with random data
matrix([[ 6.76425276e-320, 9.79033856e-307],
[ 7.39337286e-309, 3.22135945e-309]]) #random
>>> np.matlib.empty((2, 2), dtype=int)
matrix([[ 6600475, 0],
[ 6586976, 22740995]]) #random
"""
return ndarray.__new__(matrix, shape, dtype, order=order) | [
"def",
"empty",
"(",
"shape",
",",
"dtype",
"=",
"None",
",",
"order",
"=",
"'C'",
")",
":",
"return",
"ndarray",
".",
"__new__",
"(",
"matrix",
",",
"shape",
",",
"dtype",
",",
"order",
"=",
"order",
")"
] | https://github.com/omz/PythonistaAppTemplate/blob/f560f93f8876d82a21d108977f90583df08d55af/PythonistaAppTemplate/PythonistaKit.framework/pylib_ext/numpy/matlib.py#L13-L49 | |
llSourcell/AI_Artist | 3038c06c2e389b9c919c881c9a169efe2fd7810e | lib/python2.7/site-packages/pip/_vendor/pkg_resources/__init__.py | python | _macosx_arch | (machine) | return {'PowerPC': 'ppc', 'Power_Macintosh': 'ppc'}.get(machine, machine) | [] | def _macosx_arch(machine):
return {'PowerPC': 'ppc', 'Power_Macintosh': 'ppc'}.get(machine, machine) | [
"def",
"_macosx_arch",
"(",
"machine",
")",
":",
"return",
"{",
"'PowerPC'",
":",
"'ppc'",
",",
"'Power_Macintosh'",
":",
"'ppc'",
"}",
".",
"get",
"(",
"machine",
",",
"machine",
")"
] | https://github.com/llSourcell/AI_Artist/blob/3038c06c2e389b9c919c881c9a169efe2fd7810e/lib/python2.7/site-packages/pip/_vendor/pkg_resources/__init__.py#L439-L440 | |||
plaid/plaid-python | 8c60fca608e426f3ff30da8857775946d29e122c | plaid/model/item_get_request.py | python | ItemGetRequest.openapi_types | () | return {
'access_token': (str,), # noqa: E501
'client_id': (str,), # noqa: E501
'secret': (str,), # noqa: E501
} | This must be a method because a model may have properties that are
of type self, this must run after the class is loaded
Returns
openapi_types (dict): The key is attribute name
and the value is attribute type. | This must be a method because a model may have properties that are
of type self, this must run after the class is loaded | [
"This",
"must",
"be",
"a",
"method",
"because",
"a",
"model",
"may",
"have",
"properties",
"that",
"are",
"of",
"type",
"self",
"this",
"must",
"run",
"after",
"the",
"class",
"is",
"loaded"
] | def openapi_types():
"""
This must be a method because a model may have properties that are
of type self, this must run after the class is loaded
Returns
openapi_types (dict): The key is attribute name
and the value is attribute type.
"""
return {
'access_token': (str,), # noqa: E501
'client_id': (str,), # noqa: E501
'secret': (str,), # noqa: E501
} | [
"def",
"openapi_types",
"(",
")",
":",
"return",
"{",
"'access_token'",
":",
"(",
"str",
",",
")",
",",
"# noqa: E501",
"'client_id'",
":",
"(",
"str",
",",
")",
",",
"# noqa: E501",
"'secret'",
":",
"(",
"str",
",",
")",
",",
"# noqa: E501",
"}"
] | https://github.com/plaid/plaid-python/blob/8c60fca608e426f3ff30da8857775946d29e122c/plaid/model/item_get_request.py#L63-L76 | |
wanggrun/Adaptively-Connected-Neural-Networks | e27066ef52301bdafa5932f43af8feeb23647edb | tensorpack-installed/tensorpack/utils/timer.py | python | print_total_timer | () | Print the content of the TotalTimer, if it's not empty. This function will automatically get
called when program exits. | Print the content of the TotalTimer, if it's not empty. This function will automatically get
called when program exits. | [
"Print",
"the",
"content",
"of",
"the",
"TotalTimer",
"if",
"it",
"s",
"not",
"empty",
".",
"This",
"function",
"will",
"automatically",
"get",
"called",
"when",
"program",
"exits",
"."
] | def print_total_timer():
"""
Print the content of the TotalTimer, if it's not empty. This function will automatically get
called when program exits.
"""
if len(_TOTAL_TIMER_DATA) == 0:
return
for k, v in six.iteritems(_TOTAL_TIMER_DATA):
logger.info("Total Time: {} -> {:.2f} sec, {} times, {:.3g} sec/time".format(
k, v.sum, v.count, v.average)) | [
"def",
"print_total_timer",
"(",
")",
":",
"if",
"len",
"(",
"_TOTAL_TIMER_DATA",
")",
"==",
"0",
":",
"return",
"for",
"k",
",",
"v",
"in",
"six",
".",
"iteritems",
"(",
"_TOTAL_TIMER_DATA",
")",
":",
"logger",
".",
"info",
"(",
"\"Total Time: {} -> {:.2f... | https://github.com/wanggrun/Adaptively-Connected-Neural-Networks/blob/e27066ef52301bdafa5932f43af8feeb23647edb/tensorpack-installed/tensorpack/utils/timer.py#L60-L69 | ||
redis/redis-py | 0affa0ed3f3cbcb6dec29b34a580f769f69ae9f7 | redis/cluster.py | python | ClusterPipeline.pipeline_execute_command | (self, *args, **options) | return self | Appends the executed command to the pipeline's command stack | Appends the executed command to the pipeline's command stack | [
"Appends",
"the",
"executed",
"command",
"to",
"the",
"pipeline",
"s",
"command",
"stack"
] | def pipeline_execute_command(self, *args, **options):
"""
Appends the executed command to the pipeline's command stack
"""
self.command_stack.append(
PipelineCommand(args, options, len(self.command_stack))
)
return self | [
"def",
"pipeline_execute_command",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"options",
")",
":",
"self",
".",
"command_stack",
".",
"append",
"(",
"PipelineCommand",
"(",
"args",
",",
"options",
",",
"len",
"(",
"self",
".",
"command_stack",
")",
")... | https://github.com/redis/redis-py/blob/0affa0ed3f3cbcb6dec29b34a580f769f69ae9f7/redis/cluster.py#L1665-L1672 | |
andresriancho/w3af | cd22e5252243a87aaa6d0ddea47cf58dacfe00a9 | w3af/plugins/crawl/oracle_discovery.py | python | oracle_discovery.send_and_check | (self, url) | [] | def send_and_check(self, url):
response = self.http_get_and_parse(url)
for regex in self.ORACLE_RE:
# pylint: disable=E1101
mo = regex.search(response.get_body(), re.DOTALL)
# pylint: enable=E1101
if mo:
desc = '"%s" version "%s" was detected at "%s".'
desc %= (mo.group(1).title(), mo.group(2).title(), response.get_url())
i = Info('Oracle Application Server', desc, response.id, self.get_name())
i.set_url(response.get_url())
kb.kb.append(self, 'oracle_discovery', i)
om.out.information(i.get_desc())
fr = FuzzableRequest.from_http_response(response)
self.output_queue.put(fr)
break
else:
msg = ('oracle_discovery found the URL: "%s" but failed to'
' parse it as an Oracle page. The first 50 bytes of'
' the response body is: "%s".')
body_start = response.get_body()[:50]
om.out.debug(msg % (response.get_url(), body_start)) | [
"def",
"send_and_check",
"(",
"self",
",",
"url",
")",
":",
"response",
"=",
"self",
".",
"http_get_and_parse",
"(",
"url",
")",
"for",
"regex",
"in",
"self",
".",
"ORACLE_RE",
":",
"# pylint: disable=E1101",
"mo",
"=",
"regex",
".",
"search",
"(",
"respon... | https://github.com/andresriancho/w3af/blob/cd22e5252243a87aaa6d0ddea47cf58dacfe00a9/w3af/plugins/crawl/oracle_discovery.py#L75-L104 | ||||
PolyAI-LDN/conversational-datasets | 50f626ad0d0e825835bd054f6a58006afa95a8e5 | baselines/vector_based.py | python | VectorMappingMethod._create_train_and_dev | (self, contexts, responses) | return train_test_split(
context_encodings, response_encodings,
test_size=0.2) | Create a train and dev set of context and response vectors. | Create a train and dev set of context and response vectors. | [
"Create",
"a",
"train",
"and",
"dev",
"set",
"of",
"context",
"and",
"response",
"vectors",
"."
] | def _create_train_and_dev(self, contexts, responses):
"""Create a train and dev set of context and response vectors."""
glog.info("Encoding the train set.")
context_encodings = []
response_encodings = []
for i in tqdm(range(0, len(contexts), self._ENCODING_BATCH_SIZE)):
contexts_batch = contexts[i:i + self._ENCODING_BATCH_SIZE]
responses_batch = responses[i:i + self._ENCODING_BATCH_SIZE]
context_encodings.append(
self._encoder.encode_context(contexts_batch))
response_encodings.append(
self._encoder.encode_response(responses_batch))
context_encodings = np.concatenate(
context_encodings).astype(np.float32)
response_encodings = np.concatenate(
response_encodings).astype(np.float32)
return train_test_split(
context_encodings, response_encodings,
test_size=0.2) | [
"def",
"_create_train_and_dev",
"(",
"self",
",",
"contexts",
",",
"responses",
")",
":",
"glog",
".",
"info",
"(",
"\"Encoding the train set.\"",
")",
"context_encodings",
"=",
"[",
"]",
"response_encodings",
"=",
"[",
"]",
"for",
"i",
"in",
"tqdm",
"(",
"r... | https://github.com/PolyAI-LDN/conversational-datasets/blob/50f626ad0d0e825835bd054f6a58006afa95a8e5/baselines/vector_based.py#L329-L350 | |
openshift/openshift-tools | 1188778e728a6e4781acf728123e5b356380fe6f | scripts/monitoring/cron-send-docker-grpc.py | python | parse_args | () | return arg | parse the args from the cli | parse the args from the cli | [
"parse",
"the",
"args",
"from",
"the",
"cli"
] | def parse_args():
""" parse the args from the cli """
parser = argparse.ArgumentParser(description='docker grpc error check')
parser.add_argument('-v', '--verbose', action='store_true', default=None, help='Verbose?')
parser.add_argument('--debug', action='store_true', default=None, help='Debug?')
arg = parser.parse_args()
if arg.verbose:
logger.setLevel(logging.INFO)
if arg.debug:
logger.setLevel(logging.DEBUG)
return arg | [
"def",
"parse_args",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'docker grpc error check'",
")",
"parser",
".",
"add_argument",
"(",
"'-v'",
",",
"'--verbose'",
",",
"action",
"=",
"'store_true'",
",",
"default",
... | https://github.com/openshift/openshift-tools/blob/1188778e728a6e4781acf728123e5b356380fe6f/scripts/monitoring/cron-send-docker-grpc.py#L31-L45 | |
cournape/Bento | 37de23d784407a7c98a4a15770ffc570d5f32d70 | bento/private/_yaku/yaku/context.py | python | ConfigureContext.start_message | (self, msg) | [] | def start_message(self, msg):
_OUTPUT.write(msg + "... ")
self.log.write("=" * 79 + "\n")
self.log.write("%s\n" % msg) | [
"def",
"start_message",
"(",
"self",
",",
"msg",
")",
":",
"_OUTPUT",
".",
"write",
"(",
"msg",
"+",
"\"... \"",
")",
"self",
".",
"log",
".",
"write",
"(",
"\"=\"",
"*",
"79",
"+",
"\"\\n\"",
")",
"self",
".",
"log",
".",
"write",
"(",
"\"%s\\n\""... | https://github.com/cournape/Bento/blob/37de23d784407a7c98a4a15770ffc570d5f32d70/bento/private/_yaku/yaku/context.py#L129-L132 | ||||
saltstack/salt | fae5bc757ad0f1716483ce7ae180b451545c2058 | salt/utils/memcached.py | python | _check_stats | (conn) | return stats | Helper function to check the stats data passed into it, and raise an
exception if none are returned. Otherwise, the stats are returned. | Helper function to check the stats data passed into it, and raise an
exception if none are returned. Otherwise, the stats are returned. | [
"Helper",
"function",
"to",
"check",
"the",
"stats",
"data",
"passed",
"into",
"it",
"and",
"raise",
"an",
"exception",
"if",
"none",
"are",
"returned",
".",
"Otherwise",
"the",
"stats",
"are",
"returned",
"."
] | def _check_stats(conn):
"""
Helper function to check the stats data passed into it, and raise an
exception if none are returned. Otherwise, the stats are returned.
"""
stats = conn.get_stats()
if not stats:
raise CommandExecutionError("memcached server is down or does not exist")
return stats | [
"def",
"_check_stats",
"(",
"conn",
")",
":",
"stats",
"=",
"conn",
".",
"get_stats",
"(",
")",
"if",
"not",
"stats",
":",
"raise",
"CommandExecutionError",
"(",
"\"memcached server is down or does not exist\"",
")",
"return",
"stats"
] | https://github.com/saltstack/salt/blob/fae5bc757ad0f1716483ce7ae180b451545c2058/salt/utils/memcached.py#L102-L110 | |
mayank93/Twitter-Sentiment-Analysis | f095c6ca6bf69787582b5dabb140fefaf278eb37 | front-end/web2py/gluon/contrib/gateways/fcgi.py | python | Connection._do_stdin | (self, inrec) | Handle the FCGI_STDIN stream. | Handle the FCGI_STDIN stream. | [
"Handle",
"the",
"FCGI_STDIN",
"stream",
"."
] | def _do_stdin(self, inrec):
"""Handle the FCGI_STDIN stream."""
req = self._requests.get(inrec.requestId)
if req is not None:
req.stdin.add_data(inrec.contentData) | [
"def",
"_do_stdin",
"(",
"self",
",",
"inrec",
")",
":",
"req",
"=",
"self",
".",
"_requests",
".",
"get",
"(",
"inrec",
".",
"requestId",
")",
"if",
"req",
"is",
"not",
"None",
":",
"req",
".",
"stdin",
".",
"add_data",
"(",
"inrec",
".",
"content... | https://github.com/mayank93/Twitter-Sentiment-Analysis/blob/f095c6ca6bf69787582b5dabb140fefaf278eb37/front-end/web2py/gluon/contrib/gateways/fcgi.py#L801-L805 | ||
Fantomas42/django-blog-zinnia | 881101a9d1d455b2fc581d6f4ae0947cdd8126c6 | zinnia/preview.py | python | HTMLPreview.has_more | (self) | return bool(self.content and self.preview != self.content) | Boolean telling if the preview has hidden content. | Boolean telling if the preview has hidden content. | [
"Boolean",
"telling",
"if",
"the",
"preview",
"has",
"hidden",
"content",
"."
] | def has_more(self):
"""
Boolean telling if the preview has hidden content.
"""
return bool(self.content and self.preview != self.content) | [
"def",
"has_more",
"(",
"self",
")",
":",
"return",
"bool",
"(",
"self",
".",
"content",
"and",
"self",
".",
"preview",
"!=",
"self",
".",
"content",
")"
] | https://github.com/Fantomas42/django-blog-zinnia/blob/881101a9d1d455b2fc581d6f4ae0947cdd8126c6/zinnia/preview.py#L42-L46 | |
vulscanteam/vulscan | 787397e267c4e6469522ee0abe55b3e98f968d4a | pocsuite/thirdparty/requests/sessions.py | python | Session.mount | (self, prefix, adapter) | Registers a connection adapter to a prefix.
Adapters are sorted in descending order by key length. | Registers a connection adapter to a prefix. | [
"Registers",
"a",
"connection",
"adapter",
"to",
"a",
"prefix",
"."
] | def mount(self, prefix, adapter):
"""Registers a connection adapter to a prefix.
Adapters are sorted in descending order by key length."""
self.adapters[prefix] = adapter
keys_to_move = [k for k in self.adapters if len(k) < len(prefix)]
for key in keys_to_move:
self.adapters[key] = self.adapters.pop(key) | [
"def",
"mount",
"(",
"self",
",",
"prefix",
",",
"adapter",
")",
":",
"self",
".",
"adapters",
"[",
"prefix",
"]",
"=",
"adapter",
"keys_to_move",
"=",
"[",
"k",
"for",
"k",
"in",
"self",
".",
"adapters",
"if",
"len",
"(",
"k",
")",
"<",
"len",
"... | https://github.com/vulscanteam/vulscan/blob/787397e267c4e6469522ee0abe55b3e98f968d4a/pocsuite/thirdparty/requests/sessions.py#L648-L657 | ||
natashamjaques/neural_chat | ddb977bb4602a67c460d02231e7bbf7b2cb49a97 | ParlAI/parlai/core/torch_agent.py | python | TorchAgent._get_init_model | (self, opt, shared) | return init_model, is_finetune | Get model file to initialize with.
If `init_model` exits, we will return the path to that file and maybe
load dict file from that path. Otherwise, use `model_file.`
:return: path to load model from, whether we loaded from `init_model`
or not | Get model file to initialize with. | [
"Get",
"model",
"file",
"to",
"initialize",
"with",
"."
] | def _get_init_model(self, opt, shared):
"""
Get model file to initialize with.
If `init_model` exits, we will return the path to that file and maybe
load dict file from that path. Otherwise, use `model_file.`
:return: path to load model from, whether we loaded from `init_model`
or not
"""
init_model = None
is_finetune = False
if not shared: # only do this on first setup
# first check load path in case we need to override paths
if opt.get('init_model') and os.path.isfile(opt['init_model']):
# check first for 'init_model' for loading model from file
init_model = opt['init_model']
is_finetune = True
if opt.get('model_file') and os.path.isfile(opt['model_file']):
# next check for 'model_file', this would override init_model
init_model = opt['model_file']
is_finetune = False
if (
opt.get('load_from_checkpoint')
and opt.get('init_model')
and opt['init_model'].endswith('.checkpoint')
):
# but if we're loading from a checkpoint, we should explicitly load
# from that point
init_model = opt['init_model']
is_finetune = False
if init_model is not None:
# if we are loading a model, should load its dict too
if os.path.isfile(init_model + '.dict') or opt['dict_file'] is None:
opt['dict_file'] = init_model + '.dict'
return init_model, is_finetune | [
"def",
"_get_init_model",
"(",
"self",
",",
"opt",
",",
"shared",
")",
":",
"init_model",
"=",
"None",
"is_finetune",
"=",
"False",
"if",
"not",
"shared",
":",
"# only do this on first setup",
"# first check load path in case we need to override paths",
"if",
"opt",
"... | https://github.com/natashamjaques/neural_chat/blob/ddb977bb4602a67c460d02231e7bbf7b2cb49a97/ParlAI/parlai/core/torch_agent.py#L759-L796 | |
awslabs/deeplearning-benchmark | 3e9a906422b402869537f91056ae771b66487a8e | tensorflow_benchmark/tf_cnn_benchmarks/cnn_util.py | python | ImageProducer.start | (self) | Start the image producer. | Start the image producer. | [
"Start",
"the",
"image",
"producer",
"."
] | def start(self):
"""Start the image producer."""
self.thread = threading.Thread(target=self._loop_producer)
# Set daemon to true to allow Ctrl + C to terminate all threads.
self.thread.daemon = True
self.thread.start() | [
"def",
"start",
"(",
"self",
")",
":",
"self",
".",
"thread",
"=",
"threading",
".",
"Thread",
"(",
"target",
"=",
"self",
".",
"_loop_producer",
")",
"# Set daemon to true to allow Ctrl + C to terminate all threads.",
"self",
".",
"thread",
".",
"daemon",
"=",
... | https://github.com/awslabs/deeplearning-benchmark/blob/3e9a906422b402869537f91056ae771b66487a8e/tensorflow_benchmark/tf_cnn_benchmarks/cnn_util.py#L141-L146 | ||
neulab/xnmt | d93f8f3710f986f36eb54e9ff3976a6b683da2a4 | xnmt/thirdparty/charcut/charcut.py | python | read_gz8 | (filename) | Read a utf8, possibly gzipped, file into memory, as a list of lines. | Read a utf8, possibly gzipped, file into memory, as a list of lines. | [
"Read",
"a",
"utf8",
"possibly",
"gzipped",
"file",
"into",
"memory",
"as",
"a",
"list",
"of",
"lines",
"."
] | def read_gz8(filename):
"""Read a utf8, possibly gzipped, file into memory, as a list of lines."""
with open(filename, 'r', encoding='utf-8') as f:
return [line for line in f] | [
"def",
"read_gz8",
"(",
"filename",
")",
":",
"with",
"open",
"(",
"filename",
",",
"'r'",
",",
"encoding",
"=",
"'utf-8'",
")",
"as",
"f",
":",
"return",
"[",
"line",
"for",
"line",
"in",
"f",
"]"
] | https://github.com/neulab/xnmt/blob/d93f8f3710f986f36eb54e9ff3976a6b683da2a4/xnmt/thirdparty/charcut/charcut.py#L66-L69 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.