content
stringlengths
35
416k
sha1
stringlengths
40
40
id
int64
0
710k
def _to_bool(value): """Simplified version of the bool filter. Avoids having a dependency on Ansible in unit tests. """ if value == 'yes': return True if value == 'no': return False return bool(value)
6e0da8b211ce638e19764a966c417841fafe2a5b
13,102
import math def tan(x): """tan(x) Return the tangent of x.""" x = complex(x, 0) sr = math.sin(x.real) cr = math.cos(x.real) shi = math.sinh(x.imag) chi = math.cosh(x.imag) rs = sr * chi is_ = cr * shi rc = cr * chi ic = -sr * shi d = rc*rc + ic * ic real = (rs*rc ...
f2aedcff8f7fbce85169dab263163aa461367a53
13,103
import random def get_best_move(board, scores): """ Function that computes the best move for the machine given the actual board state """ max_score = max(scores[row][col] for row, col in board.get_empty_squares()) candidates = [(row, col) for row, col in board.get_empty_squares() ...
afabd281ad1547b118cab10ccc912bdf4956f9c4
13,104
def vapour_pressure_deficit(es, ea): """ VPD - Vapour Pressure Deficit :param es: :param ea: calculated by vp_from_rhmin_rhmax() :return: """ return es - ea
cb1d22a236081b3de3f080f8f2e2acb64543620f
13,105
import pathlib import json def load_json(filepath): """ Loads the metrics in a dictionary. :param log_dir: The directory in which the log is saved :param metrics_file_name: The name of the metrics file :return: A dict with the metrics """ if isinstance(filepath, pathlib.Path): fil...
1dd8ff7822228bc0173a66df626902a723338d55
13,109
from typing import Callable import random def choose(option1: Callable = lambda: None, option2: Callable = lambda: None): """ Randomly run either option 1 or option 2 :param option1: a possible function to run :param option2: another possible function to run :return: the result of the function ...
0f0ecbc945de9f6d5698cd86103265eccf5708e6
13,110
def transform_response_to_context_format(data: dict, keys: list) -> dict: """ Transform API response data to suitable XSOAR context data. Remove 'x-ms' prefix and replace '-' to '_' for more readable and conventional variables. Args: data (dict): Data to exchange. keys (list): Keys to fi...
34f1a613654deb71581bcd33757b8741840ae44f
13,111
def per_field_value(values, fields): """ This normalises all patches relative to their field. 'fields' is a map of field numbers to a list of patches in that field. """ field_list = list(fields.values()) # We calculate the maximum and minimum values for each field. maxs = [max((values[inde...
b51e344463d4d75f21ab8fc3a58d6201249fc2dc
13,112
import torch def one_hot(y, K, smooth_eps = 0): # pylint: disable=invalid-name """One-hot encodes a tensor with optional label smoothing. Args: y: A tensor containing the ground-truth labels of shape (N,), i.e. one label for each element in the batch. K: The number of classes. smooth_eps: Labe...
ee47f9c778d875834c49c098ded4936edb104887
13,113
import re def wrap_with_span(string, arg): """ Wraps all instances of a string with a span element""" words = arg.split(' ') for word in words: if word[-1].lower() == 's': word = word[:-1] pattern = re.compile(r'\b({0}[\w\d]*)\b'.format(word), flags=re.I) for (match) ...
9390f0f12d673c9a809760c1e7ff614d4fc079ef
13,114
def import_name(modulename, name=None): """ Import identifier ``name`` from module ``modulename``. If ``name`` is omitted, ``modulename`` must contain the name after the module path, delimited by a colon. Parameters: modulename (str): Fully qualified module name, e.g. ``x.y.z``...
a320063e878db935f8a2409c7487617e2c9f1802
13,117
import argparse def get_opts(): """Return hostname and server from the list of command arguments.""" parser = argparse.ArgumentParser( description='Get certificate information from server and validate it') parser.add_argument('--server', '-s', help='Server to connect to') parser.add_argument( ...
6ac6b243d8757828339f9ed0d7e9c59059c659c2
13,118
def sort_012(arr): """ Given an input array consisting on only 0, 1, and 2, sort the array in a single traversal. Args: arr(list): List to be sorted """ if arr is None: return arr zero_index = 0 current_index = 0 two_index = len(arr) - 1 while current_index < len(arr...
d1fa4ee67c9d6b62928b5ea1e2fc1daf011db29d
13,119
def stop_process(client, pid): """获取进程状态""" stop_result = "" command = 'kill -9 "%s" ' stdin, stdout, stderr = client.exec_command(command % pid) # 执行bash命令 kill_status = stdout.read() error = stderr.read() if error or kill_status: error = error.split(':')[3].strip() stop_re...
454bb8763017119efe360cb5f7c07b9a353ba345
13,120
def calculate(): """ Perform a super important calculation. """ return 12
b6aa643b9f6e24f579fdc273c2dec512692cdc4b
13,123
def N_(msg): """Designate a string to be found by gettext but not to be translated.""" return msg
e82c1f4219e53be05e863bfd636bec932ddd7f5c
13,125
import json def _get_needed_packages(json_file, test=None): """ Returns a dict with needed packages based on a JSON file. If a test is specified it will return the dict just for that test. """ needed_packages = {} with open(json_file) as f: test_packages = json.load(f) for key,va...
b929e57beda05372b03936598db275e87a318962
13,126
def get_factory_log_recipients(entry): """Read the log recipients specified by the Factory in its configuration Args: entry: dict-like object representing the entry configuration Returns: list: list contaning the URLs of the log servers, empty if none present """ entr_attrs = entry...
f3e776ea9b8102247b5c7e817762523467d9f953
13,129
import csv def get_conditions_bids(infile): """ read onsets, duration and amplitude from 3 column format file. (e.g. events.tsv in BIDS format) """ spec = [] if infile.endswith('.tsv'): # read tsv file with open(infile) as f: reader = csv.reader(f, delimiter='\t'...
3bd0546115fa635abbcc7829911fdb476ad1c33e
13,131
def preprocess(raw): """ Basic text formatting e.g. BOM at start of file """ ## 1. Remove byte order marks if necessary if raw[0]=='\ufeff': raw = raw[1:] # if raw[0] == '\xef': # raw = raw[1:] # if raw[0] == '\xbb': # raw = raw[1:] # if ...
dfeb75152196ff2ab751ee206aab03eed1f28502
13,133
def calc_num_pixels(num_pixels, stride): """ Converts the current number of pixels to the number there will be given a specific stride. """ return 1 + (num_pixels - 1) // stride
b6ae056339913c496017251709381c19f551a074
13,134
def readme(): """Returns the contents of the README without the header image.""" header = '======\nGimbal\n======\n' with open('README.rst', 'r') as f: f.readline() return header + f.read()
892100a63287917a35850258c677ee53ee2883a0
13,137
import os def load_images_map(images_dir): """From all face images, produce an easy lookup table. Format: {frame_index1: set(bbs_tuple1, bbs_tuple2, etc...)} """ _, _, files = next(os.walk(images_dir)) # facerec image file format: <movie_id>:<frame_i>:x1_y1_x2_y2.jpeg image_map = {} for ...
691a5b3a03af4dcd14ce08ba33326b6d33d1f927
13,140
def rewrite_arcs (label_map, nfa): """Rewrite the label arcs in a NFA according to the input remapping.""" states = [[(label_map[label], tostate) for (label, tostate) in arcs] for arcs in nfa[2]] return (nfa[0], nfa[1], states, nfa[3], nfa[4])
2bd9911a5c65ce7711848746614a3a6ceb37f8d2
13,141
import copy def merge_params(base_params, partial_params=None): """Merge a partial change to the base configuration. Parameters ---------- base_params The base parameters partial_params The partial parameters Returns ------- final_params The final parameters ...
4c52d492358106b7c5e6df0c1e099d45043a7935
13,142
def create_dicts_same_nodes(my_set, neighbors_dict, node, dict_out, dict_in): """ A function to create useful dictionaries to represent connections between nodes that have the same type, i.e between nodes that are in the embedding and between nodes that aren't in the embedding. It depends on the input. ...
c4ef94964f2944dcbddd79f76182a4bcc64633e7
13,143
def flatten(list_of_lists): """Single level flattening of a list.""" return sum((list(sublist) for sublist in list_of_lists), [])
d7a2b9b75a1bd920f50d78cc725f8e551d6bb2f5
13,144
def maximum() -> int: """Returns 9.""" return 9
dfd9a240bdaf985f89ca1b90c2b6e01f5426b2b0
13,146
def config(): """ Configuration file for edith usage """ config = { "edith": { # don't change "version": 1.0 # don't change }, "config": { # change this "host": "Raspberry Pi Zero WH", # change host to machine running program "online serv...
3c4adf4407311428be2c97fdc61dd636de63d760
13,147
import os def _has_extension(file_name, extension): """Check if a file has an extension.""" return os.path.splitext(file_name)[1] == extension
0b8a0979bd3aeaa65509c3b817ca48507775ac4d
13,148
def _is_schar(self): """Test auf Schar""" return len(self.sch_par) == 1
8d1229a45fab73a9d7f1560806c6e3497bbb1bcf
13,149
def read_format(info): """input info and return readable format""" info_name = info["name"] info_desc = info["description"] info_coun = info["country"] return f"{info_name}, a {info_desc}, from {info_coun}"
1804b25b8d1d01b2525887e9f4ba75d031cdf515
13,154
def score_function(nom_cosine, w): """ 最终得分值为归一化的余弦距离 * 权重项 :param nom_cosine: :param w: :return: """ return nom_cosine * w
99468bca131a42148b0bf012f5f3c61215716b57
13,155
def load_motion_masks(motion_root): """Load motion masks from disk. Args: motion_root (Path): Points to a directory which contains a subdirectory for each sequence, which in turn contains a .png for each frame in the sequence. Returns: motion_masks (dict): Map seque...
babe7c83b7f2c7a1cade2d4fcb3de8461d88ba00
13,156
def parse_genetic_models(models_info, case_id): """Parse the genetic models entry of a vcf Args: models_info(str): The raw vcf information case_id(str) Returns: genetic_models(list) """ genetic_models = [] if models_info: for family_info in models_info.split(",...
9d8d94d9008e2f287a875aa9bd15330c82bbf8b5
13,157
def read_labels(labels_file): """Get the labels from names file""" with open(labels_file, 'r') as f: lines = f.readlines() return [lab for lab in lines if len(lab) > 0]
a1b4ce5c0b5c613db5ec0d7d619910210d88106e
13,158
def welcome(): """List all available api routes.""" return ( f"Welcome to Climate App<br/>" f"Available Routes:<br/>" f"Precipitation Data: /api/v1.0/precipitation<br/>" f"Stations List: /api/v1.0/stations<br/>" f"Temperature Observation for the most active station: /api/...
3fead56e744b1399b20ab24da4d2c1c9b901379e
13,159
from bs4 import BeautifulSoup def get_string_from_tag(row_with_tag): """Given a row with a tag, return the string from it. Ex. Given, <a href="http://www.example.com/page/index.html">Example Page</a> return the string "Example Page" """ row = BeautifulSoup(str(row_with_tag)) return u''.join([r...
7c154fa4752ae59a2a33c45aaded394db2cb42f3
13,160
import re def slug_sub(match): """Assigns id-less headers a slug that is derived from their titles. Slugs are generated by lower-casing the titles, stripping all punctuation, and converting spaces to hyphens (-). """ level = match.group(1) title = match.group(2) slug = title.lower() sl...
58c40e4ca23bd76a0e25d746aeb4ccdbed6640d7
13,162
def validateIsNotEmpty(data: str, fieldName: str): """Validate if data empty""" if data == '' or data == None: return "{} Must be not empty".format(fieldName) return None
26bec771bb881e32ded022acc57e62b81b2991f9
13,163
def get_message_after(response, index): """Returns next message of search response after index or None""" try: return response[index + 1].object except IndexError: return None
0208fd1f4397e77636df11b62054e86eb84fb682
13,164
import time import json def result_running_callback(request, context): # pylint: disable=unused-argument """ Callback function returning 'running' JSON. """ job_result_running = { 'status': 'running', } time.sleep(1) return json.dumps(job_result_running)
cb38b44b86cdcc96706dbf40a764d8d2059de449
13,165
import os import zipfile import xml.etree.ElementTree as ET def get_files_list(folderlist): """Gets a list of files from the arg folder and check for errors. Args: folderlist: the list of folder where the Lattes CV files are found. The Lattes CV files are downloaded as .zip files containin...
d8191746b2545111617b086f5f06a1fd2d4d2572
13,166
import struct def get_system_bits(): """Return 32 for 32-bit systems and 64 for 64-bit""" return struct.calcsize("P") * 8
252d5acab4dec512df238031f89c072129485959
13,168
def format_knot_hash(value, format_spec): """ >>> format_knot_hash([64, 7, 255], '02x') '4007ff' >>> format_knot_hash(bytearray.fromhex('A0C20170'), '08b') '10100000110000100000000101110000' """ return "".join(format(h, format_spec) for h in value)
2a12f299807bcc6606a00092faecf1b34ec32170
13,171
def compute_intersection_length(A, B): """Compute the intersection length of two tuples. Args: A: a (speaker, start, end) tuple of type (string, float, float) B: a (speaker, start, end) tuple of type (string, float, float) Returns: a float number of the intersection between `A` and...
6cf038e1febbc1a7aa19eb104f5628ff2f935174
13,173
import socket def bindsocket(port, host=''): """ Creates a socket assigned to the IP address (host, port). Parameters ---------- port : int port assigned to the socket. host : str, optional host assigned to the socket. The default is ''. Returns ------- tcpsock : ...
48be29952a3d35af0ec0886e3ca332f9280384f1
13,175
import re def _yesno(message, default='no', suffix=' '): """Modified from github.com/tylerdave/prompter to reduce depenencies. All credit to the creator.""" if default == 'yes': yesno_prompt = '[Y/n]' elif default == 'no': yesno_prompt = '[y/N]' else: raise ValueError("defa...
f66bdf51fd79deb9ccba52f426a691361c9c6993
13,176
import json import logging def output(post, quiet=False, use_test_node=False, diagnostic=False, urls_only=False) -> int: """Prints out the post and extracts the custom_json""" data = json.loads(post.get("json")) if diagnostic: logging.info( ...
31f3e977d47d44ed6b9ec45d171cbe9cfecb7ed9
13,178
import os def get_filepath(date, data_source='data'): """Renvoie le filepath d'un fichier donné Args: date (string): string contenant la date sous le format {jour}{Mois abbrégé} -> exemple : 7Nov Returns: string """ return os.path.join(data_source, f'data...
27456a7a49c56d11d76ce63c5e043fcc94cdac27
13,179
import six def _UnitsByMagnitude(units, type_abbr): """Returns a list of the units in scales sorted by magnitude.""" scale_items = sorted(six.iteritems(units), key=lambda value: (value[1], value[0])) return [key + type_abbr for key, _ in scale_items if key]
972a17b51901a133444ddb77989c4ebc372fc35e
13,180
import functools import traceback def check_workchain_step(func): """ Decorator for workchain steps that logs (and re-raises) errors occuring within that step. """ @functools.wraps(func) def inner(self, *args, **kwargs): try: return func(self, *args, **kwargs) except Ex...
d6e5834b233075fbb1097a84f7e3010c3f292194
13,183
def _construct_GPL_url(accession): """Example URL: ftp://ftp.ncbi.nlm.nih.gov/geo/platforms/GPLnnn/GPL570/annot/GPL570.annot.gz """ number_digits = len(accession) - 3 # 'GPL' is of length 3. if number_digits < 4: folder = accession[:3] + 'nnn' # e.g. GPLnnn. elif 3 < number_digits < 5: folder = accession[...
36527d413cc005abe5055eab46e4d7fe93f4aa8e
13,184
def get_get_upload_details_retry_predicate(resp): """Triggers retry if upload details came back without last status.""" return not resp.last_status
ecadf182751e55c2c3cbd85f2a7343adc34821e5
13,185
def get_setuptools_package_version(setuptools_version: str) -> str: """ Generate the right setuptools command for pip command :param setuptools_version: Setuptools version obtained from :return: A string formatted for pip install command (e.g setuptools==58.0.0) """ setuptools_version = setupto...
99554292253752545d1bbf82edfef92a925b1746
13,186
import os import re def base_disk_for_block_device(partition: str) -> str: """ Returns the base disk of a disk partition. :param partition: Path to the partition to get the base disk of :return: Path to base disk of given partition """ # Follow link(s) # partition should now be in forma...
4734d67dbc958637d088be17b25b0ee8e63fa20d
13,188
import torch def log1pMSELoss(log_predicted_counts, true_counts): """A MSE loss on the log(x+1) of the inputs. This loss will accept tensors of predicted counts and a vector of true counts and return the MSE on the log of the labels. The squared error is calculated for each position in the tensor and then averag...
ba7d244885303fa6755c4c25f1f991afae6d10ed
13,189
import logging def check_connection(ssh_conn): """ This will check if the connection is still available. Return (bool) : True if it's still alive, False otherwise. """ try: ssh_conn.exec_command("ls", timeout=5) return True except Exception as e: logging.error( ...
f443d6788eb4a79db7011f0ca9dc4ae15cdf6145
13,190
import re def parse_show_ip_bgp_route_map(raw_result): """ Parse the 'show ip bgp route-map' command raw output. :param str raw_result: vtysh raw result string. :rtype: dict :return: The parsed result of the show ip bgp route-map command in a \ dictionary of the form: :: { ...
48aecdc76da27fbbc991c30405d1efef82bcbfc3
13,191
import torch def sample_image(): """Sample torch image of correct shape.""" return torch.zeros((3, 300, 300))
fc62ae5720fc1237822faad81c8924026f5b42a7
13,192
def generate_layer(layer_def, query_tokens, extent, empty_zoom): """ If empty_zoom is True, adds an extra sql column with a constant value, otherwise if it is an integer, tests if the geometry of this layer covers the whole tile, and outputs true/false, otherwise no extra column is added """ lay...
6afc16d5d84775f329ceda1334c714e72b341e7a
13,193
def __create_brightness_temparature_levels(df): """ Args: df (pandas.DataFrame): Returns: dict: a dictionary of DataFrame objects; """ levels = {} levels[1] = df.query("value > 330") levels[2] = df.query("value <= 330 and value > 320") levels[3] = df.query("value <= 320 ...
6d85267219026c978720d0ba4dadc6ac58bb5836
13,194
def arch2abi(arch): """Map arch to abi""" # pylint: disable=too-many-return-statements if "rv32e" in arch: if "d" in arch: return "ilp32ed" if "f" in arch: return "ilp32ef" return "ilp32e" if "rv32i" in arch: if "d" in arch: return "ilp...
a315f04f5c45588953a15cc0fbfda8e3b9621621
13,195
def find_nearest_date(items, pivot): """This function will return the datetime in items which is the closest to the date pivot. See https://stackoverflow.com/questions/32237862/find-the-closest-date-to-a-given-date Parameters ---------- items : list List containing datetimes pivot : dat...
7b719357c92210729857957e5b4ed8aee4a1f466
13,196
def get_time_tied_leading_trailing(event, previous_score, last_goal_time): """ Calculate time of previous score state according to current event time and time of last goal scored. """ if previous_score['home'] == previous_score['road']: return 'tied', event['time'] - last_goal_time elif ...
d53172e0beb9ab3155f02f3feca3680d25e5bcd0
13,197
import os def has_freesurfer(): """Aux function""" return 'FREESURFER_HOME' in os.environ
4cc6137ac5bcf0b6fdc24797967147266851948d
13,199
def J_int_yt(yt, membrane_geometry): """ Jacobian using yt = 1. - rt coordination Note that the coordination definition for y is not consist between [1] and [2]. """ J = 1. - yt if (membrane_geometry=='FMM' or membrane_geometry=='FMS'): J = 1. return J
45e8ea2ef74c7bfd2dfa96543a8bfcb47531d6d4
13,201
def get_primer_direction(primer, delimiter='_', left='left', right='right'): """ Check if the primer is on the left or the right side of the amplicon. """ primer = delimiter.join([str(item) for item in primer]) try: if left in primer.lower(): return 'LEFT' elif right in p...
3aed4e1d3397befa2ae713c5cae1a0c018abb5ae
13,202
import os def exists(name): """Returns whether the given file or folder exists""" return os.path.exists(name)
d3f3ff1971a12b74355623feb5954356d0811735
13,204
import os def is_package(folder): """ Comprueba si una carpeta es un paquete python :param str folder: ruta de la carpeta :return: True si es un paquete, False en otro caso :rtype: bool .. code-block:: python >> is_package('../pydoc') 'True' """ return os.path.isdir...
4cc46b31df07d36d478192294fb8c50c53f716f8
13,205
def sample_from_simplex(rng, dim): """Uniformly samples a probability vector from a simplex of dimension dim.""" alpha = [1] * dim return rng.dirichlet(alpha)
d034c4502634678874f89e17f2fde28eb8c28e0b
13,206
import subprocess def sh(command, bg=False, **kwargs): """Execute a local command.""" kwargs['shell'] = True if bg: return subprocess.Popen(command, **kwargs) else: subprocess.check_call(command, **kwargs)
f4d4b562e77738a4a371587926b32a8c3df8422d
13,207
import math def getDistance(p1, p2): """Return the distance between p1 and p2.""" return math.sqrt(sum([(p1[i] - p2[i])**2 for i in range(max(len(p1), len(p2)))]))
28d8156ad1eb5557a3fb3fa8bc7a94a66d06db3e
13,208
def format_condition_value(conditions): """ @summary: ['111', '222'] -> ['111', '222'] ['111', '222\n333'] -> ['111', '222', '333'] ['', '222\n', ' 333 '] -> ['222', '333'] @param conditions: @return: """ formatted = [] for val in conditions: formatted += [it...
b79269ab375c1bec9724f29528c5a42d3bda3a72
13,210
def links_and_nodes(): """ J4 S1 / \ / / \ / S3 / J3 S2 \ / | / \ / | / J6 BR | // \ | // \ ~BI J2 INF ...
b8a154738407fee77fbd2d111443a42753ff749c
13,212
import numbers def is_numeric(N): """Determine if `N` is numeric. `N` may be a single value or a collection. """ def is_num(n): return isinstance(n, numbers.Number) and (not isinstance(n, bool)) if '__iter__' in dir(N): return False not in [is_num(n) for n in N] else: ...
4381d9ad7a3ee5f2f689b78f54b663e8349c58ff
13,213
import os def search(pathe, folder): """ Busqueda De carpetas al interior de los directorios que contienen las imagenes :pathe: Directorio en el cual se desea buscar :folder: Nombre de la carpeta que se desea encontrar Devuelve array con la totalidad de coincidencias encontradas """ direc...
12b7fe6125959b4abda605dd9bb633c783c8057c
13,215
import argparse def build_parser(): """Build argument parser""" parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter ) parser.add_argument( "input_json", type=str, help="json of generated sequences", ) parser.add_argument("reference_file", ty...
21b83044e749c041b0d2a32630489823db8a8895
13,216
def file_is_pdf(filename: str) -> bool: """ Check if `filename` has the .pdf extension. Args: filename (str): Any filename, including its path. Returns: True if `filename` ends with .pdf, false otherwise. """ return filename.endswith(".pdf")
ba9a540a1f0edd33e48010a001de4493bdff80d9
13,217
import glob import os def isempty(path): """Determine whether the given directory is empty.""" flist = glob.glob(os.path.join(path,'*')) return flist == []
6f18b4f3956d25af20ee43c6177d76ac001db699
13,218
from typing import Callable from typing import Iterator from typing import Optional def mk_omit(skip_func: Callable) -> Callable: """The skip function is either minleq or maxgeq""" def omit_(pot: int, seqs: Iterator[Iterator[int]]) -> Iterator[Optional[int]]: """Given an iterator of ite...
ce1aafd0a67dd1acfbc9fc7b966fd14a76b1e85d
13,219
def generateClosures(transactions, generators): """ Generate the closures of the generators transactions : list of sets The list of transactions generators : lists of lists The list of generator itemsets whose closures need to be computed Returns ...
452f12fec6dff0e3c8903344976fcb44728fa563
13,220
import torch def torch_hilbert(x_real, n_fft=None): """ Obtain imaginary counterpart to a real signal such that there are no negative frequency components when represented as a complex signal. This is done by using the Hilbert transform. We end up with an analytic signal and return only the imaginary ...
33bb230c78beb84ca5569c5fca8ebb61a36fd7c5
13,221
import math def calcCirclePos(robotIdx, numRobots, radius=3, center=(0,0)): """ Helper function to distribute robot positions on a circle. """ gamma = 2*math.pi / numRobots x = radius * math.cos(gamma * robotIdx) + center[0] y = radius * math.sin(gamma * robotIdx) + center[1] phi = gamma *...
393c044dcb4016c34b8efe2a7acd185b45c52467
13,224
def open_file_handler(file_name): """ function returning opened file handler :param file_name: :return: """ return open(file_name, mode='r', encoding='utf8')
9f78ba9e11060cff515405ffc87d48a585fdc2ed
13,226
import re def is_valid_vlive_url(url: str) -> bool: """Uses a regex to check if the given url is a valid 'vlive.tv./video/' address.""" # VLIVE videos are only identified by numbers in the url (unlike Youtube IDs, # for example) vlive_url_regex = r"(vlive\.tv\/video\/[0-9]*)" if not re.search(vl...
35c741ea512cad5edd791ebbb8acef99b19d84d3
13,227
from typing import Tuple import argparse def loadbuild_cli() -> Tuple[bool, bool]: """ Convenience CLI args for rebuilding data using `load_or_build` """ parser = argparse.ArgumentParser() parser.add_argument('--rebuild', action='store_true') parser.add_argument('--rebuild-down', action='store_true') ...
a99515b4fdadb733fe398f64b919b531787dade1
13,228
def insertion_sort(arr): """Performs insertion sort of given IntsToSort""" if len(arr) < 2: return arr if len(arr) > 1: i = 1 while i < len(arr): curr_val = arr[i] j = i - 1 # Start with curr val and compare to all previous values whil...
0e8da20d1e5e958f8df73dc5e9e83a7bdf6d235b
13,232
def default_resolution(): """Note that this and the number of ts objects created below are fine tuned for these tests to create just over a week of data, and changing them might cause the tests to fail. See docstrings of tests for info""" return 20
eacfdecb06665c52930f959ea9ee0adfde2775c3
13,233
import torch def embedding_similarity( batch: torch.Tensor, similarity: str = 'cosine', reduction: str = 'none', zero_diagonal: bool = True ) -> torch.Tensor: """ Computes representation similarity Example: >>> from pytorch_lightning.metrics.functional import embedding_similarity ...
dda82b8fa4dc4f3760a5c7ec329c77b980f3860c
13,234
from typing import List from typing import Dict from typing import Any import logging import json def entity2tag(token_list: List[str], entities: List[Dict[str, Any]]): """ 将实体 entity 格式转为 tag 格式,若标注过程中有重叠标注,则会自动将靠后的 实体忽略、删除。针对单条处理,不支持批量处理。 Args: token_list(List[str]): token 化的文本的 list en...
79c0d228da642013dfcbfa59aa2e317185e413c2
13,235
import sys def loadingFinder(load): """ """ _load = str(load).lower() _load = _load.replace(' ','') _load = _load.replace('-','') _load = _load.replace('_','') _load = _load.strip() # _static = ['static'] _dyamic = ['dynamic'] # if _load in _static : _type = 'static' ...
7bf6cc738932f1b04dc0d7532302f7402437eaf1
13,236
def fib(n): """ Computing the nth of Fib series Implemetation focusing on 1 time running of fib. """ memoire = [0] * 100 def rec_fib(n): if n == 1 or n == 2: memoire[n-1] = 1 return 1 else: if memoire[n - 1] == 0: mem...
dfeae222af315c55a1010ce73857a8925f20d837
13,238
def fixName(name): """PMML tag name substitutions to avoid conflicts with Python syntax.""" out = name.replace("-", "_") if out == "True": out = "AlwaysTrue" elif out == "False": out = "AlwaysFalse" elif out == "from": out = "isfrom" return out
e5bb85465f8a599f45ff12bf48247beab123472e
13,240
import time def microseconds(): """ Get the time in microseconds """ return time.time() * 1000000.0
82d9258a8b0f68295b9ba2c86a9165309c19ae90
13,241
def _compute_input_padding(size, bcount, bsize, boffset, bstride): """Computes the padding for the operation. :param size: `[SZH, SZW]` list-like of ints, size of image :param bcount: `[BCH, BCW]` list of ints :param bsize: :param boffset: :param bstride: :returns: `pad_h, pad_w` for _pad_inputs function...
bce6ed06406f0d259d029c745e3c9f5ff015959e
13,242
from typing import Union import string def _strip_unwanted_chars(price: Union[int, str]) -> str: """Returns price text with all unnecessary chars stripped (nonnumeric etc). Examples: "100" should return "100" "100 yen" should return "100" "10,000" should return "10000" Args: price: The raw val...
18679bbd7e53fcea7cadd3343fc82a3dd875f8af
13,243
def isDocx(filename): """确定上传文件为docx""" return '.' in filename and filename.rsplit('.', 1)[1] in {"docx",}
547236d821e0ecb3bb59a2ea00623adbf7d5c6df
13,245
import warnings def update(data): """Update the data in place to remove deprecated properties. Args: data (dict): dictionary to be updated Returns: True if data was changed, False otherwise """ updated = False if 'include' in data: msg = ("included configuration files...
2e604cde4455bb1ab784651798fb3be0cd3733db
13,247
from typing import List def calc_high_actual_pd(actual_temps_dict: dict, final_high_rcp_list: list) -> List[float]: """ Return a list of percentage differences of high RCP values to actual temperature values """ actual_temps_list = list(actual_temps_dict.values()) high_rcp_...
6aee2dbf9ab62dab7c5b4671a1c1ce64ad4ad2eb
13,249