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
jython/jython3
def4f8ec47cb7a9c799ea4c745f12badf92c5769
lib-python/3.5.1/tkinter/__init__.py
python
Text.tag_nextrange
(self, tagName, index1, index2=None)
return self.tk.splitlist(self.tk.call( self._w, 'tag', 'nextrange', tagName, index1, index2))
Return a list of start and end index for the first sequence of characters between INDEX1 and INDEX2 which all have tag TAGNAME. The text is searched forward from INDEX1.
Return a list of start and end index for the first sequence of characters between INDEX1 and INDEX2 which all have tag TAGNAME. The text is searched forward from INDEX1.
[ "Return", "a", "list", "of", "start", "and", "end", "index", "for", "the", "first", "sequence", "of", "characters", "between", "INDEX1", "and", "INDEX2", "which", "all", "have", "tag", "TAGNAME", ".", "The", "text", "is", "searched", "forward", "from", "IN...
def tag_nextrange(self, tagName, index1, index2=None): """Return a list of start and end index for the first sequence of characters between INDEX1 and INDEX2 which all have tag TAGNAME. The text is searched forward from INDEX1.""" return self.tk.splitlist(self.tk.call( self._w, 'tag', 'nextrange', tagName, index1, index2))
[ "def", "tag_nextrange", "(", "self", ",", "tagName", ",", "index1", ",", "index2", "=", "None", ")", ":", "return", "self", ".", "tk", ".", "splitlist", "(", "self", ".", "tk", ".", "call", "(", "self", ".", "_w", ",", "'tag'", ",", "'nextrange'", ...
https://github.com/jython/jython3/blob/def4f8ec47cb7a9c799ea4c745f12badf92c5769/lib-python/3.5.1/tkinter/__init__.py#L3228-L3233
conan7882/GoogLeNet-Inception
2a015d1e0f378fb3b5ba8509586b4e2cebb84156
src/models/layers.py
python
batch_norm
(x, train=True, name='bn')
return tf.contrib.layers.batch_norm( x, decay=0.9, updates_collections=None, epsilon=1e-5, scale=False, is_training=train, scope=name)
batch normal Args: x (tf.tensor): a tensor name (str): name scope train (bool): whether training or not Returns: tf.tensor with name 'name'
batch normal Args: x (tf.tensor): a tensor name (str): name scope train (bool): whether training or not Returns: tf.tensor with name 'name'
[ "batch", "normal", "Args", ":", "x", "(", "tf", ".", "tensor", ")", ":", "a", "tensor", "name", "(", "str", ")", ":", "name", "scope", "train", "(", "bool", ")", ":", "whether", "training", "or", "not", "Returns", ":", "tf", ".", "tensor", "with", ...
def batch_norm(x, train=True, name='bn'): """ batch normal Args: x (tf.tensor): a tensor name (str): name scope train (bool): whether training or not Returns: tf.tensor with name 'name' """ return tf.contrib.layers.batch_norm( x, decay=0.9, updates_collections=None, epsilon=1e-5, scale=False, is_training=train, scope=name)
[ "def", "batch_norm", "(", "x", ",", "train", "=", "True", ",", "name", "=", "'bn'", ")", ":", "return", "tf", ".", "contrib", ".", "layers", ".", "batch_norm", "(", "x", ",", "decay", "=", "0.9", ",", "updates_collections", "=", "None", ",", "epsilon...
https://github.com/conan7882/GoogLeNet-Inception/blob/2a015d1e0f378fb3b5ba8509586b4e2cebb84156/src/models/layers.py#L85-L98
proofit404/dependencies
204e0cfadca801d64857f24aa4c74e7939ed9af0
src/_dependencies/trace.py
python
_Trace.__str__
(self)
return self.error + ":\n\n" + "\n".join(map(indentation, self.stack()))
[]
def __str__(self): indentation = _Indentation() return self.error + ":\n\n" + "\n".join(map(indentation, self.stack()))
[ "def", "__str__", "(", "self", ")", ":", "indentation", "=", "_Indentation", "(", ")", "return", "self", ".", "error", "+", "\":\\n\\n\"", "+", "\"\\n\"", ".", "join", "(", "map", "(", "indentation", ",", "self", ".", "stack", "(", ")", ")", ")" ]
https://github.com/proofit404/dependencies/blob/204e0cfadca801d64857f24aa4c74e7939ed9af0/src/_dependencies/trace.py#L8-L10
pjlantz/Hale
5c4c96f18f9a7ed0362e115007813c0b56dc3853
src/modules/httpModule.py
python
HTTPClientFactory.clientConnectionLost
(self, connector, reason)
Called on lost connection to server
Called on lost connection to server
[ "Called", "on", "lost", "connection", "to", "server" ]
def clientConnectionLost(self, connector, reason): """ Called on lost connection to server """ moduleCoordinator.ModuleCoordinator().putError("Connection lost to " + self.config['botnet'], self.module)
[ "def", "clientConnectionLost", "(", "self", ",", "connector", ",", "reason", ")", ":", "moduleCoordinator", ".", "ModuleCoordinator", "(", ")", ".", "putError", "(", "\"Connection lost to \"", "+", "self", ".", "config", "[", "'botnet'", "]", ",", "self", ".",...
https://github.com/pjlantz/Hale/blob/5c4c96f18f9a7ed0362e115007813c0b56dc3853/src/modules/httpModule.py#L200-L205
pantsbuild/pex
473c6ac732ed4bc338b4b20a9ec930d1d722c9b4
pex/vendor/_vendored/setuptools/pkg_resources/__init__.py
python
WorkingSet.run_script
(self, requires, script_name)
Locate distribution for `requires` and run `script_name` script
Locate distribution for `requires` and run `script_name` script
[ "Locate", "distribution", "for", "requires", "and", "run", "script_name", "script" ]
def run_script(self, requires, script_name): """Locate distribution for `requires` and run `script_name` script""" ns = sys._getframe(1).f_globals name = ns['__name__'] ns.clear() ns['__name__'] = name self.require(requires)[0].run_script(script_name, ns)
[ "def", "run_script", "(", "self", ",", "requires", ",", "script_name", ")", ":", "ns", "=", "sys", ".", "_getframe", "(", "1", ")", ".", "f_globals", "name", "=", "ns", "[", "'__name__'", "]", "ns", ".", "clear", "(", ")", "ns", "[", "'__name__'", ...
https://github.com/pantsbuild/pex/blob/473c6ac732ed4bc338b4b20a9ec930d1d722c9b4/pex/vendor/_vendored/setuptools/pkg_resources/__init__.py#L692-L698
francisck/DanderSpritz_docs
86bb7caca5a957147f120b18bb5c31f299914904
Python/Core/Lib/idlelib/ScriptBinding.py
python
ScriptBinding.getfilename
(self)
return filename
Get source filename. If not saved, offer to save (or create) file The debugger requires a source file. Make sure there is one, and that the current version of the source buffer has been saved. If the user declines to save or cancels the Save As dialog, return None. If the user has configured IDLE for Autosave, the file will be silently saved if it already exists and is dirty.
Get source filename. If not saved, offer to save (or create) file The debugger requires a source file. Make sure there is one, and that the current version of the source buffer has been saved. If the user declines to save or cancels the Save As dialog, return None. If the user has configured IDLE for Autosave, the file will be silently saved if it already exists and is dirty.
[ "Get", "source", "filename", ".", "If", "not", "saved", "offer", "to", "save", "(", "or", "create", ")", "file", "The", "debugger", "requires", "a", "source", "file", ".", "Make", "sure", "there", "is", "one", "and", "that", "the", "current", "version", ...
def getfilename(self): """Get source filename. If not saved, offer to save (or create) file The debugger requires a source file. Make sure there is one, and that the current version of the source buffer has been saved. If the user declines to save or cancels the Save As dialog, return None. If the user has configured IDLE for Autosave, the file will be silently saved if it already exists and is dirty. """ filename = self.editwin.io.filename if not self.editwin.get_saved(): autosave = idleConf.GetOption('main', 'General', 'autosave', type='bool') if autosave and filename: self.editwin.io.save(None) else: confirm = self.ask_save_dialog() self.editwin.text.focus_set() if confirm: self.editwin.io.save(None) filename = self.editwin.io.filename else: filename = None return filename
[ "def", "getfilename", "(", "self", ")", ":", "filename", "=", "self", ".", "editwin", ".", "io", ".", "filename", "if", "not", "self", ".", "editwin", ".", "get_saved", "(", ")", ":", "autosave", "=", "idleConf", ".", "GetOption", "(", "'main'", ",", ...
https://github.com/francisck/DanderSpritz_docs/blob/86bb7caca5a957147f120b18bb5c31f299914904/Python/Core/Lib/idlelib/ScriptBinding.py#L157-L181
Chaffelson/nipyapi
d3b186fd701ce308c2812746d98af9120955e810
nipyapi/nifi/models/process_group_dto.py
python
ProcessGroupDTO.__eq__
(self, other)
return self.__dict__ == other.__dict__
Returns true if both objects are equal
Returns true if both objects are equal
[ "Returns", "true", "if", "both", "objects", "are", "equal" ]
def __eq__(self, other): """ Returns true if both objects are equal """ if not isinstance(other, ProcessGroupDTO): return False return self.__dict__ == other.__dict__
[ "def", "__eq__", "(", "self", ",", "other", ")", ":", "if", "not", "isinstance", "(", "other", ",", "ProcessGroupDTO", ")", ":", "return", "False", "return", "self", ".", "__dict__", "==", "other", ".", "__dict__" ]
https://github.com/Chaffelson/nipyapi/blob/d3b186fd701ce308c2812746d98af9120955e810/nipyapi/nifi/models/process_group_dto.py#L992-L999
Alexey-T/CudaText
6a8b9a974c5d5029c6c273bde83198c83b3a5fb9
app/py/sys/requests/utils.py
python
is_ipv4_address
(string_ip)
return True
:rtype: bool
:rtype: bool
[ ":", "rtype", ":", "bool" ]
def is_ipv4_address(string_ip): """ :rtype: bool """ try: socket.inet_aton(string_ip) except socket.error: return False return True
[ "def", "is_ipv4_address", "(", "string_ip", ")", ":", "try", ":", "socket", ".", "inet_aton", "(", "string_ip", ")", "except", "socket", ".", "error", ":", "return", "False", "return", "True" ]
https://github.com/Alexey-T/CudaText/blob/6a8b9a974c5d5029c6c273bde83198c83b3a5fb9/app/py/sys/requests/utils.py#L673-L681
saltstack/salt
fae5bc757ad0f1716483ce7ae180b451545c2058
salt/states/zfs.py
python
filesystem_absent
(name, force=False, recursive=False)
return ret
ensure filesystem is absent on the system name : string name of filesystem force : boolean try harder to destroy the dataset (zfs destroy -f) recursive : boolean also destroy all the child datasets (zfs destroy -r) .. warning:: If a volume with ``name`` exists, this state will succeed without destroying the volume specified by ``name``. This module is dataset type sensitive.
ensure filesystem is absent on the system
[ "ensure", "filesystem", "is", "absent", "on", "the", "system" ]
def filesystem_absent(name, force=False, recursive=False): """ ensure filesystem is absent on the system name : string name of filesystem force : boolean try harder to destroy the dataset (zfs destroy -f) recursive : boolean also destroy all the child datasets (zfs destroy -r) .. warning:: If a volume with ``name`` exists, this state will succeed without destroying the volume specified by ``name``. This module is dataset type sensitive. """ if not __utils__["zfs.is_dataset"](name): ret = { "name": name, "changes": {}, "result": False, "comment": "invalid dataset name: {}".format(name), } else: ret = _absent(name, "filesystem", force, recursive) return ret
[ "def", "filesystem_absent", "(", "name", ",", "force", "=", "False", ",", "recursive", "=", "False", ")", ":", "if", "not", "__utils__", "[", "\"zfs.is_dataset\"", "]", "(", "name", ")", ":", "ret", "=", "{", "\"name\"", ":", "name", ",", "\"changes\"", ...
https://github.com/saltstack/salt/blob/fae5bc757ad0f1716483ce7ae180b451545c2058/salt/states/zfs.py#L126-L152
dabeaz/ply
559a7a1feabb0853be79d4f4dd9e9e9e5ea0d08c
example/ansic/cparse.py
python
p_abstract_declarator_opt_2
(t)
abstract_declarator_opt : abstract_declarator
abstract_declarator_opt : abstract_declarator
[ "abstract_declarator_opt", ":", "abstract_declarator" ]
def p_abstract_declarator_opt_2(t): 'abstract_declarator_opt : abstract_declarator' pass
[ "def", "p_abstract_declarator_opt_2", "(", "t", ")", ":", "pass" ]
https://github.com/dabeaz/ply/blob/559a7a1feabb0853be79d4f4dd9e9e9e5ea0d08c/example/ansic/cparse.py#L480-L482
fabioz/PyDev.Debugger
0f8c02a010fe5690405da1dd30ed72326191ce63
pydevd.py
python
PyDB._exec
(self, is_module, entry_point_fn, module_name, file, globals, locals)
return globals
This function should have frames tracked by unhandled exceptions (the `_exec` name is important).
This function should have frames tracked by unhandled exceptions (the `_exec` name is important).
[ "This", "function", "should", "have", "frames", "tracked", "by", "unhandled", "exceptions", "(", "the", "_exec", "name", "is", "important", ")", "." ]
def _exec(self, is_module, entry_point_fn, module_name, file, globals, locals): ''' This function should have frames tracked by unhandled exceptions (the `_exec` name is important). ''' if not is_module: pydev_imports.execfile(file, globals, locals) # execute the script else: # treat ':' as a separator between module and entry point function # if there is no entry point we run we same as with -m switch. Otherwise we perform # an import and execute the entry point if entry_point_fn: mod = __import__(module_name, level=0, fromlist=[entry_point_fn], globals=globals, locals=locals) func = getattr(mod, entry_point_fn) func() else: # Run with the -m switch import runpy if hasattr(runpy, '_run_module_as_main'): # Newer versions of Python actually use this when the -m switch is used. if sys.version_info[:2] <= (2, 6): runpy._run_module_as_main(module_name, set_argv0=False) else: runpy._run_module_as_main(module_name, alter_argv=False) else: runpy.run_module(module_name) return globals
[ "def", "_exec", "(", "self", ",", "is_module", ",", "entry_point_fn", ",", "module_name", ",", "file", ",", "globals", ",", "locals", ")", ":", "if", "not", "is_module", ":", "pydev_imports", ".", "execfile", "(", "file", ",", "globals", ",", "locals", "...
https://github.com/fabioz/PyDev.Debugger/blob/0f8c02a010fe5690405da1dd30ed72326191ce63/pydevd.py#L2455-L2480
Qirky/FoxDot
76318f9630bede48ff3994146ed644affa27bfa4
FoxDot/lib/Code/main_lib.py
python
FoxDotCode.__call__
(self, code, verbose=True, verbose_error=None)
return response
Takes a string of FoxDot code and executes as Python
Takes a string of FoxDot code and executes as Python
[ "Takes", "a", "string", "of", "FoxDot", "code", "and", "executes", "as", "Python" ]
def __call__(self, code, verbose=True, verbose_error=None): """ Takes a string of FoxDot code and executes as Python """ if self.namespace['_Clock'].waiting_for_sync: time.sleep(0.25) return self.__call__(code, verbose, verbose_error) if verbose_error is None: verbose_error = verbose if not code: return try: if type(code) != CodeType: code = clean(code) response = stdout(code) if verbose is True: print(response) exec(self._compile(code), self.namespace) except Exception as e: response = error_stack() if verbose_error is True: print(response) return response
[ "def", "__call__", "(", "self", ",", "code", ",", "verbose", "=", "True", ",", "verbose_error", "=", "None", ")", ":", "if", "self", ".", "namespace", "[", "'_Clock'", "]", ".", "waiting_for_sync", ":", "time", ".", "sleep", "(", "0.25", ")", "return",...
https://github.com/Qirky/FoxDot/blob/76318f9630bede48ff3994146ed644affa27bfa4/FoxDot/lib/Code/main_lib.py#L127-L165
holzschu/Carnets
44effb10ddfc6aa5c8b0687582a724ba82c6b547
Library/lib/python3.7/site-packages/sympy/calculus/util.py
python
AccumulationBounds.__ge__
(self, other)
return super(AccumulationBounds, self).__ge__(other)
Returns True if range of values attained by `self` AccumulationBounds object is less that the range of values attained by `other`, where other may be any value of type AccumulationBounds object or extended real number value, False if `other` satisfies the same property, else an unevaluated Relational. Examples ======== >>> from sympy import AccumBounds, oo >>> AccumBounds(1, 3) >= AccumBounds(4, oo) False >>> AccumBounds(1, 4) >= AccumBounds(3, 4) AccumBounds(1, 4) >= AccumBounds(3, 4) >>> AccumBounds(1, oo) >= 1 True
Returns True if range of values attained by `self` AccumulationBounds object is less that the range of values attained by `other`, where other may be any value of type AccumulationBounds object or extended real number value, False if `other` satisfies the same property, else an unevaluated Relational.
[ "Returns", "True", "if", "range", "of", "values", "attained", "by", "self", "AccumulationBounds", "object", "is", "less", "that", "the", "range", "of", "values", "attained", "by", "other", "where", "other", "may", "be", "any", "value", "of", "type", "Accumul...
def __ge__(self, other): """ Returns True if range of values attained by `self` AccumulationBounds object is less that the range of values attained by `other`, where other may be any value of type AccumulationBounds object or extended real number value, False if `other` satisfies the same property, else an unevaluated Relational. Examples ======== >>> from sympy import AccumBounds, oo >>> AccumBounds(1, 3) >= AccumBounds(4, oo) False >>> AccumBounds(1, 4) >= AccumBounds(3, 4) AccumBounds(1, 4) >= AccumBounds(3, 4) >>> AccumBounds(1, oo) >= 1 True """ other = _sympify(other) if isinstance(other, AccumBounds): if self.min >= other.max: return True if self.max < other.min: return False elif not other.is_extended_real: raise TypeError( "Invalid comparison of %s %s" % (type(other), other)) elif other.is_comparable: if self.min >= other: return True if self.max < other: return False return super(AccumulationBounds, self).__ge__(other)
[ "def", "__ge__", "(", "self", ",", "other", ")", ":", "other", "=", "_sympify", "(", "other", ")", "if", "isinstance", "(", "other", ",", "AccumBounds", ")", ":", "if", "self", ".", "min", ">=", "other", ".", "max", ":", "return", "True", "if", "se...
https://github.com/holzschu/Carnets/blob/44effb10ddfc6aa5c8b0687582a724ba82c6b547/Library/lib/python3.7/site-packages/sympy/calculus/util.py#L1466-L1501
implus/PytorchInsight
2864528f8b83f52c3df76f7c3804aa468b91e5cf
detection/mmdet/datasets/coco.py
python
CocoDataset._parse_ann_info
(self, ann_info, with_mask=True)
return ann
Parse bbox and mask annotation. Args: ann_info (list[dict]): Annotation info of an image. with_mask (bool): Whether to parse mask annotations. Returns: dict: A dict containing the following keys: bboxes, bboxes_ignore, labels, masks, mask_polys, poly_lens.
Parse bbox and mask annotation.
[ "Parse", "bbox", "and", "mask", "annotation", "." ]
def _parse_ann_info(self, ann_info, with_mask=True): """Parse bbox and mask annotation. Args: ann_info (list[dict]): Annotation info of an image. with_mask (bool): Whether to parse mask annotations. Returns: dict: A dict containing the following keys: bboxes, bboxes_ignore, labels, masks, mask_polys, poly_lens. """ gt_bboxes = [] gt_labels = [] gt_bboxes_ignore = [] # Two formats are provided. # 1. mask: a binary map of the same size of the image. # 2. polys: each mask consists of one or several polys, each poly is a # list of float. if with_mask: gt_masks = [] gt_mask_polys = [] gt_poly_lens = [] for i, ann in enumerate(ann_info): if ann.get('ignore', False): continue x1, y1, w, h = ann['bbox'] if ann['area'] <= 0 or w < 1 or h < 1: continue bbox = [x1, y1, x1 + w - 1, y1 + h - 1] if ann['iscrowd']: gt_bboxes_ignore.append(bbox) else: gt_bboxes.append(bbox) gt_labels.append(self.cat2label[ann['category_id']]) if with_mask: gt_masks.append(self.coco.annToMask(ann)) mask_polys = [ p for p in ann['segmentation'] if len(p) >= 6 ] # valid polygons have >= 3 points (6 coordinates) poly_lens = [len(p) for p in mask_polys] gt_mask_polys.append(mask_polys) gt_poly_lens.extend(poly_lens) if gt_bboxes: gt_bboxes = np.array(gt_bboxes, dtype=np.float32) gt_labels = np.array(gt_labels, dtype=np.int64) else: gt_bboxes = np.zeros((0, 4), dtype=np.float32) gt_labels = np.array([], dtype=np.int64) if gt_bboxes_ignore: gt_bboxes_ignore = np.array(gt_bboxes_ignore, dtype=np.float32) else: gt_bboxes_ignore = np.zeros((0, 4), dtype=np.float32) ann = dict( bboxes=gt_bboxes, labels=gt_labels, bboxes_ignore=gt_bboxes_ignore) if with_mask: ann['masks'] = gt_masks # poly format is not used in the current implementation ann['mask_polys'] = gt_mask_polys ann['poly_lens'] = gt_poly_lens return ann
[ "def", "_parse_ann_info", "(", "self", ",", "ann_info", ",", "with_mask", "=", "True", ")", ":", "gt_bboxes", "=", "[", "]", "gt_labels", "=", "[", "]", "gt_bboxes_ignore", "=", "[", "]", "# Two formats are provided.", "# 1. mask: a binary map of the same size of th...
https://github.com/implus/PytorchInsight/blob/2864528f8b83f52c3df76f7c3804aa468b91e5cf/detection/mmdet/datasets/coco.py#L56-L118
facebookresearch/hgnn
2a22fdb479996c2318f85ad36d2750a383011773
task/BaseTask.py
python
BaseTask.__init__
(self, args, logger, criterion='max')
criterion: min/max
criterion: min/max
[ "criterion", ":", "min", "/", "max" ]
def __init__(self, args, logger, criterion='max'): """ criterion: min/max """ self.args = args self.logger = logger self.early_stop = EarlyStoppingCriterion(self.args.patience, criterion)
[ "def", "__init__", "(", "self", ",", "args", ",", "logger", ",", "criterion", "=", "'max'", ")", ":", "self", ".", "args", "=", "args", "self", ".", "logger", "=", "logger", "self", ".", "early_stop", "=", "EarlyStoppingCriterion", "(", "self", ".", "a...
https://github.com/facebookresearch/hgnn/blob/2a22fdb479996c2318f85ad36d2750a383011773/task/BaseTask.py#L21-L27
CellProfiler/CellProfiler
a90e17e4d258c6f3900238be0f828e0b4bd1b293
cellprofiler/gui/pipelinelistview.py
python
PipelineListCtrl.update_drop_insert_point
(self, index)
Change the visual drop indication index - the first dropped module would end up here.
Change the visual drop indication
[ "Change", "the", "visual", "drop", "indication" ]
def update_drop_insert_point(self, index): """Change the visual drop indication index - the first dropped module would end up here. """ self.drop_insert_point = index self.Refresh(eraseBackground=False)
[ "def", "update_drop_insert_point", "(", "self", ",", "index", ")", ":", "self", ".", "drop_insert_point", "=", "index", "self", ".", "Refresh", "(", "eraseBackground", "=", "False", ")" ]
https://github.com/CellProfiler/CellProfiler/blob/a90e17e4d258c6f3900238be0f828e0b4bd1b293/cellprofiler/gui/pipelinelistview.py#L1570-L1576
thangvubk/Cascade-RPN
c832973b8d849acbe4c0ebf75f353c7f48ec457b
mmdet/core/anchor/anchor_target.py
python
anchor_target
(anchor_list, valid_flag_list, gt_bboxes_list, img_metas, target_means, target_stds, cfg, gt_bboxes_ignore_list=None, gt_labels_list=None, label_channels=1, sampling=True, unmap_outputs=True)
return (labels_list, label_weights_list, bbox_targets_list, bbox_weights_list, rois_list, num_total_pos, num_total_neg)
Compute regression and classification targets for anchors. Args: anchor_list (list[list]): Multi level anchors of each image. valid_flag_list (list[list]): Multi level valid flags of each image. gt_bboxes_list (list[Tensor]): Ground truth bboxes of each image. img_metas (list[dict]): Meta info of each image. target_means (Iterable): Mean value of regression targets. target_stds (Iterable): Std value of regression targets. cfg (dict): RPN train configs. Returns: tuple
Compute regression and classification targets for anchors.
[ "Compute", "regression", "and", "classification", "targets", "for", "anchors", "." ]
def anchor_target(anchor_list, valid_flag_list, gt_bboxes_list, img_metas, target_means, target_stds, cfg, gt_bboxes_ignore_list=None, gt_labels_list=None, label_channels=1, sampling=True, unmap_outputs=True): """Compute regression and classification targets for anchors. Args: anchor_list (list[list]): Multi level anchors of each image. valid_flag_list (list[list]): Multi level valid flags of each image. gt_bboxes_list (list[Tensor]): Ground truth bboxes of each image. img_metas (list[dict]): Meta info of each image. target_means (Iterable): Mean value of regression targets. target_stds (Iterable): Std value of regression targets. cfg (dict): RPN train configs. Returns: tuple """ num_imgs = len(img_metas) assert len(anchor_list) == len(valid_flag_list) == num_imgs # anchor number of multi levels num_level_anchors = [anchors.size(0) for anchors in anchor_list[0]] # concat all level anchors and flags to a single tensor _anchor_list = [] _valid_flag_list = [] for i in range(num_imgs): assert len(anchor_list[i]) == len(valid_flag_list[i]) _anchor_list.append(torch.cat(anchor_list[i])) _valid_flag_list.append(torch.cat(valid_flag_list[i])) # compute targets for each image if gt_bboxes_ignore_list is None: gt_bboxes_ignore_list = [None for _ in range(num_imgs)] if gt_labels_list is None: gt_labels_list = [None for _ in range(num_imgs)] (all_labels, all_label_weights, all_bbox_targets, all_bbox_weights, pos_inds_list, neg_inds_list) = multi_apply( anchor_target_single, _anchor_list, _valid_flag_list, gt_bboxes_list, gt_bboxes_ignore_list, gt_labels_list, img_metas, target_means=target_means, target_stds=target_stds, cfg=cfg, label_channels=label_channels, sampling=sampling, unmap_outputs=unmap_outputs) # no valid anchors if any([labels is None for labels in all_labels]): return None # sampled anchors of all images num_total_pos = sum([max(inds.numel(), 1) for inds in pos_inds_list]) num_total_neg = sum([max(inds.numel(), 1) for inds in neg_inds_list]) # split targets to a list w.r.t. multiple levels labels_list = images_to_levels(all_labels, num_level_anchors) label_weights_list = images_to_levels(all_label_weights, num_level_anchors) bbox_targets_list = images_to_levels(all_bbox_targets, num_level_anchors) bbox_weights_list = images_to_levels(all_bbox_weights, num_level_anchors) rois_list = images_to_levels(_anchor_list, num_level_anchors) return (labels_list, label_weights_list, bbox_targets_list, bbox_weights_list, rois_list, num_total_pos, num_total_neg)
[ "def", "anchor_target", "(", "anchor_list", ",", "valid_flag_list", ",", "gt_bboxes_list", ",", "img_metas", ",", "target_means", ",", "target_stds", ",", "cfg", ",", "gt_bboxes_ignore_list", "=", "None", ",", "gt_labels_list", "=", "None", ",", "label_channels", ...
https://github.com/thangvubk/Cascade-RPN/blob/c832973b8d849acbe4c0ebf75f353c7f48ec457b/mmdet/core/anchor/anchor_target.py#L7-L79
BMW-InnovationLab/BMW-TensorFlow-Training-GUI
4f10d1f00f9ac312ca833e5b28fd0f8952cfee17
training_api/research/object_detection/core/box_list_ops.py
python
to_normalized_coordinates
(boxlist, height, width, check_range=True, scope=None)
Converts absolute box coordinates to normalized coordinates in [0, 1]. Usually one uses the dynamic shape of the image or conv-layer tensor: boxlist = box_list_ops.to_normalized_coordinates(boxlist, tf.shape(images)[1], tf.shape(images)[2]), This function raises an assertion failed error at graph execution time when the maximum coordinate is smaller than 1.01 (which means that coordinates are already normalized). The value 1.01 is to deal with small rounding errors. Args: boxlist: BoxList with coordinates in terms of pixel-locations. height: Maximum value for height of absolute box coordinates. width: Maximum value for width of absolute box coordinates. check_range: If True, checks if the coordinates are normalized or not. scope: name scope. Returns: boxlist with normalized coordinates in [0, 1].
Converts absolute box coordinates to normalized coordinates in [0, 1].
[ "Converts", "absolute", "box", "coordinates", "to", "normalized", "coordinates", "in", "[", "0", "1", "]", "." ]
def to_normalized_coordinates(boxlist, height, width, check_range=True, scope=None): """Converts absolute box coordinates to normalized coordinates in [0, 1]. Usually one uses the dynamic shape of the image or conv-layer tensor: boxlist = box_list_ops.to_normalized_coordinates(boxlist, tf.shape(images)[1], tf.shape(images)[2]), This function raises an assertion failed error at graph execution time when the maximum coordinate is smaller than 1.01 (which means that coordinates are already normalized). The value 1.01 is to deal with small rounding errors. Args: boxlist: BoxList with coordinates in terms of pixel-locations. height: Maximum value for height of absolute box coordinates. width: Maximum value for width of absolute box coordinates. check_range: If True, checks if the coordinates are normalized or not. scope: name scope. Returns: boxlist with normalized coordinates in [0, 1]. """ with tf.name_scope(scope, 'ToNormalizedCoordinates'): height = tf.cast(height, tf.float32) width = tf.cast(width, tf.float32) if check_range: max_val = tf.reduce_max(boxlist.get()) max_assert = tf.Assert(tf.greater(max_val, 1.01), ['max value is lower than 1.01: ', max_val]) with tf.control_dependencies([max_assert]): width = tf.identity(width) return scale(boxlist, 1 / height, 1 / width)
[ "def", "to_normalized_coordinates", "(", "boxlist", ",", "height", ",", "width", ",", "check_range", "=", "True", ",", "scope", "=", "None", ")", ":", "with", "tf", ".", "name_scope", "(", "scope", ",", "'ToNormalizedCoordinates'", ")", ":", "height", "=", ...
https://github.com/BMW-InnovationLab/BMW-TensorFlow-Training-GUI/blob/4f10d1f00f9ac312ca833e5b28fd0f8952cfee17/training_api/research/object_detection/core/box_list_ops.py#L740-L774
aws/aws-sam-cli
2aa7bf01b2e0b0864ef63b1898a8b30577443acc
samcli/commands/local/cli_common/invoke_context.py
python
InvokeContext._get_debug_context
( debug_ports: Optional[Tuple[int]], debug_args: Optional[str], debugger_path: Optional[str], container_env_vars: Optional[Dict[str, str]], debug_function: Optional[str] = None, )
return DebugContext( debug_ports=debug_ports, debug_args=debug_args, debugger_path=debugger_path, debug_function=debug_function, container_env_vars=container_env_vars, )
Creates a DebugContext if the InvokeContext is in a debugging mode Parameters ---------- debug_ports tuple(int) Ports to bind the debugger to debug_args str Additional arguments passed to the debugger debugger_path str Path to the directory of the debugger to mount on Docker container_env_vars dict Dictionary containing debugging based environmental variables. debug_function str The Lambda function logicalId that will have the debugging options enabled in case of warm containers option is enabled Returns ------- samcli.commands.local.lib.debug_context.DebugContext Object representing the DebugContext Raises ------ samcli.commands.local.cli_common.user_exceptions.DebugContext When the debugger_path is not valid
Creates a DebugContext if the InvokeContext is in a debugging mode
[ "Creates", "a", "DebugContext", "if", "the", "InvokeContext", "is", "in", "a", "debugging", "mode" ]
def _get_debug_context( debug_ports: Optional[Tuple[int]], debug_args: Optional[str], debugger_path: Optional[str], container_env_vars: Optional[Dict[str, str]], debug_function: Optional[str] = None, ) -> DebugContext: """ Creates a DebugContext if the InvokeContext is in a debugging mode Parameters ---------- debug_ports tuple(int) Ports to bind the debugger to debug_args str Additional arguments passed to the debugger debugger_path str Path to the directory of the debugger to mount on Docker container_env_vars dict Dictionary containing debugging based environmental variables. debug_function str The Lambda function logicalId that will have the debugging options enabled in case of warm containers option is enabled Returns ------- samcli.commands.local.lib.debug_context.DebugContext Object representing the DebugContext Raises ------ samcli.commands.local.cli_common.user_exceptions.DebugContext When the debugger_path is not valid """ if debug_ports and debugger_path: try: debugger = Path(debugger_path).resolve(strict=True) except OSError as error: if error.errno == errno.ENOENT: raise DebugContextException("'{}' could not be found.".format(debugger_path)) from error raise error if not debugger.is_dir(): raise DebugContextException("'{}' should be a directory with the debugger in it.".format(debugger_path)) debugger_path = str(debugger) return DebugContext( debug_ports=debug_ports, debug_args=debug_args, debugger_path=debugger_path, debug_function=debug_function, container_env_vars=container_env_vars, )
[ "def", "_get_debug_context", "(", "debug_ports", ":", "Optional", "[", "Tuple", "[", "int", "]", "]", ",", "debug_args", ":", "Optional", "[", "str", "]", ",", "debugger_path", ":", "Optional", "[", "str", "]", ",", "container_env_vars", ":", "Optional", "...
https://github.com/aws/aws-sam-cli/blob/2aa7bf01b2e0b0864ef63b1898a8b30577443acc/samcli/commands/local/cli_common/invoke_context.py#L470-L523
qutip/qutip
52d01da181a21b810c3407812c670f35fdc647e8
qutip/qobj.py
python
shape
(inpt)
Returns the shape attribute of a quantum object. Parameters ---------- inpt : :class:`qutip.Qobj` Input quantum object. Returns ------- shape : list A ``list`` of the quantum objects shape. Notes ----- This function is for legacy compatibility only. Using the `Qobj.shape` attribute is recommended.
Returns the shape attribute of a quantum object.
[ "Returns", "the", "shape", "attribute", "of", "a", "quantum", "object", "." ]
def shape(inpt): """Returns the shape attribute of a quantum object. Parameters ---------- inpt : :class:`qutip.Qobj` Input quantum object. Returns ------- shape : list A ``list`` of the quantum objects shape. Notes ----- This function is for legacy compatibility only. Using the `Qobj.shape` attribute is recommended. """ if isinstance(inpt, Qobj): return Qobj.shape else: return np.shape(inpt)
[ "def", "shape", "(", "inpt", ")", ":", "if", "isinstance", "(", "inpt", ",", "Qobj", ")", ":", "return", "Qobj", ".", "shape", "else", ":", "return", "np", ".", "shape", "(", "inpt", ")" ]
https://github.com/qutip/qutip/blob/52d01da181a21b810c3407812c670f35fdc647e8/qutip/qobj.py#L2262-L2284
Srinivas11789/PcapXray
dc2bd65e94b2031b9203ed68e549110f46f9cd9c
Source/Module/legacy/plotLanNetwork.py
python
plotLan.apply_custom_style
(self, graph, color)
return graph
[]
def apply_custom_style(self, graph, color): style = {'edges': { 'style': 'dashed', 'color': color, 'arrowhead': 'open', 'fontname': 'Courier', 'fontsize': '12', 'fontcolor': color, }} graph.edge_attr.update( ('edges' in style and style['edges']) or {} ) return graph
[ "def", "apply_custom_style", "(", "self", ",", "graph", ",", "color", ")", ":", "style", "=", "{", "'edges'", ":", "{", "'style'", ":", "'dashed'", ",", "'color'", ":", "color", ",", "'arrowhead'", ":", "'open'", ",", "'fontname'", ":", "'Courier'", ",",...
https://github.com/Srinivas11789/PcapXray/blob/dc2bd65e94b2031b9203ed68e549110f46f9cd9c/Source/Module/legacy/plotLanNetwork.py#L61-L73
twilio/twilio-python
6e1e811ea57a1edfadd5161ace87397c563f6915
twilio/rest/pricing/v1/phone_number/country.py
python
CountryContext.__init__
(self, version, iso_country)
Initialize the CountryContext :param Version version: Version that contains the resource :param iso_country: The ISO country code :returns: twilio.rest.pricing.v1.phone_number.country.CountryContext :rtype: twilio.rest.pricing.v1.phone_number.country.CountryContext
Initialize the CountryContext
[ "Initialize", "the", "CountryContext" ]
def __init__(self, version, iso_country): """ Initialize the CountryContext :param Version version: Version that contains the resource :param iso_country: The ISO country code :returns: twilio.rest.pricing.v1.phone_number.country.CountryContext :rtype: twilio.rest.pricing.v1.phone_number.country.CountryContext """ super(CountryContext, self).__init__(version) # Path Solution self._solution = {'iso_country': iso_country, } self._uri = '/PhoneNumbers/Countries/{iso_country}'.format(**self._solution)
[ "def", "__init__", "(", "self", ",", "version", ",", "iso_country", ")", ":", "super", "(", "CountryContext", ",", "self", ")", ".", "__init__", "(", "version", ")", "# Path Solution", "self", ".", "_solution", "=", "{", "'iso_country'", ":", "iso_country", ...
https://github.com/twilio/twilio-python/blob/6e1e811ea57a1edfadd5161ace87397c563f6915/twilio/rest/pricing/v1/phone_number/country.py#L182-L196
openshift/openshift-tools
1188778e728a6e4781acf728123e5b356380fe6f
openshift/installer/vendored/openshift-ansible-3.11.28-1/roles/lib_openshift/library/oc_label.py
python
Yedit.load
(self, content_type='yaml')
return self.yaml_dict
return yaml file
return yaml file
[ "return", "yaml", "file" ]
def load(self, content_type='yaml'): ''' return yaml file ''' contents = self.read() if not contents and not self.content: return None if self.content: if isinstance(self.content, dict): self.yaml_dict = self.content return self.yaml_dict elif isinstance(self.content, str): contents = self.content # check if it is yaml try: if content_type == 'yaml' and contents: # Try to set format attributes if supported try: self.yaml_dict.fa.set_block_style() except AttributeError: pass # Try to use RoundTripLoader if supported. try: self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) # Try to set format attributes if supported try: self.yaml_dict.fa.set_block_style() except AttributeError: pass elif content_type == 'json' and contents: self.yaml_dict = json.loads(contents) except yaml.YAMLError as err: # Error loading yaml or json raise YeditException('Problem with loading yaml file. {}'.format(err)) return self.yaml_dict
[ "def", "load", "(", "self", ",", "content_type", "=", "'yaml'", ")", ":", "contents", "=", "self", ".", "read", "(", ")", "if", "not", "contents", "and", "not", "self", ".", "content", ":", "return", "None", "if", "self", ".", "content", ":", "if", ...
https://github.com/openshift/openshift-tools/blob/1188778e728a6e4781acf728123e5b356380fe6f/openshift/installer/vendored/openshift-ansible-3.11.28-1/roles/lib_openshift/library/oc_label.py#L418-L459
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/lib/python2.7/site-packages/werkzeug/_internal.py
python
_get_environ
(obj)
return env
[]
def _get_environ(obj): env = getattr(obj, 'environ', obj) assert isinstance(env, dict), \ '%r is not a WSGI environment (has to be a dict)' % type(obj).__name__ return env
[ "def", "_get_environ", "(", "obj", ")", ":", "env", "=", "getattr", "(", "obj", ",", "'environ'", ",", "obj", ")", "assert", "isinstance", "(", "env", ",", "dict", ")", ",", "'%r is not a WSGI environment (has to be a dict)'", "%", "type", "(", "obj", ")", ...
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/lib/python2.7/site-packages/werkzeug/_internal.py#L69-L73
conan-io/conan
28ec09f6cbf1d7e27ec27393fd7bbc74891e74a8
conans/client/build/compiler_flags.py
python
adjust_path
(path, settings, win_bash=False, subsystem=None)
return '"%s"' % path if ' ' in path else path
adjusts path to be safely passed to the compiler command line for Windows bash, ensures path is in format according to the subsystem for path with spaces, places double quotes around it converts slashes to backslashes, or vice versa
adjusts path to be safely passed to the compiler command line for Windows bash, ensures path is in format according to the subsystem for path with spaces, places double quotes around it converts slashes to backslashes, or vice versa
[ "adjusts", "path", "to", "be", "safely", "passed", "to", "the", "compiler", "command", "line", "for", "Windows", "bash", "ensures", "path", "is", "in", "format", "according", "to", "the", "subsystem", "for", "path", "with", "spaces", "places", "double", "quo...
def adjust_path(path, settings, win_bash=False, subsystem=None): """ adjusts path to be safely passed to the compiler command line for Windows bash, ensures path is in format according to the subsystem for path with spaces, places double quotes around it converts slashes to backslashes, or vice versa """ compiler = _base_compiler(settings) if str(compiler) == 'Visual Studio': path = path.replace('/', '\\') else: path = path.replace('\\', '/') if win_bash: path = unix_path(path, subsystem) return '"%s"' % path if ' ' in path else path
[ "def", "adjust_path", "(", "path", ",", "settings", ",", "win_bash", "=", "False", ",", "subsystem", "=", "None", ")", ":", "compiler", "=", "_base_compiler", "(", "settings", ")", "if", "str", "(", "compiler", ")", "==", "'Visual Studio'", ":", "path", ...
https://github.com/conan-io/conan/blob/28ec09f6cbf1d7e27ec27393fd7bbc74891e74a8/conans/client/build/compiler_flags.py#L190-L204
heronsystems/adeptRL
d8554d134c1dfee6659baafd886684351c1dd982
examples/custom_network_stub.py
python
MyCustomNetwork.new_internals
(self, device)
Define any initial hidden states here, move them to device if necessary. InternalKey=str :return: Dict[InternalKey, torch.Tensor (ND)]
Define any initial hidden states here, move them to device if necessary. InternalKey=str :return: Dict[InternalKey, torch.Tensor (ND)]
[ "Define", "any", "initial", "hidden", "states", "here", "move", "them", "to", "device", "if", "necessary", ".", "InternalKey", "=", "str", ":", "return", ":", "Dict", "[", "InternalKey", "torch", ".", "Tensor", "(", "ND", ")", "]" ]
def new_internals(self, device): """ Define any initial hidden states here, move them to device if necessary. InternalKey=str :return: Dict[InternalKey, torch.Tensor (ND)] """ pass
[ "def", "new_internals", "(", "self", ",", "device", ")", ":", "pass" ]
https://github.com/heronsystems/adeptRL/blob/d8554d134c1dfee6659baafd886684351c1dd982/examples/custom_network_stub.py#L32-L38
wuub/SublimeREPL
d17e8649c0d0008a364158d671ac0c7d33d0c896
repls/sublimepython_repl.py
python
SublimePythonRepl.__init__
(self, encoding)
[]
def __init__(self, encoding): super(SublimePythonRepl, self).__init__(encoding, "python", "\n", False) self._console = InterceptingConsole(encoding) self._thread = threading.Thread(target=self._console.run) self._thread.start()
[ "def", "__init__", "(", "self", ",", "encoding", ")", ":", "super", "(", "SublimePythonRepl", ",", "self", ")", ".", "__init__", "(", "encoding", ",", "\"python\"", ",", "\"\\n\"", ",", "False", ")", "self", ".", "_console", "=", "InterceptingConsole", "("...
https://github.com/wuub/SublimeREPL/blob/d17e8649c0d0008a364158d671ac0c7d33d0c896/repls/sublimepython_repl.py#L79-L83
urwid/urwid
e2423b5069f51d318ea1ac0f355a0efe5448f7eb
urwid/decoration.py
python
BoxAdapter.mouse_event
(self, size, event, button, col, row, focus)
return self._original_widget.mouse_event((maxcol, self.height), event, button, col, row, focus)
[]
def mouse_event(self, size, event, button, col, row, focus): (maxcol,) = size if not hasattr(self._original_widget,'mouse_event'): return False return self._original_widget.mouse_event((maxcol, self.height), event, button, col, row, focus)
[ "def", "mouse_event", "(", "self", ",", "size", ",", "event", ",", "button", ",", "col", ",", "row", ",", "focus", ")", ":", "(", "maxcol", ",", ")", "=", "size", "if", "not", "hasattr", "(", "self", ".", "_original_widget", ",", "'mouse_event'", ")"...
https://github.com/urwid/urwid/blob/e2423b5069f51d318ea1ac0f355a0efe5448f7eb/urwid/decoration.py#L395-L400
benoitc/couchdbkit
6be148640c00b54ee87a2f2d502e9d67fa5b45a8
couchdbkit/consumer/ceventlet.py
python
ChangeConsumer._run
(self)
[]
def _run(self): while True: try: resp = self.db.res.get("_changes", **self.params) return self.consume(resp) except (SystemExit, KeyboardInterrupt): eventlet.sleep(5) break except: traceback.print_exc() eventlet.sleep(5) break self.stop_event.send(True)
[ "def", "_run", "(", "self", ")", ":", "while", "True", ":", "try", ":", "resp", "=", "self", ".", "db", ".", "res", ".", "get", "(", "\"_changes\"", ",", "*", "*", "self", ".", "params", ")", "return", "self", ".", "consume", "(", "resp", ")", ...
https://github.com/benoitc/couchdbkit/blob/6be148640c00b54ee87a2f2d502e9d67fa5b45a8/couchdbkit/consumer/ceventlet.py#L30-L42
securityclippy/elasticintel
aa08d3e9f5ab1c000128e95161139ce97ff0e334
whois_lambda/requests/sessions.py
python
Session.put
(self, url, data=None, **kwargs)
return self.request('PUT', url, data=data, **kwargs)
Sends a PUT request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes.
Sends a PUT request. Returns :class:`Response` object.
[ "Sends", "a", "PUT", "request", ".", "Returns", ":", "class", ":", "Response", "object", "." ]
def put(self, url, data=None, **kwargs): """Sends a PUT request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. """ return self.request('PUT', url, data=data, **kwargs)
[ "def", "put", "(", "self", ",", "url", ",", "data", "=", "None", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "request", "(", "'PUT'", ",", "url", ",", "data", "=", "data", ",", "*", "*", "kwargs", ")" ]
https://github.com/securityclippy/elasticintel/blob/aa08d3e9f5ab1c000128e95161139ce97ff0e334/whois_lambda/requests/sessions.py#L513-L521
accel-brain/accel-brain-code
86f489dc9be001a3bae6d053f48d6b57c0bedb95
Accel-Brain-Base/accelbrainbase/controllablemodel/_mxnet/gan_controller.py
python
GANController.collect_params
(self, select=None)
return params_dict
Overrided `collect_params` in `mxnet.gluon.HybridBlok`.
Overrided `collect_params` in `mxnet.gluon.HybridBlok`.
[ "Overrided", "collect_params", "in", "mxnet", ".", "gluon", ".", "HybridBlok", "." ]
def collect_params(self, select=None): ''' Overrided `collect_params` in `mxnet.gluon.HybridBlok`. ''' params_dict = self.__generative_model.collect_params(select) params_dict.update(self.__discriminative_model.collect_params(select)) return params_dict
[ "def", "collect_params", "(", "self", ",", "select", "=", "None", ")", ":", "params_dict", "=", "self", ".", "__generative_model", ".", "collect_params", "(", "select", ")", "params_dict", ".", "update", "(", "self", ".", "__discriminative_model", ".", "collec...
https://github.com/accel-brain/accel-brain-code/blob/86f489dc9be001a3bae6d053f48d6b57c0bedb95/Accel-Brain-Base/accelbrainbase/controllablemodel/_mxnet/gan_controller.py#L164-L170
IronLanguages/main
a949455434b1fda8c783289e897e78a9a0caabb5
External.LCA_RESTRICTED/Languages/CPython/27/Lib/decimal.py
python
Decimal._round_down
(self, prec)
Also known as round-towards-0, truncate.
Also known as round-towards-0, truncate.
[ "Also", "known", "as", "round", "-", "towards", "-", "0", "truncate", "." ]
def _round_down(self, prec): """Also known as round-towards-0, truncate.""" if _all_zeros(self._int, prec): return 0 else: return -1
[ "def", "_round_down", "(", "self", ",", "prec", ")", ":", "if", "_all_zeros", "(", "self", ".", "_int", ",", "prec", ")", ":", "return", "0", "else", ":", "return", "-", "1" ]
https://github.com/IronLanguages/main/blob/a949455434b1fda8c783289e897e78a9a0caabb5/External.LCA_RESTRICTED/Languages/CPython/27/Lib/decimal.py#L1736-L1741
wikimedia/pywikibot
81a01ffaec7271bf5b4b170f85a80388420a4e78
pywikibot/site/_basesite.py
python
BaseSite.category_on_one_line
(self)
return self.code in self.family.category_on_one_line
Return True if this site wants all category links on one line.
Return True if this site wants all category links on one line.
[ "Return", "True", "if", "this", "site", "wants", "all", "category", "links", "on", "one", "line", "." ]
def category_on_one_line(self): # TODO: is this even needed? No family in the framework uses it. """Return True if this site wants all category links on one line.""" return self.code in self.family.category_on_one_line
[ "def", "category_on_one_line", "(", "self", ")", ":", "# TODO: is this even needed? No family in the framework uses it.", "return", "self", ".", "code", "in", "self", ".", "family", ".", "category_on_one_line" ]
https://github.com/wikimedia/pywikibot/blob/81a01ffaec7271bf5b4b170f85a80388420a4e78/pywikibot/site/_basesite.py#L410-L413
yt-project/yt
dc7b24f9b266703db4c843e329c6c8644d47b824
yt/visualization/volume_rendering/image_handling.py
python
import_rgba
(name, h5=True)
return np.array([r, g, b, a]).swapaxes(0, 2).swapaxes(0, 1)
This function will read back in an HDF5 file, as saved by export_rgba, and return the frames to the user. *name* is the name of the file to be read in.
This function will read back in an HDF5 file, as saved by export_rgba, and return the frames to the user. *name* is the name of the file to be read in.
[ "This", "function", "will", "read", "back", "in", "an", "HDF5", "file", "as", "saved", "by", "export_rgba", "and", "return", "the", "frames", "to", "the", "user", ".", "*", "name", "*", "is", "the", "name", "of", "the", "file", "to", "be", "read", "i...
def import_rgba(name, h5=True): """ This function will read back in an HDF5 file, as saved by export_rgba, and return the frames to the user. *name* is the name of the file to be read in. """ if h5: f = h5py.File(name, mode="r") r = f["R"].value g = f["G"].value b = f["B"].value a = f["A"].value f.close() else: mylog.error("No support for fits import.") return np.array([r, g, b, a]).swapaxes(0, 2).swapaxes(0, 1)
[ "def", "import_rgba", "(", "name", ",", "h5", "=", "True", ")", ":", "if", "h5", ":", "f", "=", "h5py", ".", "File", "(", "name", ",", "mode", "=", "\"r\"", ")", "r", "=", "f", "[", "\"R\"", "]", ".", "value", "g", "=", "f", "[", "\"G\"", "...
https://github.com/yt-project/yt/blob/dc7b24f9b266703db4c843e329c6c8644d47b824/yt/visualization/volume_rendering/image_handling.py#L39-L54
fonttools/fonttools
892322aaff6a89bea5927379ec06bc0da3dfb7df
Lib/fontTools/subset/__init__.py
python
neuter_lookups
(self, lookup_indices)
Sets lookups not in lookup_indices to None.
Sets lookups not in lookup_indices to None.
[ "Sets", "lookups", "not", "in", "lookup_indices", "to", "None", "." ]
def neuter_lookups(self, lookup_indices): """Sets lookups not in lookup_indices to None.""" if self.table.LookupList: self.table.LookupList.neuter_lookups(lookup_indices)
[ "def", "neuter_lookups", "(", "self", ",", "lookup_indices", ")", ":", "if", "self", ".", "table", ".", "LookupList", ":", "self", ".", "table", ".", "LookupList", ".", "neuter_lookups", "(", "lookup_indices", ")" ]
https://github.com/fonttools/fonttools/blob/892322aaff6a89bea5927379ec06bc0da3dfb7df/Lib/fontTools/subset/__init__.py#L1599-L1602
vibora-io/vibora
4cda888f89aec6bfb2541ee53548ae1bf50fbf1b
vibora/client/session.py
python
HTTPEngine.get_pool
(self, protocol: str, host: str, port: int)
return self.pools[key]
:param protocol: :param host: :param port: :return:
[]
def get_pool(self, protocol: str, host: str, port: int) -> ConnectionPool: """ :param protocol: :param host: :param port: :return: """ key = (protocol, host, port) if port in (0, None): if protocol == 'https': port = 443 else: port = 80 try: return self.pools[key] except KeyError: self.pools[key] = ConnectionPool(loop=self.loop, host=host, port=port, protocol=protocol, keep_alive=self.session.keep_alive) return self.pools[key]
[ "def", "get_pool", "(", "self", ",", "protocol", ":", "str", ",", "host", ":", "str", ",", "port", ":", "int", ")", "->", "ConnectionPool", ":", "key", "=", "(", "protocol", ",", "host", ",", "port", ")", "if", "port", "in", "(", "0", ",", "None"...
https://github.com/vibora-io/vibora/blob/4cda888f89aec6bfb2541ee53548ae1bf50fbf1b/vibora/client/session.py#L31-L50
joe42/CloudFusion
c4b94124e74a81e0634578c7754d62160081f7a1
cloudfusion/store/chunk_caching_store.py
python
ChunkMultiprocessingCachingStore.__init__
(self, store, cache_expiration_time=60, cache_size_in_mb=2000, cache_id=None, max_archive_size_in_mb = 4, cache_dir='/tmp/cloudfusion')
:param store: the store whose access should be cached :param max_archive_size_in_mb: the maximum size of an archive :param cache_expiration_time: the time in seconds until any cache entry is expired :param cache_size_in_mb: Approximate (soft) limit of the cache in MB. :param hard_cache_size_limit_in_mb: Hard limit of the cache in MB, exceeding this limit should slow down write operations. :param cache_id: Serves as identifier for a persistent cache instance. :param cache_dir: Cache directory on local hard drive disk, default value is */tmp/cloudfusion*.
:param store: the store whose access should be cached :param max_archive_size_in_mb: the maximum size of an archive :param cache_expiration_time: the time in seconds until any cache entry is expired :param cache_size_in_mb: Approximate (soft) limit of the cache in MB. :param hard_cache_size_limit_in_mb: Hard limit of the cache in MB, exceeding this limit should slow down write operations. :param cache_id: Serves as identifier for a persistent cache instance. :param cache_dir: Cache directory on local hard drive disk, default value is */tmp/cloudfusion*.
[ ":", "param", "store", ":", "the", "store", "whose", "access", "should", "be", "cached", ":", "param", "max_archive_size_in_mb", ":", "the", "maximum", "size", "of", "an", "archive", ":", "param", "cache_expiration_time", ":", "the", "time", "in", "seconds", ...
def __init__(self, store, cache_expiration_time=60, cache_size_in_mb=2000, cache_id=None, max_archive_size_in_mb = 4, cache_dir='/tmp/cloudfusion'): """ :param store: the store whose access should be cached :param max_archive_size_in_mb: the maximum size of an archive :param cache_expiration_time: the time in seconds until any cache entry is expired :param cache_size_in_mb: Approximate (soft) limit of the cache in MB. :param hard_cache_size_limit_in_mb: Hard limit of the cache in MB, exceeding this limit should slow down write operations. :param cache_id: Serves as identifier for a persistent cache instance. :param cache_dir: Cache directory on local hard drive disk, default value is */tmp/cloudfusion*.""" #prevent simultaneous access to store (synchronous use of __deepcopy__ by _store SyncThread and a different method): self.store = SynchronizeProxy(store, private_methods_to_synchronize=['__deepcopy__']) self.max_archive_size_in_mb = max_archive_size_in_mb if cache_id == None: cache_id = str(random.random()) self.logger = logging.getLogger(self.get_logging_handler()) self.logger.debug("creating ChunkTransparentMultiprocessingCachingStore object") if cache_expiration_time < 240: self.logger.warning("Be aware of the synchronization issue https://github.com/joe42/CloudFusion/issues/16 \ or to avoid the issue set cache_expiration_time to more than 240 seconds.") self.cache_expiration_time = cache_expiration_time self.time_of_last_flush = time.time() self.cache_dir = cache_dir[:-1] if cache_dir[-1:] == '/' else cache_dir # remove slash at the end temp_dir = self.cache_dir+"/cachingstore_"+cache_id cache = PersistentLRUCache(temp_dir, cache_expiration_time, cache_size_in_mb) cache.set_resize_intervall(10) self.entries = SynchronizeProxy( cache ) #[shares_resource: write self.entries] self.sync_thread = ChunkStoreSyncThread(self.entries, self.store, temp_dir, self.logger) self.sync_thread.start()
[ "def", "__init__", "(", "self", ",", "store", ",", "cache_expiration_time", "=", "60", ",", "cache_size_in_mb", "=", "2000", ",", "cache_id", "=", "None", ",", "max_archive_size_in_mb", "=", "4", ",", "cache_dir", "=", "'/tmp/cloudfusion'", ")", ":", "#prevent...
https://github.com/joe42/CloudFusion/blob/c4b94124e74a81e0634578c7754d62160081f7a1/cloudfusion/store/chunk_caching_store.py#L18-L45
elfi-dev/elfi
07ac0ed5e81d5d5fb42de63db3cf9ccc9135b88c
elfi/methods/inference/parameter_inference.py
python
ParameterInference.prepare_new_batch
(self, batch_index)
Prepare values for a new batch. ELFI calls this method before submitting a new batch with an increasing index `batch_index`. This is an optional method to override. Use this if you have a need do do preparations, e.g. in Bayesian optimization algorithm, the next acquisition points would be acquired here. If you need provide values for certain nodes, you can do so by constructing a batch dictionary and returning it. See e.g. BayesianOptimization for an example. Parameters ---------- batch_index : int next batch_index to be submitted Returns ------- batch : dict or None Keys should match to node names in the model. These values will override any default values or operations in those nodes.
Prepare values for a new batch.
[ "Prepare", "values", "for", "a", "new", "batch", "." ]
def prepare_new_batch(self, batch_index): """Prepare values for a new batch. ELFI calls this method before submitting a new batch with an increasing index `batch_index`. This is an optional method to override. Use this if you have a need do do preparations, e.g. in Bayesian optimization algorithm, the next acquisition points would be acquired here. If you need provide values for certain nodes, you can do so by constructing a batch dictionary and returning it. See e.g. BayesianOptimization for an example. Parameters ---------- batch_index : int next batch_index to be submitted Returns ------- batch : dict or None Keys should match to node names in the model. These values will override any default values or operations in those nodes. """ pass
[ "def", "prepare_new_batch", "(", "self", ",", "batch_index", ")", ":", "pass" ]
https://github.com/elfi-dev/elfi/blob/07ac0ed5e81d5d5fb42de63db3cf9ccc9135b88c/elfi/methods/inference/parameter_inference.py#L175-L198
kapicorp/kapitan
ad925478023f8b7a0ccc99762b77babf1064a8df
kapitan/resources.py
python
read_file
(search_paths, name)
return content of file in name
return content of file in name
[ "return", "content", "of", "file", "in", "name" ]
def read_file(search_paths, name): """return content of file in name""" for path in search_paths: full_path = os.path.join(path, name) logger.debug("read_file trying file %s", full_path) if os.path.exists(full_path): logger.debug("read_file found file at %s", full_path) with io.open(full_path, newline="") as f: return f.read() raise IOError("Could not find file {}".format(name))
[ "def", "read_file", "(", "search_paths", ",", "name", ")", ":", "for", "path", "in", "search_paths", ":", "full_path", "=", "os", ".", "path", ".", "join", "(", "path", ",", "name", ")", "logger", ".", "debug", "(", "\"read_file trying file %s\"", ",", "...
https://github.com/kapicorp/kapitan/blob/ad925478023f8b7a0ccc99762b77babf1064a8df/kapitan/resources.py#L159-L169
theatlantic/django-nested-admin
2554f51f6d05489dd2d81b24c60b59781fda4e8a
nested_admin/formsets.py
python
NestedInlineFormSetMixin.process_forms_pre_save
(self, forms)
return forms
Sort by the sortable_field_name of the formset, if it has been set, and re-index the form positions (to account for gaps caused by blank or deleted forms) Allows customizable sorting and modification of self.forms before they're iterated through in save(). Returns list of forms.
Sort by the sortable_field_name of the formset, if it has been set, and re-index the form positions (to account for gaps caused by blank or deleted forms)
[ "Sort", "by", "the", "sortable_field_name", "of", "the", "formset", "if", "it", "has", "been", "set", "and", "re", "-", "index", "the", "form", "positions", "(", "to", "account", "for", "gaps", "caused", "by", "blank", "or", "deleted", "forms", ")" ]
def process_forms_pre_save(self, forms): """ Sort by the sortable_field_name of the formset, if it has been set, and re-index the form positions (to account for gaps caused by blank or deleted forms) Allows customizable sorting and modification of self.forms before they're iterated through in save(). Returns list of forms. """ sort_field = getattr(self, 'sortable_field_name', None) def get_position(form): return getattr(form, 'cleaned_data', {sort_field: 0}).get(sort_field, 0) if sort_field is not None: forms.sort(key=get_position) i = 0 for form in forms: if self._should_delete_form(form): # Skip deleted forms continue original_position = form.data.get(form.add_prefix(sort_field)) if ("%s" % i) != original_position: # If this is an unchanged extra form, continue because # this form will be skipped when saving if not form.changed_data and not form._is_initial: continue # Set the sort field on the instance and in the form data setattr(form.instance, sort_field, i) with mutable_querydict(form.data): form.data[form.add_prefix(sort_field)] = six.text_type(i) # Force recalculation of changed_data form.__dict__.pop('changed_data', None) i += 1 return forms
[ "def", "process_forms_pre_save", "(", "self", ",", "forms", ")", ":", "sort_field", "=", "getattr", "(", "self", ",", "'sortable_field_name'", ",", "None", ")", "def", "get_position", "(", "form", ")", ":", "return", "getattr", "(", "form", ",", "'cleaned_da...
https://github.com/theatlantic/django-nested-admin/blob/2554f51f6d05489dd2d81b24c60b59781fda4e8a/nested_admin/formsets.py#L173-L216
santhoshkolloju/Abstractive-Summarization-With-Transfer-Learning
97ff2ae3ba9f2d478e174444c4e0f5349f28c319
texar_repo/texar/modules/memory/memory_network.py
python
MemNetBase.get_default_embed_fn
(self, memory_size, embed_fn_hparams)
return _embed_fn, memory_dim
Creates a default embedding function. Can be used for A, C, or B operation. For B operation (i.e., query_embed_fn), :attr:`memory_size` must be 1. The function is a combination of both memory embedding and temporal embedding, with the combination method specified by "combine_mode" in the `embed_fn_hparams`. .. role:: python(code) :language: python Args: embed_fn_hparams (dict or HParams): Hyperparameter of the embedding function. See :func:`~texar.modules.default_memnet_embed_fn` for details. Returns: A tuple `(embed_fn, memory_dim)`, where - **`memory_dim`** is the dimension of memory entry embedding, \ inferred from :attr:`embed_fn_hparams`. - If `combine_mode` == 'add', `memory_dim` is the \ embedder dimension. - If `combine_mode` == 'concat', `memory_dim` is the sum \ of the memory embedder dimension and the temporal embedder \ dimension. - **`embed_fn`** is an embedding function that takes in memory \ and returns memory embedding. \ Specifically, the function has signature \ :python:`memory_embedding= embed_fn(memory=None, soft_memory=None)`\ where one of `memory` and `soft_memory` is provided (but not both). Args: memory: An `int` Tensor of shape `[batch_size, memory_size]` containing memory indexes used for embedding lookup. soft_memory: A Tensor of shape `[batch_size, memory_size, raw_memory_dim]` containing soft weights used to mix the embedding vectors. Returns: A Tensor of shape `[batch_size, memory_size, memory_dim]` containing the memory entry embeddings.
Creates a default embedding function. Can be used for A, C, or B operation.
[ "Creates", "a", "default", "embedding", "function", ".", "Can", "be", "used", "for", "A", "C", "or", "B", "operation", "." ]
def get_default_embed_fn(self, memory_size, embed_fn_hparams): """Creates a default embedding function. Can be used for A, C, or B operation. For B operation (i.e., query_embed_fn), :attr:`memory_size` must be 1. The function is a combination of both memory embedding and temporal embedding, with the combination method specified by "combine_mode" in the `embed_fn_hparams`. .. role:: python(code) :language: python Args: embed_fn_hparams (dict or HParams): Hyperparameter of the embedding function. See :func:`~texar.modules.default_memnet_embed_fn` for details. Returns: A tuple `(embed_fn, memory_dim)`, where - **`memory_dim`** is the dimension of memory entry embedding, \ inferred from :attr:`embed_fn_hparams`. - If `combine_mode` == 'add', `memory_dim` is the \ embedder dimension. - If `combine_mode` == 'concat', `memory_dim` is the sum \ of the memory embedder dimension and the temporal embedder \ dimension. - **`embed_fn`** is an embedding function that takes in memory \ and returns memory embedding. \ Specifically, the function has signature \ :python:`memory_embedding= embed_fn(memory=None, soft_memory=None)`\ where one of `memory` and `soft_memory` is provided (but not both). Args: memory: An `int` Tensor of shape `[batch_size, memory_size]` containing memory indexes used for embedding lookup. soft_memory: A Tensor of shape `[batch_size, memory_size, raw_memory_dim]` containing soft weights used to mix the embedding vectors. Returns: A Tensor of shape `[batch_size, memory_size, memory_dim]` containing the memory entry embeddings. """ # memory embedder embedder = WordEmbedder( vocab_size=self._raw_memory_dim, hparams=embed_fn_hparams["embedding"] ) # temporal embedder temporal_embedder = PositionEmbedder( position_size=memory_size, hparams=embed_fn_hparams["temporal_embedding"] ) combine = embed_fn_hparams['combine_mode'] if combine == 'add': if embedder.dim != temporal_embedder.dim: raise ValueError('`embedding` and `temporal_embedding` must ' 'have the same dimension for "add" ' 'combination.') memory_dim = embedder.dim elif combine == 'concat': memory_dim = embedder.dim + temporal_embedder.dim def _embed_fn(memory, soft_memory, mode=None): if memory is None and soft_memory is None: raise ValueError( "Either `memory` or `soft_memory` is required.") if memory is not None and soft_memory is not None: raise ValueError( "Must not specify `memory` and `soft_memory` at the " "same time.") embedded_memory = embedder( ids=memory, soft_ids=soft_memory, mode=mode) temporal_embedded = temporal_embedder( sequence_length=tf.constant([memory_size]), mode=mode) temporal_embedded = tf.tile( temporal_embedded, [tf.shape(embedded_memory)[0], 1, 1]) if combine == 'add': return tf.add(embedded_memory, temporal_embedded) elif combine == 'concat': return tf.concat([embedded_memory, temporal_embedded], axis=-1) else: raise ValueError('Unknown combine method: {}'.format(combine)) return _embed_fn, memory_dim
[ "def", "get_default_embed_fn", "(", "self", ",", "memory_size", ",", "embed_fn_hparams", ")", ":", "# memory embedder", "embedder", "=", "WordEmbedder", "(", "vocab_size", "=", "self", ".", "_raw_memory_dim", ",", "hparams", "=", "embed_fn_hparams", "[", "\"embeddin...
https://github.com/santhoshkolloju/Abstractive-Summarization-With-Transfer-Learning/blob/97ff2ae3ba9f2d478e174444c4e0f5349f28c319/texar_repo/texar/modules/memory/memory_network.py#L207-L300
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_hxb2/lib/python3.5/site-packages/django/contrib/gis/gdal/raster/band.py
python
GDALBand.width
(self)
return capi.get_band_xsize(self._ptr)
Width (X axis) in pixels of the band.
Width (X axis) in pixels of the band.
[ "Width", "(", "X", "axis", ")", "in", "pixels", "of", "the", "band", "." ]
def width(self): """ Width (X axis) in pixels of the band. """ return capi.get_band_xsize(self._ptr)
[ "def", "width", "(", "self", ")", ":", "return", "capi", ".", "get_band_xsize", "(", "self", ".", "_ptr", ")" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_hxb2/lib/python3.5/site-packages/django/contrib/gis/gdal/raster/band.py#L38-L42
danielegrattarola/keras-gat
c870d198a6137201d354fddbe4f7250903ab483c
keras_gat/utils.py
python
sample_mask
(idx, l)
return np.array(mask, dtype=np.bool)
Create mask.
Create mask.
[ "Create", "mask", "." ]
def sample_mask(idx, l): """Create mask.""" mask = np.zeros(l) mask[idx] = 1 return np.array(mask, dtype=np.bool)
[ "def", "sample_mask", "(", "idx", ",", "l", ")", ":", "mask", "=", "np", ".", "zeros", "(", "l", ")", "mask", "[", "idx", "]", "=", "1", "return", "np", ".", "array", "(", "mask", ",", "dtype", "=", "np", ".", "bool", ")" ]
https://github.com/danielegrattarola/keras-gat/blob/c870d198a6137201d354fddbe4f7250903ab483c/keras_gat/utils.py#L20-L24
jtriley/StarCluster
bc7c950e73f193eac9aab986b6764939cfdad978
starcluster/utils.py
python
is_valid_device
(dev)
Checks that dev matches the following regular expression: /dev/sd[a-z]$
Checks that dev matches the following regular expression: /dev/sd[a-z]$
[ "Checks", "that", "dev", "matches", "the", "following", "regular", "expression", ":", "/", "dev", "/", "sd", "[", "a", "-", "z", "]", "$" ]
def is_valid_device(dev): """ Checks that dev matches the following regular expression: /dev/sd[a-z]$ """ regex = re.compile('/dev/sd[a-z]$') try: return regex.match(dev) is not None except TypeError: return False
[ "def", "is_valid_device", "(", "dev", ")", ":", "regex", "=", "re", ".", "compile", "(", "'/dev/sd[a-z]$'", ")", "try", ":", "return", "regex", ".", "match", "(", "dev", ")", "is", "not", "None", "except", "TypeError", ":", "return", "False" ]
https://github.com/jtriley/StarCluster/blob/bc7c950e73f193eac9aab986b6764939cfdad978/starcluster/utils.py#L127-L136
wishinlife/SyncY
71597eb523cc411e5f41558570d3814d52cfe92e
syncy.py
python
SYCurl.__init__
(self)
[]
def __init__(self): self.__response = '' self.__op = None self.__fd = None self.__startpos = 0 self.__endpos = None self.__buffer = ''
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "__response", "=", "''", "self", ".", "__op", "=", "None", "self", ".", "__fd", "=", "None", "self", ".", "__startpos", "=", "0", "self", ".", "__endpos", "=", "None", "self", ".", "__buffer", ...
https://github.com/wishinlife/SyncY/blob/71597eb523cc411e5f41558570d3814d52cfe92e/syncy.py#L1595-L1601
matplotlib/matplotlib
8d7a2b9d2a38f01ee0d6802dd4f9e98aec812322
lib/matplotlib/colorbar.py
python
Colorbar._long_axis
(self)
return self.ax.xaxis
Return the long axis
Return the long axis
[ "Return", "the", "long", "axis" ]
def _long_axis(self): """Return the long axis""" if self.orientation == 'vertical': return self.ax.yaxis return self.ax.xaxis
[ "def", "_long_axis", "(", "self", ")", ":", "if", "self", ".", "orientation", "==", "'vertical'", ":", "return", "self", ".", "ax", ".", "yaxis", "return", "self", ".", "ax", ".", "xaxis" ]
https://github.com/matplotlib/matplotlib/blob/8d7a2b9d2a38f01ee0d6802dd4f9e98aec812322/lib/matplotlib/colorbar.py#L1300-L1304
bmc/munkres
23d11c83057c7d93fa7f4ebfa191f9b746374792
munkres.py
python
Munkres.__step1
(self)
return 2
For each row of the matrix, find the smallest element and subtract it from every element in its row. Go to Step 2.
For each row of the matrix, find the smallest element and subtract it from every element in its row. Go to Step 2.
[ "For", "each", "row", "of", "the", "matrix", "find", "the", "smallest", "element", "and", "subtract", "it", "from", "every", "element", "in", "its", "row", ".", "Go", "to", "Step", "2", "." ]
def __step1(self) -> int: """ For each row of the matrix, find the smallest element and subtract it from every element in its row. Go to Step 2. """ C = self.C n = self.n for i in range(n): vals = [x for x in self.C[i] if x is not DISALLOWED] if len(vals) == 0: # All values in this row are DISALLOWED. This matrix is # unsolvable. raise UnsolvableMatrix( "Row {0} is entirely DISALLOWED.".format(i) ) minval = min(vals) # Find the minimum value for this row and subtract that minimum # from every element in the row. for j in range(n): if self.C[i][j] is not DISALLOWED: self.C[i][j] -= minval return 2
[ "def", "__step1", "(", "self", ")", "->", "int", ":", "C", "=", "self", ".", "C", "n", "=", "self", ".", "n", "for", "i", "in", "range", "(", "n", ")", ":", "vals", "=", "[", "x", "for", "x", "in", "self", ".", "C", "[", "i", "]", "if", ...
https://github.com/bmc/munkres/blob/23d11c83057c7d93fa7f4ebfa191f9b746374792/munkres.py#L184-L205
cuthbertLab/music21
bd30d4663e52955ed922c10fdf541419d8c67671
music21/alpha/analysis/aligner.py
python
StreamAligner.populateDistanceMatrix
(self)
Sets up the distance matrix for back-tracing >>> note1 = note.Note('C#4') >>> note2 = note.Note('C4') Test 1: similar streams >>> targetA = stream.Stream() >>> sourceA = stream.Stream() >>> targetA.append([note1, note2]) >>> sourceA.append([note1, note2]) >>> saA = alpha.analysis.aligner.StreamAligner(targetA, sourceA) >>> saA.makeHashedStreams() >>> saA.setupDistanceMatrix() >>> saA.populateDistanceMatrix() >>> saA.distanceMatrix array([[0, 2, 4], [2, 0, 2], [4, 2, 0]]) Second Test >>> targetB = stream.Stream() >>> sourceB = stream.Stream() >>> targetB.append([note1, note2]) >>> sourceB.append(note1) >>> saB = alpha.analysis.aligner.StreamAligner(targetB, sourceB) >>> saB.makeHashedStreams() >>> saB.setupDistanceMatrix() >>> saB.populateDistanceMatrix() >>> saB.distanceMatrix array([[0, 2], [2, 0], [4, 2]]) Third Test >>> note3 = note.Note('D5') >>> note3.quarterLength = 3 >>> note4 = note.Note('E3') >>> targetC = stream.Stream() >>> sourceC = stream.Stream() >>> targetC.append([note1, note2, note4]) >>> sourceC.append([note3, note1, note4]) >>> saC = alpha.analysis.aligner.StreamAligner(targetC, sourceC) >>> saC.makeHashedStreams() >>> saC.setupDistanceMatrix() >>> saC.populateDistanceMatrix() >>> saC.distanceMatrix array([[0, 2, 4, 6], [2, 2, 2, 4], [4, 4, 3, 3], [6, 6, 5, 3]])
Sets up the distance matrix for back-tracing
[ "Sets", "up", "the", "distance", "matrix", "for", "back", "-", "tracing" ]
def populateDistanceMatrix(self): ''' Sets up the distance matrix for back-tracing >>> note1 = note.Note('C#4') >>> note2 = note.Note('C4') Test 1: similar streams >>> targetA = stream.Stream() >>> sourceA = stream.Stream() >>> targetA.append([note1, note2]) >>> sourceA.append([note1, note2]) >>> saA = alpha.analysis.aligner.StreamAligner(targetA, sourceA) >>> saA.makeHashedStreams() >>> saA.setupDistanceMatrix() >>> saA.populateDistanceMatrix() >>> saA.distanceMatrix array([[0, 2, 4], [2, 0, 2], [4, 2, 0]]) Second Test >>> targetB = stream.Stream() >>> sourceB = stream.Stream() >>> targetB.append([note1, note2]) >>> sourceB.append(note1) >>> saB = alpha.analysis.aligner.StreamAligner(targetB, sourceB) >>> saB.makeHashedStreams() >>> saB.setupDistanceMatrix() >>> saB.populateDistanceMatrix() >>> saB.distanceMatrix array([[0, 2], [2, 0], [4, 2]]) Third Test >>> note3 = note.Note('D5') >>> note3.quarterLength = 3 >>> note4 = note.Note('E3') >>> targetC = stream.Stream() >>> sourceC = stream.Stream() >>> targetC.append([note1, note2, note4]) >>> sourceC.append([note3, note1, note4]) >>> saC = alpha.analysis.aligner.StreamAligner(targetC, sourceC) >>> saC.makeHashedStreams() >>> saC.setupDistanceMatrix() >>> saC.populateDistanceMatrix() >>> saC.distanceMatrix array([[0, 2, 4, 6], [2, 2, 2, 4], [4, 4, 3, 3], [6, 6, 5, 3]]) ''' # calculate insert and delete costs based on the first tuple in the Source S insertCost = self.insertCost(self.hashedSourceStream[0]) deleteCost = self.deleteCost(self.hashedSourceStream[0]) # setup all the entries in the first column, the target stream for i in range(1, self.n + 1): self.distanceMatrix[i][0] = self.distanceMatrix[i - 1][0] + insertCost # setup all the entries in the first row, the source stream for j in range(1, self.m + 1): self.distanceMatrix[0][j] = self.distanceMatrix[0][j - 1] + deleteCost # fill in rest of matrix for i in range(1, self.n + 1): for j in range(1, self.m + 1): substCost = self.substitutionCost(self.hashedTargetStream[i - 1], self.hashedSourceStream[j - 1]) previousValues = [self.distanceMatrix[i - 1][j] + insertCost, self.distanceMatrix[i][j - 1] + deleteCost, self.distanceMatrix[i - 1][j - 1] + substCost] self.distanceMatrix[i][j] = min(previousValues)
[ "def", "populateDistanceMatrix", "(", "self", ")", ":", "# calculate insert and delete costs based on the first tuple in the Source S", "insertCost", "=", "self", ".", "insertCost", "(", "self", ".", "hashedSourceStream", "[", "0", "]", ")", "deleteCost", "=", "self", "...
https://github.com/cuthbertLab/music21/blob/bd30d4663e52955ed922c10fdf541419d8c67671/music21/alpha/analysis/aligner.py#L250-L330
ACloudGuru/AdvancedCloudFormation
6831cfbff1888951c9b2ede6cb87eeb71cfd8bf5
206-LambdaCustomEnhancements/autosubnet/netaddr/ip/__init__.py
python
IPNetwork.ipv4
(self)
return ip
:return: A numerically equivalent version 4 `IPNetwork` object. \ Raises an `AddrConversionError` if IPv6 address cannot be \ converted to IPv4.
:return: A numerically equivalent version 4 `IPNetwork` object. \ Raises an `AddrConversionError` if IPv6 address cannot be \ converted to IPv4.
[ ":", "return", ":", "A", "numerically", "equivalent", "version", "4", "IPNetwork", "object", ".", "\\", "Raises", "an", "AddrConversionError", "if", "IPv6", "address", "cannot", "be", "\\", "converted", "to", "IPv4", "." ]
def ipv4(self): """ :return: A numerically equivalent version 4 `IPNetwork` object. \ Raises an `AddrConversionError` if IPv6 address cannot be \ converted to IPv4. """ ip = None klass = self.__class__ if self._module.version == 4: ip = klass('%s/%d' % (self.ip, self.prefixlen)) elif self._module.version == 6: if 0 <= self._value <= _ipv4.max_int: addr = _ipv4.int_to_str(self._value) ip = klass('%s/%d' % (addr, self.prefixlen - 96)) elif _ipv4.max_int <= self._value <= 0xffffffffffff: addr = _ipv4.int_to_str(self._value - 0xffff00000000) ip = klass('%s/%d' % (addr, self.prefixlen - 96)) else: raise AddrConversionError('IPv6 address %s unsuitable for ' \ 'conversion to IPv4!' % self) return ip
[ "def", "ipv4", "(", "self", ")", ":", "ip", "=", "None", "klass", "=", "self", ".", "__class__", "if", "self", ".", "_module", ".", "version", "==", "4", ":", "ip", "=", "klass", "(", "'%s/%d'", "%", "(", "self", ".", "ip", ",", "self", ".", "p...
https://github.com/ACloudGuru/AdvancedCloudFormation/blob/6831cfbff1888951c9b2ede6cb87eeb71cfd8bf5/206-LambdaCustomEnhancements/autosubnet/netaddr/ip/__init__.py#L1135-L1156
TencentCloud/tencentcloud-sdk-python
3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2
tencentcloud/vpc/v20170312/models.py
python
DirectConnectGatewayCcnRoute.__init__
(self)
r""" :param RouteId: 路由ID。 :type RouteId: str :param DestinationCidrBlock: IDC网段。 :type DestinationCidrBlock: str :param ASPath: `BGP`的`AS-Path`属性。 :type ASPath: list of str :param Description: 备注 :type Description: str :param UpdateTime: 最后更新时间 :type UpdateTime: str
r""" :param RouteId: 路由ID。 :type RouteId: str :param DestinationCidrBlock: IDC网段。 :type DestinationCidrBlock: str :param ASPath: `BGP`的`AS-Path`属性。 :type ASPath: list of str :param Description: 备注 :type Description: str :param UpdateTime: 最后更新时间 :type UpdateTime: str
[ "r", ":", "param", "RouteId", ":", "路由ID。", ":", "type", "RouteId", ":", "str", ":", "param", "DestinationCidrBlock", ":", "IDC网段。", ":", "type", "DestinationCidrBlock", ":", "str", ":", "param", "ASPath", ":", "BGP", "的", "AS", "-", "Path", "属性。", ":", ...
def __init__(self): r""" :param RouteId: 路由ID。 :type RouteId: str :param DestinationCidrBlock: IDC网段。 :type DestinationCidrBlock: str :param ASPath: `BGP`的`AS-Path`属性。 :type ASPath: list of str :param Description: 备注 :type Description: str :param UpdateTime: 最后更新时间 :type UpdateTime: str """ self.RouteId = None self.DestinationCidrBlock = None self.ASPath = None self.Description = None self.UpdateTime = None
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "RouteId", "=", "None", "self", ".", "DestinationCidrBlock", "=", "None", "self", ".", "ASPath", "=", "None", "self", ".", "Description", "=", "None", "self", ".", "UpdateTime", "=", "None" ]
https://github.com/TencentCloud/tencentcloud-sdk-python/blob/3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2/tencentcloud/vpc/v20170312/models.py#L11528-L11545
deepinsight/insightface
c0b25f998a649f662c7136eb389abcacd7900e9d
detection/scrfd/mmdet/apis/inference.py
python
LoadImage.__call__
(self, results)
return results
Call function to load images into results. Args: results (dict): A result dict contains the file name of the image to be read. Returns: dict: ``results`` will be returned containing loaded image.
Call function to load images into results.
[ "Call", "function", "to", "load", "images", "into", "results", "." ]
def __call__(self, results): """Call function to load images into results. Args: results (dict): A result dict contains the file name of the image to be read. Returns: dict: ``results`` will be returned containing loaded image. """ if isinstance(results['img'], str): results['filename'] = results['img'] results['ori_filename'] = results['img'] else: results['filename'] = None results['ori_filename'] = None img = mmcv.imread(results['img']) results['img'] = img results['img_fields'] = ['img'] results['img_shape'] = img.shape results['ori_shape'] = img.shape return results
[ "def", "__call__", "(", "self", ",", "results", ")", ":", "if", "isinstance", "(", "results", "[", "'img'", "]", ",", "str", ")", ":", "results", "[", "'filename'", "]", "=", "results", "[", "'img'", "]", "results", "[", "'ori_filename'", "]", "=", "...
https://github.com/deepinsight/insightface/blob/c0b25f998a649f662c7136eb389abcacd7900e9d/detection/scrfd/mmdet/apis/inference.py#L58-L79
stopstalk/stopstalk-deployment
10c3ab44c4ece33ae515f6888c15033db2004bb1
aws_lambda/spoj_aws_lambda_function/lambda_code/pip/_vendor/requests/api.py
python
put
(url, data=None, **kwargs)
return request('put', url, data=data, **kwargs)
r"""Sends a PUT request. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json data to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response <Response>` object :rtype: requests.Response
r"""Sends a PUT request.
[ "r", "Sends", "a", "PUT", "request", "." ]
def put(url, data=None, **kwargs): r"""Sends a PUT request. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json data to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response <Response>` object :rtype: requests.Response """ return request('put', url, data=data, **kwargs)
[ "def", "put", "(", "url", ",", "data", "=", "None", ",", "*", "*", "kwargs", ")", ":", "return", "request", "(", "'put'", ",", "url", ",", "data", "=", "data", ",", "*", "*", "kwargs", ")" ]
https://github.com/stopstalk/stopstalk-deployment/blob/10c3ab44c4ece33ae515f6888c15033db2004bb1/aws_lambda/spoj_aws_lambda_function/lambda_code/pip/_vendor/requests/api.py#L115-L126
sagemath/sage
f9b2db94f675ff16963ccdefba4f1a3393b3fe0d
src/sage/topology/simplicial_complex_morphism.py
python
SimplicialComplexMorphism.associated_chain_complex_morphism
(self,base_ring=ZZ,augmented=False,cochain=False)
return ChainComplexMorphism(matrices, self.codomain().chain_complex(base_ring=base_ring,augmented=augmented,cochain=cochain), self.domain().chain_complex(base_ring=base_ring,augmented=augmented,cochain=cochain))
Return the associated chain complex morphism of ``self``. EXAMPLES:: sage: S = simplicial_complexes.Sphere(1) sage: T = simplicial_complexes.Sphere(2) sage: H = Hom(S,T) sage: f = {0:0,1:1,2:2} sage: x = H(f) sage: x Simplicial complex morphism: From: Minimal triangulation of the 1-sphere To: Minimal triangulation of the 2-sphere Defn: 0 |--> 0 1 |--> 1 2 |--> 2 sage: a = x.associated_chain_complex_morphism() sage: a Chain complex morphism: From: Chain complex with at most 2 nonzero terms over Integer Ring To: Chain complex with at most 3 nonzero terms over Integer Ring sage: a._matrix_dictionary {0: [1 0 0] [0 1 0] [0 0 1] [0 0 0], 1: [1 0 0] [0 1 0] [0 0 0] [0 0 1] [0 0 0] [0 0 0], 2: []} sage: x.associated_chain_complex_morphism(augmented=True) Chain complex morphism: From: Chain complex with at most 3 nonzero terms over Integer Ring To: Chain complex with at most 4 nonzero terms over Integer Ring sage: x.associated_chain_complex_morphism(cochain=True) Chain complex morphism: From: Chain complex with at most 3 nonzero terms over Integer Ring To: Chain complex with at most 2 nonzero terms over Integer Ring sage: x.associated_chain_complex_morphism(augmented=True,cochain=True) Chain complex morphism: From: Chain complex with at most 4 nonzero terms over Integer Ring To: Chain complex with at most 3 nonzero terms over Integer Ring sage: x.associated_chain_complex_morphism(base_ring=GF(11)) Chain complex morphism: From: Chain complex with at most 2 nonzero terms over Finite Field of size 11 To: Chain complex with at most 3 nonzero terms over Finite Field of size 11 Some simplicial maps which reverse the orientation of a few simplices:: sage: g = {0:1, 1:2, 2:0} sage: H(g).associated_chain_complex_morphism()._matrix_dictionary {0: [0 0 1] [1 0 0] [0 1 0] [0 0 0], 1: [ 0 -1 0] [ 0 0 -1] [ 0 0 0] [ 1 0 0] [ 0 0 0] [ 0 0 0], 2: []} sage: X = SimplicialComplex([[0, 1]], is_mutable=False) sage: Hom(X,X)({0:1, 1:0}).associated_chain_complex_morphism()._matrix_dictionary {0: [0 1] [1 0], 1: [-1]}
Return the associated chain complex morphism of ``self``.
[ "Return", "the", "associated", "chain", "complex", "morphism", "of", "self", "." ]
def associated_chain_complex_morphism(self,base_ring=ZZ,augmented=False,cochain=False): """ Return the associated chain complex morphism of ``self``. EXAMPLES:: sage: S = simplicial_complexes.Sphere(1) sage: T = simplicial_complexes.Sphere(2) sage: H = Hom(S,T) sage: f = {0:0,1:1,2:2} sage: x = H(f) sage: x Simplicial complex morphism: From: Minimal triangulation of the 1-sphere To: Minimal triangulation of the 2-sphere Defn: 0 |--> 0 1 |--> 1 2 |--> 2 sage: a = x.associated_chain_complex_morphism() sage: a Chain complex morphism: From: Chain complex with at most 2 nonzero terms over Integer Ring To: Chain complex with at most 3 nonzero terms over Integer Ring sage: a._matrix_dictionary {0: [1 0 0] [0 1 0] [0 0 1] [0 0 0], 1: [1 0 0] [0 1 0] [0 0 0] [0 0 1] [0 0 0] [0 0 0], 2: []} sage: x.associated_chain_complex_morphism(augmented=True) Chain complex morphism: From: Chain complex with at most 3 nonzero terms over Integer Ring To: Chain complex with at most 4 nonzero terms over Integer Ring sage: x.associated_chain_complex_morphism(cochain=True) Chain complex morphism: From: Chain complex with at most 3 nonzero terms over Integer Ring To: Chain complex with at most 2 nonzero terms over Integer Ring sage: x.associated_chain_complex_morphism(augmented=True,cochain=True) Chain complex morphism: From: Chain complex with at most 4 nonzero terms over Integer Ring To: Chain complex with at most 3 nonzero terms over Integer Ring sage: x.associated_chain_complex_morphism(base_ring=GF(11)) Chain complex morphism: From: Chain complex with at most 2 nonzero terms over Finite Field of size 11 To: Chain complex with at most 3 nonzero terms over Finite Field of size 11 Some simplicial maps which reverse the orientation of a few simplices:: sage: g = {0:1, 1:2, 2:0} sage: H(g).associated_chain_complex_morphism()._matrix_dictionary {0: [0 0 1] [1 0 0] [0 1 0] [0 0 0], 1: [ 0 -1 0] [ 0 0 -1] [ 0 0 0] [ 1 0 0] [ 0 0 0] [ 0 0 0], 2: []} sage: X = SimplicialComplex([[0, 1]], is_mutable=False) sage: Hom(X,X)({0:1, 1:0}).associated_chain_complex_morphism()._matrix_dictionary {0: [0 1] [1 0], 1: [-1]} """ max_dim = max(self.domain().dimension(),self.codomain().dimension()) min_dim = min(self.domain().dimension(),self.codomain().dimension()) matrices = {} if augmented is True: m = matrix(base_ring,1,1,1) if not cochain: matrices[-1] = m else: matrices[-1] = m.transpose() for dim in range(min_dim+1): X_faces = self.domain()._n_cells_sorted(dim) Y_faces = self.codomain()._n_cells_sorted(dim) num_faces_X = len(X_faces) num_faces_Y = len(Y_faces) mval = [0 for i in range(num_faces_X*num_faces_Y)] for i in X_faces: y, oriented = self(i, orientation=True) if y.dimension() < dim: pass else: mval[X_faces.index(i)+(Y_faces.index(y)*num_faces_X)] = oriented m = matrix(base_ring,num_faces_Y,num_faces_X,mval,sparse=True) if not cochain: matrices[dim] = m else: matrices[dim] = m.transpose() for dim in range(min_dim+1,max_dim+1): try: l1 = len(self.codomain().n_cells(dim)) except KeyError: l1 = 0 try: l2 = len(self.domain().n_cells(dim)) except KeyError: l2 = 0 m = zero_matrix(base_ring,l1,l2,sparse=True) if not cochain: matrices[dim] = m else: matrices[dim] = m.transpose() if not cochain: return ChainComplexMorphism(matrices, self.domain().chain_complex(base_ring=base_ring,augmented=augmented,cochain=cochain), self.codomain().chain_complex(base_ring=base_ring,augmented=augmented,cochain=cochain)) return ChainComplexMorphism(matrices, self.codomain().chain_complex(base_ring=base_ring,augmented=augmented,cochain=cochain), self.domain().chain_complex(base_ring=base_ring,augmented=augmented,cochain=cochain))
[ "def", "associated_chain_complex_morphism", "(", "self", ",", "base_ring", "=", "ZZ", ",", "augmented", "=", "False", ",", "cochain", "=", "False", ")", ":", "max_dim", "=", "max", "(", "self", ".", "domain", "(", ")", ".", "dimension", "(", ")", ",", ...
https://github.com/sagemath/sage/blob/f9b2db94f675ff16963ccdefba4f1a3393b3fe0d/src/sage/topology/simplicial_complex_morphism.py#L306-L420
IronLanguages/ironpython2
51fdedeeda15727717fb8268a805f71b06c0b9f1
Src/StdLib/Lib/sets.py
python
BaseSet.__xor__
(self, other)
return self.symmetric_difference(other)
Return the symmetric difference of two sets as a new set. (I.e. all elements that are in exactly one of the sets.)
Return the symmetric difference of two sets as a new set.
[ "Return", "the", "symmetric", "difference", "of", "two", "sets", "as", "a", "new", "set", "." ]
def __xor__(self, other): """Return the symmetric difference of two sets as a new set. (I.e. all elements that are in exactly one of the sets.) """ if not isinstance(other, BaseSet): return NotImplemented return self.symmetric_difference(other)
[ "def", "__xor__", "(", "self", ",", "other", ")", ":", "if", "not", "isinstance", "(", "other", ",", "BaseSet", ")", ":", "return", "NotImplemented", "return", "self", ".", "symmetric_difference", "(", "other", ")" ]
https://github.com/IronLanguages/ironpython2/blob/51fdedeeda15727717fb8268a805f71b06c0b9f1/Src/StdLib/Lib/sets.py#L219-L226
ucsb-seclab/karonte
427ac313e596f723e40768b95d13bd7a9fc92fd8
eval/multi_bin/all_bins/run_utils.py
python
get_memcp_like
(p)
return summarized_f
[]
def get_memcp_like(p): addrs = get_dyn_sym_addrs(p, ['strcmp', 'strcasecmp']) summarized_f = {} for f in addrs: summarized_f[f] = summary_functions.memcmp_unsized return summarized_f
[ "def", "get_memcp_like", "(", "p", ")", ":", "addrs", "=", "get_dyn_sym_addrs", "(", "p", ",", "[", "'strcmp'", ",", "'strcasecmp'", "]", ")", "summarized_f", "=", "{", "}", "for", "f", "in", "addrs", ":", "summarized_f", "[", "f", "]", "=", "summary_f...
https://github.com/ucsb-seclab/karonte/blob/427ac313e596f723e40768b95d13bd7a9fc92fd8/eval/multi_bin/all_bins/run_utils.py#L154-L160
airbnb/streamalert
26cf1d08432ca285fd4f7410511a6198ca104bbb
streamalert/rules_engine/rules_engine.py
python
RulesEngine._configure_dynamic_outputs
(cls, record, rule)
return [ output for dynamic_output_function in rule.dynamic_outputs_set for output in cls._call_dynamic_output_function( dynamic_output_function, rule.name, args_list ) ]
Generate list of outputs from dynamic_outputs Args: record (dict): Record to pass through to the dynamic_output function rule (rule.Rule): Attributes for the rule which triggered the alert Returns: list: list of additional outputs to append to the current set
Generate list of outputs from dynamic_outputs
[ "Generate", "list", "of", "outputs", "from", "dynamic_outputs" ]
def _configure_dynamic_outputs(cls, record, rule): """Generate list of outputs from dynamic_outputs Args: record (dict): Record to pass through to the dynamic_output function rule (rule.Rule): Attributes for the rule which triggered the alert Returns: list: list of additional outputs to append to the current set """ args_list = [record] if rule.context: # Pass context to dynamic_output function if context exists args_list.append(rule.context) return [ output for dynamic_output_function in rule.dynamic_outputs_set for output in cls._call_dynamic_output_function( dynamic_output_function, rule.name, args_list ) ]
[ "def", "_configure_dynamic_outputs", "(", "cls", ",", "record", ",", "rule", ")", ":", "args_list", "=", "[", "record", "]", "if", "rule", ".", "context", ":", "# Pass context to dynamic_output function if context exists", "args_list", ".", "append", "(", "rule", ...
https://github.com/airbnb/streamalert/blob/26cf1d08432ca285fd4f7410511a6198ca104bbb/streamalert/rules_engine/rules_engine.py#L246-L266
tensorflow/model-analysis
e38c23ce76eff039548ce69e3160ed4d7984f2fc
tensorflow_model_analysis/eval_saved_model/graph_ref.py
python
load_legacy_features_and_labels
( meta_graph_def: tf.compat.v1.MetaGraphDef, graph: tf.Graph )
return (features_map, labels_map)
Loads legacy features and labels nodes. Args: meta_graph_def: MetaGraphDef to lookup nodes in. graph: TensorFlow graph to lookup the nodes in. Returns: Tuple of (features_map, labels_map)
Loads legacy features and labels nodes.
[ "Loads", "legacy", "features", "and", "labels", "nodes", "." ]
def load_legacy_features_and_labels( meta_graph_def: tf.compat.v1.MetaGraphDef, graph: tf.Graph ) -> Tuple[Dict[str, types.TensorType], Dict[str, types.TensorType]]: """Loads legacy features and labels nodes. Args: meta_graph_def: MetaGraphDef to lookup nodes in. graph: TensorFlow graph to lookup the nodes in. Returns: Tuple of (features_map, labels_map) """ encoded_features_map = collections.OrderedDict( get_node_map_in_graph(meta_graph_def, encoding.FEATURES_COLLECTION, [encoding.NODE_SUFFIX], graph)) features_map = collections.OrderedDict() for key in encoded_features_map: features_map[key] = encoded_features_map[key][encoding.NODE_SUFFIX] encoded_labels_map = collections.OrderedDict( get_node_map_in_graph(meta_graph_def, encoding.LABELS_COLLECTION, [encoding.NODE_SUFFIX], graph)) labels_map = collections.OrderedDict() for key in encoded_labels_map: labels_map[key] = encoded_labels_map[key][encoding.NODE_SUFFIX] # Assume that KeyType is only Text # pytype: disable=bad-return-type return (features_map, labels_map)
[ "def", "load_legacy_features_and_labels", "(", "meta_graph_def", ":", "tf", ".", "compat", ".", "v1", ".", "MetaGraphDef", ",", "graph", ":", "tf", ".", "Graph", ")", "->", "Tuple", "[", "Dict", "[", "str", ",", "types", ".", "TensorType", "]", ",", "Dic...
https://github.com/tensorflow/model-analysis/blob/e38c23ce76eff039548ce69e3160ed4d7984f2fc/tensorflow_model_analysis/eval_saved_model/graph_ref.py#L132-L160
sqlalchemy/alembic
85152025ddba1dbeb51b467f40eb36b795d2ca37
alembic/autogenerate/api.py
python
compare_metadata
(context: "MigrationContext", metadata: "MetaData")
return migration_script.upgrade_ops.as_diffs()
Compare a database schema to that given in a :class:`~sqlalchemy.schema.MetaData` instance. The database connection is presented in the context of a :class:`.MigrationContext` object, which provides database connectivity as well as optional comparison functions to use for datatypes and server defaults - see the "autogenerate" arguments at :meth:`.EnvironmentContext.configure` for details on these. The return format is a list of "diff" directives, each representing individual differences:: from alembic.migration import MigrationContext from alembic.autogenerate import compare_metadata from sqlalchemy.schema import SchemaItem from sqlalchemy.types import TypeEngine from sqlalchemy import (create_engine, MetaData, Column, Integer, String, Table, text) import pprint engine = create_engine("sqlite://") with engine.begin() as conn: conn.execute(text(''' create table foo ( id integer not null primary key, old_data varchar, x integer )''')) conn.execute(text(''' create table bar ( data varchar )''')) metadata = MetaData() Table('foo', metadata, Column('id', Integer, primary_key=True), Column('data', Integer), Column('x', Integer, nullable=False) ) Table('bat', metadata, Column('info', String) ) mc = MigrationContext.configure(engine.connect()) diff = compare_metadata(mc, metadata) pprint.pprint(diff, indent=2, width=20) Output:: [ ( 'add_table', Table('bat', MetaData(bind=None), Column('info', String(), table=<bat>), schema=None)), ( 'remove_table', Table(u'bar', MetaData(bind=None), Column(u'data', VARCHAR(), table=<bar>), schema=None)), ( 'add_column', None, 'foo', Column('data', Integer(), table=<foo>)), ( 'remove_column', None, 'foo', Column(u'old_data', VARCHAR(), table=None)), [ ( 'modify_nullable', None, 'foo', u'x', { 'existing_server_default': None, 'existing_type': INTEGER()}, True, False)]] :param context: a :class:`.MigrationContext` instance. :param metadata: a :class:`~sqlalchemy.schema.MetaData` instance. .. seealso:: :func:`.produce_migrations` - produces a :class:`.MigrationScript` structure based on metadata comparison.
Compare a database schema to that given in a :class:`~sqlalchemy.schema.MetaData` instance.
[ "Compare", "a", "database", "schema", "to", "that", "given", "in", "a", ":", "class", ":", "~sqlalchemy", ".", "schema", ".", "MetaData", "instance", "." ]
def compare_metadata(context: "MigrationContext", metadata: "MetaData") -> Any: """Compare a database schema to that given in a :class:`~sqlalchemy.schema.MetaData` instance. The database connection is presented in the context of a :class:`.MigrationContext` object, which provides database connectivity as well as optional comparison functions to use for datatypes and server defaults - see the "autogenerate" arguments at :meth:`.EnvironmentContext.configure` for details on these. The return format is a list of "diff" directives, each representing individual differences:: from alembic.migration import MigrationContext from alembic.autogenerate import compare_metadata from sqlalchemy.schema import SchemaItem from sqlalchemy.types import TypeEngine from sqlalchemy import (create_engine, MetaData, Column, Integer, String, Table, text) import pprint engine = create_engine("sqlite://") with engine.begin() as conn: conn.execute(text(''' create table foo ( id integer not null primary key, old_data varchar, x integer )''')) conn.execute(text(''' create table bar ( data varchar )''')) metadata = MetaData() Table('foo', metadata, Column('id', Integer, primary_key=True), Column('data', Integer), Column('x', Integer, nullable=False) ) Table('bat', metadata, Column('info', String) ) mc = MigrationContext.configure(engine.connect()) diff = compare_metadata(mc, metadata) pprint.pprint(diff, indent=2, width=20) Output:: [ ( 'add_table', Table('bat', MetaData(bind=None), Column('info', String(), table=<bat>), schema=None)), ( 'remove_table', Table(u'bar', MetaData(bind=None), Column(u'data', VARCHAR(), table=<bar>), schema=None)), ( 'add_column', None, 'foo', Column('data', Integer(), table=<foo>)), ( 'remove_column', None, 'foo', Column(u'old_data', VARCHAR(), table=None)), [ ( 'modify_nullable', None, 'foo', u'x', { 'existing_server_default': None, 'existing_type': INTEGER()}, True, False)]] :param context: a :class:`.MigrationContext` instance. :param metadata: a :class:`~sqlalchemy.schema.MetaData` instance. .. seealso:: :func:`.produce_migrations` - produces a :class:`.MigrationScript` structure based on metadata comparison. """ migration_script = produce_migrations(context, metadata) return migration_script.upgrade_ops.as_diffs()
[ "def", "compare_metadata", "(", "context", ":", "\"MigrationContext\"", ",", "metadata", ":", "\"MetaData\"", ")", "->", "Any", ":", "migration_script", "=", "produce_migrations", "(", "context", ",", "metadata", ")", "return", "migration_script", ".", "upgrade_ops"...
https://github.com/sqlalchemy/alembic/blob/85152025ddba1dbeb51b467f40eb36b795d2ca37/alembic/autogenerate/api.py#L41-L133
nansencenter/nansat
5700ec673fbf522c19b8dedcb01cc15f7cd29a6a
nansat/vrt.py
python
VRT.create_bands
(self, metadata_dict)
Generic function called from the mappers to create bands in the VRT dataset from an input dictionary of metadata Parameters ---------- metadata_dict : list of dict with params of input bands and generated bands. Each dict has: 'src' : dictionary with parameters of the sources: 'dst' : dictionary with parameters of the generated bands Notes --------- Adds bands to the self.dataset based on info in metaDict See Also --------- VRT.create_band()
Generic function called from the mappers to create bands in the VRT dataset from an input dictionary of metadata
[ "Generic", "function", "called", "from", "the", "mappers", "to", "create", "bands", "in", "the", "VRT", "dataset", "from", "an", "input", "dictionary", "of", "metadata" ]
def create_bands(self, metadata_dict): """ Generic function called from the mappers to create bands in the VRT dataset from an input dictionary of metadata Parameters ---------- metadata_dict : list of dict with params of input bands and generated bands. Each dict has: 'src' : dictionary with parameters of the sources: 'dst' : dictionary with parameters of the generated bands Notes --------- Adds bands to the self.dataset based on info in metaDict See Also --------- VRT.create_band() """ for band_dict in metadata_dict: src = band_dict['src'] dst = band_dict.get('dst', None) self.create_band(src, dst) self.logger.debug('Creating band - OK!') self.dataset.FlushCache()
[ "def", "create_bands", "(", "self", ",", "metadata_dict", ")", ":", "for", "band_dict", "in", "metadata_dict", ":", "src", "=", "band_dict", "[", "'src'", "]", "dst", "=", "band_dict", ".", "get", "(", "'dst'", ",", "None", ")", "self", ".", "create_band...
https://github.com/nansencenter/nansat/blob/5700ec673fbf522c19b8dedcb01cc15f7cd29a6a/nansat/vrt.py#L895-L920
CouchPotato/CouchPotatoV1
135b3331d1b88ef645e29b76f2d4cc4a732c9232
library/hachoir_core/tools.py
python
makePrintable
(data, charset, quote=None, to_unicode=False, smart=True)
return data
r""" Prepare a string to make it printable in the specified charset. It escapes control characters. Characters with code bigger than 127 are escaped if data type is 'str' or if charset is "ASCII". Examples with Unicode: >>> aged = unicode("âgé", "UTF-8") >>> repr(aged) # text type is 'unicode' "u'\\xe2g\\xe9'" >>> makePrintable("abc\0", "UTF-8") 'abc\\0' >>> makePrintable(aged, "latin1") '\xe2g\xe9' >>> makePrintable(aged, "latin1", quote='"') '"\xe2g\xe9"' Examples with string encoded in latin1: >>> aged_latin = unicode("âgé", "UTF-8").encode("latin1") >>> repr(aged_latin) # text type is 'str' "'\\xe2g\\xe9'" >>> makePrintable(aged_latin, "latin1") '\\xe2g\\xe9' >>> makePrintable("", "latin1") '' >>> makePrintable("a", "latin1", quote='"') '"a"' >>> makePrintable("", "latin1", quote='"') '(empty)' >>> makePrintable("abc", "latin1", quote="'") "'abc'" Control codes: >>> makePrintable("\0\x03\x0a\x10 \x7f", "latin1") '\\0\\3\\n\\x10 \\x7f' Quote character may also be escaped (only ' and "): >>> print makePrintable("a\"b", "latin-1", quote='"') "a\"b" >>> print makePrintable("a\"b", "latin-1", quote="'") 'a"b' >>> print makePrintable("a'b", "latin-1", quote="'") 'a\'b'
r""" Prepare a string to make it printable in the specified charset. It escapes control characters. Characters with code bigger than 127 are escaped if data type is 'str' or if charset is "ASCII".
[ "r", "Prepare", "a", "string", "to", "make", "it", "printable", "in", "the", "specified", "charset", ".", "It", "escapes", "control", "characters", ".", "Characters", "with", "code", "bigger", "than", "127", "are", "escaped", "if", "data", "type", "is", "s...
def makePrintable(data, charset, quote=None, to_unicode=False, smart=True): r""" Prepare a string to make it printable in the specified charset. It escapes control characters. Characters with code bigger than 127 are escaped if data type is 'str' or if charset is "ASCII". Examples with Unicode: >>> aged = unicode("âgé", "UTF-8") >>> repr(aged) # text type is 'unicode' "u'\\xe2g\\xe9'" >>> makePrintable("abc\0", "UTF-8") 'abc\\0' >>> makePrintable(aged, "latin1") '\xe2g\xe9' >>> makePrintable(aged, "latin1", quote='"') '"\xe2g\xe9"' Examples with string encoded in latin1: >>> aged_latin = unicode("âgé", "UTF-8").encode("latin1") >>> repr(aged_latin) # text type is 'str' "'\\xe2g\\xe9'" >>> makePrintable(aged_latin, "latin1") '\\xe2g\\xe9' >>> makePrintable("", "latin1") '' >>> makePrintable("a", "latin1", quote='"') '"a"' >>> makePrintable("", "latin1", quote='"') '(empty)' >>> makePrintable("abc", "latin1", quote="'") "'abc'" Control codes: >>> makePrintable("\0\x03\x0a\x10 \x7f", "latin1") '\\0\\3\\n\\x10 \\x7f' Quote character may also be escaped (only ' and "): >>> print makePrintable("a\"b", "latin-1", quote='"') "a\"b" >>> print makePrintable("a\"b", "latin-1", quote="'") 'a"b' >>> print makePrintable("a'b", "latin-1", quote="'") 'a\'b' """ if data: if not isinstance(data, unicode): data = unicode(data, "ISO-8859-1") charset = "ASCII" data = regex_control_code.sub( lambda regs: controlchars[ord(regs.group(1))], data) if quote: if quote in "\"'": data = data.replace(quote, '\\' + quote) data = ''.join((quote, data, quote)) elif quote: data = "(empty)" data = data.encode(charset, "backslashreplace") if smart: # Replace \x00\x01 by \0\1 data = re.sub(r"\\x0([0-7])(?=[^0-7]|$)", r"\\\1", data) if to_unicode: data = unicode(data, charset) return data
[ "def", "makePrintable", "(", "data", ",", "charset", ",", "quote", "=", "None", ",", "to_unicode", "=", "False", ",", "smart", "=", "True", ")", ":", "if", "data", ":", "if", "not", "isinstance", "(", "data", ",", "unicode", ")", ":", "data", "=", ...
https://github.com/CouchPotato/CouchPotatoV1/blob/135b3331d1b88ef645e29b76f2d4cc4a732c9232/library/hachoir_core/tools.py#L255-L318
reiinakano/xcessiv
a48dff7d370c84eb5c243bde87164c1f5fd096d5
xcessiv/views.py
python
create_base_learner
(id)
This creates a single base learner from a base learner origin and queues it up
This creates a single base learner from a base learner origin and queues it up
[ "This", "creates", "a", "single", "base", "learner", "from", "a", "base", "learner", "origin", "and", "queues", "it", "up" ]
def create_base_learner(id): """This creates a single base learner from a base learner origin and queues it up""" path = functions.get_path_from_query_string(request) with functions.DBContextManager(path) as session: base_learner_origin = session.query(models.BaseLearnerOrigin).filter_by(id=id).first() if base_learner_origin is None: raise exceptions.UserError('Base learner origin {} not found'.format(id), 404) if not base_learner_origin.final: raise exceptions.UserError('Base learner origin {} is not final'.format(id)) req_body = request.get_json() # Retrieve full hyperparameters est = base_learner_origin.return_estimator() hyperparameters = functions.import_object_from_string_code(req_body['source'], 'params') est.set_params(**hyperparameters) hyperparameters = functions.make_serializable(est.get_params()) base_learners = session.query(models.BaseLearner).\ filter_by(base_learner_origin_id=id, hyperparameters=hyperparameters).all() if base_learners: raise exceptions.UserError('Base learner exists with given hyperparameters') base_learner = models.BaseLearner(hyperparameters, 'queued', base_learner_origin) if 'single_searches' not in base_learner_origin.description: base_learner_origin.description['single_searches'] = [] base_learner_origin.description['single_searches'] += ([req_body['source']]) session.add(base_learner) session.add(base_learner_origin) session.commit() with Connection(get_redis_connection()): rqtasks.generate_meta_features.delay(path, base_learner.id) return jsonify(base_learner.serialize)
[ "def", "create_base_learner", "(", "id", ")", ":", "path", "=", "functions", ".", "get_path_from_query_string", "(", "request", ")", "with", "functions", ".", "DBContextManager", "(", "path", ")", "as", "session", ":", "base_learner_origin", "=", "session", ".",...
https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/views.py#L306-L348
keiffster/program-y
8c99b56f8c32f01a7b9887b5daae9465619d0385
src/programy/storage/utils/processors.py
python
TextFile.close
(self)
[]
def close(self): self._file.close()
[ "def", "close", "(", "self", ")", ":", "self", ".", "_file", ".", "close", "(", ")" ]
https://github.com/keiffster/program-y/blob/8c99b56f8c32f01a7b9887b5daae9465619d0385/src/programy/storage/utils/processors.py#L61-L62
quic/aimet
dae9bae9a77ca719aa7553fefde4768270fc3518
TrainingExtensions/torch/src/python/aimet_torch/cross_layer_equalization.py
python
HighBiasFold.bias_fold
(cls_set_info_list: List[ClsSetInfo], bn_layers: Dict[Union[torch.nn.Conv2d, torch.nn.ConvTranspose2d], torch.nn.BatchNorm2d])
Folds bias values greater than 3 * sigma to next layer's bias :param cls_set_info_list: List of info elements for each cls set :param bn_layers: Key: Conv/Linear layer Value: Corresponding folded BN layer :return: None
Folds bias values greater than 3 * sigma to next layer's bias
[ "Folds", "bias", "values", "greater", "than", "3", "*", "sigma", "to", "next", "layer", "s", "bias" ]
def bias_fold(cls_set_info_list: List[ClsSetInfo], bn_layers: Dict[Union[torch.nn.Conv2d, torch.nn.ConvTranspose2d], torch.nn.BatchNorm2d]): """ Folds bias values greater than 3 * sigma to next layer's bias :param cls_set_info_list: List of info elements for each cls set :param bn_layers: Key: Conv/Linear layer Value: Corresponding folded BN layer :return: None """ if not bn_layers: logger.info('High Bias folding is not supported for models without BatchNorm Layers') return for cls_set_info in cls_set_info_list: for cls_pair_info in cls_set_info.cls_pair_info_list: if (cls_pair_info.layer1.bias is None) or (cls_pair_info.layer2.bias is None) or \ (cls_pair_info.layer1 not in bn_layers): continue prev_layer_params, curr_layer_params = HighBiasFold.call_mo_high_bias_fold(cls_pair_info, bn_layers) prev_layer_bias_shape = cls_pair_info.layer1.weight.shape[0] # Transpose weight back to N, C, H, W for transposed Conv2D if isinstance(cls_pair_info.layer1, torch.nn.ConvTranspose2d) and cls_pair_info.layer1.groups == 1: prev_layer_bias_shape = cls_pair_info.layer1.weight.shape[1] cls_pair_info.layer1.bias.data = torch.from_numpy(np.reshape(prev_layer_params.bias, prev_layer_bias_shape)) cls_pair_info.layer1.bias.data = cls_pair_info.layer1.bias.data.type(torch.FloatTensor) cls_pair_info.layer2.bias.data = torch.from_numpy(np.reshape(curr_layer_params.bias, curr_layer_params.weightShape[0])) cls_pair_info.layer2.bias.data = cls_pair_info.layer2.bias.data.type(torch.FloatTensor)
[ "def", "bias_fold", "(", "cls_set_info_list", ":", "List", "[", "ClsSetInfo", "]", ",", "bn_layers", ":", "Dict", "[", "Union", "[", "torch", ".", "nn", ".", "Conv2d", ",", "torch", ".", "nn", ".", "ConvTranspose2d", "]", ",", "torch", ".", "nn", ".", ...
https://github.com/quic/aimet/blob/dae9bae9a77ca719aa7553fefde4768270fc3518/TrainingExtensions/torch/src/python/aimet_torch/cross_layer_equalization.py#L572-L605
smart-mobile-software/gitstack
d9fee8f414f202143eb6e620529e8e5539a2af56
python/Lib/decimal.py
python
Decimal.log10
(self, context=None)
return ans
Returns the base 10 logarithm of self.
Returns the base 10 logarithm of self.
[ "Returns", "the", "base", "10", "logarithm", "of", "self", "." ]
def log10(self, context=None): """Returns the base 10 logarithm of self.""" if context is None: context = getcontext() # log10(NaN) = NaN ans = self._check_nans(context=context) if ans: return ans # log10(0.0) == -Infinity if not self: return _NegativeInfinity # log10(Infinity) = Infinity if self._isinfinity() == 1: return _Infinity # log10(negative or -Infinity) raises InvalidOperation if self._sign == 1: return context._raise_error(InvalidOperation, 'log10 of a negative value') # log10(10**n) = n if self._int[0] == '1' and self._int[1:] == '0'*(len(self._int) - 1): # answer may need rounding ans = Decimal(self._exp + len(self._int) - 1) else: # result is irrational, so necessarily inexact op = _WorkRep(self) c, e = op.int, op.exp p = context.prec # correctly rounded result: repeatedly increase precision # until result is unambiguously roundable places = p-self._log10_exp_bound()+2 while True: coeff = _dlog10(c, e, places) # assert len(str(abs(coeff)))-p >= 1 if coeff % (5*10**(len(str(abs(coeff)))-p-1)): break places += 3 ans = _dec_from_triple(int(coeff<0), str(abs(coeff)), -places) context = context._shallow_copy() rounding = context._set_rounding(ROUND_HALF_EVEN) ans = ans._fix(context) context.rounding = rounding return ans
[ "def", "log10", "(", "self", ",", "context", "=", "None", ")", ":", "if", "context", "is", "None", ":", "context", "=", "getcontext", "(", ")", "# log10(NaN) = NaN", "ans", "=", "self", ".", "_check_nans", "(", "context", "=", "context", ")", "if", "an...
https://github.com/smart-mobile-software/gitstack/blob/d9fee8f414f202143eb6e620529e8e5539a2af56/python/Lib/decimal.py#L3140-L3189
leancloud/satori
701caccbd4fe45765001ca60435c0cb499477c03
satori-rules/plugin/libs/gevent/pool.py
python
GroupMappingMixin.map_async
(self, func, iterable, callback=None)
return Greenlet.spawn(self.map_cb, func, iterable, callback)
A variant of the map() method which returns a Greenlet object that is executing the map function. If callback is specified then it should be a callable which accepts a single argument.
A variant of the map() method which returns a Greenlet object that is executing the map function.
[ "A", "variant", "of", "the", "map", "()", "method", "which", "returns", "a", "Greenlet", "object", "that", "is", "executing", "the", "map", "function", "." ]
def map_async(self, func, iterable, callback=None): """ A variant of the map() method which returns a Greenlet object that is executing the map function. If callback is specified then it should be a callable which accepts a single argument. """ return Greenlet.spawn(self.map_cb, func, iterable, callback)
[ "def", "map_async", "(", "self", ",", "func", ",", "iterable", ",", "callback", "=", "None", ")", ":", "return", "Greenlet", ".", "spawn", "(", "self", ".", "map_cb", ",", "func", ",", "iterable", ",", "callback", ")" ]
https://github.com/leancloud/satori/blob/701caccbd4fe45765001ca60435c0cb499477c03/satori-rules/plugin/libs/gevent/pool.py#L316-L324
nosmokingbandit/watcher
dadacd21a5790ee609058a98a17fcc8954d24439
lib/sqlalchemy/orm/relationships.py
python
JoinCondition._annotate_local
(self)
Annotate the primaryjoin and secondaryjoin structures with 'local' annotations. This annotates all column elements found simultaneously in the parent table and the join condition that don't have a 'remote' annotation set up from _annotate_remote() or user-defined.
Annotate the primaryjoin and secondaryjoin structures with 'local' annotations.
[ "Annotate", "the", "primaryjoin", "and", "secondaryjoin", "structures", "with", "local", "annotations", "." ]
def _annotate_local(self): """Annotate the primaryjoin and secondaryjoin structures with 'local' annotations. This annotates all column elements found simultaneously in the parent table and the join condition that don't have a 'remote' annotation set up from _annotate_remote() or user-defined. """ if self._has_annotation(self.primaryjoin, "local"): return if self._local_remote_pairs: local_side = util.column_set([l for (l, r) in self._local_remote_pairs]) else: local_side = util.column_set(self.parent_selectable.c) def locals_(elem): if "remote" not in elem._annotations and \ elem in local_side: return elem._annotate({"local": True}) self.primaryjoin = visitors.replacement_traverse( self.primaryjoin, {}, locals_ )
[ "def", "_annotate_local", "(", "self", ")", ":", "if", "self", ".", "_has_annotation", "(", "self", ".", "primaryjoin", ",", "\"local\"", ")", ":", "return", "if", "self", ".", "_local_remote_pairs", ":", "local_side", "=", "util", ".", "column_set", "(", ...
https://github.com/nosmokingbandit/watcher/blob/dadacd21a5790ee609058a98a17fcc8954d24439/lib/sqlalchemy/orm/relationships.py#L2425-L2451
automl/RoBO
91366b12a1a3deb8e80dd08599e0eaf4df28adc1
robo/models/base_model.py
python
BaseModel.train
(self, X, y)
Trains the model on the provided data. Parameters ---------- X: np.ndarray (N, D) Input data points. The dimensionality of X is (N, D), with N as the number of points and D is the number of input dimensions. y: np.ndarray (N,) The corresponding target values of the input data points.
Trains the model on the provided data.
[ "Trains", "the", "model", "on", "the", "provided", "data", "." ]
def train(self, X, y): """ Trains the model on the provided data. Parameters ---------- X: np.ndarray (N, D) Input data points. The dimensionality of X is (N, D), with N as the number of points and D is the number of input dimensions. y: np.ndarray (N,) The corresponding target values of the input data points. """ pass
[ "def", "train", "(", "self", ",", "X", ",", "y", ")", ":", "pass" ]
https://github.com/automl/RoBO/blob/91366b12a1a3deb8e80dd08599e0eaf4df28adc1/robo/models/base_model.py#L16-L28
ahmetcemturan/SFACT
7576e29ba72b33e5058049b77b7b558875542747
fabmetheus_utilities/svg_reader.py
python
PathReader.processPathWordA
(self)
Process path word A.
Process path word A.
[ "Process", "path", "word", "A", "." ]
def processPathWordA(self): 'Process path word A.' self.addPathArc( self.getComplexByExtraIndex( 6 ) )
[ "def", "processPathWordA", "(", "self", ")", ":", "self", ".", "addPathArc", "(", "self", ".", "getComplexByExtraIndex", "(", "6", ")", ")" ]
https://github.com/ahmetcemturan/SFACT/blob/7576e29ba72b33e5058049b77b7b558875542747/fabmetheus_utilities/svg_reader.py#L724-L726
jendrikseipp/rednotebook
3ec73124af8679371b4fdb379824149f7407006d
rednotebook/journal.py
python
Journal.get_journal_path
(self)
Retrieve the path from optional args or return standard value if args not present
Retrieve the path from optional args or return standard value if args not present
[ "Retrieve", "the", "path", "from", "optional", "args", "or", "return", "standard", "value", "if", "args", "not", "present" ]
def get_journal_path(self): """ Retrieve the path from optional args or return standard value if args not present """ if not args.journal: data_dir = self.config.read("dataDir", self.dirs.data_dir) if not os.path.isabs(data_dir): data_dir = os.path.join(self.dirs.app_dir, data_dir) data_dir = os.path.normpath(data_dir) return data_dir # path_arg can be e.g. data (under .rednotebook), data (elsewhere), # or an absolute path /home/username/myjournal # Try to find the journal under the standard location or at the given # absolute or relative location path_arg = args.journal logging.debug('Trying to find journal "%s"' % path_arg) paths_to_check = [path_arg, os.path.join(self.dirs.journal_user_dir, path_arg)] for path in paths_to_check: if os.path.exists(path): if os.path.isdir(path): return path else: logging.warning( "To open a journal you must specify a " "directory, not a file." ) logging.error( 'The path "%s" is not a valid journal directory. ' 'Execute "rednotebook -h" for instructions' % path_arg ) sys.exit(2)
[ "def", "get_journal_path", "(", "self", ")", ":", "if", "not", "args", ".", "journal", ":", "data_dir", "=", "self", ".", "config", ".", "read", "(", "\"dataDir\"", ",", "self", ".", "dirs", ".", "data_dir", ")", "if", "not", "os", ".", "path", ".", ...
https://github.com/jendrikseipp/rednotebook/blob/3ec73124af8679371b4fdb379824149f7407006d/rednotebook/journal.py#L244-L279
caronc/apprise
e5945e0be1b7051ab4890bf78949058304f2d641
apprise/plugins/NotifyLametric.py
python
NotifyLametric.parse_url
(url)
return results
Parses the URL and returns enough arguments that can allow us to re-instantiate this object.
Parses the URL and returns enough arguments that can allow us to re-instantiate this object.
[ "Parses", "the", "URL", "and", "returns", "enough", "arguments", "that", "can", "allow", "us", "to", "re", "-", "instantiate", "this", "object", "." ]
def parse_url(url): """ Parses the URL and returns enough arguments that can allow us to re-instantiate this object. """ results = NotifyBase.parse_url(url, verify_host=False) if not results: # We're done early as we couldn't load the results return results if results.get('user') and not results.get('password'): # Handle URL like: # schema://user@host # This becomes the password results['password'] = results['user'] results['user'] = None # Priority Handling if 'priority' in results['qsd'] and results['qsd']['priority']: results['priority'] = NotifyLametric.unquote( results['qsd']['priority'].strip().lower()) # Icon Type if 'icon' in results['qsd'] and results['qsd']['icon']: results['icon'] = NotifyLametric.unquote( results['qsd']['icon'].strip().lower()) # Icon Type if 'icon_type' in results['qsd'] and results['qsd']['icon_type']: results['icon_type'] = NotifyLametric.unquote( results['qsd']['icon_type'].strip().lower()) # Sound if 'sound' in results['qsd'] and results['qsd']['sound']: results['sound'] = NotifyLametric.unquote( results['qsd']['sound'].strip().lower()) # API Key (Device Mode) if 'apikey' in results['qsd'] and results['qsd']['apikey']: # Extract API Key from an argument results['apikey'] = \ NotifyLametric.unquote(results['qsd']['apikey']) # App ID if 'app' in results['qsd'] \ and results['qsd']['app']: # Extract the App ID from an argument results['app_id'] = \ NotifyLametric.unquote(results['qsd']['app']) # App Version if 'app_ver' in results['qsd'] \ and results['qsd']['app_ver']: # Extract the App ID from an argument results['app_ver'] = \ NotifyLametric.unquote(results['qsd']['app_ver']) if 'token' in results['qsd'] and results['qsd']['token']: # Extract Application Access Token from an argument results['app_token'] = \ NotifyLametric.unquote(results['qsd']['token']) # Mode override if 'mode' in results['qsd'] and results['qsd']['mode']: results['mode'] = NotifyLametric.unquote( results['qsd']['mode'].strip().lower()) else: # We can try to detect the mode based on the validity of the # hostname. We can also scan the validity of the Application # Access token # # This isn't a surfire way to do things though; it's best to # specify the mode= flag results['mode'] = LametricMode.DEVICE \ if ((is_hostname(results['host']) or is_ipaddr(results['host'])) and # make sure password is not an Access Token (results['password'] and not LAMETRIC_IS_APP_TOKEN.match(results['password'])) and # Scan for app_ flags next((f for f in results.keys() \ if f.startswith('app_')), None) is None) \ else LametricMode.CLOUD # Handle defaults if not set if results['mode'] == LametricMode.DEVICE: # Device Mode Defaults if 'apikey' not in results: results['apikey'] = \ NotifyLametric.unquote(results['password']) else: # CLOUD Mode Defaults if 'app_id' not in results: results['app_id'] = \ NotifyLametric.unquote(results['host']) if 'app_token' not in results: results['app_token'] = \ NotifyLametric.unquote(results['password']) # Set cycles try: results['cycles'] = abs(int(results['qsd'].get('cycles'))) except (TypeError, ValueError): # Not a valid integer; ignore entry pass return results
[ "def", "parse_url", "(", "url", ")", ":", "results", "=", "NotifyBase", ".", "parse_url", "(", "url", ",", "verify_host", "=", "False", ")", "if", "not", "results", ":", "# We're done early as we couldn't load the results", "return", "results", "if", "results", ...
https://github.com/caronc/apprise/blob/e5945e0be1b7051ab4890bf78949058304f2d641/apprise/plugins/NotifyLametric.py#L852-L967
Tencent/QT4i
75f8705c194505b483c6b7464da8522cd53ba679
qt4i/driver/host.py
python
RPCServerHost.push_file_data
(self, data, file_path, override=True)
return os.path.isfile(file_path)
push file to rpc server :param data: str :param file_path: str :param override: boolean :return: boolean
push file to rpc server
[ "push", "file", "to", "rpc", "server" ]
def push_file_data(self, data, file_path, override=True): '''push file to rpc server :param data: str :param file_path: str :param override: boolean :return: boolean ''' if os.path.exists(file_path) and override: os.remove(file_path) with open(file_path, "ab") as fd: if six.PY3 and isinstance(data, six.string_types): data = data.encode('utf-8') fd.write(base64.decodebytes(data)) else: fd.write(base64.decodestring(data)) return os.path.isfile(file_path)
[ "def", "push_file_data", "(", "self", ",", "data", ",", "file_path", ",", "override", "=", "True", ")", ":", "if", "os", ".", "path", ".", "exists", "(", "file_path", ")", "and", "override", ":", "os", ".", "remove", "(", "file_path", ")", "with", "o...
https://github.com/Tencent/QT4i/blob/75f8705c194505b483c6b7464da8522cd53ba679/qt4i/driver/host.py#L60-L78
keras-team/keras
5caa668b6a415675064a730f5eb46ecc08e40f65
keras/applications/efficientnet_v2.py
python
round_filters
(filters, width_coefficient, min_depth, depth_divisor)
return int(new_filters)
Round number of filters based on depth multiplier.
Round number of filters based on depth multiplier.
[ "Round", "number", "of", "filters", "based", "on", "depth", "multiplier", "." ]
def round_filters(filters, width_coefficient, min_depth, depth_divisor): """Round number of filters based on depth multiplier.""" filters *= width_coefficient minimum_depth = min_depth or depth_divisor new_filters = max( minimum_depth, int(filters + depth_divisor / 2) // depth_divisor * depth_divisor, ) return int(new_filters)
[ "def", "round_filters", "(", "filters", ",", "width_coefficient", ",", "min_depth", ",", "depth_divisor", ")", ":", "filters", "*=", "width_coefficient", "minimum_depth", "=", "min_depth", "or", "depth_divisor", "new_filters", "=", "max", "(", "minimum_depth", ",", ...
https://github.com/keras-team/keras/blob/5caa668b6a415675064a730f5eb46ecc08e40f65/keras/applications/efficientnet_v2.py#L591-L599
Nuitka/Nuitka
39262276993757fa4e299f497654065600453fc9
nuitka/build/inline_copy/lib/scons-3.1.2/SCons/Tool/mssdk.py
python
generate
(env)
Add construction variables for an MS SDK to an Environment.
Add construction variables for an MS SDK to an Environment.
[ "Add", "construction", "variables", "for", "an", "MS", "SDK", "to", "an", "Environment", "." ]
def generate(env): """Add construction variables for an MS SDK to an Environment.""" mssdk_setup_env(env)
[ "def", "generate", "(", "env", ")", ":", "mssdk_setup_env", "(", "env", ")" ]
https://github.com/Nuitka/Nuitka/blob/39262276993757fa4e299f497654065600453fc9/nuitka/build/inline_copy/lib/scons-3.1.2/SCons/Tool/mssdk.py#L39-L41
freyta/7Eleven-Python
e3702fec61743950370e1f35121b2a313e080210
API_REQUESTS/api/account.py
python
logout
(deviceSecret, accessToken)
return(response.content)
[]
def logout(deviceSecret, accessToken): payload = '""' tssa = generateTssa(BASE_URL + "account/logout", "POST", payload, accessToken) headers = {'User-Agent':'Apache-HttpClient/UNAVAILABLE (java 1.4)', 'Connection':'Keep-Alive', 'Host':'711-goodcall.api.tigerspike.com', 'Authorization':'%s' % tssa, 'X-OsVersion':ANDROID_VERSION, 'X-OsName':'Android', 'X-DeviceID':DEVICE_ID, 'X-AppVersion':APP_VERSION, 'X-DeviceSecret':deviceSecret, 'Content-Type':'application/json; charset=utf-8'} response = requests.post(BASE_URL + "account/logout", data=payload, headers=headers) return(response.content)
[ "def", "logout", "(", "deviceSecret", ",", "accessToken", ")", ":", "payload", "=", "'\"\"'", "tssa", "=", "generateTssa", "(", "BASE_URL", "+", "\"account/logout\"", ",", "\"POST\"", ",", "payload", ",", "accessToken", ")", "headers", "=", "{", "'User-Agent'"...
https://github.com/freyta/7Eleven-Python/blob/e3702fec61743950370e1f35121b2a313e080210/API_REQUESTS/api/account.py#L60-L78
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/Python-2.7.9/Lib/calendar.py
python
TextCalendar.formatweekday
(self, day, width)
return names[day][:width].center(width)
Returns a formatted week day name.
Returns a formatted week day name.
[ "Returns", "a", "formatted", "week", "day", "name", "." ]
def formatweekday(self, day, width): """ Returns a formatted week day name. """ if width >= 9: names = day_name else: names = day_abbr return names[day][:width].center(width)
[ "def", "formatweekday", "(", "self", ",", "day", ",", "width", ")", ":", "if", "width", ">=", "9", ":", "names", "=", "day_name", "else", ":", "names", "=", "day_abbr", "return", "names", "[", "day", "]", "[", ":", "width", "]", ".", "center", "(",...
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/Python-2.7.9/Lib/calendar.py#L287-L295
BigBrotherBot/big-brother-bot
848823c71413c86e7f1ff9584f43e08d40a7f2c0
b3/plugins/callvote/__init__.py
python
CallvotePlugin.getLevel
(self, level)
return mingroup.name
Return the group name associated to the given group level
Return the group name associated to the given group level
[ "Return", "the", "group", "name", "associated", "to", "the", "given", "group", "level" ]
def getLevel(self, level): """ Return the group name associated to the given group level """ mingroup = None groups = self.console.storage.getGroups() for x in groups: if x.level < level: continue if mingroup is None: mingroup = x continue if x.level < mingroup.level: mingroup = x return mingroup.name
[ "def", "getLevel", "(", "self", ",", "level", ")", ":", "mingroup", "=", "None", "groups", "=", "self", ".", "console", ".", "storage", ".", "getGroups", "(", ")", "for", "x", "in", "groups", ":", "if", "x", ".", "level", "<", "level", ":", "contin...
https://github.com/BigBrotherBot/big-brother-bot/blob/848823c71413c86e7f1ff9584f43e08d40a7f2c0/b3/plugins/callvote/__init__.py#L258-L277
henkelis/sonospy
841f52010fd6e1e932d8f1a8896ad4e5a0667b8a
sonospy/gui/extractTab.py
python
ExtractPanel.setButtons
(self, state)
Toggle for the button states.
Toggle for the button states.
[ "Toggle", "for", "the", "button", "states", "." ]
def setButtons(self, state): """ Toggle for the button states. """ if state == True: self.bt_Extract.Enable() self.bt_MainDatabase.Enable() self.bt_SaveLog.Enable() self.bt_TargetDatabase.Enable() self.ck_ExtractVerbose.Enable() self.ck_OverwriteExisting.Enable() self.bt_SaveDefaults.Enable() pub.sendMessage(('setLaunchPanel'), "Enable") pub.sendMessage(('setScanPanel'), "Enable") pub.sendMessage(('setVirtualPanel'), "Enable") wx.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) else: self.bt_Extract.Disable() self.bt_MainDatabase.Disable() self.bt_SaveLog.Disable() self.bt_TargetDatabase.Disable() self.ck_ExtractVerbose.Disable() self.ck_OverwriteExisting.Disable() self.bt_SaveDefaults.Disable() pub.sendMessage(('setLaunchPanel'), "Disable") pub.sendMessage(('setScanPanel'), "Disable") pub.sendMessage(('setVirtualPanel'), "Disable") wx.SetCursor(wx.StockCursor(wx.CURSOR_WATCH))
[ "def", "setButtons", "(", "self", ",", "state", ")", ":", "if", "state", "==", "True", ":", "self", ".", "bt_Extract", ".", "Enable", "(", ")", "self", ".", "bt_MainDatabase", ".", "Enable", "(", ")", "self", ".", "bt_SaveLog", ".", "Enable", "(", ")...
https://github.com/henkelis/sonospy/blob/841f52010fd6e1e932d8f1a8896ad4e5a0667b8a/sonospy/gui/extractTab.py#L516-L543
TencentCloud/tencentcloud-sdk-python
3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2
tencentcloud/mongodb/v20190725/models.py
python
DescribeCurrentOpResponse.__init__
(self)
r""" :param TotalCount: 符合查询条件的操作总数 :type TotalCount: int :param CurrentOps: 当前操作列表 :type CurrentOps: list of CurrentOp :param RequestId: 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 :type RequestId: str
r""" :param TotalCount: 符合查询条件的操作总数 :type TotalCount: int :param CurrentOps: 当前操作列表 :type CurrentOps: list of CurrentOp :param RequestId: 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 :type RequestId: str
[ "r", ":", "param", "TotalCount", ":", "符合查询条件的操作总数", ":", "type", "TotalCount", ":", "int", ":", "param", "CurrentOps", ":", "当前操作列表", ":", "type", "CurrentOps", ":", "list", "of", "CurrentOp", ":", "param", "RequestId", ":", "唯一请求", "ID,每次请求都会返回。定位问题时需要提供该次请求...
def __init__(self): r""" :param TotalCount: 符合查询条件的操作总数 :type TotalCount: int :param CurrentOps: 当前操作列表 :type CurrentOps: list of CurrentOp :param RequestId: 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 :type RequestId: str """ self.TotalCount = None self.CurrentOps = None self.RequestId = None
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "TotalCount", "=", "None", "self", ".", "CurrentOps", "=", "None", "self", ".", "RequestId", "=", "None" ]
https://github.com/TencentCloud/tencentcloud-sdk-python/blob/3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2/tencentcloud/mongodb/v20190725/models.py#L1155-L1166
cloudera/hue
23f02102d4547c17c32bd5ea0eb24e9eadd657a4
desktop/core/ext-py/SQLAlchemy-1.3.17/lib/sqlalchemy/sql/dml.py
python
ValuesBase.return_defaults
(self, *cols)
Make use of a :term:`RETURNING` clause for the purpose of fetching server-side expressions and defaults. E.g.:: stmt = table.insert().values(data='newdata').return_defaults() result = connection.execute(stmt) server_created_at = result.returned_defaults['created_at'] When used against a backend that supports RETURNING, all column values generated by SQL expression or server-side-default will be added to any existing RETURNING clause, provided that :meth:`.UpdateBase.returning` is not used simultaneously. The column values will then be available on the result using the :attr:`_engine.ResultProxy.returned_defaults` accessor as a dictionary , referring to values keyed to the :class:`_schema.Column` object as well as its ``.key``. This method differs from :meth:`.UpdateBase.returning` in these ways: 1. :meth:`.ValuesBase.return_defaults` is only intended for use with an INSERT or an UPDATE statement that matches exactly one row. While the RETURNING construct in the general sense supports multiple rows for a multi-row UPDATE or DELETE statement, or for special cases of INSERT that return multiple rows (e.g. INSERT from SELECT, multi-valued VALUES clause), :meth:`.ValuesBase.return_defaults` is intended only for an "ORM-style" single-row INSERT/UPDATE statement. The row returned by the statement is also consumed implicitly when :meth:`.ValuesBase.return_defaults` is used. By contrast, :meth:`.UpdateBase.returning` leaves the RETURNING result-set intact with a collection of any number of rows. 2. It is compatible with the existing logic to fetch auto-generated primary key values, also known as "implicit returning". Backends that support RETURNING will automatically make use of RETURNING in order to fetch the value of newly generated primary keys; while the :meth:`.UpdateBase.returning` method circumvents this behavior, :meth:`.ValuesBase.return_defaults` leaves it intact. 3. It can be called against any backend. Backends that don't support RETURNING will skip the usage of the feature, rather than raising an exception. The return value of :attr:`_engine.ResultProxy.returned_defaults` will be ``None`` :meth:`.ValuesBase.return_defaults` is used by the ORM to provide an efficient implementation for the ``eager_defaults`` feature of :func:`.mapper`. :param cols: optional list of column key names or :class:`_schema.Column` objects. If omitted, all column expressions evaluated on the server are added to the returning list. .. versionadded:: 0.9.0 .. seealso:: :meth:`.UpdateBase.returning` :attr:`_engine.ResultProxy.returned_defaults`
Make use of a :term:`RETURNING` clause for the purpose of fetching server-side expressions and defaults.
[ "Make", "use", "of", "a", ":", "term", ":", "RETURNING", "clause", "for", "the", "purpose", "of", "fetching", "server", "-", "side", "expressions", "and", "defaults", "." ]
def return_defaults(self, *cols): """Make use of a :term:`RETURNING` clause for the purpose of fetching server-side expressions and defaults. E.g.:: stmt = table.insert().values(data='newdata').return_defaults() result = connection.execute(stmt) server_created_at = result.returned_defaults['created_at'] When used against a backend that supports RETURNING, all column values generated by SQL expression or server-side-default will be added to any existing RETURNING clause, provided that :meth:`.UpdateBase.returning` is not used simultaneously. The column values will then be available on the result using the :attr:`_engine.ResultProxy.returned_defaults` accessor as a dictionary , referring to values keyed to the :class:`_schema.Column` object as well as its ``.key``. This method differs from :meth:`.UpdateBase.returning` in these ways: 1. :meth:`.ValuesBase.return_defaults` is only intended for use with an INSERT or an UPDATE statement that matches exactly one row. While the RETURNING construct in the general sense supports multiple rows for a multi-row UPDATE or DELETE statement, or for special cases of INSERT that return multiple rows (e.g. INSERT from SELECT, multi-valued VALUES clause), :meth:`.ValuesBase.return_defaults` is intended only for an "ORM-style" single-row INSERT/UPDATE statement. The row returned by the statement is also consumed implicitly when :meth:`.ValuesBase.return_defaults` is used. By contrast, :meth:`.UpdateBase.returning` leaves the RETURNING result-set intact with a collection of any number of rows. 2. It is compatible with the existing logic to fetch auto-generated primary key values, also known as "implicit returning". Backends that support RETURNING will automatically make use of RETURNING in order to fetch the value of newly generated primary keys; while the :meth:`.UpdateBase.returning` method circumvents this behavior, :meth:`.ValuesBase.return_defaults` leaves it intact. 3. It can be called against any backend. Backends that don't support RETURNING will skip the usage of the feature, rather than raising an exception. The return value of :attr:`_engine.ResultProxy.returned_defaults` will be ``None`` :meth:`.ValuesBase.return_defaults` is used by the ORM to provide an efficient implementation for the ``eager_defaults`` feature of :func:`.mapper`. :param cols: optional list of column key names or :class:`_schema.Column` objects. If omitted, all column expressions evaluated on the server are added to the returning list. .. versionadded:: 0.9.0 .. seealso:: :meth:`.UpdateBase.returning` :attr:`_engine.ResultProxy.returned_defaults` """ self._return_defaults = cols or True
[ "def", "return_defaults", "(", "self", ",", "*", "cols", ")", ":", "self", ".", "_return_defaults", "=", "cols", "or", "True" ]
https://github.com/cloudera/hue/blob/23f02102d4547c17c32bd5ea0eb24e9eadd657a4/desktop/core/ext-py/SQLAlchemy-1.3.17/lib/sqlalchemy/sql/dml.py#L415-L483
jilljenn/tryalgo
46da31aea9a0ff58819e360c987f9506b21f6e9d
tryalgo/closest_points.py
python
cell
(point, size)
return (int(x // size), int(y // size))
returns the grid cell coordinates containing the given point. size is the side length of a grid cell beware: in other languages negative coordinates need special care in C++ for example int(-1.5) == -1 and not -2 as we need hence we need floor(x / pas) in C++ using #include <cmath>
returns the grid cell coordinates containing the given point. size is the side length of a grid cell
[ "returns", "the", "grid", "cell", "coordinates", "containing", "the", "given", "point", ".", "size", "is", "the", "side", "length", "of", "a", "grid", "cell" ]
def cell(point, size): """ returns the grid cell coordinates containing the given point. size is the side length of a grid cell beware: in other languages negative coordinates need special care in C++ for example int(-1.5) == -1 and not -2 as we need hence we need floor(x / pas) in C++ using #include <cmath> """ x, y = point # size = grid cell side length return (int(x // size), int(y // size))
[ "def", "cell", "(", "point", ",", "size", ")", ":", "x", ",", "y", "=", "point", "# size = grid cell side length", "return", "(", "int", "(", "x", "//", "size", ")", ",", "int", "(", "y", "//", "size", ")", ")" ]
https://github.com/jilljenn/tryalgo/blob/46da31aea9a0ff58819e360c987f9506b21f6e9d/tryalgo/closest_points.py#L28-L37
timonwong/OmniMarkupPreviewer
21921ac7a99d2b5924a2219b33679a5b53621392
OmniMarkupLib/Renderers/libs/python3/genshi/path.py
python
Axis.forname
(cls, name)
return getattr(cls, name.upper().replace('-', '_'), None)
Return the axis constant for the given name, or `None` if no such axis was defined.
Return the axis constant for the given name, or `None` if no such axis was defined.
[ "Return", "the", "axis", "constant", "for", "the", "given", "name", "or", "None", "if", "no", "such", "axis", "was", "defined", "." ]
def forname(cls, name): """Return the axis constant for the given name, or `None` if no such axis was defined. """ return getattr(cls, name.upper().replace('-', '_'), None)
[ "def", "forname", "(", "cls", ",", "name", ")", ":", "return", "getattr", "(", "cls", ",", "name", ".", "upper", "(", ")", ".", "replace", "(", "'-'", ",", "'_'", ")", ",", "None", ")" ]
https://github.com/timonwong/OmniMarkupPreviewer/blob/21921ac7a99d2b5924a2219b33679a5b53621392/OmniMarkupLib/Renderers/libs/python3/genshi/path.py#L69-L73
tendenci/tendenci
0f2c348cc0e7d41bc56f50b00ce05544b083bf1d
tendenci/apps/corporate_memberships/models.py
python
CorpMembership.is_join_pending
(self)
return not self.renewal and self.status_detail in [ 'pending', 'paid - pending approval']
[]
def is_join_pending(self): return not self.renewal and self.status_detail in [ 'pending', 'paid - pending approval']
[ "def", "is_join_pending", "(", "self", ")", ":", "return", "not", "self", ".", "renewal", "and", "self", ".", "status_detail", "in", "[", "'pending'", ",", "'paid - pending approval'", "]" ]
https://github.com/tendenci/tendenci/blob/0f2c348cc0e7d41bc56f50b00ce05544b083bf1d/tendenci/apps/corporate_memberships/models.py#L1363-L1366
alexgolec/tda-api
3a5232178ecaad423bd530764e547f968a822ec1
tda/client/base.py
python
BaseClient._datetime_as_millis
(self, var_name, dt)
return int(dt.timestamp() * 1000)
Converts datetime objects to compatible millisecond values
Converts datetime objects to compatible millisecond values
[ "Converts", "datetime", "objects", "to", "compatible", "millisecond", "values" ]
def _datetime_as_millis(self, var_name, dt): 'Converts datetime objects to compatible millisecond values' self._assert_type(var_name, dt, [self._DATETIME]) return int(dt.timestamp() * 1000)
[ "def", "_datetime_as_millis", "(", "self", ",", "var_name", ",", "dt", ")", ":", "self", ".", "_assert_type", "(", "var_name", ",", "dt", ",", "[", "self", ".", "_DATETIME", "]", ")", "return", "int", "(", "dt", ".", "timestamp", "(", ")", "*", "1000...
https://github.com/alexgolec/tda-api/blob/3a5232178ecaad423bd530764e547f968a822ec1/tda/client/base.py#L100-L104
mesalock-linux/mesapy
ed546d59a21b36feb93e2309d5c6b75aa0ad95c9
pypy/module/cpyext/stubsactive.py
python
Py_AddPendingCall
(space, func, arg)
return -1
Post a notification to the Python main thread. If successful, func will be called with the argument arg at the earliest convenience. func will be called having the global interpreter lock held and can thus use the full Python API and can take any action such as setting object attributes to signal IO completion. It must return 0 on success, or -1 signalling an exception. The notification function won't be interrupted to perform another asynchronous notification recursively, but it can still be interrupted to switch threads if the global interpreter lock is released, for example, if it calls back into Python code. This function returns 0 on success in which case the notification has been scheduled. Otherwise, for example if the notification buffer is full, it returns -1 without setting any exception. This function can be called on any thread, be it a Python thread or some other system thread. If it is a Python thread, it doesn't matter if it holds the global interpreter lock or not.
Post a notification to the Python main thread. If successful, func will be called with the argument arg at the earliest convenience. func will be called having the global interpreter lock held and can thus use the full Python API and can take any action such as setting object attributes to signal IO completion. It must return 0 on success, or -1 signalling an exception. The notification function won't be interrupted to perform another asynchronous notification recursively, but it can still be interrupted to switch threads if the global interpreter lock is released, for example, if it calls back into Python code.
[ "Post", "a", "notification", "to", "the", "Python", "main", "thread", ".", "If", "successful", "func", "will", "be", "called", "with", "the", "argument", "arg", "at", "the", "earliest", "convenience", ".", "func", "will", "be", "called", "having", "the", "...
def Py_AddPendingCall(space, func, arg): """Post a notification to the Python main thread. If successful, func will be called with the argument arg at the earliest convenience. func will be called having the global interpreter lock held and can thus use the full Python API and can take any action such as setting object attributes to signal IO completion. It must return 0 on success, or -1 signalling an exception. The notification function won't be interrupted to perform another asynchronous notification recursively, but it can still be interrupted to switch threads if the global interpreter lock is released, for example, if it calls back into Python code. This function returns 0 on success in which case the notification has been scheduled. Otherwise, for example if the notification buffer is full, it returns -1 without setting any exception. This function can be called on any thread, be it a Python thread or some other system thread. If it is a Python thread, it doesn't matter if it holds the global interpreter lock or not. """ return -1
[ "def", "Py_AddPendingCall", "(", "space", ",", "func", ",", "arg", ")", ":", "return", "-", "1" ]
https://github.com/mesalock-linux/mesapy/blob/ed546d59a21b36feb93e2309d5c6b75aa0ad95c9/pypy/module/cpyext/stubsactive.py#L13-L33
Qiskit/qiskit-terra
b66030e3b9192efdd3eb95cf25c6545fe0a13da4
qiskit/qobj/converters/pulse_instruction.py
python
QobjToInstructionConverter.bind_pulse
(self, pulse)
Bind the supplied pulse to a converter method by pulse name. Args: pulse (PulseLibraryItem): Pulse to bind
Bind the supplied pulse to a converter method by pulse name.
[ "Bind", "the", "supplied", "pulse", "to", "a", "converter", "method", "by", "pulse", "name", "." ]
def bind_pulse(self, pulse): """Bind the supplied pulse to a converter method by pulse name. Args: pulse (PulseLibraryItem): Pulse to bind """ pulse = library.Waveform(pulse.samples, pulse.name) @self.bind_name(pulse.name) def convert_named_drive(self, instruction): """Return converted `Play`. Args: instruction (PulseQobjInstruction): pulse qobj Returns: Schedule: Converted and scheduled pulse """ t0 = instruction.t0 channel = self.get_channel(instruction.ch) return instructions.Play(pulse, channel) << t0
[ "def", "bind_pulse", "(", "self", ",", "pulse", ")", ":", "pulse", "=", "library", ".", "Waveform", "(", "pulse", ".", "samples", ",", "pulse", ".", "name", ")", "@", "self", ".", "bind_name", "(", "pulse", ".", "name", ")", "def", "convert_named_drive...
https://github.com/Qiskit/qiskit-terra/blob/b66030e3b9192efdd3eb95cf25c6545fe0a13da4/qiskit/qobj/converters/pulse_instruction.py#L634-L653
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/lib/python2.7/site-packages/pip/_vendor/pyparsing.py
python
MatchFirst.__init__
( self, exprs, savelist = False )
[]
def __init__( self, exprs, savelist = False ): super(MatchFirst,self).__init__(exprs, savelist) if self.exprs: self.mayReturnEmpty = any(e.mayReturnEmpty for e in self.exprs) else: self.mayReturnEmpty = True
[ "def", "__init__", "(", "self", ",", "exprs", ",", "savelist", "=", "False", ")", ":", "super", "(", "MatchFirst", ",", "self", ")", ".", "__init__", "(", "exprs", ",", "savelist", ")", "if", "self", ".", "exprs", ":", "self", ".", "mayReturnEmpty", ...
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/lib/python2.7/site-packages/pip/_vendor/pyparsing.py#L3518-L3523
mayank93/Twitter-Sentiment-Analysis
f095c6ca6bf69787582b5dabb140fefaf278eb37
front-end/web2py/gluon/dal.py
python
BaseAdapter.file_close
(self, fileobj)
to be used ONLY for files that on GAE may not be on filesystem
to be used ONLY for files that on GAE may not be on filesystem
[ "to", "be", "used", "ONLY", "for", "files", "that", "on", "GAE", "may", "not", "be", "on", "filesystem" ]
def file_close(self, fileobj): """ to be used ONLY for files that on GAE may not be on filesystem """ if fileobj: fileobj.close()
[ "def", "file_close", "(", "self", ",", "fileobj", ")", ":", "if", "fileobj", ":", "fileobj", ".", "close", "(", ")" ]
https://github.com/mayank93/Twitter-Sentiment-Analysis/blob/f095c6ca6bf69787582b5dabb140fefaf278eb37/front-end/web2py/gluon/dal.py#L650-L655
ClusterHQ/powerstrip
b18dc7261b001720149849b8ed8f2a31880d76c1
powerstrip/powerstrip.py
python
DockerProxyClient.handleHeader
(self, key, value)
return proxy.ProxyClient.handleHeader(self, key, value)
[]
def handleHeader(self, key, value): if (key.lower() == "content-type" and value == "application/vnd.docker.raw-stream"): self._handleRawStream() return proxy.ProxyClient.handleHeader(self, key, value)
[ "def", "handleHeader", "(", "self", ",", "key", ",", "value", ")", ":", "if", "(", "key", ".", "lower", "(", ")", "==", "\"content-type\"", "and", "value", "==", "\"application/vnd.docker.raw-stream\"", ")", ":", "self", ".", "_handleRawStream", "(", ")", ...
https://github.com/ClusterHQ/powerstrip/blob/b18dc7261b001720149849b8ed8f2a31880d76c1/powerstrip/powerstrip.py#L86-L90
angr/angr
4b04d56ace135018083d36d9083805be8146688b
angr/analyses/variable_recovery/engine_vex.py
python
SimEngineVRVEX._handle_Load
(self, expr: pyvex.IRExpr.Load)
return self._load(addr, size)
[]
def _handle_Load(self, expr: pyvex.IRExpr.Load) -> RichR: addr = self._expr(expr.addr) size = expr.result_size(self.tyenv) // 8 return self._load(addr, size)
[ "def", "_handle_Load", "(", "self", ",", "expr", ":", "pyvex", ".", "IRExpr", ".", "Load", ")", "->", "RichR", ":", "addr", "=", "self", ".", "_expr", "(", "expr", ".", "addr", ")", "size", "=", "expr", ".", "result_size", "(", "self", ".", "tyenv"...
https://github.com/angr/angr/blob/4b04d56ace135018083d36d9083805be8146688b/angr/analyses/variable_recovery/engine_vex.py#L107-L111
davidbau/ganseeing
93cea2c8f391aef001ddf9dcb35c43990681a47c
seeing/upsegmodel/resnet.py
python
conv3x3
(in_planes, out_planes, stride=1)
return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=1, bias=False)
3x3 convolution with padding
3x3 convolution with padding
[ "3x3", "convolution", "with", "padding" ]
def conv3x3(in_planes, out_planes, stride=1): "3x3 convolution with padding" return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=1, bias=False)
[ "def", "conv3x3", "(", "in_planes", ",", "out_planes", ",", "stride", "=", "1", ")", ":", "return", "nn", ".", "Conv2d", "(", "in_planes", ",", "out_planes", ",", "kernel_size", "=", "3", ",", "stride", "=", "stride", ",", "padding", "=", "1", ",", "...
https://github.com/davidbau/ganseeing/blob/93cea2c8f391aef001ddf9dcb35c43990681a47c/seeing/upsegmodel/resnet.py#L26-L29
igraph/python-igraph
e9f83e8af08f24ea025596e745917197d8b44d94
src/igraph/cut.py
python
Flow.flow
(self)
return self._flow
Returns the flow values for each edge. For directed graphs, this is simply a list where element M{i} corresponds to the flow on edge M{i}. For undirected graphs, the direction of the flow is not constrained (since the edges are undirected), hence positive flow always means a flow from the smaller vertex ID to the larger, while negative flow means a flow from the larger vertex ID to the smaller.
Returns the flow values for each edge.
[ "Returns", "the", "flow", "values", "for", "each", "edge", "." ]
def flow(self): """Returns the flow values for each edge. For directed graphs, this is simply a list where element M{i} corresponds to the flow on edge M{i}. For undirected graphs, the direction of the flow is not constrained (since the edges are undirected), hence positive flow always means a flow from the smaller vertex ID to the larger, while negative flow means a flow from the larger vertex ID to the smaller. """ return self._flow
[ "def", "flow", "(", "self", ")", ":", "return", "self", ".", "_flow" ]
https://github.com/igraph/python-igraph/blob/e9f83e8af08f24ea025596e745917197d8b44d94/src/igraph/cut.py#L179-L189
deepfakes/faceswap
09c7d8aca3c608d1afad941ea78e9fd9b64d9219
plugins/convert/color/_base.py
python
Adjustment.set_config
(self, configfile, config)
return retval
Set the config to either global config or passed in config
Set the config to either global config or passed in config
[ "Set", "the", "config", "to", "either", "global", "config", "or", "passed", "in", "config" ]
def set_config(self, configfile, config): """ Set the config to either global config or passed in config """ section = ".".join(self.__module__.split(".")[-2:]) if config is None: retval = get_config(section, configfile) else: config.section = section retval = config.config_dict config.section = None logger.debug("Config: %s", retval) return retval
[ "def", "set_config", "(", "self", ",", "configfile", ",", "config", ")", ":", "section", "=", "\".\"", ".", "join", "(", "self", ".", "__module__", ".", "split", "(", "\".\"", ")", "[", "-", "2", ":", "]", ")", "if", "config", "is", "None", ":", ...
https://github.com/deepfakes/faceswap/blob/09c7d8aca3c608d1afad941ea78e9fd9b64d9219/plugins/convert/color/_base.py#L26-L36
achael/eht-imaging
bbd3aeb06bef52bf89fa1c06de71e5509a5b0015
ehtim/caltable.py
python
Caltable.copy
(self)
return new_caltable
Copy the observation object. Args: Returns: (Caltable): a copy of the Caltable object.
Copy the observation object.
[ "Copy", "the", "observation", "object", "." ]
def copy(self): """Copy the observation object. Args: Returns: (Caltable): a copy of the Caltable object. """ new_caltable = Caltable(self.ra, self.dec, self.rf, self.bw, self.data, self.tarr, source=self.source, mjd=self.mjd, timetype=self.timetype) return new_caltable
[ "def", "copy", "(", "self", ")", ":", "new_caltable", "=", "Caltable", "(", "self", ".", "ra", ",", "self", ".", "dec", ",", "self", ".", "rf", ",", "self", ".", "bw", ",", "self", ".", "data", ",", "self", ".", "tarr", ",", "source", "=", "sel...
https://github.com/achael/eht-imaging/blob/bbd3aeb06bef52bf89fa1c06de71e5509a5b0015/ehtim/caltable.py#L103-L113
IronLanguages/ironpython3
7a7bb2a872eeab0d1009fc8a6e24dca43f65b693
Src/StdLib/Lib/fileinput.py
python
hook_compressed
(filename, mode)
[]
def hook_compressed(filename, mode): ext = os.path.splitext(filename)[1] if ext == '.gz': import gzip return gzip.open(filename, mode) elif ext == '.bz2': import bz2 return bz2.BZ2File(filename, mode) else: return open(filename, mode)
[ "def", "hook_compressed", "(", "filename", ",", "mode", ")", ":", "ext", "=", "os", ".", "path", ".", "splitext", "(", "filename", ")", "[", "1", "]", "if", "ext", "==", "'.gz'", ":", "import", "gzip", "return", "gzip", ".", "open", "(", "filename", ...
https://github.com/IronLanguages/ironpython3/blob/7a7bb2a872eeab0d1009fc8a6e24dca43f65b693/Src/StdLib/Lib/fileinput.py#L402-L411
JetBrains/colorSchemeTool
5536207cf92f66509318e8fc51dacc2b5a80cac7
colorSchemeTool.py
python
capitalize_colors
(elem)
[]
def capitalize_colors(elem): if len(elem): for elem in elem: if elem.get("value") is not None: elem.set("value", elem.get("value").upper()) capitalize_colors(elem)
[ "def", "capitalize_colors", "(", "elem", ")", ":", "if", "len", "(", "elem", ")", ":", "for", "elem", "in", "elem", ":", "if", "elem", ".", "get", "(", "\"value\"", ")", "is", "not", "None", ":", "elem", ".", "set", "(", "\"value\"", ",", "elem", ...
https://github.com/JetBrains/colorSchemeTool/blob/5536207cf92f66509318e8fc51dacc2b5a80cac7/colorSchemeTool.py#L31-L36
IronLanguages/main
a949455434b1fda8c783289e897e78a9a0caabb5
External.LCA_RESTRICTED/Languages/IronPython/repackage/pip/pip/_vendor/requests/adapters.py
python
HTTPAdapter.request_url
(self, request, proxies)
return url
Obtain the url to use when making the final request. If the message is being sent through a HTTP proxy, the full URL has to be used. Otherwise, we should only use the path portion of the URL. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`. :param request: The :class:`PreparedRequest <PreparedRequest>` being sent. :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs.
Obtain the url to use when making the final request.
[ "Obtain", "the", "url", "to", "use", "when", "making", "the", "final", "request", "." ]
def request_url(self, request, proxies): """Obtain the url to use when making the final request. If the message is being sent through a HTTP proxy, the full URL has to be used. Otherwise, we should only use the path portion of the URL. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`. :param request: The :class:`PreparedRequest <PreparedRequest>` being sent. :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs. """ proxy = select_proxy(request.url, proxies) scheme = urlparse(request.url).scheme if proxy and scheme != 'https': url = urldefragauth(request.url) else: url = request.path_url return url
[ "def", "request_url", "(", "self", ",", "request", ",", "proxies", ")", ":", "proxy", "=", "select_proxy", "(", "request", ".", "url", ",", "proxies", ")", "scheme", "=", "urlparse", "(", "request", ".", "url", ")", ".", "scheme", "if", "proxy", "and",...
https://github.com/IronLanguages/main/blob/a949455434b1fda8c783289e897e78a9a0caabb5/External.LCA_RESTRICTED/Languages/IronPython/repackage/pip/pip/_vendor/requests/adapters.py#L272-L292
entropy1337/infernal-twin
10995cd03312e39a48ade0f114ebb0ae3a711bb8
Modules/build/pillow/build/lib.linux-i686-2.7/PIL/IcoImagePlugin.py
python
IcoFile.frame
(self, idx)
return im
Get an image from frame idx
Get an image from frame idx
[ "Get", "an", "image", "from", "frame", "idx" ]
def frame(self, idx): """ Get an image from frame idx """ header = self.entry[idx] self.buf.seek(header['offset']) data = self.buf.read(8) self.buf.seek(header['offset']) if data[:8] == PngImagePlugin._MAGIC: # png frame im = PngImagePlugin.PngImageFile(self.buf) else: # XOR + AND mask bmp frame im = BmpImagePlugin.DibImageFile(self.buf) # change tile dimension to only encompass XOR image im.size = (im.size[0], int(im.size[1] / 2)) d, e, o, a = im.tile[0] im.tile[0] = d, (0, 0) + im.size, o, a # figure out where AND mask image starts mode = a[0] bpp = 8 for k in BmpImagePlugin.BIT2MODE.keys(): if mode == BmpImagePlugin.BIT2MODE[k][1]: bpp = k break if 32 == bpp: # 32-bit color depth icon image allows semitransparent areas # PIL's DIB format ignores transparency bits, recover them. # The DIB is packed in BGRX byte order where X is the alpha # channel. # Back up to start of bmp data self.buf.seek(o) # extract every 4th byte (eg. 3,7,11,15,...) alpha_bytes = self.buf.read(im.size[0] * im.size[1] * 4)[3::4] # convert to an 8bpp grayscale image mask = Image.frombuffer( 'L', # 8bpp im.size, # (w, h) alpha_bytes, # source chars 'raw', # raw decoder ('L', 0, -1) # 8bpp inverted, unpadded, reversed ) else: # get AND image from end of bitmap w = im.size[0] if (w % 32) > 0: # bitmap row data is aligned to word boundaries w += 32 - (im.size[0] % 32) # the total mask data is # padded row size * height / bits per char and_mask_offset = o + int(im.size[0] * im.size[1] * (bpp / 8.0)) total_bytes = int((w * im.size[1]) / 8) self.buf.seek(and_mask_offset) maskData = self.buf.read(total_bytes) # convert raw data to image mask = Image.frombuffer( '1', # 1 bpp im.size, # (w, h) maskData, # source chars 'raw', # raw decoder ('1;I', int(w/8), -1) # 1bpp inverted, padded, reversed ) # now we have two images, im is XOR image and mask is AND image # apply mask image as alpha channel im = im.convert('RGBA') im.putalpha(mask) return im
[ "def", "frame", "(", "self", ",", "idx", ")", ":", "header", "=", "self", ".", "entry", "[", "idx", "]", "self", ".", "buf", ".", "seek", "(", "header", "[", "'offset'", "]", ")", "data", "=", "self", ".", "buf", ".", "read", "(", "8", ")", "...
https://github.com/entropy1337/infernal-twin/blob/10995cd03312e39a48ade0f114ebb0ae3a711bb8/Modules/build/pillow/build/lib.linux-i686-2.7/PIL/IcoImagePlugin.py#L153-L235
edfungus/Crouton
ada98b3930192938a48909072b45cb84b945f875
clients/esp8266_clients/venv/lib/python2.7/site-packages/paho/mqtt/client.py
python
Client.loop_forever
(self, timeout=1.0, max_packets=1, retry_first_connection=False)
return rc
This function call loop() for you in an infinite blocking loop. It is useful for the case where you only want to run the MQTT client loop in your program. loop_forever() will handle reconnecting for you. If you call disconnect() in a callback it will return. timeout: The time in seconds to wait for incoming/outgoing network traffic before timing out and returning. max_packets: Not currently used. retry_first_connection: Should the first connection attempt be retried on failure. Raises socket.error on first connection failures unless retry_first_connection=True
This function call loop() for you in an infinite blocking loop. It is useful for the case where you only want to run the MQTT client loop in your program.
[ "This", "function", "call", "loop", "()", "for", "you", "in", "an", "infinite", "blocking", "loop", ".", "It", "is", "useful", "for", "the", "case", "where", "you", "only", "want", "to", "run", "the", "MQTT", "client", "loop", "in", "your", "program", ...
def loop_forever(self, timeout=1.0, max_packets=1, retry_first_connection=False): """This function call loop() for you in an infinite blocking loop. It is useful for the case where you only want to run the MQTT client loop in your program. loop_forever() will handle reconnecting for you. If you call disconnect() in a callback it will return. timeout: The time in seconds to wait for incoming/outgoing network traffic before timing out and returning. max_packets: Not currently used. retry_first_connection: Should the first connection attempt be retried on failure. Raises socket.error on first connection failures unless retry_first_connection=True """ run = True while run: if self._state == mqtt_cs_connect_async: try: self.reconnect() except socket.error: if not retry_first_connection: raise self._easy_log(MQTT_LOG_DEBUG, "Connection failed, retrying") time.sleep(1) else: break while run: rc = MQTT_ERR_SUCCESS while rc == MQTT_ERR_SUCCESS: rc = self.loop(timeout, max_packets) # We don't need to worry about locking here, because we've # either called loop_forever() when in single threaded mode, or # in multi threaded mode when loop_stop() has been called and # so no other threads can access _current_out_packet, # _out_packet or _messages. if (self._thread_terminate is True and self._current_out_packet is None and len(self._out_packet) == 0 and len(self._out_messages) == 0): rc = 1 run = False self._state_mutex.acquire() if self._state == mqtt_cs_disconnecting or run is False or self._thread_terminate is True: run = False self._state_mutex.release() else: self._state_mutex.release() time.sleep(1) self._state_mutex.acquire() if self._state == mqtt_cs_disconnecting or run is False or self._thread_terminate is True: run = False self._state_mutex.release() else: self._state_mutex.release() try: self.reconnect() except socket.error as err: pass return rc
[ "def", "loop_forever", "(", "self", ",", "timeout", "=", "1.0", ",", "max_packets", "=", "1", ",", "retry_first_connection", "=", "False", ")", ":", "run", "=", "True", "while", "run", ":", "if", "self", ".", "_state", "==", "mqtt_cs_connect_async", ":", ...
https://github.com/edfungus/Crouton/blob/ada98b3930192938a48909072b45cb84b945f875/clients/esp8266_clients/venv/lib/python2.7/site-packages/paho/mqtt/client.py#L1227-L1294
django-oscar/django-oscar
ffcc530844d40283b6b1552778a140536b904f5f
src/oscar/apps/shipping/repository.py
python
Repository.get_available_shipping_methods
( self, basket, shipping_addr=None, **kwargs)
return self.methods
Return a list of all applicable shipping method instances for a given basket, address etc. This method is intended to be overridden.
Return a list of all applicable shipping method instances for a given basket, address etc. This method is intended to be overridden.
[ "Return", "a", "list", "of", "all", "applicable", "shipping", "method", "instances", "for", "a", "given", "basket", "address", "etc", ".", "This", "method", "is", "intended", "to", "be", "overridden", "." ]
def get_available_shipping_methods( self, basket, shipping_addr=None, **kwargs): """ Return a list of all applicable shipping method instances for a given basket, address etc. This method is intended to be overridden. """ return self.methods
[ "def", "get_available_shipping_methods", "(", "self", ",", "basket", ",", "shipping_addr", "=", "None", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "methods" ]
https://github.com/django-oscar/django-oscar/blob/ffcc530844d40283b6b1552778a140536b904f5f/src/oscar/apps/shipping/repository.py#L60-L66
pfnet-research/xfeat
b199c3cdacef408b3d2b1d920b22c243cfe0667c
xfeat/cat_encoder/_basic_encoder.py
python
LabelEncoder.transform
(self, input_df: XDataFrame)
return new_df
Transform data frame. Args: input_df (XDataFrame): Input data frame. Returns: XDataFrame : Output data frame.
Transform data frame.
[ "Transform", "data", "frame", "." ]
def transform(self, input_df: XDataFrame) -> XDataFrame: """Transform data frame. Args: input_df (XDataFrame): Input data frame. Returns: XDataFrame : Output data frame. """ new_df = input_df.copy() input_cols = self._input_cols if not input_cols: input_cols = new_df.columns.tolist() if self._exclude_cols: for col in self._exclude_cols: input_cols.remove(col) for col in input_cols: out_col = self._output_prefix + col + self._output_suffix if cudf_is_available() and isinstance(new_df, cudf.DataFrame): X = self._uniques[col].get_indexer(new_df[col].to_array()) else: X = self._uniques[col].get_indexer(new_df[col]) if self._unseen == "n_unique": missing_values = new_df[col].isna() unseen_values = np.invert(new_df[col].isin(self._uniques[col])) unseen_mask = np.bitwise_xor(missing_values, unseen_values) X[unseen_mask] = len(self._uniques[col]) new_df[out_col] = X return new_df
[ "def", "transform", "(", "self", ",", "input_df", ":", "XDataFrame", ")", "->", "XDataFrame", ":", "new_df", "=", "input_df", ".", "copy", "(", ")", "input_cols", "=", "self", ".", "_input_cols", "if", "not", "input_cols", ":", "input_cols", "=", "new_df",...
https://github.com/pfnet-research/xfeat/blob/b199c3cdacef408b3d2b1d920b22c243cfe0667c/xfeat/cat_encoder/_basic_encoder.py#L112-L144