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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
IronLanguages/ironpython3 | 7a7bb2a872eeab0d1009fc8a6e24dca43f65b693 | Src/StdLib/Lib/ast.py | python | walk | (node) | Recursively yield all descendant nodes in the tree starting at *node*
(including *node* itself), in no specified order. This is useful if you
only want to modify nodes in place and don't care about the context. | Recursively yield all descendant nodes in the tree starting at *node*
(including *node* itself), in no specified order. This is useful if you
only want to modify nodes in place and don't care about the context. | [
"Recursively",
"yield",
"all",
"descendant",
"nodes",
"in",
"the",
"tree",
"starting",
"at",
"*",
"node",
"*",
"(",
"including",
"*",
"node",
"*",
"itself",
")",
"in",
"no",
"specified",
"order",
".",
"This",
"is",
"useful",
"if",
"you",
"only",
"want",
... | def walk(node):
"""
Recursively yield all descendant nodes in the tree starting at *node*
(including *node* itself), in no specified order. This is useful if you
only want to modify nodes in place and don't care about the context.
"""
from collections import deque
todo = deque([node])
while todo:
node = todo.popleft()
todo.extend(iter_child_nodes(node))
yield node | [
"def",
"walk",
"(",
"node",
")",
":",
"from",
"collections",
"import",
"deque",
"todo",
"=",
"deque",
"(",
"[",
"node",
"]",
")",
"while",
"todo",
":",
"node",
"=",
"todo",
".",
"popleft",
"(",
")",
"todo",
".",
"extend",
"(",
"iter_child_nodes",
"("... | https://github.com/IronLanguages/ironpython3/blob/7a7bb2a872eeab0d1009fc8a6e24dca43f65b693/Src/StdLib/Lib/ast.py#L207-L218 | ||
calebstewart/pwncat | d67865bdaac60dd0761d0698062e7b443a62c6db | pwncat/modules/windows/enumerate/domain/__init__.py | python | DomainObject.__getitem__ | (self, name: str) | return self.domain[name] | Shortcut for getting properties from the `self.domain` property. | Shortcut for getting properties from the `self.domain` property. | [
"Shortcut",
"for",
"getting",
"properties",
"from",
"the",
"self",
".",
"domain",
"property",
"."
] | def __getitem__(self, name: str):
"""Shortcut for getting properties from the `self.domain` property."""
return self.domain[name] | [
"def",
"__getitem__",
"(",
"self",
",",
"name",
":",
"str",
")",
":",
"return",
"self",
".",
"domain",
"[",
"name",
"]"
] | https://github.com/calebstewart/pwncat/blob/d67865bdaac60dd0761d0698062e7b443a62c6db/pwncat/modules/windows/enumerate/domain/__init__.py#L18-L21 | |
wechatpy/wechatpy | 5f693a7e90156786c2540ad3c941d12cdf6d88ef | wechatpy/client/api/customservice.py | python | WeChatCustomService.get_session_list | (self, account) | return res | 获取客服的会话列表
详情请参考
http://mp.weixin.qq.com/wiki/2/6c20f3e323bdf5986cfcb33cbd3b829a.html
:param account: 完整客服账号
:return: 客服的会话列表 | 获取客服的会话列表
详情请参考
http://mp.weixin.qq.com/wiki/2/6c20f3e323bdf5986cfcb33cbd3b829a.html | [
"获取客服的会话列表",
"详情请参考",
"http",
":",
"//",
"mp",
".",
"weixin",
".",
"qq",
".",
"com",
"/",
"wiki",
"/",
"2",
"/",
"6c20f3e323bdf5986cfcb33cbd3b829a",
".",
"html"
] | def get_session_list(self, account):
"""
获取客服的会话列表
详情请参考
http://mp.weixin.qq.com/wiki/2/6c20f3e323bdf5986cfcb33cbd3b829a.html
:param account: 完整客服账号
:return: 客服的会话列表
"""
res = self._get(
"https://api.weixin.qq.com/customservice/kfsession/getsessionlist",
params={"kf_account": account},
result_processor=lambda x: x["sessionlist"],
)
return res | [
"def",
"get_session_list",
"(",
"self",
",",
"account",
")",
":",
"res",
"=",
"self",
".",
"_get",
"(",
"\"https://api.weixin.qq.com/customservice/kfsession/getsessionlist\"",
",",
"params",
"=",
"{",
"\"kf_account\"",
":",
"account",
"}",
",",
"result_processor",
"... | https://github.com/wechatpy/wechatpy/blob/5f693a7e90156786c2540ad3c941d12cdf6d88ef/wechatpy/client/api/customservice.py#L149-L163 | |
freelawproject/courtlistener | ab3ae7bb6e5e836b286749113e7dbb403d470912 | cl/api/views.py | python | annotate_courts_with_counts | (courts, court_count_tuples) | return courts | Solr gives us a response like:
court_count_tuples = [
('ca2', 200),
('ca1', 42),
...
]
Here we add an attribute to our court objects so they have these values. | Solr gives us a response like: | [
"Solr",
"gives",
"us",
"a",
"response",
"like",
":"
] | def annotate_courts_with_counts(courts, court_count_tuples):
"""Solr gives us a response like:
court_count_tuples = [
('ca2', 200),
('ca1', 42),
...
]
Here we add an attribute to our court objects so they have these values.
"""
# Convert the tuple to a dict
court_count_dict = {}
for court_str, count in court_count_tuples:
court_count_dict[court_str] = count
for court in courts:
court.count = court_count_dict.get(court.pk, 0)
return courts | [
"def",
"annotate_courts_with_counts",
"(",
"courts",
",",
"court_count_tuples",
")",
":",
"# Convert the tuple to a dict",
"court_count_dict",
"=",
"{",
"}",
"for",
"court_str",
",",
"count",
"in",
"court_count_tuples",
":",
"court_count_dict",
"[",
"court_str",
"]",
... | https://github.com/freelawproject/courtlistener/blob/ab3ae7bb6e5e836b286749113e7dbb403d470912/cl/api/views.py#L24-L43 | |
materialsproject/pymatgen | 8128f3062a334a2edd240e4062b5b9bdd1ae6f58 | pymatgen/io/vasp/help.py | python | VaspDoc.get_incar_tags | (cls) | return tags | Returns: All incar tags | Returns: All incar tags | [
"Returns",
":",
"All",
"incar",
"tags"
] | def get_incar_tags(cls):
"""
Returns: All incar tags
"""
tags = []
for page in [
"http://www.vasp.at/wiki/index.php/Category:INCAR",
"http://www.vasp.at/wiki/index.php?title=Category:INCAR&pagefrom=ML+FF+LCONF+DISCARD#mw-pages",
]:
r = requests.get(page, verify=False)
soup = BeautifulSoup(r.text)
for div in soup.findAll("div", {"class": "mw-category-group"}):
children = div.findChildren("li")
for child in children:
tags.append(child.text.strip())
return tags | [
"def",
"get_incar_tags",
"(",
"cls",
")",
":",
"tags",
"=",
"[",
"]",
"for",
"page",
"in",
"[",
"\"http://www.vasp.at/wiki/index.php/Category:INCAR\"",
",",
"\"http://www.vasp.at/wiki/index.php?title=Category:INCAR&pagefrom=ML+FF+LCONF+DISCARD#mw-pages\"",
",",
"]",
":",
"r",... | https://github.com/materialsproject/pymatgen/blob/8128f3062a334a2edd240e4062b5b9bdd1ae6f58/pymatgen/io/vasp/help.py#L69-L84 | |
KoreLogicSecurity/mastiff | 04d569e4fa59513572e77c74b049cad82f9b0310 | mastiff/plugins/__init__.py | python | encode_multipart_formdata | (fields, files) | return content_type, body | fields is a sequence of (name, value) elements for regular form fields.
files is a sequence of (name, filename, value) elements for data to be uploaded as files
Return (content_type, body) ready for httplib.HTTP instance | fields is a sequence of (name, value) elements for regular form fields.
files is a sequence of (name, filename, value) elements for data to be uploaded as files
Return (content_type, body) ready for httplib.HTTP instance | [
"fields",
"is",
"a",
"sequence",
"of",
"(",
"name",
"value",
")",
"elements",
"for",
"regular",
"form",
"fields",
".",
"files",
"is",
"a",
"sequence",
"of",
"(",
"name",
"filename",
"value",
")",
"elements",
"for",
"data",
"to",
"be",
"uploaded",
"as",
... | def encode_multipart_formdata(fields, files):
"""
fields is a sequence of (name, value) elements for regular form fields.
files is a sequence of (name, filename, value) elements for data to be uploaded as files
Return (content_type, body) ready for httplib.HTTP instance
"""
BOUNDARY = '----------MASTIFF_STATIC_ANALYSIS_FRAMEWORK$'
CRLF = '\r\n'
L = []
for (key, value) in fields:
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s"' % key)
L.append('')
L.append(value)
for (key, filename, value) in files:
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename))
L.append('Content-Type: %s' % get_content_type(filename))
L.append('')
L.append(value)
L.append('--' + BOUNDARY + '--')
L.append('')
body = CRLF.join(L)
content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
return content_type, body | [
"def",
"encode_multipart_formdata",
"(",
"fields",
",",
"files",
")",
":",
"BOUNDARY",
"=",
"'----------MASTIFF_STATIC_ANALYSIS_FRAMEWORK$'",
"CRLF",
"=",
"'\\r\\n'",
"L",
"=",
"[",
"]",
"for",
"(",
"key",
",",
"value",
")",
"in",
"fields",
":",
"L",
".",
"a... | https://github.com/KoreLogicSecurity/mastiff/blob/04d569e4fa59513572e77c74b049cad82f9b0310/mastiff/plugins/__init__.py#L49-L73 | |
khalim19/gimp-plugin-export-layers | b37255f2957ad322f4d332689052351cdea6e563 | export_layers/pygimplib/_lib/future/future/backports/email/iterators.py | python | body_line_iterator | (msg, decode=False) | Iterate over the parts, returning string payloads line-by-line.
Optional decode (default False) is passed through to .get_payload(). | Iterate over the parts, returning string payloads line-by-line. | [
"Iterate",
"over",
"the",
"parts",
"returning",
"string",
"payloads",
"line",
"-",
"by",
"-",
"line",
"."
] | def body_line_iterator(msg, decode=False):
"""Iterate over the parts, returning string payloads line-by-line.
Optional decode (default False) is passed through to .get_payload().
"""
for subpart in msg.walk():
payload = subpart.get_payload(decode=decode)
if isinstance(payload, str):
for line in StringIO(payload):
yield line | [
"def",
"body_line_iterator",
"(",
"msg",
",",
"decode",
"=",
"False",
")",
":",
"for",
"subpart",
"in",
"msg",
".",
"walk",
"(",
")",
":",
"payload",
"=",
"subpart",
".",
"get_payload",
"(",
"decode",
"=",
"decode",
")",
"if",
"isinstance",
"(",
"paylo... | https://github.com/khalim19/gimp-plugin-export-layers/blob/b37255f2957ad322f4d332689052351cdea6e563/export_layers/pygimplib/_lib/future/future/backports/email/iterators.py#L37-L46 | ||
cloudera/hue | 23f02102d4547c17c32bd5ea0eb24e9eadd657a4 | desktop/core/ext-py/protobuf-3.13.0/google/protobuf/internal/containers.py | python | RepeatedCompositeFieldContainer.__delitem__ | (self, key) | Deletes the item at the specified position. | Deletes the item at the specified position. | [
"Deletes",
"the",
"item",
"at",
"the",
"specified",
"position",
"."
] | def __delitem__(self, key):
"""Deletes the item at the specified position."""
del self._values[key]
self._message_listener.Modified() | [
"def",
"__delitem__",
"(",
"self",
",",
"key",
")",
":",
"del",
"self",
".",
"_values",
"[",
"key",
"]",
"self",
".",
"_message_listener",
".",
"Modified",
"(",
")"
] | https://github.com/cloudera/hue/blob/23f02102d4547c17c32bd5ea0eb24e9eadd657a4/desktop/core/ext-py/protobuf-3.13.0/google/protobuf/internal/containers.py#L438-L441 | ||
adamcaudill/EquationGroupLeak | 52fa871c89008566c27159bd48f2a8641260c984 | windows/fuzzbunch/fuzzbunch.py | python | Fuzzbunch.set_logdir | (self, log_dir=None) | Set the current log directory and create a new log file | Set the current log directory and create a new log file | [
"Set",
"the",
"current",
"log",
"directory",
"and",
"create",
"a",
"new",
"log",
"file"
] | def set_logdir(self, log_dir=None):
"""Set the current log directory and create a new log file"""
if not log_dir:
log_dir = os.path.normpath(self.default_logdir)
base_dir = self.get_basedir()
self.session.set_dirs(base_dir, log_dir)
logname = "fuzzbunch-%s.log" % util.formattime()
self.io.setlogfile(os.path.join(log_dir, logname)) | [
"def",
"set_logdir",
"(",
"self",
",",
"log_dir",
"=",
"None",
")",
":",
"if",
"not",
"log_dir",
":",
"log_dir",
"=",
"os",
".",
"path",
".",
"normpath",
"(",
"self",
".",
"default_logdir",
")",
"base_dir",
"=",
"self",
".",
"get_basedir",
"(",
")",
... | https://github.com/adamcaudill/EquationGroupLeak/blob/52fa871c89008566c27159bd48f2a8641260c984/windows/fuzzbunch/fuzzbunch.py#L133-L142 | ||
attardi/deepnl | e1ad450f2768a084f44b128de313f19c2f15100f | deepnl/utils.py | python | boundaries_to_arg_limits | (boundaries) | return np.array(limits, int) | Converts a sequence of IOBES tags delimiting arguments to an array
of argument boundaries, used by the network. | Converts a sequence of IOBES tags delimiting arguments to an array
of argument boundaries, used by the network. | [
"Converts",
"a",
"sequence",
"of",
"IOBES",
"tags",
"delimiting",
"arguments",
"to",
"an",
"array",
"of",
"argument",
"boundaries",
"used",
"by",
"the",
"network",
"."
] | def boundaries_to_arg_limits(boundaries):
"""
Converts a sequence of IOBES tags delimiting arguments to an array
of argument boundaries, used by the network.
"""
limits = []
start = None
for i, tag in enumerate(boundaries):
if tag == 'S':
limits.append([i, i])
elif tag == 'B':
start = i
elif tag == 'E':
limits.append([start, i])
return np.array(limits, int) | [
"def",
"boundaries_to_arg_limits",
"(",
"boundaries",
")",
":",
"limits",
"=",
"[",
"]",
"start",
"=",
"None",
"for",
"i",
",",
"tag",
"in",
"enumerate",
"(",
"boundaries",
")",
":",
"if",
"tag",
"==",
"'S'",
":",
"limits",
".",
"append",
"(",
"[",
"... | https://github.com/attardi/deepnl/blob/e1ad450f2768a084f44b128de313f19c2f15100f/deepnl/utils.py#L142-L158 | |
securesystemslab/zippy | ff0e84ac99442c2c55fe1d285332cfd4e185e089 | zippy/benchmarks/src/benchmarks/python-graph-bench.py | python | test_accessibility_on_very_deep_graph | () | [] | def test_accessibility_on_very_deep_graph():
gr = graph()
gr.add_nodes(range(0,311)) # 2001
for i in range(0,310): #2000
gr.add_edge((i,i+1))
recursionlimit = getrecursionlimit()
accessibility(gr)
assert getrecursionlimit() == recursionlimit | [
"def",
"test_accessibility_on_very_deep_graph",
"(",
")",
":",
"gr",
"=",
"graph",
"(",
")",
"gr",
".",
"add_nodes",
"(",
"range",
"(",
"0",
",",
"311",
")",
")",
"# 2001",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"310",
")",
":",
"#2000",
"gr",
"... | https://github.com/securesystemslab/zippy/blob/ff0e84ac99442c2c55fe1d285332cfd4e185e089/zippy/benchmarks/src/benchmarks/python-graph-bench.py#L16-L23 | ||||
pyjs/pyjs | 6c4a3d3a67300cd5df7f95a67ca9dcdc06950523 | pyjs/runners/imputil.py | python | _timestamp | (pathname) | return long(s.st_mtime) | Return the file modification time as a Long. | Return the file modification time as a Long. | [
"Return",
"the",
"file",
"modification",
"time",
"as",
"a",
"Long",
"."
] | def _timestamp(pathname):
"Return the file modification time as a Long."
try:
s = _os_stat(pathname)
except OSError:
return None
return long(s.st_mtime) | [
"def",
"_timestamp",
"(",
"pathname",
")",
":",
"try",
":",
"s",
"=",
"_os_stat",
"(",
"pathname",
")",
"except",
"OSError",
":",
"return",
"None",
"return",
"long",
"(",
"s",
".",
"st_mtime",
")"
] | https://github.com/pyjs/pyjs/blob/6c4a3d3a67300cd5df7f95a67ca9dcdc06950523/pyjs/runners/imputil.py#L524-L530 | |
shiweibsw/Translation-Tools | 2fbbf902364e557fa7017f9a74a8797b7440c077 | venv/Lib/site-packages/pip-9.0.3-py3.6.egg/pip/_vendor/cachecontrol/serialize.py | python | _b64_encode_str | (s) | return _b64_encode_bytes(s.encode("utf8")) | [] | def _b64_encode_str(s):
return _b64_encode_bytes(s.encode("utf8")) | [
"def",
"_b64_encode_str",
"(",
"s",
")",
":",
"return",
"_b64_encode_bytes",
"(",
"s",
".",
"encode",
"(",
"\"utf8\"",
")",
")"
] | https://github.com/shiweibsw/Translation-Tools/blob/2fbbf902364e557fa7017f9a74a8797b7440c077/venv/Lib/site-packages/pip-9.0.3-py3.6.egg/pip/_vendor/cachecontrol/serialize.py#L15-L16 | |||
sagemath/sage | f9b2db94f675ff16963ccdefba4f1a3393b3fe0d | src/sage/groups/perm_gps/symgp_conjugacy_class.py | python | SymmetricGroupConjugacyClassMixin.__init__ | (self, domain, part) | Initialize ``self``.
EXAMPLES::
sage: G = SymmetricGroup(5)
sage: g = G([(1,2), (3,4,5)])
sage: C = G.conjugacy_class(Partition([3,2]))
sage: type(C._part)
<class 'sage.combinat.partition.Partitions_n_with_category.element_class'> | Initialize ``self``. | [
"Initialize",
"self",
"."
] | def __init__(self, domain, part):
"""
Initialize ``self``.
EXAMPLES::
sage: G = SymmetricGroup(5)
sage: g = G([(1,2), (3,4,5)])
sage: C = G.conjugacy_class(Partition([3,2]))
sage: type(C._part)
<class 'sage.combinat.partition.Partitions_n_with_category.element_class'>
"""
P = Partitions_n(len(domain))
self._part = P(part)
self._domain = domain
self._set = None | [
"def",
"__init__",
"(",
"self",
",",
"domain",
",",
"part",
")",
":",
"P",
"=",
"Partitions_n",
"(",
"len",
"(",
"domain",
")",
")",
"self",
".",
"_part",
"=",
"P",
"(",
"part",
")",
"self",
".",
"_domain",
"=",
"domain",
"self",
".",
"_set",
"="... | https://github.com/sagemath/sage/blob/f9b2db94f675ff16963ccdefba4f1a3393b3fe0d/src/sage/groups/perm_gps/symgp_conjugacy_class.py#L23-L38 | ||
mlcommons/ck | 558a22c5970eb0d6708d0edc080e62a92566bab0 | incubator/cdatabase/cdatabase/crepo.py | python | cRepo.__init__ | (self, path: str) | Initialize cObject in a given path
Args:
path (str): Path to cDataBase | Initialize cObject in a given path | [
"Initialize",
"cObject",
"in",
"a",
"given",
"path"
] | def __init__(self, path: str):
"""
Initialize cObject in a given path
Args:
path (str): Path to cDataBase
"""
self.path = path | [
"def",
"__init__",
"(",
"self",
",",
"path",
":",
"str",
")",
":",
"self",
".",
"path",
"=",
"path"
] | https://github.com/mlcommons/ck/blob/558a22c5970eb0d6708d0edc080e62a92566bab0/incubator/cdatabase/cdatabase/crepo.py#L16-L25 | ||
phyllisstein/alp | cbc9e9fa2de19cfd72bc416b9c879b571dc92972 | alp/request/requests/packages/urllib3/packages/ordered_dict.py | python | OrderedDict.setdefault | (self, key, default=None) | return default | od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od | od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od | [
"od",
".",
"setdefault",
"(",
"k",
"[",
"d",
"]",
")",
"-",
">",
"od",
".",
"get",
"(",
"k",
"d",
")",
"also",
"set",
"od",
"[",
"k",
"]",
"=",
"d",
"if",
"k",
"not",
"in",
"od"
] | def setdefault(self, key, default=None):
'od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od'
if key in self:
return self[key]
self[key] = default
return default | [
"def",
"setdefault",
"(",
"self",
",",
"key",
",",
"default",
"=",
"None",
")",
":",
"if",
"key",
"in",
"self",
":",
"return",
"self",
"[",
"key",
"]",
"self",
"[",
"key",
"]",
"=",
"default",
"return",
"default"
] | https://github.com/phyllisstein/alp/blob/cbc9e9fa2de19cfd72bc416b9c879b571dc92972/alp/request/requests/packages/urllib3/packages/ordered_dict.py#L191-L196 | |
scikit-hep/awkward-0.x | dd885bef15814f588b58944d2505296df4aaae0e | awkward0/arrow.py | python | _ParquetFile._init | (self) | [] | def _init(self):
import pyarrow.parquet
self.parquetfile = pyarrow.parquet.ParquetFile(self.file, metadata=self.metadata, common_metadata=self.common_metadata)
self.type = schema2type(self.parquetfile.schema.to_arrow_schema()) | [
"def",
"_init",
"(",
"self",
")",
":",
"import",
"pyarrow",
".",
"parquet",
"self",
".",
"parquetfile",
"=",
"pyarrow",
".",
"parquet",
".",
"ParquetFile",
"(",
"self",
".",
"file",
",",
"metadata",
"=",
"self",
".",
"metadata",
",",
"common_metadata",
"... | https://github.com/scikit-hep/awkward-0.x/blob/dd885bef15814f588b58944d2505296df4aaae0e/awkward0/arrow.py#L532-L535 | ||||
facebookincubator/OnlineSchemaChange | a63f6973221ba82d07e327af701813bc8c9707ec | core/lib/payload/copy.py | python | CopyPayload.checksum_column_list | (self) | return column_list | A list of non-pk column name suitable for comparing checksum | A list of non-pk column name suitable for comparing checksum | [
"A",
"list",
"of",
"non",
"-",
"pk",
"column",
"name",
"suitable",
"for",
"comparing",
"checksum"
] | def checksum_column_list(self):
"""
A list of non-pk column name suitable for comparing checksum
"""
column_list = []
old_pk_name_list = [c.name for c in self._old_table.primary_key.column_list]
for col in self._old_table.column_list:
if col.name in old_pk_name_list:
continue
if col.name in self.dropped_column_name_list:
continue
new_columns = {col.name: col for col in self._new_table.column_list}
if col != new_columns[col.name]:
if self.skip_checksum_for_modified:
continue
column_list.append(col.name)
return column_list | [
"def",
"checksum_column_list",
"(",
"self",
")",
":",
"column_list",
"=",
"[",
"]",
"old_pk_name_list",
"=",
"[",
"c",
".",
"name",
"for",
"c",
"in",
"self",
".",
"_old_table",
".",
"primary_key",
".",
"column_list",
"]",
"for",
"col",
"in",
"self",
".",... | https://github.com/facebookincubator/OnlineSchemaChange/blob/a63f6973221ba82d07e327af701813bc8c9707ec/core/lib/payload/copy.py#L227-L243 | |
nipy/nibabel | 4703f4d8e32be4cec30e829c2d93ebe54759bb62 | nibabel/nifti1.py | python | Nifti1Header.get_qform | (self, coded=False) | return out | Return 4x4 affine matrix from qform parameters in header
Parameters
----------
coded : bool, optional
If True, return {affine or None}, and qform code. If False, just
return affine. {affine or None} means, return None if qform code
== 0, and affine otherwise.
Returns
-------
affine : None or (4,4) ndarray
If `coded` is False, always return affine reconstructed from qform
quaternion. If `coded` is True, return None if qform code is 0,
else return the affine.
code : int
Qform code. Only returned if `coded` is True. | Return 4x4 affine matrix from qform parameters in header | [
"Return",
"4x4",
"affine",
"matrix",
"from",
"qform",
"parameters",
"in",
"header"
] | def get_qform(self, coded=False):
""" Return 4x4 affine matrix from qform parameters in header
Parameters
----------
coded : bool, optional
If True, return {affine or None}, and qform code. If False, just
return affine. {affine or None} means, return None if qform code
== 0, and affine otherwise.
Returns
-------
affine : None or (4,4) ndarray
If `coded` is False, always return affine reconstructed from qform
quaternion. If `coded` is True, return None if qform code is 0,
else return the affine.
code : int
Qform code. Only returned if `coded` is True.
"""
hdr = self._structarr
code = int(hdr['qform_code'])
if code == 0 and coded:
return None, 0
quat = self.get_qform_quaternion()
R = quat2mat(quat)
vox = hdr['pixdim'][1:4].copy()
if np.any(vox < 0):
raise HeaderDataError('pixdims[1,2,3] should be positive')
qfac = hdr['pixdim'][0]
if qfac not in (-1, 1):
raise HeaderDataError('qfac (pixdim[0]) should be 1 or -1')
vox[-1] *= qfac
S = np.diag(vox)
M = np.dot(R, S)
out = np.eye(4)
out[0:3, 0:3] = M
out[0:3, 3] = [hdr['qoffset_x'], hdr['qoffset_y'], hdr['qoffset_z']]
if coded:
return out, code
return out | [
"def",
"get_qform",
"(",
"self",
",",
"coded",
"=",
"False",
")",
":",
"hdr",
"=",
"self",
".",
"_structarr",
"code",
"=",
"int",
"(",
"hdr",
"[",
"'qform_code'",
"]",
")",
"if",
"code",
"==",
"0",
"and",
"coded",
":",
"return",
"None",
",",
"0",
... | https://github.com/nipy/nibabel/blob/4703f4d8e32be4cec30e829c2d93ebe54759bb62/nibabel/nifti1.py#L892-L931 | |
maoschanz/drawing | d4a69258570c7a120817484eaadac1145dedb62d | src/tools/transform_tools/abstract_transform_tool.py | python | AbstractCanvasTool.temp_preview | (self, is_selection, local_dx, local_dy) | Part of the previewing methods shared by all transform tools. | Part of the previewing methods shared by all transform tools. | [
"Part",
"of",
"the",
"previewing",
"methods",
"shared",
"by",
"all",
"transform",
"tools",
"."
] | def temp_preview(self, is_selection, local_dx, local_dy):
"""Part of the previewing methods shared by all transform tools."""
pixbuf = self.get_image().temp_pixbuf
if is_selection:
cairo_context = self.get_context()
cairo_context.set_source_surface(self.get_surface(), 0, 0)
cairo_context.paint()
x = self.get_selection().selection_x + local_dx
y = self.get_selection().selection_y + local_dy
Gdk.cairo_set_source_pixbuf(cairo_context, pixbuf, x, y)
cairo_context.paint()
else:
cairo_context = self.get_context()
# widget_surface = cairo.ImageSurface(cairo.Format.ARGB32, w, h)
# cairo_context = cairo.Context(widget_surface)
# TODO concerning the scale(/crop)/rotate/skew preview ^
cairo_context.set_operator(cairo.Operator.SOURCE)
Gdk.cairo_set_source_pixbuf(cairo_context, pixbuf, 0, 0)
cairo_context.paint()
cairo_context.set_operator(cairo.Operator.OVER)
self.get_image().update() | [
"def",
"temp_preview",
"(",
"self",
",",
"is_selection",
",",
"local_dx",
",",
"local_dy",
")",
":",
"pixbuf",
"=",
"self",
".",
"get_image",
"(",
")",
".",
"temp_pixbuf",
"if",
"is_selection",
":",
"cairo_context",
"=",
"self",
".",
"get_context",
"(",
")... | https://github.com/maoschanz/drawing/blob/d4a69258570c7a120817484eaadac1145dedb62d/src/tools/transform_tools/abstract_transform_tool.py#L67-L87 | ||
CLUEbenchmark/CLUEPretrainedModels | b384fd41665a8261f9c689c940cf750b3bc21fce | baselines/models/bert/optimization.py | python | AdamWeightDecayOptimizer.__init__ | (self,
learning_rate,
weight_decay_rate=0.0,
beta_1=0.9,
beta_2=0.999,
epsilon=1e-6,
exclude_from_weight_decay=None,
name="AdamWeightDecayOptimizer") | Constructs a AdamWeightDecayOptimizer. | Constructs a AdamWeightDecayOptimizer. | [
"Constructs",
"a",
"AdamWeightDecayOptimizer",
"."
] | def __init__(self,
learning_rate,
weight_decay_rate=0.0,
beta_1=0.9,
beta_2=0.999,
epsilon=1e-6,
exclude_from_weight_decay=None,
name="AdamWeightDecayOptimizer"):
"""Constructs a AdamWeightDecayOptimizer."""
super(AdamWeightDecayOptimizer, self).__init__(False, name)
self.learning_rate = learning_rate
self.weight_decay_rate = weight_decay_rate
self.beta_1 = beta_1
self.beta_2 = beta_2
self.epsilon = epsilon
self.exclude_from_weight_decay = exclude_from_weight_decay | [
"def",
"__init__",
"(",
"self",
",",
"learning_rate",
",",
"weight_decay_rate",
"=",
"0.0",
",",
"beta_1",
"=",
"0.9",
",",
"beta_2",
"=",
"0.999",
",",
"epsilon",
"=",
"1e-6",
",",
"exclude_from_weight_decay",
"=",
"None",
",",
"name",
"=",
"\"AdamWeightDec... | https://github.com/CLUEbenchmark/CLUEPretrainedModels/blob/b384fd41665a8261f9c689c940cf750b3bc21fce/baselines/models/bert/optimization.py#L90-L106 | ||
pysathq/pysat | 07bf3a5a4428d40eca804e7ebdf4f496aadf4213 | pysat/_fileio.py | python | FileObject.close | (self) | Close a file pointer. | Close a file pointer. | [
"Close",
"a",
"file",
"pointer",
"."
] | def close(self):
"""
Close a file pointer.
"""
if self.fp:
self.fp.close()
self.fp = None
if self.fp_extra:
self.fp_extra.close()
self.fp_extra = None
self.ctype = None | [
"def",
"close",
"(",
"self",
")",
":",
"if",
"self",
".",
"fp",
":",
"self",
".",
"fp",
".",
"close",
"(",
")",
"self",
".",
"fp",
"=",
"None",
"if",
"self",
".",
"fp_extra",
":",
"self",
".",
"fp_extra",
".",
"close",
"(",
")",
"self",
".",
... | https://github.com/pysathq/pysat/blob/07bf3a5a4428d40eca804e7ebdf4f496aadf4213/pysat/_fileio.py#L147-L160 | ||
cloudera/hue | 23f02102d4547c17c32bd5ea0eb24e9eadd657a4 | desktop/core/ext-py/asn1crypto-0.24.0/asn1crypto/core.py | python | Boolean.set | (self, value) | Sets the value of the object
:param value:
True, False or another value that works with bool() | Sets the value of the object | [
"Sets",
"the",
"value",
"of",
"the",
"object"
] | def set(self, value):
"""
Sets the value of the object
:param value:
True, False or another value that works with bool()
"""
self._native = bool(value)
self.contents = b'\x00' if not value else b'\xff'
self._header = None
if self._trailer != b'':
self._trailer = b'' | [
"def",
"set",
"(",
"self",
",",
"value",
")",
":",
"self",
".",
"_native",
"=",
"bool",
"(",
"value",
")",
"self",
".",
"contents",
"=",
"b'\\x00'",
"if",
"not",
"value",
"else",
"b'\\xff'",
"self",
".",
"_header",
"=",
"None",
"if",
"self",
".",
"... | https://github.com/cloudera/hue/blob/23f02102d4547c17c32bd5ea0eb24e9eadd657a4/desktop/core/ext-py/asn1crypto-0.24.0/asn1crypto/core.py#L1783-L1795 | ||
Source-Python-Dev-Team/Source.Python | d0ffd8ccbd1e9923c9bc44936f20613c1c76b7fb | addons/source-python/packages/site-packages/sphinx/ext/autosummary/generate.py | python | find_autosummary_in_docstring | (name, module=None, filename=None) | return [] | Find out what items are documented in the given object's docstring.
See `find_autosummary_in_lines`. | Find out what items are documented in the given object's docstring. | [
"Find",
"out",
"what",
"items",
"are",
"documented",
"in",
"the",
"given",
"object",
"s",
"docstring",
"."
] | def find_autosummary_in_docstring(name, module=None, filename=None):
"""Find out what items are documented in the given object's docstring.
See `find_autosummary_in_lines`.
"""
try:
real_name, obj, parent, modname = import_by_name(name)
lines = pydoc.getdoc(obj).splitlines()
return find_autosummary_in_lines(lines, module=name, filename=filename)
except AttributeError:
pass
except ImportError as e:
print("Failed to import '%s': %s" % (name, e))
except SystemExit as e:
print("Failed to import '%s'; the module executes module level "
"statement and it might call sys.exit()." % name)
return [] | [
"def",
"find_autosummary_in_docstring",
"(",
"name",
",",
"module",
"=",
"None",
",",
"filename",
"=",
"None",
")",
":",
"try",
":",
"real_name",
",",
"obj",
",",
"parent",
",",
"modname",
"=",
"import_by_name",
"(",
"name",
")",
"lines",
"=",
"pydoc",
"... | https://github.com/Source-Python-Dev-Team/Source.Python/blob/d0ffd8ccbd1e9923c9bc44936f20613c1c76b7fb/addons/source-python/packages/site-packages/sphinx/ext/autosummary/generate.py#L232-L248 | |
inkandswitch/livebook | 93c8d467734787366ad084fc3566bf5cbe249c51 | public/pypyjs/modules/tarfile.py | python | TarFile.taropen | (cls, name, mode="r", fileobj=None, **kwargs) | return cls(name, mode, fileobj, **kwargs) | Open uncompressed tar archive name for reading or writing. | Open uncompressed tar archive name for reading or writing. | [
"Open",
"uncompressed",
"tar",
"archive",
"name",
"for",
"reading",
"or",
"writing",
"."
] | def taropen(cls, name, mode="r", fileobj=None, **kwargs):
"""Open uncompressed tar archive name for reading or writing.
"""
if mode not in ("r", "a", "w"):
raise ValueError("mode must be 'r', 'a' or 'w'")
return cls(name, mode, fileobj, **kwargs) | [
"def",
"taropen",
"(",
"cls",
",",
"name",
",",
"mode",
"=",
"\"r\"",
",",
"fileobj",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"mode",
"not",
"in",
"(",
"\"r\"",
",",
"\"a\"",
",",
"\"w\"",
")",
":",
"raise",
"ValueError",
"(",
"\"mo... | https://github.com/inkandswitch/livebook/blob/93c8d467734787366ad084fc3566bf5cbe249c51/public/pypyjs/modules/tarfile.py#L1709-L1714 | |
modin-project/modin | 0d9d14e6669be3dd6bb3b72222dbe6a6dffe1bee | modin/experimental/xgboost/xgboost_ray.py | python | create_actors | (num_actors) | return actors | Create ModinXGBoostActors.
Parameters
----------
num_actors : int
Number of actors to create.
Returns
-------
list
List of pairs (ip, actor). | Create ModinXGBoostActors. | [
"Create",
"ModinXGBoostActors",
"."
] | def create_actors(num_actors):
"""
Create ModinXGBoostActors.
Parameters
----------
num_actors : int
Number of actors to create.
Returns
-------
list
List of pairs (ip, actor).
"""
num_cpus_per_actor = _get_cpus_per_actor(num_actors)
node_ips = [
key for key in ray.cluster_resources().keys() if key.startswith("node:")
]
num_actors_per_node = num_actors // len(node_ips)
actors_ips = [ip for ip in node_ips for _ in range(num_actors_per_node)]
actors = [
(
node_ip.split("node:")[-1],
ModinXGBoostActor.options(resources={node_ip: 0.01}).remote(
i, nthread=num_cpus_per_actor
),
)
for i, node_ip in enumerate(actors_ips)
]
return actors | [
"def",
"create_actors",
"(",
"num_actors",
")",
":",
"num_cpus_per_actor",
"=",
"_get_cpus_per_actor",
"(",
"num_actors",
")",
"node_ips",
"=",
"[",
"key",
"for",
"key",
"in",
"ray",
".",
"cluster_resources",
"(",
")",
".",
"keys",
"(",
")",
"if",
"key",
"... | https://github.com/modin-project/modin/blob/0d9d14e6669be3dd6bb3b72222dbe6a6dffe1bee/modin/experimental/xgboost/xgboost_ray.py#L255-L285 | |
national-voter-file/national-voter-file | f8bae42418c9307150d10c9e71174defaefa4e60 | src/python/national_voter_file/transformers/base.py | python | BaseTransformer.extract_race | (self, input_dict) | Inputs:
input_dict: names of columns and corresponding values
Outputs:
Dictionary with following keys
'RACE' | Inputs:
input_dict: names of columns and corresponding values
Outputs:
Dictionary with following keys
'RACE' | [
"Inputs",
":",
"input_dict",
":",
"names",
"of",
"columns",
"and",
"corresponding",
"values",
"Outputs",
":",
"Dictionary",
"with",
"following",
"keys",
"RACE"
] | def extract_race(self, input_dict):
"""
Inputs:
input_dict: names of columns and corresponding values
Outputs:
Dictionary with following keys
'RACE'
"""
raise NotImplementedError('Must implement extract_race method') | [
"def",
"extract_race",
"(",
"self",
",",
"input_dict",
")",
":",
"raise",
"NotImplementedError",
"(",
"'Must implement extract_race method'",
")"
] | https://github.com/national-voter-file/national-voter-file/blob/f8bae42418c9307150d10c9e71174defaefa4e60/src/python/national_voter_file/transformers/base.py#L725-L733 | ||
apache/tvm | 6eb4ed813ebcdcd9558f0906a1870db8302ff1e0 | python/tvm/topi/cuda/conv2d.py | python | conv2d_nchw | (cfg, data, kernel, strides, padding, dilation, out_dtype="float32") | return nn.conv2d_nchw(data, kernel, strides, padding, dilation, out_dtype) | Compute conv2d with NCHW layout | Compute conv2d with NCHW layout | [
"Compute",
"conv2d",
"with",
"NCHW",
"layout"
] | def conv2d_nchw(cfg, data, kernel, strides, padding, dilation, out_dtype="float32"):
"""Compute conv2d with NCHW layout"""
return nn.conv2d_nchw(data, kernel, strides, padding, dilation, out_dtype) | [
"def",
"conv2d_nchw",
"(",
"cfg",
",",
"data",
",",
"kernel",
",",
"strides",
",",
"padding",
",",
"dilation",
",",
"out_dtype",
"=",
"\"float32\"",
")",
":",
"return",
"nn",
".",
"conv2d_nchw",
"(",
"data",
",",
"kernel",
",",
"strides",
",",
"padding",... | https://github.com/apache/tvm/blob/6eb4ed813ebcdcd9558f0906a1870db8302ff1e0/python/tvm/topi/cuda/conv2d.py#L31-L33 | |
aws-samples/aws-kube-codesuite | ab4e5ce45416b83bffb947ab8d234df5437f4fca | src/kubernetes/client/models/v2alpha1_horizontal_pod_autoscaler_spec.py | python | V2alpha1HorizontalPodAutoscalerSpec.metrics | (self) | return self._metrics | Gets the metrics of this V2alpha1HorizontalPodAutoscalerSpec.
metrics contains the specifications for which to use to calculate the desired replica count (the maximum replica count across all metrics will be used). The desired replica count is calculated multiplying the ratio between the target value and the current value by the current number of pods. Ergo, metrics used must decrease as the pod count is increased, and vice-versa. See the individual metric source types for more information about how each type of metric must respond.
:return: The metrics of this V2alpha1HorizontalPodAutoscalerSpec.
:rtype: list[V2alpha1MetricSpec] | Gets the metrics of this V2alpha1HorizontalPodAutoscalerSpec.
metrics contains the specifications for which to use to calculate the desired replica count (the maximum replica count across all metrics will be used). The desired replica count is calculated multiplying the ratio between the target value and the current value by the current number of pods. Ergo, metrics used must decrease as the pod count is increased, and vice-versa. See the individual metric source types for more information about how each type of metric must respond. | [
"Gets",
"the",
"metrics",
"of",
"this",
"V2alpha1HorizontalPodAutoscalerSpec",
".",
"metrics",
"contains",
"the",
"specifications",
"for",
"which",
"to",
"use",
"to",
"calculate",
"the",
"desired",
"replica",
"count",
"(",
"the",
"maximum",
"replica",
"count",
"ac... | def metrics(self):
"""
Gets the metrics of this V2alpha1HorizontalPodAutoscalerSpec.
metrics contains the specifications for which to use to calculate the desired replica count (the maximum replica count across all metrics will be used). The desired replica count is calculated multiplying the ratio between the target value and the current value by the current number of pods. Ergo, metrics used must decrease as the pod count is increased, and vice-versa. See the individual metric source types for more information about how each type of metric must respond.
:return: The metrics of this V2alpha1HorizontalPodAutoscalerSpec.
:rtype: list[V2alpha1MetricSpec]
"""
return self._metrics | [
"def",
"metrics",
"(",
"self",
")",
":",
"return",
"self",
".",
"_metrics"
] | https://github.com/aws-samples/aws-kube-codesuite/blob/ab4e5ce45416b83bffb947ab8d234df5437f4fca/src/kubernetes/client/models/v2alpha1_horizontal_pod_autoscaler_spec.py#L78-L86 | |
psychopy/psychopy | 01b674094f38d0e0bd51c45a6f66f671d7041696 | psychopy/tools/gltools.py | python | SimpleMaterial.diffuseRGB | (self) | return self._diffuseRGB[:3] | Diffuse color of the material. | Diffuse color of the material. | [
"Diffuse",
"color",
"of",
"the",
"material",
"."
] | def diffuseRGB(self):
"""Diffuse color of the material."""
return self._diffuseRGB[:3] | [
"def",
"diffuseRGB",
"(",
"self",
")",
":",
"return",
"self",
".",
"_diffuseRGB",
"[",
":",
"3",
"]"
] | https://github.com/psychopy/psychopy/blob/01b674094f38d0e0bd51c45a6f66f671d7041696/psychopy/tools/gltools.py#L3299-L3301 | |
futapi/fut | 3792c9eee8f5884f38a02210e649c46c6c7a756d | fut/core.py | python | baseId | (resource_id, return_version=False) | return resource_id | Calculate base id and version from a resource id.
:params resource_id: Resource id.
:params return_version: (optional) True if You need version, returns (resource_id, version). | Calculate base id and version from a resource id. | [
"Calculate",
"base",
"id",
"and",
"version",
"from",
"a",
"resource",
"id",
"."
] | def baseId(resource_id, return_version=False):
"""Calculate base id and version from a resource id.
:params resource_id: Resource id.
:params return_version: (optional) True if You need version, returns (resource_id, version).
"""
version = 0
resource_id = resource_id + 0xC4000000 # 3288334336
# TODO: version is broken due ^^, needs refactoring
while resource_id > 0x01000000: # 16777216
version += 1
if version == 1:
resource_id -= 0x80000000 # 2147483648 # 0x50000000 # 1342177280 ? || 0x2000000 # 33554432
elif version == 2:
resource_id -= 0x03000000 # 50331648
else:
resource_id -= 0x01000000 # 16777216
if return_version:
return resource_id, version - 67 # just correct "magic number"
return resource_id | [
"def",
"baseId",
"(",
"resource_id",
",",
"return_version",
"=",
"False",
")",
":",
"version",
"=",
"0",
"resource_id",
"=",
"resource_id",
"+",
"0xC4000000",
"# 3288334336",
"# TODO: version is broken due ^^, needs refactoring",
"while",
"resource_id",
">",
"0x01000000... | https://github.com/futapi/fut/blob/3792c9eee8f5884f38a02210e649c46c6c7a756d/fut/core.py#L52-L74 | |
cloudera/hue | 23f02102d4547c17c32bd5ea0eb24e9eadd657a4 | desktop/core/ext-py/pycryptodomex-3.9.7/lib/Cryptodome/Cipher/_mode_siv.py | python | SivMode.verify | (self, received_mac_tag) | Validate the *binary* MAC tag.
The caller invokes this function at the very end.
This method checks if the decrypted message is indeed valid
(that is, if the key is correct) and it has not been
tampered with while in transit.
:Parameters:
received_mac_tag : bytes/bytearray/memoryview
This is the *binary* MAC, as received from the sender.
:Raises ValueError:
if the MAC does not match. The message has been tampered with
or the key is incorrect. | Validate the *binary* MAC tag. | [
"Validate",
"the",
"*",
"binary",
"*",
"MAC",
"tag",
"."
] | def verify(self, received_mac_tag):
"""Validate the *binary* MAC tag.
The caller invokes this function at the very end.
This method checks if the decrypted message is indeed valid
(that is, if the key is correct) and it has not been
tampered with while in transit.
:Parameters:
received_mac_tag : bytes/bytearray/memoryview
This is the *binary* MAC, as received from the sender.
:Raises ValueError:
if the MAC does not match. The message has been tampered with
or the key is incorrect.
"""
if self.verify not in self._next:
raise TypeError("verify() cannot be called"
" when encrypting a message")
self._next = [self.verify]
if self._mac_tag is None:
self._mac_tag = self._kdf.derive()
secret = get_random_bytes(16)
mac1 = BLAKE2s.new(digest_bits=160, key=secret, data=self._mac_tag)
mac2 = BLAKE2s.new(digest_bits=160, key=secret, data=received_mac_tag)
if mac1.digest() != mac2.digest():
raise ValueError("MAC check failed") | [
"def",
"verify",
"(",
"self",
",",
"received_mac_tag",
")",
":",
"if",
"self",
".",
"verify",
"not",
"in",
"self",
".",
"_next",
":",
"raise",
"TypeError",
"(",
"\"verify() cannot be called\"",
"\" when encrypting a message\"",
")",
"self",
".",
"_next",
"=",
... | https://github.com/cloudera/hue/blob/23f02102d4547c17c32bd5ea0eb24e9eadd657a4/desktop/core/ext-py/pycryptodomex-3.9.7/lib/Cryptodome/Cipher/_mode_siv.py#L226-L257 | ||
daoluan/decode-Django | d46a858b45b56de48b0355f50dd9e45402d04cfd | Django-1.5.1/django/contrib/gis/gdal/feature.py | python | Feature.fields | (self) | return [capi.get_field_name(capi.get_field_defn(self._layer._ldefn, i))
for i in xrange(self.num_fields)] | Returns a list of fields in the Feature. | Returns a list of fields in the Feature. | [
"Returns",
"a",
"list",
"of",
"fields",
"in",
"the",
"Feature",
"."
] | def fields(self):
"Returns a list of fields in the Feature."
return [capi.get_field_name(capi.get_field_defn(self._layer._ldefn, i))
for i in xrange(self.num_fields)] | [
"def",
"fields",
"(",
"self",
")",
":",
"return",
"[",
"capi",
".",
"get_field_name",
"(",
"capi",
".",
"get_field_defn",
"(",
"self",
".",
"_layer",
".",
"_ldefn",
",",
"i",
")",
")",
"for",
"i",
"in",
"xrange",
"(",
"self",
".",
"num_fields",
")",
... | https://github.com/daoluan/decode-Django/blob/d46a858b45b56de48b0355f50dd9e45402d04cfd/Django-1.5.1/django/contrib/gis/gdal/feature.py#L92-L95 | |
robinhood/faust | 01b4c0ad8390221db71751d80001b0fd879291e2 | faust/types/settings/params.py | python | Param.on_set | (self, settings: Any, value: OT) | What happens when the setting is stored/set. | What happens when the setting is stored/set. | [
"What",
"happens",
"when",
"the",
"setting",
"is",
"stored",
"/",
"set",
"."
] | def on_set(self, settings: Any, value: OT) -> None:
"""What happens when the setting is stored/set."""
settings.__dict__[self.storage_name] = value
assert getattr(settings, self.storage_name) == value | [
"def",
"on_set",
"(",
"self",
",",
"settings",
":",
"Any",
",",
"value",
":",
"OT",
")",
"->",
"None",
":",
"settings",
".",
"__dict__",
"[",
"self",
".",
"storage_name",
"]",
"=",
"value",
"assert",
"getattr",
"(",
"settings",
",",
"self",
".",
"sto... | https://github.com/robinhood/faust/blob/01b4c0ad8390221db71751d80001b0fd879291e2/faust/types/settings/params.py#L390-L393 | ||
QData/TextAttack | 33c98738b84e88a46d9f01f17b85ec595863b43a | textattack/metrics/attack_metrics/attack_success_rate.py | python | AttackSuccessRate.calculate | (self, results) | return self.all_metrics | Calculates all metrics related to number of succesful, failed and
skipped results in an attack.
Args:
results (``AttackResult`` objects):
Attack results for each instance in dataset | Calculates all metrics related to number of succesful, failed and
skipped results in an attack. | [
"Calculates",
"all",
"metrics",
"related",
"to",
"number",
"of",
"succesful",
"failed",
"and",
"skipped",
"results",
"in",
"an",
"attack",
"."
] | def calculate(self, results):
"""Calculates all metrics related to number of succesful, failed and
skipped results in an attack.
Args:
results (``AttackResult`` objects):
Attack results for each instance in dataset
"""
self.results = results
self.total_attacks = len(self.results)
for i, result in enumerate(self.results):
if isinstance(result, FailedAttackResult):
self.failed_attacks += 1
continue
elif isinstance(result, SkippedAttackResult):
self.skipped_attacks += 1
continue
else:
self.successful_attacks += 1
# Calculated numbers
self.all_metrics["successful_attacks"] = self.successful_attacks
self.all_metrics["failed_attacks"] = self.failed_attacks
self.all_metrics["skipped_attacks"] = self.skipped_attacks
# Percentages wrt the calculations
self.all_metrics["original_accuracy"] = self.original_accuracy_perc()
self.all_metrics["attack_accuracy_perc"] = self.attack_accuracy_perc()
self.all_metrics["attack_success_rate"] = self.attack_success_rate_perc()
return self.all_metrics | [
"def",
"calculate",
"(",
"self",
",",
"results",
")",
":",
"self",
".",
"results",
"=",
"results",
"self",
".",
"total_attacks",
"=",
"len",
"(",
"self",
".",
"results",
")",
"for",
"i",
",",
"result",
"in",
"enumerate",
"(",
"self",
".",
"results",
... | https://github.com/QData/TextAttack/blob/33c98738b84e88a46d9f01f17b85ec595863b43a/textattack/metrics/attack_metrics/attack_success_rate.py#L20-L51 | |
fengsp/plan | 1f7b212e041599c4399dd2077c9d65b35ea5e260 | plan/output.py | python | Output.__init__ | (self, output=None) | [] | def __init__(self, output=None):
self.output = output | [
"def",
"__init__",
"(",
"self",
",",
"output",
"=",
"None",
")",
":",
"self",
".",
"output",
"=",
"output"
] | https://github.com/fengsp/plan/blob/1f7b212e041599c4399dd2077c9d65b35ea5e260/plan/output.py#L19-L20 | ||||
oracle/graalpython | 577e02da9755d916056184ec441c26e00b70145c | graalpython/lib-python/3/wsgiref/util.py | python | setup_testing_defaults | (environ) | Update 'environ' with trivial defaults for testing purposes
This adds various parameters required for WSGI, including HTTP_HOST,
SERVER_NAME, SERVER_PORT, REQUEST_METHOD, SCRIPT_NAME, PATH_INFO,
and all of the wsgi.* variables. It only supplies default values,
and does not replace any existing settings for these variables.
This routine is intended to make it easier for unit tests of WSGI
servers and applications to set up dummy environments. It should *not*
be used by actual WSGI servers or applications, since the data is fake! | Update 'environ' with trivial defaults for testing purposes | [
"Update",
"environ",
"with",
"trivial",
"defaults",
"for",
"testing",
"purposes"
] | def setup_testing_defaults(environ):
"""Update 'environ' with trivial defaults for testing purposes
This adds various parameters required for WSGI, including HTTP_HOST,
SERVER_NAME, SERVER_PORT, REQUEST_METHOD, SCRIPT_NAME, PATH_INFO,
and all of the wsgi.* variables. It only supplies default values,
and does not replace any existing settings for these variables.
This routine is intended to make it easier for unit tests of WSGI
servers and applications to set up dummy environments. It should *not*
be used by actual WSGI servers or applications, since the data is fake!
"""
environ.setdefault('SERVER_NAME','127.0.0.1')
environ.setdefault('SERVER_PROTOCOL','HTTP/1.0')
environ.setdefault('HTTP_HOST',environ['SERVER_NAME'])
environ.setdefault('REQUEST_METHOD','GET')
if 'SCRIPT_NAME' not in environ and 'PATH_INFO' not in environ:
environ.setdefault('SCRIPT_NAME','')
environ.setdefault('PATH_INFO','/')
environ.setdefault('wsgi.version', (1,0))
environ.setdefault('wsgi.run_once', 0)
environ.setdefault('wsgi.multithread', 0)
environ.setdefault('wsgi.multiprocess', 0)
from io import StringIO, BytesIO
environ.setdefault('wsgi.input', BytesIO())
environ.setdefault('wsgi.errors', StringIO())
environ.setdefault('wsgi.url_scheme',guess_scheme(environ))
if environ['wsgi.url_scheme']=='http':
environ.setdefault('SERVER_PORT', '80')
elif environ['wsgi.url_scheme']=='https':
environ.setdefault('SERVER_PORT', '443') | [
"def",
"setup_testing_defaults",
"(",
"environ",
")",
":",
"environ",
".",
"setdefault",
"(",
"'SERVER_NAME'",
",",
"'127.0.0.1'",
")",
"environ",
".",
"setdefault",
"(",
"'SERVER_PROTOCOL'",
",",
"'HTTP/1.0'",
")",
"environ",
".",
"setdefault",
"(",
"'HTTP_HOST'"... | https://github.com/oracle/graalpython/blob/577e02da9755d916056184ec441c26e00b70145c/graalpython/lib-python/3/wsgiref/util.py#L124-L160 | ||
ponyriders/django-amazon-price-monitor | c45d9f48a5bf429bfe696fcd9fc3f41f388bac2d | price_monitor/management/commands/price_monitor_search.py | python | Command.handle | (self, *args, **options) | Searches for a product with the given ASIN. | Searches for a product with the given ASIN. | [
"Searches",
"for",
"a",
"product",
"with",
"the",
"given",
"ASIN",
"."
] | def handle(self, *args, **options):
"""Searches for a product with the given ASIN."""
asins = options['asins']
api = ProductAdvertisingAPI()
pprint(api.item_lookup(asins), indent=4) | [
"def",
"handle",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"options",
")",
":",
"asins",
"=",
"options",
"[",
"'asins'",
"]",
"api",
"=",
"ProductAdvertisingAPI",
"(",
")",
"pprint",
"(",
"api",
".",
"item_lookup",
"(",
"asins",
")",
",",
"indent... | https://github.com/ponyriders/django-amazon-price-monitor/blob/c45d9f48a5bf429bfe696fcd9fc3f41f388bac2d/price_monitor/management/commands/price_monitor_search.py#L23-L27 | ||
cool-RR/python_toolbox | cb9ef64b48f1d03275484d707dc5079b6701ad0c | python_toolbox/wx_tools/widgets/third_party/hypertreelist.py | python | HyperTreeList.SetForegroundColour | (self, colour) | return self._main_win.SetForegroundColour(colour) | Changes the foreground colour of L{HyperTreeList}.
:param `colour`: the colour to be used as the foreground colour, pass
`wx.NullColour` to reset to the default colour.
:note: Overridden from `wx.PyControl`. | Changes the foreground colour of L{HyperTreeList}. | [
"Changes",
"the",
"foreground",
"colour",
"of",
"L",
"{",
"HyperTreeList",
"}",
"."
] | def SetForegroundColour(self, colour):
"""
Changes the foreground colour of L{HyperTreeList}.
:param `colour`: the colour to be used as the foreground colour, pass
`wx.NullColour` to reset to the default colour.
:note: Overridden from `wx.PyControl`.
"""
if not self._main_win:
return False
return self._main_win.SetForegroundColour(colour) | [
"def",
"SetForegroundColour",
"(",
"self",
",",
"colour",
")",
":",
"if",
"not",
"self",
".",
"_main_win",
":",
"return",
"False",
"return",
"self",
".",
"_main_win",
".",
"SetForegroundColour",
"(",
"colour",
")"
] | https://github.com/cool-RR/python_toolbox/blob/cb9ef64b48f1d03275484d707dc5079b6701ad0c/python_toolbox/wx_tools/widgets/third_party/hypertreelist.py#L4278-L4291 | |
holoviz/holoviews | cc6b27f01710402fdfee2aeef1507425ca78c91f | holoviews/element/stats.py | python | StatisticsElement.dframe | (self, dimensions=None, multi_index=False) | return super().dframe(dimensions, False) | Convert dimension values to DataFrame.
Returns a pandas dataframe of columns along each dimension,
either completely flat or indexed by key dimensions.
Args:
dimensions: Dimensions to return as columns
multi_index: Convert key dimensions to (multi-)index
Returns:
DataFrame of columns corresponding to each dimension | Convert dimension values to DataFrame. | [
"Convert",
"dimension",
"values",
"to",
"DataFrame",
"."
] | def dframe(self, dimensions=None, multi_index=False):
"""Convert dimension values to DataFrame.
Returns a pandas dataframe of columns along each dimension,
either completely flat or indexed by key dimensions.
Args:
dimensions: Dimensions to return as columns
multi_index: Convert key dimensions to (multi-)index
Returns:
DataFrame of columns corresponding to each dimension
"""
if dimensions:
dimensions = [self.get_dimension(d, strict=True) for d in dimensions]
else:
dimensions = self.kdims
vdims = [d for d in dimensions if d in self.vdims]
if vdims:
raise ValueError('%s element does not hold data for value '
'dimensions. Could not return data for %s '
'dimension(s).' %
(type(self).__name__, ', '.join([d.name for d in vdims])))
return super().dframe(dimensions, False) | [
"def",
"dframe",
"(",
"self",
",",
"dimensions",
"=",
"None",
",",
"multi_index",
"=",
"False",
")",
":",
"if",
"dimensions",
":",
"dimensions",
"=",
"[",
"self",
".",
"get_dimension",
"(",
"d",
",",
"strict",
"=",
"True",
")",
"for",
"d",
"in",
"dim... | https://github.com/holoviz/holoviews/blob/cc6b27f01710402fdfee2aeef1507425ca78c91f/holoviews/element/stats.py#L113-L136 | |
OpenEndedGroup/Field | 4f7c8edfb01bb0ccc927b78d3c500f018a4ae37c | Contents/lib/python/inspect.py | python | getclasstree | (classes, unique=0) | return walktree(roots, children, None) | Arrange the given list of classes into a hierarchy of nested lists.
Where a nested list appears, it contains classes derived from the class
whose entry immediately precedes the list. Each entry is a 2-tuple
containing a class and a tuple of its base classes. If the 'unique'
argument is true, exactly one entry appears in the returned structure
for each class in the given list. Otherwise, classes using multiple
inheritance and their descendants will appear multiple times. | Arrange the given list of classes into a hierarchy of nested lists. | [
"Arrange",
"the",
"given",
"list",
"of",
"classes",
"into",
"a",
"hierarchy",
"of",
"nested",
"lists",
"."
] | def getclasstree(classes, unique=0):
"""Arrange the given list of classes into a hierarchy of nested lists.
Where a nested list appears, it contains classes derived from the class
whose entry immediately precedes the list. Each entry is a 2-tuple
containing a class and a tuple of its base classes. If the 'unique'
argument is true, exactly one entry appears in the returned structure
for each class in the given list. Otherwise, classes using multiple
inheritance and their descendants will appear multiple times."""
children = {}
roots = []
for c in classes:
if c.__bases__:
for parent in c.__bases__:
if not parent in children:
children[parent] = []
children[parent].append(c)
if unique and parent in classes: break
elif c not in roots:
roots.append(c)
for parent in children:
if parent not in classes:
roots.append(parent)
return walktree(roots, children, None) | [
"def",
"getclasstree",
"(",
"classes",
",",
"unique",
"=",
"0",
")",
":",
"children",
"=",
"{",
"}",
"roots",
"=",
"[",
"]",
"for",
"c",
"in",
"classes",
":",
"if",
"c",
".",
"__bases__",
":",
"for",
"parent",
"in",
"c",
".",
"__bases__",
":",
"i... | https://github.com/OpenEndedGroup/Field/blob/4f7c8edfb01bb0ccc927b78d3c500f018a4ae37c/Contents/lib/python/inspect.py#L656-L679 | |
Runbook/runbook | 7b68622f75ef09f654046f0394540025f3ee7445 | src/monitors/checks/cloudflare-http-codes/cloudflare.py | python | del_rec | (email, key, zoneid, logger, recid) | Delete the specified DNS entry | Delete the specified DNS entry | [
"Delete",
"the",
"specified",
"DNS",
"entry"
] | def del_rec(email, key, zoneid, logger, recid):
''' Delete the specified DNS entry '''
headers = {
'X-Auth-Email' : email,
'X-Auth-Key' : key,
'Content-Type' : 'application/json'
}
url = "%s/zones/%s/dns_records/%s" % (baseurl, str(zoneid), str(recid))
try:
req = requests.delete(url=url, headers=headers)
return validate_response(req, logger)
except:
return False | [
"def",
"del_rec",
"(",
"email",
",",
"key",
",",
"zoneid",
",",
"logger",
",",
"recid",
")",
":",
"headers",
"=",
"{",
"'X-Auth-Email'",
":",
"email",
",",
"'X-Auth-Key'",
":",
"key",
",",
"'Content-Type'",
":",
"'application/json'",
"}",
"url",
"=",
"\"... | https://github.com/Runbook/runbook/blob/7b68622f75ef09f654046f0394540025f3ee7445/src/monitors/checks/cloudflare-http-codes/cloudflare.py#L140-L152 | ||
tensorflow/transform | bc5c3da6aebe9c8780da806e7e8103959c242863 | tensorflow_transform/tf_utils.py | python | _num_terms_and_factors | (num_samples, dtype) | return (current_samples, current_pairs, current_triplets, current_quadruplets,
l1_factors, l2_factors, l3_factors, l4_factors) | Computes counts and sample multipliers for the given number of samples.
Args:
num_samples: An integral type scalar `Tensor` containing the number of
samples used to compute the L-moments. This must be non-negative.
dtype: The dtype of the samples to process. This determines the output
`Tensor`s dtype.
Returns:
The tuple (current_samples, current_pairs, current_triplets,
current_quadruplets, l1_factors, l2_factors, l3_factors, l4_factors).
Entries are `Tensor`s with the given dtype containing counters for each
moment and the factors to use to compute the moments. | Computes counts and sample multipliers for the given number of samples. | [
"Computes",
"counts",
"and",
"sample",
"multipliers",
"for",
"the",
"given",
"number",
"of",
"samples",
"."
] | def _num_terms_and_factors(num_samples, dtype):
"""Computes counts and sample multipliers for the given number of samples.
Args:
num_samples: An integral type scalar `Tensor` containing the number of
samples used to compute the L-moments. This must be non-negative.
dtype: The dtype of the samples to process. This determines the output
`Tensor`s dtype.
Returns:
The tuple (current_samples, current_pairs, current_triplets,
current_quadruplets, l1_factors, l2_factors, l3_factors, l4_factors).
Entries are `Tensor`s with the given dtype containing counters for each
moment and the factors to use to compute the moments.
"""
has_pairs = tf.math.greater(num_samples, 1)
has_triplets = tf.math.greater(num_samples, 2)
has_quadruplets = tf.math.greater(num_samples, 3)
current_samples = tf.cast(num_samples, dtype=dtype)
current_pairs = tf.cast(
current_samples * (current_samples - 1.0) / 2.0, dtype=dtype)
current_triplets = tf.cast(
current_pairs * (current_samples - 2.0) / 3.0, dtype=dtype)
current_quadruplets = tf.cast(
current_triplets * (current_samples - 3.0) / 4.0, dtype=dtype)
term_up = tf.range(0, current_samples, 1, dtype=dtype)
term_up_delay_1 = tf.range(-1, current_samples - 1, 1, dtype=dtype)
term_up_delay_2 = tf.range(-2, current_samples - 2, 1, dtype=dtype)
term_down = tf.range(current_samples - 1, -1, -1, dtype=dtype)
term_down_delay_1 = tf.range(current_samples - 2, -2, -1, dtype=dtype)
term_down_delay_2 = tf.range(current_samples - 3, -3, -1, dtype=dtype)
l1_denominator = tf.cond(tf.math.greater(num_samples, 0),
lambda: current_samples,
lambda: tf.constant(1, dtype))
l1_factors = tf.ones([num_samples], dtype=dtype) / l1_denominator
l2_denominator = tf.cond(has_pairs,
lambda: tf.cast(current_pairs * 2.0, dtype=dtype),
lambda: tf.constant(1, dtype))
l2_factors = (term_up - term_down) / l2_denominator
l3_denominator = tf.cond(has_triplets,
lambda: tf.cast(current_triplets * 6, dtype=dtype),
lambda: tf.constant(1, dtype))
l3_factors = ((term_up * term_up_delay_1 - 4.0 * term_up * term_down +
term_down * term_down_delay_1) / l3_denominator)
l4_denominator = tf.cond(
has_quadruplets,
lambda: tf.cast(current_quadruplets * 24, dtype=dtype),
lambda: tf.constant(1, dtype))
l4_factors = ((term_up * term_up_delay_1 * term_up_delay_2 -
9.0 * term_up * term_up_delay_1 * term_down +
9.0 * term_up * term_down * term_down_delay_1 -
term_down * term_down_delay_1 * term_down_delay_2) /
l4_denominator)
return (current_samples, current_pairs, current_triplets, current_quadruplets,
l1_factors, l2_factors, l3_factors, l4_factors) | [
"def",
"_num_terms_and_factors",
"(",
"num_samples",
",",
"dtype",
")",
":",
"has_pairs",
"=",
"tf",
".",
"math",
".",
"greater",
"(",
"num_samples",
",",
"1",
")",
"has_triplets",
"=",
"tf",
".",
"math",
".",
"greater",
"(",
"num_samples",
",",
"2",
")"... | https://github.com/tensorflow/transform/blob/bc5c3da6aebe9c8780da806e7e8103959c242863/tensorflow_transform/tf_utils.py#L798-L855 | |
google/deepvariant | 9cf1c7b0e2342d013180aa153cba3c9331c9aef7 | deepvariant/variant_caller.py | python | VariantCaller.make_gvcfs | (self, allele_count_summaries, include_med_dp=False) | Primary interface function for computing gVCF confidence at a site.
Looks at the counts in the provided list of AlleleCountSummary protos and
returns properly-formatted Variant protos containing gVCF reference
blocks for all sites in allele_count_summaries. The returned Variant has
reference_name, start, end are set and contains a single VariantCall in the
calls field with call_set_name of options.sample_name, genotypes set to 0/0
(diploid reference), a GQ value bound in the info field appropriate to the
data in allele_count, and a MIN_DP value which is the minimum read coverage
seen in the block.
The provided allele count must have either a canonical DNA sequence base (
A, C, G, T) or be "N".
Args:
allele_count_summaries: iterable of AlleleCountSummary protos in
coordinate-sorted order. Each proto is used to get the read counts for
reference and alternate alleles, the reference position, and reference
base.
include_med_dp: boolean. If True, in the gVCF records, we will include
MED_DP.
Yields:
third_party.nucleus.protos.Variant proto in
coordinate-sorted order containing gVCF records. | Primary interface function for computing gVCF confidence at a site. | [
"Primary",
"interface",
"function",
"for",
"computing",
"gVCF",
"confidence",
"at",
"a",
"site",
"."
] | def make_gvcfs(self, allele_count_summaries, include_med_dp=False):
"""Primary interface function for computing gVCF confidence at a site.
Looks at the counts in the provided list of AlleleCountSummary protos and
returns properly-formatted Variant protos containing gVCF reference
blocks for all sites in allele_count_summaries. The returned Variant has
reference_name, start, end are set and contains a single VariantCall in the
calls field with call_set_name of options.sample_name, genotypes set to 0/0
(diploid reference), a GQ value bound in the info field appropriate to the
data in allele_count, and a MIN_DP value which is the minimum read coverage
seen in the block.
The provided allele count must have either a canonical DNA sequence base (
A, C, G, T) or be "N".
Args:
allele_count_summaries: iterable of AlleleCountSummary protos in
coordinate-sorted order. Each proto is used to get the read counts for
reference and alternate alleles, the reference position, and reference
base.
include_med_dp: boolean. If True, in the gVCF records, we will include
MED_DP.
Yields:
third_party.nucleus.protos.Variant proto in
coordinate-sorted order containing gVCF records.
"""
def with_gq_and_likelihoods(summary_counts):
"""Returns summary_counts along with GQ and genotype likelihoods.
If the reference base is not in CANONICAL_DNA_BASES, both GQ and genotype
likelihoods are set to None.
Args:
summary_counts: A single AlleleCountSummary.
Returns:
A tuple of summary_counts, quantized GQ, raw GQ, and genotype
likelihoods for summary_counts where raw GQ and genotype_likelihood are
calculated by self.reference_confidence.
Raises:
ValueError: The reference base is not a valid DNA or IUPAC base.
"""
if summary_counts.ref_base not in CANONICAL_DNA_BASES:
if summary_counts.ref_base in EXTENDED_IUPAC_CODES:
# Skip calculating gq and likelihoods, since this is an ambiguous
# reference base.
quantized_gq, raw_gq, likelihoods = None, None, None
has_valid_gl = True
n_total = summary_counts.total_read_count
else:
raise ValueError('Invalid reference base={} found during gvcf '
'calculation'.format(summary_counts.ref_base))
else:
n_ref = summary_counts.ref_supporting_read_count
n_total = summary_counts.total_read_count
raw_gq, likelihoods = self.reference_confidence(n_ref, n_total)
quantized_gq = _quantize_gq(raw_gq, self.options.gq_resolution)
has_valid_gl = (np.amax(likelihoods) == likelihoods[0])
return _GVCF(
summary_counts=summary_counts,
quantized_gq=quantized_gq,
raw_gq=raw_gq,
likelihoods=likelihoods,
read_depth=n_total,
has_valid_gl=has_valid_gl)
# Combines contiguous, compatible single-bp blocks into larger gVCF blocks,
# respecting non-reference variants interspersed among them. Yields each
# combined gVCF Variant proto, in order. Compatible right now means that the
# blocks to be merged have the same non-None GQ value.
for key, combinable in itertools.groupby(
(with_gq_and_likelihoods(sc) for sc in allele_count_summaries),
key=operator.attrgetter('quantized_gq', 'has_valid_gl')):
quantized_gq_val, gl_is_valid = key
if quantized_gq_val is None:
# A None key indicates that a non-DNA reference base was encountered, so
# skip this group.
continue
if gl_is_valid:
combinable = list(combinable)
min_gq = min(elt.raw_gq for elt in combinable)
min_dp = min(elt.read_depth for elt in combinable)
med_dp = int(statistics.median(elt.read_depth for elt in combinable))
first_record, last_record = combinable[0], combinable[-1]
call = variants_pb2.VariantCall(
call_set_name=self.options.sample_name,
genotype=[0, 0],
genotype_likelihood=first_record.likelihoods)
variantcall_utils.set_gq(call, min_gq)
variantcall_utils.set_min_dp(call, min_dp)
if include_med_dp:
variantcall_utils.set_med_dp(call, med_dp)
yield variants_pb2.Variant(
reference_name=first_record.summary_counts.reference_name,
reference_bases=first_record.summary_counts.ref_base,
alternate_bases=[vcf_constants.GVCF_ALT_ALLELE],
start=first_record.summary_counts.position,
end=last_record.summary_counts.position + 1,
calls=[call])
else:
# After evaluating the effect of including sites with contradictory GL
# (where the value for hom_ref is not maximal), we concluded that
# un-calling these sites (by setting its genotype "./.") is better
# for cohort merging.
# See internal for detail.
for elt in combinable:
uncalled_gt = [-1, -1]
call = variants_pb2.VariantCall(
call_set_name=self.options.sample_name,
genotype=uncalled_gt,
genotype_likelihood=elt.likelihoods)
variantcall_utils.set_gq(call, elt.raw_gq)
variantcall_utils.set_min_dp(call, elt.read_depth)
if include_med_dp:
variantcall_utils.set_med_dp(call, elt.read_depth)
yield variants_pb2.Variant(
reference_name=elt.summary_counts.reference_name,
reference_bases=elt.summary_counts.ref_base,
alternate_bases=[vcf_constants.GVCF_ALT_ALLELE],
start=elt.summary_counts.position,
end=elt.summary_counts.position + 1,
calls=[call]) | [
"def",
"make_gvcfs",
"(",
"self",
",",
"allele_count_summaries",
",",
"include_med_dp",
"=",
"False",
")",
":",
"def",
"with_gq_and_likelihoods",
"(",
"summary_counts",
")",
":",
"\"\"\"Returns summary_counts along with GQ and genotype likelihoods.\n\n If the reference base ... | https://github.com/google/deepvariant/blob/9cf1c7b0e2342d013180aa153cba3c9331c9aef7/deepvariant/variant_caller.py#L221-L346 | ||
openstack/sahara | c4f4d29847d5bcca83d49ef7e9a3378458462a79 | sahara/service/trusts.py | python | delete_trust | (trustee, trust_id) | Delete a trust from a trustee
:param trustee: The user to delete the trust from, this is an auth plugin.
:param trust_id: The identifier of the trust to delete.
:raises DeletionFailed: If the trust cannot be deleted. | Delete a trust from a trustee | [
"Delete",
"a",
"trust",
"from",
"a",
"trustee"
] | def delete_trust(trustee, trust_id):
'''Delete a trust from a trustee
:param trustee: The user to delete the trust from, this is an auth plugin.
:param trust_id: The identifier of the trust to delete.
:raises DeletionFailed: If the trust cannot be deleted.
'''
try:
client = keystone.client_from_auth(trustee)
client.trusts.delete(trust_id)
LOG.debug('Deleted trust {trust_id}'.format(
trust_id=six.text_type(trust_id)))
except Exception as e:
LOG.error('Unable to delete trust (reason: {reason})'.format(reason=e))
raise ex.DeletionFailed(
_('Failed to delete trust {0}').format(trust_id)) | [
"def",
"delete_trust",
"(",
"trustee",
",",
"trust_id",
")",
":",
"try",
":",
"client",
"=",
"keystone",
".",
"client_from_auth",
"(",
"trustee",
")",
"client",
".",
"trusts",
".",
"delete",
"(",
"trust_id",
")",
"LOG",
".",
"debug",
"(",
"'Deleted trust {... | https://github.com/openstack/sahara/blob/c4f4d29847d5bcca83d49ef7e9a3378458462a79/sahara/service/trusts.py#L102-L120 | ||
kupferlauncher/kupfer | 1c1e9bcbce05a82f503f68f8b3955c20b02639b3 | kupfer/plugin/tracker1.py | python | sparql_escape | (ustr) | return ustr.translate(sparql_escape_table) | Escape unicode string @ustr for insertion into a SPARQL query
Implemented to behave like tracker_sparql_escape in libtracker-client | Escape unicode string @ustr for insertion into a SPARQL query | [
"Escape",
"unicode",
"string",
"@ustr",
"for",
"insertion",
"into",
"a",
"SPARQL",
"query"
] | def sparql_escape(ustr):
"""Escape unicode string @ustr for insertion into a SPARQL query
Implemented to behave like tracker_sparql_escape in libtracker-client
"""
sparql_escape_table = {
ord('\t'): r'\t',
ord('\n'): r'\n',
ord('\r'): r'\r',
ord('\b'): r'\b',
ord('\f'): r'\f',
ord('"') : r'\"',
ord('\\'): '\\\\',
# Extra rule: Can't have ?
ord("?") : "",
}
return ustr.translate(sparql_escape_table) | [
"def",
"sparql_escape",
"(",
"ustr",
")",
":",
"sparql_escape_table",
"=",
"{",
"ord",
"(",
"'\\t'",
")",
":",
"r'\\t'",
",",
"ord",
"(",
"'\\n'",
")",
":",
"r'\\n'",
",",
"ord",
"(",
"'\\r'",
")",
":",
"r'\\r'",
",",
"ord",
"(",
"'\\b'",
")",
":",... | https://github.com/kupferlauncher/kupfer/blob/1c1e9bcbce05a82f503f68f8b3955c20b02639b3/kupfer/plugin/tracker1.py#L93-L109 | |
robotlearn/pyrobolearn | 9cd7c060723fda7d2779fa255ac998c2c82b8436 | pyrobolearn/simulators/middlewares/ros.py | python | ROS.get_joint_torques | (self, body_id, joint_ids) | Get the applied torque(s) on the given joint(s). "This is the motor torque applied during the last `step`.
Note that this only applies in VELOCITY_CONTROL and POSITION_CONTROL. If you use TORQUE_CONTROL then the
applied joint motor torque is exactly what you provide, so there is no need to report it separately." [1]
Args:
body_id (int): unique body id.
joint_ids (int, list[int]): a joint id, or list of joint ids.
Returns:
if 1 joint:
float: torque [Nm]
if multiple joints:
np.array[float[N]]: torques associated to the given joints [Nm] | Get the applied torque(s) on the given joint(s). "This is the motor torque applied during the last `step`.
Note that this only applies in VELOCITY_CONTROL and POSITION_CONTROL. If you use TORQUE_CONTROL then the
applied joint motor torque is exactly what you provide, so there is no need to report it separately." [1] | [
"Get",
"the",
"applied",
"torque",
"(",
"s",
")",
"on",
"the",
"given",
"joint",
"(",
"s",
")",
".",
"This",
"is",
"the",
"motor",
"torque",
"applied",
"during",
"the",
"last",
"step",
".",
"Note",
"that",
"this",
"only",
"applies",
"in",
"VELOCITY_CON... | def get_joint_torques(self, body_id, joint_ids):
"""
Get the applied torque(s) on the given joint(s). "This is the motor torque applied during the last `step`.
Note that this only applies in VELOCITY_CONTROL and POSITION_CONTROL. If you use TORQUE_CONTROL then the
applied joint motor torque is exactly what you provide, so there is no need to report it separately." [1]
Args:
body_id (int): unique body id.
joint_ids (int, list[int]): a joint id, or list of joint ids.
Returns:
if 1 joint:
float: torque [Nm]
if multiple joints:
np.array[float[N]]: torques associated to the given joints [Nm]
"""
robot = self._robots.get(body_id)
if robot is not None:
return robot.get_joint_torques(joint_ids) | [
"def",
"get_joint_torques",
"(",
"self",
",",
"body_id",
",",
"joint_ids",
")",
":",
"robot",
"=",
"self",
".",
"_robots",
".",
"get",
"(",
"body_id",
")",
"if",
"robot",
"is",
"not",
"None",
":",
"return",
"robot",
".",
"get_joint_torques",
"(",
"joint_... | https://github.com/robotlearn/pyrobolearn/blob/9cd7c060723fda7d2779fa255ac998c2c82b8436/pyrobolearn/simulators/middlewares/ros.py#L1518-L1536 | ||
ucas-vg/TinyBenchmark | bf6b83aa9a149ae15087eed4e9a7283f5cc67603 | tiny_benchmark/maskrcnn_benchmark/modeling/rpn/inference.py | python | RPNPostProcessor.forward | (self, anchors, objectness, box_regression, targets=None) | return boxlists | Arguments:
anchors: list[list[BoxList]]
objectness: list[tensor]
box_regression: list[tensor]
Returns:
boxlists (list[BoxList]): the post-processed anchors, after
applying box decoding and NMS | Arguments:
anchors: list[list[BoxList]]
objectness: list[tensor]
box_regression: list[tensor] | [
"Arguments",
":",
"anchors",
":",
"list",
"[",
"list",
"[",
"BoxList",
"]]",
"objectness",
":",
"list",
"[",
"tensor",
"]",
"box_regression",
":",
"list",
"[",
"tensor",
"]"
] | def forward(self, anchors, objectness, box_regression, targets=None):
"""
Arguments:
anchors: list[list[BoxList]]
objectness: list[tensor]
box_regression: list[tensor]
Returns:
boxlists (list[BoxList]): the post-processed anchors, after
applying box decoding and NMS
"""
sampled_boxes = []
num_levels = len(objectness)
anchors = list(zip(*anchors))
for a, o, b in zip(anchors, objectness, box_regression):
sampled_boxes.append(self.forward_for_single_feature_map(a, o, b))
boxlists = list(zip(*sampled_boxes))
boxlists = [cat_boxlist(boxlist) for boxlist in boxlists]
if num_levels > 1:
boxlists = self.select_over_all_levels(boxlists)
# append ground-truth bboxes to proposals
if self.training and targets is not None:
boxlists = self.add_gt_proposals(boxlists, targets)
return boxlists | [
"def",
"forward",
"(",
"self",
",",
"anchors",
",",
"objectness",
",",
"box_regression",
",",
"targets",
"=",
"None",
")",
":",
"sampled_boxes",
"=",
"[",
"]",
"num_levels",
"=",
"len",
"(",
"objectness",
")",
"anchors",
"=",
"list",
"(",
"zip",
"(",
"... | https://github.com/ucas-vg/TinyBenchmark/blob/bf6b83aa9a149ae15087eed4e9a7283f5cc67603/tiny_benchmark/maskrcnn_benchmark/modeling/rpn/inference.py#L127-L154 | |
overviewer/Minecraft-Overviewer | 7171af587399fee9140eb83fb9b066acd251f57a | overviewer_core/world.py | python | RegionSet.get_chunk | (self, x, z) | return chunk_data | Returns a dictionary object representing the "Level" NBT Compound
structure for a chunk given its x, z coordinates. The coordinates given
are chunk coordinates. Raises ChunkDoesntExist exception if the given
chunk does not exist.
The returned dictionary corresponds to the "Level" structure in the
chunk file, with a few changes:
* The Biomes array is transformed into a 16x16 numpy array
* For each chunk section:
* The "Blocks" byte string is transformed into a 16x16x16 numpy array
* The Add array, if it exists, is bitshifted left 8 bits and
added into the Blocks array
* The "SkyLight" byte string is transformed into a 16x16x128 numpy
array
* The "BlockLight" byte string is transformed into a 16x16x128 numpy
array
* The "Data" byte string is transformed into a 16x16x128 numpy array
Warning: the returned data may be cached and thus should not be
modified, lest it affect the return values of future calls for the same
chunk. | Returns a dictionary object representing the "Level" NBT Compound
structure for a chunk given its x, z coordinates. The coordinates given
are chunk coordinates. Raises ChunkDoesntExist exception if the given
chunk does not exist. | [
"Returns",
"a",
"dictionary",
"object",
"representing",
"the",
"Level",
"NBT",
"Compound",
"structure",
"for",
"a",
"chunk",
"given",
"its",
"x",
"z",
"coordinates",
".",
"The",
"coordinates",
"given",
"are",
"chunk",
"coordinates",
".",
"Raises",
"ChunkDoesntEx... | def get_chunk(self, x, z):
"""Returns a dictionary object representing the "Level" NBT Compound
structure for a chunk given its x, z coordinates. The coordinates given
are chunk coordinates. Raises ChunkDoesntExist exception if the given
chunk does not exist.
The returned dictionary corresponds to the "Level" structure in the
chunk file, with a few changes:
* The Biomes array is transformed into a 16x16 numpy array
* For each chunk section:
* The "Blocks" byte string is transformed into a 16x16x16 numpy array
* The Add array, if it exists, is bitshifted left 8 bits and
added into the Blocks array
* The "SkyLight" byte string is transformed into a 16x16x128 numpy
array
* The "BlockLight" byte string is transformed into a 16x16x128 numpy
array
* The "Data" byte string is transformed into a 16x16x128 numpy array
Warning: the returned data may be cached and thus should not be
modified, lest it affect the return values of future calls for the same
chunk.
"""
regionfile = self._get_region_path(x, z)
if regionfile is None:
raise ChunkDoesntExist("Chunk %s,%s doesn't exist (and neither does its region)" % (x,z))
# Try a few times to load and parse this chunk before giving up and
# raising an error
tries = 5
while True:
try:
region = self._get_regionobj(regionfile)
data = region.load_chunk(x, z)
except nbt.CorruptionError as e:
tries -= 1
if tries > 0:
# Flush the region cache to possibly read a new region file header
logging.debug("Encountered a corrupt chunk or read error at %s,%s. "
"Flushing cache and retrying", x, z)
del self.regioncache[regionfile]
time.sleep(0.25)
continue
else:
logging.warning("The following was encountered while reading from %s:", self.regiondir)
if isinstance(e, nbt.CorruptRegionError):
logging.warning("Tried several times to read chunk %d,%d. Its region (%d,%d) may be corrupt. Giving up.",
x, z,x//32,z//32)
elif isinstance(e, nbt.CorruptChunkError):
logging.warning("Tried several times to read chunk %d,%d. It may be corrupt. Giving up.",
x, z)
else:
logging.warning("Tried several times to read chunk %d,%d. Unknown error. Giving up.",
x, z)
logging.debug("Full traceback:", exc_info=1)
# Let this exception propagate out through the C code into
# tileset.py, where it is caught and gracefully continues
# with the next chunk
raise
else:
# no exception raised: break out of the loop
break
if data is None:
raise ChunkDoesntExist("Chunk %s,%s doesn't exist" % (x,z))
chunk_data = data[1]
if not 'sections' in chunk_data:
# This world was generated pre 21w43a and thus most chunk data is contained
# in the "Level" key
chunk_data = chunk_data['Level']
else:
# This world was generated post 21w43a
chunk_data['Sections'] = chunk_data['sections']
longarray_unpacker = self._packed_longarray_to_shorts
if data[1].get('DataVersion', 0) >= 2529:
# starting with 1.16 snapshot 20w17a, block states are packed differently
longarray_unpacker = self._packed_longarray_to_shorts_v116
# From the interior of a map to the edge, a chunk's status may be one of:
# - postprocessed (interior, or next to fullchunk)
# - fullchunk (next to decorated)
# - decorated (next to liquid_carved)
# - liquid_carved (next to carved)
# - carved (edge of world)
# - empty
# Empty is self-explanatory, and liquid_carved and carved seem to correspond
# to SkyLight not being calculated, which results in mostly-black chunks,
# so we'll just pretend they aren't there.
if chunk_data.get("Status", "") not in ("full", "postprocessed", "fullchunk",
"mobs_spawned", "spawn", ""):
raise ChunkDoesntExist("Chunk %s,%s doesn't exist" % (x,z))
# Turn the Biomes array into a 16x16 numpy array
if 'Biomes' in chunk_data and len(chunk_data['Biomes']) > 0:
biomes = chunk_data['Biomes']
if isinstance(biomes, bytes):
biomes = numpy.frombuffer(biomes, dtype=numpy.uint8)
else:
biomes = numpy.asarray(biomes)
biomes = reshape_biome_data(biomes)
else:
# Worlds converted by Jeb's program may be missing the Biomes key.
# Additionally, 19w09a worlds have an empty array as biomes key
# in some cases.
# TODO: Implement paletted biomes for >21w39a
biomes = numpy.zeros((16, 16), dtype=numpy.uint8)
chunk_data['Biomes'] = biomes
chunk_data['NewBiomes'] = (len(biomes.shape) == 3)
unrecognized_block_types = {}
for section in chunk_data['Sections']:
# Turn the skylight array into a 16x16x16 matrix. The array comes
# packed 2 elements per byte, so we need to expand it.
try:
# Sometimes, Minecraft loves generating chunks with no light info.
# These mostly appear to have those two properties, and in this case
# we default to full-bright as it's less jarring to look at than all-black.
if chunk_data.get("Status", "") == "spawn" and 'Lights' in chunk_data:
section['SkyLight'] = numpy.full((16,16,16), 255, dtype=numpy.uint8)
else:
if 'SkyLight' in section:
skylight = numpy.frombuffer(section['SkyLight'], dtype=numpy.uint8)
skylight = skylight.reshape((16,16,8))
else: # Special case introduced with 1.14
skylight = numpy.zeros((16,16,8), dtype=numpy.uint8)
skylight_expanded = numpy.empty((16,16,16), dtype=numpy.uint8)
skylight_expanded[:,:,::2] = skylight & 0x0F
skylight_expanded[:,:,1::2] = (skylight & 0xF0) >> 4
del skylight
section['SkyLight'] = skylight_expanded
# Turn the BlockLight array into a 16x16x16 matrix, same as SkyLight
if 'BlockLight' in section:
blocklight = numpy.frombuffer(section['BlockLight'], dtype=numpy.uint8)
blocklight = blocklight.reshape((16,16,8))
else: # Special case introduced with 1.14
blocklight = numpy.zeros((16,16,8), dtype=numpy.uint8)
blocklight_expanded = numpy.empty((16,16,16), dtype=numpy.uint8)
blocklight_expanded[:,:,::2] = blocklight & 0x0F
blocklight_expanded[:,:,1::2] = (blocklight & 0xF0) >> 4
del blocklight
section['BlockLight'] = blocklight_expanded
if 'block_states' in section:
(blocks, data) = self._get_blockdata_v118(section, unrecognized_block_types, longarray_unpacker)
elif 'Palette' in section:
(blocks, data) = self._get_blockdata_v113(section, unrecognized_block_types, longarray_unpacker)
elif 'Data' in section:
(blocks, data) = self._get_blockdata_v112(section)
else: # Special case introduced with 1.14
blocks = numpy.zeros((16,16,16), dtype=numpy.uint16)
data = numpy.zeros((16,16,16), dtype=numpy.uint8)
(section['Blocks'], section['Data']) = (blocks, data)
except ValueError:
# iv'e seen at least 1 case where numpy raises a value error during the reshapes. i'm not
# sure what's going on here, but let's treat this as a corrupt chunk error
logging.warning("There was a problem reading chunk %d,%d. It might be corrupt. I am giving up and will not render this particular chunk.", x, z)
logging.debug("Full traceback:", exc_info=1)
raise nbt.CorruptChunkError()
for k in unrecognized_block_types:
logging.debug("Found %d blocks of unknown type %s" % (unrecognized_block_types[k], k))
return chunk_data | [
"def",
"get_chunk",
"(",
"self",
",",
"x",
",",
"z",
")",
":",
"regionfile",
"=",
"self",
".",
"_get_region_path",
"(",
"x",
",",
"z",
")",
"if",
"regionfile",
"is",
"None",
":",
"raise",
"ChunkDoesntExist",
"(",
"\"Chunk %s,%s doesn't exist (and neither does ... | https://github.com/overviewer/Minecraft-Overviewer/blob/7171af587399fee9140eb83fb9b066acd251f57a/overviewer_core/world.py#L1639-L1812 | |
sagemath/sage | f9b2db94f675ff16963ccdefba4f1a3393b3fe0d | src/sage/functions/error.py | python | Function_Fresnel_cos.__init__ | (self) | r"""
The cosine Fresnel integral.
It is defined by the integral
.. MATH ::
\operatorname{C}(x) = \int_0^x \cos\left(\frac{\pi t^2}{2}\right)\, dt
for real `x`. Using power series expansions, it can be extended to the
domain of complex numbers. See the :wikipedia:`Fresnel_integral`.
INPUT:
- ``x`` -- the argument of the function
EXAMPLES::
sage: fresnel_cos(0)
0
sage: fresnel_cos(x).subs(x==0)
0
sage: x = var('x')
sage: fresnel_cos(1).n(100)
0.77989340037682282947420641365
sage: fresnel_cos(x)._sympy_()
fresnelc(x) | r"""
The cosine Fresnel integral. | [
"r",
"The",
"cosine",
"Fresnel",
"integral",
"."
] | def __init__(self):
r"""
The cosine Fresnel integral.
It is defined by the integral
.. MATH ::
\operatorname{C}(x) = \int_0^x \cos\left(\frac{\pi t^2}{2}\right)\, dt
for real `x`. Using power series expansions, it can be extended to the
domain of complex numbers. See the :wikipedia:`Fresnel_integral`.
INPUT:
- ``x`` -- the argument of the function
EXAMPLES::
sage: fresnel_cos(0)
0
sage: fresnel_cos(x).subs(x==0)
0
sage: x = var('x')
sage: fresnel_cos(1).n(100)
0.77989340037682282947420641365
sage: fresnel_cos(x)._sympy_()
fresnelc(x)
"""
BuiltinFunction.__init__(self, "fresnel_cos", nargs=1,
latex_name=r"\operatorname{C}",
conversions=dict(maxima='fresnel_c',
sympy='fresnelc',
mathematica='FresnelC',
maple='FresnelC',
fricas='fresnelC')) | [
"def",
"__init__",
"(",
"self",
")",
":",
"BuiltinFunction",
".",
"__init__",
"(",
"self",
",",
"\"fresnel_cos\"",
",",
"nargs",
"=",
"1",
",",
"latex_name",
"=",
"r\"\\operatorname{C}\"",
",",
"conversions",
"=",
"dict",
"(",
"maxima",
"=",
"'fresnel_c'",
"... | https://github.com/sagemath/sage/blob/f9b2db94f675ff16963ccdefba4f1a3393b3fe0d/src/sage/functions/error.py#L674-L709 | ||
open-mmlab/mmfashion | 0e26ab36847684fbf7f736c39df8d518129d9a69 | configs/fashion_parsing_segmentation/inference.py | python | inference_detector | (model, img) | return result | Inference image(s) with the detector.
Args:
model (nn.Module): The loaded detector.
imgs (str/ndarray or list[str/ndarray]): Either image files or loaded
images.
Returns:
If imgs is a str, a generator will be returned, otherwise return the
detection results directly. | Inference image(s) with the detector. | [
"Inference",
"image",
"(",
"s",
")",
"with",
"the",
"detector",
"."
] | def inference_detector(model, img):
"""Inference image(s) with the detector.
Args:
model (nn.Module): The loaded detector.
imgs (str/ndarray or list[str/ndarray]): Either image files or loaded
images.
Returns:
If imgs is a str, a generator will be returned, otherwise return the
detection results directly.
"""
cfg = model.cfg
device = next(model.parameters()).device # model device
# build the data pipeline
test_pipeline = [LoadImage()] + cfg.data.test.pipeline[1:]
test_pipeline = Compose(test_pipeline)
# prepare data
data = dict(img=img)
data = test_pipeline(data)
data = scatter(collate([data], samples_per_gpu=1), [device])[0]
# forward the model
with torch.no_grad():
result = model(return_loss=False, rescale=True, **data)
return result | [
"def",
"inference_detector",
"(",
"model",
",",
"img",
")",
":",
"cfg",
"=",
"model",
".",
"cfg",
"device",
"=",
"next",
"(",
"model",
".",
"parameters",
"(",
")",
")",
".",
"device",
"# model device",
"# build the data pipeline",
"test_pipeline",
"=",
"[",
... | https://github.com/open-mmlab/mmfashion/blob/0e26ab36847684fbf7f736c39df8d518129d9a69/configs/fashion_parsing_segmentation/inference.py#L62-L86 | |
leo-editor/leo-editor | 383d6776d135ef17d73d935a2f0ecb3ac0e99494 | leo/plugins/qt_tree.py | python | LeoQtTree.endEditLabel | (self) | Override LeoTree.endEditLabel.
Just end editing of the presently-selected QLineEdit!
This will trigger the editingFinished_callback defined in createEditorForItem. | Override LeoTree.endEditLabel. | [
"Override",
"LeoTree",
".",
"endEditLabel",
"."
] | def endEditLabel(self):
"""
Override LeoTree.endEditLabel.
Just end editing of the presently-selected QLineEdit!
This will trigger the editingFinished_callback defined in createEditorForItem.
"""
item = self.getCurrentItem()
if not item:
return
e = self.getTreeEditorForItem(item)
if not e:
return
# Trigger the end-editing event.
w = self.treeWidget
w.closeEditor(e, EndEditHint.NoHint)
w.setCurrentItem(item) | [
"def",
"endEditLabel",
"(",
"self",
")",
":",
"item",
"=",
"self",
".",
"getCurrentItem",
"(",
")",
"if",
"not",
"item",
":",
"return",
"e",
"=",
"self",
".",
"getTreeEditorForItem",
"(",
"item",
")",
"if",
"not",
"e",
":",
"return",
"# Trigger the end-e... | https://github.com/leo-editor/leo-editor/blob/383d6776d135ef17d73d935a2f0ecb3ac0e99494/leo/plugins/qt_tree.py#L1329-L1345 | ||
OpenMined/PySyft | f181ca02d307d57bfff9477610358df1a12e3ac9 | packages/syft/src/syft/ast/static_attr.py | python | StaticAttribute.solve_get_value | (self) | return getattr(self.parent.object_ref, self.path_and_name.rsplit(".")[-1]) | Local execution of the getter function is performed.
The `solve_get_value` method executes the getter function on the AST.
Raises:
ValueError : If `path_and_name` is `None`.
Returns:
Value of the AST node | Local execution of the getter function is performed. | [
"Local",
"execution",
"of",
"the",
"getter",
"function",
"is",
"performed",
"."
] | def solve_get_value(self) -> Any:
"""Local execution of the getter function is performed.
The `solve_get_value` method executes the getter function on the AST.
Raises:
ValueError : If `path_and_name` is `None`.
Returns:
Value of the AST node
"""
self.apply_node_changes()
if self.path_and_name is None:
raise ValueError("path_and_name should not be None")
return getattr(self.parent.object_ref, self.path_and_name.rsplit(".")[-1]) | [
"def",
"solve_get_value",
"(",
"self",
")",
"->",
"Any",
":",
"self",
".",
"apply_node_changes",
"(",
")",
"if",
"self",
".",
"path_and_name",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"path_and_name should not be None\"",
")",
"return",
"getattr",
"(",
... | https://github.com/OpenMined/PySyft/blob/f181ca02d307d57bfff9477610358df1a12e3ac9/packages/syft/src/syft/ast/static_attr.py#L87-L103 | |
python/cpython | e13cdca0f5224ec4e23bdd04bb3120506964bc8b | Lib/tkinter/__init__.py | python | Misc.bind_class | (self, className, sequence=None, func=None, add=None) | return self._bind(('bind', className), sequence, func, add, 0) | Bind to widgets with bindtag CLASSNAME at event
SEQUENCE a call of function FUNC. An additional
boolean parameter ADD specifies whether FUNC will be
called additionally to the other bound function or
whether it will replace the previous function. See bind for
the return value. | Bind to widgets with bindtag CLASSNAME at event
SEQUENCE a call of function FUNC. An additional
boolean parameter ADD specifies whether FUNC will be
called additionally to the other bound function or
whether it will replace the previous function. See bind for
the return value. | [
"Bind",
"to",
"widgets",
"with",
"bindtag",
"CLASSNAME",
"at",
"event",
"SEQUENCE",
"a",
"call",
"of",
"function",
"FUNC",
".",
"An",
"additional",
"boolean",
"parameter",
"ADD",
"specifies",
"whether",
"FUNC",
"will",
"be",
"called",
"additionally",
"to",
"th... | def bind_class(self, className, sequence=None, func=None, add=None):
"""Bind to widgets with bindtag CLASSNAME at event
SEQUENCE a call of function FUNC. An additional
boolean parameter ADD specifies whether FUNC will be
called additionally to the other bound function or
whether it will replace the previous function. See bind for
the return value."""
return self._bind(('bind', className), sequence, func, add, 0) | [
"def",
"bind_class",
"(",
"self",
",",
"className",
",",
"sequence",
"=",
"None",
",",
"func",
"=",
"None",
",",
"add",
"=",
"None",
")",
":",
"return",
"self",
".",
"_bind",
"(",
"(",
"'bind'",
",",
"className",
")",
",",
"sequence",
",",
"func",
... | https://github.com/python/cpython/blob/e13cdca0f5224ec4e23bdd04bb3120506964bc8b/Lib/tkinter/__init__.py#L1440-L1448 | |
atlas0fd00m/CanCat | be8fb53b0583658aa8226de79f36c56309756778 | cancat/envi/__init__.py | python | Emulator.intSubBase | (self, subtrahend, minuend, ssize, msize) | return (ssize, msize, sres, ures, ssubtra, usubtra) | Base for integer subtraction.
Segmented such that order of operands can easily be overridden by
subclasses. Does not set flags (arch-specific), and doesn't set
the dest operand. That's up to the instruction implementation.
So we can either do a BUNCH of crazyness with xor and shifting to
get the necessary flags here, *or* we can just do both a signed and
unsigned sub and use the results.
Math vocab refresher: Subtrahend - Minuend = Difference | Base for integer subtraction.
Segmented such that order of operands can easily be overridden by
subclasses. Does not set flags (arch-specific), and doesn't set
the dest operand. That's up to the instruction implementation. | [
"Base",
"for",
"integer",
"subtraction",
".",
"Segmented",
"such",
"that",
"order",
"of",
"operands",
"can",
"easily",
"be",
"overridden",
"by",
"subclasses",
".",
"Does",
"not",
"set",
"flags",
"(",
"arch",
"-",
"specific",
")",
"and",
"doesn",
"t",
"set"... | def intSubBase(self, subtrahend, minuend, ssize, msize):
'''
Base for integer subtraction.
Segmented such that order of operands can easily be overridden by
subclasses. Does not set flags (arch-specific), and doesn't set
the dest operand. That's up to the instruction implementation.
So we can either do a BUNCH of crazyness with xor and shifting to
get the necessary flags here, *or* we can just do both a signed and
unsigned sub and use the results.
Math vocab refresher: Subtrahend - Minuend = Difference
'''
usubtra = e_bits.unsigned(subtrahend, ssize)
uminuend = e_bits.unsigned(minuend, msize)
ssubtra = e_bits.signed(subtrahend, ssize)
sminuend = e_bits.signed(minuend, msize)
ures = usubtra - uminuend
sres = ssubtra - sminuend
return (ssize, msize, sres, ures, ssubtra, usubtra) | [
"def",
"intSubBase",
"(",
"self",
",",
"subtrahend",
",",
"minuend",
",",
"ssize",
",",
"msize",
")",
":",
"usubtra",
"=",
"e_bits",
".",
"unsigned",
"(",
"subtrahend",
",",
"ssize",
")",
"uminuend",
"=",
"e_bits",
".",
"unsigned",
"(",
"minuend",
",",
... | https://github.com/atlas0fd00m/CanCat/blob/be8fb53b0583658aa8226de79f36c56309756778/cancat/envi/__init__.py#L787-L809 | |
tp4a/teleport | 1fafd34f1f775d2cf80ea4af6e44468d8e0b24ad | server/www/packages/packages-linux/x64/cffi/vengine_gen.py | python | VGenericEngine._loaded_gen_constant | (self, tp, name, module, library) | [] | def _loaded_gen_constant(self, tp, name, module, library):
is_int = isinstance(tp, model.PrimitiveType) and tp.is_integer_type()
value = self._load_constant(is_int, tp, name, module)
setattr(library, name, value)
type(library)._cffi_dir.append(name) | [
"def",
"_loaded_gen_constant",
"(",
"self",
",",
"tp",
",",
"name",
",",
"module",
",",
"library",
")",
":",
"is_int",
"=",
"isinstance",
"(",
"tp",
",",
"model",
".",
"PrimitiveType",
")",
"and",
"tp",
".",
"is_integer_type",
"(",
")",
"value",
"=",
"... | https://github.com/tp4a/teleport/blob/1fafd34f1f775d2cf80ea4af6e44468d8e0b24ad/server/www/packages/packages-linux/x64/cffi/vengine_gen.py#L465-L469 | ||||
edfungus/Crouton | ada98b3930192938a48909072b45cb84b945f875 | clients/python_clients/venv/lib/python2.7/site-packages/pip/_vendor/distlib/locators.py | python | Locator.convert_url_to_download_info | (self, url, project_name) | return result | See if a URL is a candidate for a download URL for a project (the URL
has typically been scraped from an HTML page).
If it is, a dictionary is returned with keys "name", "version",
"filename" and "url"; otherwise, None is returned. | See if a URL is a candidate for a download URL for a project (the URL
has typically been scraped from an HTML page). | [
"See",
"if",
"a",
"URL",
"is",
"a",
"candidate",
"for",
"a",
"download",
"URL",
"for",
"a",
"project",
"(",
"the",
"URL",
"has",
"typically",
"been",
"scraped",
"from",
"an",
"HTML",
"page",
")",
"."
] | def convert_url_to_download_info(self, url, project_name):
"""
See if a URL is a candidate for a download URL for a project (the URL
has typically been scraped from an HTML page).
If it is, a dictionary is returned with keys "name", "version",
"filename" and "url"; otherwise, None is returned.
"""
def same_project(name1, name2):
name1, name2 = name1.lower(), name2.lower()
if name1 == name2:
result = True
else:
# distribute replaces '-' by '_' in project names, so it
# can tell where the version starts in a filename.
result = name1.replace('_', '-') == name2.replace('_', '-')
return result
result = None
scheme, netloc, path, params, query, frag = urlparse(url)
if frag.lower().startswith('egg='):
logger.debug('%s: version hint in fragment: %r',
project_name, frag)
m = HASHER_HASH.match(frag)
if m:
algo, digest = m.groups()
else:
algo, digest = None, None
origpath = path
if path and path[-1] == '/':
path = path[:-1]
if path.endswith('.whl'):
try:
wheel = Wheel(path)
if is_compatible(wheel, self.wheel_tags):
if project_name is None:
include = True
else:
include = same_project(wheel.name, project_name)
if include:
result = {
'name': wheel.name,
'version': wheel.version,
'filename': wheel.filename,
'url': urlunparse((scheme, netloc, origpath,
params, query, '')),
'python-version': ', '.join(
['.'.join(list(v[2:])) for v in wheel.pyver]),
}
except Exception as e:
logger.warning('invalid path for wheel: %s', path)
elif path.endswith(self.downloadable_extensions):
path = filename = posixpath.basename(path)
for ext in self.downloadable_extensions:
if path.endswith(ext):
path = path[:-len(ext)]
t = self.split_filename(path, project_name)
if not t:
logger.debug('No match for project/version: %s', path)
else:
name, version, pyver = t
if not project_name or same_project(project_name, name):
result = {
'name': name,
'version': version,
'filename': filename,
'url': urlunparse((scheme, netloc, origpath,
params, query, '')),
#'packagetype': 'sdist',
}
if pyver:
result['python-version'] = pyver
break
if result and algo:
result['%s_digest' % algo] = digest
return result | [
"def",
"convert_url_to_download_info",
"(",
"self",
",",
"url",
",",
"project_name",
")",
":",
"def",
"same_project",
"(",
"name1",
",",
"name2",
")",
":",
"name1",
",",
"name2",
"=",
"name1",
".",
"lower",
"(",
")",
",",
"name2",
".",
"lower",
"(",
")... | https://github.com/edfungus/Crouton/blob/ada98b3930192938a48909072b45cb84b945f875/clients/python_clients/venv/lib/python2.7/site-packages/pip/_vendor/distlib/locators.py#L204-L279 | |
jazzband/django-admin2 | 7770da8a4931db60326f87d9fa7a15b1ef704c4c | djadmin2/views.py | python | ModelListView._modify_queryset_for_ordering | (self, queryset) | return queryset | [] | def _modify_queryset_for_ordering(self, queryset):
ordering = self.model_admin.get_ordering(self.request)
if ordering:
queryset = queryset.order_by(*ordering)
return queryset | [
"def",
"_modify_queryset_for_ordering",
"(",
"self",
",",
"queryset",
")",
":",
"ordering",
"=",
"self",
".",
"model_admin",
".",
"get_ordering",
"(",
"self",
".",
"request",
")",
"if",
"ordering",
":",
"queryset",
"=",
"queryset",
".",
"order_by",
"(",
"*",... | https://github.com/jazzband/django-admin2/blob/7770da8a4931db60326f87d9fa7a15b1ef704c4c/djadmin2/views.py#L197-L201 | |||
securesystemslab/zippy | ff0e84ac99442c2c55fe1d285332cfd4e185e089 | zippy/lib-python/3/ntpath.py | python | _get_altsep | (path) | [] | def _get_altsep(path):
if isinstance(path, bytes):
return b'/'
else:
return '/' | [
"def",
"_get_altsep",
"(",
"path",
")",
":",
"if",
"isinstance",
"(",
"path",
",",
"bytes",
")",
":",
"return",
"b'/'",
"else",
":",
"return",
"'/'"
] | https://github.com/securesystemslab/zippy/blob/ff0e84ac99442c2c55fe1d285332cfd4e185e089/zippy/lib-python/3/ntpath.py#L50-L54 | ||||
ni/nidaqmx-python | 62fc6b48cbbb330fe1bcc9aedadc86610a1269b6 | nidaqmx/task.py | python | Task.do_channels | (self) | return self._do_channels | :class:`nidaqmx._task_modules.do_channel_collection.DOChannelCollection`:
Gets the collection of digital output channels for this task. | :class:`nidaqmx._task_modules.do_channel_collection.DOChannelCollection`:
Gets the collection of digital output channels for this task. | [
":",
"class",
":",
"nidaqmx",
".",
"_task_modules",
".",
"do_channel_collection",
".",
"DOChannelCollection",
":",
"Gets",
"the",
"collection",
"of",
"digital",
"output",
"channels",
"for",
"this",
"task",
"."
] | def do_channels(self):
"""
:class:`nidaqmx._task_modules.do_channel_collection.DOChannelCollection`:
Gets the collection of digital output channels for this task.
"""
return self._do_channels | [
"def",
"do_channels",
"(",
"self",
")",
":",
"return",
"self",
".",
"_do_channels"
] | https://github.com/ni/nidaqmx-python/blob/62fc6b48cbbb330fe1bcc9aedadc86610a1269b6/nidaqmx/task.py#L319-L324 | |
microsoft/nni | 31f11f51249660930824e888af0d4e022823285c | nni/retiarii/graph.py | python | Model.get_nodes_by_label | (self, label: str) | return matched_nodes | Traverse all the nodes to find the matched node(s) with the given label.
There could be multiple nodes with the same label. Name space name can uniquely
identify a graph or node.
NOTE: the implementation does not support the class abstraction | Traverse all the nodes to find the matched node(s) with the given label.
There could be multiple nodes with the same label. Name space name can uniquely
identify a graph or node. | [
"Traverse",
"all",
"the",
"nodes",
"to",
"find",
"the",
"matched",
"node",
"(",
"s",
")",
"with",
"the",
"given",
"label",
".",
"There",
"could",
"be",
"multiple",
"nodes",
"with",
"the",
"same",
"label",
".",
"Name",
"space",
"name",
"can",
"uniquely",
... | def get_nodes_by_label(self, label: str) -> List['Node']:
"""
Traverse all the nodes to find the matched node(s) with the given label.
There could be multiple nodes with the same label. Name space name can uniquely
identify a graph or node.
NOTE: the implementation does not support the class abstraction
"""
matched_nodes = []
for graph in self.graphs.values():
nodes = graph.get_nodes_by_label(label)
matched_nodes.extend(nodes)
return matched_nodes | [
"def",
"get_nodes_by_label",
"(",
"self",
",",
"label",
":",
"str",
")",
"->",
"List",
"[",
"'Node'",
"]",
":",
"matched_nodes",
"=",
"[",
"]",
"for",
"graph",
"in",
"self",
".",
"graphs",
".",
"values",
"(",
")",
":",
"nodes",
"=",
"graph",
".",
"... | https://github.com/microsoft/nni/blob/31f11f51249660930824e888af0d4e022823285c/nni/retiarii/graph.py#L179-L191 | |
raffaele-forte/climber | 5530a780446e35b1ce977bae140557050fe0b47c | Exscript/workqueue/Pipeline.py | python | Pipeline.wait | (self) | Waits for all currently running tasks to complete. | Waits for all currently running tasks to complete. | [
"Waits",
"for",
"all",
"currently",
"running",
"tasks",
"to",
"complete",
"."
] | def wait(self):
"""
Waits for all currently running tasks to complete.
"""
with self.condition:
while self.working:
self.condition.wait() | [
"def",
"wait",
"(",
"self",
")",
":",
"with",
"self",
".",
"condition",
":",
"while",
"self",
".",
"working",
":",
"self",
".",
"condition",
".",
"wait",
"(",
")"
] | https://github.com/raffaele-forte/climber/blob/5530a780446e35b1ce977bae140557050fe0b47c/Exscript/workqueue/Pipeline.py#L188-L194 | ||
quay/quay | b7d325ed42827db9eda2d9f341cb5a6cdfd155a6 | data/model/blob.py | python | initiate_upload | (namespace, repo_name, uuid, location_name, storage_metadata) | return initiate_upload_for_repo(repo, uuid, location_name, storage_metadata) | Initiates a blob upload for the repository with the given namespace and name, in a specific
location. | Initiates a blob upload for the repository with the given namespace and name, in a specific
location. | [
"Initiates",
"a",
"blob",
"upload",
"for",
"the",
"repository",
"with",
"the",
"given",
"namespace",
"and",
"name",
"in",
"a",
"specific",
"location",
"."
] | def initiate_upload(namespace, repo_name, uuid, location_name, storage_metadata):
"""
Initiates a blob upload for the repository with the given namespace and name, in a specific
location.
"""
repo = _basequery.get_existing_repository(namespace, repo_name)
return initiate_upload_for_repo(repo, uuid, location_name, storage_metadata) | [
"def",
"initiate_upload",
"(",
"namespace",
",",
"repo_name",
",",
"uuid",
",",
"location_name",
",",
"storage_metadata",
")",
":",
"repo",
"=",
"_basequery",
".",
"get_existing_repository",
"(",
"namespace",
",",
"repo_name",
")",
"return",
"initiate_upload_for_rep... | https://github.com/quay/quay/blob/b7d325ed42827db9eda2d9f341cb5a6cdfd155a6/data/model/blob.py#L191-L197 | |
securesystemslab/zippy | ff0e84ac99442c2c55fe1d285332cfd4e185e089 | zippy/benchmarks/src/benchmarks/whoosh/src/whoosh/matching/combo.py | python | ArrayUnionMatcher.skip_to_quality | (self, minquality) | return skipped | [] | def skip_to_quality(self, minquality):
skipped = 0
while self.is_active() and self.block_quality() <= minquality:
skipped += 1
self._docnum = self._limit
self._read_part()
if self.is_active():
self._find_next()
return skipped | [
"def",
"skip_to_quality",
"(",
"self",
",",
"minquality",
")",
":",
"skipped",
"=",
"0",
"while",
"self",
".",
"is_active",
"(",
")",
"and",
"self",
".",
"block_quality",
"(",
")",
"<=",
"minquality",
":",
"skipped",
"+=",
"1",
"self",
".",
"_docnum",
... | https://github.com/securesystemslab/zippy/blob/ff0e84ac99442c2c55fe1d285332cfd4e185e089/zippy/benchmarks/src/benchmarks/whoosh/src/whoosh/matching/combo.py#L276-L284 | |||
bjmayor/hacker | e3ce2ad74839c2733b27dac6c0f495e0743e1866 | venv/lib/python3.5/site-packages/mechanize/_urllib2_fork.py | python | randombytes | (n) | Return n random bytes. | Return n random bytes. | [
"Return",
"n",
"random",
"bytes",
"."
] | def randombytes(n):
"""Return n random bytes."""
# Use /dev/urandom if it is available. Fall back to random module
# if not. It might be worthwhile to extend this function to use
# other platform-specific mechanisms for getting random bytes.
if os.path.exists("/dev/urandom"):
f = open("/dev/urandom")
s = f.read(n)
f.close()
return s
else:
L = [chr(random.randrange(0, 256)) for i in range(n)]
return "".join(L) | [
"def",
"randombytes",
"(",
"n",
")",
":",
"# Use /dev/urandom if it is available. Fall back to random module",
"# if not. It might be worthwhile to extend this function to use",
"# other platform-specific mechanisms for getting random bytes.",
"if",
"os",
".",
"path",
".",
"exists",
... | https://github.com/bjmayor/hacker/blob/e3ce2ad74839c2733b27dac6c0f495e0743e1866/venv/lib/python3.5/site-packages/mechanize/_urllib2_fork.py#L845-L857 | ||
yuanxiaosc/BERT-for-Sequence-Labeling-and-Text-Classification | 2a6d2f9c732a362458030643e131540e7d1cdcca | bert/run_classifier.py | python | create_model | (bert_config, is_training, input_ids, input_mask, segment_ids,
labels, num_labels, use_one_hot_embeddings) | Creates a classification model. | Creates a classification model. | [
"Creates",
"a",
"classification",
"model",
"."
] | def create_model(bert_config, is_training, input_ids, input_mask, segment_ids,
labels, num_labels, use_one_hot_embeddings):
"""Creates a classification model."""
model = modeling.BertModel(
config=bert_config,
is_training=is_training,
input_ids=input_ids,
input_mask=input_mask,
token_type_ids=segment_ids,
use_one_hot_embeddings=use_one_hot_embeddings)
# In the demo, we are doing a simple classification task on the entire
# segment.
#
# If you want to use the token-level output, use model.get_sequence_output()
# instead.
output_layer = model.get_pooled_output()
hidden_size = output_layer.shape[-1].value
output_weights = tf.get_variable(
"output_weights", [num_labels, hidden_size],
initializer=tf.truncated_normal_initializer(stddev=0.02))
output_bias = tf.get_variable(
"output_bias", [num_labels], initializer=tf.zeros_initializer())
with tf.variable_scope("loss"):
if is_training:
# I.e., 0.1 dropout
output_layer = tf.nn.dropout(output_layer, keep_prob=0.9)
logits = tf.matmul(output_layer, output_weights, transpose_b=True)
logits = tf.nn.bias_add(logits, output_bias)
probabilities = tf.nn.softmax(logits, axis=-1)
log_probs = tf.nn.log_softmax(logits, axis=-1)
one_hot_labels = tf.one_hot(labels, depth=num_labels, dtype=tf.float32)
per_example_loss = -tf.reduce_sum(one_hot_labels * log_probs, axis=-1)
loss = tf.reduce_mean(per_example_loss)
return (loss, per_example_loss, logits, probabilities) | [
"def",
"create_model",
"(",
"bert_config",
",",
"is_training",
",",
"input_ids",
",",
"input_mask",
",",
"segment_ids",
",",
"labels",
",",
"num_labels",
",",
"use_one_hot_embeddings",
")",
":",
"model",
"=",
"modeling",
".",
"BertModel",
"(",
"config",
"=",
"... | https://github.com/yuanxiaosc/BERT-for-Sequence-Labeling-and-Text-Classification/blob/2a6d2f9c732a362458030643e131540e7d1cdcca/bert/run_classifier.py#L574-L616 | ||
xtiankisutsa/MARA_Framework | ac4ac88bfd38f33ae8780a606ed09ab97177c562 | tools/lobotomy/core/include/androguard/androguard/core/analysis/ganalysis.py | python | Graph.nodes_with_selfloops | (self) | return [ n for n,nbrs in self.adj.items() if n in nbrs ] | Return a list of nodes with self loops.
A node with a self loop has an edge with both ends adjacent
to that node.
Returns
-------
nodelist : list
A list of nodes with self loops.
See Also
--------
selfloop_edges, number_of_selfloops
Examples
--------
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> G.add_edge(1,1)
>>> G.add_edge(1,2)
>>> G.nodes_with_selfloops()
[1] | Return a list of nodes with self loops. | [
"Return",
"a",
"list",
"of",
"nodes",
"with",
"self",
"loops",
"."
] | def nodes_with_selfloops(self):
"""Return a list of nodes with self loops.
A node with a self loop has an edge with both ends adjacent
to that node.
Returns
-------
nodelist : list
A list of nodes with self loops.
See Also
--------
selfloop_edges, number_of_selfloops
Examples
--------
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> G.add_edge(1,1)
>>> G.add_edge(1,2)
>>> G.nodes_with_selfloops()
[1]
"""
return [ n for n,nbrs in self.adj.items() if n in nbrs ] | [
"def",
"nodes_with_selfloops",
"(",
"self",
")",
":",
"return",
"[",
"n",
"for",
"n",
",",
"nbrs",
"in",
"self",
".",
"adj",
".",
"items",
"(",
")",
"if",
"n",
"in",
"nbrs",
"]"
] | https://github.com/xtiankisutsa/MARA_Framework/blob/ac4ac88bfd38f33ae8780a606ed09ab97177c562/tools/lobotomy/core/include/androguard/androguard/core/analysis/ganalysis.py#L1529-L1552 | |
espnet/espnet | ea411f3f627b8f101c211e107d0ff7053344ac80 | utils/generate_wav_from_fbank.py | python | TimeInvariantMLSAFilter.__call__ | (self, y) | return self.mlsa_filter.synthesis(y, coef) | Apply time invariant MLSA filter.
Args:
y (ndarray): Waveform signal normalized from -1 to 1 (N,).
Returns:
y (ndarray): Filtered waveform signal normalized from -1 to 1 (N,). | Apply time invariant MLSA filter. | [
"Apply",
"time",
"invariant",
"MLSA",
"filter",
"."
] | def __call__(self, y):
"""Apply time invariant MLSA filter.
Args:
y (ndarray): Waveform signal normalized from -1 to 1 (N,).
Returns:
y (ndarray): Filtered waveform signal normalized from -1 to 1 (N,).
"""
# check shape and type
assert len(y.shape) == 1
y = np.float64(y)
# get frame number and then replicate mlsa coef
num_frames = int(len(y) / self.n_shift) + 1
coef = np.tile(self.coef, [num_frames, 1])
return self.mlsa_filter.synthesis(y, coef) | [
"def",
"__call__",
"(",
"self",
",",
"y",
")",
":",
"# check shape and type",
"assert",
"len",
"(",
"y",
".",
"shape",
")",
"==",
"1",
"y",
"=",
"np",
".",
"float64",
"(",
"y",
")",
"# get frame number and then replicate mlsa coef",
"num_frames",
"=",
"int",... | https://github.com/espnet/espnet/blob/ea411f3f627b8f101c211e107d0ff7053344ac80/utils/generate_wav_from_fbank.py#L55-L73 | |
tensorflow/models | 6b8bb0cbeb3e10415c7a87448f08adc3c484c1d3 | research/object_detection/models/faster_rcnn_inception_resnet_v2_feature_extractor.py | python | FasterRCNNInceptionResnetV2FeatureExtractor.restore_from_classification_checkpoint_fn | (
self,
first_stage_feature_extractor_scope,
second_stage_feature_extractor_scope) | return variables_to_restore | Returns a map of variables to load from a foreign checkpoint.
Note that this overrides the default implementation in
faster_rcnn_meta_arch.FasterRCNNFeatureExtractor which does not work for
InceptionResnetV2 checkpoints.
TODO(jonathanhuang,rathodv): revisit whether it's possible to force the
`Repeat` namescope as created in `_extract_box_classifier_features` to
start counting at 2 (e.g. `Repeat_2`) so that the default restore_fn can
be used.
Args:
first_stage_feature_extractor_scope: A scope name for the first stage
feature extractor.
second_stage_feature_extractor_scope: A scope name for the second stage
feature extractor.
Returns:
A dict mapping variable names (to load from a checkpoint) to variables in
the model graph. | Returns a map of variables to load from a foreign checkpoint. | [
"Returns",
"a",
"map",
"of",
"variables",
"to",
"load",
"from",
"a",
"foreign",
"checkpoint",
"."
] | def restore_from_classification_checkpoint_fn(
self,
first_stage_feature_extractor_scope,
second_stage_feature_extractor_scope):
"""Returns a map of variables to load from a foreign checkpoint.
Note that this overrides the default implementation in
faster_rcnn_meta_arch.FasterRCNNFeatureExtractor which does not work for
InceptionResnetV2 checkpoints.
TODO(jonathanhuang,rathodv): revisit whether it's possible to force the
`Repeat` namescope as created in `_extract_box_classifier_features` to
start counting at 2 (e.g. `Repeat_2`) so that the default restore_fn can
be used.
Args:
first_stage_feature_extractor_scope: A scope name for the first stage
feature extractor.
second_stage_feature_extractor_scope: A scope name for the second stage
feature extractor.
Returns:
A dict mapping variable names (to load from a checkpoint) to variables in
the model graph.
"""
variables_to_restore = {}
for variable in variables_helper.get_global_variables_safely():
if variable.op.name.startswith(
first_stage_feature_extractor_scope):
var_name = variable.op.name.replace(
first_stage_feature_extractor_scope + '/', '')
variables_to_restore[var_name] = variable
if variable.op.name.startswith(
second_stage_feature_extractor_scope):
var_name = variable.op.name.replace(
second_stage_feature_extractor_scope
+ '/InceptionResnetV2/Repeat', 'InceptionResnetV2/Repeat_2')
var_name = var_name.replace(
second_stage_feature_extractor_scope + '/', '')
variables_to_restore[var_name] = variable
return variables_to_restore | [
"def",
"restore_from_classification_checkpoint_fn",
"(",
"self",
",",
"first_stage_feature_extractor_scope",
",",
"second_stage_feature_extractor_scope",
")",
":",
"variables_to_restore",
"=",
"{",
"}",
"for",
"variable",
"in",
"variables_helper",
".",
"get_global_variables_saf... | https://github.com/tensorflow/models/blob/6b8bb0cbeb3e10415c7a87448f08adc3c484c1d3/research/object_detection/models/faster_rcnn_inception_resnet_v2_feature_extractor.py#L171-L212 | |
marinho/geraldo | 868ebdce67176d9b6205cddc92476f642c783fff | site/newsite/site-geraldo/django/forms/formsets.py | python | BaseFormSet._construct_form | (self, i, **kwargs) | return form | Instantiates and returns the i-th form instance in a formset. | Instantiates and returns the i-th form instance in a formset. | [
"Instantiates",
"and",
"returns",
"the",
"i",
"-",
"th",
"form",
"instance",
"in",
"a",
"formset",
"."
] | def _construct_form(self, i, **kwargs):
"""
Instantiates and returns the i-th form instance in a formset.
"""
defaults = {'auto_id': self.auto_id, 'prefix': self.add_prefix(i)}
if self.data or self.files:
defaults['data'] = self.data
defaults['files'] = self.files
if self.initial:
try:
defaults['initial'] = self.initial[i]
except IndexError:
pass
# Allow extra forms to be empty.
if i >= self._initial_form_count:
defaults['empty_permitted'] = True
defaults.update(kwargs)
form = self.form(**defaults)
self.add_fields(form, i)
return form | [
"def",
"_construct_form",
"(",
"self",
",",
"i",
",",
"*",
"*",
"kwargs",
")",
":",
"defaults",
"=",
"{",
"'auto_id'",
":",
"self",
".",
"auto_id",
",",
"'prefix'",
":",
"self",
".",
"add_prefix",
"(",
"i",
")",
"}",
"if",
"self",
".",
"data",
"or"... | https://github.com/marinho/geraldo/blob/868ebdce67176d9b6205cddc92476f642c783fff/site/newsite/site-geraldo/django/forms/formsets.py#L78-L97 | |
IntelPython/sdc | 1ebf55c00ef38dfbd401a70b3945e352a5a38b87 | sdc/io/np_io.py | python | get_file_size_overload | (fname) | [] | def get_file_size_overload(fname):
if fname == string_type:
return lambda fname: _get_file_size(fname._data) | [
"def",
"get_file_size_overload",
"(",
"fname",
")",
":",
"if",
"fname",
"==",
"string_type",
":",
"return",
"lambda",
"fname",
":",
"_get_file_size",
"(",
"fname",
".",
"_data",
")"
] | https://github.com/IntelPython/sdc/blob/1ebf55c00ef38dfbd401a70b3945e352a5a38b87/sdc/io/np_io.py#L179-L181 | ||||
rspeer/wordfreq | 11a3138cea5f46d2229a110c1774ac64a2fcd92b | wordfreq/__init__.py | python | available_languages | (wordlist='best') | return available | Given a wordlist name, return a dictionary of language codes to filenames,
representing all the languages in which that wordlist is available. | Given a wordlist name, return a dictionary of language codes to filenames,
representing all the languages in which that wordlist is available. | [
"Given",
"a",
"wordlist",
"name",
"return",
"a",
"dictionary",
"of",
"language",
"codes",
"to",
"filenames",
"representing",
"all",
"the",
"languages",
"in",
"which",
"that",
"wordlist",
"is",
"available",
"."
] | def available_languages(wordlist='best'):
"""
Given a wordlist name, return a dictionary of language codes to filenames,
representing all the languages in which that wordlist is available.
"""
if wordlist == 'best':
available = available_languages('small')
available.update(available_languages('large'))
return available
elif wordlist == 'combined':
logger.warning(
"The 'combined' wordlists have been renamed to 'small'."
)
wordlist = 'small'
available = {}
for path in DATA_PATH.glob('*.msgpack.gz'):
if not path.name.startswith('_'):
list_name = path.name.split('.')[0]
name, lang = list_name.split('_')
if name == wordlist:
available[lang] = str(path)
return available | [
"def",
"available_languages",
"(",
"wordlist",
"=",
"'best'",
")",
":",
"if",
"wordlist",
"==",
"'best'",
":",
"available",
"=",
"available_languages",
"(",
"'small'",
")",
"available",
".",
"update",
"(",
"available_languages",
"(",
"'large'",
")",
")",
"retu... | https://github.com/rspeer/wordfreq/blob/11a3138cea5f46d2229a110c1774ac64a2fcd92b/wordfreq/__init__.py#L88-L110 | |
titusjan/argos | 5a9c31a8a9a2ca825bbf821aa1e685740e3682d7 | argos/repo/rtiplugins/hdf5.py | python | H5pyFieldRti.__init__ | (self, h5Dataset, nodeName, fileName='', iconColor=ICON_COLOR_UNDEF) | Constructor.
The name of the field must be given to the nodeName parameter. | Constructor.
The name of the field must be given to the nodeName parameter. | [
"Constructor",
".",
"The",
"name",
"of",
"the",
"field",
"must",
"be",
"given",
"to",
"the",
"nodeName",
"parameter",
"."
] | def __init__(self, h5Dataset, nodeName, fileName='', iconColor=ICON_COLOR_UNDEF):
""" Constructor.
The name of the field must be given to the nodeName parameter.
"""
super(H5pyFieldRti, self).__init__(nodeName, fileName=fileName, iconColor=iconColor)
check_class(h5Dataset, h5py.Dataset)
self._h5Dataset = h5Dataset | [
"def",
"__init__",
"(",
"self",
",",
"h5Dataset",
",",
"nodeName",
",",
"fileName",
"=",
"''",
",",
"iconColor",
"=",
"ICON_COLOR_UNDEF",
")",
":",
"super",
"(",
"H5pyFieldRti",
",",
"self",
")",
".",
"__init__",
"(",
"nodeName",
",",
"fileName",
"=",
"f... | https://github.com/titusjan/argos/blob/5a9c31a8a9a2ca825bbf821aa1e685740e3682d7/argos/repo/rtiplugins/hdf5.py#L232-L238 | ||
reddit/baseplate.py | f29bd1ce0f1ec4962f65ecd5a2b016b1cd4fd5ac | baseplate/__init__.py | python | Baseplate.configure_context | (self, context_spec: Dict[str, Any]) | Add a number of objects to each request's context object.
Configure and attach multiple clients to the
:py:class:`~baseplate.RequestContext` in one place. This takes a full
configuration spec like :py:func:`baseplate.lib.config.parse_config`
and will attach the specified structure onto the context object each
request.
For example, a configuration like::
baseplate = Baseplate(app_config)
baseplate.configure_context({
"cfg": {
"doggo_is_good": config.Boolean,
},
"cache": MemcachedClient(),
"cassandra": {
"foo": CassandraClient("foo_keyspace"),
"bar": CassandraClient("bar_keyspace"),
},
})
would build a context object that could be used like::
assert context.cfg.doggo_is_good == True
context.cache.get("example")
context.cassandra.foo.execute()
:param app_config: The raw stringy configuration dictionary.
:param context_spec: A specification of what the configuration should
look like. | Add a number of objects to each request's context object. | [
"Add",
"a",
"number",
"of",
"objects",
"to",
"each",
"request",
"s",
"context",
"object",
"."
] | def configure_context(self, context_spec: Dict[str, Any]) -> None:
"""Add a number of objects to each request's context object.
Configure and attach multiple clients to the
:py:class:`~baseplate.RequestContext` in one place. This takes a full
configuration spec like :py:func:`baseplate.lib.config.parse_config`
and will attach the specified structure onto the context object each
request.
For example, a configuration like::
baseplate = Baseplate(app_config)
baseplate.configure_context({
"cfg": {
"doggo_is_good": config.Boolean,
},
"cache": MemcachedClient(),
"cassandra": {
"foo": CassandraClient("foo_keyspace"),
"bar": CassandraClient("bar_keyspace"),
},
})
would build a context object that could be used like::
assert context.cfg.doggo_is_good == True
context.cache.get("example")
context.cassandra.foo.execute()
:param app_config: The raw stringy configuration dictionary.
:param context_spec: A specification of what the configuration should
look like.
"""
cfg = config.parse_config(self._app_config, context_spec)
self._context_config.update(cfg) | [
"def",
"configure_context",
"(",
"self",
",",
"context_spec",
":",
"Dict",
"[",
"str",
",",
"Any",
"]",
")",
"->",
"None",
":",
"cfg",
"=",
"config",
".",
"parse_config",
"(",
"self",
".",
"_app_config",
",",
"context_spec",
")",
"self",
".",
"_context_c... | https://github.com/reddit/baseplate.py/blob/f29bd1ce0f1ec4962f65ecd5a2b016b1cd4fd5ac/baseplate/__init__.py#L379-L414 | ||
xiangyue9607/BioNEV | bf685e44f665bcb3afbde78fb1be0a966aa9c2bc | src/bionev/GAE/initialization.py | python | weight_variable_glorot | (input_dim, output_dim, name="") | return tf.Variable(initial, name=name) | Create a weight variable with Glorot & Bengio (AISTATS 2010)
initialization. | Create a weight variable with Glorot & Bengio (AISTATS 2010)
initialization. | [
"Create",
"a",
"weight",
"variable",
"with",
"Glorot",
"&",
"Bengio",
"(",
"AISTATS",
"2010",
")",
"initialization",
"."
] | def weight_variable_glorot(input_dim, output_dim, name=""):
"""Create a weight variable with Glorot & Bengio (AISTATS 2010)
initialization.
"""
init_range = np.sqrt(6.0 / (input_dim + output_dim))
initial = tf.random_uniform([input_dim, output_dim], minval=-init_range,
maxval=init_range, dtype=tf.float32)
return tf.Variable(initial, name=name) | [
"def",
"weight_variable_glorot",
"(",
"input_dim",
",",
"output_dim",
",",
"name",
"=",
"\"\"",
")",
":",
"init_range",
"=",
"np",
".",
"sqrt",
"(",
"6.0",
"/",
"(",
"input_dim",
"+",
"output_dim",
")",
")",
"initial",
"=",
"tf",
".",
"random_uniform",
"... | https://github.com/xiangyue9607/BioNEV/blob/bf685e44f665bcb3afbde78fb1be0a966aa9c2bc/src/bionev/GAE/initialization.py#L7-L14 | |
zhl2008/awd-platform | 0416b31abea29743387b10b3914581fbe8e7da5e | web_hxb2/lib/python3.5/site-packages/wagtail/wagtailadmin/views/home.py | python | RecentEditsPanel.__init__ | (self, request) | [] | def __init__(self, request):
self.request = request
# Last n edited pages
edit_count = getattr(settings, 'WAGTAILADMIN_RECENT_EDITS_LIMIT', 5)
if connection.vendor == 'mysql':
# MySQL can't handle the subselect created by the ORM version -
# it fails with "This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'"
last_edits = PageRevision.objects.raw(
"""
SELECT wp.* FROM
wagtailcore_pagerevision wp JOIN (
SELECT max(created_at) AS max_created_at, page_id FROM
wagtailcore_pagerevision WHERE user_id = %s GROUP BY page_id ORDER BY max_created_at DESC LIMIT %s
) AS max_rev ON max_rev.max_created_at = wp.created_at ORDER BY wp.created_at DESC
""", [
User._meta.pk.get_db_prep_value(self.request.user.pk, connection),
edit_count
]
)
else:
last_edits_dates = (PageRevision.objects.filter(user=self.request.user)
.values('page_id').annotate(latest_date=Max('created_at'))
.order_by('-latest_date').values('latest_date')[:edit_count])
last_edits = PageRevision.objects.filter(created_at__in=last_edits_dates).order_by('-created_at')
page_keys = [pr.page_id for pr in last_edits]
pages = Page.objects.specific().in_bulk(page_keys)
self.last_edits = [
[review, pages.get(review.page.pk)] for review in last_edits
] | [
"def",
"__init__",
"(",
"self",
",",
"request",
")",
":",
"self",
".",
"request",
"=",
"request",
"# Last n edited pages",
"edit_count",
"=",
"getattr",
"(",
"settings",
",",
"'WAGTAILADMIN_RECENT_EDITS_LIMIT'",
",",
"5",
")",
"if",
"connection",
".",
"vendor",
... | https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_hxb2/lib/python3.5/site-packages/wagtail/wagtailadmin/views/home.py#L55-L85 | ||||
yaqwsx/KiKit | 14de7f60b64e6d03ce638e78d279915d09bb9ac7 | kikit/plugin/__init__.py | python | enable | (all, plugin) | Enable given plugins. Specify none to disable all plugins. | Enable given plugins. Specify none to disable all plugins. | [
"Enable",
"given",
"plugins",
".",
"Specify",
"none",
"to",
"disable",
"all",
"plugins",
"."
] | def enable(all, plugin):
"""
Enable given plugins. Specify none to disable all plugins.
"""
if all:
plugins = availablePlugins
else:
pNames = [x[0] for x in availablePlugins]
for p in plugin:
if p not in pNames:
sys.exit(f"Unknown plugin '{p}'. See available plugins via kikit-plugin list")
plugins = [p for p in availablePlugins if p[0] in plugin]
if isV6():
location = GetUserScriptingPath()
else:
location = str(Path.home()) + "/.kicad_plugins/"
Path(location).mkdir(exist_ok=True, parents=True)
location = os.path.join(location, "kikit_plugin.py")
print(f"File '{location}' was created")
with open(location, "w") as f:
f.write(registrationRoutine(plugins)) | [
"def",
"enable",
"(",
"all",
",",
"plugin",
")",
":",
"if",
"all",
":",
"plugins",
"=",
"availablePlugins",
"else",
":",
"pNames",
"=",
"[",
"x",
"[",
"0",
"]",
"for",
"x",
"in",
"availablePlugins",
"]",
"for",
"p",
"in",
"plugin",
":",
"if",
"p",
... | https://github.com/yaqwsx/KiKit/blob/14de7f60b64e6d03ce638e78d279915d09bb9ac7/kikit/plugin/__init__.py#L99-L120 | ||
adipandas/multi-object-tracker | 8b327f6b15ee1af3c5e5ea74fbe162a1a8bc7b29 | motrackers/utils/misc.py | python | iou | (bbox1, bbox2) | return iou_ | Calculates the intersection-over-union of two bounding boxes.
Source: https://github.com/bochinski/iou-tracker/blob/master/util.py
Args:
bbox1 (numpy.array or list[floats]): Bounding box of length 4 containing
``(x-top-left, y-top-left, x-bottom-right, y-bottom-right)``.
bbox2 (numpy.array or list[floats]): Bounding box of length 4 containing
``(x-top-left, y-top-left, x-bottom-right, y-bottom-right)``.
Returns:
float: intersection-over-onion of bbox1, bbox2. | Calculates the intersection-over-union of two bounding boxes.
Source: https://github.com/bochinski/iou-tracker/blob/master/util.py | [
"Calculates",
"the",
"intersection",
"-",
"over",
"-",
"union",
"of",
"two",
"bounding",
"boxes",
".",
"Source",
":",
"https",
":",
"//",
"github",
".",
"com",
"/",
"bochinski",
"/",
"iou",
"-",
"tracker",
"/",
"blob",
"/",
"master",
"/",
"util",
".",
... | def iou(bbox1, bbox2):
"""
Calculates the intersection-over-union of two bounding boxes.
Source: https://github.com/bochinski/iou-tracker/blob/master/util.py
Args:
bbox1 (numpy.array or list[floats]): Bounding box of length 4 containing
``(x-top-left, y-top-left, x-bottom-right, y-bottom-right)``.
bbox2 (numpy.array or list[floats]): Bounding box of length 4 containing
``(x-top-left, y-top-left, x-bottom-right, y-bottom-right)``.
Returns:
float: intersection-over-onion of bbox1, bbox2.
"""
bbox1 = [float(x) for x in bbox1]
bbox2 = [float(x) for x in bbox2]
(x0_1, y0_1, x1_1, y1_1), (x0_2, y0_2, x1_2, y1_2) = bbox1, bbox2
# get the overlap rectangle
overlap_x0 = max(x0_1, x0_2)
overlap_y0 = max(y0_1, y0_2)
overlap_x1 = min(x1_1, x1_2)
overlap_y1 = min(y1_1, y1_2)
# check if there is an overlap
if overlap_x1 - overlap_x0 <= 0 or overlap_y1 - overlap_y0 <= 0:
return 0.0
# if yes, calculate the ratio of the overlap to each ROI size and the unified size
size_1 = (x1_1 - x0_1) * (y1_1 - y0_1)
size_2 = (x1_2 - x0_2) * (y1_2 - y0_2)
size_intersection = (overlap_x1 - overlap_x0) * (overlap_y1 - overlap_y0)
size_union = size_1 + size_2 - size_intersection
iou_ = size_intersection / size_union
return iou_ | [
"def",
"iou",
"(",
"bbox1",
",",
"bbox2",
")",
":",
"bbox1",
"=",
"[",
"float",
"(",
"x",
")",
"for",
"x",
"in",
"bbox1",
"]",
"bbox2",
"=",
"[",
"float",
"(",
"x",
")",
"for",
"x",
"in",
"bbox2",
"]",
"(",
"x0_1",
",",
"y0_1",
",",
"x1_1",
... | https://github.com/adipandas/multi-object-tracker/blob/8b327f6b15ee1af3c5e5ea74fbe162a1a8bc7b29/motrackers/utils/misc.py#L37-L75 | |
zhufz/nlp_research | b435319858520edcca7c0320dca3e0013087c276 | tasks/task_base.py | python | TaskBase.read_data | (self) | you can load data in different formats for different task | you can load data in different formats for different task | [
"you",
"can",
"load",
"data",
"in",
"different",
"formats",
"for",
"different",
"task"
] | def read_data(self):
"""you can load data in different formats for different task
"""
raise NotImplementedError('subclasses must override read_data()!') | [
"def",
"read_data",
"(",
"self",
")",
":",
"raise",
"NotImplementedError",
"(",
"'subclasses must override read_data()!'",
")"
] | https://github.com/zhufz/nlp_research/blob/b435319858520edcca7c0320dca3e0013087c276/tasks/task_base.py#L18-L21 | ||
TurboGears/tg2 | f40a82d016d70ce560002593b4bb8f83b57f87b3 | tg/configuration/utils.py | python | get_partial_dict | (prefix, dictionary, container_type=dict,
ignore_missing=False, pop_keys=False) | Given a dictionary and a prefix, return a Bunch, with just items
that start with prefix
The returned dictionary will have 'prefix.' stripped so::
get_partial_dict('prefix', {'prefix.xyz':1, 'prefix.zyx':2, 'xy':3})
would return::
{'xyz':1,'zyx':2} | Given a dictionary and a prefix, return a Bunch, with just items
that start with prefix | [
"Given",
"a",
"dictionary",
"and",
"a",
"prefix",
"return",
"a",
"Bunch",
"with",
"just",
"items",
"that",
"start",
"with",
"prefix"
] | def get_partial_dict(prefix, dictionary, container_type=dict,
ignore_missing=False, pop_keys=False):
"""Given a dictionary and a prefix, return a Bunch, with just items
that start with prefix
The returned dictionary will have 'prefix.' stripped so::
get_partial_dict('prefix', {'prefix.xyz':1, 'prefix.zyx':2, 'xy':3})
would return::
{'xyz':1,'zyx':2}
"""
match = prefix + "."
n = len(match)
new_dict = container_type(((key[n:], dictionary[key])
for key in dictionary
if key.startswith(match)))
if pop_keys:
for key in list(dictionary.keys()):
if key.startswith(match):
dictionary.pop(key, None)
if new_dict:
return new_dict
else:
if ignore_missing:
return {}
raise AttributeError(prefix) | [
"def",
"get_partial_dict",
"(",
"prefix",
",",
"dictionary",
",",
"container_type",
"=",
"dict",
",",
"ignore_missing",
"=",
"False",
",",
"pop_keys",
"=",
"False",
")",
":",
"match",
"=",
"prefix",
"+",
"\".\"",
"n",
"=",
"len",
"(",
"match",
")",
"new_... | https://github.com/TurboGears/tg2/blob/f40a82d016d70ce560002593b4bb8f83b57f87b3/tg/configuration/utils.py#L52-L83 | ||
brainiak/brainiak | ee093597c6c11597b0a59e95b48d2118e40394a5 | brainiak/factoranalysis/htfa.py | python | HTFA._mse_converged | (self) | Check convergence based on mean squared difference between
prior and posterior
Returns
-------
converged : boolean
Whether the parameter estimation converged.
mse : float
Mean squared error between prior and posterior. | Check convergence based on mean squared difference between
prior and posterior | [
"Check",
"convergence",
"based",
"on",
"mean",
"squared",
"difference",
"between",
"prior",
"and",
"posterior"
] | def _mse_converged(self):
"""Check convergence based on mean squared difference between
prior and posterior
Returns
-------
converged : boolean
Whether the parameter estimation converged.
mse : float
Mean squared error between prior and posterior.
"""
prior = self.global_prior_[0:self.prior_size]
posterior = self.global_posterior_[0:self.prior_size]
mse = mean_squared_error(prior, posterior,
multioutput='uniform_average')
if mse > self.threshold:
return False, mse
else:
return True, mse | [
"def",
"_mse_converged",
"(",
"self",
")",
":",
"prior",
"=",
"self",
".",
"global_prior_",
"[",
"0",
":",
"self",
".",
"prior_size",
"]",
"posterior",
"=",
"self",
".",
"global_posterior_",
"[",
"0",
":",
"self",
".",
"prior_size",
"]",
"mse",
"=",
"m... | https://github.com/brainiak/brainiak/blob/ee093597c6c11597b0a59e95b48d2118e40394a5/brainiak/factoranalysis/htfa.py#L222-L244 | ||
microsoft/nni | 31f11f51249660930824e888af0d4e022823285c | nni/experiment/experiment.py | python | Experiment.view | (experiment_id: str, port: int = 8080, non_blocking: bool = False) | View a stopped experiment.
Parameters
----------
experiment_id
The stopped experiment id.
port
The port of web UI.
non_blocking
If false, run in the foreground. If true, run in the background. | View a stopped experiment. | [
"View",
"a",
"stopped",
"experiment",
"."
] | def view(experiment_id: str, port: int = 8080, non_blocking: bool = False):
"""
View a stopped experiment.
Parameters
----------
experiment_id
The stopped experiment id.
port
The port of web UI.
non_blocking
If false, run in the foreground. If true, run in the background.
"""
experiment = Experiment._view(experiment_id)
experiment.start(port=port, debug=False)
if non_blocking:
return experiment
else:
try:
while True:
time.sleep(10)
except KeyboardInterrupt:
_logger.warning('KeyboardInterrupt detected')
finally:
experiment.stop() | [
"def",
"view",
"(",
"experiment_id",
":",
"str",
",",
"port",
":",
"int",
"=",
"8080",
",",
"non_blocking",
":",
"bool",
"=",
"False",
")",
":",
"experiment",
"=",
"Experiment",
".",
"_view",
"(",
"experiment_id",
")",
"experiment",
".",
"start",
"(",
... | https://github.com/microsoft/nni/blob/31f11f51249660930824e888af0d4e022823285c/nni/experiment/experiment.py#L234-L258 | ||
bbfamily/abu | 2de85ae57923a720dac99a545b4f856f6b87304b | abupy/IndicatorBu/ABuNDAtr.py | python | _calc_atr_from_pd | (high, low, close, time_period=14) | return atr.values | 通过atr公式手动计算atr
:param high: 最高价格序列,pd.Series或者np.array
:param low: 最低价格序列,pd.Series或者np.array
:param close: 收盘价格序列,pd.Series或者np.array
:param time_period: atr的N值默认值14,int
:return: atr值序列,np.array对象 | 通过atr公式手动计算atr
:param high: 最高价格序列,pd.Series或者np.array
:param low: 最低价格序列,pd.Series或者np.array
:param close: 收盘价格序列,pd.Series或者np.array
:param time_period: atr的N值默认值14,int
:return: atr值序列,np.array对象 | [
"通过atr公式手动计算atr",
":",
"param",
"high",
":",
"最高价格序列,pd",
".",
"Series或者np",
".",
"array",
":",
"param",
"low",
":",
"最低价格序列,pd",
".",
"Series或者np",
".",
"array",
":",
"param",
"close",
":",
"收盘价格序列,pd",
".",
"Series或者np",
".",
"array",
":",
"param",
"time... | def _calc_atr_from_pd(high, low, close, time_period=14):
"""
通过atr公式手动计算atr
:param high: 最高价格序列,pd.Series或者np.array
:param low: 最低价格序列,pd.Series或者np.array
:param close: 收盘价格序列,pd.Series或者np.array
:param time_period: atr的N值默认值14,int
:return: atr值序列,np.array对象
"""
if isinstance(close, pd.Series):
# shift(1)构成昨天收盘价格序列
pre_close = close.shift(1).values
else:
from scipy.ndimage.interpolation import shift
# 也可以暂时转换为pd.Series进行shift
pre_close = shift(close, 1)
pre_close[0] = pre_close[1]
if isinstance(high, pd.Series):
high = high.values
if isinstance(low, pd.Series):
low = low.values
# ∣最高价 - 最低价∣
tr_hl = np.abs(high - low)
# ∣最高价 - 昨收∣
tr_hc = np.abs(high - pre_close)
# ∣昨收 - 最低价∣
tr_cl = np.abs(pre_close - low)
# TR =∣最高价 - 最低价∣,∣最高价 - 昨收∣,∣昨收 - 最低价∣中的最大值
tr = np.maximum(np.maximum(tr_hl, tr_hc), tr_cl)
# (ATR)= MA(TR, N)(TR的N日简单移动平均), 这里没有完全按照标准公式使用简单移动平均,使用了pd_ewm_mean,即加权移动平均
atr = pd_ewm_mean(pd.Series(tr), span=time_period, min_periods=1)
# 返回atr值序列,np.array对象
return atr.values | [
"def",
"_calc_atr_from_pd",
"(",
"high",
",",
"low",
",",
"close",
",",
"time_period",
"=",
"14",
")",
":",
"if",
"isinstance",
"(",
"close",
",",
"pd",
".",
"Series",
")",
":",
"# shift(1)构成昨天收盘价格序列",
"pre_close",
"=",
"close",
".",
"shift",
"(",
"1",
... | https://github.com/bbfamily/abu/blob/2de85ae57923a720dac99a545b4f856f6b87304b/abupy/IndicatorBu/ABuNDAtr.py#L51-L85 | |
JaniceWuo/MovieRecommend | 4c86db64ca45598917d304f535413df3bc9fea65 | movierecommend/venv1/Lib/site-packages/pip-9.0.1-py3.6.egg/pip/_vendor/packaging/_structures.py | python | Infinity.__ne__ | (self, other) | return not isinstance(other, self.__class__) | [] | def __ne__(self, other):
return not isinstance(other, self.__class__) | [
"def",
"__ne__",
"(",
"self",
",",
"other",
")",
":",
"return",
"not",
"isinstance",
"(",
"other",
",",
"self",
".",
"__class__",
")"
] | https://github.com/JaniceWuo/MovieRecommend/blob/4c86db64ca45598917d304f535413df3bc9fea65/movierecommend/venv1/Lib/site-packages/pip-9.0.1-py3.6.egg/pip/_vendor/packaging/_structures.py#L24-L25 | |||
samuelclay/NewsBlur | 2c45209df01a1566ea105e04d499367f32ac9ad2 | utils/image_functions.py | python | ImageOps.image_size | (cls, url, headers=None) | return None, None | [] | def image_size(cls, url, headers=None):
if not headers: headers = {}
req = urllib.request.Request(url, data=None, headers=headers)
file = urllib.request.urlopen(req)
size = file.headers.get("content-length")
if size:
size = int(size)
p = ImageFile.Parser()
while True:
data = file.read(1024)
if not data:
break
p.feed(data)
if p.image:
return p.image.size
break
file.close()
return None, None | [
"def",
"image_size",
"(",
"cls",
",",
"url",
",",
"headers",
"=",
"None",
")",
":",
"if",
"not",
"headers",
":",
"headers",
"=",
"{",
"}",
"req",
"=",
"urllib",
".",
"request",
".",
"Request",
"(",
"url",
",",
"data",
"=",
"None",
",",
"headers",
... | https://github.com/samuelclay/NewsBlur/blob/2c45209df01a1566ea105e04d499367f32ac9ad2/utils/image_functions.py#L75-L92 | |||
xiaoyufenfei/Efficient-Segmentation-Networks | 0f0c32e7af3463d381cb184a158ff60e16f7fb9a | model/FPENet.py | python | conv3x3 | (in_planes, out_planes, stride=1, padding=1, dilation=1, groups=1, bias=False) | return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride,
padding=padding, dilation=dilation, groups=groups,bias=bias) | 3x3 convolution with padding | 3x3 convolution with padding | [
"3x3",
"convolution",
"with",
"padding"
] | def conv3x3(in_planes, out_planes, stride=1, padding=1, dilation=1, groups=1, bias=False):
"""3x3 convolution with padding"""
return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride,
padding=padding, dilation=dilation, groups=groups,bias=bias) | [
"def",
"conv3x3",
"(",
"in_planes",
",",
"out_planes",
",",
"stride",
"=",
"1",
",",
"padding",
"=",
"1",
",",
"dilation",
"=",
"1",
",",
"groups",
"=",
"1",
",",
"bias",
"=",
"False",
")",
":",
"return",
"nn",
".",
"Conv2d",
"(",
"in_planes",
",",... | https://github.com/xiaoyufenfei/Efficient-Segmentation-Networks/blob/0f0c32e7af3463d381cb184a158ff60e16f7fb9a/model/FPENet.py#L16-L19 | |
Tautulli/Tautulli | 2410eb33805aaac4bd1c5dad0f71e4f15afaf742 | lib/pyparsing/core.py | python | ParserElement.__invert__ | (self) | return NotAny(self) | Implementation of ``~`` operator - returns :class:`NotAny` | Implementation of ``~`` operator - returns :class:`NotAny` | [
"Implementation",
"of",
"~",
"operator",
"-",
"returns",
":",
"class",
":",
"NotAny"
] | def __invert__(self):
"""
Implementation of ``~`` operator - returns :class:`NotAny`
"""
return NotAny(self) | [
"def",
"__invert__",
"(",
"self",
")",
":",
"return",
"NotAny",
"(",
"self",
")"
] | https://github.com/Tautulli/Tautulli/blob/2410eb33805aaac4bd1c5dad0f71e4f15afaf742/lib/pyparsing/core.py#L1599-L1603 | |
sabri-zaki/EasY_HaCk | 2a39ac384dd0d6fc51c0dd22e8d38cece683fdb9 | .modules/.metagoofil/hachoir_metadata/image.py | python | computeComprRate | (meta, compr_size) | Compute image compression rate. Skip size of color palette, focus on
image pixels. Original size is width x height x bpp. Compressed size
is an argument (in bits).
Set "compr_data" with a string like "1.52x". | Compute image compression rate. Skip size of color palette, focus on
image pixels. Original size is width x height x bpp. Compressed size
is an argument (in bits). | [
"Compute",
"image",
"compression",
"rate",
".",
"Skip",
"size",
"of",
"color",
"palette",
"focus",
"on",
"image",
"pixels",
".",
"Original",
"size",
"is",
"width",
"x",
"height",
"x",
"bpp",
".",
"Compressed",
"size",
"is",
"an",
"argument",
"(",
"in",
"... | def computeComprRate(meta, compr_size):
"""
Compute image compression rate. Skip size of color palette, focus on
image pixels. Original size is width x height x bpp. Compressed size
is an argument (in bits).
Set "compr_data" with a string like "1.52x".
"""
if not meta.has("width") \
or not meta.has("height") \
or not meta.has("bits_per_pixel"):
return
if not compr_size:
return
orig_size = meta.get('width') * meta.get('height') * meta.get('bits_per_pixel')
meta.compr_rate = float(orig_size) / compr_size | [
"def",
"computeComprRate",
"(",
"meta",
",",
"compr_size",
")",
":",
"if",
"not",
"meta",
".",
"has",
"(",
"\"width\"",
")",
"or",
"not",
"meta",
".",
"has",
"(",
"\"height\"",
")",
"or",
"not",
"meta",
".",
"has",
"(",
"\"bits_per_pixel\"",
")",
":",
... | https://github.com/sabri-zaki/EasY_HaCk/blob/2a39ac384dd0d6fc51c0dd22e8d38cece683fdb9/.modules/.metagoofil/hachoir_metadata/image.py#L11-L26 | ||
qiucheng025/zao- | 3a5edf3607b3a523f95746bc69b688090c76d89a | tools/lib_alignments/jobs_manual.py | python | MouseHandler.check_click_location | (self, pt_x, pt_y) | Check whether the point clicked is within an existing
bounding box and set face_id | Check whether the point clicked is within an existing
bounding box and set face_id | [
"Check",
"whether",
"the",
"point",
"clicked",
"is",
"within",
"an",
"existing",
"bounding",
"box",
"and",
"set",
"face_id"
] | def check_click_location(self, pt_x, pt_y):
""" Check whether the point clicked is within an existing
bounding box and set face_id """
frame = self.media["frame_id"]
alignments = self.alignments.get_faces_in_frame(frame)
scale = self.interface.get_frame_scaling()
pt_x = int(pt_x / scale)
pt_y = int(pt_y / scale)
for idx, alignment in enumerate(alignments):
left = alignment["x"]
right = alignment["x"] + alignment["w"]
top = alignment["y"]
bottom = alignment["y"] + alignment["h"]
if left <= pt_x <= right and top <= pt_y <= bottom:
self.interface.set_state_value("edit", "selected", idx)
break | [
"def",
"check_click_location",
"(",
"self",
",",
"pt_x",
",",
"pt_y",
")",
":",
"frame",
"=",
"self",
".",
"media",
"[",
"\"frame_id\"",
"]",
"alignments",
"=",
"self",
".",
"alignments",
".",
"get_faces_in_frame",
"(",
"frame",
")",
"scale",
"=",
"self",
... | https://github.com/qiucheng025/zao-/blob/3a5edf3607b3a523f95746bc69b688090c76d89a/tools/lib_alignments/jobs_manual.py#L899-L916 | ||
triaquae/triaquae | bbabf736b3ba56a0c6498e7f04e16c13b8b8f2b9 | TriAquae/models/Ubuntu_13/paramiko/rsakey.py | python | RSAKey.__init__ | (self, msg=None, data=None, filename=None, password=None, vals=None, file_obj=None) | [] | def __init__(self, msg=None, data=None, filename=None, password=None, vals=None, file_obj=None):
self.n = None
self.e = None
self.d = None
self.p = None
self.q = None
if file_obj is not None:
self._from_private_key(file_obj, password)
return
if filename is not None:
self._from_private_key_file(filename, password)
return
if (msg is None) and (data is not None):
msg = Message(data)
if vals is not None:
self.e, self.n = vals
else:
if msg is None:
raise SSHException('Key object may not be empty')
if msg.get_string() != 'ssh-rsa':
raise SSHException('Invalid key')
self.e = msg.get_mpint()
self.n = msg.get_mpint()
self.size = util.bit_length(self.n) | [
"def",
"__init__",
"(",
"self",
",",
"msg",
"=",
"None",
",",
"data",
"=",
"None",
",",
"filename",
"=",
"None",
",",
"password",
"=",
"None",
",",
"vals",
"=",
"None",
",",
"file_obj",
"=",
"None",
")",
":",
"self",
".",
"n",
"=",
"None",
"self"... | https://github.com/triaquae/triaquae/blob/bbabf736b3ba56a0c6498e7f04e16c13b8b8f2b9/TriAquae/models/Ubuntu_13/paramiko/rsakey.py#L41-L64 | ||||
kkroening/ffmpeg-python | f3079726fae7b7b71e4175f79c5eeaddc1d205fb | ffmpeg/_filters.py | python | asplit | (stream) | return FilterNode(stream, asplit.__name__) | [] | def asplit(stream):
return FilterNode(stream, asplit.__name__) | [
"def",
"asplit",
"(",
"stream",
")",
":",
"return",
"FilterNode",
"(",
"stream",
",",
"asplit",
".",
"__name__",
")"
] | https://github.com/kkroening/ffmpeg-python/blob/f3079726fae7b7b71e4175f79c5eeaddc1d205fb/ffmpeg/_filters.py#L66-L67 | |||
pypa/pip | 7f8a6844037fb7255cfd0d34ff8e8cf44f2598d4 | src/pip/_vendor/rich/progress.py | python | Progress.get_renderable | (self) | return renderable | Get a renderable for the progress display. | Get a renderable for the progress display. | [
"Get",
"a",
"renderable",
"for",
"the",
"progress",
"display",
"."
] | def get_renderable(self) -> RenderableType:
"""Get a renderable for the progress display."""
renderable = Group(*self.get_renderables())
return renderable | [
"def",
"get_renderable",
"(",
"self",
")",
"->",
"RenderableType",
":",
"renderable",
"=",
"Group",
"(",
"*",
"self",
".",
"get_renderables",
"(",
")",
")",
"return",
"renderable"
] | https://github.com/pypa/pip/blob/7f8a6844037fb7255cfd0d34ff8e8cf44f2598d4/src/pip/_vendor/rich/progress.py#L868-L871 | |
dimagi/commcare-hq | d67ff1d3b4c51fa050c19e60c3253a79d3452a39 | corehq/apps/export/models/new.py | python | ExportInstance.wrap | (cls, data) | return export_instance | [] | def wrap(cls, data):
from corehq.apps.export.views.utils import clean_odata_columns
export_instance = super(ExportInstance, cls).wrap(data)
if export_instance.is_odata_config:
clean_odata_columns(export_instance)
return export_instance | [
"def",
"wrap",
"(",
"cls",
",",
"data",
")",
":",
"from",
"corehq",
".",
"apps",
".",
"export",
".",
"views",
".",
"utils",
"import",
"clean_odata_columns",
"export_instance",
"=",
"super",
"(",
"ExportInstance",
",",
"cls",
")",
".",
"wrap",
"(",
"data"... | https://github.com/dimagi/commcare-hq/blob/d67ff1d3b4c51fa050c19e60c3253a79d3452a39/corehq/apps/export/models/new.py#L793-L798 | |||
fake-name/ReadableWebProxy | ed5c7abe38706acc2684a1e6cd80242a03c5f010 | WebMirror/management/DbManage.py | python | exposed_reset_walk_epochs | () | Set the walk epoch for all rows in the table to zero
Useful when the walk interval has been changed to a larger value, as this can cause the
next rewalk to be pushed far out into the future and block re-fetching for far longer then intended | Set the walk epoch for all rows in the table to zero | [
"Set",
"the",
"walk",
"epoch",
"for",
"all",
"rows",
"in",
"the",
"table",
"to",
"zero"
] | def exposed_reset_walk_epochs():
'''
Set the walk epoch for all rows in the table to zero
Useful when the walk interval has been changed to a larger value, as this can cause the
next rewalk to be pushed far out into the future and block re-fetching for far longer then intended
'''
commit_interval = 10000
step = 50000
commit_every = 30
last_commit = time.time()
with db.session_context(override_timeout_ms=60 * 1000 * 15) as sess:
try:
# sess.execute('''SET enable_bitmapscan TO off;''')
print("Getting minimum row in need or update..")
start = sess.execute("""SELECT min(id), max(id) FROM web_pages WHERE epoch <> 0""")
# start = sess.execute("""SELECT min(id) FROM web_pages WHERE (state = 'fetching' OR state = 'processing') OR state = 'specialty_deferred' OR state = 'specialty_ready'""")
start, stop = list(start)[0]
if start is None:
print("No rows to reset!")
return
print("Minimum row ID: ", start, "Maximum row ID: ", stop)
print("Need to fix rows from %s to %s" % (start, stop))
start = start - (start % step)
changed = 0
tot_changed = 0
# for idx in range(start, stop, step):
for idx in tqdm.tqdm(range(start, stop, step), desc="Resetting Epochs"):
try:
# SQL String munging! I'm a bad person!
# Only done because I can't easily find how to make sqlalchemy
# bind parameters ignore the postgres specific cast
# The id range forces the query planner to use a much smarter approach which is much more performant for small numbers of updates
have = sess.execute("""UPDATE
web_pages
SET
epoch = 0
WHERE
epoch <> 0
AND
id > {}
AND
id <= {}
;""".format(idx, idx+step))
# processed = idx - start
# total_todo = stop - start
# print('\r%10i, %10i, %7.4f, %6i, %8i\r' % (idx, stop, processed/total_todo * 100, have.rowcount, tot_changed), end="", flush=True)
changed += have.rowcount
tot_changed += have.rowcount
if changed > commit_interval:
print("Committing (%s changed rows)...." % changed, end=' ')
sess.commit()
print("done")
changed = 0
last_commit = time.time()
if time.time() > last_commit + commit_every:
last_commit = time.time()
print("Committing (%s changed rows, timed out)...." % changed, end=' ')
sess.commit()
print("done")
changed = 0
except sqlalchemy.exc.OperationalError:
sess.rollback()
except sqlalchemy.exc.InvalidRequestError:
sess.rollback()
sess.commit()
finally:
pass | [
"def",
"exposed_reset_walk_epochs",
"(",
")",
":",
"commit_interval",
"=",
"10000",
"step",
"=",
"50000",
"commit_every",
"=",
"30",
"last_commit",
"=",
"time",
".",
"time",
"(",
")",
"with",
"db",
".",
"session_context",
"(",
"override_timeout_ms",
"=",
"60",... | https://github.com/fake-name/ReadableWebProxy/blob/ed5c7abe38706acc2684a1e6cd80242a03c5f010/WebMirror/management/DbManage.py#L289-L368 | ||
tp4a/teleport | 1fafd34f1f775d2cf80ea4af6e44468d8e0b24ad | server/www/packages/packages-darwin/x64/pyasn1/type/univ.py | python | SequenceAndSetBase.getNameByPosition | (self, idx) | [] | def getNameByPosition(self, idx):
if self._componentTypeLen:
return self.componentType[idx].name | [
"def",
"getNameByPosition",
"(",
"self",
",",
"idx",
")",
":",
"if",
"self",
".",
"_componentTypeLen",
":",
"return",
"self",
".",
"componentType",
"[",
"idx",
"]",
".",
"name"
] | https://github.com/tp4a/teleport/blob/1fafd34f1f775d2cf80ea4af6e44468d8e0b24ad/server/www/packages/packages-darwin/x64/pyasn1/type/univ.py#L2494-L2496 | ||||
openshift/openshift-tools | 1188778e728a6e4781acf728123e5b356380fe6f | openshift/installer/vendored/openshift-ansible-3.10.0-0.29.0/roles/lib_vendored_deps/library/oc_configmap.py | python | Yedit.exists | (self, path, value) | return entry == value | check if value exists at path | check if value exists at path | [
"check",
"if",
"value",
"exists",
"at",
"path"
] | def exists(self, path, value):
''' check if value exists at path'''
try:
entry = Yedit.get_entry(self.yaml_dict, path, self.separator)
except KeyError:
entry = None
if isinstance(entry, list):
if value in entry:
return True
return False
elif isinstance(entry, dict):
if isinstance(value, dict):
rval = False
for key, val in value.items():
if entry[key] != val:
rval = False
break
else:
rval = True
return rval
return value in entry
return entry == value | [
"def",
"exists",
"(",
"self",
",",
"path",
",",
"value",
")",
":",
"try",
":",
"entry",
"=",
"Yedit",
".",
"get_entry",
"(",
"self",
".",
"yaml_dict",
",",
"path",
",",
"self",
".",
"separator",
")",
"except",
"KeyError",
":",
"entry",
"=",
"None",
... | https://github.com/openshift/openshift-tools/blob/1188778e728a6e4781acf728123e5b356380fe6f/openshift/installer/vendored/openshift-ansible-3.10.0-0.29.0/roles/lib_vendored_deps/library/oc_configmap.py#L498-L523 | |
autotest/autotest | 4614ae5f550cc888267b9a419e4b90deb54f8fae | client/shared/utils.py | python | configure | (extra=None, configure='./configure') | Run configure passing in the correct host, build, and target options.
:param extra: extra command line arguments to pass to configure
:param configure: which configure script to use | Run configure passing in the correct host, build, and target options. | [
"Run",
"configure",
"passing",
"in",
"the",
"correct",
"host",
"build",
"and",
"target",
"options",
"."
] | def configure(extra=None, configure='./configure'):
"""
Run configure passing in the correct host, build, and target options.
:param extra: extra command line arguments to pass to configure
:param configure: which configure script to use
"""
args = []
if 'CHOST' in os.environ:
args.append('--host=' + os.environ['CHOST'])
if 'CBUILD' in os.environ:
args.append('--build=' + os.environ['CBUILD'])
if 'CTARGET' in os.environ:
args.append('--target=' + os.environ['CTARGET'])
if extra:
args.append(extra)
system('%s %s' % (configure, ' '.join(args))) | [
"def",
"configure",
"(",
"extra",
"=",
"None",
",",
"configure",
"=",
"'./configure'",
")",
":",
"args",
"=",
"[",
"]",
"if",
"'CHOST'",
"in",
"os",
".",
"environ",
":",
"args",
".",
"append",
"(",
"'--host='",
"+",
"os",
".",
"environ",
"[",
"'CHOST... | https://github.com/autotest/autotest/blob/4614ae5f550cc888267b9a419e4b90deb54f8fae/client/shared/utils.py#L2029-L2046 | ||
sahana/eden | 1696fa50e90ce967df69f66b571af45356cc18da | modules/pygsm/scanlinux.py | python | scan | () | return glob.glob('/dev/ttyS*') + glob.glob('/dev/ttyUSB*') | scan for available ports. return a list of device names. | scan for available ports. return a list of device names. | [
"scan",
"for",
"available",
"ports",
".",
"return",
"a",
"list",
"of",
"device",
"names",
"."
] | def scan():
"""scan for available ports. return a list of device names."""
return glob.glob('/dev/ttyS*') + glob.glob('/dev/ttyUSB*') | [
"def",
"scan",
"(",
")",
":",
"return",
"glob",
".",
"glob",
"(",
"'/dev/ttyS*'",
")",
"+",
"glob",
".",
"glob",
"(",
"'/dev/ttyUSB*'",
")"
] | https://github.com/sahana/eden/blob/1696fa50e90ce967df69f66b571af45356cc18da/modules/pygsm/scanlinux.py#L13-L15 | |
kennethreitz/bake | 3ee3d0ba2e7134035de01b803058e0d6033c00b2 | bake/bakefile.py | python | Bakefile.iter_root_source_lines | (self) | The source of the 'root level' of the Bashfile. | The source of the 'root level' of the Bashfile. | [
"The",
"source",
"of",
"the",
"root",
"level",
"of",
"the",
"Bashfile",
"."
] | def iter_root_source_lines(self):
"""The source of the 'root level' of the Bashfile."""
task_active = False
for line in self.source_lines:
if line:
if self._is_declaration_line(line):
task_active = True
else:
if not self._is_task_line(line):
task_active = False
if not task_active:
yield line | [
"def",
"iter_root_source_lines",
"(",
"self",
")",
":",
"task_active",
"=",
"False",
"for",
"line",
"in",
"self",
".",
"source_lines",
":",
"if",
"line",
":",
"if",
"self",
".",
"_is_declaration_line",
"(",
"line",
")",
":",
"task_active",
"=",
"True",
"el... | https://github.com/kennethreitz/bake/blob/3ee3d0ba2e7134035de01b803058e0d6033c00b2/bake/bakefile.py#L220-L232 | ||
huggingface/transformers | 623b4f7c63f60cce917677ee704d6c93ee960b4b | src/transformers/models/m2m_100/tokenization_m2m_100.py | python | M2M100Tokenizer.save_vocabulary | (self, save_directory: str, filename_prefix: Optional[str] = None) | return (str(vocab_save_path), str(spm_save_path)) | [] | def save_vocabulary(self, save_directory: str, filename_prefix: Optional[str] = None) -> Tuple[str]:
save_dir = Path(save_directory)
assert save_dir.is_dir(), f"{save_directory} should be a directory"
vocab_save_path = save_dir / (
(filename_prefix + "-" if filename_prefix else "") + self.vocab_files_names["vocab_file"]
)
spm_save_path = save_dir / (
(filename_prefix + "-" if filename_prefix else "") + self.vocab_files_names["spm_file"]
)
save_json(self.encoder, vocab_save_path)
if not spm_save_path.exists():
copyfile(self.spm_file, spm_save_path)
return (str(vocab_save_path), str(spm_save_path)) | [
"def",
"save_vocabulary",
"(",
"self",
",",
"save_directory",
":",
"str",
",",
"filename_prefix",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
")",
"->",
"Tuple",
"[",
"str",
"]",
":",
"save_dir",
"=",
"Path",
"(",
"save_directory",
")",
"assert",
"sav... | https://github.com/huggingface/transformers/blob/623b4f7c63f60cce917677ee704d6c93ee960b4b/src/transformers/models/m2m_100/tokenization_m2m_100.py#L303-L318 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.