content stringlengths 39 9.28k | sha1 stringlengths 40 40 | id int64 8 710k |
|---|---|---|
def print_args(args):
"""Convenience function for printing the current value of the input
arguments to the command line.
----------------------------------------------------------------------------
Args:
args: argparse object returned by ArgumentParser.parse_args()
Returns:
None
... | 18548ce7ad9f8683cbebf7bbda5198c97ea5dfd9 | 694,184 |
def find_col_index_with_name(name, trained_schema):
"""
finds the index of the column with name 'name' and returns the index
:param name: name of the column to look for
:type name: str
:param trained_schema:
:type trained_schema: List(dict)
:return: index of the element in trained_schema tha... | 66bc4c9d3f78ba6bf16a03854909787eaad21171 | 669,561 |
def always_true(*args, **kwargs): # pylint: disable=unused-argument
"""
Returns ``True`` whatever the arguments are.
"""
return True | 6f755e48a482dba4a3cccc8dad92cb6fbb610a1b | 19,616 |
def load_file(filename: str) -> list:
"""Load the submarine commands from a file
:param filename: Location of the input file
:return: List of commands
"""
with open(filename) as f:
commands = f.readlines()
commands = [c.split() for c in commands]
return commands | 33d853a5950816ef98b5d57cbd7b9de84aed1cfa | 305,610 |
def isValidArch(sArch):
"""
Validates the CPU architecture name.
"""
if sArch in ('x86', 'amd64', 'sparc32', 'sparc64', 's390', 's390x', 'ppc32', 'ppc64', \
'mips32', 'mips64', 'ia64', 'hppa32', 'hppa64', 'arm', 'alpha'):
return True;
return False; | 52c16150cff896902462bef19384909f341ab784 | 450,072 |
def int32_unpack(var, buff):
"""
Unpack int32.
:param var: variable name, ``str``
:returns: struct unpacking code for an int32
"""
return '(%s,) = _struct_I.unpack(%s)' % (var, buff) | e88935db559ffc139ad72fa77902d4c3c29d584d | 427,820 |
def actual_svg(pathname: str) -> str:
"""Read SVG image from disk."""
with open(pathname, "r") as file:
svg = file.read()
return svg | ba7ae52d3bdbae1d3112a183de2f484f4bcc066d | 20,073 |
def f1_score(tp,fp,tn,fn):
""" Computes F1-score, see http://en.wikipedia.org/wiki/F1_score
:param tp: True positives (TP)
:param fp: False positives (FP)
:param tn: True negatives (TN)
:param fn: False negatives (FN)
:return: F1-score in [0,1]
"""
return 2*tp/float(2*tp + fn + fp) | ad4716db78c16479ed2df17ce5bf07dc76b1b50b | 91,409 |
def unique_word_count(string):
"""
Returns the count of unique words in a string.
"""
words = string.split(" ")
unique_words = set(words)
return len(unique_words) | dad9ef98a60702b695b5a0b9674cd2fc5f6edd53 | 174,169 |
import re
def contentfilter(fsname, pattern):
"""
Filter files which contain the given expression
:arg fsname: Filename to scan for lines matching a pattern
:arg pattern: Pattern to look for inside of line
:rtype: bool
:returns: True if one of the lines in fsname matches the pattern. Otherwise... | ea30d6af9df3adc0986d9eaed9913f1160bd24d3 | 26,094 |
def dictionary2list(element, dictionary):
"""
Converts dictionary to list, prepending element
"""
return [(element, i[0], i[1]) for i in dictionary.iteritems()] | 0c901100583b8a4990c31d9321dc71632392feb3 | 607,496 |
from typing import Dict
def merge_hooks(hooks1: Dict[str, list], hooks2: Dict[str, list]) -> Dict[str, list]:
"""
Overview:
merge two hooks, which has the same keys, each value is sorted by hook priority with stable method
Arguments:
- hooks1 (:obj:`dict`): hooks1 to be merged
- ho... | add5ae72917ca9aff109e8ac86a4d6902c14b298 | 5,614 |
def get_job_tasks(rank, ranks, tasks_tot):
"""
Return a tuple of job task indices for a particular rank.
This function distribute the job tasks in tasks_tot
over all the ranks.
Note
----
This is a primerly a MPI help function.
Parameters
----------
rank : int
Current M... | d61a77d737bc198ac13487999699d4434fd5b290 | 615,920 |
def get_number_rows(ai_settings, defender_width):
"""Determine the number of rows of the defense."""
#random_rows = randint(3,6)
#available_space_x = (ai_settings.screen_width -
#(random_rows * defender_width))
number_rows = 4 #int(available_space_x / (3 * defender_width))
return number_... | 100109eaf0364ec3165e397ddc5fbe63cead7769 | 482,010 |
def has_block_sibling(item):
"""
Test if passed node has block-level sibling element
@type item: ZenNode
@return: bool
"""
return item.parent and item.parent.has_block_children() | f06849f71c6a99e8f4004a038ae424106845c5ff | 58,912 |
import json
def load_json(filename: str) -> dict:
"""Load a json file
Will simply use the `json library <https://docs.python.org/3/library/json.html>` and return the
loaded dictionary.
Args:
filename (str): The file to load
Returns:
dict: The loaded json file contents in a dicti... | ba2bc0c725c80d1fbb0173f5d9f807ad365b25c7 | 212,787 |
def mermin_klyshko_quantum_bound(n):
"""The quantum bound for the Mermin-Klyshko inequality is :math:`2^{3(n-1)/2}`.
:param n: The number of measurement nodes.
:type n: Int
:returns: The quantum bound.
:rtype: Float
"""
return 2 ** (3 * (n - 1) / 2) | 721ca41b19ef72cae77baf1ad6dea5377b6eb67d | 4,740 |
import random
import time
def retry(initial_delay,
max_delay,
factor=2.0,
jitter=0.25,
is_retriable=None):
"""Simple decorator for wrapping retriable functions.
Args:
initial_delay: the initial delay.
factor: each subsequent retry, the delay is multiplied by this v... | 4c62282671d46e1eb1d1720a84f6792380c21995 | 680,376 |
import re
def calc_word_frequency(my_string, my_word):
"""Calculate the number of occurrences of a given word in a given string.
Args:
my_string (str): String to search
my_word (str): The word to search for
Returns:
int: The number of occurrences of the given word in the given st... | 15ff723dd2ff089fb12cccb38283f1f75e37079d | 1,160 |
def css_class(field):
"""
Returns widgets class name in lowercase
"""
return field.field.widget.__class__.__name__.lower() | e6a555199c9b6762758837e0f7794bd69dc7fe09 | 681,578 |
import itertools
import random
import bisect
def weighted_choice(distribution):
"""Choose an element from a weighted distribution.
Algorithm is taken from the documentation for the Python random module.
distribution
A sequence of (element, weight) tuples."""
choices, weights = zip(*distribut... | 0f7f04916904f2164d5bcabe7b27c66c29e41865 | 138,409 |
import io
import csv
def ids_from_csv_file_str(csv_file_str, fieldnames, fieldname):
"""return a set of ids from a string that is the contents of a file string
fieldnames is all the field names in the file
fieldname is one of the fieldnamds that is the id"""
infile = io.StringIO(csv_file_str)
read... | 24d2277bcc1036730d23fd2516642cec2e89926e | 530,344 |
def pv_fullname(name):
""" make sure an Epics PV name ends with .VAL or .SOMETHING!
Parameters
----------
pvname: name of PV
Returns
-------
string with full PV name
"""
name = str(name)
if '.' not in name:
name = "%s.VAL" % name
return name | 5ad60054057a5668ac9cdaab2384d1f65f14f1c7 | 612,747 |
def _gaspr_input(endfin, pendfin, pendfout,
**kwargs):
"""
Write gaspr input.
Parameters
----------
endfin : `int`
tape number for input ENDF-6 file
pendfin : `int`
tape number for input PENDF file
pendfout : `int`
tape number for output PENDF file
... | 70f7208816b37469eb59346e98c43339e5a443c9 | 579,453 |
def shorten(text, length):
"""Truncate the text if it is too long.
"""
if len(text) > length:
pos = text.rfind(' ', 0, length - 2)
if pos == -1:
pos = length - 3
return text[:pos] + "..."
else:
return text | 5ffd470de78534de0b95a999d55ed10edda043ed | 196,944 |
import re
def last_name_first_author(authors):
"""Return displays of info based on the authors field
Selects the last name of the first author
Doctest:
.. doctest::
>>> last_name_first_author('Pimentel, Joao')
'pimentel'
>>> last_name_first_author('Pimentel, Joao and Braganh... | 609e9e72e821dde8360dae645ec2d7a915e67ab5 | 425,119 |
def source_information_from_method(source_method):
"""Obtain source information from a method of a source object.
:param source_method: Source method that is used
:type source_method: method
:returns: string with source information identifying the object that the
method belongs to
:rtype: str
... | 8f6cd465eb4b0979089753ce6cce4cdb96ab8283 | 39,463 |
import functools
def map_wrap(f):
"""Wrap standard function to easily pass into 'map' processing.
"""
@functools.wraps(f)
def wrapper(*args, **kwargs):
return f(*args, **kwargs)
return wrapper | 83e2d9cd2bd36e993dd168a64236095db3608acc | 65,960 |
def get_word_freq_in_sentences(word, sentences):
"""
:param word: the word which frequency we calculate
:param sentences: a list of the sentences, representing the document / search space
:return: the number of occurrences of the given word in the search space. Letter case is ignored
"""... | beeed940dad86259c208ba893b4ae9354b01a115 | 423,060 |
def _get_subclasses(classname):
"""Recursively obtains all subclasses of the given class."""
subclasses = []
for p in classname.__subclasses__():
subclasses.append(p)
subclasses.extend(_get_subclasses(p))
return subclasses | a5edde240c97d8c21109a055593ca488552affa3 | 616,501 |
import ast
def _not_expr(expr: ast.expr) -> ast.expr:
"""Generates AST node for `not expr`."""
return ast.UnaryOp(op=ast.Not(), operand=expr) | 2a0c2cdfc0fe07857661c568a1f45719e76b41e7 | 355,133 |
def _make_cache_key(times, targets):
"""
Make a unique key to reference this combination of ``times`` and ``targets``.
Often, we wish to store expensive calculations for a combination of
``targets`` and ``times`` in a cache on an ``observer``` object. This
routine will provide an appropriate, hasha... | 602cfb9aab0d358d0ca22de82cecc79b084dd590 | 382,583 |
def len_selfie(molecule):
"""Returns the length of selfies <molecule>, in other words, the
number of characters in the sequence."""
return molecule.count('[') + molecule.count('.') | 2eb96c839c94778a9f54c0f89633dea0edcbba46 | 232,902 |
def crop_roi(im, bbox):
"""Crops ROI
:param im: (np.ndarray) image BGR
:param bbox: (BBox)
:returns (np.ndarray) BGR image ROi
"""
dim = im.shape[:2][::-1]
x1, y1, x2, y2 = bbox.xyxy_int
im_roi = im[y1:y2, x1:x2]
return im_roi | 5952d6617e3cf4e24e5aff2fb8527d5e7daba8b0 | 220,583 |
def _create_ip_range(range_start, range_end):
"""
Given a start ip, eg 192.168.1.1, and an end ip, eg 192.168.1.254,
generate a list of all of the ips within that range, including
the start and end ips.
"""
ip_range = []
start = int(range_start[range_start.rfind('.')+1:])
end = int(range... | af3d96862c0522d3737c2587ff0c57477fc4cad3 | 618,427 |
def absolute(value):
"""
Get the absolute value for "value". This template tag is a wrapper for
pythons "abs(...)" method.
Usage:
>>> absolute(-5)
5
"""
try:
return abs(value)
except:
return value | be4e5a28b1983a83f83f89bb483fcc1797be06b8 | 298,548 |
def lcsplit(lcstate):
"""Splits a composite lcstate and availability string into a tuple"""
return lcstate.split('_', 1) | e6f01568317c07643dc63357adee34732ad0b6e6 | 490,548 |
def exclusion_payload(passed_keywords: dict) -> dict:
"""Create a properly formatted exclusion payload.
{
"comment": "string",
"groups": [
"string"
],
"value": "string"
}
"""
returned_payload = {}
if passed_keywords.get("comment", None):
retur... | d9578ae0b6a84b4c0a7d73a2d05e8fa4e5d5af3c | 103,276 |
import re
def _remove_extra_spaces_from_text(text: str) -> str:
"""
Replace multiple spaces with a single space
"""
return re.sub(r'\s+', ' ', text) | b2bb7977190145cdf038644830decac7d4743f9d | 455,185 |
def escape_markdown(content):
"""
Escapes markdown from the given content.
Parameters
----------
content : `None` or `str`
The content to sanitize.
Returns
-------
content : `None` or `str`
"""
if (content is None):
return
content = content.repl... | 4e8cc969aead0232a712b87fc4c5a8f78bda1037 | 508,791 |
import importlib
def import_cpp(name):
"""
Import jet generated cpp as module
Args:
name (str) The name (corresponding to the compile_cpp name given)
Returns:
Compiled and imported Python module
"""
try:
return importlib.import_module('jet_generated.' + name)
except ... | 5fdf871283cc207efe0360d5dbb4dfbfb10e768d | 289,123 |
def mag_squared(x):
"""
Return the squared magnitude of ``x``.
.. note::
If ``x`` is an uncertain number, the magnitude
squared is returned as an uncertain real number,
otherwise :func:``abs(x)**2`` is returned.
"""
try:
return x._mag_squared()
except ... | 2fdc8527242b00549201efd79d86089ccdb0e10c | 261,108 |
def bisect_right(arr, x):
"""Binary search array to find (right-most) x."""
lo, hi = 0, len(arr)
while lo < hi:
mid = lo + hi >> 1
if arr[mid] <= x: lo = mid + 1
else: hi = mid
return lo | 05985287fa1ea7fbe1ef3d3105f95460692a4afd | 603,979 |
def parse_copy_availability(line):
"""Parses 'Status-'line for availability.
:param line: Line string.
:type line: str
:return: Availability.
:rtype: bool
"""
if 'Entliehen' in line:
return False
elif 'Verfügbar' in line:
return True
else:
return False | c027bc6ee9f3a33c18f4eece47fa9e409354ba8d | 677,511 |
def search_for_attr_value(obj_list, attr, value):
"""
Finds the first (not necesarilly the only) object in a list, where its
attribute 'attr' is equal to 'value', returns None if none is found.
"""
return next((obj for obj in obj_list if getattr(obj,attr, None) == value), None) | 2e92b69d253158747194cbd9d9415df9078ffc4c | 601,853 |
import requests
def zenodo_file_download_helper(auth_parameter, is_record, project_name, metadata_helper, files):
"""
Downloads a single file from Zenodo and returns the expected dictionary.
Parameters
----------
auth_parameter : dict
The Authentication parameter expected by Zenodo.
i... | f14d8ee8be9e257331f4768c9cb64f29c358031f | 422,945 |
def test(env, *args, **kwargs):
"""build Program with fixed RPATH"""
denv = env.Clone()
denv.AppendUnique(RPATH=["$PREFIX/lib"])
return denv.Program(*args, **kwargs) | c7121ce1551a5130d1b6e031486b87a4edad4ce9 | 607,525 |
def _entities_years_list_to_dict(l):
"""
Create a dict of entites by year
:param l: list which each element is a size two tuple (year, entity_id
:return: a dict in which each key is a year and each value is a list of entities
:rtype: dict<int,list>
"""
d = {}
for y, eid in l:
y =... | 6a82707aeb7a9663297970d5bda03c3bd1041a15 | 335,705 |
from pathlib import Path
def maybe_start_with_home_prefix(p: Path) -> Path:
"""
If the input path starts with the home directory path string, then return
a path that starts with the home directory and points to the same location.
Otherwise, return the path unchanged.
"""
try:
return Pa... | 6ee4e49e8dfb9bc68a1c10f5ea792715fb5d5336 | 4,531 |
def to_world_canvas(world_point, canvas_extents, world_extents):
"""Transforms a point from world coord system to world canvas coord system."""
x = int(world_point[0] / world_extents[0] * canvas_extents[0])
y = int(canvas_extents[1] - 1 - world_point[1] / world_extents[1] * canvas_extents[1])
return (x,... | 5dec7f87fae35542b5798f88b0353c9b593e88fb | 49,369 |
from typing import Iterable
import functools
from operator import getitem
def get_in(keys: Iterable):
"""Creates a function that returns coll[i0][i1]...[iX] where [i0, i1, ..., iX]==keys.
>>> get_in(["a", "b", 1])({"a": {"b": [0, 1, 2]}})
1
"""
def get_in(coll):
return functools.reduce(... | b04c67beb2a9bf6f969b0f4193e5dc49f4d9bbf4 | 658,263 |
def get_high_lows_lookback(high, low, lookback_days):
"""
Get the highs and lows in a lookback window.
Parameters
----------
high : DataFrame
High price for each ticker and date
low : DataFrame
Low price for each ticker and date
lookback_days : int
The number of ... | d24905db2ae2425f7d57e3af503802c597d0c212 | 30,698 |
import torch
def optim_method(name):
"""Get optimizer."""
method = {"sgd": torch.optim.SGD, "adam": torch.optim.Adam}
return method[name] | 69930ad96d2977592809a72511381462b6450f7f | 354,952 |
import json
def load_concepts(concept_fpath):
"""
Load stored concepts
Params:
concept_fpath (str): file-path to stored concepts
Returns: the dict containing the report (stored) concepts
"""
with open(concept_fpath, 'r') as f:
concepts = json.load(f)
return concepts | bd75cab139556cdc95446c2c5505f56014c1ae77 | 236,987 |
def solution(A):
"""
On the face of it this is quite simple, until you factor in negative
numbers.
Approach is very simple:
1. Sort array in descending order (or ascending if you like)
2. Take the max value in between the sum of the head of the array and the first
element of the array c... | ad8b58e8bb9fe9959afed7b95f7abdbe05742a11 | 606,258 |
import textwrap
def _textwrap_wrap(string, justify):
"""
Custom instantiation of textwrap.wrap() to account for new lines in string.
"""
output = []
for line in string.splitlines():
justified = textwrap.wrap(
line, justify,
break_long_words=False, replace_whitespac... | b16e0865919dcfc688ea990928dde4a7fe79f56b | 232,806 |
import functools
def memoize(func, cache, num_args):
"""
Wrap a function so that results for any argument tuple are stored in
'cache'. Note that the args to the function must be usable as dictionary
keys.
Only the first num_args are considered when creating the key.
"""
@functools.wraps(f... | b12ff23b822d18a3a0e6a5f6db497d8e67114369 | 84,932 |
from typing import Union
from typing import List
def read_file(file_path: str, split: bool = False) -> Union[str, List[str]]:
"""
Reads a text file.
>>> from snakypy import helpers
>>> file = '/tmp/my_file.txt'
>>> helpers.files.create_file('My content file', file, force=True)
True
>>> he... | af2429f9d696a693b89c0fa33200e453906ee0c8 | 29,791 |
def select_value_from_list(text, value_list):
"""
:param text: value (case insensitive) or index of value list or None
:param value_list: list of strings to choose from
:return: chosen value, or if text is None, None
:raises ValueError: if the string is not a valid value and not an index
:raises... | be1b316da9a68cb215187449bba33c1a2fc0ab71 | 246,456 |
def sumatorio_tope(tope):
"""
Va sumando números naturales hasta llegar al tope.
Ejemplos
--------
>>> sumatorio_tope(9)
6
# 1 + 2 + 3
>>> sumatorio_tope(10)
10 # 1 + 2 + 3 + 4
>>> sumatorio_tope(12)
10 # 1 + 2 + 3 + 4
>>> sumatorio_tope(16)
1... | c8a0307f5876b2eb641edc10a4dc93ad38270e95 | 647,167 |
def pow2(x):
"""Return the square of x
:param float x: input value
:rtype: float
"""
return x*x | 955e83c526430582a542eb6c3b1d2ab92d7bff61 | 674,621 |
def epc_calc_bin_mode(reg_dict):
"""
Get the current binning modes
Parameters
----------
reg_dict : dict
The dictionary that contains all the register information
Returns
----------
bool
Row binning mode
bool
Column binning mode
"""
bin_mode = reg... | 551a36dc130c3c5b4048acadf50d108dc9100390 | 102,383 |
def is_absolute_url(parsed_url):
""" check if it is an absolute url """
return all([parsed_url.scheme, parsed_url.netloc]) | 578c1443ec18f9b741cd205763604cba2242ac48 | 5,952 |
import math
def regular_poly_side_length_to_apothem(n_sides, side_length):
"""Compute apothem for regular polygon with given side length."""
return side_length / (2 * math.tan(math.pi / n_sides)) | 38969b7d33086b9b9fd39f8b49b25001da595c97 | 525,077 |
from typing import Any
from typing import Callable
def ask_for_input(
question: str, default: Any = None, callback: Callable[[Any], Any] = str
) -> Any:
"""
Ask for input from the user at the command line.
Parameters
----------
question
A string to display as a prompt for the user.
... | d43b2b9d954b8e0f3984b5937156e886a2f54c59 | 367,126 |
from typing import Any
def _convert_sql_format(value: Any) -> str:
"""
Given a Python value, convert to string representation
of the equivalent SQL datatype.
:param value: A value, ie: a literal, a variable etc.
:return: The string representation of the SQL equivalent.
>>> _convert_sql_format(... | 7e1728c19fb8698694ac194e60d76b2bddaf9c41 | 45,036 |
import json
def CheckJsonParses(input_api, output_api):
"""Verifies that all JSON files at least parse as valid JSON."""
affected_files = input_api.AffectedFiles(
include_deletes=False,
file_filter=lambda x: x.LocalPath().endswith('.json'))
warnings = []
for f in affected_files:
with open(f.Ab... | 23723bca79f110e5c161509127241aa901c8a056 | 457,468 |
from pathlib import Path
import gzip
def as_file_handle(filepath, mode):
"""Return a file-handle from a given file path.
Infers if file is compressed or not based on extension.
Parameters
----------
filepath : str or pathlib.Path
Path to file to open. If file name ends in 'gz', will
... | f49452b2f22f2501edf139259cf0e6b3e4b83368 | 175,048 |
def format_message(date_str, node, msg):
"""Format log message"""
message = f"{date_str}: {node.site_name}: {node.location or node.model} ({node.serial}) {msg}"
return message | 53dc7e2716f935a083c36e40ad4887cfe23c0aad | 14,089 |
def __getmappingcases__(mapping, value):
"""
Gets index of case value in mapping.
:param mapping: mapping dictionary
:param value: value for which the mapping is searched for
:return: index of value in mapping
"""
if value in mapping["cases"]:
return mapping["cases"].index(value)
... | 53fde9936da9e8b7a099e209ac824d370f225bfb | 149,681 |
def can_ship(weight, distance):
"""
Determines if we can ship a package based on its weight,
and distance traveled.
"""
if weight * distance < 1000:
return True
else:
return False | 63373b6fb11caf772180266e60ba3011ae87b625 | 424,257 |
def mel2hz(mel, formula="htk"):
"""
Convert the mel-scale representation of a signal into Hz
Parameters
----------
mel : :py:class:`ndarray <numpy.ndarray>` of shape `(N, \*)`
An array of mel frequencies to convert
formula : {"htk", "slaney"}
The Mel formula to use. "htk" uses t... | 67dab362223ceda0d211aa22b2ee20805fdde48f | 316,999 |
def dict_map(f, d):
"""Apply function f to all terminal elements of dict d."""
if isinstance(d, dict):
return {k: dict_map(f, v) for k, v in d.items()}
elif isinstance(d, list):
return [dict_map(f, x) for x in d]
else:
return f(d) | 8abcb5df97ae6ff5c28361fdcf1a723dfe5b5640 | 139,166 |
def calculate_gruneisen_parameter_from_temperature(temperature_in_celcius):
"""
This function returns the dimensionless gruneisen parameter based on a heuristic formula that
was determined experimentally::
@book{wang2012biomedical,
title={Biomedical optics: principles and imaging},
... | 248214c393e52e24d301e3d79159ab9dfc9b0c6c | 211,200 |
def find_correspondance_date(index, csv_file):
"""
The method returns the dates reported in the csv_file for the i-subject
:param index: index corresponding to the subject analysed
:param csv_file: csv file where all the information are listed
:return date
"""
return csv_f... | 915b9a493247f04fc1f62e614bc26b6c342783c8 | 706,074 |
def tag_filter(tag_list, base_df):
"""Search with tags.
Args:
base_df (DataFrame): Search target.
tag_list (list): List of search tag.
Returns:
(DataFrame): Searched DataFrame.
"""
result_df = base_df
for tag in tag_list:
mask = result_df["tag"].apply(lambda x:... | fe6a9f075d859167d3ec160b96c7f839db394154 | 663,872 |
def parse_authmap(fp):
"""
Low level parser for authmap files. Takes a file pointer to an open authmap
file and parses it into a dict.
The returned dict will be composed as follows:
- The keys are the names of local entities (users or groups)
- The values are lists of authorized LDAP entiti... | cfe4e5d53df4b208c14b76b02001b77c54d4b5c4 | 564,098 |
def add_inputs(input_1: float, input_2: float, *extra) -> float:
"""
adds 2 or more numbers together
:param input_1: first number
:type input_1: float
:param input_2: second number
:type input_2: float
:return: all the inputs added together
:rtype: float
"""
... | a28e92787f51a2b4525562dcfb74ffd9a3c61d3b | 639,442 |
import math
def angle_vector_2D(v1, v2):
"""
Return angle between two 2D vectors (i.e. use only x and y coordinate values)
Angle (from v1 to v2, positive angle of rotation) is in the range -pi < x < pi.
"""
dot = v1[0] * v2[0] + v1[1] * v2[1] # dot product
det = v1[0] * v2[1] - v1[1] * v2[0] #... | 33addb9c0cacbc0a391e4c6267af9dce486c46be | 588,839 |
import re
def is_qt_example(example):
"""
Is the example a Qt example?
:param example: The example.
:return: True if it is a Qt example.
"""
reg = re.compile(r".*Qt.*", re.DOTALL)
return reg.match(example) | 28ac55ac65be28202e1fc01d78406909a0e5d5d7 | 338,701 |
def python2iraf(x1, x2, y1, y2):
"""
Convert from Pythonic indexes to IRAFonic indexes.
Args:
x1: int
x2: int
y1: int
y2: int
Returns:
section : str
"""
s = '[{:1d}:{:1d}, {:1d}:{:1d}]'.format(x1 + 1, x2, y1 + 1, y2)
return s | 8035656637430c9b6ecf67cf9a9c14b8df68d87b | 415,306 |
def identifyCategoricalFeatures(x_data,categorical_cutoff):
""" Takes a dataframe (of independent variables) with column labels and returns a list of column names identified as
being categorical based on user defined cutoff. """
categorical_variables = []
for each in x_data:
if x_data[each].nuni... | 531eb49871155b5042de08b0c7b3189a15e55ca2 | 652,363 |
def batch_eye_like(tensor):
"""
Creates a sequence of identity tensors indicted by the batch size with the
shape of the input tensor
Parameters
----------
tensor: Tensor (b, n, ..., n)
b tensors with the same shape
Returns
-------
Tensor (b, n, ..., n)
b identit... | ef86884a79ec3ff62c02eb3aea15ea7373a766ef | 405,047 |
def cli(ctx, toolShed_id):
"""Get details of a given Tool Shed repository as it is installed on this Galaxy instance.
"""
return ctx.gi.toolshed.show_repository(toolShed_id) | c69c0711c68ccd8a55ec5a95e2bc56f7e7246b29 | 130,006 |
def check_who_queued(user):
"""
Returns a function that checks if the song was requested by user
"""
def pred(song):
if song.requested_by and song.requested_by.id == user.id:
return True
return False
return pred | e53a1434077ec7b97e237d1ff8bcc8c2454c4015 | 702,539 |
def _t(a):
"""transpose the last two axes of a three axis array"""
return a.transpose((0, 2, 1)) | 91911a8863136538f3f419e20e4515f28d85d859 | 501,211 |
from typing import OrderedDict
def sorted_dict(d: dict):
"""
Returns OrderedDict sorted by ascending key
:param d: dict
:return: OrderedDict
"""
return OrderedDict(sorted(d.items())) | 46e550f428841d66601a4e36c654dd450f0231ed | 473,221 |
def my_vtk_grid_props(vtk_reader):
"""
Get grid properties from vtk_reader instance.
Parameters
----------
vtk_reader: vtk Reader instance
vtk Reader containing information about a vtk-file.
Returns
----------
step_x : float
For regular grid, stepsize in x-direction.
... | 26ef8a51648ea487372ae06b54c8ccf953aeb414 | 3,408 |
from typing import Dict
def failed_chunk(event: Dict, _c: Dict) -> Dict:
"""
Lambda function to handle a failed chunk to allow processing to continue.
:param event: lambda expected event object
:param _c: lambda expected context object (unused)
:returns: remaining records to be processed
"""
... | 75ed7fc0cb410099d111fd9bf4e03578e654c0ad | 550,624 |
def index(seq, i):
""" Returns the ith element in the sequence `seq`. """
return seq[i] | 3ff17125a70154daece8df742109ae1c7e78878c | 584,934 |
def poly_points(P, T):
"""
Returns the ordered points from the given polygons
Parameters
----------
P : Tensor
a (N, D,) points set tensor
T : LongTensor
a (M, T,) topology tensor
Returns
-------
tuple
a tuple containing the points of the given polygons
... | 2fed449c71766d20e3cb48c518eca8a6b725eb1f | 453,218 |
def rotl(num, shift):
"""Rotate left"""
return ((num << shift) | (num >> (32 - shift))) & 0xFFFFFFFF | 9f4f95fc5423366ca777d3876fe2a75eaaf65c12 | 284,847 |
def init_feed(feed):
"""
Initialise a feed
:param feed: Feed
:return: tf.data.Iterator.initializer
:return: tensor slices
"""
feed = feed.feed
iterator_tensor = feed.make_initializable_iterator()
return iterator_tensor.initializer, iterator_tensor.get_next() | 3d9148a4bc064883aad22c771fe68cf5551dd60f | 51,564 |
def _pandas_in_schemas(schemas):
"""
Check if any schema contains pandas metadata
"""
has_pandas = False
for schema in schemas:
if schema.metadata and b"pandas" in schema.metadata:
has_pandas = True
return has_pandas | ec5bdb8f3431883f7f5bace86ebbb3a0d46e1c91 | 329,856 |
import string
def find_words(text):
"""
text: string
Returns a list of words from input text
"""
text = text.replace("\n", " ")
for char in string.punctuation:
text = text.replace(char, "")
words = text.split(" ")
return words | 86c2691b9f0e57e758f7bc2d5b8fa51adcc1ebc0 | 661,537 |
def format_attr_value(entry, attr):
""" Helper that formats attribute to be presented in the table output.
Args:
entry (Dict[str, str]): CONFIG DB entry configuration.
attr (Dict): Attribute metadata.
Returns:
str: fomatted attribute value.
"""
if attr["is-leaf-list"]:
... | 30de403f26a5fd1ae12758c461e94beda79fccd1 | 489,382 |
def hard_mish(x, inplace: bool = False) :
"""Implements the HardMish activation function
Args:
x: input tensor
Returns:
output tensor
"""
if inplace:
return x.mul_(0.5 * (x + 2).clamp(min=0, max=2))
else:
return 0.5 * x * (x + 2).clamp(min=0, max=2) | f2ad1e6604596e0bab73564ca67a2c4e2a7f1141 | 236,895 |
def misclassification_rate(preds, alt_preds, k=1):
"""
Computes the misclassification rate for a group of base and alternative predictions.
For details, check: Narodytska, Nina, and Shiva Prasad Kasiviswanathan. "Simple black-box
adversarial perturbations for deep networks." arXiv preprint arXiv:1612.06... | 37323d9036e06d5db4cc6e8873c45bf4242183ab | 458,987 |
def _concat_lists_safe(A, B):
""" Safely concatenate two lists if one or both may be None """
if A is None and B is None:
return None
elif isinstance(A, list) and B is None:
return A
elif isinstance(B, list) and A is None:
return B
elif isinstance(A, list) and isinstance(B, ... | 8254127958320aceea58c1e82c321a5c7fbdf493 | 604,834 |
def getIntUserResponse(uio, prompt, allowQuit=True):
"""Get int repsonse from user.
If allowQuit is True and the user enters q then None is returned to
indicate that the user selected quit."""
while True:
response = uio.getInput(prompt=prompt)
try:
return int(response... | 2bf06c8d8dc3af4955d743a94e2d640793a233c0 | 184,066 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.