content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def scheming_field_by_name(fields, name):
"""
Simple helper to grab a field from a schema field list
based on the field name passed. Returns None when not found.
"""
for f in fields:
if f.get('field_name') == name:
return f | ba4d04585b12ab941db8bc0787b076c32e76cadb | 707,894 |
def daysBetweenDates(year1, month1, day1, year2, month2, day2):
"""Returns the number of days between year1/month1/day1
and year2/month2/day2. Assumes inputs are valid dates
in Gregorian calendar, and the first date is not after
the second."""
month = month2
year = year2
day = day2 ... | 687a7ff0b29ec2a931d872c18057741d93571ac1 | 707,895 |
def collapse(board_u):
"""
takes a row/column of the board
and collapses it to the left
"""
i = 1
limit = 0
while i < 4:
if board_u[i]==0:
i += 1
continue
up_index = i-1
curr_index = i
while up_index>=0 and board_u[up_index]==0:
... | a79a3c7b83355f95face09e0ab21ab0b15a81053 | 707,896 |
import re
def find_match_in_file(search_term, file_location):
"""
This function is used to query a file
search_term = Term to find
file_location = Location of file to query.
"""
try:
with open(file_location) as line:
for search in line:
result = re.match(... | d78776069c8f2b4da5f09bf0ce3e675e215ee584 | 707,897 |
def create_C1(data_set):
"""
Create frequent candidate 1-itemset C1 by scaning data set.
Args:
data_set: A list of transactions. Each transaction contains several items.
Returns:
C1: A set which contains all frequent candidate 1-itemsets
"""
C1 = set()
for t in data_set:
... | 9f3deb61c6c3b982976c61c4247102431794daa8 | 707,898 |
def generalise_sent_pos(s):
"""
generalise sentence pattern by POS tags only
:param s:
:return:
"""
rets = []
for token in s['sent']:
e = token.idx + len(token.text)
is_matched = False
for ann in s['anns']:
if token.idx >= ann['s'] and e <= ann['e']:
... | 03092bd253f13739d918438839ff4234f5ef80af | 707,899 |
def line_break(text, line_len=79, indent=1):
"""
Split some text into an array of lines.
Enter: text: the text to split.
line_len: the maximum length of a line.
indent: how much to indent all but the first line.
Exit: lines: an array of lines.
"""
lines = [text.rstrip()]
... | 34b866109689796a4d428e7d3a68a34f7152250f | 707,900 |
def altsumma(f, k, p):
"""Return the sum of f(i) from i=k, k+1, ... till p(i) holds true or 0.
This is an implementation of the Summation formula from Kahan,
see Theorem 8 in Goldberg, David 'What Every Computer Scientist
Should Know About Floating-Point Arithmetic', ACM Computer Survey,
Vol. 23, No... | 952e77fcedfbe01658342126d95b79175c082976 | 707,902 |
def word_sorter(x):
"""
Function to sort the word frequency pairs after frequency
Lowest frequency collocates first - highest frerquency collocates last
"""
# getting length of list of word/frequency pairs
lst = len(x)
# sort by frequency
for i in range(0, lst):
for j i... | 571570bb03d6473b9c6839aa6fdc0b1ba8efbe3c | 707,903 |
def le_assinatura():
"""[A funcao le os valores dos tracos linguisticos do modelo e devolve uma assinatura a ser comparada com os textos fornecidos]
Returns:
[list] -- [description]
"""
print("Bem-vindo ao detector automático de COH-PIAH.")
print("Informe a assinatura típica de um aluno in... | b6a0bacb02f3f878a88a6681d87d11408c292fe2 | 707,904 |
import argparse
def parse_args() -> argparse.Namespace:
"""
Creates the parser for train arguments
Returns:
The parser
"""
parse = argparse.ArgumentParser()
parse.add_argument('--local_rank', dest='local_rank', type=int, default=0)
parse.add_argument('--port', dest='port', type=i... | 70370de42d6e80f108399776c119724c3417a125 | 707,905 |
def GenerateConfig(_):
"""Returns empty string."""
return '' | ed42eb1c320ca1df25603a53d4abf4a1b14215f3 | 707,906 |
def if_statement(env, node):
"""
'If' statement def for AST.
interpret - runtime function for Evaluator (true of false statement depending on condition).
"""
condition_value = node.condition.interpret(env)
if condition_value:
node.true_stmt.interpret(env)
else:
if node.altern... | 96522698c42d7649d3951f5fd2ffe3bbd992c985 | 707,908 |
import re
import json
def str_to_list_1(string):
"""
Parameters
----------
string : str
The str of first line in each sample of sample.txt
Returns
---------
final_list: lst
"""
final_list = []
li = re.findall(r'\[... | 92b4b11a339d2101a0af5408caee58cc9b9668a1 | 707,909 |
def one_mini_batch(data, batch_indices):
"""
产生每一次的小的batch
:param data:
:param batch_indices:
:return:
"""
batch_data = {
"raw_data": [data[i] for i in batch_indices],
"word_id_list": [],
"label_vector": []
}
for data in batch_data["raw_data"]:
batch_d... | 2bbbd62a00422431bb3322ebfce26d7fe95edc09 | 707,910 |
def get_maya_property_name(prop, ignore_channel=False):
"""
Given a property, return a reasonable Maya name to use for it.
If ignore_channel is True, return the property for the whole vector, eg. return
'.translate' instead of '.translateX'.
This doesn't create or query anything. It just generates... | 591a49f054db3936d5a345919a2c69491b6f345e | 707,911 |
def prefix_sums(A):
"""
This function calculate of sums of eements in given slice (contiguous segments of array).
Its main idea uses prefix sums which
are defined as the consecutive totals of the first 0, 1, 2, . . . , n elements of an array.
Args:
A: an array represents number of mushroom... | d61e49eb4a973f7718ccef864d8e09adf0e09ce2 | 707,913 |
import re
def checkParams(opts):
"""
检查模块名是否符合命名规则
检查目录是否存在
"""
res = {}
for opt, arg in opts:
if opt in ('--name'):
if re.match('^[a-zA-Z_][a-zA-Z0-9_]*$', arg):
res['name'] = arg
else:
return res
elif opt in ('--dir'):
... | 5b8306a1c9805786e4a98509dcea3af59ffd04d1 | 707,915 |
def sql2dict(queryset):
"""Return a SQL alchemy style query result into a list of dicts.
Args:
queryset (object): The SQL alchemy result.
Returns:
result (list): The converted query set.
"""
if queryset is None:
return []
return [record.__dict__ for record in queryset] | c55fa18773142cca591aac8ed6bdc37657569961 | 707,916 |
def float_to_bin(x, m_digits:int):
"""
Convert a number x in range [0,1] to a binary string truncated to length m_digits
arguments:
x: float
m_digits: integer
return:
x_bin: string
The decimal representation of digits AFTER '0.'
Ex:
Input 0.75... | f95e72d9449b66681575b230f6c858e8b3833cc2 | 707,917 |
from typing import Callable
from typing import List
def apply(func: Callable, args: List):
"""Call `func` expanding `args`.
Example:
>>> def add(a, b):
>>> return a + b
>>> apply(add, [1, 2])
3
"""
return func(*args) | f866087d07c7c036b405f8d97ba993f12c392d76 | 707,918 |
import torch
def l2_mat(b1, b2):
"""b1 has size B x M x D, b2 has size b2 B x N x D, res has size P x M x N
Args:
b1:
b2:
Returns:
"""
b1_norm = b1.pow(2).sum(dim=-1, keepdim=True)
b2_norm = b2.pow(2).sum(dim=-1, keepdim=True)
res = torch.addmm(b2_norm.transpose(-2, -1),... | ad254c2c11dccab5dd97c7e72ef3b00c7b6143fb | 707,919 |
import fnmatch
import os
def find_files(base, pattern):
"""Return list of files matching pattern in base folder."""
return [n for n in fnmatch.filter(os.listdir(base), pattern) if os.path.isfile(os.path.join(base, n))] | e84dd19e6746d92de1852f162eaa997734ac245c | 707,920 |
def compute_correlations(states):
"""compute_correlations.
Calculate the average correlation of spin 0 and every other spin.
Parameters
----------
states : list of states.
``len(states)`` must be >= 1!
Returns
-------
correlations : list of floats.
"""
return [
... | 471949aa63a3d65b262fb9dad1c77d160a3f5ac7 | 707,921 |
def rhs_of_rule(rule):
""" This function takes a grammatical rule, and returns its RHS """
return rule[0] | 004b99ac97c50f7b33cc798997463a28c3ae9a6f | 707,922 |
def to_bin(val):
"""
Receive int and return a string in binary. Padded by 32 bits considering 2's complement for negative values
"""
COMMON_DIGITS = 32
val_str = "{:b}".format(val) # Count '-' in negative case
padded_len = len(val_str) + ((COMMON_DIGITS - (len(val_str) % COMMON_DIGITS)) % COMMON... | 819d1c0a9d387f6ad1635f0fe0e2ab98b3ca17b0 | 707,923 |
import os
def reddit_client_secret() -> str:
"""Client secret of the reddit app."""
value = os.getenv("REDDIT_CLIENT_SECRET")
if not value:
raise ValueError("REDDIT_CLIENT_SECRET environment variable not set")
return value | dfddbb4b7306b9638b68f3b75721471a82118a64 | 707,924 |
def rgetattr(obj, attr):
"""
Get named attribute from an object, i.e. getattr(obj, 'a.a') is
equivalent to ``obj.a.a''.
- obj: object
- attr: attribute name(s)
>>> class A: pass
>>> a = A()
>>> a.a = A()
>>> a.a.a = 1
>>> rgetattr(a, 'a.a')
1
>>> rgetattr(a, 'a.c')
... | 5fb58634c4ba910d0a20753c04addf667614a07f | 707,925 |
def lambda1_plus_lambda2(lambda1, lambda2):
"""Return the sum of the primary objects tidal deformability and the
secondary objects tidal deformability
"""
return lambda1 + lambda2 | 4ac3ef51bb66861b06b16cec564f0773c7692775 | 707,926 |
def unicode_is_ascii(u_string):
"""Determine if unicode string only contains ASCII characters.
:param str u_string: unicode string to check. Must be unicode
and not Python 2 `str`.
:rtype: bool
"""
assert isinstance(u_string, str)
try:
u_string.encode('ascii')
return Tru... | 2a742c7334d68fe0bf6b546fb79bf00a338355f9 | 707,927 |
import grp
import os
import subprocess
def _is_industrial_user():
"""Checking if industrial user is trying to use relion_it.."""
if not grp:
# We're not on a linux/unix system, therefore not at Diamond
return False
not_allowed = ["m10_valid_users", "m10_staff", "m08_valid_users", "m08_sta... | 8b462431a96b25b7fc9a456807bfcd087a799651 | 707,928 |
def production(*args):
"""Creates a production rule or list of rules from the input.
Supports two kinds of input:
A parsed string of form "S->ABC" where S is a single character, and
ABC is a string of characters. S is the input symbol, ABC is the output
symbols.
Neither... | bcb3e415a283f654ab65e0656a3c7e3912eeb53b | 707,929 |
def flatten(items):
"""Convert a sequence of sequences to a single flat sequence.
Works on dictionaries, tuples, lists.
"""
result = []
for item in items:
if isinstance(item, list):
result += flatten(item)
else:
result.append(item)
return result | d44e3391f791dfd2ec9b323c37c510a415bb23bf | 707,930 |
from typing import Tuple
def extract_entity_type_and_name_from_uri(uri: str) -> Tuple[str, str]:
"""
从entity uri中提取出其type和name
:param uri: 如 http://www.kg.com/kg/ontoligies/ifa#Firm/百度
:return: ('Firm', '百度')
"""
name_separator = uri.rfind('/')
type_separator = uri.rfind('#')
return ur... | a70b1fdb5490f029cc6a88bee53eee048731a709 | 707,931 |
def load_rokdoc_well_markers(infile):
"""
Function to load well markers exported from RokDoc in ASCII format.
"""
with open(infile, 'r') as fd:
buf = fd.readlines()
marker = []
well = []
md = []
tvdkb = []
twt = []
tvdss = []
x = []
y = []
... | f3a781accdd84ff2f5aff12e59aeff05aa428d6a | 707,933 |
def _is_src(file):
""" Returns true if the file is a source file
Bazel allows for headers in the srcs attributes, we need to filter them out.
Args:
file (File): The file to check.
"""
if file.extension in ["c", "cc", "cpp", "cxx", "C", "c++", "C++"] and \
file.is_source:
return ... | b0466073d4d1b05c5cab37946fb6ca8432dc752d | 707,934 |
def calculate_signal_strength(rssi):
# type: (int) -> int
"""Calculate the signal strength of access point."""
signal_strength = 0
if rssi >= -50:
signal_strength = 100
else:
signal_strength = 2 * (rssi + 100)
return signal_strength | d5a0955446e0fe0548639ddd1a849f7e7901c36b | 707,935 |
def lookAtThisMethod(
first_parameter,
second_paramter=None,
third_parameter=32,
fourth_parameter="a short string as default argument",
**kwargs
):
"""The point of this is see how it reformats parameters
It might be fun to see what goes on
Here I guess it should respect this spacing, since we are in... | 8dab028b40184bb7cf686c524d5abd452cee2bc3 | 707,936 |
def parse_bjobs_nodes(output):
"""Parse and return the bjobs command run with
options to obtain node list, i.e. with `-w`.
This function parses and returns the nodes of
a job in a list with the duplicates removed.
:param output: output of the `bjobs -w` command
:type output: str
:return: c... | a582307d0d869d2dbde454928571246320cb6e31 | 707,938 |
def coord_for(n, a=0, b=1):
"""Function that takes 3 parameters or arguments, listed above, and returns a list of the interval division coordinates."""
a=float(a)
b=float(b)
coords = []
inc = (b-a)/ n
for x in range(n+1):
coords.append(a+inc*x)
return coords | 57e12200dcc113786c9deeb4865d7906d74c763f | 707,940 |
import subprocess
def get_rpm_package_list():
""" Gets all installed packages in the system """
pkgstr = subprocess.check_output(['rpm', '-qa', '--queryformat', '%{NAME}\n'])
return pkgstr.splitlines() | 3ffddefe7e3859f4bc76ae5581b89338c376e03f | 707,941 |
def validate_ints(*args):
""" validates that inputs are ints only """
for value in args:
if not isinstance(value, int):
return False
return True | e56ebf78e072731188b2c8282289d307fcfaabdf | 707,942 |
def _cals(raw):
"""Helper to deal with the .cals->._cals attribute change."""
try:
return raw._cals
except AttributeError:
return raw.cals | a08273a559b780022c04fe5d5d60a71c600fd481 | 707,943 |
def workaround_issue_20(handler):
"""
Workaround for
https://github.com/pytest-dev/pytest-services/issues/20,
disabling installation of a broken handler.
"""
return hasattr(handler, 'socket') | 20d688aedad9e771362d97ad9cac391e7dbfac32 | 707,944 |
def item_count(sequences, sequence_column_name):
"""
input:Dataframe sequences
"""
item_max_id = sequences[sequence_column_name].map(max).max()
return int(item_max_id) | 9bcb64ff3389ef34ed297bca4f55b4de66ac5966 | 707,945 |
def define_network(*addr):
"""gives all network related data or host addresses if requested
addr = tuple of arguments netaddr/mask[nb of requested hosts]
"""
if len(addr) == 2:
# provides list of host-addresses for this subnet
# we do this by calling the generator host_g
host_g... | 905cf702fda005645c608b9dadb84f3659d991c1 | 707,946 |
from typing import List
def init_anim() -> List:
"""Initialize the animation."""
return [] | 121fff8b4102c2961449d970307e762bd983bdbe | 707,947 |
def keep_digits(txt: str) -> str:
"""Discard from ``txt`` all non-numeric characters."""
return "".join(filter(str.isdigit, txt)) | 34387003ea03651dd2582b3c49f1095c5589167b | 707,948 |
import six
def validate_hatch(s):
"""
Validate a hatch pattern.
A hatch pattern string can have any sequence of the following
characters: ``\\ / | - + * . x o O``.
"""
if not isinstance(s, six.text_type):
raise ValueError("Hatch pattern must be a string")
unique_chars = set(s)
... | 4ddf056dab2681759a462005effc4ae5488a4461 | 707,950 |
def filter_example(config, example, mode="train"):
"""
Whether filter a given example according to configure.
:param config: config contains parameters for filtering example
:param example: an example instance
:param mode: "train" or "test", they differs in filter restrictions
:return: boolean
... | 9c49990fe36c0a82d0a99a62fe810a19cd5a8749 | 707,951 |
def _dict_flatten(data):
"""Return flattened dict of input dict <data>.
After https://codereview.stackexchange.com/revisions/21035/3
Parameters
----------
data : dict
Input dict to flatten
Returns
-------
fdata : dict
Flattened dict.
"""
def expand(key, valu... | a1db4a552ced44efa45fe4f86fbfe04871463356 | 707,952 |
def _get_item(i, j, block):
"""
Returns a single item from the block. Coords must be in block space.
"""
return block[i, j] | 45a12ecb3959a75ad8f026616242ba64174441fc | 707,953 |
def check_all_rows(A):
"""
Check if all rows in 2-dimensional matrix don't have more than one queen
"""
for row_inx in range(len(A)):
# compute sum of row row_inx
if sum(A[row_inx]) > 1:
return False
return True | e39f4ca3e401c02b13c5b55ed4389a7e6deceb40 | 707,954 |
import subprocess
import sys
def _run_cli_cmd(cmd_list):
"""Run a shell command and return the error code.
:param cmd_list: A list of strings that make up the command to execute.
"""
try:
return subprocess.call(cmd_list)
except Exception as e:
print(str(e))
sys.exit(1) | 473d28ec5469ff195b716edfe32723e2379303f3 | 707,955 |
def group_set_array_data_ptr(d):
"""
call view%set_external_data_ptr
hide c_loc call and add target attribute
"""
# XXX - should this check the type/shape of value against the view?
# typename - part of function name
# nd - number of dimensions
# f_type - fortran type
# shape... | 36a18ca9099edf24d37386103f111bde7753ed46 | 707,956 |
def get_experiment_type(filename):
"""
Get the experiment type from the filename.
The filename is assumed to be in the form of:
'<reliability>_<durability>_<history kind>_<topic>_<timestamp>'
:param filename: The filename to get the type.
:return: A string where the timesptamp is taken out fro... | e1853a95d034b8f9e36ca65f6f5d200cbf4b86dc | 707,957 |
import pytz
def getAwareTime(tt):
"""
Generates timezone aware timestamp from timezone unaware timestamp
PARAMETERS
------------
:param tt: datatime
timezome unaware timestamp
RETURNS
------------
:return: datatime
timezone aware timestamp
... | 1b286c92c7f5d8f0ff48d77296489fbd358c14ce | 707,958 |
def inverse_word_map(word_map):
""" Create an inverse word mapping.
:param word_map: word mapping
"""
return {v: k for k, v in word_map.items()} | 4048a21ea1c75791a92d57ee0a440a6c9d31b6b9 | 707,959 |
def get_coalition_wins_sql_string_for_state(coalition_id,state_id):
"""
:type party_id: integer
"""
str = """ select
lr.candidate_id,
c.fullname as winning_candidate,
lr.constituency_id,
cons.name as constituency,
lr.party_id,
lr.max_votes,
(lr.max_vot... | 76fb0704779e20e8a53ca80dc17c969f1e455d20 | 707,960 |
import torch
def iou_score(pred_cls, true_cls, nclass, drop=(), mask=None):
"""
compute the intersection-over-union score
both inputs should be categorical (as opposed to one-hot)
"""
assert pred_cls.shape == true_cls.shape, 'Shape of predictions should match GT'
if mask is not None:
a... | d38871f339b2126d418a7fca53fbfd874e263aa2 | 707,961 |
import queue
def task_checkqueue(storage):
"""
Task that watches a queue for messages and acts on them when received.
"""
# Get the queue object from the storage dictionary
thequeue = storage.get("queue")
try:
# Use a timeout so it blocks for at-most 0.5 seconds while waiting for a mes... | 3c7e8cfda53abb0551916894719e66b3d27886e9 | 707,962 |
import os
def get_stand_exe() -> str:
"""Get the path to standexe
Returns:
Path to standexe
Raises:
ValueError: If STAND_EXE is not found in environment variables.
"""
if os.environ['STAND_EXE']:
return os.environ['STAND_EXE']
else:
raise ValueError('STAND_EXE... | da44d23239060874965617c24ab0bd678c9535b9 | 707,964 |
def b64pad(b64data):
"""Pad base64 string with '=' to achieve a length that is a multiple of 4
"""
return b64data + '=' * (4 - (len(b64data) % 4)) | bdc14821bfbdbf220ff371fbe5e486d3e682337b | 707,965 |
def parse_copy_core_dump(raw_result):
"""
Parse the 'parse_copy_core_dump' command raw output.
:param str raw_result: copy core-dump raw result string.
:rtype: dict
:return: The parsed result of the copy core-dump to server:
::
{
0:{
'status': 'success'
... | 4ce168c9bc8c462ecc36beba889adb36cc64135d | 707,966 |
def compute_lifting_parameter(lamb, lambda_plane_idxs, lambda_offset_idxs, cutoff):
"""One way to compute a per-particle "4D" offset in terms of an adjustable lamb and
constant per-particle parameters.
Notes
-----
(ytz): this initializes the 4th dimension to a fixed plane adjust by an offset
fo... | a9455ed67fcb21bcf1382fe66a77e0563f467421 | 707,967 |
def endgame_score_connectfour(board, is_current_player_maximizer) :
"""Given an endgame board, returns 1000 if the maximizer has won,
-1000 if the minimizer has won, or 0 in case of a tie."""
chains_1 = board.get_all_chains(current_player=is_current_player_maximizer)
chains_2 = board.get_all_chains(curr... | bcb37381a9633377cb3405fbae45123e2a391df9 | 707,969 |
import copy
def identify_all_failure_paths(network_df_in,edge_failure_set,flow_dataframe,path_criteria):
"""Identify all paths that contain an edge
Parameters
---------
network_df_in - Pandas DataFrame of network
edge_failure_set - List of string edge ID's
flow_dataframe - Pandas DataFrame of... | db2da6ad20a4ae547c309ac63b6e68a17c3874e7 | 707,970 |
def update_bitweights(realization, asgn, tileids, tg_ids, tg_ids2idx, bitweights):
"""
Update bit weights for assigned science targets
"""
for tileid in tileids:
try: # Find which targets were assigned
adata = asgn.tile_location_target(tileid)
for loc, tgid in adata.items... | f1b7e085d43e36b025aa1c61ab1b7156ba1d3ed7 | 707,971 |
def load_from_input_flags(params, params_source, input_flags):
"""Update params dictionary with input flags.
Args:
params: Python dictionary of hyperparameters.
params_source: Python dictionary to record source of hyperparameters.
input_flags: All the flags with non-null value of overridden
hyper... | 7ec8662f03469f1ed03f29c9f7e9663c49aa7056 | 707,972 |
import os
import glob
def generate_dada_filelist(filename):
""" Generate a list of DADA files from start filename
Args:
filename (str): Path to file. e.g.
/data/dprice/2020-07-23-02:33:07.587_0000000000000000.000000.dada
Returns:
flist (list): A list of all a... | 55cde1a818e78886ace3aa89ff9535f099033a79 | 707,973 |
import os
import shutil
import subprocess
def buildWheels(buildDir, requirements):
"""build wheels
:param buildDir: directory to put wheels in (under 'wheelhouse')
:type buildDir: string
:param requirements: name of file holding names of Python packages
:type requirements: string
"""
whee... | 81bb1879ee1ce0e711dc36fe55cf0b47ad48f3c7 | 707,974 |
def kml_start(params):
"""Define basic kml
header string"""
kmlstart = '''
<Document>
<name>%s</name>
<open>1</open>
<description>%s</description>
'''
return kmlstart % (params[0], params[1]) | c2fa4c1eeff086dfc3baa41ecd067634920b25b1 | 707,975 |
import sys
import numpy
def _create_rpc_callback(label, result_counter):
"""Creates RPC callback function.
Args:
label: The correct label for the predicted example.
result_counter: Counter for the prediction result.
Returns:
The callback function.
"""
def _callback(result_futur... | 6b3276e9db5d551cb5abdd3f3f9b1f5ce041b02e | 707,976 |
def get_file_iterator(options):
"""
returns a sequence of files
raises IOError if problemmatic
raises ValueError if problemmatic
"""
# -------- BUILD FILE ITERATOR/GENERATOR --------
if options.f is not None:
files = options.f
elif options.l is not None:
try:
... | 53b16f49d14dc346e404a63415772dd2a1d10f50 | 707,977 |
def find_last_match(view, what, start, end, flags=0):
"""Find last occurrence of `what` between `start`, `end`.
"""
match = view.find(what, start, flags)
new_match = None
while match:
new_match = view.find(what, match.end(), flags)
if new_match and new_match.end() <= end:
... | fc863cf00d05a1fb6302a34b5b1e891e3c9eb3d7 | 707,978 |
import asyncio
async def get_series(database, series_id):
"""Get a series."""
series_query = """
select series.id, series.played, series_metadata.name, rounds.tournament_id, tournaments.id as tournament_id,
tournaments.name as tournament_name, events.id as event_id, events.name as event_name
... | f5e122052209c399c41afcd579f9b16e863c7a28 | 707,979 |
import math
def calc_distance(p1, p2):
""" calculates a distance on a 2d euclidean space, between two points"""
dist = math.sqrt((p2[0] - p1[0]) ** 2 + (p2[1] - p1[1]) ** 2)
return dist | d4005d44d5724c051860fb9aa2edeab1654157c6 | 707,980 |
def is_unique_n_bit_vector(string: str) -> bool:
"""
Similiar to the dict solution, it just uses a bit vector instead of a dict or array.
"""
vector = 0
for letter in string:
if vector & 1 << ord(letter):
return False
vector |= 1 << ord(letter)
return True | d19609f1fb1e6a189a9adb11b37a96632c8d0958 | 707,981 |
def crtb_cb(client, crtb):
"""Wait for the crtb to have the userId populated"""
def cb():
c = client.reload(crtb)
return c.userId is not None
return cb | eff248a877e195e59d2f6db812af2ff43955aee0 | 707,982 |
def _matching_not_matching(on, **kwargs):
"""
Change the text for matching/not matching
"""
text = "matching" if not on else "not matching"
classname = "colour-off" if not on else "colour-on"
return text, classname | aeefa7f16e3268ffe7af93db72490abe053370b2 | 707,983 |
import json
def metadata_to_list(metadata):
"""Transform a metadata dictionary retrieved from Cassandra to a list of
tuples. If metadata items are lists they are split into multiple pairs in
the result list
:param metadata: dict"""
res = []
for k, v in metadata.iteritems():
try:
... | 1044a93742a635e72e443d3a5c2e5805702d1602 | 707,984 |
def keep_english_for_spacy_nn(df):
"""This function takes the DataFrame for songs
and keep songs with english as main language
for english version of spacy neural network for word processing"""
#Keep only english for spacy NN English preprocessing words
#Network for other languages like fre... | e24402fa91ee0444c86867c98777fbd3cb7c9894 | 707,985 |
def parse_coap_response_code(response_code):
"""
Parse the binary code from CoAP response and return the response code as a float.
See also https://tools.ietf.org/html/rfc7252#section-5.9 for response code definitions.
:rtype float
"""
response_code_class = response_code // 32
response_code... | 9a8165f205ec2f6fe8576e18a831498f82834a10 | 707,986 |
def binary_search(sorted_list, item):
"""
Implements a Binary Search, O(log n).
If item is is list, returns amount of steps.
If item not in list, returns None.
"""
steps = 0
start = 0
end = len(sorted_list)
while start < end:
steps += 1
mid = (start + end) // 2
... | 30b1bba330752455d932b4c6cf1ad4dab5969db3 | 707,987 |
import traceback
def selectgender(value):
"""格式化为是/否
:param value:M/F,
:return: 男/女
"""
absent = {"M": u'男', "F": u'女'}
try:
if value:
return absent[value]
return ""
except:
traceback.print_exc() | 7b6b0b41b5ea8d3eaab5574881b40f5c00da73cd | 707,988 |
def unpack_batch(batch, use_cuda=False):
""" Unpack a batch from the data loader. """
input_ids = batch[0]
input_mask = batch[1]
segment_ids = batch[2]
boundary_ids = batch[3]
pos_ids = batch[4]
rel_ids = batch[5]
knowledge_feature = batch[6]
bio_ids = batch[1]
# knowledge_adjoin... | 6bc8bc9b3c8a9e2b40ac08e67c9fbcf84914e2eb | 707,989 |
def truncate(text: str, length: int = 255, end: str = "...") -> str:
"""Truncate text.
Parameters
---------
text : str
length : int, default 255
Max text length.
end : str, default "..."
The characters that come at the end of the text.
Returns
-------
truncated text... | f14605542418ca95e4752be7ec2fea189b9454ce | 707,990 |
def use_bcbio_variation_recall(algs):
"""Processing uses bcbio-variation-recall. Avoids core requirement if not used.
"""
for alg in algs:
jointcaller = alg.get("jointcaller", [])
if not isinstance(jointcaller, (tuple, list)):
jointcaller = [jointcaller]
for caller in joi... | c833f9a2dd9523f78cf294a1822b251b6940a1cd | 707,991 |
def merge_hedge_positions(df, hedge):
"""
将一个表中的多条记录进行合并,然后对冲
:param self:
:param df:
:return:
"""
# 临时使用,主要是因为i1709.与i1709一类在分组时会出问题,i1709.是由api中查询得到
if df.empty:
return df
df['Symbol'] = df['InstrumentID']
# 合并
df = df.groupby(by=['Symbol', 'InstrumentID', 'HedgeFla... | 4bcaa8b160186c6c5e6e3382017d0db3ee9d6c6e | 707,992 |
import numpy
def BackwardSubTri(U,y):
"""
usage: x = BackwardSubTri(U,y)
Row-oriented backward substitution to solve the upper-triangular, 'tridiagonal'
linear system
U x = y
This function does not ensure that U has the correct nonzero structure. It does,
however, attempt to catch ... | 5b7c2c636eac0912aa26bc8a236f1c870b95c48b | 707,993 |
def get_parameter_by_name(device, name):
""" Find the given device's parameter that belongs to the given name """
for i in device.parameters:
if i.original_name == name:
return i
return | 9669262a9bcac8b4c054e07b2c04b780b5f84f87 | 707,994 |
def sum_of_proper_divisors(number: int):
"""
Let d(n) be defined as the sum of proper divisors of n
(numbers less than n which divide evenly into n).
:param number:
:return:
"""
divisors = []
for n in range(1, number):
if number % n == 0:
divisors.append(n)
retu... | 9015dd3809f90d328b0b4a6b51f6fcb145f0241d | 707,996 |
import functools
def catch_exception(func):
"""
Returns:
object:
"""
@functools.wraps(func)
def wrapper(*args, **kwargs):
worker = kwargs['error_catcher']
try:
return func(*args, **kwargs)
except Exception as e:
print('stdout:', worker.stdou... | be579d9b6723e5025b7b70f38c83bcedc30196a5 | 707,997 |
def int_max(int_a, int_b):
"""
max(a, b)
"""
if int_a > int_b:
return int_a
else:
return int_b | 5ae0df8ff7bdc5539d127fad4df03b6215d9380f | 707,998 |
def get_cognates(wordlist, ref):
"""
Retrieve cognate sets from a wordlist.
"""
etd = wordlist.get_etymdict(ref=ref)
cognates = {}
if ref == "cogids":
for cogid, idxs_ in etd.items():
idxs, count = {}, 0
for idx, language in zip(idxs_, wordlist.cols):
... | bf64ecb8f2182dba06f0b28b384c0e66ba78d49e | 707,999 |
def get_lessons_of_day(day):
"""
Returns the lessons as a string for the given day webelement
:param day: day webelement
:return: dictionary with day as key and list with lessons as value
"""
day_lessons = []
to_iterate = day.find_elements_by_class_name('event-content')
to_iterate.reve... | 47b3ba18fd530ac8e724eb91e4b4d2886a008ac5 | 708,000 |
def bookShop():
"""
Este programa resuelve el siguiente ejercicio: Book Shop
Link: https://cses.fi/problemset/task/1158
Este programa retorna el máximo número de páginas que se pueden conseguir
comprando libros dados el precio y páginas de los libros disponibles y la
cantidad de dinero disponible.
"""
... | 52f2b3ca84c7d6db529f51e2c05ad4767d4466c7 | 708,001 |
import mpmath
def pdf(x, nu, sigma):
"""
PDF for the Rice distribution.
"""
if x <= 0:
return mpmath.mp.zero
with mpmath.extradps(5):
x = mpmath.mpf(x)
nu = mpmath.mpf(nu)
sigma = mpmath.mpf(sigma)
sigma2 = sigma**2
p = ((x / sigma2) * mpmath.exp(-(x... | b2d96bc19fb61e5aaf542b916d06c11a0e3dea46 | 708,002 |
def make_adder(n):
"""Return a function that takes one argument k and returns k + n.
>>> add_three = make_adder(3)
>>> add_three(4)
7
"""
def adder(k):
return k + n
return adder | 64808cb857f7bd17c8c81bfd749ed96efcc88a9f | 708,004 |
import torch
from typing import Union
from typing import Tuple
def groupby_apply(
keys: torch.Tensor, values: torch.Tensor, bins: int = 95, reduction: str = "mean", return_histogram: bool = False
) -> Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]:
"""
Groupby apply for torch tensors
Args:
... | 711acc0cf2eb30e978f7f30686dbf67644d51fb0 | 708,005 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.