content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def reduce_behave_data(df):
"""Trims df and changes dtypes to reduce pkl size"""
df = df[
["type_", "class_", "response", "correct", "rt", "reward", "stim_id", "subj"]
]
for col in ["correct", "reward"]:
df[col] = df[col].astype(bool)
for col in ["type_", "class_", "response", "subj"... | 1100f792040bb9f943e6b9c7b4159a3a7f617cd2 | 696,972 |
import re
def find_serial_number(show_ver):
"""
Find the serial number in show version output.
Example: Processor board ID FTX1512038X
"""
match = re.search(r"Processor board ID (.*)", show_ver)
if match:
return match.group(1)
return '' | 37b678555caaa58c08c3629c5a1fd85bd024a862 | 696,973 |
def unique_cols(x):
"""
Checks the columns for a taxid entry and only returns unique indices
This is meant to fix the problem of some taxids having multiple entries
for the same taxonomic rank.
Example: Alouatta palliata mexicana (Howler monkey)
taxid = 182248
superkingdom phylum or... | 6d2af3bf4257f57b265c0b573ef1b5ad2d8a40e6 | 696,974 |
def get_net_adjusted_income(gross_income, salary_sacrifice):
"""Returns net adjusted income, i.e. gross income net of salary sacrifice.
Should be fed with an absolute salary sacrifice."""
net_adjusted_income = gross_income - salary_sacrifice
return net_adjusted_income | e0acdd3d0f926d5268961729239b38598dc8be05 | 696,975 |
def byte_str(object):
"""bytes to str, str to bytes"""
if isinstance(object, str):
return object.encode(encoding="utf-8")
elif isinstance(object, bytes):
return bytes.decode(object)
else:
print(type(object)) | f84ec4e9b7932f397761296a5ef37ccd4b5e5d05 | 696,976 |
import random
import string
def random_name(N=10):
""" String of N random characters
Args:
N: int: the number of random characters
Returns:
s: string: the random string with N characters
"""
return "".join(
random.choice(string.ascii_lowercase + string.digits) for _ ... | 9f63408193f4636135ebf4689eaf81be35fa2b71 | 696,977 |
from typing import Tuple
def intersect(input_blocks: Tuple[int, int]) -> int:
"""Intersect tuple of input blocks to return air or stone
Arguments:
input_blocks {Tuple[int, int]} -- Two input blocks
Returns:
int -- Intersected block
"""
if input_blocks[0] == 0 or input_blocks[1] ... | f1a900d3421244b2754b2ec60fe527568fa76739 | 696,978 |
def calculate_driver_ability(calculated_data):
"""Calculates the relative driver ability for a team using driver zscores.
calculated_data is the calculated data for the team being calculated."""
agility_weight = 0.65
speed_weight = 0.35
driver_ability = calculated_data['agilityZScore'] * agility_we... | 5ae090342635b85514b1bdda0e49ed2d507589fb | 696,979 |
import struct
def decode_string(binary_input):
"""Decode a binary uon string. Length of the string is encoded
on the two first bytes, the string value is utf-8 encoded on the rest.
Args:
binary_input (bytes): a binary uon string
Returns:
tuple: uon string with the decoded value,
... | 96a7857352d0530bf5ed896be1203e82b8540f5b | 696,980 |
def url_add(**kwargs):
""" Displays a box containing an "add pattern" entry box and its form
"""
return kwargs | 7b515d82c20a5372eece459de26de66a38cbb15d | 696,981 |
def handle_es_request_error(error):
"""
handle all sorts of client errors (ClientError is a custom exception that is raised whenever
the search fails due to client errors)
"""
return str(error), 400 | b45686dcda1c11acd10283801e5dd03021fb71c1 | 696,982 |
def get_single_key_value_pair(d):
"""
Get the key and value of a length one dictionary.
Parameters
----------
d : dict
Single element dictionary to split into key and value.
Returns
-------
tuple
of length 2, containing the key and value
Examples
--------
... | c4fb7a05aa74a69ebb55a867e23298748a919738 | 696,983 |
def _fconvert(value):
"""
Convert one tile from a number to a pentomino character
"""
return {523: 'U', 39: 'N', 15: 'F', 135: 'W', 23: 'P', 267: 'L',
139: 'Z', 77: 'T', 85: 'Y', 43: 'V', 33033: 'I', 29: 'X'}[value] | 73900c0f76fd8ab50d92c9db049547c83ab1c5d0 | 696,984 |
def is_bad_ker(radar):
"""Kerava radar data rejection conditions"""
return False | d71526b11f1e48094a850a4ec400d35c48309255 | 696,985 |
def load_story_ids(filename):
""" Load a file and read it line-by-line
Parameters:
-----------
filename: string
path to the file to load
Returns:
--------
raw: list of sentences
"""
f = open(filename, "r")
story_ids = [line[:-1] for line in f]
f.close()
return story_... | a97580467da036b687fa1de4179159c113cf1d1b | 696,987 |
import os
def checkFileExists(filePathName):
""" check if file exists
Parameters:
filePathName: Path and name of the file to check
when the file was not found
return:
original filePathName or updated filePathName with new path
"" when file was not found
"""
... | 52ce7c67cae443ae36f7cc0ff8560d212c3b3054 | 696,988 |
import os
def get_base_filename(filename):
"""
Strips out preceding path and file extension from a filename.
:param filename: Filename, possibly including path and extension.
:return: Filename without path and without extension.
"""
base_file = os.path.basename(filename)
return os.path.spl... | 0b2ae0f6482979f530568b631826fcd0da107eb0 | 696,989 |
import six
def make_model_tuple(model):
"""
Takes a model or a string of the form "app_label.ModelName" and returns a
corresponding ("app_label", "modelname") tuple. If a tuple is passed in,
it's assumed to be a valid model tuple already and returned unchanged.
"""
if isinstance(model, tuple):... | 250586856243d6d019a45f0dc3f1b2a5eedf5dfb | 696,990 |
import socket
def is_live_server():
"""예를 들어 hostname이 '-live'로 끝나면 live server로 인식"""
return socket.gethostname().endswith('-live') | 629f6bd56d53bb5e3b20169ca05433f0cc095104 | 696,992 |
import re
def format_label_name(name):
"""
Format string label name to remove negative label if it is
EverythingElse
"""
m = re.match("\[([A-Za-z0-9]+)\]Vs\[EverythingElse\]", name)
if m is None:
return name
else:
return m.group(1) | 7fd5769314da849810b81a23ab32fe099ed600ae | 696,993 |
from pathlib import Path
def set_outputfile(file_pattern,
target_directory,
target_out_directory=None,
start_year=None,
end_year=None):
"""
Set output filename based on variables.
Parameters
----------
file_pattern : TYPE... | d3f52e95a95eb09121be7e60b5e8fc24aa356e76 | 696,994 |
def readFile(fileName):
"""Read a file, returning its contents as a single string.
Args:
fileName (str): The name of the file to be read.
Returns:
str: The contents of the file.
"""
fileContents = ""
with open(fileName) as inputFile:
fileContents = inputFile.rea... | 7292b38ac46fb60a733bffeddb9c7ee8fa600e03 | 696,995 |
def regenerate_node(arbor, node):
"""
Regenerate the TreeNode using the provided arbor.
This is to be used when the original arbor associated with the
TreeNode no longer exists.
"""
if node.is_root:
return arbor[node._arbor_index]
root_node = node.root
return root_node.get_node... | 6c900050ed03f8dc175a7b584cba04d9519cb232 | 696,996 |
import torch
def label2one_hot_torch(labels, C=14):
""" Converts an integer label torch.autograd.Variable to a one-hot Variable.
Args:
labels(tensor) : segmentation label
C (integer) : number of classes in labels
Returns:
target (tensor) : one-hot vector of the input label
Shape:
... | f44170bc7c8a37ca1ccb9afb104c9786e11f8396 | 696,997 |
def get_shape_columns(shape):
"""Return the number of columns for the shape."""
try:
return shape[1]
except (IndexError, TypeError):
return 0 | 48f5fb00248e7c51fb2c8e26e705b92d57f20d46 | 696,998 |
def formacion(soup, home_or_away):
"""
Given a ficha soup, it will return either the formacion table of the home team, or the away one.
Args:
soup (BeautifulSoup): Soup of the current match
home_or_away (int): Either a 1(home team) or 0(away team)
"""
return soup.find('table', attrs... | 9213eb269bbca0b5fd86ed9e5b5e43eef871dd4d | 696,999 |
def _observables_plots():
"""
Metadata for observables plots.
"""
def id_parts_plots(obs):
return [(obs, species, dict(label=label)) for species, label in [
('pion', '$\pi$'), ('kaon', '$K$'), ('proton', '$p$')
]]
return [
dict(
title='Yields',
... | b2c5d89eb7d70e140afbdf7efd191372c4e47ac6 | 697,000 |
def natural_death(params, substep, state_history, prev_state):
"""
Remove agents which are old or hungry enough.
"""
agents = prev_state['agents']
maximum_age = params['agent_lifespan']
agents_to_remove = []
for agent_label, agent_properties in agents.items():
to_remove = agent_prope... | 2b85c4161d20f8904485a80b847b7b6bf669dbc1 | 697,001 |
def _2D_ticks(x_num_ticks, y_num_ticks, env_config, type_):
"""
Generates the tick labels for the heatmap on a 2D-state environment
Parameters
----------
num_ticks : int
The total number of ticks along the axis
env_config : dict
The environment configuration file as a dict
t... | e0b93f06c0d8161d3464ac396b592baa1dcd965f | 697,002 |
def _splitDate(nymd):
"""
Split nymd into year, month, date tuple.
"""
nymd = int(nymd)
yy = nymd/10000
mm = (nymd - yy*10000)/100
dd = nymd - (10000*yy + 100*mm )
return (yy,mm,dd) | 0dca81925f6ea4e965962cd436444c3b78e05467 | 697,003 |
def authorized_cols():
"""Initialize authorized cols."""
return ['one', 'two'] | df580b201b94400530f74755bb55204fd32d8101 | 697,004 |
def get_values_greater_than(values, A): # O(N)
"""
From a ascendingly sorted array of values, get values > A
>>> get_values_greater_than([1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121], 64)
[121, 100, 81, 64]
>>> get_values_greater_than([1], 1)
[1]
"""
num_values... | a1599139be2823cdf05de88ef1cfdc0dd6eceb4c | 697,005 |
import numpy
def weight(x, J, delta, sigma, z):
"""
Generate a single block of connectivity matrix.
"""
return numpy.exp(-(x - x.T)**2/(2 * sigma**2)) * (J + delta * z) | ada874bcb3410811d576f02ce2b365d48d8e2146 | 697,006 |
import re
def sort_twisted37(arr):
"""
Sorts the array in ascending order, but where there is a 3 a 7 is placed and vice versa
Will first sort the array the usual way, creating a sorted copy of the input array
Loops through each number in the sorted array, checking the number is 3 or contains a 3
... | d71b5d748a7e10f76b11d1946939d0f48063b3a5 | 697,007 |
def by_command(extractor, prefix=('/',), separator=' ', pass_args=False):
"""
:param extractor:
a function that takes one argument (the message) and returns a portion
of message to be interpreted. To extract the text of a chat message,
use ``lambda msg: msg['text']``.
:param prefix:... | db76383bcad80be4381bb26fb65f4594576248b8 | 697,008 |
def get_filename_from_path(file_path, delimiter="/"):
""" Get filename from file path (filename.txt -> filename)
"""
filename = file_path.split(delimiter)[-1]
return filename.split(".")[0] | b079ce15dd44e8db314fdd5cb354e3bf2cab8471 | 697,009 |
import time
def loop(tasks=1, breaks=0, *args, **kwargs):
"""
Loop a function X amount of times
:param tasks: Amount of times to loop the function
:param breaks: The amount of time to wait between each loop.
"""
def wrapper(original_func, *args, **kwargs):
for i in range(tasks):
... | 6d682d7d980c7f17ad2ccc45c7a509b52cf23065 | 697,010 |
def add(first, second):
"""Return the sum of the two numbers."""
return first + second | 2b9b604d4958579774e6c96eab2bea63506468df | 697,011 |
import os
import csv
import gc
def read_RSEM_counts_files(geneFilePath,isoformFilePath):
"""
read the RSEM counts files into a matrix
"""
if not os.path.exists(geneFilePath):
raise Exception("Cannot find gene file\n%s"%(geneFilePath))
if not os.path.exists(isoformFilePath):
raise ... | 8c692b0c9089ae1eb95fbc006b97d12e1b8fefb5 | 697,012 |
import os
def list_dir_abspath(path):
"""
Return a list absolute file paths.
see mkdir_p os.listdir.
"""
return map(lambda f: os.path.join(path, f), os.listdir(path)) | 55fc543efd4bbad63c66c5c5537a4b640d5fff56 | 697,013 |
import socket
import re
def inject_payload(conn: socket.socket, payload) -> bool:
"""
Inject a payload into the backdoor connection.
:param conn: socket object connected to backdoor
:param payload: payload to inject (usually a reverse shell)
:return: boolean indicating success or failure
"""
... | 907df512f344288d076c1d1fed95aecfc016d413 | 697,014 |
def nraphson(f, df, x0, tol=1e-3, maxit=20000):
"""
Newto Raphson Equation Solving
Compute Equation roots given its equation and derivate
Xn = Xn-1 - f(x)/f'(x)
:param f: Function f(x) handler
:param df: Derivate of f'(x) handler
:param x0: Inital guess
:param maxit: ... | 6256ba5e51f94ea1a35fd4e4957520348ae69d6f | 697,015 |
def doublecomplement(i,j):
"""
returns the two element of (1,2,3,4) not in the input
"""
list=[1,2,3,4]
list.remove(i)
list.remove(j)
return list | b4bb329b320b2b8c3e7b7648914636f96394b6d7 | 697,016 |
def yr_label(yr_range):
"""Create label of start and end years for aospy data I/O."""
assert yr_range is not None, "yr_range is None"
if yr_range[0] == yr_range[1]:
return '{:04d}'.format(yr_range[0])
else:
return '{:04d}-{:04d}'.format(*yr_range) | c453d759a23dce169593afc64846e9560d9f1cb5 | 697,017 |
def setup_with_context_manager(testcase, cm):
"""Use a contextmanager to setUp a test case.
If you have a context manager you like::
with ctxmgr(a, b, c) as v:
# do something with v
and you want to have that effect for a test case, call this function from
your setUp, and it will s... | e2a67d9a9600203223a220eb0a5e40c96ae6166d | 697,018 |
def zip_with(fn, xs, ys):
"""
Standard python zip with function. User can define custom zipping function instead of the standard tuple.
"""
return [fn(a, b) for (a, b) in zip(xs, ys)] | 7ac086d61198262b8b355e6eacb82be364b1f6a6 | 697,019 |
import os
def simple_path(input_path, use_basename=True, max_len=50):
"""
Return the last part of long paths
"""
if use_basename:
return os.path.basename(input_path)
if len(input_path) > max_len:
return f"[Trunked]..{input_path[len(input_path)-max_len:]}"
return input_path | 15ad6cb5a5b07bb7b5db9b2d1f6c62c45bc43517 | 697,020 |
def catch_bare_exception_sanitize_array(e):
"""See pandas-dev/pandas#35744"""
return isinstance(e, Exception) and 'Data must be 1-dimensional' in str(e) | c5a327ba0ba22cbbe877206635c3a089daa6f5a1 | 697,021 |
from typing import Tuple
def hosting_period_get(month: int) -> Tuple[int, int]:
"""Determine the Hosting period for the current month."""
# In February only, Hosts begin on the 1st and 15th
if month == 2:
return (1, 15)
# For all other months, Hosts begin on the 1st and 16th
return (1, 16... | 77d7bc84f969b8be0f4e81ddb26d96e0d7569561 | 697,022 |
def exclude_sims_by_regex(sims, regex):
"""Removes sims by using a regular expression.
DESCRIPTION:
Returns all sims that do NOT match the regular expression.
ARGS:
sims (iterable of strings): An iterable of strings contating candidate
sim files
regex (_sre.SRE_Pattern)... | e8ca8399430e7d0017e1fb621b38103eac678089 | 697,023 |
import pytz
def http_date(dt):
""" Convert datetime object into http date according to RFC 1123.
:param datetime dt: datetime object to convert
:return: dt as a string according to RFC 1123 format
:rtype: str
"""
return dt.astimezone(pytz.utc).strftime('%a, %d %b %Y %H:%M:%S GMT') | 20db2de2969216d201bc65227fb4b54e5c71a4c5 | 697,024 |
def get_completer_delims(): # real signature unknown; restored from __doc__
"""
get_completer_delims() -> string
get the word delimiters for completion
"""
return "" | 4cef2f0f98efaa4a624065c9ac60c96534b576f9 | 697,025 |
def build_telegram(name: str, message: str, title="Dr") -> str:
"""Generate a properly formatted telegram message body.
Args:
name: The recipient of this telegram
message: The message to send this user
title: The recipient's title
Returns:
A properly formatted string fo... | 7d3af3b3a61a7f2f141be6f50e10199e340245d2 | 697,027 |
def train2rect(ratios, imagew, imageh):
"""
Takes in data used during training and transforms it into format matching
the format outputted by darknet's valid function.
"""
xratio, yratio, wratio, hratio = ratios
xmin = xratio*imagew - wratio*imagew/2
ymin = yratio*imageh - hratio*imageh/2
... | 7675df2c314088d6363bf40dff1aac04b22c61bf | 697,028 |
def is_key_complete(key):
"""Returns true if the key is complete. Complete keys are marked
with a blank symbol at the end of the string. A complete key
corresponds to a full word, incomplete keys cannot be mapped to
word IDs.
Args:
key (string): The key
Returns:
bool. Return tr... | ecf905f973fd14f1be21b1490ad8a18988397ab9 | 697,029 |
def acknowledgements(name, tag):
"""Returns acknowledgements for space weather dataset
Parameters
----------
name : string
Name of space weather index, eg, dst, f107, kp
tag : string
Tag of the space waether index
"""
swpc = ''.join(['Prepared by the U.S. Dept. of Commerce,... | f490fe6cd4f85baad6a097b71410bb014ec0394e | 697,030 |
def rectangleOverlap(BLx1, BLy1, TRx1, TRy1, BLx2, BLy2, TRx2, TRy2):
""" returns true if two rectangles overlap
BL: Bottom left
TR: top right
"1" rectangle 1
"2" rectangle 2
"""
return not (TRx1 < BLx2 or BLx1 > TRx2 or TRy1 < BLy2 or BLy1> TRy2) | 96ea5aab6738f72587c5dd9db45598e291e68338 | 697,031 |
import itertools
def build_vocab(tokenized_src_trgs_pairs, opt):
"""Construct a vocabulary from tokenized lines."""
vocab = {}
for src_tokens, trgs_tokens in tokenized_src_trgs_pairs:
tokens = src_tokens + list(itertools.chain(*trgs_tokens))
for token in tokens:
if token not in... | 67abde6882f9ef9b6f20a06447a2dae2ec4b6ad8 | 697,032 |
from typing import Tuple
def _identify_missing_columns(
schema_field_names: Tuple[str, ...],
column_names: Tuple[str, ...],
) -> Tuple[bool, ...]:
"""Returns boolean mask of schema field names not in column names."""
return tuple(field_name not in column_names for field_name in schema_field_names) | c6ca296e5dd4d2271b06e5e3a21a3a8d716d76cd | 697,033 |
import re
def get_patient_uuid(element):
"""
Extracts the UUID of a patient from an entry's "content" node.
>>> element = etree.XML('''<entry>
... <content type="application/vnd.atomfeed+xml">
... <![CDATA[/openmrs/ws/rest/v1/patient/e8aa08f6-86cd-42f9-8924-1b3ea021aeb4?v=full]]>
... | 0d80313b6c7305ec72c96e29269d15718e4105da | 697,034 |
def split_member_name(name_member):
"""split_member_name
Quebra o nome do usuário a partir do "#" retornando somente o nome
"""
name_of_author_return, hashtag_atrelada = name_member.split('#')
hashtag_atrelada = hashtag_atrelada
return name_of_author_return | a492ef055b4bf68749a9d0a217d8cc21de9eb8ac | 697,036 |
import subprocess
def execute_program(args):
"""Executes a process and waits for it to complete.
@param args: is passed into subprocess.Popen().
@returns a tuple of the process output (returncode, output)
"""
proc = subprocess.Popen(args, stdout=subprocess.PIPE,
stde... | dbf64fa8ae4d0250ab9082cc822690756a62a4e2 | 697,037 |
def read_teachers(connection):
"""
read teacher to extract results.
:param connection:
:return:
"""
teachers_list = []
sql_select = """SELECT DISTINCT(LOWER(XMPY)) FROM teacher"""
cursor = connection.cursor()
cursor.execute(sql_select)
teachers = cursor.fetchall()
for teacher... | 3b37e454f779da2f186a96a4cdf1d1d95164037a | 697,038 |
import argparse
def get_args():
"""
Supports the command-line arguments listed below.
"""
parser = argparse.ArgumentParser(
description='vfs_stress Server runner')
parser.add_argument('cluster', type=str, help='File server name or IP')
parser.add_argument('-c', '--clients', type=str, ... | 7af2c93aaa51d83d15d6b24424ef4d4e59083db0 | 697,039 |
from typing import List
def csv_to_ints(school_description: str) -> List[int]:
"""Convert a comma separated string of integers to a list of integers.
Returns
-------
list[int]
The list of integers from the string of comma separated values.
>>> csv_to_ints('3,8,0')
[3, 8, 0]
"""
... | 199fe36a12ba5a95895110c0614761578bc786ca | 697,040 |
def next_left(node):
"""
It returns the successor of node on this contour.This successor is either given by
the leftmost child of node or by the thread of node. The function returns None if
and only if node is on the highest level of its subtree.
"""
if node.children: # if node has ... | 2ae9b2fec699f3a2da72901ad12f3a331c260044 | 697,041 |
import functools
def chainingmethod(func):
"""
Declare a method is a chaining method which return self as returned value
:param func: real func
"""
@functools.wraps(func)
def chaining(self, *args, **kwg):
func(self, *args, **kwg)
return self
return chaining | 0e07d99bd196257483e50c6df119ad3c4f0128fd | 697,042 |
def event_counter(json_, counter):
"""
takes a json and counts the number of events that happened during that game
inputs
------
json__: events json
counter: counter dictionary
returns
-----
counter: counter dict with counts
"""
for event in json_:
event_type = event... | 97a10f5f219cf383c419ba65764b4c9c3f47b5ec | 697,043 |
import hashlib
import base64
def calc_md5(string):
"""Generates base64-encoded MD5 hash of `string`."""
md5_hash = hashlib.md5()
md5_hash.update(string)
return base64.b64encode(md5_hash.digest()).strip(b"\n") | 88135c92de48fe45888a4a4243cce13fcddceca8 | 697,044 |
def get_content(file):
"""Returns a string
If file 'bruh' contains "Hellor"
get_content("bruh") returns 'Hellor'
"""
file = open(file, "r")
res = file.read()
file.close()
return res | ae86220be856e23ed143d77117a181054565eff0 | 697,045 |
import os
import fnmatch
def find_all_files(path, suffix="*.jpg"):
""" find all the absolute path of files """
dirs = [path]
files = []
while True:
_dir = dirs.pop(0)
subdirs = [os.path.join(_dir, subdir) for subdir in os.listdir(_dir)]
for subdir in subdirs:
if os.... | 936b577953468f468f95e91a7c3ea2fc79450b18 | 697,046 |
def convert_to_float(frac_str):
"""
convert string of fraction (1/3) to float (0.3333)
Parameters
----------
frac_str: string, string to be transloated into
Returns
-------
float value corresponding to the string of fraction
"""
try:
return float(frac_str)
except Valu... | 4f4e2ad0e5eeee7a8cc54b8b724031a48a48d747 | 697,047 |
import re
def parse_fst_session_event(ev):
"""Parses FST session event that comes as a string, e.g.
"<3>FST-EVENT-SESSION event_type=EVENT_FST_SESSION_STATE session_id=0 reason=REASON_STT"
Returns a dictionary with parsed "type", "id", and "reason"; or None if not
a FST event or can't be parsed"""
... | e57cb2561e23ad89bb42559ae90c61c22d98e977 | 697,048 |
from typing import List
def parse_input_file(file_path: str) -> List[List[int]]:
"""Parse a file with the following format:
21 22 24
12
7 21 23
Returns each line as integers in a nested list
"""
with open(file_path) as input_file:
parsed_file = [list(map(int, line.split())) for li... | f281dbcc7c9dc70eab491b1a334e0cb0cc3e45e4 | 697,049 |
def unlines(line):
"""Remove all newlines from a string."""
return line.translate(str.maketrans('\n', ' ')) | 0c2079d9694a8c48f8ddf0a87696ea89a72b1dc3 | 697,050 |
import random
def train_valid_test_split_by_conversation(conversations, split_ratio=[0.8, 0.1, 0.1]):
"""Train/Validation/Test split by randomly selected movies"""
train_ratio, valid_ratio, test_ratio = split_ratio
assert train_ratio + valid_ratio + test_ratio == 1.0
n_conversations = len(conversati... | 6084f28af77dd2598c9d563b4cbb1a7fda5423ac | 697,051 |
import torch
def cheb_conv(laplacian, inputs, weight):
"""
Chebyshev convolution.
Args:
laplacian (:obj:`torch.sparse.Tensor`): The laplacian corresponding to the current sampling of the sphere.
inputs (:obj:`torch.Tensor`): The current input data being forwarded.
weight (:obj:`to... | 219d3d7055bbe588d3a25de1f05106436f867d24 | 697,055 |
def reencode(s):
"""Reencodes a string using xmlcharrefreplace."""
return s.encode('ascii', 'xmlcharrefreplace').decode() | ff5bd9c2ac6754bf76f3935c947a3081f83a6781 | 697,056 |
def decode_note(message):
"""
Used by note update methods (add/change/remove).
Only the latter omits the pitch/pos, and therefore is shorter.
"""
instrument_id = ord(message[1])
note = {
'id': ord(message[2])
}
if len(message) > 3:
note['pos'] = ord(message[3])
... | fbc5e1bfc39b91447226e6ac5c4c549a8b78de9b | 697,057 |
from typing import List
def _bucket_to_range(bucket: int, boundaries: List[float]) -> bytes:
"""Returns boundaries of bucket as string."""
if bucket == len(boundaries):
end = 'inf'
else:
end = str(boundaries[bucket])
if bucket == 0:
start = '-inf'
else:
start = str(boundaries[bucket - 1])
... | 78ad10f1db48beba4c909635180e31dff7c5407e | 697,058 |
import aiohttp
import json
async def fetch(url: str) -> dict:
""" Method to easily fetech data from an api """
async with aiohttp.ClientSession() as session:
async with session.get(url) as r:
data = await r.read()
return json.loads(data) | 9694a77ebfcb78d70368e8ba305bd1f66b936d2c | 697,059 |
import random
def distselect(weight_l):
"""Perform a weighted selection using the weights
from the provided list. Return the selected index"""
if not isinstance(weight_l, list):
raise Exception("distselect requires a list of values")
# Create a weight/index vector
weight_v = []
tota... | 8877c957cbd3c82f37f9bec948fb64c1c33dc341 | 697,060 |
def load_grid(input_grid):
"""
Convert the text form of the grid into an array form. For now this input is
always the same. If this changes then this code would need to be replaced.
"""
grid = [
[".#./..#/###"]
]
return grid | a7a01542aea9d2332c0e307044930538f8ee42d5 | 697,061 |
import requests
def retrieve_online_json(url:str) -> dict:
"""
This function downloads an online json file and returns it.
:argument url: The url where to find the json file to retrieve.
:return: A dictionary containing all the downloaded data.
"""
return requests.get(url).json() | d99d7219f91f2ab67bace1b0ef0d4e9c4201318e | 697,062 |
import torch
def adjusted_rand_index(true_mask, pred_mask):
"""
compute the ARI for a single image. N.b. ARI
is invariant to permutations of the cluster IDs.
See https://en.wikipedia.org/wiki/Rand_index#Adjusted_Rand_index.
true_mask: LongTensor of shape [N, C, H, W]
background == 0
... | 19a56838b86e97188c68e537a2ef2312a3c76ed1 | 697,063 |
import re
def strip_markdown(s):
"""
Strip some common markdown out of
the description, for the cases where the
description is taken from the first paragraph
of the text.
"""
s = re.sub("[\\[\\]]", "", s)
s = re.sub("\(.*\)", "", s)
return s | e10e02ec385990e908e4096272df40f3dccee364 | 697,064 |
def get_expression_samples(header_line):
"""
Parse header of expression file to return sample names and column indices.
Args:
header_line (str): Header line from expression file.
Returns:
act_samples (dict): Dictionary of {sample_name (str): sample_data_index (int)}.
sample... | 615ee0421b1efaf4ef45cab9610cea883f9636b1 | 697,066 |
import sys
import re
def fastq_to_fasta(file, new_file):
"""
Convert fastq file to fasta
Fastq format short example:
@SEQ_ID
GATCTGG
+
!''****
Fasta format short example:
>SEQ_INFO
GATCTGG
"""
try:
file_handle_read = open(file, "rt")
line ... | 6c7acbefc2279bf78953357d7229dec68eac5e17 | 697,067 |
def evens(i):
"""assumes i is a number
returns a boolean, True if i is even, else False"""
if i % 2 == 0:
return True
else:
return False | 2dafcad23f38f4c8a610d24646ef482ef7e99f43 | 697,069 |
def ot2bio_ts(ts_tag_sequence):
"""
ot2bio function for ts tag sequence
:param ts_tag_sequence:
:return:
"""
new_ts_sequence = []
n_tag = len(ts_tag_sequence)
prev_pos = '$$$'
for i in range(n_tag):
cur_ts_tag = ts_tag_sequence[i]
if cur_ts_tag == 'O':
new... | 0b6ff5c84627b4fff7aad92201c122e23a9ca3a3 | 697,070 |
import os
def read_bboxes_data(file_path, images_folder):
""" 从bounding box的txt文件中读取信息
:param file_path: 保存bounding box信息的txt文件路径
:param images_folder: 图片根目录
:return: 图片路径及bounding box信息
{'images':路径列表,'bboxes':对应的bounding boxes}
"""
images_path = []
bboxes = []
with open(file_path... | 15ce684172b8de3b1eab048331a7bdc520751bab | 697,071 |
from typing import List
def is_cyclic(dp_heads: List[int]) -> bool:
"""return True if dp_heads is cyclic, else False"""
dp_heads = [0] + dp_heads
detected = [False] * len(dp_heads)
detected[0] = True
for word_idx, parent_idx in enumerate(dp_heads[1:]):
if detected[word_idx]:
co... | 078d32133a90cc3197ca22026ab7b38cec559d97 | 697,072 |
def add_column(sheet, meta_column, col, colname):
"""
Add one empty column to a sheet
@param sheet : sheet to be updated
@param col : column number
@param colname : text for row 0 in the column
"""
sheet.cell(column=col, row=0).value = colname
meta_column[colname] = col
return met... | 9a85d8ef92851bf194c66e1e6b6a7fae9974ce1d | 697,073 |
def composite_simpson(f, b, a, n):
"""
Calculate the integral from 1/3 Simpson's Rule
Parameters:
f: Function f(x)
a: Initial point
b: End point
n: Number of intervals
Returns:
xi: Integral value
"""
h = (b - a) / n
sum_odd = 0
sum_even = 0
f... | eb06a4776248763a825c9c41f592b736af230238 | 697,074 |
def PyMapping_Check(space, w_obj):
"""Return 1 if the object provides mapping protocol, and 0 otherwise. This
function always succeeds."""
return int(space.ismapping_w(w_obj)) | f9d0644fc5f7bfeaa3c08b2c2596a4658b2e508b | 697,075 |
def create_shift_vars(prev_shift_vars, model, staff, shifts, shift_days):
"""Shift variables for current roster period."""
shift_vars = {
(staff_member, role, day, shift): model.NewBoolVar(
f"staff:{staff_member}_role:{role}_day:{day}_shift:{shift}"
)
for staff_member in staf... | da61519cbe61cd066c8072382ccf659aad6829e9 | 697,076 |
def validate_field(field):
"""
Return field if it exists
otherwise empty string
:param field: string to validate
:return: field: input string if not empty, empty string otherwise
"""
if field:
pass
else:
field = ''
return field | a7f631372914de355872063d80f40c586c098788 | 697,077 |
from random import randint
def generate_random_ip():
"""
Returns a random IP as a string
:return: a random stringified ip
:rtype: str
"""
return '.'.join(str(randint(0, 255)) for _ in range(4)) | 8ea26fc948664b1d84923f03960e9822a45ecc53 | 697,078 |
def linear_search(nums_array: list, search: int) -> int:
"""
Linear Search Algorithm
Time Complexity --> O(N)
:param nums_array: list
:param search: int
:return index: int
"""
for i in range(len(nums_array)):
if search == nums_array[i]:
return i
return -1 | a02db3d42d6b6f1b8b2a82940d3e17d69bbd41e7 | 697,079 |
import math
def _acosd(v):
"""Return the arc cosine (measured in in degrees) of x."""
return math.degrees(math.acos(v)) | 2e31e36a33a4ac25f2b2548733138dcbf910028f | 697,081 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.