content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def assemble_result_str(ref_snp, alt_snp, flanking_5, flanking_3):
"""
(str, str, str, str) -> str
ref_snp : str
DESCRIPTION: 1 character (A, T, G or C), the reference SNP.
alt_snp : str
DESCRIPTION: 1 character (A, T, G or C), the variant SNP.
flanking_5 : str
DESCRIPTI... | bc0b43464124d0d19f4bfc5646730a1f951a5ced | 8,517 |
import requests
def get_api_data(session, url, date_time):
"""Get the JSON-formatted response from the AMM API for the desired
date-time.
"""
session = session or requests.Session()
return session.get(url, params={"dt": date_time.format("DD/MM/YYYY")}).json() | ff44be4a958c4f05cc5bd562854059c552f693e1 | 8,518 |
def trunc(s, length):
"""Truncate a string to a given length.
The string is truncated by cutting off the last (length-4) characters
and replacing them with ' ...'
"""
if s and len(s) > length:
return s[:length - 4] + ' ...'
return s or '' | ea6d1702d709ac7d94cc2bcb2e945da71009c0fe | 8,520 |
import operator
def sort_values(values: list[tuple]) -> list[tuple]:
"""Returns a list of tuples sorted by x value (the value at index 0 of the inner tuple."""
return sorted(values, key=operator.itemgetter(0)) | f172f68418988d4e01dcc406de8ec467abfe7aa8 | 8,521 |
def calc_rank(age, is_veteran=False, has_disability=False):
"""
Calculate a participant's rank. A higher number is higher ranked (top of the list).
(i.e., Reverse this when sorting.)
Change this function to change the ranking algorithm.
The code in the comments below is a ranking system based ... | 2c3ab7446ac12e634ffe47b0e57e2232908b12b9 | 8,522 |
from pathlib import Path
import os
import zipfile
import re
def list_geo_file(folder=""):
"""Lists all the files in the folder named "folder"
contained in GeoWatch Labs Agricultural Maps.
Args:
folder (str): folder name in which to search in GeoWatch Labs Agricultural
Maps folder.
Re... | 6d233447bcba53401900b3073843e8c435c967dd | 8,523 |
def expose(class_method):
"""
Decorator which exposes given method into interface
:param class_method: method to expose
:return: given method with modifications
"""
class_method.is_exposed = True
return class_method | ee234bd7535f29c39fc80643997b89aeb3c0f533 | 8,524 |
def merge_length_list(lists):
"""
Merge the list that demonstrates the word length
"""
res_list = []
for l in lists:
if len(res_list) < len(l):
res_list[len(res_list):] = [0] * (len(l)-len(res_list))
for length, num in enumerate(l):
res_list[length] += num
... | 564742fd7e0a7f3a0a8535a1f02c343d193a69ac | 8,525 |
def func(pseudo_state, a1, a2, b1, b2, c1, c2, d1, d2):
"""
quadratic fit function for the Bellman value at given pseudo-state
:param pseudo_state: list(float) - list of the four state variables for a given state
:param a1, a2, ... d2: float - parameters of the quadratic fit function
"""
sum = a1*pseudo_state[0... | 6478219704999dc4cfcbc915126d919e15fe3043 | 8,526 |
def intersection(box1, box2):
"""
Args:
box1: bounding box
box2: bounding box
Returns:
float: the area that intersects the two boxes
"""
y_min1, x_min1, y_max1, x_max1 = box1
y_min2, x_min2, y_max2, x_max2 = box2
min_ymax = min(y_max1, y_max2)
max_ymin = max(y_mi... | 71746d93ead54aa5b36e7e6a5eb40e757711bef5 | 8,527 |
import sys
def deep_getsizeof(data, ids=None):
"""
Returns the memory footprint of a (essentially) any object;
based on sys.getsizeof, but uses a recursive method to handle collections
of objects.
"""
if ids is None:
ids = set()
if id(data) in ids:
return 0
size = sys... | 5e92a2b2e917f6d3a3bee06d305b580e669573c1 | 8,530 |
def calculateHeaders(tokens: list, rawHeaders: tuple) -> tuple:
"""
Takes sanitised, tokenised URCL code and the rawHeaders.
Calculates the new optimised header values, then returns them.
"""
BITS = rawHeaders[0]
bitsOperator = rawHeaders[1]
MINREG = 0
MINHEAP = rawHeaders[3]
... | 472eeb4397d68e232b66517064f91e5688c33e3c | 8,531 |
def weg(m) -> str:
"""capture multiple "weg"s"""
return m | 2be9b16a4969d04f1322c22b07ffd98318fa05fb | 8,532 |
def _monom(n):
"""
monomial in `eta` variables from the number `n` encoding it
"""
v = []
i = 0
while n:
if n % 2:
v.append(i)
n = n >> 1
i += 1
return v | 42621ddbca95b8fc3ca3d7eea51cc1dc97524758 | 8,534 |
from datetime import datetime
def month_counter(fm, LAST_DAY_OF_TRAIN_PRD=(2015, 10, 31)):
"""Calculate number of months (i.e. month boundaries) between the first
month of train period and the end month of validation period.
Parameters:
-----------
fm : datetime
First day of first month o... | e10e6be0eb8a7762b182d073ca85ed1b97f831d3 | 8,535 |
def to_unicode(obj):
"""Convert object to unicode"""
if isinstance(obj, bytes):
return obj.decode('utf-8', 'ignore')
return str(obj) | e54c02e04109b8a99a7eb4e357e95ead89166137 | 8,536 |
def get_shape(x, unknown_dim_size=1):
"""
Extract shape from onnxruntime input.
Replace unknown dimension by default with 1.
Parameters
----------
x: onnxruntime.capi.onnxruntime_pybind11_state.NodeArg
unknown_dim_size: int
Default: 1
"""
shape = x.shape
# replace unknow... | 1c719191922a46b948fb567273e3a5152769e190 | 8,539 |
def word_tally(word_list):
"""
Compiles a dictionary of words. Keys are the word, values are the number of occurrences
of this word in the page.
:param word_list: list
List of words
:return: dictionary
Dict of words: total
"""
word_dict = {}
for word in word_list:
... | 5ab1f7ac4c8a72cd5ceda2a391cef8a62a1ec34f | 8,540 |
def step_lr(lr_max, epoch, num_epochs):
"""Step Scheduler"""
ratio = epoch/float(num_epochs)
if ratio < 0.3: return lr_max
elif ratio < 0.6: return lr_max*0.2
elif ratio <0.8: return lr_max*0.2*0.2
else: return lr_max*0.2*0.2*0.2 | 515bb508a207f6aa5175756b49f26d53de9d7f6f | 8,543 |
def dir_basename_from_pid(pid,j):
""" Mapping article id from metadata to its location in the arxiv S3 tarbals.
Returns dir/basename without extention and without full qualified path.
It also ignores version because there is no version in the tarbals.
I understand they have the updated version in the tarball... | 38a955b2caecfa65f8aad44c8cf0fbc21d0b3709 | 8,545 |
import re
def fix_extension(filename_end):
"""Processes ending section of filename to get extension
Args:
filename_end (str): starting section of filename
Returns:
str: file extension
"""
return_value = filename_end
pattern_string = r".*\.(\w{3})$"
pattern = re.compile(
... | 5317c3c52920d669374ac72cc6cccc70a2740174 | 8,548 |
import numpy as np
def acf(x,l):
""" Auto correlation function of a given vector x with a maximum lag of length l.
"""
return np.array([1]+[np.corrcoef(x[:-i], x[i:])[0,1] \
for i in range(1, l)]) | f168cf69b7055508a95c22b869b36e5c808f5953 | 8,550 |
def parse_map_align_stdout(stdout):
"""Parse the stdout of map_align and extract the alignment of residues.
Parameters
----------
stdout : str
Standard output created with map_align
Returns
------
dict
A dictionary where aligned residue numbers in map_b are the keys and resi... | 4cb699ffbb817e80402af22b08240323012919f8 | 8,551 |
import math
def ads(x, adsParameter):
""" ADS function """
p = adsParameter
exp1 = 1 + math.exp(-1 * (x - p.C + p.D / 2) / p.E)
exp2 = 1 + math.exp(-1 * (x - p.C - p.D / 2) / p.F)
dx = p.A + p.B / exp1 * (1 - 1 / exp2)
return dx / p.DMAX | f09f35aea0bc43c3dcefb922a306c6745e472aaa | 8,553 |
def last_common_ancestor(taxonomies):
"""Compute last common ancestor"""
lca = list()
if len(taxonomies) > 1:
zipped = zip(*taxonomies)
for level in zipped:
if len(set(level)) > 1:
level = "*"
else:
level = level[0]
lca.appe... | 0f49b2faa2e480afd41b93d5442d2ee1b86d5b24 | 8,554 |
import struct
import socket
def ip_to_ascii(ip_address):
""" Converts the quad IP format to an integer representation. """
return struct.unpack('!L', socket.inet_aton(ip_address))[0] | 2cb3ccbe70eed2dd2e8ac21d10e180805dec95ea | 8,555 |
def _method_from_mod(block_dets, modname, methodname):
"""
E.g.
from os import getcwd
from os.path import join
from os.path import join as joinpath
<ImportFrom lineno="4" col_offset="0" type="int" module="os" level="0">
<names>
<alias type="str" name="getcwd"/>
"""
imp... | d50c91099feee6ee40e8d7ae682112bd4ce6d0f6 | 8,556 |
from typing import Any
from typing import Sequence
def complete_ports(_: Any, __: Any, incomplete: str) -> Sequence[str]:
"""Returns common ports for completion."""
return [k for k in ('80', '443', '8080') if k.startswith(incomplete)] | 694306ae57bcfd21d6fa73a595768dde0ffba86a | 8,557 |
def _get_max_mem():
"""Return the current cgroup's memory high water mark."""
try:
with open("/sys/fs/cgroup/memory/memory.max_usage_in_bytes") as f:
return float(f.read().strip())
except Exception:
return 0 | 6031fdc75c6ca2fd8f74e52951316e708b0eb36e | 8,558 |
import os
def add_image(qc_html, image, title=None):
"""
Adds an image to the report.
"""
if title:
qc_html.write('<center> {} </center>'.format(title))
relpath = os.path.relpath(image, os.path.dirname(qc_html.name))
qc_html.write('<a href="' + relpath + '" >')
qc_html.write('<img... | 01c4117c3ae9e18b6cfc49bcad11af97b80bc130 | 8,559 |
def coord_arg_to_coord(carg):
"""
Parameters
----------
carg : str
Argument from parser for coordinates
Eligible formats are like:
J081240.7+320809
122.223,-23.2322
07:45:00.47,34:17:31.1
Returns
-------
icoord : str or tuple
Allowed format for c... | 16a6cb8090dc040b7b5f6a1a4ba873ea65e0dfdf | 8,561 |
def amount_in_location(obj, user):
"""
Returns how many instances of this product
are at the current user's location
"""
return obj.get_amount_stocked(user) | 4b722cb9e5721cbc2c7d87ff30046087853cd5c0 | 8,563 |
def format_string():
"""Returns the format string of the binary file"""
return "IIccccI?cccc" | f833be1ff5ffcbc538ba0b785e9fe43c0513b688 | 8,564 |
def getCountryData(df):
"""
Implement a function to get counts of data based on show type
"""
country_df = df[["country","type","index"]]
country_df = country_df.groupby(['country','type']).count().unstack()
country_df.columns = ['Movie','TV Show']
country_df = country_df.reset_index().filln... | bde3247bc95c4914d3b665225aee9dd2a0bfe2b6 | 8,565 |
def all_success(mgmt_commands):
"""Determines if all child processes were successful.
Args:
mgmt_commands : A list of all Command objects
Returns:
True if all child processes succeeded
"""
for mgmt_command in mgmt_commands:
if mgmt_command.retcode != 0:
return False
return True | 1bc0d32491711e0d20106f1f294093b30e77bd55 | 8,566 |
import re
def get_nameservice(hdfs_site):
"""
Multiple nameservices can be configured for example to support seamless distcp
between two HA clusters. The nameservices are defined as a comma separated
list in hdfs_site['dfs.nameservices']. The parameter
hdfs['dfs.internal.nameservices'] was introduced in Had... | 65a86316112a94b6f361daea88cd5658d8019668 | 8,567 |
def checkChanList(chanprof, profile, chanList):
""" Return non-zero value if any element of chanlist is not in the channel list of profile
"""
for c in chanList:
if c not in chanprof[profile-1]:
return 1
return 0 | face301b61634bcff8721fcafb1cbc09e2bd0e5f | 8,568 |
import json
def image_get_class_cn_dict(cn_imagenet_class_path):
"""
获得分类的中文对照词典
:param cn_imagenet_class_path:
:return:
"""
fn = open(cn_imagenet_class_path, "r", encoding='UTF-8')
str_json = fn.read()
dic = json.loads(str_json)
fn.close()
return dic | 190cb80d929bdef3fe33b082fa12149c1c290446 | 8,569 |
def jsonp(func):
"""
Decorator for the following JSON API functions for the connection test.
"""
def dec(request, *args, **kw):
resp = func(request, *args, **kw)
cb = request.GET.get('callback')
if not cb:
cb = ''
resp['Content-Type'] = 'application/javascrip... | ccf8bfbffdd1ac865eb2d001f212925c332f1f82 | 8,570 |
def get_base_required_field_types():
""" Get field types for UI asset required fields.
2016-08-24: removed 'coordinates': 'floatlist',
2016-08-26" remove 'augmented': 'bool', 'Ref Des': 'string','hasDeploymentEvent': 'bool','remoteDocuments': 'list',
added 'editPhase' can have values: EDIT, STAGED, OPER... | 0cb8b6041aeaf25efe8ad29e3986237efe5e382f | 8,571 |
import numpy
def encode_data(labeldata,hot_vector = 1):
"""
Takes array of label data, and transforms it into array of one-hot encoded vectors.
Args:
labeldata (iterable): Array or list of data labels
hot_vector: value assingned for hot, default 1
Returns:
... | 92f4bb37428fa2023047abf9d368876bb6d529e5 | 8,573 |
def get_copysetup(copytools, copytool_name):
"""
Return the copysetup for the given copytool.
:param copytools: copytools list from infosys.
:param copytool name: name of copytool (string).
:return: copysetup (string).
"""
copysetup = ""
for ct in copytools.keys():
if copytool_... | 1181352a178f954d17cf7d7b8fc6c798b441d4a6 | 8,574 |
def last_occurence_of_tag_chain(sequence, tag_type):
"""
Takes a sequence of tags. Assuming the first N tags of the sequence are all of the type tag_type, it will return
the index of the last such tag in that chain, i.e. N-1
If the first element of the sequence is not of type tag_type, it will return -... | 0edcf25e18ff4b3701f92c13bab2b634b738c158 | 8,575 |
def supports_parenting():
"""Does this Engine support parenting of objects, aka nesting of
transforms or attaching objects.
This is important when sending transformation values.
"""
return False | 0dd8fc9e5c1917f10cf9d09a1fb75b470abc6eec | 8,576 |
def split_residue_id(atom):
"""Takes an atom and splits its het ID into components.
:param Atom atom: the atom to read.
:rtype: ``tuple``"""
if atom.het:
id = atom.het.id.split(".")[-1]
num = "".join([c for c in id if c.isdigit()])
insert = "".join([c for c in id if c.isalpha()... | 7340c24dc1ef982fd0a3772764a02d7c8fd30126 | 8,577 |
import numpy as np
def pvs(t):
"""
Saturation vapor pressure as a function of tempetature
t [°C]
"""
T = t + 273.15 # [K] Temperature
# pws(T) [Pa] saturation pressure over liquid water
# for temp range [0 200] °C eq. (6)
C8 = -5.800_220_6e3
C9 = 1.391_499_3e0
C10 = -4.864... | 8ba1aced4669753cca0ff2332bc2bd7ad5ad7814 | 8,578 |
def save_output_node(out):
"""
This calcfunction saves the out dict in the db
"""
out_wc = out.clone()
return out_wc | 7f89752332c023558dfb2ea7774231e1c1eeab99 | 8,579 |
def cal_fdp_power(selected, non_zero_index, r_index=False):
""" Calculate power and False Discovery Proportion
Parameters
----------
selected: list index (in R format) of selected non-null variables
non_zero_index: true index of non-null variables
r_index : True if the index is taken from rpy2 ... | 5e14b19c95ec0bc465c6ea6c98606768f00ee49e | 8,580 |
def _create_types_map(sqltypes):
"""Take a types module and utilising the `dir` function create a
mapping from the string value of that attribute to the SQLAlchemy
type instance.
"""
sql_types_map = {
item.lower(): getattr(sqltypes, item)
for item in dir(sqltypes)
if item[0].... | 69a3902663eadc70050acc0c1869fcb86a2a6384 | 8,581 |
def discuss(topic) :
"""Discuss a topic with the user and return their response.
Ask if the user likes the topic and why.
Parameters:
topic (str): The topic under discussion.
Return:
str: Response to the question of why they like the topic.
"""
like = input("Do you like " + to... | 854dcb744440b98fbbeb763e9ae0a866afb5d7d0 | 8,582 |
def numba_update_portability_matrix(
portability_matrix, r_ct_g, c_ct_g, c_f_g, c_cf_g, c_dt_g
):
"""
updating the probability matrix
"""
for a, b, c, d, e in zip(r_ct_g, c_ct_g, c_f_g, c_cf_g, c_dt_g):
portability_matrix[a, b, c, d, e] = 1
return portability_matrix | 138a55af650ab98d1ff4d991b5f81e6f709148c8 | 8,583 |
def find_author(name, authors):
""" Find the author with the provided name, in the list of authors"""
for author in authors:
if author.name == name: return author
raise ValueError('Author', name, 'not found.') | dd47f0ecf8574d68a0ce9b5e94dff19b58f5887a | 8,584 |
def removeblanklines(astr):
"""remove the blank lines in astr"""
lines = astr.splitlines()
lines = [line for line in lines if line.strip() != ""]
return "\n".join(lines) | fa4e04ca1b9cc643782af9363b5e6e6405a2b56d | 8,585 |
def printChapterE(self, section):
"""
"""
output = []
#if self.FAxial == 'COMPRESSION':
#
output.append(" "+"\n")
output.append("_______________________________________________________________________________________"+"\n")
output.append(" "+"\n")
output.append(" F... | 9cd8ab3004864dd571f9853b9dc5554ebbb1b538 | 8,586 |
import re
def CheckEmailFormat(email: str) -> bool:
"""
Emailアドレスのフォーマットをチェックする。
ask him
"""
regex = r'^(\w|\.|\_|\-)+[@](\w|\_|\-|\.)+[.]\w{2,3}$'
if(re.search(regex, email)):
# print("Valid Email")
return True
else:
# print("Invalid Email")
return False | 042afa1e96934e11211bfff2b6e492768c7c5f50 | 8,587 |
def to_type(cls):
"""
Cast the data to a specific type
Parameters
----------
cls : class object
The class to cast the object to
"""
return lambda _, value: cls(value) | 3ae4daac59db30ce988adf55bc4f7f9e15822361 | 8,588 |
import hashlib
def md5_key(chrom, start, end, ref, alt, assembly):
"""Generate a md5 key representing uniquely the variant
Accepts:
chrom(str): chromosome
start(int): variant start
end(int): variant end
ref(str): references bases
alt(str): alternative bases
ass... | 64db55c0075d063aeec500f97700ec769840cc4f | 8,589 |
def _missing_ids(vba, pcode_ids, verbose=False):
"""
See if there are any function names or variables that appear in
the p-code that do not appear in the decompressed VBA source code.
vba - (str) The decompressed VBA source code.
pcode_ids - (set) The IDs defined in the p-code.
return - (floa... | 86dfb5abf8bd9c24078adbed60f6428872ee1ae4 | 8,590 |
def faceBlobSalientBasedOnAverageValue(value, salientLabelValue):
"""Deprecated"""
# the face is considered salient if 50% of pixels or more are marked salient
if value > (0.5 * salientLabelValue):
return True # bright green
# if the face is not salient:
else:
return False | 7a1f7d46e1cd251a80ebf8f7405dde58d108fdd8 | 8,595 |
import base64
def base64_encode_nifti(image):
"""Returns base64 encoded string of the specified image.
Parameters
----------
image : nibabel.Nifti2Image
image to be encoded.
Returns
-------
str
base64 encoded string of the image.
"""
encoded_image = base64.encodeb... | 5e3758089240d8840c1cb1828ab908dead3b4b7c | 8,596 |
import numpy
def calc_array_manifold_f(fbinX, fftlen, samplerate, delays, half_band_shift):
"""
Calculate one (conjugate) array manifold vector for each frequancy bin or subband.
"""
chan_num = len(delays)
Delta_f = samplerate / float(fftlen)
J = (0+1j)
fftlen2 = fftlen / 2
if half_ba... | 26005e6c831e4a04052f6beed86bc861a97eb522 | 8,597 |
import numpy
def rotate(p, angle, center=(0, 0)):
"""
Rotates given point around specified center.
Args:
p: (float, float)
Point to rotate.
angle: float
Angle in radians.
center: (float, float)
Center of rotation.
"""
... | 41b95c1b4162ad9ebacc2250c293e33daaa8a526 | 8,598 |
def pure_water_density_tanaka(t, a5=0.999974950):
"""Equation according Tanaka, M., et. al; Recommended table for the density of water between 0 C and 40 C based on
recent experimental reports, Metrologia, 2001, 38, 301-309
:param t: water temperature (°C)
:param a5: density of SMOW water under one atm... | 27bcc12f8f9089cf8307d72ba784675bbcd5036a | 8,599 |
from pathlib import Path
import pickle
def load_trained_model(fname: str):
"""
Loads a saved ModelData object from file.
Args:
fname (str): Complete path to the file.
Returns: A ModelData object containing the model, list of titles, list of
authors, list of genres, list of summaries,... | 3bdfa3f090fa5efcd54b17bd47a0cd4ea57e1c4a | 8,600 |
def generate_hostfile(map_, file):
"""
generate hostfile base on map_
"""
for node in map_:
print('node-{}.simgrid.org'.format(node), file=file)
file.flush()
return file.name | 76de14bfec5e94ddbce4e29fbcaee844f566b086 | 8,601 |
import typing
import asyncio
def sync(
awaitable: typing.Awaitable,
event_loop: typing.Optional[asyncio.events.AbstractEventLoop] = None,
):
"""
Run an awaitable synchronously. Good for calling asyncio code from sync Python.
The usage is as follows:
.. highlight:: python
.. code-block:: ... | 4fda68c3132564d9c6620fe8e4c1cfac401528a6 | 8,602 |
import math
def check_float(a, b, precision=1e-4):
"""
check float data
Args:
a(list): input_data1
b(list): input_data2
precision(float): precision for checking diff for a and b
Returns:
bool
"""
def __adjust_data(num):
if num == 0.0:
return... | 240c4dac3228669592317e44b69f19d436a1c17d | 8,603 |
def icosahedron_nodes_calculator(order):
"""Calculate the number of nodes
corresponding to the order of an icosahedron graph
Args:
order (int): order of an icosahedron graph
Returns:
int: number of nodes in icosahedron sampling for that order
"""
nodes = 10 * (4 ** order) + 2
... | eccea98ec5da3fae748c3505af4689dfe6f47b73 | 8,604 |
def load_board_state(file_name):
"""
o = food / point thing
X = wall
P = pac man
S = ghost spawn
' ' = empty space
"""
board = []
with open(file_name, 'r') as file:
for line in file:
line = line.strip()
board.append(list(line))
return board | 4d3a1822649724407f62abfa7909014562fd6978 | 8,606 |
import click
def validate_profile(context, param, value):
"""
Validates existance of profile.
Returns the profile name if it exists; otherwise throws BadParameter
"""
if value in context.obj.configuration.profiles():
return value
else:
raise click.BadParameter("\"%s\" was not f... | ac1fd3caa99a510173aa96f4c781abfacb6eed97 | 8,607 |
def formatPath(a):
"""Format SVG path data from an array"""
return "".join([cmd + " ".join([str(p) for p in params]) for cmd, params in a]) | f56f62b001bf37696fa3636310fda1c8e26e8ae9 | 8,609 |
def merge_configs(*configs):
"""
Merges dictionaries of dictionaries, by combining top-level dictionaries with last value taking
precedence.
For example:
>>> merge_configs({'a': {'b': 1, 'c': 2}}, {'a': {'b': 2, 'd': 3}})
{'a': {'b': 2, 'c': 2, 'd': 3}}
"""
merged_config = {}
for co... | dbbdff74695233b522cd4381a78ca82e6f8057fd | 8,611 |
import torch
def expected_unique(probabilities, sample_size):
"""Get expected number of unique samples.
This computes the expected number of unique samples for a multinomial
distribution from which we sample a fixed number of times.
"""
vals = 1 - (1 - probabilities) ** sample_size
expectati... | fd9b7ebd35db0d29c32495f50cd7f220e76267ba | 8,612 |
def label_tsne(tsne_results, sample_names, tool_label):
"""
Label tSNE results.
Parameters
----------
tsne_results : np.array
Output from run_tsne.
sample_names : list
List of sample names.
tool_label : str
The tool name to use for adding labels.
Returns
---... | 50422e192e57fb6a019618d46e9a95b9b3c3c768 | 8,613 |
def diff_list(l1, l2):
"""Returns side by side equality test"""
return [False if i1==i2 else True for (i1, i2) in zip(l1, l2)] | 50a81f3c517168d6b369e11ac874520cf5110656 | 8,615 |
from typing import List
def get_routes(vehicles: List[int], stops: List[int]):
"""
Create dict of vehicles (key) and their routes (value).
:vehicles: list of vehicle identities (same order as demand)
:stops: list of stop numbers (same order as vehicles)
return dict
"""
counts... | 966baf998c0ec22ad381175a5680b4cefd045a6f | 8,616 |
def progress_bar(progress, size = 20):
"""
Returns an ASCII progress bar.
:param progress: A floating point number between 0 and 1 representing the
progress that has been completed already.
:param size: The width of the bar.
.. code-block:: python
>>> ui.progress_bar(0.5, 10)
... | ab3bffd9e2c9c0060001a3058217690e8d30a67d | 8,618 |
def hasblocks(hashlist):
"""Determines which blocks are on this server"""
print("HasBlocks()")
return hashlist | 9bcd481b6c6ec1ecbbcb1978edae0bff86fd5cb7 | 8,619 |
def instantiate_domains(domains, encoding_cnt):
"""create domain for fields we want to encode. """
instantiated = {}
for d in domains:
if "/encoding/*" in d:
for i in range(encoding_cnt):
instantiated[d.replace("/encoding/*", "/encoding/{}".format(i))] = domains[d]
else:
instantiated[d] = domains[d]
r... | 69857f67070eeabeaf9b1b4b8eb4d62f48563528 | 8,623 |
def density(temp):
"""
Calculating density of water due to given temperature (Eq. 3.11)
:param temp: temperature prediction Y[d, t] at depth d and time t
:return: corresponding density prediction
"""
return 1000 * (1 - ((temp + 288.9414) * (temp - 3.9863) ** 2) / (508929.2 * (temp + 68.12963))) | 92d6d7c5639e03790715f62a1027a15357cdf1cf | 8,624 |
import torch
def distance2bbox(points, distance, max_shape=None):
"""Decode distance prediction to bounding box.
Args:
points (Tensor): Shape (n, 3), [t, x, y].
distance (Tensor): Distance from the given point to 4
boundaries (left, top, right, bottom, frDis, 4point, bkDis, 4point... | ea773f3bd0d53a2aaccb85c7b7042c51c3dd0653 | 8,625 |
from typing import Tuple
def _partition(lst: list, pivot: object) -> Tuple[list, list]:
"""Return a partition of <lst> with the chosen pivot.
Return two lists, where the first contains the items in <lst>
that are <= pivot, and the second is the items in <lst> that are > pivot.
"""
smaller = []
... | 07950d665eca6b5591d3c8b65a980c2597b9e45a | 8,627 |
def split_arguments(args, splitter_name=None, splitter_index=None):
"""Split list of args into (other, split_args, other) between splitter_name/index and `--`
:param args: list of all arguments
:type args: list of str
:param splitter_name: optional argument used to split out specific args
:type spl... | c6e800ff6d109699d346c76052a70e4e5ab670d8 | 8,628 |
import torch
def cumulative_laplace_norm(input):
"""
Args:
input: [B, C, F, T]
Returns:
"""
batch_size, num_channels, num_freqs, num_frames = input.size()
input = input.reshape(batch_size * num_channels, num_freqs, num_frames)
step_sum = torch.sum(input, dim=1) # [B * C, F, T] =>... | 1c61399c3b36a6552e59f3ed62da651207370670 | 8,629 |
import re
def is_valid_record2(parsed_record):
"""Check if parsed_record is properly formatted"""
if not (
"byr" in parsed_record
and parsed_record["byr"].isdigit()
and len(parsed_record["byr"]) == 4
and (1920 <= int(parsed_record["byr"]) <= 2002)
):
return False
... | d3fdb17f6c6726e74e02f41813c665e8be223406 | 8,630 |
def LargestPrimeFactor(num):
"""Calculate greatest prime factor using length of list
It is best practice to use greatest prime factor for hash table's
capacity. This method calculates the greatest prime factor using the
int passed in and returns the prime integer.
Time complexity of O(logn)
:p... | ccb09b7bd385a8b4795dbdeb3a4e886cd0922f20 | 8,631 |
def lua_property(name):
""" Decorator for marking methods that make attributes available to Lua """
def decorator(meth):
def setter(method):
meth._setter_method = method.__name__
return method
meth._is_lua_property = True
meth._name = name
meth.lua_setter... | 97cd57cf21c4afdb43b6504af56139228df751cd | 8,632 |
def toalphanum(s):
"""
gets rid of the unwanted characters
"""
_s = ''
for c in s:
if c in '\\ /(.)-':
_s += '_'
else:
_s += c
return _s | 14ce33504a467406f42c095526cc232364ac6d1a | 8,633 |
def ip2int(ip_str):
"""
Convert XXX.XXX.XXX.XXX to integer representation
Args:
ip_str (str): IP in a XXX.XXX.XXX.XXX string format
Returns:
ip_int (int): Integer IP representation
"""
ip_int = None
if isinstance(ip_str,str):
# clean IP
if ip_str.find(':') >... | bb48f28519593222c005df1b009d7e669dde7669 | 8,634 |
import itertools
def _find_chordless_cycles(bond_graph, max_cycle_size):
"""Find all chordless cycles (i.e. rings) in the bond graph
Traverses the bond graph to determine all cycles (i.e. rings) each
atom is contained within. Algorithm has been adapted from:
https://stackoverflow.com/questions/402266... | ad7228c31477f457e13e45c789022aca35f00183 | 8,635 |
def access_token_generator(token_generator, access_token_template):
"""A function that generates a signed access token"""
def func(**extra_claims):
claims = {**access_token_template, **extra_claims}
return token_generator(**claims)
return func | 4a1052b46dc85e3f15375fbbc5062a950fe40874 | 8,637 |
import os
def create_ABC_estimate_config(path_run_ABC, param_num):
"""
Create ABCtoolbox config file for estimation.
:param path_run_ABC: full or relative path to directory to run ABC in.
:param param_num: number of parameters
:return:
"""
file_name = '{}/test_ABC_estimate.txt'.format(pa... | 31287b0e03d0ae730a503370ebd05447190aa2b2 | 8,638 |
def calculate_mixing_param_constants(asm_obj):
"""Calculate the constants Cs and Cm required for the
determination of the Cheng-Todreas mixing parameters
Parameters
----------
asm_obj : DASSH Assembly object
Contains the geometry and flow parameters
Returns
-------
tuple
... | 336aa6de073fa9eece218deef0d236f47c7fea79 | 8,639 |
def cast_str_to_bool(input_string: str) -> bool:
"""Convert string to boolean with special handling for case, "True", 1.
Special string parsing for booleans.
Args:
input_string (str): Evaluate this string as bool.
Returns:
case-insensitive 'True', '1' or '1.0' is True.
It will... | 38898f9aaa14ce9d6872941252213431c07878d1 | 8,640 |
def phi31_v_from_i_skow(phi31_i):
"""
Calculates the V band phi31 for the given I band phi3 using the
relationship found in Skowron et al. (2016).
(Skowron et al., 2016) (6)
Parameters
----------
phi31_i : float64
The I band phi31 of the star.
Returns
-------
phi31_v :... | 9594e7676bf844908e6555c4064aa795272e529d | 8,641 |
def get_object_type(objects: list, types: list) -> list:
"""Get the object specified.
Args:
objects: a list of objects.
types: a list of the types.
Returns:
A list of a certain type.
"""
return [item for item in objects if item.get('type') in types] | bfccc9c838f0a2d3294068acc0d2091c44de4798 | 8,642 |
import time
def unix() -> int:
"""
Return the current time in seconds since the Epoch.
Fractions of a second may be present if the system clock provides them.
Returns:
int
"""
return int(time.time()) | 3e5a0933d9a9eaee7c9f4136f651af6f2982dacc | 8,643 |
def _get_relative_anchors(cluster_medoids, bounds):
"""Get medoid coords relative to fetched RGB."""
relative_medoids = cluster_medoids.copy()
relative_medoids.loc[:, "xmin"] -= bounds["XMIN"]
relative_medoids.loc[:, "ymin"] -= bounds["YMIN"]
relative_medoids.loc[:, "xmax"] -= bounds["XMIN"]
rel... | 5b1bf76aa2e5bf21831df573dd85941dc738a5cc | 8,645 |
def capacity_cost_rule(mod, g, p):
"""
"""
return mod.DRNew_Cost[g, p] | cb6c7160cbdafa4b884f38083a20f59c155a63dc | 8,646 |
import csv
def create_fann_train_from_csv(csv_fname, train_fname, sections, all_species):
"""
takes the csv file saved by the leaf collection and creates FANN training
data from it.
"""
# format 'binomial nomenclature: [leaf measurements]
imported_data = {}
total_leaves = 0
# read and ... | d0783c6a78c125250d47bffac753cda1c9df6f2e | 8,647 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.