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
jorgebastida/gordon
4c1cd0c4dea2499d98115672095714592f80f7aa
examples/apigateway/helloworld/hellopy.py
python
handler
(event, context)
return "Hello from python!"
[]
def handler(event, context): return "Hello from python!"
[ "def", "handler", "(", "event", ",", "context", ")", ":", "return", "\"Hello from python!\"" ]
https://github.com/jorgebastida/gordon/blob/4c1cd0c4dea2499d98115672095714592f80f7aa/examples/apigateway/helloworld/hellopy.py#L4-L5
Source-Python-Dev-Team/Source.Python
d0ffd8ccbd1e9923c9bc44936f20613c1c76b7fb
addons/source-python/Python3/datetime.py
python
_ord2ymd
(n)
return year, month, n+1
ordinal -> (year, month, day), considering 01-Jan-0001 as day 1.
ordinal -> (year, month, day), considering 01-Jan-0001 as day 1.
[ "ordinal", "-", ">", "(", "year", "month", "day", ")", "considering", "01", "-", "Jan", "-", "0001", "as", "day", "1", "." ]
def _ord2ymd(n): "ordinal -> (year, month, day), considering 01-Jan-0001 as day 1." # n is a 1-based index, starting at 1-Jan-1. The pattern of leap years # repeats exactly every 400 years. The basic strategy is to find the # closest 400-year boundary at or before n, then work with the offset # from that boundary to n. Life is much clearer if we subtract 1 from # n first -- then the values of n at 400-year boundaries are exactly # those divisible by _DI400Y: # # D M Y n n-1 # -- --- ---- ---------- ---------------- # 31 Dec -400 -_DI400Y -_DI400Y -1 # 1 Jan -399 -_DI400Y +1 -_DI400Y 400-year boundary # ... # 30 Dec 000 -1 -2 # 31 Dec 000 0 -1 # 1 Jan 001 1 0 400-year boundary # 2 Jan 001 2 1 # 3 Jan 001 3 2 # ... # 31 Dec 400 _DI400Y _DI400Y -1 # 1 Jan 401 _DI400Y +1 _DI400Y 400-year boundary n -= 1 n400, n = divmod(n, _DI400Y) year = n400 * 400 + 1 # ..., -399, 1, 401, ... # Now n is the (non-negative) offset, in days, from January 1 of year, to # the desired date. Now compute how many 100-year cycles precede n. # Note that it's possible for n100 to equal 4! In that case 4 full # 100-year cycles precede the desired day, which implies the desired # day is December 31 at the end of a 400-year cycle. n100, n = divmod(n, _DI100Y) # Now compute how many 4-year cycles precede it. n4, n = divmod(n, _DI4Y) # And now how many single years. Again n1 can be 4, and again meaning # that the desired day is December 31 at the end of the 4-year cycle. n1, n = divmod(n, 365) year += n100 * 100 + n4 * 4 + n1 if n1 == 4 or n100 == 4: assert n == 0 return year-1, 12, 31 # Now the year is correct, and n is the offset from January 1. We find # the month via an estimate that's either exact or one too large. leapyear = n1 == 3 and (n4 != 24 or n100 == 3) assert leapyear == _is_leap(year) month = (n + 50) >> 5 preceding = _DAYS_BEFORE_MONTH[month] + (month > 2 and leapyear) if preceding > n: # estimate is too large month -= 1 preceding -= _DAYS_IN_MONTH[month] + (month == 2 and leapyear) n -= preceding assert 0 <= n < _days_in_month(year, month) # Now the year and month are correct, and n is the offset from the # start of that month: we're done! return year, month, n+1
[ "def", "_ord2ymd", "(", "n", ")", ":", "# n is a 1-based index, starting at 1-Jan-1. The pattern of leap years", "# repeats exactly every 400 years. The basic strategy is to find the", "# closest 400-year boundary at or before n, then work with the offset", "# from that boundary to n. Life is m...
https://github.com/Source-Python-Dev-Team/Source.Python/blob/d0ffd8ccbd1e9923c9bc44936f20613c1c76b7fb/addons/source-python/Python3/datetime.py#L82-L142
IronLanguages/ironpython3
7a7bb2a872eeab0d1009fc8a6e24dca43f65b693
Src/StdLib/Lib/ctypes/__init__.py
python
CFUNCTYPE
(restype, *argtypes, **kw)
CFUNCTYPE(restype, *argtypes, use_errno=False, use_last_error=False) -> function prototype. restype: the result type argtypes: a sequence specifying the argument types The function prototype can be called in different ways to create a callable object: prototype(integer address) -> foreign function prototype(callable) -> create and return a C callable function from callable prototype(integer index, method name[, paramflags]) -> foreign function calling a COM method prototype((ordinal number, dll object)[, paramflags]) -> foreign function exported by ordinal prototype((function name, dll object)[, paramflags]) -> foreign function exported by name
CFUNCTYPE(restype, *argtypes, use_errno=False, use_last_error=False) -> function prototype.
[ "CFUNCTYPE", "(", "restype", "*", "argtypes", "use_errno", "=", "False", "use_last_error", "=", "False", ")", "-", ">", "function", "prototype", "." ]
def CFUNCTYPE(restype, *argtypes, **kw): """CFUNCTYPE(restype, *argtypes, use_errno=False, use_last_error=False) -> function prototype. restype: the result type argtypes: a sequence specifying the argument types The function prototype can be called in different ways to create a callable object: prototype(integer address) -> foreign function prototype(callable) -> create and return a C callable function from callable prototype(integer index, method name[, paramflags]) -> foreign function calling a COM method prototype((ordinal number, dll object)[, paramflags]) -> foreign function exported by ordinal prototype((function name, dll object)[, paramflags]) -> foreign function exported by name """ flags = _FUNCFLAG_CDECL if kw.pop("use_errno", False): flags |= _FUNCFLAG_USE_ERRNO if kw.pop("use_last_error", False): flags |= _FUNCFLAG_USE_LASTERROR if kw: raise ValueError("unexpected keyword argument(s) %s" % kw.keys()) try: return _c_functype_cache[(restype, argtypes, flags)] except KeyError: class CFunctionType(_CFuncPtr): _argtypes_ = argtypes _restype_ = restype _flags_ = flags _c_functype_cache[(restype, argtypes, flags)] = CFunctionType return CFunctionType
[ "def", "CFUNCTYPE", "(", "restype", ",", "*", "argtypes", ",", "*", "*", "kw", ")", ":", "flags", "=", "_FUNCFLAG_CDECL", "if", "kw", ".", "pop", "(", "\"use_errno\"", ",", "False", ")", ":", "flags", "|=", "_FUNCFLAG_USE_ERRNO", "if", "kw", ".", "pop"...
https://github.com/IronLanguages/ironpython3/blob/7a7bb2a872eeab0d1009fc8a6e24dca43f65b693/Src/StdLib/Lib/ctypes/__init__.py#L73-L104
IJDykeman/wangTiles
7c1ee2095ebdf7f72bce07d94c6484915d5cae8b
experimental_code/tiles_3d/venv/lib/python2.7/site-packages/pip/util.py
python
is_installable_dir
(path)
return False
Return True if `path` is a directory containing a setup.py file.
Return True if `path` is a directory containing a setup.py file.
[ "Return", "True", "if", "path", "is", "a", "directory", "containing", "a", "setup", ".", "py", "file", "." ]
def is_installable_dir(path): """Return True if `path` is a directory containing a setup.py file.""" if not os.path.isdir(path): return False setup_py = os.path.join(path, 'setup.py') if os.path.isfile(setup_py): return True return False
[ "def", "is_installable_dir", "(", "path", ")", ":", "if", "not", "os", ".", "path", ".", "isdir", "(", "path", ")", ":", "return", "False", "setup_py", "=", "os", ".", "path", ".", "join", "(", "path", ",", "'setup.py'", ")", "if", "os", ".", "path...
https://github.com/IJDykeman/wangTiles/blob/7c1ee2095ebdf7f72bce07d94c6484915d5cae8b/experimental_code/tiles_3d/venv/lib/python2.7/site-packages/pip/util.py#L191-L198
hhursev/recipe-scrapers
478b9ddb0dda02b17b14f299eea729bef8131aa9
recipe_scrapers/sunbasket.py
python
SunBasket.title
(self)
return self.soup.find("h1").get_text()
[]
def title(self): return self.soup.find("h1").get_text()
[ "def", "title", "(", "self", ")", ":", "return", "self", ".", "soup", ".", "find", "(", "\"h1\"", ")", ".", "get_text", "(", ")" ]
https://github.com/hhursev/recipe-scrapers/blob/478b9ddb0dda02b17b14f299eea729bef8131aa9/recipe_scrapers/sunbasket.py#L12-L13
jfkirk/tensorrec
80690737ac039a5b41fc99e67372c4f67d8cfc51
tensorrec/tensorrec.py
python
TensorRec.__init__
(self, n_components=100, n_tastes=1, user_repr_graph=LinearRepresentationGraph(), item_repr_graph=LinearRepresentationGraph(), attention_graph=None, prediction_graph=DotProductPredictionGraph(), loss_graph=RMSELossGraph(), biased=True,)
A TensorRec recommendation model. :param n_components: Integer The dimension of a single output of the representation function. Must be >= 1. :param n_tastes: Integer The number of tastes/reprs to be calculated for each user. Must be >= 1. :param user_repr_graph: AbstractRepresentationGraph An object which inherits AbstractRepresentationGraph that contains a method to calculate user representations. See tensorrec.representation_graphs for examples. :param item_repr_graph: AbstractRepresentationGraph An object which inherits AbstractRepresentationGraph that contains a method to calculate item representations. See tensorrec.representation_graphs for examples. :param attention_graph: AbstractRepresentationGraph or None Optional. An object which inherits AbstractRepresentationGraph that contains a method to calculate user attention. Any valid repr_graph is also a valid attention graph. If None, no attention process will be applied. :param prediction_graph: AbstractPredictionGraph An object which inherits AbstractPredictionGraph that contains a method to calculate predictions from a pair of user/item reprs. See tensorrec.prediction_graphs for examples. :param loss_graph: AbstractLossGraph An object which inherits AbstractLossGraph that contains a method to calculate the loss function. See tensorrec.loss_graphs for examples. :param biased: bool If True, a bias value will be calculated for every user feature and item feature.
A TensorRec recommendation model. :param n_components: Integer The dimension of a single output of the representation function. Must be >= 1. :param n_tastes: Integer The number of tastes/reprs to be calculated for each user. Must be >= 1. :param user_repr_graph: AbstractRepresentationGraph An object which inherits AbstractRepresentationGraph that contains a method to calculate user representations. See tensorrec.representation_graphs for examples. :param item_repr_graph: AbstractRepresentationGraph An object which inherits AbstractRepresentationGraph that contains a method to calculate item representations. See tensorrec.representation_graphs for examples. :param attention_graph: AbstractRepresentationGraph or None Optional. An object which inherits AbstractRepresentationGraph that contains a method to calculate user attention. Any valid repr_graph is also a valid attention graph. If None, no attention process will be applied. :param prediction_graph: AbstractPredictionGraph An object which inherits AbstractPredictionGraph that contains a method to calculate predictions from a pair of user/item reprs. See tensorrec.prediction_graphs for examples. :param loss_graph: AbstractLossGraph An object which inherits AbstractLossGraph that contains a method to calculate the loss function. See tensorrec.loss_graphs for examples. :param biased: bool If True, a bias value will be calculated for every user feature and item feature.
[ "A", "TensorRec", "recommendation", "model", ".", ":", "param", "n_components", ":", "Integer", "The", "dimension", "of", "a", "single", "output", "of", "the", "representation", "function", ".", "Must", "be", ">", "=", "1", ".", ":", "param", "n_tastes", "...
def __init__(self, n_components=100, n_tastes=1, user_repr_graph=LinearRepresentationGraph(), item_repr_graph=LinearRepresentationGraph(), attention_graph=None, prediction_graph=DotProductPredictionGraph(), loss_graph=RMSELossGraph(), biased=True,): """ A TensorRec recommendation model. :param n_components: Integer The dimension of a single output of the representation function. Must be >= 1. :param n_tastes: Integer The number of tastes/reprs to be calculated for each user. Must be >= 1. :param user_repr_graph: AbstractRepresentationGraph An object which inherits AbstractRepresentationGraph that contains a method to calculate user representations. See tensorrec.representation_graphs for examples. :param item_repr_graph: AbstractRepresentationGraph An object which inherits AbstractRepresentationGraph that contains a method to calculate item representations. See tensorrec.representation_graphs for examples. :param attention_graph: AbstractRepresentationGraph or None Optional. An object which inherits AbstractRepresentationGraph that contains a method to calculate user attention. Any valid repr_graph is also a valid attention graph. If None, no attention process will be applied. :param prediction_graph: AbstractPredictionGraph An object which inherits AbstractPredictionGraph that contains a method to calculate predictions from a pair of user/item reprs. See tensorrec.prediction_graphs for examples. :param loss_graph: AbstractLossGraph An object which inherits AbstractLossGraph that contains a method to calculate the loss function. See tensorrec.loss_graphs for examples. :param biased: bool If True, a bias value will be calculated for every user feature and item feature. """ # Check TensorFlow version major, minor, patch = tf.__version__.split(".") if int(major) < 1 or int(major) == 1 and int(minor) < 7: raise TfVersionException(tf_version=tf.__version__) # Arg Check if (n_components is None) or (n_tastes is None) or (user_repr_graph is None) or (item_repr_graph is None) \ or (prediction_graph is None) or (loss_graph is None): raise ValueError("All arguments to TensorRec() must be non-None") if n_components < 1: raise ValueError("n_components must be >= 1") if n_tastes < 1: raise ValueError("n_tastes must be >= 1") if not isinstance(user_repr_graph, AbstractRepresentationGraph): raise ValueError("user_repr_graph must inherit AbstractRepresentationGraph") if not isinstance(item_repr_graph, AbstractRepresentationGraph): raise ValueError("item_repr_graph must inherit AbstractRepresentationGraph") if not isinstance(prediction_graph, AbstractPredictionGraph): raise ValueError("prediction_graph must inherit AbstractPredictionGraph") if not isinstance(loss_graph, AbstractLossGraph): raise ValueError("loss_graph must inherit AbstractLossGraph") if attention_graph is not None: if not isinstance(attention_graph, AbstractRepresentationGraph): raise ValueError("attention_graph must be None or inherit AbstractRepresentationGraph") if n_tastes == 1: raise ValueError("attention_graph must be None if n_tastes == 1") self.n_components = n_components self.n_tastes = n_tastes self.user_repr_graph_factory = user_repr_graph self.item_repr_graph_factory = item_repr_graph self.attention_graph_factory = attention_graph self.prediction_graph_factory = prediction_graph self.loss_graph_factory = loss_graph self.biased = biased # A list of the attr names of every graph hook attr self.graph_tensor_hook_attr_names = [ # Top-level API nodes 'tf_user_representation', 'tf_item_representation', 'tf_prediction_serial', 'tf_prediction', 'tf_rankings', 'tf_predict_similar_items', 'tf_rank_similar_items', # Training nodes 'tf_basic_loss', 'tf_weight_reg_loss', 'tf_loss', # Feed placeholders 'tf_learning_rate', 'tf_alpha', 'tf_sample_indices', 'tf_n_sampled_items', 'tf_similar_items_ids', ] if self.biased: self.graph_tensor_hook_attr_names += ['tf_projected_user_biases', 'tf_projected_item_biases'] if self.attention_graph_factory is not None: self.graph_tensor_hook_attr_names += ['tf_user_attention_representation'] self.graph_operation_hook_attr_names = [ # AdamOptimizer 'tf_optimizer', ] self.graph_iterator_hook_attr_names = [ # Input data iterators 'tf_user_feature_iterator', 'tf_item_feature_iterator', 'tf_interaction_iterator', ] # Calling the break routine during __init__ creates all the attrs on the TensorRec object with an initial value # of None self._break_graph_hooks() # A map of every graph hook attr name to the node name after construction # Tensors and operations are stored separated because they are handled differently by TensorFlow self.graph_tensor_hook_node_names = {} self.graph_operation_hook_node_names = {} self.graph_iterator_hook_node_names = {}
[ "def", "__init__", "(", "self", ",", "n_components", "=", "100", ",", "n_tastes", "=", "1", ",", "user_repr_graph", "=", "LinearRepresentationGraph", "(", ")", ",", "item_repr_graph", "=", "LinearRepresentationGraph", "(", ")", ",", "attention_graph", "=", "None...
https://github.com/jfkirk/tensorrec/blob/80690737ac039a5b41fc99e67372c4f67d8cfc51/tensorrec/tensorrec.py#L28-L134
eth-sri/eran
973e3b52d297d079d5402edec8f7922d824b8cc2
tf_verify/deepzono_nodes.py
python
DeepzonoConvbias.__init__
(self, image_shape, filters, bias, strides, pad_top, pad_left, pad_bottom, pad_right, input_names, output_name, output_shape)
Arguments --------- image_shape : numpy.ndarray of shape [height, width, channels] filters : numpy.ndarray the 4D array with the filter weights bias : numpy.ndarray array with the bias (has to have as many elements as the filter has out channels) strides : numpy.ndarray of shape [height, width] padding : str type of padding, either 'VALID' or 'SAME' input_names : iterable iterable with the name of the second addend output_name : str name of this node's output output_shape : iterable iterable of ints with the shape of the output of this node
Arguments --------- image_shape : numpy.ndarray of shape [height, width, channels] filters : numpy.ndarray the 4D array with the filter weights bias : numpy.ndarray array with the bias (has to have as many elements as the filter has out channels) strides : numpy.ndarray of shape [height, width] padding : str type of padding, either 'VALID' or 'SAME' input_names : iterable iterable with the name of the second addend output_name : str name of this node's output output_shape : iterable iterable of ints with the shape of the output of this node
[ "Arguments", "---------", "image_shape", ":", "numpy", ".", "ndarray", "of", "shape", "[", "height", "width", "channels", "]", "filters", ":", "numpy", ".", "ndarray", "the", "4D", "array", "with", "the", "filter", "weights", "bias", ":", "numpy", ".", "nd...
def __init__(self, image_shape, filters, bias, strides, pad_top, pad_left, pad_bottom, pad_right, input_names, output_name, output_shape): """ Arguments --------- image_shape : numpy.ndarray of shape [height, width, channels] filters : numpy.ndarray the 4D array with the filter weights bias : numpy.ndarray array with the bias (has to have as many elements as the filter has out channels) strides : numpy.ndarray of shape [height, width] padding : str type of padding, either 'VALID' or 'SAME' input_names : iterable iterable with the name of the second addend output_name : str name of this node's output output_shape : iterable iterable of ints with the shape of the output of this node """ DeepzonoConv.__init__(self, image_shape, filters, strides, pad_top, pad_left, pad_bottom, pad_right, input_names, output_name, output_shape) self.bias = np.ascontiguousarray(bias, dtype=np.double)
[ "def", "__init__", "(", "self", ",", "image_shape", ",", "filters", ",", "bias", ",", "strides", ",", "pad_top", ",", "pad_left", ",", "pad_bottom", ",", "pad_right", ",", "input_names", ",", "output_name", ",", "output_shape", ")", ":", "DeepzonoConv", ".",...
https://github.com/eth-sri/eran/blob/973e3b52d297d079d5402edec8f7922d824b8cc2/tf_verify/deepzono_nodes.py#L587-L609
naparuba/shinken
8163d645e801fa43ee1704f099a4684f120e667b
shinken/objects/service.py
python
Services.explode_services_duplicates
(self, hosts, s)
Explodes services holding a `duplicate_foreach` clause. :param hosts: The hosts container :param s: The service to explode :type s: Service
Explodes services holding a `duplicate_foreach` clause.
[ "Explodes", "services", "holding", "a", "duplicate_foreach", "clause", "." ]
def explode_services_duplicates(self, hosts, s): """ Explodes services holding a `duplicate_foreach` clause. :param hosts: The hosts container :param s: The service to explode :type s: Service """ hname = getattr(s, "host_name", None) if hname is None: return # the generator case, we must create several new services # we must find our host, and get all key:value we need h = hosts.find_by_name(hname.strip()) if h is None: err = 'Error: The hostname %s is unknown for the ' \ 'service %s!' % (hname, s.get_name()) s.configuration_errors.append(err) return # Duplicate services for new_s in s.duplicate(h): if h.is_excluded_for(new_s): continue # Adds concrete instance self.add_item(new_s)
[ "def", "explode_services_duplicates", "(", "self", ",", "hosts", ",", "s", ")", ":", "hname", "=", "getattr", "(", "s", ",", "\"host_name\"", ",", "None", ")", "if", "hname", "is", "None", ":", "return", "# the generator case, we must create several new services",...
https://github.com/naparuba/shinken/blob/8163d645e801fa43ee1704f099a4684f120e667b/shinken/objects/service.py#L1735-L1762
CLUEbenchmark/CLUEPretrainedModels
b384fd41665a8261f9c689c940cf750b3bc21fce
create_pretraining_data.py
python
create_masked_lm_predictions
(tokens, masked_lm_prob, max_predictions_per_seq, vocab_words, rng)
return (output_tokens, masked_lm_positions, masked_lm_labels)
Creates the predictions for the masked LM objective.
Creates the predictions for the masked LM objective.
[ "Creates", "the", "predictions", "for", "the", "masked", "LM", "objective", "." ]
def create_masked_lm_predictions(tokens, masked_lm_prob, max_predictions_per_seq, vocab_words, rng): """Creates the predictions for the masked LM objective.""" cand_indexes = [] for (i, token) in enumerate(tokens): if token == "[CLS]" or token == "[SEP]": continue # Whole Word Masking means that if we mask all of the wordpieces # corresponding to an original word. When a word has been split into # WordPieces, the first token does not have any marker and any subsequence # tokens are prefixed with ##. So whenever we see the ## token, we # append it to the previous set of word indexes. # # Note that Whole Word Masking does *not* change the training code # at all -- we still predict each WordPiece independently, softmaxed # over the entire vocabulary. if (FLAGS.do_whole_word_mask and len(cand_indexes) >= 1 and token.startswith("##")): cand_indexes[-1].append(i) else: cand_indexes.append([i]) rng.shuffle(cand_indexes) output_tokens = list(tokens) num_to_predict = min(max_predictions_per_seq, max(1, int(round(len(tokens) * masked_lm_prob)))) masked_lms = [] covered_indexes = set() for index_set in cand_indexes: if len(masked_lms) >= num_to_predict: break # If adding a whole-word mask would exceed the maximum number of # predictions, then just skip this candidate. if len(masked_lms) + len(index_set) > num_to_predict: continue is_any_index_covered = False for index in index_set: if index in covered_indexes: is_any_index_covered = True break if is_any_index_covered: continue for index in index_set: covered_indexes.add(index) masked_token = None # 80% of the time, replace with [MASK] if rng.random() < 0.8: masked_token = "[MASK]" else: # 10% of the time, keep original if rng.random() < 0.5: masked_token = tokens[index] # 10% of the time, replace with random word else: masked_token = vocab_words[rng.randint(0, len(vocab_words) - 1)] output_tokens[index] = masked_token masked_lms.append(MaskedLmInstance(index=index, label=tokens[index])) assert len(masked_lms) <= num_to_predict masked_lms = sorted(masked_lms, key=lambda x: x.index) masked_lm_positions = [] masked_lm_labels = [] for p in masked_lms: masked_lm_positions.append(p.index) masked_lm_labels.append(p.label) return (output_tokens, masked_lm_positions, masked_lm_labels)
[ "def", "create_masked_lm_predictions", "(", "tokens", ",", "masked_lm_prob", ",", "max_predictions_per_seq", ",", "vocab_words", ",", "rng", ")", ":", "cand_indexes", "=", "[", "]", "for", "(", "i", ",", "token", ")", "in", "enumerate", "(", "tokens", ")", "...
https://github.com/CLUEbenchmark/CLUEPretrainedModels/blob/b384fd41665a8261f9c689c940cf750b3bc21fce/create_pretraining_data.py#L349-L422
Huangying-Zhan/DF-VO
6a2ec43fc6209d9058ae1709d779c5ada68a31f3
tools/evaluation/odometry/kitti_odometry.py
python
KittiEvalOdom.compute_RPE
(self, gt, pred)
return rpe_errors
Compute RPE Args: gt (dict): ground-truth poses as [4x4] array pred (dict): predicted poses as [4x4] array Returns: trans_errors (list): list of rpe translation error rot_errors (list): list of RPE rotation error
Compute RPE Args: gt (dict): ground-truth poses as [4x4] array pred (dict): predicted poses as [4x4] array Returns: trans_errors (list): list of rpe translation error rot_errors (list): list of RPE rotation error
[ "Compute", "RPE", "Args", ":", "gt", "(", "dict", ")", ":", "ground", "-", "truth", "poses", "as", "[", "4x4", "]", "array", "pred", "(", "dict", ")", ":", "predicted", "poses", "as", "[", "4x4", "]", "array", "Returns", ":", "trans_errors", "(", "...
def compute_RPE(self, gt, pred): """Compute RPE Args: gt (dict): ground-truth poses as [4x4] array pred (dict): predicted poses as [4x4] array Returns: trans_errors (list): list of rpe translation error rot_errors (list): list of RPE rotation error """ rpe_errors = {'trans': [], 'rot': []} pred_keys = list(pred.keys()) for cnt in range(len(pred_keys)-1): gt1 = gt[pred_keys[cnt]] gt2 = gt[pred_keys[cnt+1]] gt_rel = np.linalg.inv(gt1) @ gt2 pred1 = pred[pred_keys[cnt]] pred2 = pred[pred_keys[cnt+1]] pred_rel = np.linalg.inv(pred1) @ pred2 rel_err = np.linalg.inv(gt_rel) @ pred_rel rpe_errors['trans'].append(self.translation_error(rel_err)) rpe_errors['rot'].append(self.rotation_error(rel_err)) return rpe_errors
[ "def", "compute_RPE", "(", "self", ",", "gt", ",", "pred", ")", ":", "rpe_errors", "=", "{", "'trans'", ":", "[", "]", ",", "'rot'", ":", "[", "]", "}", "pred_keys", "=", "list", "(", "pred", ".", "keys", "(", ")", ")", "for", "cnt", "in", "ran...
https://github.com/Huangying-Zhan/DF-VO/blob/6a2ec43fc6209d9058ae1709d779c5ada68a31f3/tools/evaluation/odometry/kitti_odometry.py#L467-L492
GoogleCloudPlatform/cloudml-samples
efddc4a9898127e55edc0946557aca4bfaf59705
sklearn/sklearn-template/template/trainer/task.py
python
run_experiment
(flags)
Testbed for running model training and evaluation.
Testbed for running model training and evaluation.
[ "Testbed", "for", "running", "model", "training", "and", "evaluation", "." ]
def run_experiment(flags): """Testbed for running model training and evaluation.""" # Get data for training and evaluation dataset = utils.read_df_from_bigquery( flags.input, num_samples=flags.num_samples) # Get model estimator = model.get_estimator(flags) # Run training and evaluation _train_and_evaluate(estimator, dataset, flags.job_dir)
[ "def", "run_experiment", "(", "flags", ")", ":", "# Get data for training and evaluation", "dataset", "=", "utils", ".", "read_df_from_bigquery", "(", "flags", ".", "input", ",", "num_samples", "=", "flags", ".", "num_samples", ")", "# Get model", "estimator", "=", ...
https://github.com/GoogleCloudPlatform/cloudml-samples/blob/efddc4a9898127e55edc0946557aca4bfaf59705/sklearn/sklearn-template/template/trainer/task.py#L74-L85
agoragames/leaderboard-python
4bc028164c259c3a31c7e6ccb2a8ecb83cfb1da2
leaderboard/leaderboard.py
python
Leaderboard.rank_member
(self, member, score, member_data=None)
Rank a member in the leaderboard. @param member [String] Member name. @param score [float] Member score. @param member_data [String] Optional member data.
Rank a member in the leaderboard.
[ "Rank", "a", "member", "in", "the", "leaderboard", "." ]
def rank_member(self, member, score, member_data=None): ''' Rank a member in the leaderboard. @param member [String] Member name. @param score [float] Member score. @param member_data [String] Optional member data. ''' self.rank_member_in(self.leaderboard_name, member, score, member_data)
[ "def", "rank_member", "(", "self", ",", "member", ",", "score", ",", "member_data", "=", "None", ")", ":", "self", ".", "rank_member_in", "(", "self", ".", "leaderboard_name", ",", "member", ",", "score", ",", "member_data", ")" ]
https://github.com/agoragames/leaderboard-python/blob/4bc028164c259c3a31c7e6ccb2a8ecb83cfb1da2/leaderboard/leaderboard.py#L117-L125
securesystemslab/zippy
ff0e84ac99442c2c55fe1d285332cfd4e185e089
zippy/lib-python/3/pydoc.py
python
TextDoc.docmodule
(self, object, name=None, mod=None)
return result
Produce text documentation for a given module object.
Produce text documentation for a given module object.
[ "Produce", "text", "documentation", "for", "a", "given", "module", "object", "." ]
def docmodule(self, object, name=None, mod=None): """Produce text documentation for a given module object.""" name = object.__name__ # ignore the passed-in name synop, desc = splitdoc(getdoc(object)) result = self.section('NAME', name + (synop and ' - ' + synop)) all = getattr(object, '__all__', None) docloc = self.getdocloc(object) if docloc is not None: result = result + self.section('MODULE REFERENCE', docloc + """ The following documentation is automatically generated from the Python source files. It may be incomplete, incorrect or include features that are considered implementation detail and may vary between Python implementations. When in doubt, consult the module reference at the location listed above. """) if desc: result = result + self.section('DESCRIPTION', desc) classes = [] for key, value in inspect.getmembers(object, inspect.isclass): # if __all__ exists, believe it. Otherwise use old heuristic. if (all is not None or (inspect.getmodule(value) or object) is object): if visiblename(key, all, object): classes.append((key, value)) funcs = [] for key, value in inspect.getmembers(object, inspect.isroutine): # if __all__ exists, believe it. Otherwise use old heuristic. if (all is not None or inspect.isbuiltin(value) or inspect.getmodule(value) is object): if visiblename(key, all, object): funcs.append((key, value)) data = [] for key, value in inspect.getmembers(object, isdata): if visiblename(key, all, object): data.append((key, value)) modpkgs = [] modpkgs_names = set() if hasattr(object, '__path__'): for importer, modname, ispkg in pkgutil.iter_modules(object.__path__): modpkgs_names.add(modname) if ispkg: modpkgs.append(modname + ' (package)') else: modpkgs.append(modname) modpkgs.sort() result = result + self.section( 'PACKAGE CONTENTS', '\n'.join(modpkgs)) # Detect submodules as sometimes created by C extensions submodules = [] for key, value in inspect.getmembers(object, inspect.ismodule): if value.__name__.startswith(name + '.') and key not in modpkgs_names: submodules.append(key) if submodules: submodules.sort() result = result + self.section( 'SUBMODULES', '\n'.join(submodules)) if classes: classlist = [value for key, value in classes] contents = [self.formattree( inspect.getclasstree(classlist, 1), name)] for key, value in classes: contents.append(self.document(value, key, name)) result = result + self.section('CLASSES', '\n'.join(contents)) if funcs: contents = [] for key, value in funcs: contents.append(self.document(value, key, name)) result = result + self.section('FUNCTIONS', '\n'.join(contents)) if data: contents = [] for key, value in data: contents.append(self.docother(value, key, name, maxlen=70)) result = result + self.section('DATA', '\n'.join(contents)) if hasattr(object, '__version__'): version = str(object.__version__) if version[:11] == '$' + 'Revision: ' and version[-1:] == '$': version = version[11:-1].strip() result = result + self.section('VERSION', version) if hasattr(object, '__date__'): result = result + self.section('DATE', str(object.__date__)) if hasattr(object, '__author__'): result = result + self.section('AUTHOR', str(object.__author__)) if hasattr(object, '__credits__'): result = result + self.section('CREDITS', str(object.__credits__)) try: file = inspect.getabsfile(object) except TypeError: file = '(built-in)' result = result + self.section('FILE', file) return result
[ "def", "docmodule", "(", "self", ",", "object", ",", "name", "=", "None", ",", "mod", "=", "None", ")", ":", "name", "=", "object", ".", "__name__", "# ignore the passed-in name", "synop", ",", "desc", "=", "splitdoc", "(", "getdoc", "(", "object", ")", ...
https://github.com/securesystemslab/zippy/blob/ff0e84ac99442c2c55fe1d285332cfd4e185e089/zippy/lib-python/3/pydoc.py#L1049-L1148
pyrocko/pyrocko
b6baefb7540fb7fce6ed9b856ec0c413961a4320
src/moment_tensor.py
python
MomentTensor.m6_up_south_east
(self)
return to6(self.m_up_south_east())
Get moment tensor in up-south-east convention as a six-element array. :returns: ``(muu, mss, mee, mus, mue, mse)``
Get moment tensor in up-south-east convention as a six-element array.
[ "Get", "moment", "tensor", "in", "up", "-", "south", "-", "east", "convention", "as", "a", "six", "-", "element", "array", "." ]
def m6_up_south_east(self): ''' Get moment tensor in up-south-east convention as a six-element array. :returns: ``(muu, mss, mee, mus, mue, mse)`` ''' return to6(self.m_up_south_east())
[ "def", "m6_up_south_east", "(", "self", ")", ":", "return", "to6", "(", "self", ".", "m_up_south_east", "(", ")", ")" ]
https://github.com/pyrocko/pyrocko/blob/b6baefb7540fb7fce6ed9b856ec0c413961a4320/src/moment_tensor.py#L792-L798
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/screenlogic/sensor.py
python
ScreenLogicChemistrySensor.sensor
(self)
return self.coordinator.data[SL_DATA.KEY_CHEMISTRY][self._key]
Shortcut to access the pump sensor data.
Shortcut to access the pump sensor data.
[ "Shortcut", "to", "access", "the", "pump", "sensor", "data", "." ]
def sensor(self): """Shortcut to access the pump sensor data.""" return self.coordinator.data[SL_DATA.KEY_CHEMISTRY][self._key]
[ "def", "sensor", "(", "self", ")", ":", "return", "self", ".", "coordinator", ".", "data", "[", "SL_DATA", ".", "KEY_CHEMISTRY", "]", "[", "self", ".", "_key", "]" ]
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/screenlogic/sensor.py#L169-L171
nsacyber/WALKOFF
52d3311abe99d64cd2a902eb998c5e398efe0e07
api_gateway/serverdb/role.py
python
Role.__init__
(self, name, description='', resources=None)
Initializes a Role object. Each user has one or more Roles associated with it, which determines the user's permissions. Args: name (str): The name of the Role. description (str, optional): A description of the role. resources (list(dict[name:resource, permissions:list[permission])): A list of dictionaries containing the name of the resource, and a list of permission names associated with the resource. Defaults to None.
Initializes a Role object. Each user has one or more Roles associated with it, which determines the user's permissions.
[ "Initializes", "a", "Role", "object", ".", "Each", "user", "has", "one", "or", "more", "Roles", "associated", "with", "it", "which", "determines", "the", "user", "s", "permissions", "." ]
def __init__(self, name, description='', resources=None): """Initializes a Role object. Each user has one or more Roles associated with it, which determines the user's permissions. Args: name (str): The name of the Role. description (str, optional): A description of the role. resources (list(dict[name:resource, permissions:list[permission])): A list of dictionaries containing the name of the resource, and a list of permission names associated with the resource. Defaults to None. """ self.name = name self.description = description self.resources = [] if resources: self.set_resources(resources)
[ "def", "__init__", "(", "self", ",", "name", ",", "description", "=", "''", ",", "resources", "=", "None", ")", ":", "self", ".", "name", "=", "name", "self", ".", "description", "=", "description", "self", ".", "resources", "=", "[", "]", "if", "res...
https://github.com/nsacyber/WALKOFF/blob/52d3311abe99d64cd2a902eb998c5e398efe0e07/api_gateway/serverdb/role.py#L13-L27
un33k/django-ipware
335a5683cca50ab743882d0a59a1ef4403341ac0
ipware/utils.py
python
get_ip_info
(ip_str)
return ip, is_routable_ip
Given a string, it returns a tuple of (IP, Routable).
Given a string, it returns a tuple of (IP, Routable).
[ "Given", "a", "string", "it", "returns", "a", "tuple", "of", "(", "IP", "Routable", ")", "." ]
def get_ip_info(ip_str): """ Given a string, it returns a tuple of (IP, Routable). """ ip = None is_routable_ip = False clean_ip = cleanup_ip(ip_str) if is_valid_ip(clean_ip): ip = clean_ip is_routable_ip = is_public_ip(ip) return ip, is_routable_ip
[ "def", "get_ip_info", "(", "ip_str", ")", ":", "ip", "=", "None", "is_routable_ip", "=", "False", "clean_ip", "=", "cleanup_ip", "(", "ip_str", ")", "if", "is_valid_ip", "(", "clean_ip", ")", ":", "ip", "=", "clean_ip", "is_routable_ip", "=", "is_public_ip",...
https://github.com/un33k/django-ipware/blob/335a5683cca50ab743882d0a59a1ef4403341ac0/ipware/utils.py#L101-L111
huggingface/transformers
623b4f7c63f60cce917677ee704d6c93ee960b4b
src/transformers/models/hubert/modeling_tf_hubert.py
python
TFHubertLayerNormConvLayer.call
(self, hidden_states: tf.Tensor)
return hidden_states
[]
def call(self, hidden_states: tf.Tensor) -> tf.Tensor: hidden_states = self.conv(hidden_states) hidden_states = self.layer_norm(hidden_states) hidden_states = self.activation(hidden_states) return hidden_states
[ "def", "call", "(", "self", ",", "hidden_states", ":", "tf", ".", "Tensor", ")", "->", "tf", ".", "Tensor", ":", "hidden_states", "=", "self", ".", "conv", "(", "hidden_states", ")", "hidden_states", "=", "self", ".", "layer_norm", "(", "hidden_states", ...
https://github.com/huggingface/transformers/blob/623b4f7c63f60cce917677ee704d6c93ee960b4b/src/transformers/models/hubert/modeling_tf_hubert.py#L598-L602
golismero/golismero
7d605b937e241f51c1ca4f47b20f755eeefb9d76
thirdparty_libs/nltk/stem/porter.py
python
PorterStemmer.setto
(self, s)
setto(s) sets (j+1),...k to the characters in the string s, readjusting k.
setto(s) sets (j+1),...k to the characters in the string s, readjusting k.
[ "setto", "(", "s", ")", "sets", "(", "j", "+", "1", ")", "...", "k", "to", "the", "characters", "in", "the", "string", "s", "readjusting", "k", "." ]
def setto(self, s): """setto(s) sets (j+1),...k to the characters in the string s, readjusting k.""" length = len(s) self.b = self.b[:self.j+1] + s + self.b[self.j+length+1:] self.k = self.j + length
[ "def", "setto", "(", "self", ",", "s", ")", ":", "length", "=", "len", "(", "s", ")", "self", ".", "b", "=", "self", ".", "b", "[", ":", "self", ".", "j", "+", "1", "]", "+", "s", "+", "self", ".", "b", "[", "self", ".", "j", "+", "leng...
https://github.com/golismero/golismero/blob/7d605b937e241f51c1ca4f47b20f755eeefb9d76/thirdparty_libs/nltk/stem/porter.py#L270-L274
PyCQA/pylint
3fc855f9d0fa8e6410be5a23cf954ffd5471b4eb
pylint/checkers/utils.py
python
find_except_wrapper_node_in_scope
( node: nodes.NodeNG, )
return None
Return the ExceptHandler in which the node is, without going out of scope.
Return the ExceptHandler in which the node is, without going out of scope.
[ "Return", "the", "ExceptHandler", "in", "which", "the", "node", "is", "without", "going", "out", "of", "scope", "." ]
def find_except_wrapper_node_in_scope( node: nodes.NodeNG, ) -> Optional[Union[nodes.ExceptHandler, nodes.TryExcept]]: """Return the ExceptHandler in which the node is, without going out of scope.""" for current in node.node_ancestors(): if isinstance(current, astroid.scoped_nodes.LocalsDictNodeNG): # If we're inside a function/class definition, we don't want to keep checking # higher ancestors for `except` clauses, because if these exist, it means our # function/class was defined in an `except` clause, rather than the current code # actually running in an `except` clause. return None if isinstance(current, nodes.ExceptHandler): return current return None
[ "def", "find_except_wrapper_node_in_scope", "(", "node", ":", "nodes", ".", "NodeNG", ",", ")", "->", "Optional", "[", "Union", "[", "nodes", ".", "ExceptHandler", ",", "nodes", ".", "TryExcept", "]", "]", ":", "for", "current", "in", "node", ".", "node_an...
https://github.com/PyCQA/pylint/blob/3fc855f9d0fa8e6410be5a23cf954ffd5471b4eb/pylint/checkers/utils.py#L977-L990
larryhastings/gilectomy
4315ec3f1d6d4f813cc82ce27a24e7f784dbfc1a
Lib/tkinter/__init__.py
python
Text.__init__
(self, master=None, cnf={}, **kw)
Construct a text widget with the parent MASTER. STANDARD OPTIONS background, borderwidth, cursor, exportselection, font, foreground, highlightbackground, highlightcolor, highlightthickness, insertbackground, insertborderwidth, insertofftime, insertontime, insertwidth, padx, pady, relief, selectbackground, selectborderwidth, selectforeground, setgrid, takefocus, xscrollcommand, yscrollcommand, WIDGET-SPECIFIC OPTIONS autoseparators, height, maxundo, spacing1, spacing2, spacing3, state, tabs, undo, width, wrap,
Construct a text widget with the parent MASTER.
[ "Construct", "a", "text", "widget", "with", "the", "parent", "MASTER", "." ]
def __init__(self, master=None, cnf={}, **kw): """Construct a text widget with the parent MASTER. STANDARD OPTIONS background, borderwidth, cursor, exportselection, font, foreground, highlightbackground, highlightcolor, highlightthickness, insertbackground, insertborderwidth, insertofftime, insertontime, insertwidth, padx, pady, relief, selectbackground, selectborderwidth, selectforeground, setgrid, takefocus, xscrollcommand, yscrollcommand, WIDGET-SPECIFIC OPTIONS autoseparators, height, maxundo, spacing1, spacing2, spacing3, state, tabs, undo, width, wrap, """ Widget.__init__(self, master, 'text', cnf, kw)
[ "def", "__init__", "(", "self", ",", "master", "=", "None", ",", "cnf", "=", "{", "}", ",", "*", "*", "kw", ")", ":", "Widget", ".", "__init__", "(", "self", ",", "master", ",", "'text'", ",", "cnf", ",", "kw", ")" ]
https://github.com/larryhastings/gilectomy/blob/4315ec3f1d6d4f813cc82ce27a24e7f784dbfc1a/Lib/tkinter/__init__.py#L2908-L2931
nanoporetech/tombo
afdb4d87249806d3a171d009f948f5b8558d35a0
tombo/tombo_helper.py
python
parse_locs_file
(locs_fn)
return dict((cs, np.array(sorted(cs_poss))) for cs, cs_poss in raw_locs.items())
Parse BED files containing genomic locations (assumes single base locations, so end coordinate is ignored).
Parse BED files containing genomic locations (assumes single base locations, so end coordinate is ignored).
[ "Parse", "BED", "files", "containing", "genomic", "locations", "(", "assumes", "single", "base", "locations", "so", "end", "coordinate", "is", "ignored", ")", "." ]
def parse_locs_file(locs_fn): """Parse BED files containing genomic locations (assumes single base locations, so end coordinate is ignored). """ n_added, n_failed = 0, 0 raw_locs = defaultdict(set) with open(locs_fn) as locs_fp: for line in locs_fp: try: chrm, pos, _, _, _, strand = line.split()[:6] # bed specs indicate 0-based start so don't shift here pos = int(pos) raw_locs[(chrm, strand)].add(pos) n_added += 1 except: n_failed += 1 continue if n_failed > 0: if n_added > 0: warning_message(( 'Some provided locations ({}) were incorrectly formatted. ' + 'Ensure that provided file ({}) is in BED format.').format( n_failed, locs_fn)) else: warning_message(( 'All provided locations from {} were incorrectly formatted. ' + 'Ensure that provided file is in BED format.').format( locs_fn)) return dict((cs, np.array(sorted(cs_poss))) for cs, cs_poss in raw_locs.items())
[ "def", "parse_locs_file", "(", "locs_fn", ")", ":", "n_added", ",", "n_failed", "=", "0", ",", "0", "raw_locs", "=", "defaultdict", "(", "set", ")", "with", "open", "(", "locs_fn", ")", "as", "locs_fp", ":", "for", "line", "in", "locs_fp", ":", "try", ...
https://github.com/nanoporetech/tombo/blob/afdb4d87249806d3a171d009f948f5b8558d35a0/tombo/tombo_helper.py#L475-L506
AppScale/gts
46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9
AppServer/lib/django-1.5/django/contrib/formtools/wizard/views.py
python
WizardView.get_step_index
(self, step=None)
return self.get_form_list().keyOrder.index(step)
Returns the index for the given `step` name. If no step is given, the current step will be used to get the index.
Returns the index for the given `step` name. If no step is given, the current step will be used to get the index.
[ "Returns", "the", "index", "for", "the", "given", "step", "name", ".", "If", "no", "step", "is", "given", "the", "current", "step", "will", "be", "used", "to", "get", "the", "index", "." ]
def get_step_index(self, step=None): """ Returns the index for the given `step` name. If no step is given, the current step will be used to get the index. """ if step is None: step = self.steps.current return self.get_form_list().keyOrder.index(step)
[ "def", "get_step_index", "(", "self", ",", "step", "=", "None", ")", ":", "if", "step", "is", "None", ":", "step", "=", "self", ".", "steps", ".", "current", "return", "self", ".", "get_form_list", "(", ")", ".", "keyOrder", ".", "index", "(", "step"...
https://github.com/AppScale/gts/blob/46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9/AppServer/lib/django-1.5/django/contrib/formtools/wizard/views.py#L502-L509
mozilla/mozillians
bd5da47fef01e4e09d3bb8cb0799735bdfbeb3f9
mozillians/common/templatetags/helpers.py
python
field_with_attrs
(bfield, **kwargs)
return bfield
Allows templates to dynamically add html attributes to bound fields from django forms. Copied from bedrock.
Allows templates to dynamically add html attributes to bound fields from django forms.
[ "Allows", "templates", "to", "dynamically", "add", "html", "attributes", "to", "bound", "fields", "from", "django", "forms", "." ]
def field_with_attrs(bfield, **kwargs): """Allows templates to dynamically add html attributes to bound fields from django forms. Copied from bedrock. """ if kwargs.get('label', None): bfield.label = kwargs['label'] bfield.field.widget.attrs.update(kwargs) return bfield
[ "def", "field_with_attrs", "(", "bfield", ",", "*", "*", "kwargs", ")", ":", "if", "kwargs", ".", "get", "(", "'label'", ",", "None", ")", ":", "bfield", ".", "label", "=", "kwargs", "[", "'label'", "]", "bfield", ".", "field", ".", "widget", ".", ...
https://github.com/mozilla/mozillians/blob/bd5da47fef01e4e09d3bb8cb0799735bdfbeb3f9/mozillians/common/templatetags/helpers.py#L73-L82
mozman/ezdxf
59d0fc2ea63f5cf82293428f5931da7e9f9718e9
src/ezdxf/path/shapes.py
python
gear
( count: int, top_width: float, bottom_width: float, height: float, outside_radius: float, transform: Matrix44 = None, )
return converter.from_vertices(vertices, close=True)
Returns a `gear <https://en.wikipedia.org/wiki/Gear>`_ (cogwheel) shape as a :class:`Path` object, with the center at (0, 0, 0). The base geometry is created by function :func:`ezdxf.render.forms.gear`. .. warning:: This function does not create correct gears for mechanical engineering! Args: count: teeth count >= 3 top_width: teeth width at outside radius bottom_width: teeth width at base radius height: teeth height; base radius = outside radius - height outside_radius: outside radius transform: transformation Matrix applied to the gear shape
Returns a `gear <https://en.wikipedia.org/wiki/Gear>`_ (cogwheel) shape as a :class:`Path` object, with the center at (0, 0, 0). The base geometry is created by function :func:`ezdxf.render.forms.gear`.
[ "Returns", "a", "gear", "<https", ":", "//", "en", ".", "wikipedia", ".", "org", "/", "wiki", "/", "Gear", ">", "_", "(", "cogwheel", ")", "shape", "as", "a", ":", "class", ":", "Path", "object", "with", "the", "center", "at", "(", "0", "0", "0",...
def gear( count: int, top_width: float, bottom_width: float, height: float, outside_radius: float, transform: Matrix44 = None, ) -> Path: """ Returns a `gear <https://en.wikipedia.org/wiki/Gear>`_ (cogwheel) shape as a :class:`Path` object, with the center at (0, 0, 0). The base geometry is created by function :func:`ezdxf.render.forms.gear`. .. warning:: This function does not create correct gears for mechanical engineering! Args: count: teeth count >= 3 top_width: teeth width at outside radius bottom_width: teeth width at base radius height: teeth height; base radius = outside radius - height outside_radius: outside radius transform: transformation Matrix applied to the gear shape """ vertices = forms.gear( count, top_width, bottom_width, height, outside_radius ) if transform is not None: vertices = transform.transform_vertices(vertices) return converter.from_vertices(vertices, close=True)
[ "def", "gear", "(", "count", ":", "int", ",", "top_width", ":", "float", ",", "bottom_width", ":", "float", ",", "height", ":", "float", ",", "outside_radius", ":", "float", ",", "transform", ":", "Matrix44", "=", "None", ",", ")", "->", "Path", ":", ...
https://github.com/mozman/ezdxf/blob/59d0fc2ea63f5cf82293428f5931da7e9f9718e9/src/ezdxf/path/shapes.py#L206-L237
ReactionMechanismGenerator/RMG-Py
2b7baf51febf27157def58fb3f6cee03fb6a684c
arkane/ess/adapter.py
python
ESSAdapter.load_geometry
(self)
Return the optimum geometry of the molecular configuration. If multiple such geometries are identified, only the last is returned.
Return the optimum geometry of the molecular configuration. If multiple such geometries are identified, only the last is returned.
[ "Return", "the", "optimum", "geometry", "of", "the", "molecular", "configuration", ".", "If", "multiple", "such", "geometries", "are", "identified", "only", "the", "last", "is", "returned", "." ]
def load_geometry(self): """ Return the optimum geometry of the molecular configuration. If multiple such geometries are identified, only the last is returned. """ pass
[ "def", "load_geometry", "(", "self", ")", ":", "pass" ]
https://github.com/ReactionMechanismGenerator/RMG-Py/blob/2b7baf51febf27157def58fb3f6cee03fb6a684c/arkane/ess/adapter.py#L78-L83
nedbat/coveragepy
d004b18a1ad59ec89b89c96c03a789a55cc51693
coverage/cmdline.py
python
unshell_list
(s)
return s.split(',')
Turn a command-line argument into a list.
Turn a command-line argument into a list.
[ "Turn", "a", "command", "-", "line", "argument", "into", "a", "list", "." ]
def unshell_list(s): """Turn a command-line argument into a list.""" if not s: return None if env.WINDOWS: # When running coverage.py as coverage.exe, some of the behavior # of the shell is emulated: wildcards are expanded into a list of # file names. So you have to single-quote patterns on the command # line, but (not) helpfully, the single quotes are included in the # argument, so we have to strip them off here. s = s.strip("'") return s.split(',')
[ "def", "unshell_list", "(", "s", ")", ":", "if", "not", "s", ":", "return", "None", "if", "env", ".", "WINDOWS", ":", "# When running coverage.py as coverage.exe, some of the behavior", "# of the shell is emulated: wildcards are expanded into a list of", "# file names. So you ...
https://github.com/nedbat/coveragepy/blob/d004b18a1ad59ec89b89c96c03a789a55cc51693/coverage/cmdline.py#L812-L823
makehumancommunity/makehuman
8006cf2cc851624619485658bb933a4244bbfd7c
makehuman/lib/sorter.py
python
Sorter._getDecorated
(keyFn, objects)
return [ (keyFn(object), i, object) for i, object in enumerate(objects)]
Static method that decorates the objects of a list to tuples containing an orderable key generated by applying keyFn on the objects, an index, and the object. :param keyFn: Ordering method (function that takes an object as parameter and returns a corresponding orderable key) :type keyFn: function :param objects: List of objects to be decorated with orderable keys :type objects: list :return: List of decorated objects :rtype: list of tuples
Static method that decorates the objects of a list to tuples containing an orderable key generated by applying keyFn on the objects, an index, and the object.
[ "Static", "method", "that", "decorates", "the", "objects", "of", "a", "list", "to", "tuples", "containing", "an", "orderable", "key", "generated", "by", "applying", "keyFn", "on", "the", "objects", "an", "index", "and", "the", "object", "." ]
def _getDecorated(keyFn, objects): """ Static method that decorates the objects of a list to tuples containing an orderable key generated by applying keyFn on the objects, an index, and the object. :param keyFn: Ordering method (function that takes an object as parameter and returns a corresponding orderable key) :type keyFn: function :param objects: List of objects to be decorated with orderable keys :type objects: list :return: List of decorated objects :rtype: list of tuples """ return [ (keyFn(object), i, object) for i, object in enumerate(objects)]
[ "def", "_getDecorated", "(", "keyFn", ",", "objects", ")", ":", "return", "[", "(", "keyFn", "(", "object", ")", ",", "i", ",", "object", ")", "for", "i", ",", "object", "in", "enumerate", "(", "objects", ")", "]" ]
https://github.com/makehumancommunity/makehuman/blob/8006cf2cc851624619485658bb933a4244bbfd7c/makehuman/lib/sorter.py#L219-L241
SteveDoyle2/pyNastran
eda651ac2d4883d95a34951f8a002ff94f642a1a
pyNastran/bdf/cards/axisymmetric/axisymmetric.py
python
RINGFL.__init__
(self, ringfl: int, xa: float, xb: float, comment: str='')
Creates the RINGFL card
Creates the RINGFL card
[ "Creates", "the", "RINGFL", "card" ]
def __init__(self, ringfl: int, xa: float, xb: float, comment: str='') -> None: # this card has missing fields """ Creates the RINGFL card """ #Ring.__init__(self) if comment: self.comment = comment self.ringfl = ringfl self.xa = xa self.xb = xb
[ "def", "__init__", "(", "self", ",", "ringfl", ":", "int", ",", "xa", ":", "float", ",", "xb", ":", "float", ",", "comment", ":", "str", "=", "''", ")", "->", "None", ":", "# this card has missing fields", "#Ring.__init__(self)", "if", "comment", ":", "s...
https://github.com/SteveDoyle2/pyNastran/blob/eda651ac2d4883d95a34951f8a002ff94f642a1a/pyNastran/bdf/cards/axisymmetric/axisymmetric.py#L244-L255
mozman/ezdxf
59d0fc2ea63f5cf82293428f5931da7e9f9718e9
src/ezdxf/entities/image.py
python
ImageBase.export_entity
(self, tagwriter: "TagWriter")
Export entity specific data as DXF tags.
Export entity specific data as DXF tags.
[ "Export", "entity", "specific", "data", "as", "DXF", "tags", "." ]
def export_entity(self, tagwriter: "TagWriter") -> None: """Export entity specific data as DXF tags.""" super().export_entity(tagwriter) tagwriter.write_tag2(SUBCLASS_MARKER, self._SUBCLASS_NAME) self.dxf.count_boundary_points = len(self.boundary_path) self.dxf.export_dxf_attribs( tagwriter, [ "class_version", "insert", "u_pixel", "v_pixel", "image_size", "image_def_handle", "flags", "clipping", "brightness", "contrast", "fade", "image_def_reactor_handle", "clipping_boundary_type", "count_boundary_points", ], ) self.export_boundary_path(tagwriter) if tagwriter.dxfversion >= DXF2010: self.dxf.export_dxf_attribs(tagwriter, "clip_mode")
[ "def", "export_entity", "(", "self", ",", "tagwriter", ":", "\"TagWriter\"", ")", "->", "None", ":", "super", "(", ")", ".", "export_entity", "(", "tagwriter", ")", "tagwriter", ".", "write_tag2", "(", "SUBCLASS_MARKER", ",", "self", ".", "_SUBCLASS_NAME", "...
https://github.com/mozman/ezdxf/blob/59d0fc2ea63f5cf82293428f5931da7e9f9718e9/src/ezdxf/entities/image.py#L98-L124
andresriancho/w3af
cd22e5252243a87aaa6d0ddea47cf58dacfe00a9
w3af/core/data/options/list_option.py
python
ListOption._get_str
(self, value)
[]
def _get_str(self, value): if isinstance(value, list): return ','.join([str(i) for i in value])
[ "def", "_get_str", "(", "self", ",", "value", ")", ":", "if", "isinstance", "(", "value", ",", "list", ")", ":", "return", "','", ".", "join", "(", "[", "str", "(", "i", ")", "for", "i", "in", "value", "]", ")" ]
https://github.com/andresriancho/w3af/blob/cd22e5252243a87aaa6d0ddea47cf58dacfe00a9/w3af/core/data/options/list_option.py#L42-L44
idanr1986/cuckoo-droid
1350274639473d3d2b0ac740cae133ca53ab7444
analyzer/android_on_linux/lib/api/androguard/dvm.py
python
FieldIdItem.get_class_idx
(self)
return self.class_idx
Return the index into the type_ids list for the definer of this field :rtype: int
Return the index into the type_ids list for the definer of this field
[ "Return", "the", "index", "into", "the", "type_ids", "list", "for", "the", "definer", "of", "this", "field" ]
def get_class_idx(self) : """ Return the index into the type_ids list for the definer of this field :rtype: int """ return self.class_idx
[ "def", "get_class_idx", "(", "self", ")", ":", "return", "self", ".", "class_idx" ]
https://github.com/idanr1986/cuckoo-droid/blob/1350274639473d3d2b0ac740cae133ca53ab7444/analyzer/android_on_linux/lib/api/androguard/dvm.py#L2131-L2137
grow/grow
97fc21730b6a674d5d33948d94968e79447ce433
grow/deployments/destinations/git_destination.py
python
GitDestination.read_file
(self, path)
return self.storage.read(path)
[]
def read_file(self, path): path = os.path.join(self.repo_path, self.config.root_dir.lstrip('/'), path.lstrip('/')) return self.storage.read(path)
[ "def", "read_file", "(", "self", ",", "path", ")", ":", "path", "=", "os", ".", "path", ".", "join", "(", "self", ".", "repo_path", ",", "self", ".", "config", ".", "root_dir", ".", "lstrip", "(", "'/'", ")", ",", "path", ".", "lstrip", "(", "'/'...
https://github.com/grow/grow/blob/97fc21730b6a674d5d33948d94968e79447ce433/grow/deployments/destinations/git_destination.py#L125-L128
smicallef/spiderfoot
fd4bf9394c9ab3ecc90adc3115c56349fb23165b
modules/sfp_countryname.py
python
sfp_countryname.detectCountryFromPhone
(self, srcPhoneNumber)
return self.sf.countryNameFromCountryCode(countryCode.upper())
Lookup name of country from phone number region code. Args: srcPhoneNumber (str): phone number Returns: str: country name
Lookup name of country from phone number region code.
[ "Lookup", "name", "of", "country", "from", "phone", "number", "region", "code", "." ]
def detectCountryFromPhone(self, srcPhoneNumber): """Lookup name of country from phone number region code. Args: srcPhoneNumber (str): phone number Returns: str: country name """ if not isinstance(srcPhoneNumber, str): return None try: phoneNumber = phonenumbers.parse(srcPhoneNumber) except Exception: self.debug(f"Skipped invalid phone number: {srcPhoneNumber}") return None try: countryCode = region_code_for_country_code(phoneNumber.country_code) except Exception: self.debug(f"Lookup of region code failed for phone number: {srcPhoneNumber}") return None if not countryCode: return None return self.sf.countryNameFromCountryCode(countryCode.upper())
[ "def", "detectCountryFromPhone", "(", "self", ",", "srcPhoneNumber", ")", ":", "if", "not", "isinstance", "(", "srcPhoneNumber", ",", "str", ")", ":", "return", "None", "try", ":", "phoneNumber", "=", "phonenumbers", ".", "parse", "(", "srcPhoneNumber", ")", ...
https://github.com/smicallef/spiderfoot/blob/fd4bf9394c9ab3ecc90adc3115c56349fb23165b/modules/sfp_countryname.py#L58-L86
openstack/sahara
c4f4d29847d5bcca83d49ef7e9a3378458462a79
sahara/utils/proxy.py
python
create_proxy_user_for_job_execution
(job_execution)
Creates a proxy user and adds the credentials to the job execution :param job_execution: The job execution model to update
Creates a proxy user and adds the credentials to the job execution
[ "Creates", "a", "proxy", "user", "and", "adds", "the", "credentials", "to", "the", "job", "execution" ]
def create_proxy_user_for_job_execution(job_execution): '''Creates a proxy user and adds the credentials to the job execution :param job_execution: The job execution model to update ''' username = 'job_{0}'.format(job_execution.id) password = key_manager.store_secret(proxy_user_create(username)) current_user = k.auth() proxy_user = k.auth_for_proxy(username, password) trust_id = t.create_trust(trustor=current_user, trustee=proxy_user, role_names=CONF.proxy_user_role_names) update = {'job_configs': job_execution.job_configs.to_dict()} update['job_configs']['proxy_configs'] = { 'proxy_username': username, 'proxy_password': password, 'proxy_trust_id': trust_id } conductor.job_execution_update(context.ctx(), job_execution, update)
[ "def", "create_proxy_user_for_job_execution", "(", "job_execution", ")", ":", "username", "=", "'job_{0}'", ".", "format", "(", "job_execution", ".", "id", ")", "password", "=", "key_manager", ".", "store_secret", "(", "proxy_user_create", "(", "username", ")", ")...
https://github.com/openstack/sahara/blob/c4f4d29847d5bcca83d49ef7e9a3378458462a79/sahara/utils/proxy.py#L57-L76
bakwc/PySyncObj
012aeb1b34be7b98f3b5c33e735836a9fc0c4cba
pysyncobj/utility.py
python
Utility.executeCommand
(self, node, command)
Executes command on the given node. :param node: where to execute the command :type node: Node or str :param command: the command which should be sent :type command: list :returns: result :rtype: any object :raises: UtilityException in case of error
Executes command on the given node.
[ "Executes", "command", "on", "the", "given", "node", "." ]
def executeCommand(self, node, command): """ Executes command on the given node. :param node: where to execute the command :type node: Node or str :param command: the command which should be sent :type command: list :returns: result :rtype: any object :raises: UtilityException in case of error """
[ "def", "executeCommand", "(", "self", ",", "node", ",", "command", ")", ":" ]
https://github.com/bakwc/PySyncObj/blob/012aeb1b34be7b98f3b5c33e735836a9fc0c4cba/pysyncobj/utility.py#L26-L37
geopython/pycsw
43a5c92fa819a3a3fdc8a8e3ef075d784dff73fc
pycsw/server.py
python
Csw.sru
(self)
return self.sruobj
enable SRU
enable SRU
[ "enable", "SRU" ]
def sru(self): """ enable SRU """ if not self.sruobj: self.sruobj = sru.Sru(self.context) return self.sruobj
[ "def", "sru", "(", "self", ")", ":", "if", "not", "self", ".", "sruobj", ":", "self", ".", "sruobj", "=", "sru", ".", "Sru", "(", "self", ".", "context", ")", "return", "self", ".", "sruobj" ]
https://github.com/geopython/pycsw/blob/43a5c92fa819a3a3fdc8a8e3ef075d784dff73fc/pycsw/server.py#L274-L279
cylc/cylc-flow
5ec221143476c7c616c156b74158edfbcd83794a
cylc/flow/task_message.py
python
send_messages
(workflow, task_job, messages, event_time)
[]
def send_messages(workflow, task_job, messages, event_time): workflow = os.path.normpath(workflow) try: pclient = get_client(workflow) except WorkflowStopped: # on a remote host this means the contact file is not present # either the workflow is stopped or the contact file is not present # on the job host (i.e. comms method is polling) # eitherway don't try messaging pass except Exception: # Backward communication not possible if cylc.flow.flags.verbosity > 1: import traceback traceback.print_exc() else: mutation_kwargs = { 'request_string': MUTATION, 'variables': { 'wFlows': [workflow], 'taskJob': task_job, 'eventTime': event_time, 'messages': messages, } } pclient('graphql', mutation_kwargs)
[ "def", "send_messages", "(", "workflow", ",", "task_job", ",", "messages", ",", "event_time", ")", ":", "workflow", "=", "os", ".", "path", ".", "normpath", "(", "workflow", ")", "try", ":", "pclient", "=", "get_client", "(", "workflow", ")", "except", "...
https://github.com/cylc/cylc-flow/blob/5ec221143476c7c616c156b74158edfbcd83794a/cylc/flow/task_message.py#L104-L129
Kismuz/btgym
7fb3316e67f1d7a17c620630fb62fb29428b2cec
btgym/research/model_based/runner.py
python
OUpRunner.__init__
(self, name='OUp_synchro', **kwargs)
[]
def __init__(self, name='OUp_synchro', **kwargs): super(OUpRunner, self).__init__(name=name, **kwargs) # True data_generating_process params: self.dgp_params = {key: [] for key in self.env.observation_space.shape['metadata']['generator'].keys()} self.dgp_dict = {key: 0 for key in self.env.observation_space.shape['metadata']['generator'].keys()} # print('self.dgp_params_00: ', self.dgp_params) self.policy.callback['dgp_params'] = self.pull_dgp_params
[ "def", "__init__", "(", "self", ",", "name", "=", "'OUp_synchro'", ",", "*", "*", "kwargs", ")", ":", "super", "(", "OUpRunner", ",", "self", ")", ".", "__init__", "(", "name", "=", "name", ",", "*", "*", "kwargs", ")", "# True data_generating_process pa...
https://github.com/Kismuz/btgym/blob/7fb3316e67f1d7a17c620630fb62fb29428b2cec/btgym/research/model_based/runner.py#L10-L18
team-ocean/veros
f62d6a2fe459a807fa6f3799c8aaa0a5fb70560f
veros/core/thermodynamics.py
python
surf_densityf
(state)
return KernelOutput(forc_rho_surface=vs.forc_rho_surface)
surface density flux
surface density flux
[ "surface", "density", "flux" ]
def surf_densityf(state): """ surface density flux """ vs = state.variables vs.forc_rho_surface = vs.maskT[:, :, -1] * ( density.get_drhodT(state, vs.salt[:, :, -1, vs.taup1], vs.temp[:, :, -1, vs.taup1], npx.abs(vs.zt[-1])) * vs.forc_temp_surface + density.get_drhodS(state, vs.salt[:, :, -1, vs.taup1], vs.temp[:, :, -1, vs.taup1], npx.abs(vs.zt[-1])) * vs.forc_salt_surface ) return KernelOutput(forc_rho_surface=vs.forc_rho_surface)
[ "def", "surf_densityf", "(", "state", ")", ":", "vs", "=", "state", ".", "variables", "vs", ".", "forc_rho_surface", "=", "vs", ".", "maskT", "[", ":", ",", ":", ",", "-", "1", "]", "*", "(", "density", ".", "get_drhodT", "(", "state", ",", "vs", ...
https://github.com/team-ocean/veros/blob/f62d6a2fe459a807fa6f3799c8aaa0a5fb70560f/veros/core/thermodynamics.py#L304-L317
TUDelft-CNS-ATM/bluesky
55a538a3cd936f33cff9df650c38924aa97557b1
bluesky/traffic/traffic.py
python
Traffic.airwaycmd
(self, key)
return False, f"No airway legs found for {key}"
Show conections of a waypoint or airway.
Show conections of a waypoint or airway.
[ "Show", "conections", "of", "a", "waypoint", "or", "airway", "." ]
def airwaycmd(self, key): ''' Show conections of a waypoint or airway. ''' reflat, reflon = bs.scr.getviewctr() if bs.navdb.awid.count(key) > 0: return self.poscommand(key) # Find connecting airway legs wpid = key iwp = bs.navdb.getwpidx(wpid,reflat,reflon) if iwp < 0: return False,key + " not found." wplat = bs.navdb.wplat[iwp] wplon = bs.navdb.wplon[iwp] connect = bs.navdb.listconnections(key, wplat, wplon) if connect: lines = "" for c in connect: if len(c)>=2: # Add airway, direction, waypoint lines = lines+ c[0]+": to "+c[1]+"\n" return True, lines[:-1] # exclude final newline return False, f"No airway legs found for {key}"
[ "def", "airwaycmd", "(", "self", ",", "key", ")", ":", "reflat", ",", "reflon", "=", "bs", ".", "scr", ".", "getviewctr", "(", ")", "if", "bs", ".", "navdb", ".", "awid", ".", "count", "(", "key", ")", ">", "0", ":", "return", "self", ".", "pos...
https://github.com/TUDelft-CNS-ATM/bluesky/blob/55a538a3cd936f33cff9df650c38924aa97557b1/bluesky/traffic/traffic.py#L731-L754
edfungus/Crouton
ada98b3930192938a48909072b45cb84b945f875
clients/esp8266_clients/venv/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/filepost.py
python
choose_boundary
()
return uuid4().hex
Our embarassingly-simple replacement for mimetools.choose_boundary.
Our embarassingly-simple replacement for mimetools.choose_boundary.
[ "Our", "embarassingly", "-", "simple", "replacement", "for", "mimetools", ".", "choose_boundary", "." ]
def choose_boundary(): """ Our embarassingly-simple replacement for mimetools.choose_boundary. """ return uuid4().hex
[ "def", "choose_boundary", "(", ")", ":", "return", "uuid4", "(", ")", ".", "hex" ]
https://github.com/edfungus/Crouton/blob/ada98b3930192938a48909072b45cb84b945f875/clients/esp8266_clients/venv/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/filepost.py#L13-L17
chaitjo/personalized-dialog
4f94e3dc1376e4e6aa1e5be3ec08b9f56871c98e
MemN2N/memn2n/memn2n_dialog.py
python
add_gradient_noise
(t, stddev=1e-3, name=None)
Adds gradient noise as described in http://arxiv.org/abs/1511.06807 [2]. The input Tensor `t` should be a gradient. The output will be `t` + gaussian noise. 0.001 was said to be a good fixed value for memory networks [2].
Adds gradient noise as described in http://arxiv.org/abs/1511.06807 [2].
[ "Adds", "gradient", "noise", "as", "described", "in", "http", ":", "//", "arxiv", ".", "org", "/", "abs", "/", "1511", ".", "06807", "[", "2", "]", "." ]
def add_gradient_noise(t, stddev=1e-3, name=None): """Adds gradient noise as described in http://arxiv.org/abs/1511.06807 [2]. The input Tensor `t` should be a gradient. The output will be `t` + gaussian noise. 0.001 was said to be a good fixed value for memory networks [2]. """ with tf.name_scope(name, "add_gradient_noise", [t, stddev]) as name: t = tf.convert_to_tensor(t, name="t") gn = tf.random_normal(tf.shape(t), stddev=stddev) return tf.add(t, gn, name=name)
[ "def", "add_gradient_noise", "(", "t", ",", "stddev", "=", "1e-3", ",", "name", "=", "None", ")", ":", "with", "tf", ".", "name_scope", "(", "name", ",", "\"add_gradient_noise\"", ",", "[", "t", ",", "stddev", "]", ")", "as", "name", ":", "t", "=", ...
https://github.com/chaitjo/personalized-dialog/blob/4f94e3dc1376e4e6aa1e5be3ec08b9f56871c98e/MemN2N/memn2n/memn2n_dialog.py#L232-L244
deepmind/mathematics_dataset
900a0813b1997f45a4d0a8e448a652f37e4b5685
mathematics_dataset/sample/polynomials.py
python
_sample_with_brackets
(depth, variables, degrees, entropy, length, force_brackets=True)
Internal recursive function for: constructs a polynomial with brackets.
Internal recursive function for: constructs a polynomial with brackets.
[ "Internal", "recursive", "function", "for", ":", "constructs", "a", "polynomial", "with", "brackets", "." ]
def _sample_with_brackets(depth, variables, degrees, entropy, length, force_brackets=True): """Internal recursive function for: constructs a polynomial with brackets.""" # To generate arbitrary polynomial recursively, can do one of: # * add two polynomials, with at least one having brackets. # * multiply two polynomials. # * call `sample` (i.e., polynomial without brackets). if force_brackets: length = max(2, length) if not force_brackets and (random.choice([False, True]) or length < 2): return sample(variables, degrees, entropy, length) length_left = random.randint(1, length - 1) length_right = length - length_left entropy_left, entropy_right = entropy * np.random.dirichlet( [length_left, length_right]) if random.choice([False, True]): # Add two. Force brackets on at least one of the polynomials, and sample # repeatedly until we don't get cancellation. while True: left = _sample_with_brackets( depth + 1, variables, degrees, entropy_left, length_left, True) right = _sample_with_brackets( depth + 1, variables, degrees, entropy_right, length_right, False) if random.choice([False, True]): left, right = right, left result = ops.Add(left, right) all_ok = True for variable, degree in zip(variables, degrees): if _degree_of_variable(result, variable) != degree: all_ok = False break if all_ok: return result else: # Multiply two. def sample_with_zero_check(degrees_, entropy_, length_): while True: result = _sample_with_brackets( depth + 1, variables, degrees_, entropy_, length_, False) if degrees_.sum() > 0 or not result.sympy().is_zero: return result degrees = np.asarray(degrees) def sample_degree(max_degree): """Select in range [0, max_degree], biased away from ends.""" if max_degree <= 1 or random.choice([False, True]): return random.randint(0, max_degree) return random.randint(1, max_degree - 1) degrees_left = np.array([sample_degree(degree) for degree in degrees]) degrees_right = degrees - degrees_left left = sample_with_zero_check(degrees_left, entropy_left, length_left) right = sample_with_zero_check(degrees_right, entropy_right, length_right) return ops.Mul(left, right)
[ "def", "_sample_with_brackets", "(", "depth", ",", "variables", ",", "degrees", ",", "entropy", ",", "length", ",", "force_brackets", "=", "True", ")", ":", "# To generate arbitrary polynomial recursively, can do one of:", "# * add two polynomials, with at least one having br...
https://github.com/deepmind/mathematics_dataset/blob/900a0813b1997f45a4d0a8e448a652f37e4b5685/mathematics_dataset/sample/polynomials.py#L399-L456
OctoPrint/OctoPrint
4b12b0e6f06c3abfb31b1840a0605e2de8e911d2
src/octoprint/plugin/types.py
python
TemplatePlugin.get_template_configs
(self)
return []
Allows configuration of injected navbar, sidebar, tab and settings templates (and also additional templates of types specified by plugins through the :ref:`octoprint.ui.web.templatetypes <sec-plugins-hook-ui-web-templatetypes>` hook). Should be a list containing one configuration object per template to inject. Each configuration object is represented by a dictionary which may contain the following keys: .. list-table:: :widths: 5 95 * - type - The template type the configuration is targeting. Possible values here are ``navbar``, ``sidebar``, ``tab``, ``settings`` and ``generic``. Mandatory. * - name - The name of the component, if not set the name of the plugin will be used. The name will be visible at a location depending on the ``type``: * ``navbar``: unused * ``sidebar``: sidebar heading * ``tab``: tab heading * ``settings``: settings link * ``wizard``: wizard link * ``about``: about link * ``generic``: unused * - template - Name of the template to inject, default value depends on the ``type``: * ``navbar``: ``<plugin identifier>_navbar.jinja2`` * ``sidebar``: ``<plugin identifier>_sidebar.jinja2`` * ``tab``: ``<plugin identifier>_tab.jinja2`` * ``settings``: ``<plugin identifier>_settings.jinja2`` * ``wizard``: ``<plugin identifier>_wizard.jinja2`` * ``about``: ``<plugin identifier>_about.jinja2`` * ``generic``: ``<plugin identifier>.jinja2`` * - suffix - Suffix to attach to the component identifier and the div identifier of the injected template. Will be ``_<index>`` if not provided and not the first template of the type, with ``index`` counting from 1 and increasing for each template of the same type. Example: If your plugin with identifier ``myplugin`` defines two tab components like this: .. code-block:: python return [ dict(type="tab", template="myplugin_first_tab.jinja2"), dict(type="tab", template="myplugin_second_tab.jinja2") ] then the first tab will have the component identifier ``plugin_myplugin`` and the second one will have the component identifier ``plugin_myplugin_2`` (the generated divs will be ``tab_plugin_myplugin`` and ``tab_plugin_myplugin_2`` accordingly). Notice that the first tab is *not* called ``plugin_myplugin_1`` -- as stated above while the ``index`` used as default suffix starts counting at 1, it will not be applied for the first component of a given type. If on the other hand your plugin's definition looks like this: .. code-block:: python return [ dict(type="tab", template="myplugin_first_tab_jinja2", suffix="_1st"), dict(type="tab", template="myplugin_second_tab_jinja2", suffix="_2nd") ] then the generated component identifier will be ``plugin_myplugin_1st`` and ``plugin_myplugin_2nd`` (and the divs will be ``tab_plugin_myplugin_1st`` and ``tab_plugin_myplugin_2nd``). * - div - Id for the div containing the component. If not provided, defaults to ``<type>_plugin_<plugin identifier>`` plus the ``suffix`` if provided or required. * - replaces - Id of the component this one replaces, might be either one of the core components or a component provided by another plugin. A list of the core component identifiers can be found :ref:`in the configuration documentation <sec-configuration-config_yaml-appearance>`. The identifiers of other plugin components always follow the format described above. * - custom_bindings - A boolean value indicating whether the default view model should be bound to the component (``false``) or if a custom binding will be used by the plugin (``true``, default). * - data_bind - Additional knockout data bindings to apply to the component, can be used to add further behaviour to the container based on internal state if necessary. * - classes - Additional classes to apply to the component, as a list of individual classes (e.g. ``classes=["myclass", "myotherclass"]``) which will be joined into the correct format by the template engine. * - styles - Additional CSS styles to apply to the component, as a list of individual declarations (e.g. ``styles=["color: red", "display: block"]``) which will be joined into the correct format by the template engine. Further keys to be included in the dictionary depend on the type: ``sidebar`` type .. list-table:: :widths: 5 95 * - icon - Icon to use for the sidebar header, should be the name of a Font Awesome icon without the leading ``icon-`` part. * - template_header - Additional template to include in the head section of the sidebar item. For an example of this, see the additional options included in the "Files" section. * - classes_wrapper - Like ``classes`` but only applied to the whole wrapper around the sidebar box. * - classes_content - Like ``classes`` but only applied to the content pane itself. * - styles_wrapper - Like ``styles`` but only applied to the whole wrapper around the sidebar box. * - styles_content - Like ``styles`` but only applied to the content pane itself ``tab`` type and ``settings`` type .. list-table:: :widths: 5 95 * - classes_link - Like ``classes`` but only applied to the link in the navigation. * - classes_content - Like ``classes`` but only applied to the content pane itself. * - styles_link - Like ``styles`` but only applied to the link in the navigation. * - styles_content - Like ``styles`` but only applied to the content pane itself. ``wizard`` type .. list-table:: :widths: 5 95 * - mandatory - Whether the wizard step is mandatory (True) or not (False). Optional, defaults to False. If set to True, OctoPrint will sort visually mark the step as mandatory in the UI (bold in the navigation and a little alert) and also sort it into the first half. .. note:: As already outlined above, each template type has a default template name (i.e. the default navbar template of a plugin is called ``<plugin identifier>_navbar.jinja2``), which may be overridden using the template configuration. If a plugin needs to include more than one template of a given type, it needs to provide an entry for each of those, since the implicit default template will only be included automatically if no other templates of that type are defined. Example: If you have a plugin that injects two tab components, one defined in the template file ``myplugin_tab.jinja2`` (the default template) and one in the template ``myplugin_othertab.jinja2``, you might be tempted to just return the following configuration since one your templates is named by the default template name: .. code-block:: python return [ dict(type="tab", template="myplugin_othertab.jinja2") ] This will only include the tab defined in ``myplugin_othertab.jinja2`` though, ``myplugin_tab.jinja2`` will not be included automatically since the presence of a definition for the ``tab`` type overrides the automatic injection of the default template. You'll have to include it explicitly: .. code-block:: python return [ dict(type="tab", template="myplugin_tab.jinja2"), dict(type="tab", template="myplugin_othertab.jinja2") ] :return list: a list containing the configuration options for the plugin's injected templates
Allows configuration of injected navbar, sidebar, tab and settings templates (and also additional templates of types specified by plugins through the :ref:`octoprint.ui.web.templatetypes <sec-plugins-hook-ui-web-templatetypes>` hook). Should be a list containing one configuration object per template to inject. Each configuration object is represented by a dictionary which may contain the following keys:
[ "Allows", "configuration", "of", "injected", "navbar", "sidebar", "tab", "and", "settings", "templates", "(", "and", "also", "additional", "templates", "of", "types", "specified", "by", "plugins", "through", "the", ":", "ref", ":", "octoprint", ".", "ui", ".",...
def get_template_configs(self): """ Allows configuration of injected navbar, sidebar, tab and settings templates (and also additional templates of types specified by plugins through the :ref:`octoprint.ui.web.templatetypes <sec-plugins-hook-ui-web-templatetypes>` hook). Should be a list containing one configuration object per template to inject. Each configuration object is represented by a dictionary which may contain the following keys: .. list-table:: :widths: 5 95 * - type - The template type the configuration is targeting. Possible values here are ``navbar``, ``sidebar``, ``tab``, ``settings`` and ``generic``. Mandatory. * - name - The name of the component, if not set the name of the plugin will be used. The name will be visible at a location depending on the ``type``: * ``navbar``: unused * ``sidebar``: sidebar heading * ``tab``: tab heading * ``settings``: settings link * ``wizard``: wizard link * ``about``: about link * ``generic``: unused * - template - Name of the template to inject, default value depends on the ``type``: * ``navbar``: ``<plugin identifier>_navbar.jinja2`` * ``sidebar``: ``<plugin identifier>_sidebar.jinja2`` * ``tab``: ``<plugin identifier>_tab.jinja2`` * ``settings``: ``<plugin identifier>_settings.jinja2`` * ``wizard``: ``<plugin identifier>_wizard.jinja2`` * ``about``: ``<plugin identifier>_about.jinja2`` * ``generic``: ``<plugin identifier>.jinja2`` * - suffix - Suffix to attach to the component identifier and the div identifier of the injected template. Will be ``_<index>`` if not provided and not the first template of the type, with ``index`` counting from 1 and increasing for each template of the same type. Example: If your plugin with identifier ``myplugin`` defines two tab components like this: .. code-block:: python return [ dict(type="tab", template="myplugin_first_tab.jinja2"), dict(type="tab", template="myplugin_second_tab.jinja2") ] then the first tab will have the component identifier ``plugin_myplugin`` and the second one will have the component identifier ``plugin_myplugin_2`` (the generated divs will be ``tab_plugin_myplugin`` and ``tab_plugin_myplugin_2`` accordingly). Notice that the first tab is *not* called ``plugin_myplugin_1`` -- as stated above while the ``index`` used as default suffix starts counting at 1, it will not be applied for the first component of a given type. If on the other hand your plugin's definition looks like this: .. code-block:: python return [ dict(type="tab", template="myplugin_first_tab_jinja2", suffix="_1st"), dict(type="tab", template="myplugin_second_tab_jinja2", suffix="_2nd") ] then the generated component identifier will be ``plugin_myplugin_1st`` and ``plugin_myplugin_2nd`` (and the divs will be ``tab_plugin_myplugin_1st`` and ``tab_plugin_myplugin_2nd``). * - div - Id for the div containing the component. If not provided, defaults to ``<type>_plugin_<plugin identifier>`` plus the ``suffix`` if provided or required. * - replaces - Id of the component this one replaces, might be either one of the core components or a component provided by another plugin. A list of the core component identifiers can be found :ref:`in the configuration documentation <sec-configuration-config_yaml-appearance>`. The identifiers of other plugin components always follow the format described above. * - custom_bindings - A boolean value indicating whether the default view model should be bound to the component (``false``) or if a custom binding will be used by the plugin (``true``, default). * - data_bind - Additional knockout data bindings to apply to the component, can be used to add further behaviour to the container based on internal state if necessary. * - classes - Additional classes to apply to the component, as a list of individual classes (e.g. ``classes=["myclass", "myotherclass"]``) which will be joined into the correct format by the template engine. * - styles - Additional CSS styles to apply to the component, as a list of individual declarations (e.g. ``styles=["color: red", "display: block"]``) which will be joined into the correct format by the template engine. Further keys to be included in the dictionary depend on the type: ``sidebar`` type .. list-table:: :widths: 5 95 * - icon - Icon to use for the sidebar header, should be the name of a Font Awesome icon without the leading ``icon-`` part. * - template_header - Additional template to include in the head section of the sidebar item. For an example of this, see the additional options included in the "Files" section. * - classes_wrapper - Like ``classes`` but only applied to the whole wrapper around the sidebar box. * - classes_content - Like ``classes`` but only applied to the content pane itself. * - styles_wrapper - Like ``styles`` but only applied to the whole wrapper around the sidebar box. * - styles_content - Like ``styles`` but only applied to the content pane itself ``tab`` type and ``settings`` type .. list-table:: :widths: 5 95 * - classes_link - Like ``classes`` but only applied to the link in the navigation. * - classes_content - Like ``classes`` but only applied to the content pane itself. * - styles_link - Like ``styles`` but only applied to the link in the navigation. * - styles_content - Like ``styles`` but only applied to the content pane itself. ``wizard`` type .. list-table:: :widths: 5 95 * - mandatory - Whether the wizard step is mandatory (True) or not (False). Optional, defaults to False. If set to True, OctoPrint will sort visually mark the step as mandatory in the UI (bold in the navigation and a little alert) and also sort it into the first half. .. note:: As already outlined above, each template type has a default template name (i.e. the default navbar template of a plugin is called ``<plugin identifier>_navbar.jinja2``), which may be overridden using the template configuration. If a plugin needs to include more than one template of a given type, it needs to provide an entry for each of those, since the implicit default template will only be included automatically if no other templates of that type are defined. Example: If you have a plugin that injects two tab components, one defined in the template file ``myplugin_tab.jinja2`` (the default template) and one in the template ``myplugin_othertab.jinja2``, you might be tempted to just return the following configuration since one your templates is named by the default template name: .. code-block:: python return [ dict(type="tab", template="myplugin_othertab.jinja2") ] This will only include the tab defined in ``myplugin_othertab.jinja2`` though, ``myplugin_tab.jinja2`` will not be included automatically since the presence of a definition for the ``tab`` type overrides the automatic injection of the default template. You'll have to include it explicitly: .. code-block:: python return [ dict(type="tab", template="myplugin_tab.jinja2"), dict(type="tab", template="myplugin_othertab.jinja2") ] :return list: a list containing the configuration options for the plugin's injected templates """ return []
[ "def", "get_template_configs", "(", "self", ")", ":", "return", "[", "]" ]
https://github.com/OctoPrint/OctoPrint/blob/4b12b0e6f06c3abfb31b1840a0605e2de8e911d2/src/octoprint/plugin/types.py#L395-L563
cbfinn/maml_rl
9c8e2ebd741cb0c7b8bf2d040c4caeeb8e06cc95
rllab/algos/cma_es_lib.py
python
CMAEvolutionStrategy.get_selective_mirrors
(self, number=None, pop_sorted=None)
return res
get mirror genotypic directions of the `number` worst solution, based on ``pop_sorted`` attribute (from last iteration). Details: Takes the last ``number=sp.lam_mirr`` entries in ``pop_sorted=self.pop_sorted`` as solutions to be mirrored.
get mirror genotypic directions of the `number` worst solution, based on ``pop_sorted`` attribute (from last iteration).
[ "get", "mirror", "genotypic", "directions", "of", "the", "number", "worst", "solution", "based", "on", "pop_sorted", "attribute", "(", "from", "last", "iteration", ")", "." ]
def get_selective_mirrors(self, number=None, pop_sorted=None): """get mirror genotypic directions of the `number` worst solution, based on ``pop_sorted`` attribute (from last iteration). Details: Takes the last ``number=sp.lam_mirr`` entries in ``pop_sorted=self.pop_sorted`` as solutions to be mirrored. """ if pop_sorted is None: if hasattr(self, 'pop_sorted'): pop_sorted = self.pop_sorted else: return None if number is None: number = self.sp.lam_mirr res = [] for i in range(1, number + 1): res.append(self.mean_old - pop_sorted[-i]) return res
[ "def", "get_selective_mirrors", "(", "self", ",", "number", "=", "None", ",", "pop_sorted", "=", "None", ")", ":", "if", "pop_sorted", "is", "None", ":", "if", "hasattr", "(", "self", ",", "'pop_sorted'", ")", ":", "pop_sorted", "=", "self", ".", "pop_so...
https://github.com/cbfinn/maml_rl/blob/9c8e2ebd741cb0c7b8bf2d040c4caeeb8e06cc95/rllab/algos/cma_es_lib.py#L3530-L3550
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/vesync/switch.py
python
VeSyncLightSwitch.__init__
(self, switch)
Initialize Light Switch device class.
Initialize Light Switch device class.
[ "Initialize", "Light", "Switch", "device", "class", "." ]
def __init__(self, switch): """Initialize Light Switch device class.""" super().__init__(switch) self.switch = switch
[ "def", "__init__", "(", "self", ",", "switch", ")", ":", "super", "(", ")", ".", "__init__", "(", "switch", ")", "self", ".", "switch", "=", "switch" ]
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/vesync/switch.py#L100-L103
rhinstaller/anaconda
63edc8680f1b05cbfe11bef28703acba808c5174
pyanaconda/core/configuration/storage_constraints.py
python
StorageConstraints.must_be_on_linuxfs
(self)
return set(self._get_option("must_be_on_linuxfs").split())
Mount points that must be on a linux file system. :return: a set of mount points
Mount points that must be on a linux file system.
[ "Mount", "points", "that", "must", "be", "on", "a", "linux", "file", "system", "." ]
def must_be_on_linuxfs(self): """Mount points that must be on a linux file system. :return: a set of mount points """ return set(self._get_option("must_be_on_linuxfs").split())
[ "def", "must_be_on_linuxfs", "(", "self", ")", ":", "return", "set", "(", "self", ".", "_get_option", "(", "\"must_be_on_linuxfs\"", ")", ".", "split", "(", ")", ")" ]
https://github.com/rhinstaller/anaconda/blob/63edc8680f1b05cbfe11bef28703acba808c5174/pyanaconda/core/configuration/storage_constraints.py#L115-L120
chribsen/simple-machine-learning-examples
dc94e52a4cebdc8bb959ff88b81ff8cfeca25022
venv/lib/python2.7/site-packages/pandas/indexes/base.py
python
Index._assert_take_fillable
(self, values, indices, allow_fill=True, fill_value=None, na_value=np.nan)
return taken
Internal method to handle NA filling of take
Internal method to handle NA filling of take
[ "Internal", "method", "to", "handle", "NA", "filling", "of", "take" ]
def _assert_take_fillable(self, values, indices, allow_fill=True, fill_value=None, na_value=np.nan): """ Internal method to handle NA filling of take """ indices = _ensure_platform_int(indices) # only fill if we are passing a non-None fill_value if allow_fill and fill_value is not None: if (indices < -1).any(): msg = ('When allow_fill=True and fill_value is not None, ' 'all indices must be >= -1') raise ValueError(msg) taken = values.take(indices) mask = indices == -1 if mask.any(): taken[mask] = na_value else: taken = values.take(indices) return taken
[ "def", "_assert_take_fillable", "(", "self", ",", "values", ",", "indices", ",", "allow_fill", "=", "True", ",", "fill_value", "=", "None", ",", "na_value", "=", "np", ".", "nan", ")", ":", "indices", "=", "_ensure_platform_int", "(", "indices", ")", "# on...
https://github.com/chribsen/simple-machine-learning-examples/blob/dc94e52a4cebdc8bb959ff88b81ff8cfeca25022/venv/lib/python2.7/site-packages/pandas/indexes/base.py#L1523-L1540
SeldonIO/alibi
ce961caf995d22648a8338857822c90428af4765
alibi/confidence/model_linearity.py
python
LinearityMeasure.score
(self, predict_fn: Callable, x: np.ndarray)
return lin
Parameters ---------- predict_fn Prediction function x Instance of interest Returns ------- Linearity measure
[]
def score(self, predict_fn: Callable, x: np.ndarray) -> np.ndarray: """ Parameters ---------- predict_fn Prediction function x Instance of interest Returns ------- Linearity measure """ input_shape = x.shape[1:] if self.is_fit: assert input_shape == self.input_shape if self.method == 'knn': if not self.is_fit: raise ValueError("Method 'knn' cannot be used without calling fit().") lin = _linearity_measure(predict_fn, x, X_train=self.X_train, feature_range=None, method=self.method, nb_samples=self.nb_samples, res=self.res, epsilon=self.epsilon, alphas=self.alphas, model_type=self.model_type, agg=self.agg) elif self.method == 'grid': if not self.is_fit: self.feature_range = np.asarray([[0, 1]] * x.shape[1]) # hardcoded (e.g. from 0 to 1) lin = _linearity_measure(predict_fn, x, X_train=None, feature_range=self.feature_range, method=self.method, nb_samples=self.nb_samples, res=self.res, epsilon=self.epsilon, alphas=self.alphas, model_type=self.model_type, agg=self.agg) else: raise ValueError('Method not understood. Supported methods: "knn", "grid"') return lin
[ "def", "score", "(", "self", ",", "predict_fn", ":", "Callable", ",", "x", ":", "np", ".", "ndarray", ")", "->", "np", ".", "ndarray", ":", "input_shape", "=", "x", ".", "shape", "[", "1", ":", "]", "if", "self", ".", "is_fit", ":", "assert", "in...
https://github.com/SeldonIO/alibi/blob/ce961caf995d22648a8338857822c90428af4765/alibi/confidence/model_linearity.py#L409-L444
pretix/pretix
96f694cf61345f54132cd26cdeb07d5d11b34232
src/pretix/presale/views/customer.py
python
LoginView.form_valid
(self, form)
return HttpResponseRedirect(self.get_success_url())
Security check complete. Log the user in.
Security check complete. Log the user in.
[ "Security", "check", "complete", ".", "Log", "the", "user", "in", "." ]
def form_valid(self, form): """Security check complete. Log the user in.""" customer_login(self.request, form.get_customer()) return HttpResponseRedirect(self.get_success_url())
[ "def", "form_valid", "(", "self", ",", "form", ")", ":", "customer_login", "(", "self", ".", "request", ",", "form", ".", "get_customer", "(", ")", ")", "return", "HttpResponseRedirect", "(", "self", ".", "get_success_url", "(", ")", ")" ]
https://github.com/pretix/pretix/blob/96f694cf61345f54132cd26cdeb07d5d11b34232/src/pretix/presale/views/customer.py#L129-L132
sebastien/cuisine
f6f70268ef1361db66815383017f7c8969002154
src/cuisine.py
python
group_create_linux
(name, gid=None)
Creates a group with the given name, and optionally given gid.
Creates a group with the given name, and optionally given gid.
[ "Creates", "a", "group", "with", "the", "given", "name", "and", "optionally", "given", "gid", "." ]
def group_create_linux(name, gid=None): """Creates a group with the given name, and optionally given gid.""" options = [] if gid: options.append("-g '%s'" % (gid)) sudo("groupadd %s '%s'" % (" ".join(options), name))
[ "def", "group_create_linux", "(", "name", ",", "gid", "=", "None", ")", ":", "options", "=", "[", "]", "if", "gid", ":", "options", ".", "append", "(", "\"-g '%s'\"", "%", "(", "gid", ")", ")", "sudo", "(", "\"groupadd %s '%s'\"", "%", "(", "\" \"", ...
https://github.com/sebastien/cuisine/blob/f6f70268ef1361db66815383017f7c8969002154/src/cuisine.py#L1846-L1851
osmr/imgclsmob
f2993d3ce73a2f7ddba05da3891defb08547d504
pytorch/pytorchcv/models/wrn.py
python
wrn_conv1x1
(in_channels, out_channels, stride, activate)
return WRNConv( in_channels=in_channels, out_channels=out_channels, kernel_size=1, stride=stride, padding=0, activate=activate)
1x1 version of the WRN specific convolution block. Parameters: ---------- in_channels : int Number of input channels. out_channels : int Number of output channels. stride : int or tuple/list of 2 int Strides of the convolution. activate : bool Whether activate the convolution block.
1x1 version of the WRN specific convolution block.
[ "1x1", "version", "of", "the", "WRN", "specific", "convolution", "block", "." ]
def wrn_conv1x1(in_channels, out_channels, stride, activate): """ 1x1 version of the WRN specific convolution block. Parameters: ---------- in_channels : int Number of input channels. out_channels : int Number of output channels. stride : int or tuple/list of 2 int Strides of the convolution. activate : bool Whether activate the convolution block. """ return WRNConv( in_channels=in_channels, out_channels=out_channels, kernel_size=1, stride=stride, padding=0, activate=activate)
[ "def", "wrn_conv1x1", "(", "in_channels", ",", "out_channels", ",", "stride", ",", "activate", ")", ":", "return", "WRNConv", "(", "in_channels", "=", "in_channels", ",", "out_channels", "=", "out_channels", ",", "kernel_size", "=", "1", ",", "stride", "=", ...
https://github.com/osmr/imgclsmob/blob/f2993d3ce73a2f7ddba05da3891defb08547d504/pytorch/pytorchcv/models/wrn.py#L59-L83
ddbourgin/numpy-ml
b0359af5285fbf9699d64fd5ec059493228af03e
numpy_ml/neural_nets/utils/utils.py
python
conv1D
(X, W, stride, pad, dilation=0)
return np.squeeze(Z2D, axis=1)
A faster (but more memory intensive) implementation of a 1D "convolution" (technically, cross-correlation) of input `X` with a collection of kernels in `W`. Notes ----- Relies on the :func:`im2col` function to perform the convolution as a single matrix multiplication. For a helpful diagram, see Pete Warden's 2015 blogpost [1]. References ---------- .. [1] Warden (2015). "Why GEMM is at the heart of deep learning," https://petewarden.com/2015/04/20/why-gemm-is-at-the-heart-of-deep-learning/ Parameters ---------- X : :py:class:`ndarray <numpy.ndarray>` of shape `(n_ex, l_in, in_ch)` Input volume (unpadded) W: :py:class:`ndarray <numpy.ndarray>` of shape `(kernel_width, in_ch, out_ch)` A volume of convolution weights/kernels for a given layer stride : int The stride of each convolution kernel pad : tuple, int, or 'same' The padding amount. If 'same', add padding to ensure that the output of a 1D convolution with a kernel of `kernel_shape` and stride `stride` produces an output volume of the same dimensions as the input. If 2-tuple, specifies the number of padding colums to add *on both sides* of the columns in X. dilation : int Number of pixels inserted between kernel elements. Default is 0. Returns ------- Z : :py:class:`ndarray <numpy.ndarray>` of shape `(n_ex, l_out, out_ch)` The convolution of X with W.
A faster (but more memory intensive) implementation of a 1D "convolution" (technically, cross-correlation) of input `X` with a collection of kernels in `W`.
[ "A", "faster", "(", "but", "more", "memory", "intensive", ")", "implementation", "of", "a", "1D", "convolution", "(", "technically", "cross", "-", "correlation", ")", "of", "input", "X", "with", "a", "collection", "of", "kernels", "in", "W", "." ]
def conv1D(X, W, stride, pad, dilation=0): """ A faster (but more memory intensive) implementation of a 1D "convolution" (technically, cross-correlation) of input `X` with a collection of kernels in `W`. Notes ----- Relies on the :func:`im2col` function to perform the convolution as a single matrix multiplication. For a helpful diagram, see Pete Warden's 2015 blogpost [1]. References ---------- .. [1] Warden (2015). "Why GEMM is at the heart of deep learning," https://petewarden.com/2015/04/20/why-gemm-is-at-the-heart-of-deep-learning/ Parameters ---------- X : :py:class:`ndarray <numpy.ndarray>` of shape `(n_ex, l_in, in_ch)` Input volume (unpadded) W: :py:class:`ndarray <numpy.ndarray>` of shape `(kernel_width, in_ch, out_ch)` A volume of convolution weights/kernels for a given layer stride : int The stride of each convolution kernel pad : tuple, int, or 'same' The padding amount. If 'same', add padding to ensure that the output of a 1D convolution with a kernel of `kernel_shape` and stride `stride` produces an output volume of the same dimensions as the input. If 2-tuple, specifies the number of padding colums to add *on both sides* of the columns in X. dilation : int Number of pixels inserted between kernel elements. Default is 0. Returns ------- Z : :py:class:`ndarray <numpy.ndarray>` of shape `(n_ex, l_out, out_ch)` The convolution of X with W. """ _, p = pad1D(X, pad, W.shape[0], stride, dilation=dilation) # add a row dimension to X to permit us to use im2col/col2im X2D = np.expand_dims(X, axis=1) W2D = np.expand_dims(W, axis=0) p2D = (0, 0, p[0], p[1]) Z2D = conv2D(X2D, W2D, stride, p2D, dilation) # drop the row dimension return np.squeeze(Z2D, axis=1)
[ "def", "conv1D", "(", "X", ",", "W", ",", "stride", ",", "pad", ",", "dilation", "=", "0", ")", ":", "_", ",", "p", "=", "pad1D", "(", "X", ",", "pad", ",", "W", ".", "shape", "[", "0", "]", ",", "stride", ",", "dilation", "=", "dilation", ...
https://github.com/ddbourgin/numpy-ml/blob/b0359af5285fbf9699d64fd5ec059493228af03e/numpy_ml/neural_nets/utils/utils.py#L668-L717
hyperledger/aries-cloudagent-python
2f36776e99f6053ae92eed8123b5b1b2e891c02a
aries_cloudagent/protocols/coordinate_mediation/v1_0/manager.py
python
MediationManager.remove_key
( self, recipient_key: str, message: Optional[KeylistUpdate] = None )
return message
Prepare keylist update remove. Args: recipient_key (str): key to remove message (Optional[KeylistUpdate]): append update to message Returns: KeylistUpdate: Message to send to mediator to notify of key removal.
Prepare keylist update remove.
[ "Prepare", "keylist", "update", "remove", "." ]
async def remove_key( self, recipient_key: str, message: Optional[KeylistUpdate] = None ) -> KeylistUpdate: """Prepare keylist update remove. Args: recipient_key (str): key to remove message (Optional[KeylistUpdate]): append update to message Returns: KeylistUpdate: Message to send to mediator to notify of key removal. """ message = message or KeylistUpdate() message.updates.append( KeylistUpdateRule(recipient_key, KeylistUpdateRule.RULE_REMOVE) ) return message
[ "async", "def", "remove_key", "(", "self", ",", "recipient_key", ":", "str", ",", "message", ":", "Optional", "[", "KeylistUpdate", "]", "=", "None", ")", "->", "KeylistUpdate", ":", "message", "=", "message", "or", "KeylistUpdate", "(", ")", "message", "....
https://github.com/hyperledger/aries-cloudagent-python/blob/2f36776e99f6053ae92eed8123b5b1b2e891c02a/aries_cloudagent/protocols/coordinate_mediation/v1_0/manager.py#L505-L522
CouchPotato/CouchPotatoV1
135b3331d1b88ef645e29b76f2d4cc4a732c9232
cherrypy/_cperror.py
python
HTTPRedirect.__call__
(self)
Use this exception as a request.handler (raise self).
Use this exception as a request.handler (raise self).
[ "Use", "this", "exception", "as", "a", "request", ".", "handler", "(", "raise", "self", ")", "." ]
def __call__(self): """Use this exception as a request.handler (raise self).""" raise self
[ "def", "__call__", "(", "self", ")", ":", "raise", "self" ]
https://github.com/CouchPotato/CouchPotatoV1/blob/135b3331d1b88ef645e29b76f2d4cc4a732c9232/cherrypy/_cperror.py#L282-L284
ucsb-seclab/karonte
427ac313e596f723e40768b95d13bd7a9fc92fd8
eval/multi_bin/all_bins/taint_analysis/coretaint.py
python
CoreTaint.add_taint_glob_dep
(self, master, slave, path)
Add a taint dependency: if master gets untainted, slave should be untainted :param master: master expression :param slave: slave expression :param path: path :return:
Add a taint dependency: if master gets untainted, slave should be untainted :param master: master expression :param slave: slave expression :param path: path :return:
[ "Add", "a", "taint", "dependency", ":", "if", "master", "gets", "untainted", "slave", "should", "be", "untainted", ":", "param", "master", ":", "master", "expression", ":", "param", "slave", ":", "slave", "expression", ":", "param", "path", ":", "path", ":...
def add_taint_glob_dep(self, master, slave, path): """ Add a taint dependency: if master gets untainted, slave should be untainted :param master: master expression :param slave: slave expression :param path: path :return: """ if not self.is_tainted(master): return leafs = list(set([l for l in master.recursive_leaf_asts if self.is_tainted(l)])) key = tuple(map(str, leafs)) if key not in self.get_state(path).globals[GLOB_TAINT_DEP_KEY]: self.get_state(path).globals[GLOB_TAINT_DEP_KEY][key] = [] self.get_state(path).globals[GLOB_TAINT_DEP_KEY][key].append(slave)
[ "def", "add_taint_glob_dep", "(", "self", ",", "master", ",", "slave", ",", "path", ")", ":", "if", "not", "self", ".", "is_tainted", "(", "master", ")", ":", "return", "leafs", "=", "list", "(", "set", "(", "[", "l", "for", "l", "in", "master", "....
https://github.com/ucsb-seclab/karonte/blob/427ac313e596f723e40768b95d13bd7a9fc92fd8/eval/multi_bin/all_bins/taint_analysis/coretaint.py#L624-L639
andyzsf/TuShare
92787ad0cd492614bdb6389b71a19c80d1c8c9ae
tushare/datayes/subject.py
python
Subject.NewsContentByTime
(self, newsPublishDate='', beginTime='', endTime='', field='')
return _ret_data(code, result)
获取某天某一段时间内的新闻全文等信息。输入新闻发布的日期、起止时间,获取该时间段内的新闻全文等信息,如:新闻ID、标题、摘要、正文、来源链接、初始来源、作者、发布来源、发布时间、入库时间等。(注:1、自2014/1/1起新闻来源众多、新闻量日均4万左右,2013年及之前的网站来源少、新闻数据量少;2、数据实时更新。)
获取某天某一段时间内的新闻全文等信息。输入新闻发布的日期、起止时间,获取该时间段内的新闻全文等信息,如:新闻ID、标题、摘要、正文、来源链接、初始来源、作者、发布来源、发布时间、入库时间等。(注:1、自2014/1/1起新闻来源众多、新闻量日均4万左右,2013年及之前的网站来源少、新闻数据量少;2、数据实时更新。)
[ "获取某天某一段时间内的新闻全文等信息。输入新闻发布的日期、起止时间,获取该时间段内的新闻全文等信息,如:新闻ID、标题、摘要、正文、来源链接、初始来源、作者、发布来源、发布时间、入库时间等。", "(", "注:1、自2014", "/", "1", "/", "1起新闻来源众多、新闻量日均4万左右,2013年及之前的网站来源少、新闻数据量少;2、数据实时更新。", ")" ]
def NewsContentByTime(self, newsPublishDate='', beginTime='', endTime='', field=''): """ 获取某天某一段时间内的新闻全文等信息。输入新闻发布的日期、起止时间,获取该时间段内的新闻全文等信息,如:新闻ID、标题、摘要、正文、来源链接、初始来源、作者、发布来源、发布时间、入库时间等。(注:1、自2014/1/1起新闻来源众多、新闻量日均4万左右,2013年及之前的网站来源少、新闻数据量少;2、数据实时更新。) """ code, result = self.client.getData(vs.NEWSCONTENTBYTIME%(newsPublishDate, beginTime, endTime, field)) return _ret_data(code, result)
[ "def", "NewsContentByTime", "(", "self", ",", "newsPublishDate", "=", "''", ",", "beginTime", "=", "''", ",", "endTime", "=", "''", ",", "field", "=", "''", ")", ":", "code", ",", "result", "=", "self", ".", "client", ".", "getData", "(", "vs", ".", ...
https://github.com/andyzsf/TuShare/blob/92787ad0cd492614bdb6389b71a19c80d1c8c9ae/tushare/datayes/subject.py#L67-L72
peplin/pygatt
70c68684ca5a2c5cbd8c4f6f039503fe9b848d24
pygatt/backends/bgapi/packets.py
python
BGAPICommandPacketBuilder.flash_ps_dump
()
return pack('<4B', 0, 0, 1, 1)
[]
def flash_ps_dump(): return pack('<4B', 0, 0, 1, 1)
[ "def", "flash_ps_dump", "(", ")", ":", "return", "pack", "(", "'<4B'", ",", "0", ",", "0", ",", "1", ",", "1", ")" ]
https://github.com/peplin/pygatt/blob/70c68684ca5a2c5cbd8c4f6f039503fe9b848d24/pygatt/backends/bgapi/packets.py#L85-L86
awslabs/gluon-ts
066ec3b7f47aa4ee4c061a28f35db7edbad05a98
src/gluonts/mx/trainer/callback.py
python
Callback.on_validation_batch_end
( self, training_network: nn.HybridBlock )
Hook that is called after each validation batch. This hook is never called if no validation data is available during training. Parameters ---------- training_network The network that is being trained.
Hook that is called after each validation batch. This hook is never called if no validation data is available during training.
[ "Hook", "that", "is", "called", "after", "each", "validation", "batch", ".", "This", "hook", "is", "never", "called", "if", "no", "validation", "data", "is", "available", "during", "training", "." ]
def on_validation_batch_end( self, training_network: nn.HybridBlock ) -> None: """ Hook that is called after each validation batch. This hook is never called if no validation data is available during training. Parameters ---------- training_network The network that is being trained. """
[ "def", "on_validation_batch_end", "(", "self", ",", "training_network", ":", "nn", ".", "HybridBlock", ")", "->", "None", ":" ]
https://github.com/awslabs/gluon-ts/blob/066ec3b7f47aa4ee4c061a28f35db7edbad05a98/src/gluonts/mx/trainer/callback.py#L97-L108
barneygale/quarry
eac47471fc55598de6b4723a728a37d035002237
quarry/types/buffer/v1_7.py
python
Buffer1_7.discard
(self)
Discards the entire buffer contents.
Discards the entire buffer contents.
[ "Discards", "the", "entire", "buffer", "contents", "." ]
def discard(self): """ Discards the entire buffer contents. """ self.pos = len(self.buff)
[ "def", "discard", "(", "self", ")", ":", "self", ".", "pos", "=", "len", "(", "self", ".", "buff", ")" ]
https://github.com/barneygale/quarry/blob/eac47471fc55598de6b4723a728a37d035002237/quarry/types/buffer/v1_7.py#L57-L62
enthought/traitsui
b7c38c7a47bf6ae7971f9ddab70c8a358647dd25
traitsui/qt4/range_editor.py
python
SimpleSliderEditor.update_object_on_scroll
(self, pos)
Handles the user changing the current slider value.
Handles the user changing the current slider value.
[ "Handles", "the", "user", "changing", "the", "current", "slider", "value", "." ]
def update_object_on_scroll(self, pos): """Handles the user changing the current slider value.""" value = self._convert_from_slider(pos) self.control.text.setText(self.string_value(value)) try: self.value = value except Exception as exc: from traitsui.api import raise_to_debug raise_to_debug()
[ "def", "update_object_on_scroll", "(", "self", ",", "pos", ")", ":", "value", "=", "self", ".", "_convert_from_slider", "(", "pos", ")", "self", ".", "control", ".", "text", ".", "setText", "(", "self", ".", "string_value", "(", "value", ")", ")", "try",...
https://github.com/enthought/traitsui/blob/b7c38c7a47bf6ae7971f9ddab70c8a358647dd25/traitsui/qt4/range_editor.py#L168-L177
oilshell/oil
94388e7d44a9ad879b12615f6203b38596b5a2d3
Python-2.7.13/Lib/timeit.py
python
Timer.repeat
(self, repeat=default_repeat, number=default_number)
return r
Call timeit() a few times. This is a convenience function that calls the timeit() repeatedly, returning a list of results. The first argument specifies how many times to call timeit(), defaulting to 3; the second argument specifies the timer argument, defaulting to one million. Note: it's tempting to calculate mean and standard deviation from the result vector and report these. However, this is not very useful. In a typical case, the lowest value gives a lower bound for how fast your machine can run the given code snippet; higher values in the result vector are typically not caused by variability in Python's speed, but by other processes interfering with your timing accuracy. So the min() of the result is probably the only number you should be interested in. After that, you should look at the entire vector and apply common sense rather than statistics.
Call timeit() a few times.
[ "Call", "timeit", "()", "a", "few", "times", "." ]
def repeat(self, repeat=default_repeat, number=default_number): """Call timeit() a few times. This is a convenience function that calls the timeit() repeatedly, returning a list of results. The first argument specifies how many times to call timeit(), defaulting to 3; the second argument specifies the timer argument, defaulting to one million. Note: it's tempting to calculate mean and standard deviation from the result vector and report these. However, this is not very useful. In a typical case, the lowest value gives a lower bound for how fast your machine can run the given code snippet; higher values in the result vector are typically not caused by variability in Python's speed, but by other processes interfering with your timing accuracy. So the min() of the result is probably the only number you should be interested in. After that, you should look at the entire vector and apply common sense rather than statistics. """ r = [] for i in range(repeat): t = self.timeit(number) r.append(t) return r
[ "def", "repeat", "(", "self", ",", "repeat", "=", "default_repeat", ",", "number", "=", "default_number", ")", ":", "r", "=", "[", "]", "for", "i", "in", "range", "(", "repeat", ")", ":", "t", "=", "self", ".", "timeit", "(", "number", ")", "r", ...
https://github.com/oilshell/oil/blob/94388e7d44a9ad879b12615f6203b38596b5a2d3/Python-2.7.13/Lib/timeit.py#L208-L232
dimagi/commcare-hq
d67ff1d3b4c51fa050c19e60c3253a79d3452a39
corehq/form_processor/backends/sql/update_strategy.py
python
_convert_type_check_length
(property_name, value)
[]
def _convert_type_check_length(property_name, value): try: return PROPERTY_TYPE_MAPPING.get(property_name, lambda x: x)(value) except ValueError as e: raise CaseValueError('Error processing case update: Field: {}, Error: {}'.format(property_name, str(e)))
[ "def", "_convert_type_check_length", "(", "property_name", ",", "value", ")", ":", "try", ":", "return", "PROPERTY_TYPE_MAPPING", ".", "get", "(", "property_name", ",", "lambda", "x", ":", "x", ")", "(", "value", ")", "except", "ValueError", "as", "e", ":", ...
https://github.com/dimagi/commcare-hq/blob/d67ff1d3b4c51fa050c19e60c3253a79d3452a39/corehq/form_processor/backends/sql/update_strategy.py#L61-L65
cloudera/hue
23f02102d4547c17c32bd5ea0eb24e9eadd657a4
desktop/core/ext-py/Django-1.11.29/django/core/management/commands/inspectdb.py
python
Command.normalize_col_name
(self, col_name, used_column_names, is_relation)
return new_name, field_params, field_notes
Modify the column name to make it Python-compatible as a field name
Modify the column name to make it Python-compatible as a field name
[ "Modify", "the", "column", "name", "to", "make", "it", "Python", "-", "compatible", "as", "a", "field", "name" ]
def normalize_col_name(self, col_name, used_column_names, is_relation): """ Modify the column name to make it Python-compatible as a field name """ field_params = {} field_notes = [] new_name = col_name.lower() if new_name != col_name: field_notes.append('Field name made lowercase.') if is_relation: if new_name.endswith('_id'): new_name = new_name[:-3] else: field_params['db_column'] = col_name new_name, num_repl = re.subn(r'\W', '_', new_name) if num_repl > 0: field_notes.append('Field renamed to remove unsuitable characters.') if new_name.find(LOOKUP_SEP) >= 0: while new_name.find(LOOKUP_SEP) >= 0: new_name = new_name.replace(LOOKUP_SEP, '_') if col_name.lower().find(LOOKUP_SEP) >= 0: # Only add the comment if the double underscore was in the original name field_notes.append("Field renamed because it contained more than one '_' in a row.") if new_name.startswith('_'): new_name = 'field%s' % new_name field_notes.append("Field renamed because it started with '_'.") if new_name.endswith('_'): new_name = '%sfield' % new_name field_notes.append("Field renamed because it ended with '_'.") if keyword.iskeyword(new_name): new_name += '_field' field_notes.append('Field renamed because it was a Python reserved word.') if new_name[0].isdigit(): new_name = 'number_%s' % new_name field_notes.append("Field renamed because it wasn't a valid Python identifier.") if new_name in used_column_names: num = 0 while '%s_%d' % (new_name, num) in used_column_names: num += 1 new_name = '%s_%d' % (new_name, num) field_notes.append('Field renamed because of name conflict.') if col_name != new_name and field_notes: field_params['db_column'] = col_name return new_name, field_params, field_notes
[ "def", "normalize_col_name", "(", "self", ",", "col_name", ",", "used_column_names", ",", "is_relation", ")", ":", "field_params", "=", "{", "}", "field_notes", "=", "[", "]", "new_name", "=", "col_name", ".", "lower", "(", ")", "if", "new_name", "!=", "co...
https://github.com/cloudera/hue/blob/23f02102d4547c17c32bd5ea0eb24e9eadd657a4/desktop/core/ext-py/Django-1.11.29/django/core/management/commands/inspectdb.py#L172-L226
fortharris/Pcode
147962d160a834c219e12cb456abc130826468e4
Extensions/Settings/ColorScheme/StyleEditor.py
python
StyleEditor.updateForeground
(self, color)
[]
def updateForeground(self, color): self.currentPropertyAttrib[1] = color
[ "def", "updateForeground", "(", "self", ",", "color", ")", ":", "self", ".", "currentPropertyAttrib", "[", "1", "]", "=", "color" ]
https://github.com/fortharris/Pcode/blob/147962d160a834c219e12cb456abc130826468e4/Extensions/Settings/ColorScheme/StyleEditor.py#L202-L203
OpenXenManager/openxenmanager
1cb5c1cb13358ba584856e99a94f9669d17670ff
src/OXM/window_host.py
python
oxcWindowHost.on_treeusers_cursor_changed
(self, widget, data=None)
Selected row in treeusers treeview
Selected row in treeusers treeview
[ "Selected", "row", "in", "treeusers", "treeview" ]
def on_treeusers_cursor_changed(self, widget, data=None): """ Selected row in treeusers treeview """ pass
[ "def", "on_treeusers_cursor_changed", "(", "self", ",", "widget", ",", "data", "=", "None", ")", ":", "pass" ]
https://github.com/OpenXenManager/openxenmanager/blob/1cb5c1cb13358ba584856e99a94f9669d17670ff/src/OXM/window_host.py#L65-L69
IOActive/jdwp-shellifier
e82ec26193861ba58179aae7f3fa93654b7abc8a
jdwp-shellifier.py
python
runtime_exec_payload
(jdwp, threadId, runtimeClassId, getRuntimeMethId, command)
return True
[]
def runtime_exec_payload(jdwp, threadId, runtimeClassId, getRuntimeMethId, command): # # This function will invoke command as a payload, which will be running # with JVM privilege on host (intrusive). # print ("[+] Selected payload '%s'" % command) # 1. allocating string containing our command to exec() cmdObjIds = jdwp.createstring( command ) if len(cmdObjIds) == 0: print ("[-] Failed to allocate command") return False cmdObjId = cmdObjIds[0]["objId"] print ("[+] Command string object created id:%x" % cmdObjId) # 2. use context to get Runtime object buf = jdwp.invokestatic(runtimeClassId, threadId, getRuntimeMethId) if buf[0] != chr(TAG_OBJECT): print ("[-] Unexpected returned type: expecting Object") return False rt = jdwp.unformat(jdwp.objectIDSize, buf[1:1+jdwp.objectIDSize]) if rt is None: print "[-] Failed to invoke Runtime.getRuntime()" return False print ("[+] Runtime.getRuntime() returned context id:%#x" % rt) # 3. find exec() method execMeth = jdwp.get_method_by_name("exec") if execMeth is None: print ("[-] Cannot find method Runtime.exec()") return False print ("[+] found Runtime.exec(): id=%x" % execMeth["methodId"]) # 4. call exec() in this context with the alloc-ed string data = [ chr(TAG_OBJECT) + jdwp.format(jdwp.objectIDSize, cmdObjId) ] buf = jdwp.invoke(rt, threadId, runtimeClassId, execMeth["methodId"], *data) if buf[0] != chr(TAG_OBJECT): print ("[-] Unexpected returned type: expecting Object") return False retId = jdwp.unformat(jdwp.objectIDSize, buf[1:1+jdwp.objectIDSize]) print ("[+] Runtime.exec() successful, retId=%x" % retId) return True
[ "def", "runtime_exec_payload", "(", "jdwp", ",", "threadId", ",", "runtimeClassId", ",", "getRuntimeMethId", ",", "command", ")", ":", "#", "# This function will invoke command as a payload, which will be running", "# with JVM privilege on host (intrusive).", "#", "print", "(",...
https://github.com/IOActive/jdwp-shellifier/blob/e82ec26193861ba58179aae7f3fa93654b7abc8a/jdwp-shellifier.py#L558-L602
dimagi/commcare-hq
d67ff1d3b4c51fa050c19e60c3253a79d3452a39
corehq/apps/reminders/views.py
python
KeywordsListView._fmt_keyword_data
(self, keyword)
return { 'id': keyword.couch_id, 'keyword': keyword.keyword, 'description': keyword.description, 'editUrl': reverse( EditStructuredKeywordView.urlname, args=[self.domain, keyword.couch_id] ) if keyword.is_structured_sms() else reverse( EditNormalKeywordView.urlname, args=[self.domain, keyword.couch_id] ), 'deleteModalId': 'delete-%s' % keyword.couch_id, }
[]
def _fmt_keyword_data(self, keyword): return { 'id': keyword.couch_id, 'keyword': keyword.keyword, 'description': keyword.description, 'editUrl': reverse( EditStructuredKeywordView.urlname, args=[self.domain, keyword.couch_id] ) if keyword.is_structured_sms() else reverse( EditNormalKeywordView.urlname, args=[self.domain, keyword.couch_id] ), 'deleteModalId': 'delete-%s' % keyword.couch_id, }
[ "def", "_fmt_keyword_data", "(", "self", ",", "keyword", ")", ":", "return", "{", "'id'", ":", "keyword", ".", "couch_id", ",", "'keyword'", ":", "keyword", ".", "keyword", ",", "'description'", ":", "keyword", ".", "description", ",", "'editUrl'", ":", "r...
https://github.com/dimagi/commcare-hq/blob/d67ff1d3b4c51fa050c19e60c3253a79d3452a39/corehq/apps/reminders/views.py#L319-L332
XuezheMax/flowseq
8cb4ae00c26fbeb3e1459e3b3b90e7e9a84c3d2b
experiments/translate.py
python
sample
(dataset, dataloader, flownmt, result_path, outfile, tau, n_len, n_tr)
[]
def sample(dataset, dataloader, flownmt, result_path, outfile, tau, n_len, n_tr): flownmt.eval() lengths = [] translations = [] num_insts = 0 start_time = time.time() num_back = 0 for step, (src, tgt, src_masks, tgt_masks) in enumerate(dataloader): trans, lens = flownmt.translate_sample(src, src_masks, n_len=n_len, n_tr=n_tr, tau=tau) translations.append(trans) lengths.append(lens) num_insts += src.size(0) if step % 10 == 0: sys.stdout.write("\b" * num_back) sys.stdout.write(" " * num_back) sys.stdout.write("\b" * num_back) log_info = 'sampling (tau={:.1f}, n_len={}, n_tr={})...{}'.format(tau, n_len, n_tr, num_insts) sys.stdout.write(log_info) sys.stdout.flush() num_back = len(log_info) print('time: {:.1f}s'.format(time.time() - start_time)) outfile = os.path.join(result_path, outfile) dataset.dump_to_file(translations, lengths, outfile, post_edit=False)
[ "def", "sample", "(", "dataset", ",", "dataloader", ",", "flownmt", ",", "result_path", ",", "outfile", ",", "tau", ",", "n_len", ",", "n_tr", ")", ":", "flownmt", ".", "eval", "(", ")", "lengths", "=", "[", "]", "translations", "=", "[", "]", "num_i...
https://github.com/XuezheMax/flowseq/blob/8cb4ae00c26fbeb3e1459e3b3b90e7e9a84c3d2b/experiments/translate.py#L91-L113
vivisect/vivisect
37b0b655d8dedfcf322e86b0f144b096e48d547e
vtrace/platforms/base.py
python
TracerBase.platformSetSignal
(self, sig=None)
Set the current signal to deliver to the process on cont. (Use None for no signal delivery.
Set the current signal to deliver to the process on cont. (Use None for no signal delivery.
[ "Set", "the", "current", "signal", "to", "deliver", "to", "the", "process", "on", "cont", ".", "(", "Use", "None", "for", "no", "signal", "delivery", "." ]
def platformSetSignal(self, sig=None): ''' Set the current signal to deliver to the process on cont. (Use None for no signal delivery. ''' self.setMeta('PendingSignal', sig)
[ "def", "platformSetSignal", "(", "self", ",", "sig", "=", "None", ")", ":", "self", ".", "setMeta", "(", "'PendingSignal'", ",", "sig", ")" ]
https://github.com/vivisect/vivisect/blob/37b0b655d8dedfcf322e86b0f144b096e48d547e/vtrace/platforms/base.py#L683-L688
danmacnish/cartoonify
39ea84d96b3e93f0480e6d6158bea506d01278ca
cartoonify/app/object_detection/models/faster_rcnn_inception_resnet_v2_feature_extractor.py
python
FasterRCNNInceptionResnetV2FeatureExtractor.restore_from_classification_checkpoint_fn
( self, first_stage_feature_extractor_scope, second_stage_feature_extractor_scope)
return variables_to_restore
Returns a map of variables to load from a foreign checkpoint. Note that this overrides the default implementation in faster_rcnn_meta_arch.FasterRCNNFeatureExtractor which does not work for InceptionResnetV2 checkpoints. TODO: revisit whether it's possible to force the `Repeat` namescope as created in `_extract_box_classifier_features` to start counting at 2 (e.g. `Repeat_2`) so that the default restore_fn can be used. Args: first_stage_feature_extractor_scope: A scope name for the first stage feature extractor. second_stage_feature_extractor_scope: A scope name for the second stage feature extractor. Returns: A dict mapping variable names (to load from a checkpoint) to variables in the model graph.
Returns a map of variables to load from a foreign checkpoint.
[ "Returns", "a", "map", "of", "variables", "to", "load", "from", "a", "foreign", "checkpoint", "." ]
def restore_from_classification_checkpoint_fn( self, first_stage_feature_extractor_scope, second_stage_feature_extractor_scope): """Returns a map of variables to load from a foreign checkpoint. Note that this overrides the default implementation in faster_rcnn_meta_arch.FasterRCNNFeatureExtractor which does not work for InceptionResnetV2 checkpoints. TODO: revisit whether it's possible to force the `Repeat` namescope as created in `_extract_box_classifier_features` to start counting at 2 (e.g. `Repeat_2`) so that the default restore_fn can be used. Args: first_stage_feature_extractor_scope: A scope name for the first stage feature extractor. second_stage_feature_extractor_scope: A scope name for the second stage feature extractor. Returns: A dict mapping variable names (to load from a checkpoint) to variables in the model graph. """ variables_to_restore = {} for variable in tf.global_variables(): if variable.op.name.startswith( first_stage_feature_extractor_scope): var_name = variable.op.name.replace( first_stage_feature_extractor_scope + '/', '') variables_to_restore[var_name] = variable if variable.op.name.startswith( second_stage_feature_extractor_scope): var_name = variable.op.name.replace( second_stage_feature_extractor_scope + '/InceptionResnetV2/Repeat', 'InceptionResnetV2/Repeat_2') var_name = var_name.replace( second_stage_feature_extractor_scope + '/', '') variables_to_restore[var_name] = variable return variables_to_restore
[ "def", "restore_from_classification_checkpoint_fn", "(", "self", ",", "first_stage_feature_extractor_scope", ",", "second_stage_feature_extractor_scope", ")", ":", "variables_to_restore", "=", "{", "}", "for", "variable", "in", "tf", ".", "global_variables", "(", ")", ":"...
https://github.com/danmacnish/cartoonify/blob/39ea84d96b3e93f0480e6d6158bea506d01278ca/cartoonify/app/object_detection/models/faster_rcnn_inception_resnet_v2_feature_extractor.py#L173-L214
khanhnamle1994/natural-language-processing
01d450d5ac002b0156ef4cf93a07cb508c1bcdc5
assignment1/.env/lib/python2.7/site-packages/zmq/error.py
python
_check_rc
(rc, errno=None)
internal utility for checking zmq return condition and raising the appropriate Exception class
internal utility for checking zmq return condition and raising the appropriate Exception class
[ "internal", "utility", "for", "checking", "zmq", "return", "condition", "and", "raising", "the", "appropriate", "Exception", "class" ]
def _check_rc(rc, errno=None): """internal utility for checking zmq return condition and raising the appropriate Exception class """ if rc < 0: from zmq.backend import zmq_errno if errno is None: errno = zmq_errno() from zmq import EAGAIN, ETERM if errno == EAGAIN: raise Again(errno) elif errno == ETERM: raise ContextTerminated(errno) else: raise ZMQError(errno)
[ "def", "_check_rc", "(", "rc", ",", "errno", "=", "None", ")", ":", "if", "rc", "<", "0", ":", "from", "zmq", ".", "backend", "import", "zmq_errno", "if", "errno", "is", "None", ":", "errno", "=", "zmq_errno", "(", ")", "from", "zmq", "import", "EA...
https://github.com/khanhnamle1994/natural-language-processing/blob/01d450d5ac002b0156ef4cf93a07cb508c1bcdc5/assignment1/.env/lib/python2.7/site-packages/zmq/error.py#L98-L113
RhetTbull/osxphotos
231d13279296ee4a242d3140d8abe7b5a5bcc9c0
osxphotos/export_db.py
python
ExportDB.set_stat_edited_for_file
(self, filename, stats)
return self._set_stat_for_file("edited", filename, stats)
set stat info for edited version of image (in Photos' library) filename: filename to set the stat info for stat: a tuple of length 3: mode, size, mtime
set stat info for edited version of image (in Photos' library) filename: filename to set the stat info for stat: a tuple of length 3: mode, size, mtime
[ "set", "stat", "info", "for", "edited", "version", "of", "image", "(", "in", "Photos", "library", ")", "filename", ":", "filename", "to", "set", "the", "stat", "info", "for", "stat", ":", "a", "tuple", "of", "length", "3", ":", "mode", "size", "mtime" ...
def set_stat_edited_for_file(self, filename, stats): """set stat info for edited version of image (in Photos' library) filename: filename to set the stat info for stat: a tuple of length 3: mode, size, mtime""" return self._set_stat_for_file("edited", filename, stats)
[ "def", "set_stat_edited_for_file", "(", "self", ",", "filename", ",", "stats", ")", ":", "return", "self", ".", "_set_stat_for_file", "(", "\"edited\"", ",", "filename", ",", "stats", ")" ]
https://github.com/RhetTbull/osxphotos/blob/231d13279296ee4a242d3140d8abe7b5a5bcc9c0/osxphotos/export_db.py#L287-L291
MIC-DKFZ/trixi
193c6cfcbe6c28576d3ee745f8a23f88a8029029
trixi/logger/message/slackmessagelogger.py
python
SlackMessageLogger.show_image
(self, image, *args, **kwargs)
Sends an image file to a chat using an existing slack bot. Args: image (str or np array): Path to the image file to be sent to the chat.
Sends an image file to a chat using an existing slack bot.
[ "Sends", "an", "image", "file", "to", "a", "chat", "using", "an", "existing", "slack", "bot", "." ]
def show_image(self, image, *args, **kwargs): """ Sends an image file to a chat using an existing slack bot. Args: image (str or np array): Path to the image file to be sent to the chat. """ try: if isinstance(image, str): with open(image, 'rb') as img_file: self.send_message(message=self.exp_name, file=img_file) elif isinstance(image, np.ndarray): buf = get_image_as_buffered_file(image) self.send_message(message=self.exp_name, file=buf) except Exception as e: print("Could not send image to slack")
[ "def", "show_image", "(", "self", ",", "image", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "try", ":", "if", "isinstance", "(", "image", ",", "str", ")", ":", "with", "open", "(", "image", ",", "'rb'", ")", "as", "img_file", ":", "self"...
https://github.com/MIC-DKFZ/trixi/blob/193c6cfcbe6c28576d3ee745f8a23f88a8029029/trixi/logger/message/slackmessagelogger.py#L153-L169
GoogleCloudPlatform/PerfKitBenchmarker
6e3412d7d5e414b8ca30ed5eaf970cef1d919a67
perfkitbenchmarker/windows_virtual_machine.py
python
BaseWindowsMixin._SmbclientRemoteCopy
(self, local_path, remote_path, copy_to, network_drive)
Copies a file to or from the VM using smbclient. Args: local_path: Local path to file. remote_path: Optional path of where to copy file on remote host. copy_to: True to copy to vm, False to copy from vm. network_drive: The smb specification for the remote drive (//{ip_address}/{share_name}). Raises: RemoteCommandError: If there was a problem copying the file.
Copies a file to or from the VM using smbclient.
[ "Copies", "a", "file", "to", "or", "from", "the", "VM", "using", "smbclient", "." ]
def _SmbclientRemoteCopy(self, local_path, remote_path, copy_to, network_drive): """Copies a file to or from the VM using smbclient. Args: local_path: Local path to file. remote_path: Optional path of where to copy file on remote host. copy_to: True to copy to vm, False to copy from vm. network_drive: The smb specification for the remote drive (//{ip_address}/{share_name}). Raises: RemoteCommandError: If there was a problem copying the file. """ local_directory, local_file = os.path.split(local_path) remote_directory, remote_file = ntpath.split(remote_path) smb_command = 'cd %s; lcd %s; ' % (remote_directory, local_directory) if copy_to: smb_command += 'put %s %s' % (local_file, remote_file) else: smb_command += 'get %s %s' % (remote_file, local_file) smb_copy = [ 'smbclient', network_drive, '--max-protocol', 'SMB3', '--user', '%s%%%s' % (self.user_name, self.password), '--port', str(self.smb_port), '--command', smb_command ] stdout, stderr, retcode = vm_util.IssueCommand(smb_copy, raise_on_failure=False) if retcode: error_text = ('Got non-zero return code (%s) executing %s\n' 'STDOUT: %sSTDERR: %s' % (retcode, smb_copy, stdout, stderr)) raise errors.VirtualMachine.RemoteCommandError(error_text)
[ "def", "_SmbclientRemoteCopy", "(", "self", ",", "local_path", ",", "remote_path", ",", "copy_to", ",", "network_drive", ")", ":", "local_directory", ",", "local_file", "=", "os", ".", "path", ".", "split", "(", "local_path", ")", "remote_directory", ",", "rem...
https://github.com/GoogleCloudPlatform/PerfKitBenchmarker/blob/6e3412d7d5e414b8ca30ed5eaf970cef1d919a67/perfkitbenchmarker/windows_virtual_machine.py#L324-L359
batiste/django-page-cms
8ba3fa07ecc4aab1013db457ff50a1ebe1ac4d06
pages/templatetags/pages_tags.py
python
pages_breadcrumb
(context, page, url='/')
return context
Render a breadcrumb like menu. Override ``pages/breadcrumb.html`` if you want to change the design. :param page: the current page :param url: not used anymore
Render a breadcrumb like menu.
[ "Render", "a", "breadcrumb", "like", "menu", "." ]
def pages_breadcrumb(context, page, url='/'): """ Render a breadcrumb like menu. Override ``pages/breadcrumb.html`` if you want to change the design. :param page: the current page :param url: not used anymore """ lang = context.get('lang', pages_settings.PAGE_DEFAULT_LANGUAGE) page = get_page_from_string_or_id(page, lang) pages_navigation = None if page: pages_navigation = page.get_ancestors() context.update({'pages_navigation': pages_navigation, 'page': page}) return context
[ "def", "pages_breadcrumb", "(", "context", ",", "page", ",", "url", "=", "'/'", ")", ":", "lang", "=", "context", ".", "get", "(", "'lang'", ",", "pages_settings", ".", "PAGE_DEFAULT_LANGUAGE", ")", "page", "=", "get_page_from_string_or_id", "(", "page", ","...
https://github.com/batiste/django-page-cms/blob/8ba3fa07ecc4aab1013db457ff50a1ebe1ac4d06/pages/templatetags/pages_tags.py#L282-L298
mlflow/mlflow
364aca7daf0fcee3ec407ae0b1b16d9cb3085081
mlflow/utils/autologging_utils/__init__.py
python
get_autologging_config
(flavor_name, config_key, default_value=None)
Returns a desired config value for a specified autologging integration. Returns `None` if specified `flavor_name` has no recorded configs. If `config_key` is not set on the config object, default value is returned. :param flavor_name: An autologging integration flavor name. :param config_key: The key for the desired config value. :param default_value: The default_value to return
Returns a desired config value for a specified autologging integration. Returns `None` if specified `flavor_name` has no recorded configs. If `config_key` is not set on the config object, default value is returned.
[ "Returns", "a", "desired", "config", "value", "for", "a", "specified", "autologging", "integration", ".", "Returns", "None", "if", "specified", "flavor_name", "has", "no", "recorded", "configs", ".", "If", "config_key", "is", "not", "set", "on", "the", "config...
def get_autologging_config(flavor_name, config_key, default_value=None): """ Returns a desired config value for a specified autologging integration. Returns `None` if specified `flavor_name` has no recorded configs. If `config_key` is not set on the config object, default value is returned. :param flavor_name: An autologging integration flavor name. :param config_key: The key for the desired config value. :param default_value: The default_value to return """ config = AUTOLOGGING_INTEGRATIONS.get(flavor_name) if config is not None: return config.get(config_key, default_value) else: return default_value
[ "def", "get_autologging_config", "(", "flavor_name", ",", "config_key", ",", "default_value", "=", "None", ")", ":", "config", "=", "AUTOLOGGING_INTEGRATIONS", ".", "get", "(", "flavor_name", ")", "if", "config", "is", "not", "None", ":", "return", "config", "...
https://github.com/mlflow/mlflow/blob/364aca7daf0fcee3ec407ae0b1b16d9cb3085081/mlflow/utils/autologging_utils/__init__.py#L427-L441
Epistimio/orion
732e739d99561020dbe620760acf062ade746006
src/orion/core/evc/conflicts.py
python
MissingDimensionConflict.detect
(cls, old_config, new_config, branching_config=None)
Detect all missing dimensions in `new_config` based on `old_config` :param branching_config:
Detect all missing dimensions in `new_config` based on `old_config` :param branching_config:
[ "Detect", "all", "missing", "dimensions", "in", "new_config", "based", "on", "old_config", ":", "param", "branching_config", ":" ]
def detect(cls, old_config, new_config, branching_config=None): """Detect all missing dimensions in `new_config` based on `old_config` :param branching_config: """ for conflict in NewDimensionConflict.detect(new_config, old_config): yield cls(old_config, new_config, conflict.dimension, conflict.prior)
[ "def", "detect", "(", "cls", ",", "old_config", ",", "new_config", ",", "branching_config", "=", "None", ")", ":", "for", "conflict", "in", "NewDimensionConflict", ".", "detect", "(", "new_config", ",", "old_config", ")", ":", "yield", "cls", "(", "old_confi...
https://github.com/Epistimio/orion/blob/732e739d99561020dbe620760acf062ade746006/src/orion/core/evc/conflicts.py#L787-L792
pyparallel/pyparallel
11e8c6072d48c8f13641925d17b147bf36ee0ba3
Lib/site-packages/ipython-4.0.0-py3.3.egg/IPython/core/application.py
python
BaseIPythonApplication.load_config_file
(self, suppress_errors=True)
Load the config file. By default, errors in loading config are handled, and a warning printed on screen. For testing, the suppress_errors option is set to False, so errors will make tests fail.
Load the config file.
[ "Load", "the", "config", "file", "." ]
def load_config_file(self, suppress_errors=True): """Load the config file. By default, errors in loading config are handled, and a warning printed on screen. For testing, the suppress_errors option is set to False, so errors will make tests fail. """ self.log.debug("Searching path %s for config files", self.config_file_paths) base_config = 'ipython_config.py' self.log.debug("Attempting to load config file: %s" % base_config) try: Application.load_config_file( self, base_config, path=self.config_file_paths ) except ConfigFileNotFound: # ignore errors loading parent self.log.debug("Config file %s not found", base_config) pass for config_file_name in self.config_files: if not config_file_name or config_file_name == base_config: continue self.log.debug("Attempting to load config file: %s" % self.config_file_name) try: Application.load_config_file( self, config_file_name, path=self.config_file_paths ) except ConfigFileNotFound: # Only warn if the default config file was NOT being used. if config_file_name in self.config_file_specified: msg = self.log.warn else: msg = self.log.debug msg("Config file not found, skipping: %s", config_file_name) except Exception: # For testing purposes. if not suppress_errors: raise self.log.warn("Error loading config file: %s" % self.config_file_name, exc_info=True)
[ "def", "load_config_file", "(", "self", ",", "suppress_errors", "=", "True", ")", ":", "self", ".", "log", ".", "debug", "(", "\"Searching path %s for config files\"", ",", "self", ".", "config_file_paths", ")", "base_config", "=", "'ipython_config.py'", "self", "...
https://github.com/pyparallel/pyparallel/blob/11e8c6072d48c8f13641925d17b147bf36ee0ba3/Lib/site-packages/ipython-4.0.0-py3.3.egg/IPython/core/application.py#L243-L288
fortharris/Pcode
147962d160a834c219e12cb456abc130826468e4
rope/base/history.py
python
History.tobe_undone
(self)
The last done change if available, `None` otherwise
The last done change if available, `None` otherwise
[ "The", "last", "done", "change", "if", "available", "None", "otherwise" ]
def tobe_undone(self): """The last done change if available, `None` otherwise""" if self.undo_list: return self.undo_list[-1]
[ "def", "tobe_undone", "(", "self", ")", ":", "if", "self", ".", "undo_list", ":", "return", "self", ".", "undo_list", "[", "-", "1", "]" ]
https://github.com/fortharris/Pcode/blob/147962d160a834c219e12cb456abc130826468e4/rope/base/history.py#L177-L180
omz/PythonistaAppTemplate
f560f93f8876d82a21d108977f90583df08d55af
PythonistaAppTemplate/PythonistaKit.framework/pylib/site-packages/sqlalchemy/dialects/mysql/base.py
python
TIMESTAMP.__init__
(self, timezone=False, fsp=None)
Construct a MySQL TIMESTAMP type. :param timezone: not used by the MySQL dialect. :param fsp: fractional seconds precision value. MySQL 5.6.4 supports storage of fractional seconds; this parameter will be used when emitting DDL for the TIMESTAMP type. .. note:: DBAPI driver support for fractional seconds may be limited; current support includes MySQL Connector/Python. .. versionadded:: 0.8.5 Added MySQL-specific :class:`.mysql.TIMESTAMP` with fractional seconds support.
Construct a MySQL TIMESTAMP type.
[ "Construct", "a", "MySQL", "TIMESTAMP", "type", "." ]
def __init__(self, timezone=False, fsp=None): """Construct a MySQL TIMESTAMP type. :param timezone: not used by the MySQL dialect. :param fsp: fractional seconds precision value. MySQL 5.6.4 supports storage of fractional seconds; this parameter will be used when emitting DDL for the TIMESTAMP type. .. note:: DBAPI driver support for fractional seconds may be limited; current support includes MySQL Connector/Python. .. versionadded:: 0.8.5 Added MySQL-specific :class:`.mysql.TIMESTAMP` with fractional seconds support. """ super(TIMESTAMP, self).__init__(timezone=timezone) self.fsp = fsp
[ "def", "__init__", "(", "self", ",", "timezone", "=", "False", ",", "fsp", "=", "None", ")", ":", "super", "(", "TIMESTAMP", ",", "self", ")", ".", "__init__", "(", "timezone", "=", "timezone", ")", "self", ".", "fsp", "=", "fsp" ]
https://github.com/omz/PythonistaAppTemplate/blob/f560f93f8876d82a21d108977f90583df08d55af/PythonistaAppTemplate/PythonistaKit.framework/pylib/site-packages/sqlalchemy/dialects/mysql/base.py#L848-L868
bruderstein/PythonScript
df9f7071ddf3a079e3a301b9b53a6dc78cf1208f
PythonLib/full/turtle.py
python
TurtleScreen.register_shape
(self, name, shape=None)
Adds a turtle shape to TurtleScreen's shapelist. Arguments: (1) name is the name of a gif-file and shape is None. Installs the corresponding image shape. !! Image-shapes DO NOT rotate when turning the turtle, !! so they do not display the heading of the turtle! (2) name is an arbitrary string and shape is a tuple of pairs of coordinates. Installs the corresponding polygon shape (3) name is an arbitrary string and shape is a (compound) Shape object. Installs the corresponding compound shape. To use a shape, you have to issue the command shape(shapename). call: register_shape("turtle.gif") --or: register_shape("tri", ((0,0), (10,10), (-10,10))) Example (for a TurtleScreen instance named screen): >>> screen.register_shape("triangle", ((5,-3),(0,5),(-5,-3)))
Adds a turtle shape to TurtleScreen's shapelist.
[ "Adds", "a", "turtle", "shape", "to", "TurtleScreen", "s", "shapelist", "." ]
def register_shape(self, name, shape=None): """Adds a turtle shape to TurtleScreen's shapelist. Arguments: (1) name is the name of a gif-file and shape is None. Installs the corresponding image shape. !! Image-shapes DO NOT rotate when turning the turtle, !! so they do not display the heading of the turtle! (2) name is an arbitrary string and shape is a tuple of pairs of coordinates. Installs the corresponding polygon shape (3) name is an arbitrary string and shape is a (compound) Shape object. Installs the corresponding compound shape. To use a shape, you have to issue the command shape(shapename). call: register_shape("turtle.gif") --or: register_shape("tri", ((0,0), (10,10), (-10,10))) Example (for a TurtleScreen instance named screen): >>> screen.register_shape("triangle", ((5,-3),(0,5),(-5,-3))) """ if shape is None: # image if name.lower().endswith(".gif"): shape = Shape("image", self._image(name)) else: raise TurtleGraphicsError("Bad arguments for register_shape.\n" + "Use help(register_shape)" ) elif isinstance(shape, tuple): shape = Shape("polygon", shape) ## else shape assumed to be Shape-instance self._shapes[name] = shape
[ "def", "register_shape", "(", "self", ",", "name", ",", "shape", "=", "None", ")", ":", "if", "shape", "is", "None", ":", "# image", "if", "name", ".", "lower", "(", ")", ".", "endswith", "(", "\".gif\"", ")", ":", "shape", "=", "Shape", "(", "\"im...
https://github.com/bruderstein/PythonScript/blob/df9f7071ddf3a079e3a301b9b53a6dc78cf1208f/PythonLib/full/turtle.py#L1108-L1141
twilio/twilio-python
6e1e811ea57a1edfadd5161ace87397c563f6915
twilio/rest/conversations/v1/service/__init__.py
python
ServiceInstance.users
(self)
return self._proxy.users
Access the users :returns: twilio.rest.conversations.v1.service.user.UserList :rtype: twilio.rest.conversations.v1.service.user.UserList
Access the users
[ "Access", "the", "users" ]
def users(self): """ Access the users :returns: twilio.rest.conversations.v1.service.user.UserList :rtype: twilio.rest.conversations.v1.service.user.UserList """ return self._proxy.users
[ "def", "users", "(", "self", ")", ":", "return", "self", ".", "_proxy", ".", "users" ]
https://github.com/twilio/twilio-python/blob/6e1e811ea57a1edfadd5161ace87397c563f6915/twilio/rest/conversations/v1/service/__init__.py#L468-L475
miroblog/deep_rl_trader
1aafa451f0f00ad3e27c43241a596a62d608ba72
modified_keras_rl_core/core.py
python
Processor.process_reward
(self, reward)
return reward
Processes the reward as obtained from the environment for use in an agent and returns it. # Arguments reward (float): A reward as obtained by the environment # Returns Reward obtained by the environment processed
Processes the reward as obtained from the environment for use in an agent and returns it.
[ "Processes", "the", "reward", "as", "obtained", "from", "the", "environment", "for", "use", "in", "an", "agent", "and", "returns", "it", "." ]
def process_reward(self, reward): """Processes the reward as obtained from the environment for use in an agent and returns it. # Arguments reward (float): A reward as obtained by the environment # Returns Reward obtained by the environment processed """ return reward
[ "def", "process_reward", "(", "self", ",", "reward", ")", ":", "return", "reward" ]
https://github.com/miroblog/deep_rl_trader/blob/1aafa451f0f00ad3e27c43241a596a62d608ba72/modified_keras_rl_core/core.py#L545-L555
tabacha/ProSafeLinux
a744882dd57e468fe70c4eeb5f91877105d9b069
psl_typ.py
python
PslTyp.get_set_help
(self)
return None
argparse help argument for set operation
argparse help argument for set operation
[ "argparse", "help", "argument", "for", "set", "operation" ]
def get_set_help(self): "argparse help argument for set operation" return None
[ "def", "get_set_help", "(", "self", ")", ":", "return", "None" ]
https://github.com/tabacha/ProSafeLinux/blob/a744882dd57e468fe70c4eeb5f91877105d9b069/psl_typ.py#L66-L68
ypxie/HDGan
d98e2a85f7ae6ce7bfacd1c15e519558d97cb931
HDGan/neuralDist/pretrainedmodels/torchvision.py
python
resnet18
(num_classes=1000, pretrained='imagenet')
return model
Constructs a ResNet-18 model.
Constructs a ResNet-18 model.
[ "Constructs", "a", "ResNet", "-", "18", "model", "." ]
def resnet18(num_classes=1000, pretrained='imagenet'): """Constructs a ResNet-18 model. """ model = models.resnet18(pretrained=False) if pretrained is not None: settings = pretrained_settings['resnet18'][pretrained] model = load_pretrained(model, num_classes, settings) return model
[ "def", "resnet18", "(", "num_classes", "=", "1000", ",", "pretrained", "=", "'imagenet'", ")", ":", "model", "=", "models", ".", "resnet18", "(", "pretrained", "=", "False", ")", "if", "pretrained", "is", "not", "None", ":", "settings", "=", "pretrained_se...
https://github.com/ypxie/HDGan/blob/d98e2a85f7ae6ce7bfacd1c15e519558d97cb931/HDGan/neuralDist/pretrainedmodels/torchvision.py#L158-L165
fatchord/WaveRNN
3595219b2f2f5353f0867a7bb59abcb15aba8831
utils/checkpoints.py
python
restore_checkpoint
(checkpoint_type: str, paths: Paths, model, optimizer, *, name=None, create_if_missing=False)
Restores from a training session saved to disk. NOTE: The optimizer's state is placed on the same device as it's model parameters. Therefore, be sure you have done `model.to(device)` before calling this method. Args: paths: Provides information about the different paths to use. model: A `Tacotron` or `WaveRNN` model to save the parameters and buffers from. optimizer: An optmizer to save the state of (momentum, etc). name: If provided, will restore from a checkpoint with the given name. Otherwise, will restore from the latest weights and optimizer state as specified in `paths`. create_if_missing: If `True`, will create the checkpoint if it doesn't yet exist, as well as update the files specified in `paths` that give the location of the current latest weights and optimizer state. If `False` and the checkpoint doesn't exist, will raise a `FileNotFoundError`.
Restores from a training session saved to disk.
[ "Restores", "from", "a", "training", "session", "saved", "to", "disk", "." ]
def restore_checkpoint(checkpoint_type: str, paths: Paths, model, optimizer, *, name=None, create_if_missing=False): """Restores from a training session saved to disk. NOTE: The optimizer's state is placed on the same device as it's model parameters. Therefore, be sure you have done `model.to(device)` before calling this method. Args: paths: Provides information about the different paths to use. model: A `Tacotron` or `WaveRNN` model to save the parameters and buffers from. optimizer: An optmizer to save the state of (momentum, etc). name: If provided, will restore from a checkpoint with the given name. Otherwise, will restore from the latest weights and optimizer state as specified in `paths`. create_if_missing: If `True`, will create the checkpoint if it doesn't yet exist, as well as update the files specified in `paths` that give the location of the current latest weights and optimizer state. If `False` and the checkpoint doesn't exist, will raise a `FileNotFoundError`. """ weights_path, optim_path, checkpoint_path = \ get_checkpoint_paths(checkpoint_type, paths) if name: path_dict = { 'w': checkpoint_path/f'{name}_weights.pyt', 'o': checkpoint_path/f'{name}_optim.pyt', } s = 'named' else: path_dict = { 'w': weights_path, 'o': optim_path } s = 'latest' num_exist = sum(p.exists() for p in path_dict.values()) if num_exist == 2: # Checkpoint exists print(f'Restoring from {s} checkpoint...') print(f'Loading {s} weights: {path_dict["w"]}') model.load(path_dict['w']) print(f'Loading {s} optimizer state: {path_dict["o"]}') optimizer.load_state_dict(torch.load(path_dict['o'])) elif create_if_missing: save_checkpoint(checkpoint_type, paths, model, optimizer, name=name, is_silent=False) else: raise FileNotFoundError(f'The {s} checkpoint could not be found!')
[ "def", "restore_checkpoint", "(", "checkpoint_type", ":", "str", ",", "paths", ":", "Paths", ",", "model", ",", "optimizer", ",", "*", ",", "name", "=", "None", ",", "create_if_missing", "=", "False", ")", ":", "weights_path", ",", "optim_path", ",", "chec...
https://github.com/fatchord/WaveRNN/blob/3595219b2f2f5353f0867a7bb59abcb15aba8831/utils/checkpoints.py#L79-L128
ucbdrive/3d-vehicle-tracking
8ee189f6792897651bb56bb2950ce07c9629a89d
faster-rcnn.pytorch/lib/model/utils/logger.py
python
Logger.histo_summary
(self, tag, values, step, bins=1000)
Log a histogram of the tensor of values.
Log a histogram of the tensor of values.
[ "Log", "a", "histogram", "of", "the", "tensor", "of", "values", "." ]
def histo_summary(self, tag, values, step, bins=1000): """Log a histogram of the tensor of values.""" # Create a histogram using numpy counts, bin_edges = np.histogram(values, bins=bins) # Fill the fields of the histogram proto hist = tf.HistogramProto() hist.min = float(np.min(values)) hist.max = float(np.max(values)) hist.num = int(np.prod(values.shape)) hist.sum = float(np.sum(values)) hist.sum_squares = float(np.sum(values ** 2)) # Drop the start of the first bin bin_edges = bin_edges[1:] # Add bin edges and counts for edge in bin_edges: hist.bucket_limit.append(edge) for c in counts: hist.bucket.append(c) # Create and write Summary summary = tf.Summary(value=[tf.Summary.Value(tag=tag, histo=hist)]) self.writer.add_summary(summary, step) self.writer.flush()
[ "def", "histo_summary", "(", "self", ",", "tag", ",", "values", ",", "step", ",", "bins", "=", "1000", ")", ":", "# Create a histogram using numpy", "counts", ",", "bin_edges", "=", "np", ".", "histogram", "(", "values", ",", "bins", "=", "bins", ")", "#...
https://github.com/ucbdrive/3d-vehicle-tracking/blob/8ee189f6792897651bb56bb2950ce07c9629a89d/faster-rcnn.pytorch/lib/model/utils/logger.py#L49-L75
glutanimate/review-heatmap
c758478125b60a81c66c87c35b12b7968ec0a348
src/review_heatmap/libaddon/utils.py
python
deepMergeLists
(original, incoming, new=False)
return result
Deep merge two lists. Optionally leaves original intact. Procedure: Reursively call deep merge on each correlated element of list. If item type in both elements are a. dict: Call deepMergeDicts on both values. b. list: Call deepMergeLists on both values. c. any other type: Value is overridden. d. conflicting types: Value is overridden. If incoming list longer than original then extra values are appended. Arguments: original {list} -- original list incoming {list} -- list with updated values new {bool} -- whether or not to create a new list instead of updating original Returns: list -- Merged list Credits: https://stackoverflow.com/a/50773244/1708932
Deep merge two lists. Optionally leaves original intact.
[ "Deep", "merge", "two", "lists", ".", "Optionally", "leaves", "original", "intact", "." ]
def deepMergeLists(original, incoming, new=False): """ Deep merge two lists. Optionally leaves original intact. Procedure: Reursively call deep merge on each correlated element of list. If item type in both elements are a. dict: Call deepMergeDicts on both values. b. list: Call deepMergeLists on both values. c. any other type: Value is overridden. d. conflicting types: Value is overridden. If incoming list longer than original then extra values are appended. Arguments: original {list} -- original list incoming {list} -- list with updated values new {bool} -- whether or not to create a new list instead of updating original Returns: list -- Merged list Credits: https://stackoverflow.com/a/50773244/1708932 """ result = original if not new else deepcopy(original) common_length = min(len(original), len(incoming)) for idx in range(common_length): if (isinstance(result[idx], dict) and isinstance(incoming[idx], dict)): deepMergeDicts(result[idx], incoming[idx]) elif (isinstance(result[idx], list) and isinstance(incoming[idx], list)): deepMergeLists(result[idx], incoming[idx]) else: result[idx] = incoming[idx] for idx in range(common_length, len(incoming)): result.append(incoming[idx]) return result
[ "def", "deepMergeLists", "(", "original", ",", "incoming", ",", "new", "=", "False", ")", ":", "result", "=", "original", "if", "not", "new", "else", "deepcopy", "(", "original", ")", "common_length", "=", "min", "(", "len", "(", "original", ")", ",", ...
https://github.com/glutanimate/review-heatmap/blob/c758478125b60a81c66c87c35b12b7968ec0a348/src/review_heatmap/libaddon/utils.py#L105-L147
ShivamSarodia/ShivyC
e7d72eff237e1ef49ec70333497348baf86be425
shivyc/il_gen.py
python
ILCode.__init__
(self)
Initialize IL code.
Initialize IL code.
[ "Initialize", "IL", "code", "." ]
def __init__(self): """Initialize IL code.""" self.commands = {} self.cur_func = None self.label_num = 0 self.static_inits = {} self.literals = {} self.string_literals = {}
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "commands", "=", "{", "}", "self", ".", "cur_func", "=", "None", "self", ".", "label_num", "=", "0", "self", ".", "static_inits", "=", "{", "}", "self", ".", "literals", "=", "{", "}", "self", ...
https://github.com/ShivamSarodia/ShivyC/blob/e7d72eff237e1ef49ec70333497348baf86be425/shivyc/il_gen.py#L19-L28
UFAL-DSG/tgen
3c43c0e29faa7ea3857a6e490d9c28a8daafc7d0
tgen/rank_nn.py
python
NNRanker._update_nn
(self, bad_feats, good_feats, rate)
Direct call to NN weights update.
Direct call to NN weights update.
[ "Direct", "call", "to", "NN", "weights", "update", "." ]
def _update_nn(self, bad_feats, good_feats, rate): """Direct call to NN weights update.""" self.nn.update(bad_feats, good_feats, rate)
[ "def", "_update_nn", "(", "self", ",", "bad_feats", ",", "good_feats", ",", "rate", ")", ":", "self", ".", "nn", ".", "update", "(", "bad_feats", ",", "good_feats", ",", "rate", ")" ]
https://github.com/UFAL-DSG/tgen/blob/3c43c0e29faa7ea3857a6e490d9c28a8daafc7d0/tgen/rank_nn.py#L79-L81
peplin/pygatt
70c68684ca5a2c5cbd8c4f6f039503fe9b848d24
pygatt/backends/gatttool/device.py
python
GATTToolBLEDevice.register_disconnect_callback
(self, callback)
[]
def register_disconnect_callback(self, callback): self._backend._receiver.register_callback("disconnected", callback)
[ "def", "register_disconnect_callback", "(", "self", ",", "callback", ")", ":", "self", ".", "_backend", ".", "_receiver", ".", "register_callback", "(", "\"disconnected\"", ",", "callback", ")" ]
https://github.com/peplin/pygatt/blob/70c68684ca5a2c5cbd8c4f6f039503fe9b848d24/pygatt/backends/gatttool/device.py#L65-L66
playframework/play1
0ecac3bc2421ae2dbec27a368bf671eda1c9cba5
python/Lib/ctypes/macholib/dyld.py
python
dyld_find
(name, executable_path=None, env=None)
Find a library or framework using dyld semantics
Find a library or framework using dyld semantics
[ "Find", "a", "library", "or", "framework", "using", "dyld", "semantics" ]
def dyld_find(name, executable_path=None, env=None): """ Find a library or framework using dyld semantics """ name = ensure_utf8(name) executable_path = ensure_utf8(executable_path) for path in dyld_image_suffix_search(chain( dyld_override_search(name, env), dyld_executable_path_search(name, executable_path), dyld_default_search(name, env), ), env): if os.path.isfile(path): return path raise ValueError("dylib %s could not be found" % (name,))
[ "def", "dyld_find", "(", "name", ",", "executable_path", "=", "None", ",", "env", "=", "None", ")", ":", "name", "=", "ensure_utf8", "(", "name", ")", "executable_path", "=", "ensure_utf8", "(", "executable_path", ")", "for", "path", "in", "dyld_image_suffix...
https://github.com/playframework/play1/blob/0ecac3bc2421ae2dbec27a368bf671eda1c9cba5/python/Lib/ctypes/macholib/dyld.py#L122-L135
markmckinnon/Autopsy-Plugins
99f8a485bda437eb0508f35fcf843c303bd367c4
Executable Programs For Plugins/Samparse/Database.py
python
SQLiteDb.__init__
(self)
Initializes the database file object.
Initializes the database file object.
[ "Initializes", "the", "database", "file", "object", "." ]
def __init__(self): """Initializes the database file object.""" super(SQLiteDb, self).__init__() self._connection = None self._cursor = None self.filename = None self.read_only = None self.reserved_word_list_dict = {'ABORT':0, 'ACTION':0, 'ADD':0, 'AFTER':0, 'ALL':0, 'ALTER':0, 'ANALYZE':0, 'AND':0, 'AS':0, 'ASC':0, \ 'ATTACH':0, 'AUTOINCREMENT':0, 'BEFORE':0, 'BEGIN':0, 'BETWEEN':0, 'BY':0, 'CASCADE':0, 'CASE':0, \ 'CAST':0, 'CHECK':0, 'COLLATE':0, 'COLUMN':0, 'COMMIT':0, 'CONFLICT':0, 'CONSTRAINT':0, 'CREATE':0, \ 'CROSS':0, 'CURRENT_DATE':0, 'CURRENT_TIME':0, 'CURRENT_TIMESTAMP':0, 'DATABASE':0, 'DEFAULT':0, \ 'DEFERRABLE':0, 'DEFERRED':0, 'DELETE':0, 'DESC':0, 'DETACH':0, 'DISTINCT':0, 'DROP':0, 'EACH':0, \ 'ELSE':0, 'END':0, 'ESCAPE':0, 'EXCEPT':0, 'EXCLUSIVE':0, 'EXISTS':0, 'EXPLAIN':0, 'FAIL':0, 'FOR':0, \ 'FOREIGN':0, 'FROM':0, 'FULL':0, 'GLOB':0, 'GROUP':0, 'HAVING':0, 'IF':0, 'IGNORE':0, 'IMMEDIATE':0, \ 'IN':0, 'INDEX':0, 'INDEXED':0, 'INITIALLY':0, 'INNER':0, 'INSERT':0, 'INSTEAD':0, 'INTERSECT':0, 'INTO':0, \ 'IS':0, 'ISNULL':0, 'JOIN':0, 'KEY':0, 'LEFT':0, 'LIKE':0, 'LIMIT':0, 'MATCH':0, 'NATURAL':0, 'NO':0, \ 'NOT':0, 'NOTNULL':0, 'NULL':0, 'OF':0, 'OFFSET':0, 'ON':0, 'OR':0, 'ORDER':0, 'OUTER':0, 'PLAN':0, \ 'PRAGMA':0, 'PRIMARY':0, 'QUERY':0, 'RAISE':0, 'RECURSIVE':0, 'REFERENCES':0, 'REGEXP':0, 'REINDEX':0, \ 'RELEASE':0, 'RENAME':0, 'REPLACE':0, 'RESTRICT':0, 'RIGHT':0, 'ROLLBACK':0, 'ROW':0, 'SAVEPOINT':0, \ 'SELECT':0, 'SET':0, 'TABLE':0, 'TEMP':0, 'TEMPORARY':0, 'THEN':0, 'TO':0, 'TRANSACTION':0, 'TRIGGER':0, \ 'UNION':0, 'UNIQUE':0, 'UPDATE':0, 'USING':0, 'VACUUM':0, 'VALUES':0, 'VIEW':0, 'VIRTUAL':0, 'WHEN':0, \ 'WHERE':0, 'WITH':0, 'WITHOUT':0}
[ "def", "__init__", "(", "self", ")", ":", "super", "(", "SQLiteDb", ",", "self", ")", ".", "__init__", "(", ")", "self", ".", "_connection", "=", "None", "self", ".", "_cursor", "=", "None", "self", ".", "filename", "=", "None", "self", ".", "read_on...
https://github.com/markmckinnon/Autopsy-Plugins/blob/99f8a485bda437eb0508f35fcf843c303bd367c4/Executable Programs For Plugins/Samparse/Database.py#L10-L31
astropy/astroquery
11c9c83fa8e5f948822f8f73c854ec4b72043016
astroquery/utils/process_asyncs.py
python
async_to_sync
(cls)
return cls
Convert all query_x_async methods to query_x methods (see http://stackoverflow.com/questions/18048341/add-methods-to-a-class-generated-from-other-methods for help understanding)
Convert all query_x_async methods to query_x methods
[ "Convert", "all", "query_x_async", "methods", "to", "query_x", "methods" ]
def async_to_sync(cls): """ Convert all query_x_async methods to query_x methods (see http://stackoverflow.com/questions/18048341/add-methods-to-a-class-generated-from-other-methods for help understanding) """ def create_method(async_method_name): @class_or_instance def newmethod(self, *args, **kwargs): verbose = kwargs.pop('verbose', False) response = getattr(self, async_method_name)(*args, **kwargs) if kwargs.get('get_query_payload') or kwargs.get('field_help'): return response result = self._parse_result(response, verbose=verbose) self.table = result return result return newmethod methods = list(cls.__dict__.keys()) for k in list(methods): newmethodname = k.replace("_async", "") if 'async' in k and newmethodname not in methods: newmethod = create_method(k) newmethod.fn.__doc__ = async_to_sync_docstr( getattr(cls, k).__doc__) newmethod.fn.__name__ = newmethodname newmethod.__name__ = newmethodname functools.update_wrapper(newmethod, newmethod.fn) setattr(cls, newmethodname, newmethod) return cls
[ "def", "async_to_sync", "(", "cls", ")", ":", "def", "create_method", "(", "async_method_name", ")", ":", "@", "class_or_instance", "def", "newmethod", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "verbose", "=", "kwargs", ".", "pop"...
https://github.com/astropy/astroquery/blob/11c9c83fa8e5f948822f8f73c854ec4b72043016/astroquery/utils/process_asyncs.py#L11-L53
FederatedAI/FATE
32540492623568ecd1afcb367360133616e02fa3
python/fate_arch/federation/pulsar/_pulsar_manager.py
python
PulsarManager._create_session
(self)
return s
[]
def _create_session(self): # retry mechanism refers to https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html#urllib3.util.Retry retry = Retry(total=MAX_RETRIES, redirect=MAX_REDIRECT, backoff_factor=BACKOFF_FACTOR) s = requests.Session() # initialize headers s.headers.update({'Content-Type': 'application/json'}) http_adapter = HTTPAdapter(max_retries=retry) s.mount('http://', http_adapter) s.mount('https://', http_adapter) return s
[ "def", "_create_session", "(", "self", ")", ":", "# retry mechanism refers to https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html#urllib3.util.Retry", "retry", "=", "Retry", "(", "total", "=", "MAX_RETRIES", ",", "redirect", "=", "MAX_REDIRECT", ",", "backoff_f...
https://github.com/FederatedAI/FATE/blob/32540492623568ecd1afcb367360133616e02fa3/python/fate_arch/federation/pulsar/_pulsar_manager.py#L34-L45
stoq/stoq
c26991644d1affcf96bc2e0a0434796cabdf8448
stoqlib/lib/validators.py
python
validate_decimal
(value)
return _validate_type(Decimal, value)
Validates an Decimal. Returns if the value is a valid Decimal, or, in case it's a string, if it can be converted to an Decimal.
Validates an Decimal.
[ "Validates", "an", "Decimal", "." ]
def validate_decimal(value): """Validates an Decimal. Returns if the value is a valid Decimal, or, in case it's a string, if it can be converted to an Decimal. """ return _validate_type(Decimal, value)
[ "def", "validate_decimal", "(", "value", ")", ":", "return", "_validate_type", "(", "Decimal", ",", "value", ")" ]
https://github.com/stoq/stoq/blob/c26991644d1affcf96bc2e0a0434796cabdf8448/stoqlib/lib/validators.py#L218-L224
nadineproject/nadine
c41c8ef7ffe18f1853029c97eecc329039b4af6c
staff/views/settings.py
python
helptexts
(request)
return render(request, 'staff/settings/helptexts.html', context)
[]
def helptexts(request): helps = HelpText.objects.all() if helps: latest = HelpText.objects.filter().order_by('-order')[0] latest_order = latest.order + 1 else: latest = None latest_order = 0 selected = None message = None selected_help = request.GET.get('selected_help', None) if selected_help: selected = HelpText.objects.get(title=selected_help) if request.method == "POST": to_update = request.POST.get('id', None) if to_update: updated = HelpText.objects.get(id=to_update) updated.title = request.POST['title'] slug = request.POST['slug'] updated.slug = slugify(slug) updated.template = request.POST['template'] updated.save() return HttpResponseRedirect(reverse('staff:tasks:todo')) else: helptext_form = HelpTextForm(request.POST) slug = slugify(request.POST['slug']) title = request.POST['title'] template = request.POST['template'] order = request.POST['order'] helptext_form = HelpText(title=title, template=template, slug=slug, order=order) helptext_form.save() return HttpResponseRedirect(reverse('staff:tasks:todo')) else: helptext_form = HelpTextForm() context = {'latest_order': latest_order, 'helps': helps, 'helptext_form': helptext_form, 'selected': selected, 'message': message} return render(request, 'staff/settings/helptexts.html', context)
[ "def", "helptexts", "(", "request", ")", ":", "helps", "=", "HelpText", ".", "objects", ".", "all", "(", ")", "if", "helps", ":", "latest", "=", "HelpText", ".", "objects", ".", "filter", "(", ")", ".", "order_by", "(", "'-order'", ")", "[", "0", "...
https://github.com/nadineproject/nadine/blob/c41c8ef7ffe18f1853029c97eecc329039b4af6c/staff/views/settings.py#L93-L133
general03/flask-autoindex
424246242c9f40aeb9ac2c8c63f4d2234024256e
.eggs/Werkzeug-1.0.1-py3.7.egg/werkzeug/wrappers/auth.py
python
WWWAuthenticateMixin.www_authenticate
(self)
return parse_www_authenticate_header(header, on_update)
The `WWW-Authenticate` header in a parsed form.
The `WWW-Authenticate` header in a parsed form.
[ "The", "WWW", "-", "Authenticate", "header", "in", "a", "parsed", "form", "." ]
def www_authenticate(self): """The `WWW-Authenticate` header in a parsed form.""" def on_update(www_auth): if not www_auth and "www-authenticate" in self.headers: del self.headers["www-authenticate"] elif www_auth: self.headers["WWW-Authenticate"] = www_auth.to_header() header = self.headers.get("www-authenticate") return parse_www_authenticate_header(header, on_update)
[ "def", "www_authenticate", "(", "self", ")", ":", "def", "on_update", "(", "www_auth", ")", ":", "if", "not", "www_auth", "and", "\"www-authenticate\"", "in", "self", ".", "headers", ":", "del", "self", ".", "headers", "[", "\"www-authenticate\"", "]", "elif...
https://github.com/general03/flask-autoindex/blob/424246242c9f40aeb9ac2c8c63f4d2234024256e/.eggs/Werkzeug-1.0.1-py3.7.egg/werkzeug/wrappers/auth.py#L23-L33