content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def filter_probes_by_nan_and_sd(data_df, probe_frac_cutoff, probe_sd_cutoff):
""" Filter out probes whose fraction of samples measured is less than probe_frac_cutoff.
Also remove probes with standard deviation higher than probe_sd_cutoff.
Args:
data_df (pandas df)
probe_frac_cutoff (float b... | 1268244d4975be7bcf114b94d33e567fb7cff1b5 | 32,741 |
import random
def get_mac():
"""
Gets a random mac address.
"""
mac = ("%02x:%02x:%02x:%02x:%02x:%02x" %
(random.randint(0x00, 0xff),
random.randint(0x00, 0xff),
random.randint(0x00, 0xff),
random.randint(0x00, 0xff),
... | 33287d8dbe5815997b6ae1bcd9ec207ad3cf8e4f | 32,742 |
import sys
def BasisForm(function_space):
"""Wrapper around the elements."""
elem_type = function_space.str_to_elem[function_space.form_type]
return getattr(sys.modules[__name__], elem_type)(function_space) | 9304f53b59b6b1e79dc227766ebc80f446231b40 | 32,743 |
def forward_pass(tproblem, add_regularization_if_available=False):
"""Forward pass in DeepOBS."""
loss, _ = tproblem.get_batch_loss_and_accuracy(
add_regularization_if_available=add_regularization_if_available
)
return loss | 8596de44f4e3a71d978e33d202e30f36a4c3e15a | 32,748 |
import difflib
def textPreservedRatio(o_text, d_text):
"""
Compute the ratio of preserved text between two revisions
Args:
o_text (list): a list of elements of the form [index of insertion position, text to be inserted]
d_text (str): text content of the destination revision.
Result:
... | 68a86c8785eeaebd17eb215e3c77846948e4925b | 32,749 |
import importlib
def get_model(params):
"""Return the model class by its name."""
module_name, class_name = params.model.name.rsplit('.', 1)
i = importlib.import_module(module_name)
return getattr(i, class_name) | 55e360f57488eeeb35d8c1479293d10ffa1fac78 | 32,750 |
def create_model_identifier(name, version):
"""Get a compatible string as a combination of name and version"""
new_name = "%s-%s" % (name, str(version).replace('.', '-'))
return new_name | 3aec457ff6836b93293b1adcb9e26a5429cfff09 | 32,751 |
def emoji_boolean(condition: bool) -> str:
"""Returns emoji depending on `condition`
Args:
condition (bool): subject condition
Returns:
str: emoji
"""
return "🟢" if condition else "🔴" | c2ca508ded5919da4811267893afd32b142cced3 | 32,752 |
def v1_protected(protected: bool | str) -> bool:
"""Cleanup old protected handling."""
if isinstance(protected, bool):
return protected
return True | ceb68509854be943ccf2846c5bd77e882373024d | 32,753 |
def _quantile(sorted_values, q):
"""
For a sorted (in increasing order) 1-d array, return the
value corresponding to the quantile ``q``.
"""
assert ((q >= 0) & (q <= 1))
if q == 1:
return sorted_values[-1]
else:
return sorted_values[int(q*len(sorted_values))] | e3356c5911b031c153a4914dcd81052743005eae | 32,754 |
import random
import math
def rGeom(p):
"""Generate a geometrically distributed random number. p is the success
probability. The numbers are in the range {0, 1, 2,...}"""
# CDF = 1-(1-p)^(k+1) (CDF of geometric distribution)
# (1-p)^(k+1) = 1-CDF (... solve for k ...)
# k+1 = log(1-CDF)/log(1-p)
... | 7eb1d3bbac0c79e1341abb2fa9528ea8c6c88e84 | 32,755 |
import re
def allXinY(word1, word2):
"""
Check if word1 properly belongs in word2
:param word1: the word to be queried
:param word2: the sentence / longer word
:return: whether word1 as a sequence of words belong in word2
"""
if word1 not in word2:
return False
# word2 = word2... | 86d999ca226e9c575a9dfe40d7a7b2b08ae5a927 | 32,757 |
import torch
from typing import Tuple
def svd_flip(u: torch.Tensor, v: torch.Tensor, u_based_decision: bool = True) -> Tuple[torch.Tensor, torch.Tensor]:
"""Sign correction to ensure deterministic output from SVD."""
if u_based_decision:
max_abs_cols = torch.argmax(torch.abs(u), dim=0)
signs =... | 2c32a016db5b6442d80dc2aba1ddeb0aaec2ca7c | 32,758 |
def process_all_children(post):
"""
Flattens comments in a Piazza thread
"""
return post['children'] + sum([process_all_children(child)
for child in post['children']], []) | a23b69cc6dcc31938240e8783b40da02c1f745b7 | 32,759 |
def recursive_dict_to_list(dict_data):
""" Returns a list containing all values from
a dictionary and any child contained dictionary.
"""
list_data = []
for v in dict_data.values():
if type(v) == dict:
for v1 in recursive_dict_to_list(v):
list_data.append(v1)
... | 40f1bd7649d0462ff12a51958f028f098aeead56 | 32,760 |
import numbers
def _operator_fallbacks(fallback_operator, doc=""):
"""Returns tuple of polymorphic binary operators.
Based on the pattern shown in Python Standard Library numbers module.
"""
if fallback_operator is None:
return (None, None)
def forward(a, b):
if type(a) == type(b... | 8c35f6a8c42633fea5785e1547575812e31df63b | 32,761 |
def format_float_dot_delimiter(value):
"""Ensure that the float value has '.' as the decimal delimiter.
This prevents errors caused by internationalisation where it is not wanted,
i.e. 'de' where the decimal delimiter is ',' and not '.' .
Parameters
----------
value : float
Arbitrary ... | 6e6873c7ee7e1fc789f41eab2d4e292cdf90d125 | 32,763 |
def cal_avg_distance(points, a, b, d, threshold_inlier):
"""
return average distance of points to the line model.
Parameter
---------
points : array like
[[x1,y1],[x2,y2],...]
a : float
b : float
d : float
thereshold_inlier : float
the threshold of discrimin... | 172d5e266d28810e002af35e868262f5213141a9 | 32,764 |
from typing import Union
from typing import Dict
from typing import Optional
from typing import Any
import json
def format_default(
message: Union[str, Dict], subject: Optional[str] = None
) -> Dict[str, Any]:
"""
Default formatter, converting event into Slack message format
:params message: SNS mess... | 9f2cef323c8a8793c072a8cf3541d96052b66fd9 | 32,765 |
def version_as_int(semver):
""""."""
v = semver.split('-')[0].replace('v', '').replace('V', '').replace('.', '')
return v | b7ef6cad69cb049f4adb25b5fb9fd97459db6d97 | 32,766 |
import csv
def sma_passenger():
"""Return SMA of international passenger of thailand air transporation"""
main_data = csv.reader(open('airtraffict.csv', newline=''))
main_data = [row for row in main_data]
arr_psng = 0
dep_psng = 0
tst_psng = 0
for i in main_data:
if i[0] == 'BKK' a... | b816a66334aef35ef7aaf542e93411cbf32938fd | 32,768 |
def full_name(app):
"""Builds App full_name, prepending the App with the name
of the parent App.
:param app: App as returned by queries.get_apps()
:type app: dict
:return: full name of the app
:rtype: string
"""
name = app['name']
if app.get('parentApp'):
parent_app = app['p... | c0b46e63ab662f9c3e33050e9a5f034400a45c58 | 32,771 |
def default_introspection_processing_hook(introspection_response, client, id_token):
"""
Hook to customise the returned data from the token introspection endpoint
:param introspection_response:
:param client:
:param id_token:
:return:
"""
return introspection_response | a3c051dd8ec1c11075d169365be6839806b9a9da | 32,772 |
import random
def get_random_crop_coords(height, width, crop_height, crop_width):
"""
get coordinates for cropping
:param height: image height, int
:param width: image width, int
:param crop_height: crop height, int
:param crop_width: crop width, int
:return: xy coordinates
"""
y1... | 3da397b33bba76df2312611731536d4b5ce5e674 | 32,774 |
import numpy
def default_sample_grid(vrange, res=8):
"""Calculate sample grid fine enough to capture point details
resolution of smallest dimension will be minres elements
"""
#If provided a full resolution, use that, otherwise will be interpreted as min res
if isinstance(res, (list,tuple)):
... | 67898ad7618a3e65bbc9f02c1d92f73fc4c00485 | 32,775 |
def _gbd(n):
"""Compute second greatest base-2 divisor"""
i = 1
if n <= 0: return 0
while not n % i:
i <<= 1
return i >> 2 | 48e86f46306149d6785a1c232138ae8effea9143 | 32,776 |
from typing import List
def remove_multiples_from_list(arr: List[int]) -> List[int]:
"""
Removes lesser multiples of an sequential ascending array
:param arr: Sequentially ascending list of integers
:return: List of numbers who have no common multiples within the array
"""
for i in reversed(a... | b1ede0d19c247df9db348e34b11a1905d77fce84 | 32,777 |
import re
def collapse(string, character=" "):
"""Removes specified character from the beginning and/or end of the
string and then condenses runs of the character within the string.
Based on Ruby's stringex package
(http://github.com/rsl/stringex/tree/master)
"""
reg = re.compile('(%s){2,... | eccff644aea51af813396b6bf764f91cd4b9d36b | 32,779 |
import requests
def isup(bot, trigger):
"""isup.me website status checker"""
site = trigger.group(2)
if not site:
return bot.reply("What site do you want to check?")
if not site.startswith('http://') and \
not site.startswith('https://'):
if '://' in site:
protocol = s... | 8981ba145178ba6a214bcefd9c1750ebd2338d98 | 32,780 |
def get_src(node):
"""
Returns src module of node, None if attr not defined
"""
return hasattr(node, "srcmodule") and getattr(node, "srcmodule") or None | 28d37a39df61353eec31248da47572df5a5f2c75 | 32,781 |
def min_med_max(x):
"""Compute min, median, max of tensor x."""
return [x.min().item(), x.median().item(), x.max().item()] | b894c11e4bf6828d3627a6d79beec8c070c6657f | 32,783 |
def Fraction2Decimal(numerator, denominator, span):
"""(n)umerator/(d)enominator를 계산하여 소수점 이하 span 자리까지 문자열 반환"""
n = numerator
d = denominator
string = str(n // d) + "."
remainer = n % d
for i in range(span):
if remainer == 0:
break
remainer = remainer * 10
s... | 17b6ba4471740e245c55cf6b77ffafca5abb0e4a | 32,784 |
def get_matching_firstlevel_children_from_node(node, child_tag):
"""Takes a xml file as input and returns a list of first
child elements to the root that matches the provided tag """
child_list = node.findall(child_tag)
return child_list | 7793a27a954c5159f037efbc5ae6902062750ff5 | 32,785 |
from typing import Dict
def finds_node_type(edge_info: Dict) -> Dict:
"""Takes a dictionary of edge information and parses the data type for each node in the edge. Returns either None or
a string containing a particular node from the edge.
Args:
edge_info: A dict of information needed to add edge... | a799aba56310a33a18d2cc6d0d978515eedebc97 | 32,787 |
import re
def extract_re_group(pattern):
"""
Extract the first captured group using the given pattern.
"""
def callable_(key, data, errors, context):
value = data.get(key) or ''
match = re.match(pattern, value)
if not match:
return
try:
data[key]... | 832c2ce3eb6e182bd22c8ee28e287dd1c207162f | 32,789 |
def get_object_api_names(api_name, list_objs):
"""
Return a list of object api_names from list_objs
"""
return [o.get(api_name) for o in list_objs] | 4ab4a1c5375e052f42511c2dbc438e1f157e5073 | 32,791 |
def fahrenheit_to_kelvin(a):
"""
Function to compute Fahrenheit from Kelvin
"""
kelvin = (a-32.0)*5/9 + 273.15
return kelvin | b24ec8c7bb2620158a93ed34a272cdf76fddb927 | 32,792 |
def get_missed_cleavages(sequences:list, n_missed_cleavages:int) -> list:
"""
Combine cleaved sequences to get sequences with missed cleavages
Args:
seqeuences (list of str): the list of cleaved sequences, no missed cleavages are there.
n_missed_cleavages (int): the number of miss cleavage s... | 7b8f3f2c11eb22d0311cefcfd59b9b5d5f1a4c78 | 32,793 |
def mkvec(ftr,seq,window,pos):
"""
>>> import feature
>>> mkvec(lambda seq:feature.seq2frq(seq),"AAKDDECCSG",window=10,pos = 4) == {706: 1, 163: 1, 1222: 1, 9: 1, 3243: 1, 844: 1, 436: 1, 862: 1}
True
"""
# ftr is the function make dict like "{pos:value for i in dimension}"
n = seq[max(0,int(pos - window/2.0)):p... | 4f3f9d2a717b4905a42a15ad21432f4b87e83240 | 32,794 |
def _set_square(mul, square):
"""
Set square if square is None
(for the initialization of methods for powering)
"""
if square == None:
return lambda x : mul(x, x)
else:
return square | 67689dc3fd5c282fd63e6cda9eb6b97f7d6b92ce | 32,795 |
def urljoin(*pieces):
"""Join componenet of url into a relative url
Use to prevent double slash when joining subpath
"""
striped = [s.strip('/') for s in pieces]
return '/'.join(s for s in striped if s) | 6f41e5ae515ae6cee3e19e36a94f45444c71b0ba | 32,796 |
def _hop(a): # NB: redefined in MPyC setup if mix of 32-bit/64-bit platforms enabled
"""Simple and efficient pseudorandom program counter hop for Python 3.6+.
Compatible between all 64-bit platforms.
Compatible between all 32-bit platforms.
Not compatible between mix of 32-bit and 64-bit platforms.
... | c28db047fe5bd0b7c2770847222c4dcb8a1178a7 | 32,797 |
def get_objects_name(objects):
""" Retrieves the names of objects.
Parameters:
objects (list): Objects to get names.
Returns:
list: Object names.
"""
names = []
for object in objects:
if object.name[-5:-3] == '}.':
names.append(object.name[:-4])
else... | f0ff4abb68c54c536338aa48eca0a3f6d57c0ae5 | 32,798 |
import math
def degrees(angle):
"""Convert angle from radians to degrees."""
return 180 * angle / math.pi | 3cdf03bb5fd34cce80a53f90ed39a2aacb2b6bda | 32,801 |
def savedata(fullpathfilename, data):
"""
Save data to a file: csv from a pandas dataframe
:param fullpathfilename: Full path to the file
:param data: pandas dataframe to save
:return: True if successful, False if not
"""
try:
data.to_csv(fullpathfilename,
header=... | 1a2ab34c04144c95764cebed7c25e54b1f326ec9 | 32,803 |
def translate_keypoints(keypoints, translation):
"""Translate keypoints.
# Arguments
kepoints: Numpy array of shape ``(num_keypoints, 2)``.
translation: A list of length two indicating the x,y translation values
# Returns
Numpy array
"""
return keypoints + translation | 02acd5ca99e86712e103be81f3b7c2362996446b | 32,804 |
def conv2d_size_out(size, kernel_size, stride):
"""
Helper function for adjusting the size correctly in CNNs.
:param size:
:param kernel_size:
:param stride:
:return:
"""
return (size - kernel_size) // stride + 1 | bf91de32122a32520f15cf4bd87079ad0cb98a26 | 32,806 |
def relu(x):
"""
ReLU element-wise activation.
Args:
x: array-like, any shape,
array to compute activations for.
Returns:
x_relu: same type and shape as x,
element wise application of ReLU to x.
"""
return x * (x > 0) | dd01c5cea3e2c77bd41c9f92dab37f5cf7890b10 | 32,807 |
def can_open_file(gcode_filepath):
"""
check whether a given filepath can be opened. If the filepath throws an error, False is returned. If the file can
be opened, True is returned.
"""
if isinstance(gcode_filepath, str): # if gcode_filepath is a string
try: # try opening file
... | 6ad51e2d67b89886edb7ca65fa25ca1f7bdfe536 | 32,808 |
def cl_arguments_classificiation(parser):
"""This is a helper method of the method parse_cmd_arguments to add
arguments to the parser that are specific to the cl setup for classifiers.
Args:
parser: Object of class :class:`argparse.ArgumentParser`.
Returns:
The Namespace object contai... | ff2a9c6ae3494c3550eba3bcbd5dd77982ba3e09 | 32,809 |
def format_box_wider2tfrecord(x, y, w, h, real_h, real_w):
"""
wider to tf_record record the rate of min point and width/height
:param x:
:param y:
:param w:
:param h:
:param real_h:
:param real_w:
:return:
"""
print('orig: ', x, y, w, h, real_h, real_w)
x_ = x / real_w
... | d6613576fa3b35df01ec9111f4c3730eb93f9fee | 32,810 |
def _filter_attributes(attr_names, attr_values, sel):
"""Returns the filenames that match the attributes given by 'dic'"""
# Then select those files whose attributes all match the selection
filenames = []
for filename, attrs in attr_values:
all_match = True
for name, value in sel.items(... | 11e29b4727c0d403bc1a01379046f824355869d9 | 32,812 |
import torch
def calculate_moment_list(moment_num, en_list, normalize=True):
"""Calculate the n'th moment (up to moment_num) of a given energies list. Same function as in the dataset."""
res = []
if not torch.is_tensor(en_list):
en_list = torch.Tensor(en_list)
first = torch.mean(en_list)
... | fb6a0c12258e4f835e4ac11d5518e3f55d28f586 | 32,813 |
import os
def get_last_modified(abs_file_path):
"""
get last modified timestamp of file
"""
return os.path.getmtime(abs_file_path) | e91a797030a93b2ccb7949fd439e9d93685a80e4 | 32,815 |
import os
import configparser
def configGlobal(*args):
"""
Read a INI file to load the configuration into the program
Returns:
cfgData (configparser): loaded configuration to execute the app
"""
cfgfp = os.path.join(*args)
cfgData = configparser.ConfigParser()
cfgData.read(cfgfp,... | 97a342cbe1fc1d5cc437771bd458f403d121f8aa | 32,817 |
def net_to_linkdict(net):
"""
Convert Net object from parse_net_file to dict { (from,to) : Link }
mapping a link indexed by (from,to) tuple to Link data
Parameters:
net - Net object as returned by parse_net_file()
Return value:
dict {(from,to):Link} as described above
"""
... | 96f8ad92486078e48ed6d914b9d21cc3ebb96141 | 32,818 |
def find_unique(arr):
"""."""
in_order = sorted(arr)
if (in_order[0] < in_order[len(in_order) - 1] and in_order[0] < in_order[len(in_order) - 2]):
num = in_order[0]
else:
num = in_order[len(in_order) - 1]
return num | 6aabd875e0a9969e4db4d20b004cb3f161eee969 | 32,826 |
def check_transaction_exceptions(trade_data: dict) -> list:
"""
Check trade data for Binance decentralized exchanges
"""
exception_list = []
gas_limit = trade_data["gas_limit"]
gas_cost = trade_data["gas_cost"]
amount = trade_data["amount"]
side = trade_data["side"]
base = trade_dat... | c52e4e9ed5c9928b7d967b9e0548990769238f46 | 32,827 |
def get_all_descendants(db, parent):
"""Return all (non-retired) descendants of the parent.
Parameters
----------
db : MongoDatabase
The Mongo database from which request document data can be
retrieved.
parent : str
The parent for which all descendants are desired.
Ret... | a94f6eed1f316cc5aa25ef8e7b1db148aaee05d3 | 32,830 |
def parseWR(str):
"""
Parses the wavelength range.
"""
wr = str.strip('wr=[ ]"')
return [float(i.strip(' ')) for i in wr.split(',')] | 72ce70fb8a1f012b440e93fbaba7a30088b1b306 | 32,832 |
def choose_one(foo):
"""
input :[[3, 4], 7, 9, [11, 12, 13, 14], [16, 17, 18], [20, 21]]
output: [0, 4, 7, 9, 13, 17, 21]
"""
loo = foo[:]
for i in range(len(foo)):
try:
if len(foo[i]):
if foo[i][0]==0:
loo[i]==0
... | 089ceaf80fea8c349ec828e24f575acee1153a6a | 32,833 |
def three_one(three):
"""
Converts three-letter amino acid codes to one-letter.
Arguments:
three (str): Three letter amino acid code; AMBER and CHARMM
nomenclature for alternative protonation states is supported,
but lost by conversion.
Returns:
str: Corresponding one-lette... | 9de2a582fa57ce1f3dd2e26b91f1a86a2c1f11cb | 32,834 |
import re
def _extract_readnum(read_dict):
"""Extract read numbers from old-style fastqs.
Handles read 1 and 2 specifications where naming is
readname/1 readname/2
"""
pat = re.compile(r"(?P<readnum>/\d+)$")
parts = pat.split(read_dict["name"])
if len(parts) == 3:
name, readnum, e... | f20c69df01b15a8411a81476f2df99f9f6358436 | 32,835 |
def warmup():
"""Handles AppEngine warmup requests."""
return "" | 47746597912ede5f1a2c8234aef690056529477a | 32,836 |
def x_ian(x, word):
"""
Given a string x, returns True if all the letters in x are
contained in word in the same order as they appear in x.
>>> x_ian('srini', 'histrionic')
True
>>> x_ian('john', 'mahjong')
False
>>> x_ian('dina', 'dinosaur')
True
>>> x_ian('pangus', 'angus')
... | def96c5dc36df5ae8a17bde26878eefcc0874f74 | 32,838 |
def unquote(s):
"""Adds quotes to a string."""
return '"' + s + '"' | be5e94d16c96da61f7302f52bfdee2dc5376102e | 32,839 |
def next_RK2(h, b, func, vars, i):
"""
Gets the 'next rk2' value as part of the main rk2 function
"""
# Define key parameters
a = 1 - b
if b != 0:
alpha = 1/(2*b)
beta = 1/(2*b)
else:
alpha = 1
beta = 1
vi_euler = vars[i] + beta * h * func(vars[0], vars[1... | 05ae16f1cdb4dc67c665b23e7b4e3aa8f6c9350a | 32,840 |
import time
import hashlib
import json
def get_location_request(lon, lat, taxi_id, operator, apikey):
"""Payload to send to geotaxi to update taxi location."""
payload = {
'timestamp': int(time.time()),
'operator': operator,
'taxi': taxi_id,
'lat': lat,
'lon': lon,
... | 5e77d892606e4fdbe2db692006876788f0575c3e | 32,841 |
def Thompson(model, _, __, n=100, rng=None):
"""
Thompson sampling policy.
"""
return model.sample_f(n, rng).get | 2c98af5f8c415a24172ca0e1ad08e8c6889d15a1 | 32,842 |
import struct
def hexptr2bin(hexptr):
"""
Input must be a int
output : bytes in little endian
"""
return struct.pack('<L',hexptr) | c9907c1249b196537f6b242c79c58c6fc69c8940 | 32,843 |
def projects_get():
"""
List all projects
:rtype: List[Project]
"""
return 'do some magic!' | 24089b1b9cb56900f4a76cfce96d50de76cbeff7 | 32,844 |
import argparse
def _get_parser():
"""
Builds an ``argparse`` parser for the ``msdss-dotenv`` command line tool.
Returns
-------
:class:`argparse.ArgumentParser`
An ``argparse`` parser for ``msdss-dotenv``.
Author
------
Richard Wen <rrwen.dev@gmail.com>
Example
----... | 2dfffb8175c2c47ac81457d18f394da3a7af4c50 | 32,845 |
import torch
def ClassificationAccuracy(output, target):
"""
ClassificationAccuracy on a given batch
Args:
output(:obj:`torch.Tensor`) - predicted segmentation mask
of shape BATCHES x SCORES FOR DIFFERENT CLASSES
target(:obj:`torch.Tensor`) - expected segmentation mask
... | 024efd8715492e7c5a2984b1846840c297edfe27 | 32,848 |
def transition_model(corpus, page, damping_factor):
"""
Return a probability distribution over which page to visit next,
given a current page.
With probability `damping_factor`, choose a link at random
linked to by `page`. With probability `1 - damping_factor`, choose
a link at random chosen fr... | 7b7c92bf2738b5ad1ad9ab78466ab7051470f1cc | 32,849 |
def be(entry: object) -> str:
""" Return a stringified version of object replacing Nones with empty strings """
return str(entry).strip() if entry else '' | 1c54dff6c3137bdeb511e149f177fe189234a70c | 32,850 |
import requests
def _get_url(url, type_=None, cookies=None):
"""Get content on given HTTP(S) url using Wget user agent.
This method uses :mod:`requests` to make the request. The
`type_` that is passed determines some behavior. Passing
`rss` will set the `Accept` header to request
`'application/rs... | 8eccfdb20bd8783091d8f79cbb200e0f579fa348 | 32,851 |
import os
def ishdf5(path):
"""Is the file an HDF5 file?"""
# tables.is_hdf5_file(path)
# tables.is_pytables_file(path)
(filename, ext) = os.path.splitext(path)
if (ext is not None) and (len(ext) > 0) and (ext.lower() in ['.h5']):
return True
else:
return False | 6c818b35c14811df75abbfb14da4a07ee1b0d4ba | 32,854 |
def _check_lfp_analysis(d):
"""if key LFP analysis is in the dict, return true"""
if "_lfp_analysis" in d.keys():
return True
else:
return False | e3a1d830ad1018b3ee3eee2b0d714432538214c9 | 32,855 |
import os
def get_sdf_files_not_in_db(db_connection, sdf_fn_in_folder):
"""
Returns the sdf_file names (full path) which are not already in the DB.
:param db_connection: sqlite3.Connection, database connection
:param sdf_fn_in_folder: list of string, filenames of the sdf-files.
"""
sdf_files_... | 463ba1f1599ef8f5306572a50dabdf942f32640c | 32,856 |
def fixture_perform_upgrades_at_unlock():
"""Perform user DB upgrades as normal during user unlock"""
return True | acb1de4738d86ccbdbfcd6d9bea35caf50aed95d | 32,857 |
def get_username_random(self):
""" Gets random username """
username = self.follows_db_c.execute(
"SELECT * FROM usernames WHERE unfollow_count=0 ORDER BY RANDOM() LIMIT 1"
).fetchone()
if username:
return username
else:
return False | 30d2c0b030b959b61880fd89a2d715a5c67edbec | 32,858 |
import os
def render_audio(midi_file_path, sound_font):
"""
Render midi to audio
"""
# split file name and extention
name, extention = midi_file_path.rsplit(".", 1)
# set file names
audio_file = name + ".wav"
# synthesize midi file to audio
cmd = "fluidsynth -F %s -O s16 -T wav ... | 72364588ff4da47a7474bdd76fc04ad5b12fa6e6 | 32,860 |
def count_args(x):
"""Counts number of unique arguments (org and response combined)."""
return x[['org', 'response']].stack().nunique() | 756db73b2065681ae5f53dfb1e9f6eedf7b8bdeb | 32,861 |
def bitLeftShift(binIn, n):
"""
Input:
- binIn: a binary number stored as a string. The most significant bit is stored as the first character in the string and so forth.
- n: the number of bits to be shifted and n >= 0.
Output: bin(binIn << n)
"""
pos = 0
allZero = True
for digit in... | 3d21e667d9e983c479c2ad1c0c7937978a9396c8 | 32,863 |
def compare_ltiv_data(expected, actual):
"""
Helper to test the LENGTH|TYPE|ID|VALUE data. It is packed in a dictionary like
{ID: (VALUE, TYPE)
"""
for k, val in expected.items():
actual_v = actual.pop(k)
if not (actual_v[0] == val[0] and actual_v[1] == val[1]):
return Fa... | 8c03f9d756a51f52b3298965c5a7f0c4d061d5c2 | 32,864 |
def avarage(num1, num2):
""" (number, number) -> number
Return the avarage of num1 and num2.
>>> avarage(10,20)
15.0
>>> avarage(2.5, 3.0)
2.75
"""
return (num1 + num2) / 2 | 275f7808a650f2c139a0f121d23e8044c59cf69b | 32,865 |
import struct
def _decode_int(fp):
"""Decode an int tag
:type fp: A binary `file object`
:rtype: int
"""
return struct.unpack('>i', fp.read(4))[0] | 9badc80814a1ce4e7bb6894b1625ca44d75ba433 | 32,867 |
import re
def sort_alphanumeric(it):
"""
Sorts the given iterable in the way that is expected.
E.g. test.txt, test_1.txt, test_2.txt, test_11.txt
:param iterable it: Iterable to be sorted
:return iterable: Sorted iterable
"""
def _convert(text):
if text.isdigit():
ret... | f7685d4e54c92002864a1c9e4384a97a4187bad3 | 32,869 |
def MultipleSameInput(Input,alphabet_guess_already):
"""if Input is in alphabet_guess_already, return True"""
if Input in alphabet_guess_already:
return True
else:
return False | a17ef3fc95582936212d23d03337e742b7b89abe | 32,870 |
def get_average_uniqueness(indicator_matrix):
"""
Advances in Financial Machine Learning, Snippet 4.4. page 65.
Compute Average Uniqueness
Average uniqueness from indicator matrix
:param indicator_matrix: (np.matrix) Indicator binary matrix
:return: (float) Average uniqueness
"""
c =... | 48b9e09f274d05456742b3aff4a36e4e37ac9085 | 32,871 |
def get_xml_tag_dict(xml_tree, tag, attribute):
"""Searches an XML tree for a tag. Under this tag it get all elements and returns them as a dict
with "attribute" as the key, and the text for the element as the value
Args:
xml_tree (xml.etree.ElementTree): XML-tree to search through
tag (str... | 4d4bc983a282ac962fe55f917446f757cbd89c55 | 32,874 |
def mknj2i(item):
"""
Transforms "mknj" notation into tensor index order for the ERI.
Args:
item (str): an arbitrary transpose of "mknj" letters;
Returns:
4 indexes.
"""
notation = "mknj"
notation = dict(zip(notation, range(len(notation))))
return tuple(notation[i] for i... | 190e15bec44503e012cf04c5ec784d2b3d744aac | 32,875 |
import math
import string
def alphabet_enumeration(length):
"""
Return list of letters : A, B, ... Z, AA, AB, ...
See mapentity/leaflet.enumeration.js
"""
if length == 0:
return []
if length == 1:
return ["A"]
width = int(math.ceil(math.log(length, 26)))
enums = []
... | 57a0e980c15b480a6f62018d5898c93f278dca93 | 32,876 |
def msec_to_units(time_ms, resolution):
"""Convert milliseconds to BLE specific time units."""
units = time_ms * 1000 / resolution
return int(units) | 7654d0ddda09514fedb4ff0f8d67194b0f4c52ae | 32,877 |
import pickle
async def load_users():
"""
Loads users from 'users.pickle' file
:return: dictionary {id:User}
"""
with open("users.pickle", "rb") as file:
users_info_loaded = pickle.load(file)
print("Users loaded")
return users_info_loaded | d0f4e0c745f4dac362373a40cb8ea7684d068f64 | 32,879 |
def strip(val):
"""
Если val - текстовая строка, убирает пробелы с начала и конца,
иначе возвращает как есть.
"""
if hasattr(val, 'strip'):
return val.strip(' ')
else:
return val | 506dc3b0f38263949c1c7034cd0c5695b3f987a7 | 32,880 |
def clean_word(word):
"""
word (str): word to clean
Returns word with specific special characters removed
"""
string = ''
for c in word:
if c in [',', '!', '?', '.', '(', ')', '"']:
continue
string += c
return string | f2881ffbb05ee77c10c7061715fb3273b192b741 | 32,882 |
def big_l_array(p, lp):
"""
Generate L array using pattern and L' array, Theorem 0.2.2, see proof
:param p: the pattern
:param lp: the L' array
:return: the L array
"""
l = [0] * len(p)
l[1] = lp[1]
for i in range(2, len(p)):
l[i] = max(l[i - 1], lp[i])
return l | b4159189965e9dd8db451c3f9aa637e8306cc0ba | 32,883 |
import ast
def is_valid_python(tkn: str) -> bool:
"""Determine whether tkn is a valid python identifier
:param tkn:
:return:
"""
try:
root = ast.parse(tkn)
except SyntaxError:
return False
return len(root.body) == 1 and isinstance(root.body[0], ast.Expr) and isinstance(roo... | b1c04002f1fab770e11477eb380d2dfdc5a986a3 | 32,884 |
import torch
def make_pad_mask(lengths: torch.Tensor, le : bool = True) -> torch.Tensor:
"""Make mask tensor containing indices of padded part.
See description of make_non_pad_mask.
Args:
lengths (torch.Tensor): Batch of lengths (B,).
Returns:
torch.Tensor: Mask tensor containing ind... | 43b32a4dc7b1053ad80a8d6c47ea39d1835d5a71 | 32,886 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.