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
rowanz/r2c
77813d9e335711759c25df79c348a7c2a8275d72
data/get_bert_embeddings/tokenization.py
python
_is_punctuation
(char)
return False
Checks whether `chars` is a punctuation character.
Checks whether `chars` is a punctuation character.
[ "Checks", "whether", "chars", "is", "a", "punctuation", "character", "." ]
def _is_punctuation(char): """Checks whether `chars` is a punctuation character.""" cp = ord(char) # We treat all non-letter/number ASCII as punctuation. # Characters such as "^", "$", and "`" are not in the Unicode # Punctuation class but we treat them as punctuation anyways, for # consistency. if ((cp >= 33 and cp <= 47) or (cp >= 58 and cp <= 64) or (cp >= 91 and cp <= 96) or (cp >= 123 and cp <= 126)): return True cat = unicodedata.category(char) if cat.startswith("P"): return True return False
[ "def", "_is_punctuation", "(", "char", ")", ":", "cp", "=", "ord", "(", "char", ")", "# We treat all non-letter/number ASCII as punctuation.", "# Characters such as \"^\", \"$\", and \"`\" are not in the Unicode", "# Punctuation class but we treat them as punctuation anyways, for", "# ...
https://github.com/rowanz/r2c/blob/77813d9e335711759c25df79c348a7c2a8275d72/data/get_bert_embeddings/tokenization.py#L269-L282
hplgit/num-methods-for-PDEs
41ff6f83467c3a7a2dd51f9e68182600f6b74800
src/softeng1/decay.py
python
exact_discrete_solution
(n, I, a, theta, dt)
return I*A**n
Return exact discrete solution of the numerical schemes.
Return exact discrete solution of the numerical schemes.
[ "Return", "exact", "discrete", "solution", "of", "the", "numerical", "schemes", "." ]
def exact_discrete_solution(n, I, a, theta, dt): """Return exact discrete solution of the numerical schemes.""" dt = float(dt) # avoid integer division A = (1 - (1-theta)*a*dt)/(1 + theta*dt*a) return I*A**n
[ "def", "exact_discrete_solution", "(", "n", ",", "I", ",", "a", ",", "theta", ",", "dt", ")", ":", "dt", "=", "float", "(", "dt", ")", "# avoid integer division", "A", "=", "(", "1", "-", "(", "1", "-", "theta", ")", "*", "a", "*", "dt", ")", "...
https://github.com/hplgit/num-methods-for-PDEs/blob/41ff6f83467c3a7a2dd51f9e68182600f6b74800/src/softeng1/decay.py#L221-L225
IronLanguages/ironpython3
7a7bb2a872eeab0d1009fc8a6e24dca43f65b693
Src/StdLib/Lib/pathlib.py
python
Path.is_fifo
(self)
Whether this path is a FIFO.
Whether this path is a FIFO.
[ "Whether", "this", "path", "is", "a", "FIFO", "." ]
def is_fifo(self): """ Whether this path is a FIFO. """ try: return S_ISFIFO(self.stat().st_mode) except OSError as e: if e.errno not in (ENOENT, ENOTDIR): raise # Path doesn't exist or is a broken symlink # (see https://bitbucket.org/pitrou/pathlib/issue/12/) return False
[ "def", "is_fifo", "(", "self", ")", ":", "try", ":", "return", "S_ISFIFO", "(", "self", ".", "stat", "(", ")", ".", "st_mode", ")", "except", "OSError", "as", "e", ":", "if", "e", ".", "errno", "not", "in", "(", "ENOENT", ",", "ENOTDIR", ")", ":"...
https://github.com/IronLanguages/ironpython3/blob/7a7bb2a872eeab0d1009fc8a6e24dca43f65b693/Src/StdLib/Lib/pathlib.py#L1273-L1284
pyg-team/pytorch_geometric
b920e9a3a64e22c8356be55301c88444ff051cae
torch_geometric/nn/models/tgn.py
python
TimeEncoder.forward
(self, t)
return self.lin(t.view(-1, 1)).cos()
[]
def forward(self, t): return self.lin(t.view(-1, 1)).cos()
[ "def", "forward", "(", "self", ",", "t", ")", ":", "return", "self", ".", "lin", "(", "t", ".", "view", "(", "-", "1", ",", "1", ")", ")", ".", "cos", "(", ")" ]
https://github.com/pyg-team/pytorch_geometric/blob/b920e9a3a64e22c8356be55301c88444ff051cae/torch_geometric/nn/models/tgn.py#L207-L208
openmc-dev/openmc
0cf7d9283786677e324bfbdd0984a54d1c86dacc
openmc/filter.py
python
MeshSurfaceFilter.get_pandas_dataframe
(self, data_size, stride, **kwargs)
return pd.concat([df, pd.DataFrame(filter_dict)])
Builds a Pandas DataFrame for the Filter's bins. This method constructs a Pandas DataFrame object for the filter with columns annotated by filter bin information. This is a helper method for :meth:`Tally.get_pandas_dataframe`. Parameters ---------- data_size : int The total number of bins in the tally corresponding to this filter stride : int Stride in memory for the filter Returns ------- pandas.DataFrame A Pandas DataFrame with three columns describing the x,y,z mesh cell indices corresponding to each filter bin. The number of rows in the DataFrame is the same as the total number of bins in the corresponding tally, with the filter bin appropriately tiled to map to the corresponding tally bins. See also -------- Tally.get_pandas_dataframe(), CrossFilter.get_pandas_dataframe()
Builds a Pandas DataFrame for the Filter's bins.
[ "Builds", "a", "Pandas", "DataFrame", "for", "the", "Filter", "s", "bins", "." ]
def get_pandas_dataframe(self, data_size, stride, **kwargs): """Builds a Pandas DataFrame for the Filter's bins. This method constructs a Pandas DataFrame object for the filter with columns annotated by filter bin information. This is a helper method for :meth:`Tally.get_pandas_dataframe`. Parameters ---------- data_size : int The total number of bins in the tally corresponding to this filter stride : int Stride in memory for the filter Returns ------- pandas.DataFrame A Pandas DataFrame with three columns describing the x,y,z mesh cell indices corresponding to each filter bin. The number of rows in the DataFrame is the same as the total number of bins in the corresponding tally, with the filter bin appropriately tiled to map to the corresponding tally bins. See also -------- Tally.get_pandas_dataframe(), CrossFilter.get_pandas_dataframe() """ # Initialize Pandas DataFrame df = pd.DataFrame() # Initialize dictionary to build Pandas Multi-index column filter_dict = {} # Append mesh ID as outermost index of multi-index mesh_key = f'mesh {self.mesh.id}' # Find mesh dimensions - use 3D indices for simplicity n_surfs = 4 * len(self.mesh.dimension) if len(self.mesh.dimension) == 3: nx, ny, nz = self.mesh.dimension elif len(self.mesh.dimension) == 2: nx, ny = self.mesh.dimension nz = 1 else: nx = self.mesh.dimension ny = nz = 1 # Generate multi-index sub-column for x-axis filter_dict[mesh_key, 'x'] = _repeat_and_tile( np.arange(1, nx + 1), n_surfs * stride, data_size) # Generate multi-index sub-column for y-axis if len(self.mesh.dimension) > 1: filter_dict[mesh_key, 'y'] = _repeat_and_tile( np.arange(1, ny + 1), n_surfs * nx * stride, data_size) # Generate multi-index sub-column for z-axis if len(self.mesh.dimension) > 2: filter_dict[mesh_key, 'z'] = _repeat_and_tile( np.arange(1, nz + 1), n_surfs * nx * ny * stride, data_size) # Generate multi-index sub-column for surface filter_dict[mesh_key, 'surf'] = _repeat_and_tile( _CURRENT_NAMES[:n_surfs], stride, data_size) # Initialize a Pandas DataFrame from the mesh dictionary return pd.concat([df, pd.DataFrame(filter_dict)])
[ "def", "get_pandas_dataframe", "(", "self", ",", "data_size", ",", "stride", ",", "*", "*", "kwargs", ")", ":", "# Initialize Pandas DataFrame", "df", "=", "pd", ".", "DataFrame", "(", ")", "# Initialize dictionary to build Pandas Multi-index column", "filter_dict", "...
https://github.com/openmc-dev/openmc/blob/0cf7d9283786677e324bfbdd0984a54d1c86dacc/openmc/filter.py#L922-L989
mdiazcl/fuzzbunch-debian
2b76c2249ade83a389ae3badb12a1bd09901fd2c
windows/Resources/Python/Core/Lib/multiprocessing/managers.py
python
Server.serve_forever
(self)
Run the server forever
Run the server forever
[ "Run", "the", "server", "forever" ]
def serve_forever(self): """ Run the server forever """ current_process()._manager_server = self try: try: while 1: try: c = self.listener.accept() except (OSError, IOError): continue t = threading.Thread(target=self.handle_request, args=(c,)) t.daemon = True t.start() except (KeyboardInterrupt, SystemExit): pass finally: self.stop = 999 self.listener.close()
[ "def", "serve_forever", "(", "self", ")", ":", "current_process", "(", ")", ".", "_manager_server", "=", "self", "try", ":", "try", ":", "while", "1", ":", "try", ":", "c", "=", "self", ".", "listener", ".", "accept", "(", ")", "except", "(", "OSErro...
https://github.com/mdiazcl/fuzzbunch-debian/blob/2b76c2249ade83a389ae3badb12a1bd09901fd2c/windows/Resources/Python/Core/Lib/multiprocessing/managers.py#L121-L143
inspurer/WorkAttendanceSystem
1221e2d67bdf5bb15fe99517cc3ded58ccb066df
V2.0/venv/Lib/site-packages/pip-9.0.1-py3.5.egg/pip/utils/__init__.py
python
captured_stdout
()
return captured_output('stdout')
Capture the output of sys.stdout: with captured_stdout() as stdout: print('hello') self.assertEqual(stdout.getvalue(), 'hello\n') Taken from Lib/support/__init__.py in the CPython repo.
Capture the output of sys.stdout:
[ "Capture", "the", "output", "of", "sys", ".", "stdout", ":" ]
def captured_stdout(): """Capture the output of sys.stdout: with captured_stdout() as stdout: print('hello') self.assertEqual(stdout.getvalue(), 'hello\n') Taken from Lib/support/__init__.py in the CPython repo. """ return captured_output('stdout')
[ "def", "captured_stdout", "(", ")", ":", "return", "captured_output", "(", "'stdout'", ")" ]
https://github.com/inspurer/WorkAttendanceSystem/blob/1221e2d67bdf5bb15fe99517cc3ded58ccb066df/V2.0/venv/Lib/site-packages/pip-9.0.1-py3.5.egg/pip/utils/__init__.py#L798-L807
scikit-learn/scikit-learn
1d1aadd0711b87d2a11c80aad15df6f8cf156712
sklearn/neural_network/_base.py
python
log_loss
(y_true, y_prob)
return -xlogy(y_true, y_prob).sum() / y_prob.shape[0]
Compute Logistic loss for classification. Parameters ---------- y_true : array-like or label indicator matrix Ground truth (correct) labels. y_prob : array-like of float, shape = (n_samples, n_classes) Predicted probabilities, as returned by a classifier's predict_proba method. Returns ------- loss : float The degree to which the samples are correctly predicted.
Compute Logistic loss for classification.
[ "Compute", "Logistic", "loss", "for", "classification", "." ]
def log_loss(y_true, y_prob): """Compute Logistic loss for classification. Parameters ---------- y_true : array-like or label indicator matrix Ground truth (correct) labels. y_prob : array-like of float, shape = (n_samples, n_classes) Predicted probabilities, as returned by a classifier's predict_proba method. Returns ------- loss : float The degree to which the samples are correctly predicted. """ eps = np.finfo(y_prob.dtype).eps y_prob = np.clip(y_prob, eps, 1 - eps) if y_prob.shape[1] == 1: y_prob = np.append(1 - y_prob, y_prob, axis=1) if y_true.shape[1] == 1: y_true = np.append(1 - y_true, y_true, axis=1) return -xlogy(y_true, y_prob).sum() / y_prob.shape[0]
[ "def", "log_loss", "(", "y_true", ",", "y_prob", ")", ":", "eps", "=", "np", ".", "finfo", "(", "y_prob", ".", "dtype", ")", ".", "eps", "y_prob", "=", "np", ".", "clip", "(", "y_prob", ",", "eps", ",", "1", "-", "eps", ")", "if", "y_prob", "."...
https://github.com/scikit-learn/scikit-learn/blob/1d1aadd0711b87d2a11c80aad15df6f8cf156712/sklearn/neural_network/_base.py#L177-L202
reahl/reahl
86aac47c3a9b5b98e9f77dad4939034a02d54d46
reahl-tofu/reahl/tofu/files.py
python
temp_file_name
()
return temp_file.name
Returns a name that may be used for a temporary file that may be created and removed by a programmer.
Returns a name that may be used for a temporary file that may be created and removed by a programmer.
[ "Returns", "a", "name", "that", "may", "be", "used", "for", "a", "temporary", "file", "that", "may", "be", "created", "and", "removed", "by", "a", "programmer", "." ]
def temp_file_name(): """Returns a name that may be used for a temporary file that may be created and removed by a programmer.""" temp_file = tempfile.NamedTemporaryFile() temp_file.close() return temp_file.name
[ "def", "temp_file_name", "(", ")", ":", "temp_file", "=", "tempfile", ".", "NamedTemporaryFile", "(", ")", "temp_file", ".", "close", "(", ")", "return", "temp_file", ".", "name" ]
https://github.com/reahl/reahl/blob/86aac47c3a9b5b98e9f77dad4939034a02d54d46/reahl-tofu/reahl/tofu/files.py#L141-L145
ipython/ipython
c0abea7a6dfe52c1f74c9d0387d4accadba7cc14
docs/sphinxext/apigen.py
python
ApiDocWriter._parse_module
(self, uri)
return FuncClsScanner().scan(mod)
Parse module defined in *uri*
Parse module defined in *uri*
[ "Parse", "module", "defined", "in", "*", "uri", "*" ]
def _parse_module(self, uri): ''' Parse module defined in *uri* ''' filename = self._uri2path(uri) if filename is None: # nothing that we could handle here. return ([],[]) with open(filename, 'rb') as f: mod = ast.parse(f.read()) return FuncClsScanner().scan(mod)
[ "def", "_parse_module", "(", "self", ",", "uri", ")", ":", "filename", "=", "self", ".", "_uri2path", "(", "uri", ")", "if", "filename", "is", "None", ":", "# nothing that we could handle here.", "return", "(", "[", "]", ",", "[", "]", ")", "with", "open...
https://github.com/ipython/ipython/blob/c0abea7a6dfe52c1f74c9d0387d4accadba7cc14/docs/sphinxext/apigen.py#L207-L215
robertkrimen/gist-it
e4e67336df783ae4626fc73805a1fd52bc299012
pyl/jinja2/environment.py
python
Environment._compile
(self, source, filename)
return compile(source, filename, 'exec')
Internal hook that can be overriden to hook a different compile method in. .. versionadded:: 2.5
Internal hook that can be overriden to hook a different compile method in.
[ "Internal", "hook", "that", "can", "be", "overriden", "to", "hook", "a", "different", "compile", "method", "in", "." ]
def _compile(self, source, filename): """Internal hook that can be overriden to hook a different compile method in. .. versionadded:: 2.5 """ return compile(source, filename, 'exec')
[ "def", "_compile", "(", "self", ",", "source", ",", "filename", ")", ":", "return", "compile", "(", "source", ",", "filename", ",", "'exec'", ")" ]
https://github.com/robertkrimen/gist-it/blob/e4e67336df783ae4626fc73805a1fd52bc299012/pyl/jinja2/environment.py#L445-L451
lixinsu/RCZoo
37fcb7962fbd4c751c561d4a0c84173881ea8339
reader/bidafv1/utils.py
python
Timer.time
(self)
return self.total
[]
def time(self): if self.running: return self.total + time.time() - self.start return self.total
[ "def", "time", "(", "self", ")", ":", "if", "self", ".", "running", ":", "return", "self", ".", "total", "+", "time", ".", "time", "(", ")", "-", "self", ".", "start", "return", "self", ".", "total" ]
https://github.com/lixinsu/RCZoo/blob/37fcb7962fbd4c751c561d4a0c84173881ea8339/reader/bidafv1/utils.py#L334-L337
qutip/qutip
52d01da181a21b810c3407812c670f35fdc647e8
qutip/qobj.py
python
Qobj.norm
(self, norm=None, sparse=False, tol=0, maxiter=100000)
Norm of a quantum object. Default norm is L2-norm for kets and trace-norm for operators. Other ket and operator norms may be specified using the `norm` and argument. Parameters ---------- norm : str Which norm to use for ket/bra vectors: L2 'l2', max norm 'max', or for operators: trace 'tr', Frobius 'fro', one 'one', or max 'max'. sparse : bool Use sparse eigenvalue solver for trace norm. Other norms are not affected by this parameter. tol : float Tolerance for sparse solver (if used) for trace norm. The sparse solver may not converge if the tolerance is set too low. maxiter : int Maximum number of iterations performed by sparse solver (if used) for trace norm. Returns ------- norm : float The requested norm of the operator or state quantum object. Notes ----- The sparse eigensolver is much slower than the dense version. Use sparse only if memory requirements demand it.
Norm of a quantum object.
[ "Norm", "of", "a", "quantum", "object", "." ]
def norm(self, norm=None, sparse=False, tol=0, maxiter=100000): """Norm of a quantum object. Default norm is L2-norm for kets and trace-norm for operators. Other ket and operator norms may be specified using the `norm` and argument. Parameters ---------- norm : str Which norm to use for ket/bra vectors: L2 'l2', max norm 'max', or for operators: trace 'tr', Frobius 'fro', one 'one', or max 'max'. sparse : bool Use sparse eigenvalue solver for trace norm. Other norms are not affected by this parameter. tol : float Tolerance for sparse solver (if used) for trace norm. The sparse solver may not converge if the tolerance is set too low. maxiter : int Maximum number of iterations performed by sparse solver (if used) for trace norm. Returns ------- norm : float The requested norm of the operator or state quantum object. Notes ----- The sparse eigensolver is much slower than the dense version. Use sparse only if memory requirements demand it. """ if self.type in ['oper', 'super']: if norm is None or norm == 'tr': _op = self.data * zcsr_adjoint(self.data) vals = sp_eigs(_op, True, vecs=False, sparse=sparse, tol=tol, maxiter=maxiter) return np.sum(np.sqrt(np.abs(vals))) elif norm == 'fro': return sp_fro_norm(self.data) elif norm == 'one': return sp_one_norm(self.data) elif norm == 'max': return sp_max_norm(self.data) else: raise ValueError( "For matrices, norm must be 'tr', 'fro', 'one', or 'max'.") else: if norm is None or norm == 'l2': return sp_L2_norm(self.data) elif norm == 'max': return sp_max_norm(self.data) else: raise ValueError("For vectors, norm must be 'l2', or 'max'.")
[ "def", "norm", "(", "self", ",", "norm", "=", "None", ",", "sparse", "=", "False", ",", "tol", "=", "0", ",", "maxiter", "=", "100000", ")", ":", "if", "self", ".", "type", "in", "[", "'oper'", ",", "'super'", "]", ":", "if", "norm", "is", "Non...
https://github.com/qutip/qutip/blob/52d01da181a21b810c3407812c670f35fdc647e8/qutip/qobj.py#L946-L1005
urllib3/urllib3
f070ec2e6f6c545f40d9196e5246df10c72e48e1
dummyserver/handlers.py
python
TestingApp.encodingrequest
(self, request: httputil.HTTPServerRequest)
return Response(data, headers=headers)
Check for UA accepting gzip/deflate encoding
Check for UA accepting gzip/deflate encoding
[ "Check", "for", "UA", "accepting", "gzip", "/", "deflate", "encoding" ]
def encodingrequest(self, request: httputil.HTTPServerRequest) -> Response: "Check for UA accepting gzip/deflate encoding" data = b"hello, world!" encoding = request.headers.get("Accept-Encoding", "") headers = None if encoding == "gzip": headers = [("Content-Encoding", "gzip")] file_ = BytesIO() with contextlib.closing( gzip.GzipFile("", mode="w", fileobj=file_) ) as zipfile: zipfile.write(data) data = file_.getvalue() elif encoding == "deflate": headers = [("Content-Encoding", "deflate")] data = zlib.compress(data) elif encoding == "garbage-gzip": headers = [("Content-Encoding", "gzip")] data = b"garbage" elif encoding == "garbage-deflate": headers = [("Content-Encoding", "deflate")] data = b"garbage" return Response(data, headers=headers)
[ "def", "encodingrequest", "(", "self", ",", "request", ":", "httputil", ".", "HTTPServerRequest", ")", "->", "Response", ":", "data", "=", "b\"hello, world!\"", "encoding", "=", "request", ".", "headers", ".", "get", "(", "\"Accept-Encoding\"", ",", "\"\"", ")...
https://github.com/urllib3/urllib3/blob/f070ec2e6f6c545f40d9196e5246df10c72e48e1/dummyserver/handlers.py#L255-L277
securesystemslab/zippy
ff0e84ac99442c2c55fe1d285332cfd4e185e089
zippy/lib-python/3/xdrlib.py
python
Unpacker.unpack_array
(self, unpack_item)
return self.unpack_farray(n, unpack_item)
[]
def unpack_array(self, unpack_item): n = self.unpack_uint() return self.unpack_farray(n, unpack_item)
[ "def", "unpack_array", "(", "self", ",", "unpack_item", ")", ":", "n", "=", "self", ".", "unpack_uint", "(", ")", "return", "self", ".", "unpack_farray", "(", "n", ",", "unpack_item", ")" ]
https://github.com/securesystemslab/zippy/blob/ff0e84ac99442c2c55fe1d285332cfd4e185e089/zippy/lib-python/3/xdrlib.py#L226-L228
volatilityfoundation/community
d9fc0727266ec552bb6412142f3f31440c601664
FrankBlock/heap_analysis.py
python
HeapAnalysis.activate_chunk_preservation
(self)
Sets _preserve_chunks to True. This forces all allocated chunk functions to store chunks in lists, which highly increases the speed of a second walk over those chunks. This feature can only be activated if performance is set to 'fast'.
Sets _preserve_chunks to True. This forces all allocated chunk functions to store chunks in lists, which highly increases the speed of a second walk over those chunks. This feature can only be activated if performance is set to 'fast'.
[ "Sets", "_preserve_chunks", "to", "True", ".", "This", "forces", "all", "allocated", "chunk", "functions", "to", "store", "chunks", "in", "lists", "which", "highly", "increases", "the", "speed", "of", "a", "second", "walk", "over", "those", "chunks", ".", "T...
def activate_chunk_preservation(self): """Sets _preserve_chunks to True. This forces all allocated chunk functions to store chunks in lists, which highly increases the speed of a second walk over those chunks. This feature can only be activated if performance is set to 'fast'.""" if not self._preserve_chunks: debug.debug( "Chunk preservation has been activated." "This might consume large amounts of memory" " depending on the chunk count. If you are low on free memory " "space (RAM), you might want to deactivate this feature by " "not using the 'fast' option. The only downside is in some " "cases a longer plugin runtime.") self._preserve_chunks = True
[ "def", "activate_chunk_preservation", "(", "self", ")", ":", "if", "not", "self", ".", "_preserve_chunks", ":", "debug", ".", "debug", "(", "\"Chunk preservation has been activated.\"", "\"This might consume large amounts of memory\"", "\" depending on the chunk count. If you are...
https://github.com/volatilityfoundation/community/blob/d9fc0727266ec552bb6412142f3f31440c601664/FrankBlock/heap_analysis.py#L142-L157
pythonarcade/arcade
1ee3eb1900683213e8e8df93943327c2ea784564
arcade/examples/sprite_collect_coins_move_down.py
python
MyGame.__init__
(self)
Initializer
Initializer
[ "Initializer" ]
def __init__(self): """ Initializer """ # Call the parent class initializer super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) # Variables that will hold sprite lists self.player_sprite_list = None self.coin_sprite_list = None # Set up the player info self.player_sprite = None self.score = 0 # Don't show the mouse cursor self.set_mouse_visible(False) arcade.set_background_color(arcade.color.AMAZON)
[ "def", "__init__", "(", "self", ")", ":", "# Call the parent class initializer", "super", "(", ")", ".", "__init__", "(", "SCREEN_WIDTH", ",", "SCREEN_HEIGHT", ",", "SCREEN_TITLE", ")", "# Variables that will hold sprite lists", "self", ".", "player_sprite_list", "=", ...
https://github.com/pythonarcade/arcade/blob/1ee3eb1900683213e8e8df93943327c2ea784564/arcade/examples/sprite_collect_coins_move_down.py#L52-L69
vivisect/vivisect
37b0b655d8dedfcf322e86b0f144b096e48d547e
vivisect/__init__.py
python
VivWorkspace.loadFromFile
(self, filename, fmtname=None, baseaddr=None)
return fname
Read the first bytes of the file and see if we can identify the type. If so, load up the parser for that file type, otherwise raise an exception. ( if it's a workspace, trigger loadWorkspace() as a convenience ) Returns the basename the file was given on load.
Read the first bytes of the file and see if we can identify the type. If so, load up the parser for that file type, otherwise raise an exception. ( if it's a workspace, trigger loadWorkspace() as a convenience )
[ "Read", "the", "first", "bytes", "of", "the", "file", "and", "see", "if", "we", "can", "identify", "the", "type", ".", "If", "so", "load", "up", "the", "parser", "for", "that", "file", "type", "otherwise", "raise", "an", "exception", ".", "(", "if", ...
def loadFromFile(self, filename, fmtname=None, baseaddr=None): """ Read the first bytes of the file and see if we can identify the type. If so, load up the parser for that file type, otherwise raise an exception. ( if it's a workspace, trigger loadWorkspace() as a convenience ) Returns the basename the file was given on load. """ mod = None if fmtname is None: fmtname = viv_parsers.guessFormatFilename(filename) if fmtname in STORAGE_MAP: self.setMeta('StorageModule', STORAGE_MAP[fmtname]) self.loadWorkspace(filename) return self.normFileName(filename) mod = viv_parsers.getParserModule(fmtname) fname = mod.parseFile(self, filename=filename, baseaddr=baseaddr) self.initMeta("StorageName", filename+".viv") # Snapin our analysis modules self._snapInAnalysisModules() return fname
[ "def", "loadFromFile", "(", "self", ",", "filename", ",", "fmtname", "=", "None", ",", "baseaddr", "=", "None", ")", ":", "mod", "=", "None", "if", "fmtname", "is", "None", ":", "fmtname", "=", "viv_parsers", ".", "guessFormatFilename", "(", "filename", ...
https://github.com/vivisect/vivisect/blob/37b0b655d8dedfcf322e86b0f144b096e48d547e/vivisect/__init__.py#L2743-L2768
Ericsson/codechecker
c4e43f62dc3acbf71d3109b337db7c97f7852f43
scripts/labels/pylint.py
python
get_severity_label_for_kind
(kind: str)
return f"severity:{severity}"
Get CodeChecker severity for a pylint kind. There are 5 kind of message types : * (C) convention, for programming standard violation * (R) refactor, for bad code smell * (W) warning, for python specific problems * (E) error, for probable bugs in the code * (F) fatal, if an error occurred which prevented pylint from doing further processing.
Get CodeChecker severity for a pylint kind.
[ "Get", "CodeChecker", "severity", "for", "a", "pylint", "kind", "." ]
def get_severity_label_for_kind(kind: str) -> str: """ Get CodeChecker severity for a pylint kind. There are 5 kind of message types : * (C) convention, for programming standard violation * (R) refactor, for bad code smell * (W) warning, for python specific problems * (E) error, for probable bugs in the code * (F) fatal, if an error occurred which prevented pylint from doing further processing. """ severity = "UNSPECIFIED" if kind == "F": severity = "CRITICAL" elif kind == "E": severity = "HIGH" elif kind == "W": severity = "MEDIUM" elif kind == "R": severity = "STYLE" elif kind == "C": severity = "LOW" return f"severity:{severity}"
[ "def", "get_severity_label_for_kind", "(", "kind", ":", "str", ")", "->", "str", ":", "severity", "=", "\"UNSPECIFIED\"", "if", "kind", "==", "\"F\"", ":", "severity", "=", "\"CRITICAL\"", "elif", "kind", "==", "\"E\"", ":", "severity", "=", "\"HIGH\"", "eli...
https://github.com/Ericsson/codechecker/blob/c4e43f62dc3acbf71d3109b337db7c97f7852f43/scripts/labels/pylint.py#L6-L30
openshift/openshift-tools
1188778e728a6e4781acf728123e5b356380fe6f
openshift/installer/vendored/openshift-ansible-3.9.40/roles/lib_vendored_deps/library/oc_group.py
python
Yedit.get_entry
(data, key, sep='.')
return data
Get an item from a dictionary with key notation a.b.c d = {'a': {'b': 'c'}}} key = a.b return c
Get an item from a dictionary with key notation a.b.c d = {'a': {'b': 'c'}}} key = a.b return c
[ "Get", "an", "item", "from", "a", "dictionary", "with", "key", "notation", "a", ".", "b", ".", "c", "d", "=", "{", "a", ":", "{", "b", ":", "c", "}}}", "key", "=", "a", ".", "b", "return", "c" ]
def get_entry(data, key, sep='.'): ''' Get an item from a dictionary with key notation a.b.c d = {'a': {'b': 'c'}}} key = a.b return c ''' if key == '': pass elif (not (key and Yedit.valid_key(key, sep)) and isinstance(data, (list, dict))): return None key_indexes = Yedit.parse_key(key, sep) for arr_ind, dict_key in key_indexes: if dict_key and isinstance(data, dict): data = data.get(dict_key) elif (arr_ind and isinstance(data, list) and int(arr_ind) <= len(data) - 1): data = data[int(arr_ind)] else: return None return data
[ "def", "get_entry", "(", "data", ",", "key", ",", "sep", "=", "'.'", ")", ":", "if", "key", "==", "''", ":", "pass", "elif", "(", "not", "(", "key", "and", "Yedit", ".", "valid_key", "(", "key", ",", "sep", ")", ")", "and", "isinstance", "(", "...
https://github.com/openshift/openshift-tools/blob/1188778e728a6e4781acf728123e5b356380fe6f/openshift/installer/vendored/openshift-ansible-3.9.40/roles/lib_vendored_deps/library/oc_group.py#L292-L314
pypa/pipenv
b21baade71a86ab3ee1429f71fbc14d4f95fb75d
pipenv/vendor/distlib/util.py
python
get_project_data
(name)
return result
[]
def get_project_data(name): url = '%s/%s/project.json' % (name[0].upper(), name) url = urljoin(_external_data_base_url, url) result = _get_external_data(url) return result
[ "def", "get_project_data", "(", "name", ")", ":", "url", "=", "'%s/%s/project.json'", "%", "(", "name", "[", "0", "]", ".", "upper", "(", ")", ",", "name", ")", "url", "=", "urljoin", "(", "_external_data_base_url", ",", "url", ")", "result", "=", "_ge...
https://github.com/pypa/pipenv/blob/b21baade71a86ab3ee1429f71fbc14d4f95fb75d/pipenv/vendor/distlib/util.py#L931-L935
golismero/golismero
7d605b937e241f51c1ca4f47b20f755eeefb9d76
golismero/api/shared.py
python
SharedMap.keys
(self)
return tuple(decode_key(k) for k in keys)
Get the keys of the map. .. warning: Due to the asynchronous nature of GoLismero plugins, it's possible the list of keys is not accurate - another instance of the plugin may remove or add new keys right after you call this method. :returns: Keys defined in this shared map, in any order. :rtype: tuple( immutable, ... )
Get the keys of the map.
[ "Get", "the", "keys", "of", "the", "map", "." ]
def keys(self): """ Get the keys of the map. .. warning: Due to the asynchronous nature of GoLismero plugins, it's possible the list of keys is not accurate - another instance of the plugin may remove or add new keys right after you call this method. :returns: Keys defined in this shared map, in any order. :rtype: tuple( immutable, ... ) """ keys = Config._context.remote_call( MessageCode.MSG_RPC_SHARED_MAP_KEYS, self.shared_id) return tuple(decode_key(k) for k in keys)
[ "def", "keys", "(", "self", ")", ":", "keys", "=", "Config", ".", "_context", ".", "remote_call", "(", "MessageCode", ".", "MSG_RPC_SHARED_MAP_KEYS", ",", "self", ".", "shared_id", ")", "return", "tuple", "(", "decode_key", "(", "k", ")", "for", "k", "in...
https://github.com/golismero/golismero/blob/7d605b937e241f51c1ca4f47b20f755eeefb9d76/golismero/api/shared.py#L530-L544
nwcell/psycopg2-windows
5698844286001962f3eeeab58164301898ef48e9
psycopg2/_range.py
python
Range.isempty
(self)
return self._bounds is None
`!True` if the range is empty.
`!True` if the range is empty.
[ "!True", "if", "the", "range", "is", "empty", "." ]
def isempty(self): """`!True` if the range is empty.""" return self._bounds is None
[ "def", "isempty", "(", "self", ")", ":", "return", "self", ".", "_bounds", "is", "None" ]
https://github.com/nwcell/psycopg2-windows/blob/5698844286001962f3eeeab58164301898ef48e9/psycopg2/_range.py#L74-L76
holzschu/Carnets
44effb10ddfc6aa5c8b0687582a724ba82c6b547
Library/lib/python3.7/site-packages/astropy-4.0-py3.7-macosx-10.9-x86_64.egg/astropy/modeling/functional_models.py
python
Disk2D.evaluate
(x, y, amplitude, x_0, y_0, R_0)
Two dimensional Disk model function
Two dimensional Disk model function
[ "Two", "dimensional", "Disk", "model", "function" ]
def evaluate(x, y, amplitude, x_0, y_0, R_0): """Two dimensional Disk model function""" rr = (x - x_0) ** 2 + (y - y_0) ** 2 result = np.select([rr <= R_0 ** 2], [amplitude]) if isinstance(amplitude, Quantity): return Quantity(result, unit=amplitude.unit, copy=False) else: return result
[ "def", "evaluate", "(", "x", ",", "y", ",", "amplitude", ",", "x_0", ",", "y_0", ",", "R_0", ")", ":", "rr", "=", "(", "x", "-", "x_0", ")", "**", "2", "+", "(", "y", "-", "y_0", ")", "**", "2", "result", "=", "np", ".", "select", "(", "[...
https://github.com/holzschu/Carnets/blob/44effb10ddfc6aa5c8b0687582a724ba82c6b547/Library/lib/python3.7/site-packages/astropy-4.0-py3.7-macosx-10.9-x86_64.egg/astropy/modeling/functional_models.py#L1428-L1437
openstack/trove
be86b79119d16ee77f596172f43b0c97cb2617bd
trove/common/extensions.py
python
ExtensionDescriptor.get_updated
(self)
The timestamp when the extension was last updated. e.g. '2011-01-22T13:25:27-06:00'
The timestamp when the extension was last updated.
[ "The", "timestamp", "when", "the", "extension", "was", "last", "updated", "." ]
def get_updated(self): """The timestamp when the extension was last updated. e.g. '2011-01-22T13:25:27-06:00' """ pass
[ "def", "get_updated", "(", "self", ")", ":", "pass" ]
https://github.com/openstack/trove/blob/be86b79119d16ee77f596172f43b0c97cb2617bd/trove/common/extensions.py#L80-L86
armancohan/long-summarization
1328d4f37b3a3a460f455e93e84ed4ddcd10dab1
attention_decoder_new.py
python
attention_decoder
(decoder_inputs, initial_state, encoder_states, cell, encoder_section_states=None, num_words_section=None, enc_padding_mask=None, enc_section_padding_mask=None, initial_state_attention=False, pointer_gen=True, use_coverage=False, prev_coverage=None, temperature=None)
Args: decoder_inputs: A list of 2D Tensors [batch_size x input_size]. initial_state: 2D Tensor [batch_size x cell.state_size]. encoder_states: 3D Tensor [batch_size x seq_len x encoder_output_size]. cell: rnn_cell.RNNCell defining the cell function and size. encoder_section_states: 3D Tensor [batch_size x section_seq_len x encoder_output_size]. Pass None if you don't want hierarchical attentive decoding num_words_section: number of words per section [batch_size x section_seq_len] enc_padding_mask: 2D Tensor [batch_size x attn_length] containing 1s and 0s; indicates which of the encoder locations are padding (0) or a real token (1). enc_section_padding_mask: 3D Tensor [batch_size x num_sections x section_len] initial_state_attention: Note that this attention decoder passes each decoder input through a linear layer with the previous step's context vector to get a modified version of the input. If initial_state_attention is False, on the first decoder step the "previous context vector" is just a zero vector. If initial_state_attention is True, we use initial_state to (re)calculate the previous step's context vector. We set this to False for train/eval mode (because we call attention_decoder once for all decoder steps) and True for decode mode (because we call attention_decoder once for each decoder step). pointer_gen: boolean. If True, calculate the generation probability p_gen for each decoder step. use_coverage: boolean. If True, use coverage mechanism. prev_coverage: If not None, a tensor with shape (batch_size, seq_len). The previous step's coverage vector. This is only not None in decode mode when using coverage. simulating the temperature hyperparam for softmax: set to 1.0 for starters Returns: outputs: A list of the same length as decoder_inputs of 2D Tensors of shape [batch_size x cell.output_size]. The output vectors. state: The final state of the decoder. A tensor shape [batch_size x cell.state_size]. attn_dists: A list containing tensors of shape (batch_size,seq_len). The attention distributions for each decoder step. p_gens: p_gens: List of length input_size, containing tensors of shape [batch_size, 1]. The values of p_gen for each decoder step. Empty list if pointer_gen=False. coverage: Coverage vector on the last step computed. None if use_coverage=False.
Args: decoder_inputs: A list of 2D Tensors [batch_size x input_size]. initial_state: 2D Tensor [batch_size x cell.state_size]. encoder_states: 3D Tensor [batch_size x seq_len x encoder_output_size]. cell: rnn_cell.RNNCell defining the cell function and size. encoder_section_states: 3D Tensor [batch_size x section_seq_len x encoder_output_size]. Pass None if you don't want hierarchical attentive decoding num_words_section: number of words per section [batch_size x section_seq_len] enc_padding_mask: 2D Tensor [batch_size x attn_length] containing 1s and 0s; indicates which of the encoder locations are padding (0) or a real token (1). enc_section_padding_mask: 3D Tensor [batch_size x num_sections x section_len] initial_state_attention: Note that this attention decoder passes each decoder input through a linear layer with the previous step's context vector to get a modified version of the input. If initial_state_attention is False, on the first decoder step the "previous context vector" is just a zero vector. If initial_state_attention is True, we use initial_state to (re)calculate the previous step's context vector. We set this to False for train/eval mode (because we call attention_decoder once for all decoder steps) and True for decode mode (because we call attention_decoder once for each decoder step). pointer_gen: boolean. If True, calculate the generation probability p_gen for each decoder step. use_coverage: boolean. If True, use coverage mechanism. prev_coverage: If not None, a tensor with shape (batch_size, seq_len). The previous step's coverage vector. This is only not None in decode mode when using coverage. simulating the temperature hyperparam for softmax: set to 1.0 for starters
[ "Args", ":", "decoder_inputs", ":", "A", "list", "of", "2D", "Tensors", "[", "batch_size", "x", "input_size", "]", ".", "initial_state", ":", "2D", "Tensor", "[", "batch_size", "x", "cell", ".", "state_size", "]", ".", "encoder_states", ":", "3D", "Tensor"...
def attention_decoder(decoder_inputs, initial_state, encoder_states, cell, encoder_section_states=None, num_words_section=None, enc_padding_mask=None, enc_section_padding_mask=None, initial_state_attention=False, pointer_gen=True, use_coverage=False, prev_coverage=None, temperature=None): """ Args: decoder_inputs: A list of 2D Tensors [batch_size x input_size]. initial_state: 2D Tensor [batch_size x cell.state_size]. encoder_states: 3D Tensor [batch_size x seq_len x encoder_output_size]. cell: rnn_cell.RNNCell defining the cell function and size. encoder_section_states: 3D Tensor [batch_size x section_seq_len x encoder_output_size]. Pass None if you don't want hierarchical attentive decoding num_words_section: number of words per section [batch_size x section_seq_len] enc_padding_mask: 2D Tensor [batch_size x attn_length] containing 1s and 0s; indicates which of the encoder locations are padding (0) or a real token (1). enc_section_padding_mask: 3D Tensor [batch_size x num_sections x section_len] initial_state_attention: Note that this attention decoder passes each decoder input through a linear layer with the previous step's context vector to get a modified version of the input. If initial_state_attention is False, on the first decoder step the "previous context vector" is just a zero vector. If initial_state_attention is True, we use initial_state to (re)calculate the previous step's context vector. We set this to False for train/eval mode (because we call attention_decoder once for all decoder steps) and True for decode mode (because we call attention_decoder once for each decoder step). pointer_gen: boolean. If True, calculate the generation probability p_gen for each decoder step. use_coverage: boolean. If True, use coverage mechanism. prev_coverage: If not None, a tensor with shape (batch_size, seq_len). The previous step's coverage vector. This is only not None in decode mode when using coverage. simulating the temperature hyperparam for softmax: set to 1.0 for starters Returns: outputs: A list of the same length as decoder_inputs of 2D Tensors of shape [batch_size x cell.output_size]. The output vectors. state: The final state of the decoder. A tensor shape [batch_size x cell.state_size]. attn_dists: A list containing tensors of shape (batch_size,seq_len). The attention distributions for each decoder step. p_gens: p_gens: List of length input_size, containing tensors of shape [batch_size, 1]. The values of p_gen for each decoder step. Empty list if pointer_gen=False. coverage: Coverage vector on the last step computed. None if use_coverage=False. """ print('encoder_states.shape', encoder_states.shape) print('decoder_inputs[0].shape', decoder_inputs[0].shape) with variable_scope.variable_scope("attention_decoder") as scope: batch_size = encoder_states.get_shape()[0].value # if this line fails, it's because the batch size isn't defined enc_output_size = encoder_states.get_shape()[2].value # encoder state size, if this line fails, it's because the attention length isn't defined hier = True if encoder_section_states is not None else False # Reshape encoder_states (need to insert a dim) encoder_states = tf.expand_dims(encoder_states, axis=2) # now is shape (batch_size, attn_len, 1, enc_output_size) # To calculate attention, we calculate # v^T tanh (W_h h_i + W_s s_t + b_attn) # where h_i is an encoder state, and s_t a decoder state. # attn_vec_size is the length of the vectors v, b_attn, (W_h h_i) and (W_s s_t). # (W_h h_i) is encoder_features, (W_s s_t) + b_att is decoder_features # We set it to be equal to the size of the encoder states. attention_vec_size = enc_output_size # Get the weight matrix W_h and apply it to each encoder state to get (W_h h_i), the encoder features # To multiply batch_size number of time_step sizes of encoder states # by W_h, we can use conv2d with stride of 1 W_h = variable_scope.get_variable("W_h", [1, 1, enc_output_size, attention_vec_size]) encoder_features = nn_ops.conv2d(encoder_states, W_h, [1, 1, 1, 1], "SAME") # shape (batch_size,seq_len,1,attention_vec_size) # encoder_features = tf.Print(encoder_features, [tf.shape(encoder_features)], # 'encoder_features.shape = ') if hier: # compute section attention enc_sec_output_size = encoder_section_states.get_shape()[2].value ### convert [batch_size, num_secs, hidden_size] to [batch_size, num_secs*sec_len, hidden_size] nwords_sec = num_words_section[0][0] # assumes section lenghts are equal shapes_sec = encoder_section_states.shape ones = tf.ones([shapes_sec[0].value, shapes_sec[1].value, nwords_sec, shapes_sec[2].value]) tmp_states = tf.multiply(tf.expand_dims(encoder_section_states, axis=2), ones) # shape [batch_size, num_secs, sec_len, hidden] tmp_states = tf.reshape(tmp_states, [shapes_sec[0].value, -1, shapes_sec[2].value]) encoder_section_states = tmp_states ### encoder_section_states = tf.expand_dims(encoder_section_states, axis=2) W_h_s = variable_scope.get_variable("W_h_s", [1, 1, enc_sec_output_size, attention_vec_size]) encoder_section_features = nn_ops.conv2d(encoder_section_states, W_h_s, [1, 1, 1, 1], "SAME") # shape (batch_size,seq_len,1,attention_vec_size) # Get the weight vectors v and w_c (w_c is for coverage) # v^T tanh (W_h h_i + W_s s_t + W_c c_t + b_attn) # c_t = \sum_{i=1}^{t-1} a^i (sum of all attention weights in the previous step) shape=(batch_size, seq_len) v = variable_scope.get_variable("v", [attention_vec_size]) if use_coverage: with variable_scope.variable_scope("coverage"): w_c = variable_scope.get_variable("w_c", [1, 1, 1, attention_vec_size]) if prev_coverage is not None: # for beam search mode with coverage # reshape from (batch_size, seq_len) to (batch_size, attn_len, 1, 1) prev_coverage = tf.expand_dims(tf.expand_dims(prev_coverage,2),3) def attention(decoder_state, coverage=None, num_words_section=None, step=None): """Calculate the context vector and attention distribution from the decoder state. Args: decoder_state: state of the decoder coverage: Optional. Previous timestep's coverage vector, shape (batch_size, attn_len, 1, 1). num_words_section: number of words in each section (only needed for hierarchical attention) [batch_size, num_sections] -- assumes number of sections in the batch is equal (TODO: check sanity) step: index of the current decoder step (needed for section attention) Returns: context_vector: weighted sum of encoder_states attn_dist: attention distribution coverage: new coverage vector. shape (batch_size, attn_len, 1, 1) """ with variable_scope.variable_scope("Attention"): # Pass the decoder state through a linear layer (this is W_s s_t + b_attn in the paper) # (W_s s_t) + b_att is decoder_features; s_t = decoder_state decoder_features = linear(decoder_state, attention_vec_size, True) # shape (batch_size, attention_vec_size) decoder_features = tf.expand_dims(tf.expand_dims(decoder_features, 1), 1) # reshape to (batch_size, 1, 1, attention_vec_size) def masked_attention(e, enc_padding_mask): if enc_section_padding_mask is not None: enc_padding_mask = tf.reshape(enc_section_padding_mask, [batch_size, -1]) enc_padding_mask = tf.cast(enc_padding_mask, tf.float32) """Take softmax of e then apply enc_padding_mask and re-normalize""" attn_dist = nn_ops.softmax(e) # take softmax. shape (batch_size, attn_length) attn_dist *= enc_padding_mask # apply mask masked_sums = tf.reduce_sum(attn_dist, axis=1) # shape (batch_size) return attn_dist / tf.reshape(masked_sums, [-1, 1]) # re-normalize if use_coverage and coverage is not None: # non-first step of coverage if not hier: # TODO: add coverage on sections # Multiply coverage vector by w_c to get coverage_features. coverage_features = nn_ops.conv2d(coverage, w_c, [1, 1, 1, 1], "SAME") # c has shape (batch_size, seq_len, 1, attention_vec_size) # Calculate v^T tanh(W_h h_i + W_s s_t + w_c c_i^t + b_attn) e = math_ops.reduce_sum(v * math_ops.tanh(encoder_features + decoder_features + coverage_features), [2, 3]) # shape (batch_size,seq_len) # Take softmax of e to get the attention distribution attn_dist = masked_attention(e, enc_padding_mask) # Update coverage vector coverage += array_ops.reshape(attn_dist, [batch_size, -1, 1, 1]) # shape=(batch_size, seq_len,1,1) else: with tf.variable_scope("attention_words_sections"): coverage_features = nn_ops.conv2d(coverage, w_c, [1, 1, 1, 1], "SAME") # c has shape (batch_size, seq_len, 1, attention_vec_size) e = math_ops.reduce_sum(v * math_ops.tanh(encoder_features + decoder_features + encoder_section_features + coverage_features), [2, 3]) # shape (batch_size,seq_len) attn_dist = masked_attention(e, enc_padding_mask) coverage += array_ops.reshape(attn_dist, [batch_size, -1, 1, 1]) # shape=(batch_size, seq_len,1,1) else: # Calculate v^T tanh(W_h h_i + W_s s_t + b_attn) if hier: with tf.variable_scope("attention_words_sections"): e = math_ops.reduce_sum(v * math_ops.tanh(encoder_features + decoder_features + encoder_section_features), [2, 3]) #[batch_size x seq_len] if enc_padding_mask is not None: attn_dist = masked_attention(e, enc_padding_mask) else: attn_dist = nn_ops.softmax(e) # shape (batch_size, seq_len) else: e = math_ops.reduce_sum(v * math_ops.tanh(encoder_features + decoder_features), [2, 3]) # calculate e # Take softmax of e to get the attention distribution if enc_padding_mask is not None: attn_dist = masked_attention(e, enc_padding_mask) else: attn_dist = nn_ops.softmax(e) # shape (batch_size, seq_len) if use_coverage: # first step of training coverage = tf.expand_dims(tf.expand_dims(attn_dist,2),2) # initialize coverage # Calculate the context vector from attn_dist and encoder_states # ecnoder_sates = [batch , seq_len , 1 , encoder_output_size], attn_dist = [batch, seq_len, 1, 1] context_vector = math_ops.reduce_sum(array_ops.reshape(attn_dist, [batch_size, -1, 1, 1]) * encoder_states, [1, 2]) # shape (batch_size, enc_output_size). context_vector = array_ops.reshape(context_vector, [-1, enc_output_size]) return context_vector, attn_dist, coverage outputs = [] attn_dists = [] attn_dists_sec_list = [] p_gens = [] state = initial_state coverage = prev_coverage # initialize coverage to None or whatever was passed in context_vector = array_ops.zeros([batch_size, enc_output_size]) context_vector.set_shape([None, enc_output_size]) # Ensure the second shape of attention vectors is set. if initial_state_attention: # true in decode mode # Re-calculate the context vector from the previous step so that we can pass it through a linear layer with this step's input to get a modified version of the input if hier: context_vector, _, coverage = attention(initial_state, coverage, num_words_section) # in decode mode, this is what updates the coverage vector else: context_vector, _, coverage = attention(initial_state, coverage) # in decode mode, this is what updates the coverage vector for i, inp in enumerate(decoder_inputs): print("Adding attention_decoder timesteps. %i done of %i" % (i+1, len(decoder_inputs)), end='\r') if i > 0: variable_scope.get_variable_scope().reuse_variables() # Merge input and previous attentions into one vector x of the same size as inp # inp is [batch_size, input_size] input_size = inp.get_shape().with_rank(2)[1] if input_size.value is None: raise ValueError("Could not infer input size from input: %s" % inp.name) x = linear([inp] + [context_vector], input_size, True) # Run the decoder RNN cell. cell_output = decoder state cell_output, state = cell(x, state) # Run the attention mechanism. if i == 0 and initial_state_attention: # always true in decode mode with variable_scope.variable_scope( variable_scope.get_variable_scope(), reuse=True): # you need this because you've already run the initial attention(...) call if hier: context_vector, attn_dist, _ = attention(state, coverage, num_words_section) else: context_vector, attn_dist, _ = attention(state, coverage) # don't allow coverage to update else: if hier: context_vector, attn_dist, coverage = attention(state, coverage, num_words_section) else: context_vector, attn_dist, coverage = attention(state, coverage) attn_dists.append(attn_dist) # Calculate p_gen if pointer_gen: with tf.variable_scope('calculate_pgen'): p_gen = linear([context_vector, state.c, state.h, x], 1, True) # Tensor shape (batch_size, 1) p_gen = tf.sigmoid(p_gen) p_gens.append(p_gen) # Concatenate the cell_output (= decoder state) and the context vector, and pass them through a linear layer # This is V[s_t, h*_t] + b in the paper with variable_scope.variable_scope("AttnOutputProjection"): output = linear([cell_output] + [context_vector], cell.output_size, True) outputs.append(output) # If using coverage, reshape it if coverage is not None: coverage = array_ops.reshape(coverage, [batch_size, -1]) return outputs, state, attn_dists, p_gens, coverage, attn_dists_sec_list
[ "def", "attention_decoder", "(", "decoder_inputs", ",", "initial_state", ",", "encoder_states", ",", "cell", ",", "encoder_section_states", "=", "None", ",", "num_words_section", "=", "None", ",", "enc_padding_mask", "=", "None", ",", "enc_section_padding_mask", "=", ...
https://github.com/armancohan/long-summarization/blob/1328d4f37b3a3a460f455e93e84ed4ddcd10dab1/attention_decoder_new.py#L31-L269
Project-MONAI/MONAI
83f8b06372a3803ebe9281300cb794a1f3395018
monai/utils/module.py
python
look_up_option
(opt_str, supported: Collection, default="no_default")
Look up the option in the supported collection and return the matched item. Raise a value error possibly with a guess of the closest match. Args: opt_str: The option string or Enum to look up. supported: The collection of supported options, it can be list, tuple, set, dict, or Enum. default: If it is given, this method will return `default` when `opt_str` is not found, instead of raising a `ValueError`. Otherwise, it defaults to `"no_default"`, so that the method may raise a `ValueError`. Examples: .. code-block:: python from enum import Enum from monai.utils import look_up_option class Color(Enum): RED = "red" BLUE = "blue" look_up_option("red", Color) # <Color.RED: 'red'> look_up_option(Color.RED, Color) # <Color.RED: 'red'> look_up_option("read", Color) # ValueError: By 'read', did you mean 'red'? # 'read' is not a valid option. # Available options are {'blue', 'red'}. look_up_option("red", {"red", "blue"}) # "red" Adapted from https://github.com/NifTK/NiftyNet/blob/v0.6.0/niftynet/utilities/util_common.py#L249
Look up the option in the supported collection and return the matched item. Raise a value error possibly with a guess of the closest match.
[ "Look", "up", "the", "option", "in", "the", "supported", "collection", "and", "return", "the", "matched", "item", ".", "Raise", "a", "value", "error", "possibly", "with", "a", "guess", "of", "the", "closest", "match", "." ]
def look_up_option(opt_str, supported: Collection, default="no_default"): """ Look up the option in the supported collection and return the matched item. Raise a value error possibly with a guess of the closest match. Args: opt_str: The option string or Enum to look up. supported: The collection of supported options, it can be list, tuple, set, dict, or Enum. default: If it is given, this method will return `default` when `opt_str` is not found, instead of raising a `ValueError`. Otherwise, it defaults to `"no_default"`, so that the method may raise a `ValueError`. Examples: .. code-block:: python from enum import Enum from monai.utils import look_up_option class Color(Enum): RED = "red" BLUE = "blue" look_up_option("red", Color) # <Color.RED: 'red'> look_up_option(Color.RED, Color) # <Color.RED: 'red'> look_up_option("read", Color) # ValueError: By 'read', did you mean 'red'? # 'read' is not a valid option. # Available options are {'blue', 'red'}. look_up_option("red", {"red", "blue"}) # "red" Adapted from https://github.com/NifTK/NiftyNet/blob/v0.6.0/niftynet/utilities/util_common.py#L249 """ if not isinstance(opt_str, Hashable): raise ValueError(f"Unrecognized option type: {type(opt_str)}:{opt_str}.") if isinstance(opt_str, str): opt_str = opt_str.strip() if isinstance(supported, enum.EnumMeta): if isinstance(opt_str, str) and opt_str in {item.value for item in cast(Iterable[enum.Enum], supported)}: # such as: "example" in MyEnum return supported(opt_str) if isinstance(opt_str, enum.Enum) and opt_str in supported: # such as: MyEnum.EXAMPLE in MyEnum return opt_str elif isinstance(supported, Mapping) and opt_str in supported: # such as: MyDict[key] return supported[opt_str] elif isinstance(supported, Collection) and opt_str in supported: return opt_str if default != "no_default": return default # find a close match set_to_check: set if isinstance(supported, enum.EnumMeta): set_to_check = {item.value for item in cast(Iterable[enum.Enum], supported)} else: set_to_check = set(supported) if supported is not None else set() if not set_to_check: raise ValueError(f"No options available: {supported}.") edit_dists = {} opt_str = f"{opt_str}" for key in set_to_check: edit_dist = damerau_levenshtein_distance(f"{key}", opt_str) if edit_dist <= 3: edit_dists[key] = edit_dist supported_msg = f"Available options are {set_to_check}.\n" if edit_dists: guess_at_spelling = min(edit_dists, key=edit_dists.get) # type: ignore raise ValueError( f"By '{opt_str}', did you mean '{guess_at_spelling}'?\n" + f"'{opt_str}' is not a valid option.\n" + supported_msg ) raise ValueError(f"Unsupported option '{opt_str}', " + supported_msg)
[ "def", "look_up_option", "(", "opt_str", ",", "supported", ":", "Collection", ",", "default", "=", "\"no_default\"", ")", ":", "if", "not", "isinstance", "(", "opt_str", ",", "Hashable", ")", ":", "raise", "ValueError", "(", "f\"Unrecognized option type: {type(opt...
https://github.com/Project-MONAI/MONAI/blob/83f8b06372a3803ebe9281300cb794a1f3395018/monai/utils/module.py#L47-L121
OpnTec/open-event-server
a48f7e4c6002db6fb4dc06bac6508536a0dc585e
app/models/event.py
python
Event.has_staff_access
(self, user_id)
return False
does user have role other than attendee
does user have role other than attendee
[ "does", "user", "have", "role", "other", "than", "attendee" ]
def has_staff_access(self, user_id): """does user have role other than attendee""" for _ in self.roles: if _.user_id == (login.current_user.id if not user_id else int(user_id)): if _.role.name != ATTENDEE: return True return False
[ "def", "has_staff_access", "(", "self", ",", "user_id", ")", ":", "for", "_", "in", "self", ".", "roles", ":", "if", "_", ".", "user_id", "==", "(", "login", ".", "current_user", ".", "id", "if", "not", "user_id", "else", "int", "(", "user_id", ")", ...
https://github.com/OpnTec/open-event-server/blob/a48f7e4c6002db6fb4dc06bac6508536a0dc585e/app/models/event.py#L282-L288
tensorly/tensorly
87b435b3f3343447b49d47ebb5461118f6c8a9ab
tensorly/contrib/sparse/backend/numpy_backend.py
python
NumpySparseBackend.solve
(self, A, b)
return x
Compute x s.t. Ax = b
Compute x s.t. Ax = b
[ "Compute", "x", "s", ".", "t", ".", "Ax", "=", "b" ]
def solve(self, A, b): """ Compute x s.t. Ax = b """ if is_sparse(A) or is_sparse(b): A, b = A.tocsc(), b.tocsc() x = sparse.COO(scipy.sparse.linalg.spsolve(A, b)) else: x = np.linalg.solve(A, b) return x
[ "def", "solve", "(", "self", ",", "A", ",", "b", ")", ":", "if", "is_sparse", "(", "A", ")", "or", "is_sparse", "(", "b", ")", ":", "A", ",", "b", "=", "A", ".", "tocsc", "(", ")", ",", "b", ".", "tocsc", "(", ")", "x", "=", "sparse", "."...
https://github.com/tensorly/tensorly/blob/87b435b3f3343447b49d47ebb5461118f6c8a9ab/tensorly/contrib/sparse/backend/numpy_backend.py#L73-L83
openstack/octavia
27e5b27d31c695ba72fb6750de2bdafd76e0d7d9
octavia/api/v2/controllers/base.py
python
BaseController._get_listener_and_loadbalancer_id
(self, db_l7policy)
return load_balancer_id, listener_id
Get listener and loadbalancer ids from the l7policy db_model.
Get listener and loadbalancer ids from the l7policy db_model.
[ "Get", "listener", "and", "loadbalancer", "ids", "from", "the", "l7policy", "db_model", "." ]
def _get_listener_and_loadbalancer_id(self, db_l7policy): """Get listener and loadbalancer ids from the l7policy db_model.""" load_balancer_id = db_l7policy.listener.load_balancer_id listener_id = db_l7policy.listener_id return load_balancer_id, listener_id
[ "def", "_get_listener_and_loadbalancer_id", "(", "self", ",", "db_l7policy", ")", ":", "load_balancer_id", "=", "db_l7policy", ".", "listener", ".", "load_balancer_id", "listener_id", "=", "db_l7policy", ".", "listener_id", "return", "load_balancer_id", ",", "listener_i...
https://github.com/openstack/octavia/blob/27e5b27d31c695ba72fb6750de2bdafd76e0d7d9/octavia/api/v2/controllers/base.py#L89-L93
quodlibet/quodlibet
e3099c89f7aa6524380795d325cc14630031886c
quodlibet/util/massagers.py
python
get_options
(tag)
Returns a list of suggested values for the tag. If the list is empty this either means that the tag is unknown or the set of valid values would be too large
Returns a list of suggested values for the tag. If the list is empty this either means that the tag is unknown or the set of valid values would be too large
[ "Returns", "a", "list", "of", "suggested", "values", "for", "the", "tag", ".", "If", "the", "list", "is", "empty", "this", "either", "means", "that", "the", "tag", "is", "unknown", "or", "the", "set", "of", "valid", "values", "would", "be", "too", "lar...
def get_options(tag): """Returns a list of suggested values for the tag. If the list is empty this either means that the tag is unknown or the set of valid values would be too large""" try: return list(Massager.for_tag(tag).options) except KeyError: return []
[ "def", "get_options", "(", "tag", ")", ":", "try", ":", "return", "list", "(", "Massager", ".", "for_tag", "(", "tag", ")", ".", "options", ")", "except", "KeyError", ":", "return", "[", "]" ]
https://github.com/quodlibet/quodlibet/blob/e3099c89f7aa6524380795d325cc14630031886c/quodlibet/util/massagers.py#L101-L109
tztztztztz/eql.detectron2
29224acf4ea549c53264e6229da69868bd5470f3
detectron2/data/common.py
python
DatasetFromList.__init__
(self, lst: list, copy: bool = True, serialize: bool = True)
Args: lst (list): a list which contains elements to produce. copy (bool): whether to deepcopy the element when producing it, so that the result can be modified in place without affecting the source in the list. serialize (bool): whether to hold memory using serialized objects, when enabled, data loader workers can use shared RAM from master process instead of making a copy.
Args: lst (list): a list which contains elements to produce. copy (bool): whether to deepcopy the element when producing it, so that the result can be modified in place without affecting the source in the list. serialize (bool): whether to hold memory using serialized objects, when enabled, data loader workers can use shared RAM from master process instead of making a copy.
[ "Args", ":", "lst", "(", "list", ")", ":", "a", "list", "which", "contains", "elements", "to", "produce", ".", "copy", "(", "bool", ")", ":", "whether", "to", "deepcopy", "the", "element", "when", "producing", "it", "so", "that", "the", "result", "can"...
def __init__(self, lst: list, copy: bool = True, serialize: bool = True): """ Args: lst (list): a list which contains elements to produce. copy (bool): whether to deepcopy the element when producing it, so that the result can be modified in place without affecting the source in the list. serialize (bool): whether to hold memory using serialized objects, when enabled, data loader workers can use shared RAM from master process instead of making a copy. """ self._lst = lst self._copy = copy self._serialize = serialize def _serialize(data): buffer = pickle.dumps(data, protocol=-1) return np.frombuffer(buffer, dtype=np.uint8) if self._serialize: logger = logging.getLogger(__name__) logger.info( "Serializing {} elements to byte tensors and concatenating them all ...".format( len(self._lst) ) ) self._lst = [_serialize(x) for x in self._lst] self._addr = np.asarray([len(x) for x in self._lst], dtype=np.int64) self._addr = np.cumsum(self._addr) self._lst = np.concatenate(self._lst) logger.info("Serialized dataset takes {:.2f} MiB".format(len(self._lst) / 1024 ** 2))
[ "def", "__init__", "(", "self", ",", "lst", ":", "list", ",", "copy", ":", "bool", "=", "True", ",", "serialize", ":", "bool", "=", "True", ")", ":", "self", ".", "_lst", "=", "lst", "self", ".", "_copy", "=", "copy", "self", ".", "_serialize", "...
https://github.com/tztztztztz/eql.detectron2/blob/29224acf4ea549c53264e6229da69868bd5470f3/detectron2/data/common.py#L65-L95
theotherp/nzbhydra
4b03d7f769384b97dfc60dade4806c0fc987514e
libs/flask_cache/__init__.py
python
function_namespace
(f, args=None)
return ns, ins
Attempts to returns unique namespace for function
Attempts to returns unique namespace for function
[ "Attempts", "to", "returns", "unique", "namespace", "for", "function" ]
def function_namespace(f, args=None): """ Attempts to returns unique namespace for function """ m_args = inspect.getargspec(f)[0] instance_token = None instance_self = getattr(f, '__self__', None) if instance_self \ and not inspect.isclass(instance_self): instance_token = repr(f.__self__) elif m_args \ and m_args[0] == 'self' \ and args: instance_token = repr(args[0]) module = f.__module__ if hasattr(f, '__qualname__'): name = f.__qualname__ else: klass = getattr(f, '__self__', None) if klass \ and not inspect.isclass(klass): klass = klass.__class__ if not klass: klass = getattr(f, 'im_class', None) if not klass: if m_args and args: if m_args[0] == 'self': klass = args[0].__class__ elif m_args[0] == 'cls': klass = args[0] if klass: name = klass.__name__ + '.' + f.__name__ else: name = f.__name__ ns = '.'.join((module, name)) ns = ns.translate(*null_control) if instance_token: ins = '.'.join((module, name, instance_token)) ins = ins.translate(*null_control) else: ins = None return ns, ins
[ "def", "function_namespace", "(", "f", ",", "args", "=", "None", ")", ":", "m_args", "=", "inspect", ".", "getargspec", "(", "f", ")", "[", "0", "]", "instance_token", "=", "None", "instance_self", "=", "getattr", "(", "f", ",", "'__self__'", ",", "Non...
https://github.com/theotherp/nzbhydra/blob/4b03d7f769384b97dfc60dade4806c0fc987514e/libs/flask_cache/__init__.py#L41-L93
triaquae/triaquae
bbabf736b3ba56a0c6498e7f04e16c13b8b8f2b9
TriAquae/models/django/db/models/fields/related.py
python
ForeignRelatedObjectsDescriptor.related_manager_cls
(self)
return RelatedManager
[]
def related_manager_cls(self): # Dynamically create a class that subclasses the related model's default # manager. superclass = self.related.model._default_manager.__class__ rel_field = self.related.field rel_model = self.related.model attname = rel_field.rel.get_related_field().attname class RelatedManager(superclass): def __init__(self, instance): super(RelatedManager, self).__init__() self.instance = instance self.core_filters = { '%s__%s' % (rel_field.name, attname): getattr(instance, attname) } self.model = rel_model def get_query_set(self): try: return self.instance._prefetched_objects_cache[rel_field.related_query_name()] except (AttributeError, KeyError): db = self._db or router.db_for_read(self.model, instance=self.instance) qs = super(RelatedManager, self).get_query_set().using(db).filter(**self.core_filters) val = getattr(self.instance, attname) if val is None or val == '' and connections[db].features.interprets_empty_strings_as_nulls: # We don't want to use qs.none() here, see #19652 return qs.filter(pk__in=[]) qs._known_related_objects = {rel_field: {self.instance.pk: self.instance}} return qs def get_prefetch_query_set(self, instances): rel_obj_attr = attrgetter(rel_field.attname) instance_attr = attrgetter(attname) instances_dict = dict((instance_attr(inst), inst) for inst in instances) db = self._db or router.db_for_read(self.model, instance=instances[0]) query = {'%s__%s__in' % (rel_field.name, attname): list(instances_dict)} qs = super(RelatedManager, self).get_query_set().using(db).filter(**query) # Since we just bypassed this class' get_query_set(), we must manage # the reverse relation manually. for rel_obj in qs: instance = instances_dict[rel_obj_attr(rel_obj)] setattr(rel_obj, rel_field.name, instance) cache_name = rel_field.related_query_name() return qs, rel_obj_attr, instance_attr, False, cache_name def add(self, *objs): for obj in objs: if not isinstance(obj, self.model): raise TypeError("'%s' instance expected, got %r" % (self.model._meta.object_name, obj)) setattr(obj, rel_field.name, self.instance) obj.save() add.alters_data = True def create(self, **kwargs): kwargs[rel_field.name] = self.instance db = router.db_for_write(self.model, instance=self.instance) return super(RelatedManager, self.db_manager(db)).create(**kwargs) create.alters_data = True def get_or_create(self, **kwargs): # Update kwargs with the related object that this # ForeignRelatedObjectsDescriptor knows about. kwargs[rel_field.name] = self.instance db = router.db_for_write(self.model, instance=self.instance) return super(RelatedManager, self.db_manager(db)).get_or_create(**kwargs) get_or_create.alters_data = True # remove() and clear() are only provided if the ForeignKey can have a value of null. if rel_field.null: def remove(self, *objs): val = getattr(self.instance, attname) for obj in objs: # Is obj actually part of this descriptor set? if getattr(obj, rel_field.attname) == val: setattr(obj, rel_field.name, None) obj.save() else: raise rel_field.rel.to.DoesNotExist("%r is not related to %r." % (obj, self.instance)) remove.alters_data = True def clear(self): self.update(**{rel_field.name: None}) clear.alters_data = True return RelatedManager
[ "def", "related_manager_cls", "(", "self", ")", ":", "# Dynamically create a class that subclasses the related model's default", "# manager.", "superclass", "=", "self", ".", "related", ".", "model", ".", "_default_manager", ".", "__class__", "rel_field", "=", "self", "."...
https://github.com/triaquae/triaquae/blob/bbabf736b3ba56a0c6498e7f04e16c13b8b8f2b9/TriAquae/models/django/db/models/fields/related.py#L477-L561
jart/fabulous
204b709f6fee796dae1b46ce34e9cf075af42806
fabulous/grapefruit.py
python
Color.NewFromYiq
(y, i, q, alpha=1.0, wref=_DEFAULT_WREF)
return Color(Color.YiqToRgb(y, i, q), 'rgb', alpha, wref)
Create a new instance based on the specifed YIQ values. Parameters: :y: The Y component value [0...1] :i: The I component value [0...1] :q: The Q component value [0...1] :alpha: The color transparency [0...1], default is opaque :wref: The whitepoint reference, default is 2° D65. Returns: A grapefruit.Color instance. >>> str(Color.NewFromYiq(0.5922, 0.45885,-0.05)) '(0.999902, 0.499955, -6.6905e-05, 1)' >>> str(Color.NewFromYiq(0.5922, 0.45885,-0.05, 0.5)) '(0.999902, 0.499955, -6.6905e-05, 0.5)'
Create a new instance based on the specifed YIQ values.
[ "Create", "a", "new", "instance", "based", "on", "the", "specifed", "YIQ", "values", "." ]
def NewFromYiq(y, i, q, alpha=1.0, wref=_DEFAULT_WREF): '''Create a new instance based on the specifed YIQ values. Parameters: :y: The Y component value [0...1] :i: The I component value [0...1] :q: The Q component value [0...1] :alpha: The color transparency [0...1], default is opaque :wref: The whitepoint reference, default is 2° D65. Returns: A grapefruit.Color instance. >>> str(Color.NewFromYiq(0.5922, 0.45885,-0.05)) '(0.999902, 0.499955, -6.6905e-05, 1)' >>> str(Color.NewFromYiq(0.5922, 0.45885,-0.05, 0.5)) '(0.999902, 0.499955, -6.6905e-05, 0.5)' ''' return Color(Color.YiqToRgb(y, i, q), 'rgb', alpha, wref)
[ "def", "NewFromYiq", "(", "y", ",", "i", ",", "q", ",", "alpha", "=", "1.0", ",", "wref", "=", "_DEFAULT_WREF", ")", ":", "return", "Color", "(", "Color", ".", "YiqToRgb", "(", "y", ",", "i", ",", "q", ")", ",", "'rgb'", ",", "alpha", ",", "wre...
https://github.com/jart/fabulous/blob/204b709f6fee796dae1b46ce34e9cf075af42806/fabulous/grapefruit.py#L1269-L1293
django/django
0a17666045de6739ae1c2ac695041823d5f827f7
django/db/models/options.py
python
Options._format_names_with_class
(self, cls, objs)
return new_objs
App label/class name interpolation for object names.
App label/class name interpolation for object names.
[ "App", "label", "/", "class", "name", "interpolation", "for", "object", "names", "." ]
def _format_names_with_class(self, cls, objs): """App label/class name interpolation for object names.""" new_objs = [] for obj in objs: obj = obj.clone() obj.name = obj.name % { 'app_label': cls._meta.app_label.lower(), 'class': cls.__name__.lower(), } new_objs.append(obj) return new_objs
[ "def", "_format_names_with_class", "(", "self", ",", "cls", ",", "objs", ")", ":", "new_objs", "=", "[", "]", "for", "obj", "in", "objs", ":", "obj", "=", "obj", ".", "clone", "(", ")", "obj", ".", "name", "=", "obj", ".", "name", "%", "{", "'app...
https://github.com/django/django/blob/0a17666045de6739ae1c2ac695041823d5f827f7/django/db/models/options.py#L205-L215
jgagneastro/coffeegrindsize
22661ebd21831dba4cf32bfc6ba59fe3d49f879c
App/dist/coffeegrindsize.app/Contents/Resources/lib/python3.7/matplotlib/offsetbox.py
python
DrawingArea.get_offset
(self)
return self._offset
return offset of the container.
return offset of the container.
[ "return", "offset", "of", "the", "container", "." ]
def get_offset(self): """ return offset of the container. """ return self._offset
[ "def", "get_offset", "(", "self", ")", ":", "return", "self", ".", "_offset" ]
https://github.com/jgagneastro/coffeegrindsize/blob/22661ebd21831dba4cf32bfc6ba59fe3d49f879c/App/dist/coffeegrindsize.app/Contents/Resources/lib/python3.7/matplotlib/offsetbox.py#L625-L629
TarrySingh/Artificial-Intelligence-Deep-Learning-Machine-Learning-Tutorials
5bb97d7e3ffd913abddb4cfa7d78a1b4c868890e
deep-learning/fastai-docs/fastai_docs-master/dev_nb/nb_004a.py
python
set_bn_eval
(m:nn.Module)
Set bn layers in eval mode for all recursive children of m
Set bn layers in eval mode for all recursive children of m
[ "Set", "bn", "layers", "in", "eval", "mode", "for", "all", "recursive", "children", "of", "m" ]
def set_bn_eval(m:nn.Module)->None: "Set bn layers in eval mode for all recursive children of m" for l in m.children(): if isinstance(l, bn_types) and not next(l.parameters()).requires_grad: l.eval() set_bn_eval(l)
[ "def", "set_bn_eval", "(", "m", ":", "nn", ".", "Module", ")", "->", "None", ":", "for", "l", "in", "m", ".", "children", "(", ")", ":", "if", "isinstance", "(", "l", ",", "bn_types", ")", "and", "not", "next", "(", "l", ".", "parameters", "(", ...
https://github.com/TarrySingh/Artificial-Intelligence-Deep-Learning-Machine-Learning-Tutorials/blob/5bb97d7e3ffd913abddb4cfa7d78a1b4c868890e/deep-learning/fastai-docs/fastai_docs-master/dev_nb/nb_004a.py#L177-L182
linxid/Machine_Learning_Study_Path
558e82d13237114bbb8152483977806fc0c222af
Machine Learning In Action/Chapter4-NaiveBayes/venv/Lib/site-packages/pip/_vendor/webencodings/x_user_defined.py
python
Codec.decode
(self, input, errors='strict')
return codecs.charmap_decode(input, errors, decoding_table)
[]
def decode(self, input, errors='strict'): return codecs.charmap_decode(input, errors, decoding_table)
[ "def", "decode", "(", "self", ",", "input", ",", "errors", "=", "'strict'", ")", ":", "return", "codecs", ".", "charmap_decode", "(", "input", ",", "errors", ",", "decoding_table", ")" ]
https://github.com/linxid/Machine_Learning_Study_Path/blob/558e82d13237114bbb8152483977806fc0c222af/Machine Learning In Action/Chapter4-NaiveBayes/venv/Lib/site-packages/pip/_vendor/webencodings/x_user_defined.py#L26-L27
leo-editor/leo-editor
383d6776d135ef17d73d935a2f0ecb3ac0e99494
leo/core/leoImport.py
python
RecursiveImportController.import_dir
(self, dir_, parent)
Import selected files from dir_, a directory.
Import selected files from dir_, a directory.
[ "Import", "selected", "files", "from", "dir_", "a", "directory", "." ]
def import_dir(self, dir_, parent): """Import selected files from dir_, a directory.""" if g.os_path_isfile(dir_): files = [dir_] else: g.es_print('importing directory:', dir_) files = os.listdir(dir_) dirs, files2 = [], [] for path in files: try: # Fix #408. Catch path exceptions. # The idea here is to keep going on small errors. path = g.os_path_join(dir_, path) if g.os_path_isfile(path): name, ext = g.os_path_splitext(path) if ext in self.theTypes: files2.append(path) elif self.recursive: if not self.ignore_pattern.search(path): dirs.append(path) except OSError: g.es_print('Exception computing', path) g.es_exception() if files or dirs: assert parent and parent.v != self.root.v, g.callers() parent = parent.insertAsLastChild() parent.v.h = dir_ if files2: for f in files2: if not self.ignore_pattern.search(f): self.import_one_file(f, parent=parent) if dirs: assert self.recursive for dir_ in sorted(dirs): self.import_dir(dir_, parent)
[ "def", "import_dir", "(", "self", ",", "dir_", ",", "parent", ")", ":", "if", "g", ".", "os_path_isfile", "(", "dir_", ")", ":", "files", "=", "[", "dir_", "]", "else", ":", "g", ".", "es_print", "(", "'importing directory:'", ",", "dir_", ")", "file...
https://github.com/leo-editor/leo-editor/blob/383d6776d135ef17d73d935a2f0ecb3ac0e99494/leo/core/leoImport.py#L1723-L1757
n1nj4sec/pupy
a5d766ea81fdfe3bc2c38c9bdaf10e9b75af3b39
pupy/packages/windows/all/pupwinutils/processes.py
python
get_current_pid
()
return dic
[]
def get_current_pid(): p = psutil.Process(os.getpid()) dic = {'Name': p.name(), 'PID': os.getpid()} return dic
[ "def", "get_current_pid", "(", ")", ":", "p", "=", "psutil", ".", "Process", "(", "os", ".", "getpid", "(", ")", ")", "dic", "=", "{", "'Name'", ":", "p", ".", "name", "(", ")", ",", "'PID'", ":", "os", ".", "getpid", "(", ")", "}", "return", ...
https://github.com/n1nj4sec/pupy/blob/a5d766ea81fdfe3bc2c38c9bdaf10e9b75af3b39/pupy/packages/windows/all/pupwinutils/processes.py#L90-L93
gaphor/gaphor
dfe8df33ef3b884afdadf7c91fc7740f8d3c2e88
gaphor/core/modeling/diagram.py
python
Diagram.save
(self, save_func)
Apply the supplied save function to this diagram and the canvas.
Apply the supplied save function to this diagram and the canvas.
[ "Apply", "the", "supplied", "save", "function", "to", "this", "diagram", "and", "the", "canvas", "." ]
def save(self, save_func): """Apply the supplied save function to this diagram and the canvas.""" super().save(save_func)
[ "def", "save", "(", "self", ",", "save_func", ")", ":", "super", "(", ")", ".", "save", "(", "save_func", ")" ]
https://github.com/gaphor/gaphor/blob/dfe8df33ef3b884afdadf7c91fc7740f8d3c2e88/gaphor/core/modeling/diagram.py#L283-L286
JiYou/openstack
8607dd488bde0905044b303eb6e52bdea6806923
chap19/monitor/monitor/monitor/openstack/common/timeutils.py
python
advance_time_seconds
(seconds)
Advance overridden time by seconds.
Advance overridden time by seconds.
[ "Advance", "overridden", "time", "by", "seconds", "." ]
def advance_time_seconds(seconds): """Advance overridden time by seconds.""" advance_time_delta(datetime.timedelta(0, seconds))
[ "def", "advance_time_seconds", "(", "seconds", ")", ":", "advance_time_delta", "(", "datetime", ".", "timedelta", "(", "0", ",", "seconds", ")", ")" ]
https://github.com/JiYou/openstack/blob/8607dd488bde0905044b303eb6e52bdea6806923/chap19/monitor/monitor/monitor/openstack/common/timeutils.py#L131-L133
giswqs/whitebox-python
b4df0bbb10a1dee3bd0f6b3482511f7c829b38fe
whitebox/whitebox_tools.py
python
WhiteboxTools.list_tools
(self, keywords=[])
Lists all available tools in WhiteboxTools.
Lists all available tools in WhiteboxTools.
[ "Lists", "all", "available", "tools", "in", "WhiteboxTools", "." ]
def list_tools(self, keywords=[]): ''' Lists all available tools in WhiteboxTools. ''' try: os.chdir(self.exe_path) args = [] args.append("." + os.path.sep + self.exe_name) args.append("--listtools") if len(keywords) > 0: for kw in keywords: args.append(kw) proc = Popen(args, shell=False, stdout=PIPE, stderr=STDOUT, bufsize=1, universal_newlines=True) ret = {} line = proc.stdout.readline() # skip number of available tools header while True: line = proc.stdout.readline() if line != '': if line.strip() != '': name, descr = line.split(':') ret[to_snakecase(name.strip())] = descr.strip() else: break return ret except (OSError, ValueError, CalledProcessError) as err: return err
[ "def", "list_tools", "(", "self", ",", "keywords", "=", "[", "]", ")", ":", "try", ":", "os", ".", "chdir", "(", "self", ".", "exe_path", ")", "args", "=", "[", "]", "args", ".", "append", "(", "\".\"", "+", "os", ".", "path", ".", "sep", "+", ...
https://github.com/giswqs/whitebox-python/blob/b4df0bbb10a1dee3bd0f6b3482511f7c829b38fe/whitebox/whitebox_tools.py#L524-L552
LinkedInAttic/Zopkio
a06e35a884cd26eedca0aac8ba6b9b40c417a01c
zopkio/adhoc_deployer.py
python
SSHDeployer.stop
(self, unique_id, configs=None)
Stop the service. If the deployer has not started a service with`unique_id` the deployer will raise an Exception There are two configs that will be considered: 'terminate_only': if this config is passed in then this method is the same as terminate(unique_id) (this is also the behavior if stop_command is None and not overridden) 'stop_command': overrides the default stop_command :param unique_id: :param configs: :return:
Stop the service. If the deployer has not started a service with`unique_id` the deployer will raise an Exception There are two configs that will be considered: 'terminate_only': if this config is passed in then this method is the same as terminate(unique_id) (this is also the behavior if stop_command is None and not overridden) 'stop_command': overrides the default stop_command
[ "Stop", "the", "service", ".", "If", "the", "deployer", "has", "not", "started", "a", "service", "with", "unique_id", "the", "deployer", "will", "raise", "an", "Exception", "There", "are", "two", "configs", "that", "will", "be", "considered", ":", "terminate...
def stop(self, unique_id, configs=None): """Stop the service. If the deployer has not started a service with`unique_id` the deployer will raise an Exception There are two configs that will be considered: 'terminate_only': if this config is passed in then this method is the same as terminate(unique_id) (this is also the behavior if stop_command is None and not overridden) 'stop_command': overrides the default stop_command :param unique_id: :param configs: :return: """ # the following is necessay to set the configs for this function as the combination of the # default configurations and the parameter with the parameter superceding the defaults but # not modifying the defaults if configs is None: configs = {} tmp = self.default_configs.copy() tmp.update(configs) configs = tmp logger.debug("stopping " + unique_id) if unique_id in self.processes: hostname = self.processes[unique_id].hostname else: logger.error("Can't stop {0}: process not known".format(unique_id)) raise DeploymentError("Can't stop {0}: process not known".format(unique_id)) if configs.get('terminate_only', False): self.terminate(unique_id, configs) else: stop_command = configs.get('stop_command') or self.default_configs.get('stop_command') env = configs.get("env", {}) if stop_command is not None: install_path = self.processes[unique_id].install_path with get_ssh_client(hostname, username=runtime.get_username(), password=runtime.get_password()) as ssh: log_output(exec_with_env(ssh, "cd {0}; {1}".format(install_path, stop_command), msg="Failed to stop {0}".format(unique_id), env=env)) else: self.terminate(unique_id, configs) if 'delay' in configs: time.sleep(configs['delay'])
[ "def", "stop", "(", "self", ",", "unique_id", ",", "configs", "=", "None", ")", ":", "# the following is necessay to set the configs for this function as the combination of the", "# default configurations and the parameter with the parameter superceding the defaults but", "# not modifyin...
https://github.com/LinkedInAttic/Zopkio/blob/a06e35a884cd26eedca0aac8ba6b9b40c417a01c/zopkio/adhoc_deployer.py#L264-L306
vpelletier/python-libusb1
86ad8ab73f7442874de71c1f9f824724d21da92b
usb1/__init__.py
python
USBDeviceHandle.interruptRead
(self, endpoint, length, timeout=0)
return data_buffer[:transferred]
Synchronous interrupt write. timeout: in milliseconds, how long to wait for data. Set to 0 to disable. See interruptWrite for other parameters description. To avoid memory copies, use an object implementing the writeable buffer interface (ex: bytearray) for the "data" parameter. Returns received data. May raise an exception from the USBError family. USBErrorTimeout exception has a "received" property giving the bytes received up to the timeout.
Synchronous interrupt write. timeout: in milliseconds, how long to wait for data. Set to 0 to disable. See interruptWrite for other parameters description.
[ "Synchronous", "interrupt", "write", ".", "timeout", ":", "in", "milliseconds", "how", "long", "to", "wait", "for", "data", ".", "Set", "to", "0", "to", "disable", ".", "See", "interruptWrite", "for", "other", "parameters", "description", "." ]
def interruptRead(self, endpoint, length, timeout=0): """ Synchronous interrupt write. timeout: in milliseconds, how long to wait for data. Set to 0 to disable. See interruptWrite for other parameters description. To avoid memory copies, use an object implementing the writeable buffer interface (ex: bytearray) for the "data" parameter. Returns received data. May raise an exception from the USBError family. USBErrorTimeout exception has a "received" property giving the bytes received up to the timeout. """ # pylint: disable=undefined-variable endpoint = (endpoint & ~ENDPOINT_DIR_MASK) | ENDPOINT_IN # pylint: enable=undefined-variable data, data_buffer = create_binary_buffer(length) try: transferred = self._interruptTransfer( endpoint, data, length, timeout, ) # pylint: disable=undefined-variable except USBErrorTimeout as exception: # pylint: enable=undefined-variable exception.received = data_buffer[:exception.transferred] raise return data_buffer[:transferred]
[ "def", "interruptRead", "(", "self", ",", "endpoint", ",", "length", ",", "timeout", "=", "0", ")", ":", "# pylint: disable=undefined-variable", "endpoint", "=", "(", "endpoint", "&", "~", "ENDPOINT_DIR_MASK", ")", "|", "ENDPOINT_IN", "# pylint: enable=undefined-var...
https://github.com/vpelletier/python-libusb1/blob/86ad8ab73f7442874de71c1f9f824724d21da92b/usb1/__init__.py#L1461-L1493
DEAP/deap
2f63dcf6aaa341b8fe5d66d99e9e003a21312fef
deap/benchmarks/gp.py
python
rational_polynomial
(data)
return 30. * (data[0] - 1) * (data[2] - 1) / (data[1]**2 * (data[0] - 10))
Rational polynomial ball benchmark function. .. list-table:: :widths: 10 50 :stub-columns: 1 * - Range - :math:`\mathbf{x} \in [0, 2]^3` * - Function - :math:`f(\mathbf{x}) = \\frac{30 * (x_1 - 1) (x_3 - 1)}{x_2^2 (x_1 - 10)}`
Rational polynomial ball benchmark function.
[ "Rational", "polynomial", "ball", "benchmark", "function", "." ]
def rational_polynomial(data): """Rational polynomial ball benchmark function. .. list-table:: :widths: 10 50 :stub-columns: 1 * - Range - :math:`\mathbf{x} \in [0, 2]^3` * - Function - :math:`f(\mathbf{x}) = \\frac{30 * (x_1 - 1) (x_3 - 1)}{x_2^2 (x_1 - 10)}` """ return 30. * (data[0] - 1) * (data[2] - 1) / (data[1]**2 * (data[0] - 10))
[ "def", "rational_polynomial", "(", "data", ")", ":", "return", "30.", "*", "(", "data", "[", "0", "]", "-", "1", ")", "*", "(", "data", "[", "2", "]", "-", "1", ")", "/", "(", "data", "[", "1", "]", "**", "2", "*", "(", "data", "[", "0", ...
https://github.com/DEAP/deap/blob/2f63dcf6aaa341b8fe5d66d99e9e003a21312fef/deap/benchmarks/gp.py#L74-L86
IronLanguages/ironpython2
51fdedeeda15727717fb8268a805f71b06c0b9f1
Src/StdLib/Lib/posixpath.py
python
isabs
(s)
return s.startswith('/')
Test whether a path is absolute
Test whether a path is absolute
[ "Test", "whether", "a", "path", "is", "absolute" ]
def isabs(s): """Test whether a path is absolute""" return s.startswith('/')
[ "def", "isabs", "(", "s", ")", ":", "return", "s", ".", "startswith", "(", "'/'", ")" ]
https://github.com/IronLanguages/ironpython2/blob/51fdedeeda15727717fb8268a805f71b06c0b9f1/Src/StdLib/Lib/posixpath.py#L52-L54
oracle/graalpython
577e02da9755d916056184ec441c26e00b70145c
graalpython/lib-python/3/distutils/command/bdist_msi.py
python
PyDialog.next
(self, title, next, name = "Next", active = 1)
return self.pushbutton(name, 236, self.h-27, 56, 17, flags, title, next)
Add a Next button with a given title, the tab-next button, its name in the Control table, possibly initially disabled. Return the button, so that events can be associated
Add a Next button with a given title, the tab-next button, its name in the Control table, possibly initially disabled.
[ "Add", "a", "Next", "button", "with", "a", "given", "title", "the", "tab", "-", "next", "button", "its", "name", "in", "the", "Control", "table", "possibly", "initially", "disabled", "." ]
def next(self, title, next, name = "Next", active = 1): """Add a Next button with a given title, the tab-next button, its name in the Control table, possibly initially disabled. Return the button, so that events can be associated""" if active: flags = 3 # Visible|Enabled else: flags = 1 # Visible return self.pushbutton(name, 236, self.h-27, 56, 17, flags, title, next)
[ "def", "next", "(", "self", ",", "title", ",", "next", ",", "name", "=", "\"Next\"", ",", "active", "=", "1", ")", ":", "if", "active", ":", "flags", "=", "3", "# Visible|Enabled", "else", ":", "flags", "=", "1", "# Visible", "return", "self", ".", ...
https://github.com/oracle/graalpython/blob/577e02da9755d916056184ec441c26e00b70145c/graalpython/lib-python/3/distutils/command/bdist_msi.py#L64-L73
beeware/toga
090370a943bdeefcdbe035b1621fbc7caeebdf1a
src/cocoa/toga_cocoa/widgets/canvas.py
python
TogaCanvas.mouseDown_
(self, event)
Invoke the on_press handler if configured.
Invoke the on_press handler if configured.
[ "Invoke", "the", "on_press", "handler", "if", "configured", "." ]
def mouseDown_(self, event) -> None: """Invoke the on_press handler if configured.""" if self.interface.on_press: position = self.convertPoint(event.locationInWindow, fromView=None) self.interface.on_press(self.interface, position.x, position.y, event.clickCount)
[ "def", "mouseDown_", "(", "self", ",", "event", ")", "->", "None", ":", "if", "self", ".", "interface", ".", "on_press", ":", "position", "=", "self", ".", "convertPoint", "(", "event", ".", "locationInWindow", ",", "fromView", "=", "None", ")", "self", ...
https://github.com/beeware/toga/blob/090370a943bdeefcdbe035b1621fbc7caeebdf1a/src/cocoa/toga_cocoa/widgets/canvas.py#L42-L46
poppy-project/pypot
c5d384fe23eef9f6ec98467f6f76626cdf20afb9
pypot/primitive/utils.py
python
Sinus.update
(self)
Compute the sin(t) where t is the elapsed time since the primitive has been started.
Compute the sin(t) where t is the elapsed time since the primitive has been started.
[ "Compute", "the", "sin", "(", "t", ")", "where", "t", "is", "the", "elapsed", "time", "since", "the", "primitive", "has", "been", "started", "." ]
def update(self): """ Compute the sin(t) where t is the elapsed time since the primitive has been started. """ pos = self._amp * numpy.sin(self._freq * 2.0 * numpy.pi * self.elapsed_time + self._phase * numpy.pi / 180.0) + self._offset for m in self.motor_list: m.goal_position = pos
[ "def", "update", "(", "self", ")", ":", "pos", "=", "self", ".", "_amp", "*", "numpy", ".", "sin", "(", "self", ".", "_freq", "*", "2.0", "*", "numpy", ".", "pi", "*", "self", ".", "elapsed_time", "+", "self", ".", "_phase", "*", "numpy", ".", ...
https://github.com/poppy-project/pypot/blob/c5d384fe23eef9f6ec98467f6f76626cdf20afb9/pypot/primitive/utils.py#L26-L32
foamliu/InsightFace-v2
e07b738adecb69b81ac9b8750db964cee673e175
lfw_eval.py
python
error_analysis
(threshold)
[]
def error_analysis(threshold): with open(angles_file) as file: angle_lines = file.readlines() fp = [] fn = [] for i, line in enumerate(angle_lines): tokens = line.split() angle = float(tokens[0]) type = int(tokens[1]) if angle <= threshold and type == 0: fp.append(i) if angle > threshold and type == 1: fn.append(i) print('len(fp): ' + str(len(fp))) print('len(fn): ' + str(len(fn))) num_fp = len(fp) num_fn = len(fn) filename = 'data/lfw_test_pair.txt' with open(filename, 'r') as file: pair_lines = file.readlines() for i in range(num_fp): fp_id = fp[i] fp_line = pair_lines[fp_id] tokens = fp_line.split() file0 = tokens[0] copy_file(file0, '{}_fp_0.jpg'.format(i)) save_aligned(file0, '{}_fp_0_aligned.jpg'.format(i)) file1 = tokens[1] copy_file(file1, '{}_fp_1.jpg'.format(i)) save_aligned(file1, '{}_fp_1_aligned.jpg'.format(i)) for i in range(num_fn): fn_id = fn[i] fn_line = pair_lines[fn_id] tokens = fn_line.split() file0 = tokens[0] copy_file(file0, '{}_fn_0.jpg'.format(i)) save_aligned(file0, '{}_fn_0_aligned.jpg'.format(i)) file1 = tokens[1] copy_file(file1, '{}_fn_1.jpg'.format(i)) save_aligned(file1, '{}_fn_1_aligned.jpg'.format(i))
[ "def", "error_analysis", "(", "threshold", ")", ":", "with", "open", "(", "angles_file", ")", "as", "file", ":", "angle_lines", "=", "file", ".", "readlines", "(", ")", "fp", "=", "[", "]", "fn", "=", "[", "]", "for", "i", ",", "line", "in", "enume...
https://github.com/foamliu/InsightFace-v2/blob/e07b738adecb69b81ac9b8750db964cee673e175/lfw_eval.py#L213-L258
PyMVPA/PyMVPA
76c476b3de8264b0bb849bf226da5674d659564e
mvpa2/clfs/stats.py
python
MCNullDist._cdf
(self, x, cdf_func)
return np.array(cdfs).reshape(xshape)
Return value of the cumulative distribution function at `x`.
Return value of the cumulative distribution function at `x`.
[ "Return", "value", "of", "the", "cumulative", "distribution", "function", "at", "x", "." ]
def _cdf(self, x, cdf_func): """Return value of the cumulative distribution function at `x`. """ if self._dist is None: # XXX We might not want to descriminate that way since # usually generators also have .cdf where they rely on the # default parameters. But then what about Nonparametric raise RuntimeError, "Distribution has to be fit first" is_scalar = np.isscalar(x) if is_scalar: x = [x] x = np.asanyarray(x) xshape = x.shape # assure x is a 1D array now x = x.reshape((-1,)) if len(self._dist) != len(x): raise ValueError, 'Distribution was fit for structure with %d' \ ' elements, whenever now queried with %d elements' \ % (len(self._dist), len(x)) # extract cdf values per each element if cdf_func == 'cdf': cdfs = [ dist.cdf(v) for v, dist in zip(x, self._dist) ] elif cdf_func == 'rcdf': cdfs = [ _auto_rcdf(dist)(v) for v, dist in zip(x, self._dist) ] else: raise ValueError return np.array(cdfs).reshape(xshape)
[ "def", "_cdf", "(", "self", ",", "x", ",", "cdf_func", ")", ":", "if", "self", ".", "_dist", "is", "None", ":", "# XXX We might not want to descriminate that way since", "# usually generators also have .cdf where they rely on the", "# default parameters. But then what about Non...
https://github.com/PyMVPA/PyMVPA/blob/76c476b3de8264b0bb849bf226da5674d659564e/mvpa2/clfs/stats.py#L459-L489
pyca/pyopenssl
fb26edde0aa27670c7bb24c0daeb05516e83d7b0
src/OpenSSL/SSL.py
python
Connection.set_alpn_protos
(self, protos)
Specify the client's ALPN protocol list. These protocols are offered to the server during protocol negotiation. :param protos: A list of the protocols to be offered to the server. This list should be a Python list of bytestrings representing the protocols to offer, e.g. ``[b'http/1.1', b'spdy/2']``.
Specify the client's ALPN protocol list.
[ "Specify", "the", "client", "s", "ALPN", "protocol", "list", "." ]
def set_alpn_protos(self, protos): """ Specify the client's ALPN protocol list. These protocols are offered to the server during protocol negotiation. :param protos: A list of the protocols to be offered to the server. This list should be a Python list of bytestrings representing the protocols to offer, e.g. ``[b'http/1.1', b'spdy/2']``. """ # Different versions of OpenSSL are inconsistent about how they handle # empty proto lists (see #1043), so we avoid the problem entirely by # rejecting them ourselves. if not protos: raise ValueError("at least one protocol must be specified") # Take the list of protocols and join them together, prefixing them # with their lengths. protostr = b"".join( chain.from_iterable((bytes((len(p),)), p) for p in protos) ) # Build a C string from the list. We don't need to save this off # because OpenSSL immediately copies the data out. input_str = _ffi.new("unsigned char[]", protostr) # https://www.openssl.org/docs/man1.1.0/man3/SSL_CTX_set_alpn_protos.html: # SSL_CTX_set_alpn_protos() and SSL_set_alpn_protos() # return 0 on success, and non-0 on failure. # WARNING: these functions reverse the return value convention. _openssl_assert( _lib.SSL_set_alpn_protos(self._ssl, input_str, len(protostr)) == 0 )
[ "def", "set_alpn_protos", "(", "self", ",", "protos", ")", ":", "# Different versions of OpenSSL are inconsistent about how they handle", "# empty proto lists (see #1043), so we avoid the problem entirely by", "# rejecting them ourselves.", "if", "not", "protos", ":", "raise", "Value...
https://github.com/pyca/pyopenssl/blob/fb26edde0aa27670c7bb24c0daeb05516e83d7b0/src/OpenSSL/SSL.py#L2567-L2599
imgarylai/bert-embedding
ad2dbb55249c52d9868266c86ba7a1473abc3cb5
bert_embedding/cli.py
python
main
()
[]
def main(): np.set_printoptions(threshold=5) parser = argparse.ArgumentParser(description='Get embeddings from BERT', formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--gpu', type=int, default=None, help='id of the gpu to use. Set it to empty means to use cpu.') parser.add_argument('--dtype', type=str, default='float32', help='data dtype') parser.add_argument('--model', type=str, default='bert_12_768_12', help='pre-trained model') parser.add_argument('--dataset_name', type=str, default='book_corpus_wiki_en_uncased', help='dataset') parser.add_argument('--max_seq_length', type=int, default=25, help='max length of each sequence') parser.add_argument('--batch_size', type=int, default=256, help='batch size') parser.add_argument('--oov_way', type=str, default='avg', help='how to handle oov\n' 'avg: average all oov embeddings to represent the original token\n' 'sum: sum all oov embeddings to represent the original token\n' 'last: use last oov embeddings to represent the original token\n') parser.add_argument('--sentences', type=str, nargs='+', default=None, help='sentence for encoding') parser.add_argument('--file', type=str, default=None, help='file for encoding') parser.add_argument('--verbose', action='store_true', help='verbose logging') args = parser.parse_args() level = logging.DEBUG if args.verbose else logging.INFO logging.getLogger().setLevel(level) logging.info(args) if args.gpu is not None: context = mx.gpu(args.gpu) else: context = mx.cpu() bert_embedding = BertEmbedding(ctx=context, model=args.model, dataset_name=args.dataset_name, max_seq_length=args.max_seq_length, batch_size=args.batch_size) result = [] sents = [] if args.sentences: sents = args.sentences result = bert_embedding(sents, oov_way=args.oov_way) elif args.file: with io.open(args.file, 'r', encoding='utf8') as in_file: for line in in_file: sents.append(line.strip()) result = bert_embedding(sents, oov_way=args.oov_way) else: logger.error('Please specify --sentence or --file') if result: for sent, embeddings in zip(sents, result): logger.info('Sentence: {}'.format(sent)) _, tokens_embedding = embeddings logger.info('Tokens embedding: {}'.format(tokens_embedding))
[ "def", "main", "(", ")", ":", "np", ".", "set_printoptions", "(", "threshold", "=", "5", ")", "parser", "=", "argparse", ".", "ArgumentParser", "(", "description", "=", "'Get embeddings from BERT'", ",", "formatter_class", "=", "argparse", ".", "RawTextHelpForma...
https://github.com/imgarylai/bert-embedding/blob/ad2dbb55249c52d9868266c86ba7a1473abc3cb5/bert_embedding/cli.py#L15-L68
fephsun/neuralnetmusic
1b559a25bcfb0af14433fad9982825ce17af5518
DeepLearningTutorials/code/mlp.py
python
MLP.__init__
(self, rng, input, n_in, n_hidden, n_out)
Initialize the parameters for the multilayer perceptron :type rng: numpy.random.RandomState :param rng: a random number generator used to initialize weights :type input: theano.tensor.TensorType :param input: symbolic variable that describes the input of the architecture (one minibatch) :type n_in: int :param n_in: number of input units, the dimension of the space in which the datapoints lie :type n_hidden: int :param n_hidden: number of hidden units :type n_out: int :param n_out: number of output units, the dimension of the space in which the labels lie
Initialize the parameters for the multilayer perceptron
[ "Initialize", "the", "parameters", "for", "the", "multilayer", "perceptron" ]
def __init__(self, rng, input, n_in, n_hidden, n_out): """Initialize the parameters for the multilayer perceptron :type rng: numpy.random.RandomState :param rng: a random number generator used to initialize weights :type input: theano.tensor.TensorType :param input: symbolic variable that describes the input of the architecture (one minibatch) :type n_in: int :param n_in: number of input units, the dimension of the space in which the datapoints lie :type n_hidden: int :param n_hidden: number of hidden units :type n_out: int :param n_out: number of output units, the dimension of the space in which the labels lie """ # Since we are dealing with a one hidden layer MLP, this will translate # into a HiddenLayer with a tanh activation function connected to the # LogisticRegression layer; the activation function can be replaced by # sigmoid or any other nonlinear function self.hiddenLayer = HiddenLayer( rng=rng, input=input, n_in=n_in, n_out=n_hidden, activation=T.tanh ) # The logistic regression layer gets as input the hidden units # of the hidden layer self.logRegressionLayer = LogisticRegression( input=self.hiddenLayer.output, n_in=n_hidden, n_out=n_out ) # end-snippet-2 start-snippet-3 # L1 norm ; one regularization option is to enforce L1 norm to # be small self.L1 = ( abs(self.hiddenLayer.W).sum() + abs(self.logRegressionLayer.W).sum() ) # square of L2 norm ; one regularization option is to enforce # square of L2 norm to be small self.L2_sqr = ( (self.hiddenLayer.W ** 2).sum() + (self.logRegressionLayer.W ** 2).sum() ) # negative log likelihood of the MLP is given by the negative # log likelihood of the output of the model, computed in the # logistic regression layer self.negative_log_likelihood = ( self.logRegressionLayer.negative_log_likelihood ) # same holds for the function computing the number of errors self.errors = self.logRegressionLayer.errors # the parameters of the model are the parameters of the two layer it is # made out of self.params = self.hiddenLayer.params + self.logRegressionLayer.params
[ "def", "__init__", "(", "self", ",", "rng", ",", "input", ",", "n_in", ",", "n_hidden", ",", "n_out", ")", ":", "# Since we are dealing with a one hidden layer MLP, this will translate", "# into a HiddenLayer with a tanh activation function connected to the", "# LogisticRegressio...
https://github.com/fephsun/neuralnetmusic/blob/1b559a25bcfb0af14433fad9982825ce17af5518/DeepLearningTutorials/code/mlp.py#L123-L191
ym2011/POC-EXP
206b22d3a6b2a172359678df33bbc5b2ad04b6c3
K8/Web-Exp/sqlmap/lib/core/common.py
python
hashDBRetrieve
(key, unserialize=False, checkConf=False)
return retVal
Helper function for restoring session data from HashDB
Helper function for restoring session data from HashDB
[ "Helper", "function", "for", "restoring", "session", "data", "from", "HashDB" ]
def hashDBRetrieve(key, unserialize=False, checkConf=False): """ Helper function for restoring session data from HashDB """ _ = "%s%s%s" % (conf.url or "%s%s" % (conf.hostname, conf.port), key, HASHDB_MILESTONE_VALUE) retVal = conf.hashDB.retrieve(_, unserialize) if kb.resumeValues and not (checkConf and any((conf.flushSession, conf.freshQueries))) else None if not kb.inferenceMode and not kb.fileReadMode and any(_ in (retVal or "") for _ in (PARTIAL_VALUE_MARKER, PARTIAL_HEX_VALUE_MARKER)): retVal = None return retVal
[ "def", "hashDBRetrieve", "(", "key", ",", "unserialize", "=", "False", ",", "checkConf", "=", "False", ")", ":", "_", "=", "\"%s%s%s\"", "%", "(", "conf", ".", "url", "or", "\"%s%s\"", "%", "(", "conf", ".", "hostname", ",", "conf", ".", "port", ")",...
https://github.com/ym2011/POC-EXP/blob/206b22d3a6b2a172359678df33bbc5b2ad04b6c3/K8/Web-Exp/sqlmap/lib/core/common.py#L3848-L3857
ayoolaolafenwa/PixelLib
ae56003c416a98780141a1170c9d888fe9a31317
pixellib/torchbackend/instance/structures/masks.py
python
PolygonMasks.__init__
(self, polygons: List[List[Union[torch.Tensor, np.ndarray]]])
Arguments: polygons (list[list[np.ndarray]]): The first level of the list correspond to individual instances, the second level to all the polygons that compose the instance, and the third level to the polygon coordinates. The third level array should have the format of [x0, y0, x1, y1, ..., xn, yn] (n >= 3).
Arguments: polygons (list[list[np.ndarray]]): The first level of the list correspond to individual instances, the second level to all the polygons that compose the instance, and the third level to the polygon coordinates. The third level array should have the format of [x0, y0, x1, y1, ..., xn, yn] (n >= 3).
[ "Arguments", ":", "polygons", "(", "list", "[", "list", "[", "np", ".", "ndarray", "]]", ")", ":", "The", "first", "level", "of", "the", "list", "correspond", "to", "individual", "instances", "the", "second", "level", "to", "all", "the", "polygons", "tha...
def __init__(self, polygons: List[List[Union[torch.Tensor, np.ndarray]]]): """ Arguments: polygons (list[list[np.ndarray]]): The first level of the list correspond to individual instances, the second level to all the polygons that compose the instance, and the third level to the polygon coordinates. The third level array should have the format of [x0, y0, x1, y1, ..., xn, yn] (n >= 3). """ if not isinstance(polygons, list): raise ValueError( "Cannot create PolygonMasks: Expect a list of list of polygons per image. " "Got '{}' instead.".format(type(polygons)) ) def _make_array(t: Union[torch.Tensor, np.ndarray]) -> np.ndarray: # Use float64 for higher precision, because why not? # Always put polygons on CPU (self.to is a no-op) since they # are supposed to be small tensors. # May need to change this assumption if GPU placement becomes useful if isinstance(t, torch.Tensor): t = t.cpu().numpy() return np.asarray(t).astype("float64") def process_polygons( polygons_per_instance: List[Union[torch.Tensor, np.ndarray]] ) -> List[np.ndarray]: if not isinstance(polygons_per_instance, list): raise ValueError( "Cannot create polygons: Expect a list of polygons per instance. " "Got '{}' instead.".format(type(polygons_per_instance)) ) # transform each polygon to a numpy array polygons_per_instance = [_make_array(p) for p in polygons_per_instance] for polygon in polygons_per_instance: if len(polygon) % 2 != 0 or len(polygon) < 6: raise ValueError(f"Cannot create a polygon from {len(polygon)} coordinates.") return polygons_per_instance self.polygons: List[List[np.ndarray]] = [ process_polygons(polygons_per_instance) for polygons_per_instance in polygons ]
[ "def", "__init__", "(", "self", ",", "polygons", ":", "List", "[", "List", "[", "Union", "[", "torch", ".", "Tensor", ",", "np", ".", "ndarray", "]", "]", "]", ")", ":", "if", "not", "isinstance", "(", "polygons", ",", "list", ")", ":", "raise", ...
https://github.com/ayoolaolafenwa/PixelLib/blob/ae56003c416a98780141a1170c9d888fe9a31317/pixellib/torchbackend/instance/structures/masks.py#L262-L304
omz/PythonistaAppTemplate
f560f93f8876d82a21d108977f90583df08d55af
PythonistaAppTemplate/PythonistaKit.framework/pylib/site-packages/werkzeug/wrappers.py
python
BaseRequest.args
(self)
return url_decode(wsgi_get_bytes(self.environ.get('QUERY_STRING', '')), self.url_charset, errors=self.encoding_errors, cls=self.parameter_storage_class)
The parsed URL parameters. By default an :class:`~werkzeug.datastructures.ImmutableMultiDict` is returned from this function. This can be changed by setting :attr:`parameter_storage_class` to a different type. This might be necessary if the order of the form data is important.
The parsed URL parameters. By default an :class:`~werkzeug.datastructures.ImmutableMultiDict` is returned from this function. This can be changed by setting :attr:`parameter_storage_class` to a different type. This might be necessary if the order of the form data is important.
[ "The", "parsed", "URL", "parameters", ".", "By", "default", "an", ":", "class", ":", "~werkzeug", ".", "datastructures", ".", "ImmutableMultiDict", "is", "returned", "from", "this", "function", ".", "This", "can", "be", "changed", "by", "setting", ":", "attr...
def args(self): """The parsed URL parameters. By default an :class:`~werkzeug.datastructures.ImmutableMultiDict` is returned from this function. This can be changed by setting :attr:`parameter_storage_class` to a different type. This might be necessary if the order of the form data is important. """ return url_decode(wsgi_get_bytes(self.environ.get('QUERY_STRING', '')), self.url_charset, errors=self.encoding_errors, cls=self.parameter_storage_class)
[ "def", "args", "(", "self", ")", ":", "return", "url_decode", "(", "wsgi_get_bytes", "(", "self", ".", "environ", ".", "get", "(", "'QUERY_STRING'", ",", "''", ")", ")", ",", "self", ".", "url_charset", ",", "errors", "=", "self", ".", "encoding_errors",...
https://github.com/omz/PythonistaAppTemplate/blob/f560f93f8876d82a21d108977f90583df08d55af/PythonistaAppTemplate/PythonistaKit.framework/pylib/site-packages/werkzeug/wrappers.py#L415-L424
google/rekall
55d1925f2df9759a989b35271b4fa48fc54a1c86
rekall-core/rekall/session.py
python
Configuration._set_autodetect_build_local_tracked
(self, tracked, _)
return set(tracked)
Update the tracked modules. When someone updates the build local tracked parameter we need to remove them from all the address resolver caches.
Update the tracked modules.
[ "Update", "the", "tracked", "modules", "." ]
def _set_autodetect_build_local_tracked(self, tracked, _): """Update the tracked modules. When someone updates the build local tracked parameter we need to remove them from all the address resolver caches. """ # Clear all profile caches in address resolver contexts. for context in list(self.session.context_cache.values()): context.reset() return set(tracked)
[ "def", "_set_autodetect_build_local_tracked", "(", "self", ",", "tracked", ",", "_", ")", ":", "# Clear all profile caches in address resolver contexts.", "for", "context", "in", "list", "(", "self", ".", "session", ".", "context_cache", ".", "values", "(", ")", ")"...
https://github.com/google/rekall/blob/55d1925f2df9759a989b35271b4fa48fc54a1c86/rekall-core/rekall/session.py#L305-L315
syb7573330/im2avatar
f4636d35f622f2f1f3915a2a8f3307f3ee104928
models/model_shape.py
python
get_MSFE_cross_entropy_loss
(pred, target)
return tf.add_n(tf.get_collection('losses'), name='total_loss')
Use loss = FPE + FNE, FPE: negative samples, empty voxels in targets FNE: positive samples, non-empty voxels in targets ref: https://www-staff.it.uts.edu.au/~lbcao/publication/IJCNN15.wang.final.pdf Args: pred: (batch, vol_dim, vol_dim, vol_dim, 1) target: (batch, vol_dim, vol_dim, vol_dim, 1), containing value = {0, 1} Rrturns: The total loss
Use loss = FPE + FNE, FPE: negative samples, empty voxels in targets FNE: positive samples, non-empty voxels in targets
[ "Use", "loss", "=", "FPE", "+", "FNE", "FPE", ":", "negative", "samples", "empty", "voxels", "in", "targets", "FNE", ":", "positive", "samples", "non", "-", "empty", "voxels", "in", "targets" ]
def get_MSFE_cross_entropy_loss(pred, target): ''' Use loss = FPE + FNE, FPE: negative samples, empty voxels in targets FNE: positive samples, non-empty voxels in targets ref: https://www-staff.it.uts.edu.au/~lbcao/publication/IJCNN15.wang.final.pdf Args: pred: (batch, vol_dim, vol_dim, vol_dim, 1) target: (batch, vol_dim, vol_dim, vol_dim, 1), containing value = {0, 1} Rrturns: The total loss ''' cross_entropy_loss = tf.nn.sigmoid_cross_entropy_with_logits(labels=target, logits=pred) # FPE fpe = tf.where(target < 0.5, cross_entropy_loss, tf.zeros_like(cross_entropy_loss)) num_neg = tf.shape(tf.where(target < 0.5))[0] # int num_neg = tf.to_float(num_neg) fpe = tf.reduce_sum(fpe) / num_neg # FNE fne = tf.where(target > 0.5, cross_entropy_loss, tf.zeros_like(cross_entropy_loss)) num_pos = tf.shape(tf.where(target > 0.5))[0] # int num_pos = tf.to_float(num_pos) fne = tf.reduce_sum(fne) / num_pos loss = tf.square(fpe) + tf.square(fne) tf.add_to_collection('losses', loss) return tf.add_n(tf.get_collection('losses'), name='total_loss')
[ "def", "get_MSFE_cross_entropy_loss", "(", "pred", ",", "target", ")", ":", "cross_entropy_loss", "=", "tf", ".", "nn", ".", "sigmoid_cross_entropy_with_logits", "(", "labels", "=", "target", ",", "logits", "=", "pred", ")", "# FPE", "fpe", "=", "tf", ".", "...
https://github.com/syb7573330/im2avatar/blob/f4636d35f622f2f1f3915a2a8f3307f3ee104928/models/model_shape.py#L14-L46
cloudera/impyla
0c736af4cad2bade9b8e313badc08ec50e81c948
impala/_thrift_gen/hive_metastore/ThriftHiveMetastore.py
python
drop_constraint_result.validate
(self)
return
[]
def validate(self): return
[ "def", "validate", "(", "self", ")", ":", "return" ]
https://github.com/cloudera/impyla/blob/0c736af4cad2bade9b8e313badc08ec50e81c948/impala/_thrift_gen/hive_metastore/ThriftHiveMetastore.py#L14309-L14310
Trusted-AI/AIF360
963df2e4eea807bd5765fee9f1c594500bdcbb5b
aif360/algorithms/inprocessing/grid_search_reduction.py
python
GridSearchReduction.__init__
(self, estimator, constraints, prot_attr=None, constraint_weight=0.5, grid_size=10, grid_limit=2.0, grid=None, drop_prot_attr=True, loss="ZeroOne", min_val=None, max_val=None)
Args: estimator: An estimator implementing methods ``fit(X, y, sample_weight)`` and ``predict(X)``, where ``X`` is the matrix of features, ``y`` is the vector of labels, and ``sample_weight`` is a vector of weights; labels ``y`` and predictions returned by ``predict(X)`` are either 0 or 1 -- e.g. scikit-learn classifiers/regressors. constraints (str or fairlearn.reductions.Moment): If string, keyword denoting the :class:`fairlearn.reductions.Moment` object defining the disparity constraints -- e.g., "DemographicParity" or "EqualizedOdds". For a full list of possible options see `self.model.moments`. Otherwise, provide the desired :class:`~fairlearn.reductions.Moment` object defining the disparity constraints. prot_attr: String or array-like column indices or column names of protected attributes. constraint_weight: When the ``selection_rule`` is "tradeoff_optimization" (default, no other option currently) this float specifies the relative weight put on the constraint violation when selecting the best model. The weight placed on the error rate will be ``1-constraint_weight``. grid_size (int): The number of Lagrange multipliers to generate in the grid. grid_limit (float): The largest Lagrange multiplier to generate. The grid will contain values distributed between ``-grid_limit`` and ``grid_limit`` by default. grid (pandas.DataFrame): Instead of supplying a size and limit for the grid, users may specify the exact set of Lagrange multipliers they desire using this argument in a DataFrame. drop_prot_attr (bool): Flag indicating whether to drop protected attributes from training data. loss (str): String identifying loss function for constraints. Options include "ZeroOne", "Square", and "Absolute." min_val: Loss function parameter for "Square" and "Absolute," typically the minimum of the range of y values. max_val: Loss function parameter for "Square" and "Absolute," typically the maximum of the range of y values.
Args: estimator: An estimator implementing methods ``fit(X, y, sample_weight)`` and ``predict(X)``, where ``X`` is the matrix of features, ``y`` is the vector of labels, and ``sample_weight`` is a vector of weights; labels ``y`` and predictions returned by ``predict(X)`` are either 0 or 1 -- e.g. scikit-learn classifiers/regressors. constraints (str or fairlearn.reductions.Moment): If string, keyword denoting the :class:`fairlearn.reductions.Moment` object defining the disparity constraints -- e.g., "DemographicParity" or "EqualizedOdds". For a full list of possible options see `self.model.moments`. Otherwise, provide the desired :class:`~fairlearn.reductions.Moment` object defining the disparity constraints. prot_attr: String or array-like column indices or column names of protected attributes. constraint_weight: When the ``selection_rule`` is "tradeoff_optimization" (default, no other option currently) this float specifies the relative weight put on the constraint violation when selecting the best model. The weight placed on the error rate will be ``1-constraint_weight``. grid_size (int): The number of Lagrange multipliers to generate in the grid. grid_limit (float): The largest Lagrange multiplier to generate. The grid will contain values distributed between ``-grid_limit`` and ``grid_limit`` by default. grid (pandas.DataFrame): Instead of supplying a size and limit for the grid, users may specify the exact set of Lagrange multipliers they desire using this argument in a DataFrame. drop_prot_attr (bool): Flag indicating whether to drop protected attributes from training data. loss (str): String identifying loss function for constraints. Options include "ZeroOne", "Square", and "Absolute." min_val: Loss function parameter for "Square" and "Absolute," typically the minimum of the range of y values. max_val: Loss function parameter for "Square" and "Absolute," typically the maximum of the range of y values.
[ "Args", ":", "estimator", ":", "An", "estimator", "implementing", "methods", "fit", "(", "X", "y", "sample_weight", ")", "and", "predict", "(", "X", ")", "where", "X", "is", "the", "matrix", "of", "features", "y", "is", "the", "vector", "of", "labels", ...
def __init__(self, estimator, constraints, prot_attr=None, constraint_weight=0.5, grid_size=10, grid_limit=2.0, grid=None, drop_prot_attr=True, loss="ZeroOne", min_val=None, max_val=None): """ Args: estimator: An estimator implementing methods ``fit(X, y, sample_weight)`` and ``predict(X)``, where ``X`` is the matrix of features, ``y`` is the vector of labels, and ``sample_weight`` is a vector of weights; labels ``y`` and predictions returned by ``predict(X)`` are either 0 or 1 -- e.g. scikit-learn classifiers/regressors. constraints (str or fairlearn.reductions.Moment): If string, keyword denoting the :class:`fairlearn.reductions.Moment` object defining the disparity constraints -- e.g., "DemographicParity" or "EqualizedOdds". For a full list of possible options see `self.model.moments`. Otherwise, provide the desired :class:`~fairlearn.reductions.Moment` object defining the disparity constraints. prot_attr: String or array-like column indices or column names of protected attributes. constraint_weight: When the ``selection_rule`` is "tradeoff_optimization" (default, no other option currently) this float specifies the relative weight put on the constraint violation when selecting the best model. The weight placed on the error rate will be ``1-constraint_weight``. grid_size (int): The number of Lagrange multipliers to generate in the grid. grid_limit (float): The largest Lagrange multiplier to generate. The grid will contain values distributed between ``-grid_limit`` and ``grid_limit`` by default. grid (pandas.DataFrame): Instead of supplying a size and limit for the grid, users may specify the exact set of Lagrange multipliers they desire using this argument in a DataFrame. drop_prot_attr (bool): Flag indicating whether to drop protected attributes from training data. loss (str): String identifying loss function for constraints. Options include "ZeroOne", "Square", and "Absolute." min_val: Loss function parameter for "Square" and "Absolute," typically the minimum of the range of y values. max_val: Loss function parameter for "Square" and "Absolute," typically the maximum of the range of y values. """ super(GridSearchReduction, self).__init__() #init model, set prot_attr during fit if prot_attr is None: prot_attr = [] self.model = skGridSearchRed(prot_attr, estimator, constraints, constraint_weight, grid_size, grid_limit, grid, drop_prot_attr, loss, min_val, max_val)
[ "def", "__init__", "(", "self", ",", "estimator", ",", "constraints", ",", "prot_attr", "=", "None", ",", "constraint_weight", "=", "0.5", ",", "grid_size", "=", "10", ",", "grid_limit", "=", "2.0", ",", "grid", "=", "None", ",", "drop_prot_attr", "=", "...
https://github.com/Trusted-AI/AIF360/blob/963df2e4eea807bd5765fee9f1c594500bdcbb5b/aif360/algorithms/inprocessing/grid_search_reduction.py#L38-L96
wonderworks-software/PyFlow
57e2c858933bf63890d769d985396dfad0fca0f0
PyFlow/UI/Widgets/QtSliders.py
python
valueBox.__init__
(self, labelText="", type="float", buttons=False, decimals=3, draggerSteps=FLOAT_SLIDER_DRAG_STEPS, *args, **kwargs)
:param type: Choose if create a float or int spinBox, defaults to "float" :type type: str, optional :param buttons: Show or hidden right up/Down Buttons, defaults to False :type buttons: bool, optional :param decimals: Number of decimals if type is "float", defaults to 3 :type decimals: int, optional :param *args: [description] :type *args: [type] :param **kwargs: [description] :type **kwargs: [type]
:param type: Choose if create a float or int spinBox, defaults to "float" :type type: str, optional :param buttons: Show or hidden right up/Down Buttons, defaults to False :type buttons: bool, optional :param decimals: Number of decimals if type is "float", defaults to 3 :type decimals: int, optional :param *args: [description] :type *args: [type] :param **kwargs: [description] :type **kwargs: [type]
[ ":", "param", "type", ":", "Choose", "if", "create", "a", "float", "or", "int", "spinBox", "defaults", "to", "float", ":", "type", "type", ":", "str", "optional", ":", "param", "buttons", ":", "Show", "or", "hidden", "right", "up", "/", "Down", "Button...
def __init__(self, labelText="", type="float", buttons=False, decimals=3, draggerSteps=FLOAT_SLIDER_DRAG_STEPS, *args, **kwargs): """ :param type: Choose if create a float or int spinBox, defaults to "float" :type type: str, optional :param buttons: Show or hidden right up/Down Buttons, defaults to False :type buttons: bool, optional :param decimals: Number of decimals if type is "float", defaults to 3 :type decimals: int, optional :param *args: [description] :type *args: [type] :param **kwargs: [description] :type **kwargs: [type] """ super(valueBox, self).__init__(*args, **kwargs) self.labelFont = QtGui.QFont('Serif', 10, QtGui.QFont.Bold) self.labelText = labelText self.draggerSteps = copy(draggerSteps) self.isFloat = type == "float" if not self.isFloat: self.setDecimals(0) else: self.setDecimals(decimals) if not buttons: self.setButtonSymbols(QtWidgets.QAbstractSpinBox.NoButtons) self.setStyleSheet(editableStyleSheet().getSliderStyleSheet("sliderStyleSheetA")) self.lineEdit().installEventFilter(self) self.installEventFilter(self) self.setFocusPolicy(QtCore.Qt.StrongFocus) self.draggers = None self.setRange(FLOAT_RANGE_MIN, FLOAT_RANGE_MAX)
[ "def", "__init__", "(", "self", ",", "labelText", "=", "\"\"", ",", "type", "=", "\"float\"", ",", "buttons", "=", "False", ",", "decimals", "=", "3", ",", "draggerSteps", "=", "FLOAT_SLIDER_DRAG_STEPS", ",", "*", "args", ",", "*", "*", "kwargs", ")", ...
https://github.com/wonderworks-software/PyFlow/blob/57e2c858933bf63890d769d985396dfad0fca0f0/PyFlow/UI/Widgets/QtSliders.py#L327-L356
chribsen/simple-machine-learning-examples
dc94e52a4cebdc8bb959ff88b81ff8cfeca25022
venv/lib/python2.7/site-packages/pandas/io/html.py
python
_HtmlFrameParser._parse_tables
(self, doc, match, attrs)
Return all tables from the parsed DOM. Parameters ---------- doc : tree-like The DOM from which to parse the table element. match : str or regular expression The text to search for in the DOM tree. attrs : dict A dictionary of table attributes that can be used to disambiguate mutliple tables on a page. Raises ------ ValueError * If `match` does not match any text in the document. Returns ------- tables : list of node-like A list of <table> elements to be parsed into raw data.
Return all tables from the parsed DOM.
[ "Return", "all", "tables", "from", "the", "parsed", "DOM", "." ]
def _parse_tables(self, doc, match, attrs): """Return all tables from the parsed DOM. Parameters ---------- doc : tree-like The DOM from which to parse the table element. match : str or regular expression The text to search for in the DOM tree. attrs : dict A dictionary of table attributes that can be used to disambiguate mutliple tables on a page. Raises ------ ValueError * If `match` does not match any text in the document. Returns ------- tables : list of node-like A list of <table> elements to be parsed into raw data. """ raise AbstractMethodError(self)
[ "def", "_parse_tables", "(", "self", ",", "doc", ",", "match", ",", "attrs", ")", ":", "raise", "AbstractMethodError", "(", "self", ")" ]
https://github.com/chribsen/simple-machine-learning-examples/blob/dc94e52a4cebdc8bb959ff88b81ff8cfeca25022/venv/lib/python2.7/site-packages/pandas/io/html.py#L252-L277
apple/ccs-calendarserver
13c706b985fb728b9aab42dc0fef85aae21921c3
txweb2/log.py
python
logFilter
(request, response, startTime=None)
return response
[]
def logFilter(request, response, startTime=None): if startTime is None: startTime = time.time() def _log(success, length): loginfo = LogInfo() loginfo.bytesSent = length loginfo.responseCompleted = success loginfo.secondsTaken = time.time() - startTime if length: request.timeStamp("t-resp-wr") log.info(interface=iweb.IRequest, request=request, response=response, loginfo=loginfo) # Or just... # ILogger(ctx).log(...) ? request.timeStamp("t-resp-gen") if response.stream: response.stream = _LogByteCounter(response.stream, _log) else: _log(True, 0) return response
[ "def", "logFilter", "(", "request", ",", "response", ",", "startTime", "=", "None", ")", ":", "if", "startTime", "is", "None", ":", "startTime", "=", "time", ".", "time", "(", ")", "def", "_log", "(", "success", ",", "length", ")", ":", "loginfo", "=...
https://github.com/apple/ccs-calendarserver/blob/13c706b985fb728b9aab42dc0fef85aae21921c3/txweb2/log.py#L93-L116
krintoxi/NoobSec-Toolkit
38738541cbc03cedb9a3b3ed13b629f781ad64f6
NoobSecToolkit - MAC OSX/scripts/sshbackdoors/rpyc/core/stream.py
python
Win32PipeStream.poll
(self, timeout, interval = 0.1)
return length != 0
a poor man's version of select()
a poor man's version of select()
[ "a", "poor", "man", "s", "version", "of", "select", "()" ]
def poll(self, timeout, interval = 0.1): """a poor man's version of select()""" if timeout is None: timeout = maxint length = 0 tmax = time.time() + timeout try: while length == 0: length = win32pipe.PeekNamedPipe(self.incoming, 0)[1] if time.time() >= tmax: break time.sleep(interval) except TypeError: ex = sys.exc_info()[1] if not self.closed: raise raise EOFError(ex) return length != 0
[ "def", "poll", "(", "self", ",", "timeout", ",", "interval", "=", "0.1", ")", ":", "if", "timeout", "is", "None", ":", "timeout", "=", "maxint", "length", "=", "0", "tmax", "=", "time", ".", "time", "(", ")", "+", "timeout", "try", ":", "while", ...
https://github.com/krintoxi/NoobSec-Toolkit/blob/38738541cbc03cedb9a3b3ed13b629f781ad64f6/NoobSecToolkit - MAC OSX/scripts/sshbackdoors/rpyc/core/stream.py#L365-L382
wistbean/fxxkpython
88e16d79d8dd37236ba6ecd0d0ff11d63143968c
vip/qyxuan/projects/venv/lib/python3.6/site-packages/pip-19.0.3-py3.6.egg/pip/_vendor/distlib/_backport/tarfile.py
python
TarFile.__iter__
(self)
Provide an iterator object.
Provide an iterator object.
[ "Provide", "an", "iterator", "object", "." ]
def __iter__(self): """Provide an iterator object. """ if self._loaded: return iter(self.members) else: return TarIter(self)
[ "def", "__iter__", "(", "self", ")", ":", "if", "self", ".", "_loaded", ":", "return", "iter", "(", "self", ".", "members", ")", "else", ":", "return", "TarIter", "(", "self", ")" ]
https://github.com/wistbean/fxxkpython/blob/88e16d79d8dd37236ba6ecd0d0ff11d63143968c/vip/qyxuan/projects/venv/lib/python3.6/site-packages/pip-19.0.3-py3.6.egg/pip/_vendor/distlib/_backport/tarfile.py#L2524-L2530
kbandla/ImmunityDebugger
2abc03fb15c8f3ed0914e1175c4d8933977c73e3
1.74/Libs/pefile.py
python
COFF.print_info
(self)
Print all the PE header information in a human readable from.
Print all the PE header information in a human readable from.
[ "Print", "all", "the", "PE", "header", "information", "in", "a", "human", "readable", "from", "." ]
def print_info(self): """Print all the PE header information in a human readable from.""" print self.dump_info()
[ "def", "print_info", "(", "self", ")", ":", "print", "self", ".", "dump_info", "(", ")" ]
https://github.com/kbandla/ImmunityDebugger/blob/2abc03fb15c8f3ed0914e1175c4d8933977c73e3/1.74/Libs/pefile.py#L3303-L3305
dvlab-research/3DSSD
8bc7605d4d3a6ec9051e7689e96a23bdac4c4cd9
lib/dataset/dataloader/kitti_dataloader.py
python
KittiDataset.evaluate_map
(self, sess, feeddict_producer, pred_list, val_size, cls_thresh, log_dir, placeholders=None)
return result_list
[]
def evaluate_map(self, sess, feeddict_producer, pred_list, val_size, cls_thresh, log_dir, placeholders=None): obj_detection_list = [] obj_detection_num = [] obj_detection_name = [] for i in tqdm.tqdm(range(val_size)): feed_dict = feeddict_producer.create_feed_dict() pred_bbox_3d_op, pred_cls_score_op, pred_cls_category_op = sess.run(pred_list, feed_dict=feed_dict) calib_P, sample_name = feeddict_producer.info sample_name = int(sample_name[0]) calib_P = calib_P[0] select_idx = np.where(pred_cls_score_op >= cls_thresh)[0] pred_cls_score_op = pred_cls_score_op[select_idx] pred_cls_category_op = pred_cls_category_op[select_idx] pred_bbox_3d_op = pred_bbox_3d_op[select_idx] pred_bbox_corners_op = box_3d_utils.get_box3d_corners_helper_np(pred_bbox_3d_op[:, :3], pred_bbox_3d_op[:, -1], pred_bbox_3d_op[:, 3:-1]) pred_bbox_2d = project_to_image_space_corners(pred_bbox_corners_op, calib_P) obj_num = len(pred_bbox_3d_op) obj_detection = np.zeros([obj_num, 14], np.float32) if 'Car' not in self.cls_list: pred_cls_category_op += 1 obj_detection[:, 0] = pred_cls_category_op obj_detection[:, 1:5] = pred_bbox_2d obj_detection[:, 6:9] = pred_bbox_3d_op[:, :3] obj_detection[:, 9] = pred_bbox_3d_op[:, 4] # h obj_detection[:, 10] = pred_bbox_3d_op[:, 5] # w obj_detection[:, 11] = pred_bbox_3d_op[:, 3] # l obj_detection[:, 12] = pred_bbox_3d_op[:, 6] # ry obj_detection[:, 13] = pred_cls_score_op obj_detection_list.append(obj_detection) obj_detection_name.append(os.path.join(self.label_dir, '%06d.txt'%sample_name)) obj_detection_num.append(obj_num) obj_detection_list = np.concatenate(obj_detection_list, axis=0) obj_detection_name = np.array(obj_detection_name, dtype=np.string_) obj_detection_num = np.array(obj_detection_num, dtype=np.int) precision_img, aos_img, precision_ground, aos_ground, precision_3d, aos_3d = evaluate(obj_detection_list, obj_detection_name, obj_detection_num) precision_img_op, aos_img_op, precision_ground_op, aos_ground_op, precision_3d_op, aos_3d_op = sess.run([precision_img, aos_img, precision_ground, aos_ground, precision_3d, aos_3d]) result_list = [precision_img_op, aos_img_op, precision_ground_op, aos_ground_op, precision_3d_op, aos_3d_op] return result_list
[ "def", "evaluate_map", "(", "self", ",", "sess", ",", "feeddict_producer", ",", "pred_list", ",", "val_size", ",", "cls_thresh", ",", "log_dir", ",", "placeholders", "=", "None", ")", ":", "obj_detection_list", "=", "[", "]", "obj_detection_num", "=", "[", "...
https://github.com/dvlab-research/3DSSD/blob/8bc7605d4d3a6ec9051e7689e96a23bdac4c4cd9/lib/dataset/dataloader/kitti_dataloader.py#L336-L382
google/clusterfuzz
f358af24f414daa17a3649b143e71ea71871ef59
src/appengine/libs/issue_management/issue_tracker.py
python
Issue.issue_tracker
(self)
The issue tracker for this issue.
The issue tracker for this issue.
[ "The", "issue", "tracker", "for", "this", "issue", "." ]
def issue_tracker(self): """The issue tracker for this issue.""" raise NotImplementedError
[ "def", "issue_tracker", "(", "self", ")", ":", "raise", "NotImplementedError" ]
https://github.com/google/clusterfuzz/blob/f358af24f414daa17a3649b143e71ea71871ef59/src/appengine/libs/issue_management/issue_tracker.py#L113-L115
JetBrains/python-skeletons
95ad24b666e475998e5d1cc02ed53a2188036167
builtins.py
python
complex.__init__
(self, real=None, imag=None)
Create a complex number with the value real + imag*j or convert a string or number to a complex number. :type real: object :type imag: object
Create a complex number with the value real + imag*j or convert a string or number to a complex number.
[ "Create", "a", "complex", "number", "with", "the", "value", "real", "+", "imag", "*", "j", "or", "convert", "a", "string", "or", "number", "to", "a", "complex", "number", "." ]
def __init__(self, real=None, imag=None): """Create a complex number with the value real + imag*j or convert a string or number to a complex number. :type real: object :type imag: object """ pass
[ "def", "__init__", "(", "self", ",", "real", "=", "None", ",", "imag", "=", "None", ")", ":", "pass" ]
https://github.com/JetBrains/python-skeletons/blob/95ad24b666e475998e5d1cc02ed53a2188036167/builtins.py#L835-L842
DLR-RM/BlenderProc
e04e03f34b66702bbca45d1ac701599b6d764609
blenderproc/python/modules/provider/sampler/DiskModule.py
python
DiskModule.run
(self)
return disk( center=center, radius=radius, rotation=euler_angles, sample_from=sample_from, start_angle=start_angle, end_angle=end_angle )
:return: A random point sampled point on a circle/disk/arc/sector. Type: mathutils.Vector.
:return: A random point sampled point on a circle/disk/arc/sector. Type: mathutils.Vector.
[ ":", "return", ":", "A", "random", "point", "sampled", "point", "on", "a", "circle", "/", "disk", "/", "arc", "/", "sector", ".", "Type", ":", "mathutils", ".", "Vector", "." ]
def run(self): """ :return: A random point sampled point on a circle/disk/arc/sector. Type: mathutils.Vector. """ center = self.config.get_vector3d("center") radius = self.config.get_float("radius") euler_angles = self.config.get_vector3d("rotation", [0, 0, 0]) sample_from = self.config.get_string("sample_from", "disk") start_angle = self.config.get_float("start_angle", 0) end_angle = self.config.get_float("end_angle", 180) return disk( center=center, radius=radius, rotation=euler_angles, sample_from=sample_from, start_angle=start_angle, end_angle=end_angle )
[ "def", "run", "(", "self", ")", ":", "center", "=", "self", ".", "config", ".", "get_vector3d", "(", "\"center\"", ")", "radius", "=", "self", ".", "config", ".", "get_float", "(", "\"radius\"", ")", "euler_angles", "=", "self", ".", "config", ".", "ge...
https://github.com/DLR-RM/BlenderProc/blob/e04e03f34b66702bbca45d1ac701599b6d764609/blenderproc/python/modules/provider/sampler/DiskModule.py#L72-L90
ChengyueGongR/Frequency-Agnostic
cfb024a4843abb2f7c768fd155cbeb4da05b44d9
fairseq-machine-translation/fairseq/distributed_utils.py
python
suppress_output
()
Suppress printing on the current device. Force printing with `force=True`.
Suppress printing on the current device. Force printing with `force=True`.
[ "Suppress", "printing", "on", "the", "current", "device", ".", "Force", "printing", "with", "force", "=", "True", "." ]
def suppress_output(): """Suppress printing on the current device. Force printing with `force=True`.""" import builtins as __builtin__ builtin_print = __builtin__.print def print(*args, **kwargs): if 'force' in kwargs: force = kwargs.pop('force') if force: builtin_print(*args, **kwargs) __builtin__.print = print
[ "def", "suppress_output", "(", ")", ":", "import", "builtins", "as", "__builtin__", "builtin_print", "=", "__builtin__", ".", "print", "def", "print", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "'force'", "in", "kwargs", ":", "force", "="...
https://github.com/ChengyueGongR/Frequency-Agnostic/blob/cfb024a4843abb2f7c768fd155cbeb4da05b44d9/fairseq-machine-translation/fairseq/distributed_utils.py#L41-L52
projecthamster/hamster
19d160090de30e756bdc3122ff935bdaa86e2843
waflib/Task.py
python
Task.are_implicit_nodes_ready
(self)
For each node returned by the scanner, see if there is a task that creates it, and infer the build order This has a low performance impact on null builds (1.86s->1.66s) thanks to caching (28s->1.86s)
For each node returned by the scanner, see if there is a task that creates it, and infer the build order
[ "For", "each", "node", "returned", "by", "the", "scanner", "see", "if", "there", "is", "a", "task", "that", "creates", "it", "and", "infer", "the", "build", "order" ]
def are_implicit_nodes_ready(self): """ For each node returned by the scanner, see if there is a task that creates it, and infer the build order This has a low performance impact on null builds (1.86s->1.66s) thanks to caching (28s->1.86s) """ bld = self.generator.bld try: cache = bld.dct_implicit_nodes except AttributeError: bld.dct_implicit_nodes = cache = {} # one cache per build group try: dct = cache[bld.current_group] except KeyError: dct = cache[bld.current_group] = {} for tsk in bld.cur_tasks: for x in tsk.outputs: dct[x] = tsk modified = False for x in bld.node_deps.get(self.uid(), []): if x in dct: self.run_after.add(dct[x]) modified = True if modified: for tsk in self.run_after: if not tsk.hasrun: #print "task is not ready..." raise Errors.TaskNotReady('not ready')
[ "def", "are_implicit_nodes_ready", "(", "self", ")", ":", "bld", "=", "self", ".", "generator", ".", "bld", "try", ":", "cache", "=", "bld", ".", "dct_implicit_nodes", "except", "AttributeError", ":", "bld", ".", "dct_implicit_nodes", "=", "cache", "=", "{",...
https://github.com/projecthamster/hamster/blob/19d160090de30e756bdc3122ff935bdaa86e2843/waflib/Task.py#L880-L912
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/Python-2.7.9/Lib/bdb.py
python
Bdb.set_return
(self, frame)
Stop when returning from the given frame.
Stop when returning from the given frame.
[ "Stop", "when", "returning", "from", "the", "given", "frame", "." ]
def set_return(self, frame): """Stop when returning from the given frame.""" self._set_stopinfo(frame.f_back, frame)
[ "def", "set_return", "(", "self", ",", "frame", ")", ":", "self", ".", "_set_stopinfo", "(", "frame", ".", "f_back", ",", "frame", ")" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/Python-2.7.9/Lib/bdb.py#L208-L210
sunnyxiaohu/R-C3D.pytorch
e8731af7b95f1dc934f6604f9c09e3c4ead74db5
lib/tf_model_zoo/models/slim/nets/inception_v4.py
python
block_inception_c
(inputs, scope=None, reuse=None)
Builds Inception-C block for Inception v4 network.
Builds Inception-C block for Inception v4 network.
[ "Builds", "Inception", "-", "C", "block", "for", "Inception", "v4", "network", "." ]
def block_inception_c(inputs, scope=None, reuse=None): """Builds Inception-C block for Inception v4 network.""" # By default use stride=1 and SAME padding with slim.arg_scope([slim.conv2d, slim.avg_pool2d, slim.max_pool2d], stride=1, padding='SAME'): with tf.variable_scope(scope, 'BlockInceptionC', [inputs], reuse=reuse): with tf.variable_scope('Branch_0'): branch_0 = slim.conv2d(inputs, 256, [1, 1], scope='Conv2d_0a_1x1') with tf.variable_scope('Branch_1'): branch_1 = slim.conv2d(inputs, 384, [1, 1], scope='Conv2d_0a_1x1') branch_1 = tf.concat(3, [ slim.conv2d(branch_1, 256, [1, 3], scope='Conv2d_0b_1x3'), slim.conv2d(branch_1, 256, [3, 1], scope='Conv2d_0c_3x1')]) with tf.variable_scope('Branch_2'): branch_2 = slim.conv2d(inputs, 384, [1, 1], scope='Conv2d_0a_1x1') branch_2 = slim.conv2d(branch_2, 448, [3, 1], scope='Conv2d_0b_3x1') branch_2 = slim.conv2d(branch_2, 512, [1, 3], scope='Conv2d_0c_1x3') branch_2 = tf.concat(3, [ slim.conv2d(branch_2, 256, [1, 3], scope='Conv2d_0d_1x3'), slim.conv2d(branch_2, 256, [3, 1], scope='Conv2d_0e_3x1')]) with tf.variable_scope('Branch_3'): branch_3 = slim.avg_pool2d(inputs, [3, 3], scope='AvgPool_0a_3x3') branch_3 = slim.conv2d(branch_3, 256, [1, 1], scope='Conv2d_0b_1x1') return tf.concat(3, [branch_0, branch_1, branch_2, branch_3])
[ "def", "block_inception_c", "(", "inputs", ",", "scope", "=", "None", ",", "reuse", "=", "None", ")", ":", "# By default use stride=1 and SAME padding", "with", "slim", ".", "arg_scope", "(", "[", "slim", ".", "conv2d", ",", "slim", ".", "avg_pool2d", ",", "...
https://github.com/sunnyxiaohu/R-C3D.pytorch/blob/e8731af7b95f1dc934f6604f9c09e3c4ead74db5/lib/tf_model_zoo/models/slim/nets/inception_v4.py#L121-L144
neptune-ai/open-solution-salt-identification
394f16b23b6e30543aee54701f81a06b5dd92a98
main.py
python
train_evaluate_predict_cv
()
[]
def train_evaluate_predict_cv(): meta = pd.read_csv(PARAMS.metadata_filepath) if DEV_MODE: meta = meta.sample(PARAMS.dev_mode_size, random_state=SEED) meta_train = meta[meta['is_train'] == 1] meta_test = meta[meta['is_train'] == 0] with neptune.create_experiment(name=EXPERIMENT_NAME, params=PARAMS, tags=TAGS + ['train', 'evaluate', 'predict', 'on_cv_folds'], upload_source_files=get_filepaths(), properties={'experiment_dir': EXPERIMENT_DIR}): cv = utils.KFoldBySortedValue(n_splits=PARAMS.n_cv_splits, shuffle=PARAMS.shuffle, random_state=SEED) fold_iou, fold_iout, out_of_fold_train_predictions, out_of_fold_test_predictions = [], [], [], [] for fold_id, (train_idx, valid_idx) in enumerate(cv.split(meta_train[DEPTH_COLUMN].values.reshape(-1))): train_data_split, valid_data_split = meta_train.iloc[train_idx], meta_train.iloc[valid_idx] if USE_AUXILIARY_DATA: auxiliary = pd.read_csv(PARAMS.auxiliary_metadata_filepath) train_auxiliary = auxiliary[auxiliary[ID_COLUMN].isin(valid_data_split[ID_COLUMN].tolist())] train_data_split = pd.concat([train_data_split, train_auxiliary], axis=0) LOGGER.info('Started fold {}'.format(fold_id)) iou, iout, out_of_fold_prediction, test_prediction = fold_fit_evaluate_predict_loop(train_data_split, valid_data_split, meta_test, fold_id) LOGGER.info('Fold {} IOU {}'.format(fold_id, iou)) neptune.send_metric('Fold {} IOU'.format(fold_id), iou) LOGGER.info('Fold {} IOUT {}'.format(fold_id, iout)) neptune.send_metric('Fold {} IOUT'.format(fold_id), iout) fold_iou.append(iou) fold_iout.append(iout) out_of_fold_train_predictions.append(out_of_fold_prediction) out_of_fold_test_predictions.append(test_prediction) train_ids, train_predictions = [], [] for idx_fold, train_pred_fold in out_of_fold_train_predictions: train_ids.extend(idx_fold) train_predictions.extend(train_pred_fold) iou_mean, iou_std = np.mean(fold_iou), np.std(fold_iou) iout_mean, iout_std = np.mean(fold_iout), np.std(fold_iout) log_scores(iou_mean, iou_std, iout_mean, iout_std) save_predictions(train_ids, train_predictions, meta_test, out_of_fold_test_predictions)
[ "def", "train_evaluate_predict_cv", "(", ")", ":", "meta", "=", "pd", ".", "read_csv", "(", "PARAMS", ".", "metadata_filepath", ")", "if", "DEV_MODE", ":", "meta", "=", "meta", ".", "sample", "(", "PARAMS", ".", "dev_mode_size", ",", "random_state", "=", "...
https://github.com/neptune-ai/open-solution-salt-identification/blob/394f16b23b6e30543aee54701f81a06b5dd92a98/main.py#L617-L668
jamalex/notion-py
c9223c0539acf38fd4cec88a629cfe4552ee4bf8
notion/client.py
python
NotionClient.get_space
(self, space_id, force_refresh=False)
return Space(self, space_id) if space else None
Retrieve an instance of Space that maps to the space identified by the ID passed in.
Retrieve an instance of Space that maps to the space identified by the ID passed in.
[ "Retrieve", "an", "instance", "of", "Space", "that", "maps", "to", "the", "space", "identified", "by", "the", "ID", "passed", "in", "." ]
def get_space(self, space_id, force_refresh=False): """ Retrieve an instance of Space that maps to the space identified by the ID passed in. """ space = self.get_record_data("space", space_id, force_refresh=force_refresh) return Space(self, space_id) if space else None
[ "def", "get_space", "(", "self", ",", "space_id", ",", "force_refresh", "=", "False", ")", ":", "space", "=", "self", ".", "get_record_data", "(", "\"space\"", ",", "space_id", ",", "force_refresh", "=", "force_refresh", ")", "return", "Space", "(", "self", ...
https://github.com/jamalex/notion-py/blob/c9223c0539acf38fd4cec88a629cfe4552ee4bf8/notion/client.py#L197-L202
pypa/pipenv
b21baade71a86ab3ee1429f71fbc14d4f95fb75d
pipenv/patched/notpip/_vendor/urllib3/contrib/socks.py
python
SOCKSConnection.__init__
(self, *args, **kwargs)
[]
def __init__(self, *args, **kwargs): self._socks_options = kwargs.pop("_socks_options") super(SOCKSConnection, self).__init__(*args, **kwargs)
[ "def", "__init__", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "self", ".", "_socks_options", "=", "kwargs", ".", "pop", "(", "\"_socks_options\"", ")", "super", "(", "SOCKSConnection", ",", "self", ")", ".", "__init__", "(", "*",...
https://github.com/pypa/pipenv/blob/b21baade71a86ab3ee1429f71fbc14d4f95fb75d/pipenv/patched/notpip/_vendor/urllib3/contrib/socks.py#L80-L82
BlackLight/platypush
a6b552504e2ac327c94f3a28b607061b6b60cf36
platypush/plugins/assistant/google/__init__.py
python
AssistantGooglePlugin.is_muted
(self)
return assistant.is_muted()
:return: True if the microphone is muted, False otherwise.
:return: True if the microphone is muted, False otherwise.
[ ":", "return", ":", "True", "if", "the", "microphone", "is", "muted", "False", "otherwise", "." ]
def is_muted(self) -> bool: """ :return: True if the microphone is muted, False otherwise. """ assistant = self._get_assistant() return assistant.is_muted()
[ "def", "is_muted", "(", "self", ")", "->", "bool", ":", "assistant", "=", "self", ".", "_get_assistant", "(", ")", "return", "assistant", ".", "is_muted", "(", ")" ]
https://github.com/BlackLight/platypush/blob/a6b552504e2ac327c94f3a28b607061b6b60cf36/platypush/plugins/assistant/google/__init__.py#L60-L65
openhatch/oh-mainline
ce29352a034e1223141dcc2f317030bbc3359a51
vendor/packages/python-openid/openid/server/server.py
python
OpenIDResponse.whichEncoding
(self)
How should I be encoded? @returns: one of ENCODE_URL, ENCODE_HTML_FORM, or ENCODE_KVFORM. @change: 2.1.0 added the ENCODE_HTML_FORM response.
How should I be encoded?
[ "How", "should", "I", "be", "encoded?" ]
def whichEncoding(self): """How should I be encoded? @returns: one of ENCODE_URL, ENCODE_HTML_FORM, or ENCODE_KVFORM. @change: 2.1.0 added the ENCODE_HTML_FORM response. """ if self.request.mode in BROWSER_REQUEST_MODES: if self.fields.getOpenIDNamespace() == OPENID2_NS and \ len(self.encodeToURL()) > OPENID1_URL_LIMIT: return ENCODE_HTML_FORM else: return ENCODE_URL else: return ENCODE_KVFORM
[ "def", "whichEncoding", "(", "self", ")", ":", "if", "self", ".", "request", ".", "mode", "in", "BROWSER_REQUEST_MODES", ":", "if", "self", ".", "fields", ".", "getOpenIDNamespace", "(", ")", "==", "OPENID2_NS", "and", "len", "(", "self", ".", "encodeToURL...
https://github.com/openhatch/oh-mainline/blob/ce29352a034e1223141dcc2f317030bbc3359a51/vendor/packages/python-openid/openid/server/server.py#L1037-L1051
bruderstein/PythonScript
df9f7071ddf3a079e3a301b9b53a6dc78cf1208f
PythonLib/full/codecs.py
python
StreamReaderWriter.reset
(self)
[]
def reset(self): self.reader.reset() self.writer.reset()
[ "def", "reset", "(", "self", ")", ":", "self", ".", "reader", ".", "reset", "(", ")", "self", ".", "writer", ".", "reset", "(", ")" ]
https://github.com/bruderstein/PythonScript/blob/df9f7071ddf3a079e3a301b9b53a6dc78cf1208f/PythonLib/full/codecs.py#L727-L730
pytroll/satpy
09e51f932048f98cce7919a4ff8bd2ec01e1ae98
satpy/readers/yaml_reader.py
python
AbstractYAMLReader.start_time
(self)
Start time of the reader.
Start time of the reader.
[ "Start", "time", "of", "the", "reader", "." ]
def start_time(self): """Start time of the reader."""
[ "def", "start_time", "(", "self", ")", ":" ]
https://github.com/pytroll/satpy/blob/09e51f932048f98cce7919a4ff8bd2ec01e1ae98/satpy/readers/yaml_reader.py#L195-L196
saltstack/salt
fae5bc757ad0f1716483ce7ae180b451545c2058
salt/states/lvs_server.py
python
absent
(name, protocol=None, service_address=None, server_address=None)
return ret
Ensure the LVS Real Server in specified service is absent. name The name of the LVS server. protocol The service protocol(only support ``tcp``, ``udp`` and ``fwmark`` service). service_address The LVS service address. server_address The LVS real server address.
Ensure the LVS Real Server in specified service is absent.
[ "Ensure", "the", "LVS", "Real", "Server", "in", "specified", "service", "is", "absent", "." ]
def absent(name, protocol=None, service_address=None, server_address=None): """ Ensure the LVS Real Server in specified service is absent. name The name of the LVS server. protocol The service protocol(only support ``tcp``, ``udp`` and ``fwmark`` service). service_address The LVS service address. server_address The LVS real server address. """ ret = {"name": name, "changes": {}, "result": True, "comment": ""} # check if server exists and remove it server_check = __salt__["lvs.check_server"]( protocol=protocol, service_address=service_address, server_address=server_address, ) if server_check is True: if __opts__["test"]: ret["result"] = None ret[ "comment" ] = "LVS Server {} in service {}({}) is present and needs to be removed".format( name, service_address, protocol ) return ret server_delete = __salt__["lvs.delete_server"]( protocol=protocol, service_address=service_address, server_address=server_address, ) if server_delete is True: ret["comment"] = "LVS Server {} in service {}({}) has been removed".format( name, service_address, protocol ) ret["changes"][name] = "Absent" return ret else: ret[ "comment" ] = "LVS Server {} in service {}({}) removed failed({})".format( name, service_address, protocol, server_delete ) ret["result"] = False return ret else: ret[ "comment" ] = "LVS Server {} in service {}({}) is not present, so it cannot be removed".format( name, service_address, protocol ) return ret
[ "def", "absent", "(", "name", ",", "protocol", "=", "None", ",", "service_address", "=", "None", ",", "server_address", "=", "None", ")", ":", "ret", "=", "{", "\"name\"", ":", "name", ",", "\"changes\"", ":", "{", "}", ",", "\"result\"", ":", "True", ...
https://github.com/saltstack/salt/blob/fae5bc757ad0f1716483ce7ae180b451545c2058/salt/states/lvs_server.py#L144-L203
GOATmessi7/ASFF
4df6f7288b7882a45b8c2dcc3e6e7b499d6cc883
dataset/dataloading.py
python
YoloBatchSampler.__set_input_dim
(self)
This function randomly changes the the input dimension of the dataset.
This function randomly changes the the input dimension of the dataset.
[ "This", "function", "randomly", "changes", "the", "the", "input", "dimension", "of", "the", "dataset", "." ]
def __set_input_dim(self): """ This function randomly changes the the input dimension of the dataset. """ if self.new_input_dim is not None: log.info(f'Resizing network {self.new_input_dim[:2]}') self.input_dim = (self.new_input_dim[0], self.new_input_dim[1]) self.new_input_dim = None
[ "def", "__set_input_dim", "(", "self", ")", ":", "if", "self", ".", "new_input_dim", "is", "not", "None", ":", "log", ".", "info", "(", "f'Resizing network {self.new_input_dim[:2]}'", ")", "self", ".", "input_dim", "=", "(", "self", ".", "new_input_dim", "[", ...
https://github.com/GOATmessi7/ASFF/blob/4df6f7288b7882a45b8c2dcc3e6e7b499d6cc883/dataset/dataloading.py#L209-L214
Billwilliams1952/PiCameraApp
61802b367d620aafb6b4e0bb84ea1ebd0dbd42c0
Source/FinerControl.py
python
FinerControl.uvValueChanged
( self )
[]
def uvValueChanged ( self ): def Clamp ( color ): return 0 if color <= 0 else 255 if color >= 255 else int(color) y = int(255 * float(self.camera.brightness) / 100.0) u = int(self.uScale.get()) v = int(self.vScale.get()) self.camera.color_effects = (u,v) # Y'UV420 to RGB - see Wikipedia - conversion for Android red = Clamp(y + 1.370705 * (v-128)) green = Clamp(y - 0.337633 * (u-128) - 0.698001 * (v-128)) blue = Clamp(y + 1.732446 * (u-128)) self.YUV.config(text='Y: %03d U: %03d V: %03d' % (y,u,v)) self.RGB.config(text='R: %03d G: %03d B: %03d' % (red, green, blue)) self.Color.config(background='#%02x%02x%02x' % (red,green,blue))
[ "def", "uvValueChanged", "(", "self", ")", ":", "def", "Clamp", "(", "color", ")", ":", "return", "0", "if", "color", "<=", "0", "else", "255", "if", "color", ">=", "255", "else", "int", "(", "color", ")", "y", "=", "int", "(", "255", "*", "float...
https://github.com/Billwilliams1952/PiCameraApp/blob/61802b367d620aafb6b4e0bb84ea1ebd0dbd42c0/Source/FinerControl.py#L155-L168
ilastik/ilastik
6acd2c554bc517e9c8ddad3623a7aaa2e6970c28
lazyflow/utility/fileLock.py
python
FileLock.locked
(self)
return self.is_locked
Returns True iff the file is owned by THIS FileLock instance. (Even if this returns false, the file could be owned by another FileLock instance, possibly in a different thread or process).
Returns True iff the file is owned by THIS FileLock instance. (Even if this returns false, the file could be owned by another FileLock instance, possibly in a different thread or process).
[ "Returns", "True", "iff", "the", "file", "is", "owned", "by", "THIS", "FileLock", "instance", ".", "(", "Even", "if", "this", "returns", "false", "the", "file", "could", "be", "owned", "by", "another", "FileLock", "instance", "possibly", "in", "a", "differ...
def locked(self): """ Returns True iff the file is owned by THIS FileLock instance. (Even if this returns false, the file could be owned by another FileLock instance, possibly in a different thread or process). """ return self.is_locked
[ "def", "locked", "(", "self", ")", ":", "return", "self", ".", "is_locked" ]
https://github.com/ilastik/ilastik/blob/6acd2c554bc517e9c8ddad3623a7aaa2e6970c28/lazyflow/utility/fileLock.py#L117-L122
espnet/espnet
ea411f3f627b8f101c211e107d0ff7053344ac80
espnet2/gan_tts/espnet_model.py
python
ESPnetGANTTSModel.__init__
( self, feats_extract: Optional[AbsFeatsExtract], normalize: Optional[AbsNormalize and InversibleInterface], pitch_extract: Optional[AbsFeatsExtract], pitch_normalize: Optional[AbsNormalize and InversibleInterface], energy_extract: Optional[AbsFeatsExtract], energy_normalize: Optional[AbsNormalize and InversibleInterface], tts: AbsGANTTS, )
Initialize ESPnetGANTTSModel module.
Initialize ESPnetGANTTSModel module.
[ "Initialize", "ESPnetGANTTSModel", "module", "." ]
def __init__( self, feats_extract: Optional[AbsFeatsExtract], normalize: Optional[AbsNormalize and InversibleInterface], pitch_extract: Optional[AbsFeatsExtract], pitch_normalize: Optional[AbsNormalize and InversibleInterface], energy_extract: Optional[AbsFeatsExtract], energy_normalize: Optional[AbsNormalize and InversibleInterface], tts: AbsGANTTS, ): """Initialize ESPnetGANTTSModel module.""" assert check_argument_types() super().__init__() self.feats_extract = feats_extract self.normalize = normalize self.pitch_extract = pitch_extract self.pitch_normalize = pitch_normalize self.energy_extract = energy_extract self.energy_normalize = energy_normalize self.tts = tts assert hasattr( tts, "generator" ), "generator module must be registered as tts.generator" assert hasattr( tts, "discriminator" ), "discriminator module must be registered as tts.discriminator"
[ "def", "__init__", "(", "self", ",", "feats_extract", ":", "Optional", "[", "AbsFeatsExtract", "]", ",", "normalize", ":", "Optional", "[", "AbsNormalize", "and", "InversibleInterface", "]", ",", "pitch_extract", ":", "Optional", "[", "AbsFeatsExtract", "]", ","...
https://github.com/espnet/espnet/blob/ea411f3f627b8f101c211e107d0ff7053344ac80/espnet2/gan_tts/espnet_model.py#L34-L59
binaryage/drydrop
2f27e15befd247255d89f9120eeee44851b82c4a
dryapp/drydrop/app/meta/validation.py
python
Validated._ToValue
(validator, value)
Convert any value to simplified collections and basic types. Args: validator: An instance of Validator that corresponds with 'value'. May also be 'str' or 'int' if those were used instead of a full Validator. value: Value to convert to simplified collections. Returns: The value as a dictionary if it is a Validated object. A list of items converted to simplified collections if value is a list or a tuple. Otherwise, just the value.
Convert any value to simplified collections and basic types.
[ "Convert", "any", "value", "to", "simplified", "collections", "and", "basic", "types", "." ]
def _ToValue(validator, value): """Convert any value to simplified collections and basic types. Args: validator: An instance of Validator that corresponds with 'value'. May also be 'str' or 'int' if those were used instead of a full Validator. value: Value to convert to simplified collections. Returns: The value as a dictionary if it is a Validated object. A list of items converted to simplified collections if value is a list or a tuple. Otherwise, just the value. """ if isinstance(value, Validated): return value.ToDict() elif isinstance(value, (list, tuple)): return [Validated._ToValue(validator, item) for item in value] else: if isinstance(validator, Validator): return validator.ToValue(value) return value
[ "def", "_ToValue", "(", "validator", ",", "value", ")", ":", "if", "isinstance", "(", "value", ",", "Validated", ")", ":", "return", "value", ".", "ToDict", "(", ")", "elif", "isinstance", "(", "value", ",", "(", "list", ",", "tuple", ")", ")", ":", ...
https://github.com/binaryage/drydrop/blob/2f27e15befd247255d89f9120eeee44851b82c4a/dryapp/drydrop/app/meta/validation.py#L290-L312
brad-sp/cuckoo-modified
038cfbba66ef76557d255aa89f2d4205f376ca45
lib/cuckoo/common/office/olevba.py
python
VBA_Parser.analyze_macros
(self, show_decoded_strings=False)
return self.analysis_results
runs extract_macros and analyze the source code of all VBA macros found in the file.
runs extract_macros and analyze the source code of all VBA macros found in the file.
[ "runs", "extract_macros", "and", "analyze", "the", "source", "code", "of", "all", "VBA", "macros", "found", "in", "the", "file", "." ]
def analyze_macros(self, show_decoded_strings=False): """ runs extract_macros and analyze the source code of all VBA macros found in the file. """ if self.detect_vba_macros(): # if the analysis was already done, avoid doing it twice: if self.analysis_results is not None: return self.analysis_results # variable to merge source code from all modules: if self.vba_code_all_modules is None: self.vba_code_all_modules = '' for (subfilename, stream_path, vba_filename, vba_code) in self.extract_all_macros(): #TODO: filter code? (each module) self.vba_code_all_modules += vba_code + '\n' # Analyze the whole code at once: scanner = VBA_Scanner(self.vba_code_all_modules) self.analysis_results = scanner.scan(show_decoded_strings) autoexec, suspicious, iocs, hexstrings, base64strings, dridex, vbastrings = scanner.scan_summary() self.nb_autoexec += autoexec self.nb_suspicious += suspicious self.nb_iocs += iocs self.nb_hexstrings += hexstrings self.nb_base64strings += base64strings self.nb_dridexstrings += dridex self.nb_vbastrings += vbastrings return self.analysis_results
[ "def", "analyze_macros", "(", "self", ",", "show_decoded_strings", "=", "False", ")", ":", "if", "self", ".", "detect_vba_macros", "(", ")", ":", "# if the analysis was already done, avoid doing it twice:", "if", "self", ".", "analysis_results", "is", "not", "None", ...
https://github.com/brad-sp/cuckoo-modified/blob/038cfbba66ef76557d255aa89f2d4205f376ca45/lib/cuckoo/common/office/olevba.py#L2006-L2033
kubernetes-client/python
47b9da9de2d02b2b7a34fbe05afb44afd130d73a
kubernetes/client/models/v1_pod_list.py
python
V1PodList.metadata
(self, metadata)
Sets the metadata of this V1PodList. :param metadata: The metadata of this V1PodList. # noqa: E501 :type: V1ListMeta
Sets the metadata of this V1PodList.
[ "Sets", "the", "metadata", "of", "this", "V1PodList", "." ]
def metadata(self, metadata): """Sets the metadata of this V1PodList. :param metadata: The metadata of this V1PodList. # noqa: E501 :type: V1ListMeta """ self._metadata = metadata
[ "def", "metadata", "(", "self", ",", "metadata", ")", ":", "self", ".", "_metadata", "=", "metadata" ]
https://github.com/kubernetes-client/python/blob/47b9da9de2d02b2b7a34fbe05afb44afd130d73a/kubernetes/client/models/v1_pod_list.py#L151-L159
googleads/google-ads-python
2a1d6062221f6aad1992a6bcca0e7e4a93d2db86
google/ads/googleads/v8/services/services/conversion_value_rule_service/client.py
python
ConversionValueRuleServiceClient.parse_common_folder_path
(path: str)
return m.groupdict() if m else {}
Parse a folder path into its component segments.
Parse a folder path into its component segments.
[ "Parse", "a", "folder", "path", "into", "its", "component", "segments", "." ]
def parse_common_folder_path(path: str) -> Dict[str, str]: """Parse a folder path into its component segments.""" m = re.match(r"^folders/(?P<folder>.+?)$", path) return m.groupdict() if m else {}
[ "def", "parse_common_folder_path", "(", "path", ":", "str", ")", "->", "Dict", "[", "str", ",", "str", "]", ":", "m", "=", "re", ".", "match", "(", "r\"^folders/(?P<folder>.+?)$\"", ",", "path", ")", "return", "m", ".", "groupdict", "(", ")", "if", "m"...
https://github.com/googleads/google-ads-python/blob/2a1d6062221f6aad1992a6bcca0e7e4a93d2db86/google/ads/googleads/v8/services/services/conversion_value_rule_service/client.py#L258-L261
microsoft/ptvsd
99c8513921021d2cc7cd82e132b65c644c256768
src/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/breakpoint.py
python
_BreakpointContainer.dont_break_on_error
(self, pid)
Alias to L{break_on_error}C{(pid, ERROR_SUCCESS)}. @type pid: int @param pid: Process ID. @raise NotImplementedError: The functionality is not supported in this system. @raise WindowsError: An error occurred while processing this request.
Alias to L{break_on_error}C{(pid, ERROR_SUCCESS)}.
[ "Alias", "to", "L", "{", "break_on_error", "}", "C", "{", "(", "pid", "ERROR_SUCCESS", ")", "}", "." ]
def dont_break_on_error(self, pid): """ Alias to L{break_on_error}C{(pid, ERROR_SUCCESS)}. @type pid: int @param pid: Process ID. @raise NotImplementedError: The functionality is not supported in this system. @raise WindowsError: An error occurred while processing this request. """ self.break_on_error(pid, 0)
[ "def", "dont_break_on_error", "(", "self", ",", "pid", ")", ":", "self", ".", "break_on_error", "(", "pid", ",", "0", ")" ]
https://github.com/microsoft/ptvsd/blob/99c8513921021d2cc7cd82e132b65c644c256768/src/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/breakpoint.py#L4760-L4773
python-diamond/Diamond
7000e16cfdf4508ed9291fc4b3800592557b2431
src/collectors/unbound/unbound.py
python
UnboundCollector.get_default_config_help
(self)
return config_help
[]
def get_default_config_help(self): config_help = super(UnboundCollector, self).get_default_config_help() config_help.update({ 'bin': 'Path to unbound-control binary', 'histogram': 'Include histogram in collection', }) return config_help
[ "def", "get_default_config_help", "(", "self", ")", ":", "config_help", "=", "super", "(", "UnboundCollector", ",", "self", ")", ".", "get_default_config_help", "(", ")", "config_help", ".", "update", "(", "{", "'bin'", ":", "'Path to unbound-control binary'", ","...
https://github.com/python-diamond/Diamond/blob/7000e16cfdf4508ed9291fc4b3800592557b2431/src/collectors/unbound/unbound.py#L23-L29
numba/numba
bf480b9e0da858a65508c2b17759a72ee6a44c51
docs/source/_ext/ghfiles.py
python
ghfile_role
(name, rawtext, text, lineno, inliner, options={}, content=[])
return my_nodes, []
Emit hyperlink nodes for a given file in repomap.
Emit hyperlink nodes for a given file in repomap.
[ "Emit", "hyperlink", "nodes", "for", "a", "given", "file", "in", "repomap", "." ]
def ghfile_role(name, rawtext, text, lineno, inliner, options={}, content=[]): """ Emit hyperlink nodes for a given file in repomap. """ my_nodes = [] if "{" in text: # myfile.{c,h} - make two nodes # could have used regexes, but this will be fine.. base = text[:text.find(".") + 1] exts = text[text.find("{") + 1:text.find("}")].split(",") for e in exts: node = nodes.reference(rawtext, base + e, refuri=make_ref(base + e), **options) my_nodes.append(node) elif "*" in text: # path/*_files.py - link to directory # Could have used something from os.path, but this will be fine.. ref = path.dirname(text) + path.sep node = nodes.reference(rawtext, text, refuri=make_ref(ref), **options) my_nodes.append(node) else: # everything else is taken verbatim node = nodes.reference(rawtext, text, refuri=make_ref(text), **options) my_nodes.append(node) # insert seperators if needed if len(my_nodes) > 1: my_nodes = intersperse(my_nodes, nodes.Text(" | ")) return my_nodes, []
[ "def", "ghfile_role", "(", "name", ",", "rawtext", ",", "text", ",", "lineno", ",", "inliner", ",", "options", "=", "{", "}", ",", "content", "=", "[", "]", ")", ":", "my_nodes", "=", "[", "]", "if", "\"{\"", "in", "text", ":", "# myfile.{c,h} - make...
https://github.com/numba/numba/blob/bf480b9e0da858a65508c2b17759a72ee6a44c51/docs/source/_ext/ghfiles.py#L42-L67
GitGuardian/ggshield
94a1fa0f6402cd1df2dd3dbc5b932862e85f99e5
ggshield/scan/scannable.py
python
Commit.get_filemode
(line: str)
Get the file mode from the line patch (new, modified or deleted) :raise: Exception if filemode is not detected
Get the file mode from the line patch (new, modified or deleted)
[ "Get", "the", "file", "mode", "from", "the", "line", "patch", "(", "new", "modified", "or", "deleted", ")" ]
def get_filemode(line: str) -> Filemode: """ Get the file mode from the line patch (new, modified or deleted) :raise: Exception if filemode is not detected """ if line.startswith("index"): return Filemode.MODIFY if line.startswith("similarity"): return Filemode.RENAME if line.startswith("new"): return Filemode.NEW if line.startswith("deleted"): return Filemode.DELETE if line.startswith("old"): return Filemode.PERMISSION_CHANGE raise click.ClickException(f"Filemode is not detected:{line}")
[ "def", "get_filemode", "(", "line", ":", "str", ")", "->", "Filemode", ":", "if", "line", ".", "startswith", "(", "\"index\"", ")", ":", "return", "Filemode", ".", "MODIFY", "if", "line", ".", "startswith", "(", "\"similarity\"", ")", ":", "return", "Fil...
https://github.com/GitGuardian/ggshield/blob/94a1fa0f6402cd1df2dd3dbc5b932862e85f99e5/ggshield/scan/scannable.py#L234-L251
RasaHQ/rasa
54823b68c1297849ba7ae841a4246193cd1223a1
rasa/cli/data.py
python
split_nlu_data
(args: argparse.Namespace)
Load data from a file path and split the NLU data into test and train examples. Args: args: Commandline arguments
Load data from a file path and split the NLU data into test and train examples.
[ "Load", "data", "from", "a", "file", "path", "and", "split", "the", "NLU", "data", "into", "test", "and", "train", "examples", "." ]
def split_nlu_data(args: argparse.Namespace) -> None: """Load data from a file path and split the NLU data into test and train examples. Args: args: Commandline arguments """ data_path = rasa.cli.utils.get_validated_path(args.nlu, "nlu", DEFAULT_DATA_PATH) data_path = rasa.shared.data.get_nlu_directory(data_path) nlu_data = rasa.shared.nlu.training_data.loading.load_data(data_path) extension = rasa.shared.nlu.training_data.util.get_file_format_extension(data_path) train, test = nlu_data.train_test_split(args.training_fraction, args.random_seed) train.persist(args.out, filename=f"training_data{extension}") test.persist(args.out, filename=f"test_data{extension}") telemetry.track_data_split(args.training_fraction, "nlu")
[ "def", "split_nlu_data", "(", "args", ":", "argparse", ".", "Namespace", ")", "->", "None", ":", "data_path", "=", "rasa", ".", "cli", ".", "utils", ".", "get_validated_path", "(", "args", ".", "nlu", ",", "\"nlu\"", ",", "DEFAULT_DATA_PATH", ")", "data_pa...
https://github.com/RasaHQ/rasa/blob/54823b68c1297849ba7ae841a4246193cd1223a1/rasa/cli/data.py#L136-L153
TencentCloud/tencentcloud-sdk-python
3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2
tencentcloud/apigateway/v20180808/models.py
python
DeleteApiResponse.__init__
(self)
r""" :param Result: 删除操作是否成功。 注意:此字段可能返回 null,表示取不到有效值。 :type Result: bool :param RequestId: 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 :type RequestId: str
r""" :param Result: 删除操作是否成功。 注意:此字段可能返回 null,表示取不到有效值。 :type Result: bool :param RequestId: 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 :type RequestId: str
[ "r", ":", "param", "Result", ":", "删除操作是否成功。", "注意:此字段可能返回", "null,表示取不到有效值。", ":", "type", "Result", ":", "bool", ":", "param", "RequestId", ":", "唯一请求", "ID,每次请求都会返回。定位问题时需要提供该次请求的", "RequestId。", ":", "type", "RequestId", ":", "str" ]
def __init__(self): r""" :param Result: 删除操作是否成功。 注意:此字段可能返回 null,表示取不到有效值。 :type Result: bool :param RequestId: 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 :type RequestId: str """ self.Result = None self.RequestId = None
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "Result", "=", "None", "self", ".", "RequestId", "=", "None" ]
https://github.com/TencentCloud/tencentcloud-sdk-python/blob/3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2/tencentcloud/apigateway/v20180808/models.py#L2781-L2790
aws-samples/aws-kube-codesuite
ab4e5ce45416b83bffb947ab8d234df5437f4fca
src/kubernetes/client/models/v1beta1_storage_class.py
python
V1beta1StorageClass.provisioner
(self, provisioner)
Sets the provisioner of this V1beta1StorageClass. Provisioner indicates the type of the provisioner. :param provisioner: The provisioner of this V1beta1StorageClass. :type: str
Sets the provisioner of this V1beta1StorageClass. Provisioner indicates the type of the provisioner.
[ "Sets", "the", "provisioner", "of", "this", "V1beta1StorageClass", ".", "Provisioner", "indicates", "the", "type", "of", "the", "provisioner", "." ]
def provisioner(self, provisioner): """ Sets the provisioner of this V1beta1StorageClass. Provisioner indicates the type of the provisioner. :param provisioner: The provisioner of this V1beta1StorageClass. :type: str """ if provisioner is None: raise ValueError("Invalid value for `provisioner`, must not be `None`") self._provisioner = provisioner
[ "def", "provisioner", "(", "self", ",", "provisioner", ")", ":", "if", "provisioner", "is", "None", ":", "raise", "ValueError", "(", "\"Invalid value for `provisioner`, must not be `None`\"", ")", "self", ".", "_provisioner", "=", "provisioner" ]
https://github.com/aws-samples/aws-kube-codesuite/blob/ab4e5ce45416b83bffb947ab8d234df5437f4fca/src/kubernetes/client/models/v1beta1_storage_class.py#L159-L170