content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
import torch
def compute_jacobian(x, fx):
"""Function to compute jacobian
Args:
x:
fx:
Returns:
Jacobian
"""
b = x.size(0)
m = fx.size(-1)
J = []
for i in range(m):
grad = torch.zeros(b, m)
grad[:,i] = 1.
grad = grad.to(x.device)
... | d304ad3c2d26779a02a4f35a1e7f4e9e5844788d | 15,956 |
import math
def calc_rec_cycle(number):
"""calculate recurring cycle of 1/n"""
result = 0
i = 10 ** (int(math.log10(number)) + 1)
s = set()
while True:
if i == number or i == 0:
result = 0
break
if i < number:
result += 1
i *= 10
... | 8d49c5d4511c33e98b596c23d669192a8f1be91d | 15,957 |
from datetime import datetime
def _get_date(element):
""" This function extracts the date the image was taken from the image element
and converts it to a datetime format.
Args:
element: A dict cuntianing all the image attributes.
Returns:
Date the image was taken in the format of dat... | b42f6b24ce3545571bf1025b5b984386fde20208 | 15,958 |
import os
def _global_env_var_is(key, value):
"""
Check if file exists on disk or not.
"""
if key not in os.environ:
return False
else:
return os.environ[key] == value | 0c606b2e15b142cd00abe98022748479f10cff99 | 15,961 |
import os
def get_config_filename():
"""Returns the configuration filename"""
return os.path.expanduser("~/.irods/irods_environment.json") | d6b58898e7ec891e560e1d194e3f354df090fa92 | 15,962 |
import copy
def __kalman_backward_smooth__(xhat_fp, xhat_fm, P_fp, P_fm, A):
"""
:param xhat_fp:
:param xhat_fm:
:param P_fp:
:param P_fm:
:param A:
:return:
"""
N = xhat_fp.shape[1]
xhat_smooth = copy.copy(xhat_fp)
P_smooth = copy.copy(P_fp)
for t in range(N-2, -1, -1... | ec2ea4494f4711d41eaa6378406108d9423c14e7 | 15,963 |
def generate_chesksum(data: bytes) -> int:
"""
生成 ICMP 校验位
"""
n = len(data)
count = sum(data[i] + ((data[i + 1]) << 8) for i in range(0, n - n % 2, 2))
count += n % 2 and data[-1]
count = (count >> 16) + (count & 0xFFFF)
count += count >> 16
answer = ~count & 0xFFFF
return (answ... | bc1d576dca880aee51ffed7f75542b30f1bb7834 | 15,964 |
def _transform_dataframe_to_dict(raw_fact, gbkey):
"""[summary]
Parameters
----------
raw_fact : [type]
[description]
gbkey : [type]
[description]
Returns
-------
[type]
[description]
"""
data_param_list = list()
if gbkey is None:
... | 0e67b06284f1e8a59f40dbfa181c02e52ef87bc1 | 15,965 |
def _get_adjust_options(options, version, setuptools_url, setuptools_version):
"""Return a string containing the definition of the adjust_options function
that will be included in the generated virtualenv bootstrapping script.
"""
anaconda_error = None
if options.dev:
code = """
for... | 02f471756b3ed347ef9352ec3b3aae952318ceb3 | 15,966 |
def find_motif(motif, visit, chain, nsteps, current, previous, motifset, allover, natom, bond, atom, eqv):
"""
This recursive function finds a specific motif in the structure.
FIXIT - the comments here
nsteps: the number of steps made
current: atom selected for testing, this is a candidate to be ... | a8ac8d425a856fc97642ecac663dfc54d94234d4 | 15,967 |
def make_predictions(data, model, weights):
"""Predict the labels of all points in a data set for a given model.
Args:
data (array[float]): Input data. A list with shape N x 2
representing points on a 2D plane.
model (qml.QNode): A QNode whose output expectation value will be
... | 4ac2ba85a12d56f0128ba518e8a7d030c0eb5734 | 15,968 |
def finds(itemlist, vec):
"""return the index of the first occurence of item in vec"""
idlist = []
for x in itemlist:
ix = -1
for i in range(len(vec)):
if x == vec[i]:
idlist.append(i)
ix = i
if ix == -1:
idlist.append(-1)
i... | a59fb3512510e8e0996779e429a588af5c82546c | 15,969 |
def get_major_minor(stat_inst):
"""get major/minor from a stat instance
:return: major,minor tuple of ints
"""
return ( stat_inst.st_rdev >> 8 ) & 0xff, stat_inst.st_rdev & 0xff | ec623deb66d1e95f5ec9744ffbefc03c52ebf6a9 | 15,970 |
def _resources_json_version_required() -> str:
"""
Specifies the version of resources.json to obtain.
"""
return "develop" | 7f9eaff50b3a03ec50501e7ae125f4daab462325 | 15,971 |
def _can_show(view, location=-1):
"""
Check if popup can be shown.
I have seen Sublime can sometimes crash if trying
to do a popup off screen. Normally it should just not show,
but sometimes it can crash. We will check if popup
can/should be attempted.
"""
can_show = True
sel = v... | adef07025a4732b7f18898f63884b4fec1d8f7e0 | 15,973 |
def driver_cookies_list_2_str(cookies_list:list) -> str:
"""
driver的cookies list 转 str
:param cookies_list: eg: [{"domain":".jianshu.com", "expirationDate":1552467568.95627, ..., "name":"_m7e_session_core", ..., "value":"cc5871cc6fd05e742b83fbf476676450",}, ...]
:return:
"""
res = ''
for ite... | d3498666af2a0a01308afb2975459f893c91bb1b | 15,974 |
import hashlib
def get_metadata_hash_for_attachments(attachments):
"""
Calculate a metadata hash from a collection of attachments.
The hash will change if any of the attachments changes.
"""
hashes = [attachment.metadata_hash for attachment in attachments]
# Sort the hashes to make the hash d... | fb56306c611a1aa1d87e897650142375a69f26e3 | 15,976 |
import torch
def rmspe(pred, true):
"""Computes RMSPE"""
return torch.mean(((true - pred) / true)**2)**0.5 | 2a83c9c10fb0547b4d90c805d94db871eb1b9e11 | 15,977 |
import os
import shlex
import subprocess
def pkgconfig(package, variable):
"""pkg-config"""
pkgconfig_env = os.environ.get("PKG_CONFIG", "pkg-config")
cmd = f"{pkgconfig_env} --variable={variable} {package}"
cmd = shlex.split(cmd)
return subprocess.check_output(cmd).decode().strip() | 157108473c030a37caf2845e696f3585d1b8dd66 | 15,978 |
def _as_phi_args(
kappa=None,
tau=None,
# _default={},
**kwargs):
"""
utility function to convert model arguments to kernel arguments
"""
kwargs = dict(**kwargs)
# kwargs.setdefault(**_default)
if kappa is not None:
kwargs['kappa'] = kappa
if tau is no... | 70e8b648bf0f18fe9bf8e670b99b0fdd4dbdc79b | 15,979 |
import unicodedata
def soundex(s):
"""
https://stackoverflow.com/a/67197882/2771733
"""
if not s:
return ""
s = unicodedata.normalize("NFKD", s)
s = s.upper()
replacements = (
("BFPV", "1"),
("CGJKQSXZ", "2"),
("DT", "3"),
("L", "4"),
("MN", ... | 94ed0c26a441cbbe56beaf8e042d346f2b195509 | 15,980 |
def load_requirements():
"""
Loads requirements.txt
:param:
:return: list of requirements
"""
with open('requirements.txt') as f:
return [req for req in f.read().split() if req] | 2e4dc452ef9f89e546e0ce49a637090056b88ced | 15,983 |
def media_anual(temperaturas):
"""Receba uma lista com as temperaturas médias de cada mês
e devolva uma lista com os números correspondentes aos meses
que possuem temperatura superior á média anual."""
media = sum(temperaturas) / len(temperaturas)
meses_acima_da_media = []
for mes, temperatura i... | 10c6da72824f8021b451ed710b6a915240a5082e | 15,984 |
def get_xr_resolution(ds):
"""
Read dataset and get pixel resolution from attributes. If
attributes don't exist, fall back to rough approach of minus
one pixel to another.
Parameters
----------
ds: xarray dataset, dataarray
A single xarray dataset with variables and x and y dims.
... | 3d87ff33190078753a496fd5f14854fa98eb1017 | 15,985 |
from datetime import datetime
def extract_date():
"""
Extract the date when the query is made in the format YYYYMMDD.
"""
return datetime.today().strftime('%Y%m%d') | 099df827a72b2fa002159f30a6f345918ad897f5 | 15,986 |
import sys
def isLinux():
"""
isLinux
"""
return sys.platform.startswith("linux") | 62e9b728864608a1e32e5d241b28fc208fdcfa8a | 15,988 |
from typing import List
from typing import Dict
def match_relationships(relationships: List):
"""Creates a dict that connects object_id to all objects_ids it has a relationship with.
Args:
relationships (List): A list of relationship objects.
Returns:
Dict. Connects object_id to all obje... | 870db3b324f340a7f632251ebe22bfae6e693076 | 15,989 |
def makeChromTiles(db):
"""
Make a region for each chromosome
"""
out = []
for (k, v) in db.chromsTuple:
out.append([k, 0, v])
return out | ca887035f05047bf7172c4e120fc7623a0fcb3e5 | 15,990 |
def _construct_GDS_url(accession):
"""Example URL:
ftp://ftp.ncbi.nlm.nih.gov/geo/datasets/GDS4nnn/GDS4999/soft/GDS4999.soft.gz
"""
number_digits = len(accession) - 3 # 'GDS' is of length 3.
if number_digits > 3:
folder = accession[:4] + "nnn"
else:
folder = accession[:3] + "n" * number_digits
url = '/'.j... | 0b6968a1d47beb3be1e521f4b84ff2174de8baf3 | 15,991 |
import re
def getMovieName(downloadLink):
"""输入ftp链接,使用正则表达式分析文本,返回电影名字"""
name_patten = re.compile(r'](?!/)\.?(.+?)\.[a-z]{3,4}$') # 结果是xxx.rmvb 或xxx.mkv
name_match = re.findall(name_patten, downloadLink)
if bool(name_match):
return name_match[0].split('.')[0]
else:
return 'None' | fee6e95bc0ada0ea983e78db62e829789e4cc248 | 15,993 |
def data2mesh(data):
"""
Extracts from a given torch_geometric Data object the mesh elements
Parameters
----------
data : Data
a torch_geometric Data object
Returns
-------
(Tensor,LongTensor,Tensor)
the points set, the topology and the vertex normals tensor
"""
... | 781489d95db76d106c910efda9bbc5f348e9d7ed | 15,994 |
def uglify(text: str):
"""
Написать фильтр который меняет четные и нечетные символы на upper(), lower()
"""
new = ''
for index in range(len(text)):
if index % 2 == 0:
new += text[index].upper()
else:
new += text[index].lower()
return new | 61228973664061adf8da616404f74a8e311b4e26 | 15,997 |
def prime_generator(maxi):
"""
Generate all the prime numbers below maxi. maxi is not included.
The method uses Aristotle's sieve algorithm.
>>> prime_generator(10)
[2, 3, 5, 7]
"""
li = []
for _ in range(maxi):
li.append(1)
li[0] = li[1] = 0
for pos, val in enumerate... | f2829ed995f0f289b22960fad706cf3ec0371446 | 15,998 |
def filter_content(contents, rules, mode=any):
"""
Filter contents by given rule.
Args:
contents `list`
List of illust, the content may vary from source to source.
Besure you know the data hierachy of object.
rules `list`
A list of function takes... | a875ee3d8523a29043b576c9d19ef8a09589ed91 | 15,999 |
def get_dict_key_by_value(source_dict: dict, dict_value):
"""Return the first key of the ``source_dict`` that has the ``dict_value`` as value."""
for k, v in source_dict.items():
if v == dict_value:
return k
return | 0ae198c7d07fe57898779f0b75b75bdb590f5a3d | 16,000 |
from pathlib import Path
def get_cases(f, sep="---"):
"""
Extracts inputs and outputs for each test/verification case within f, where f is a folder.
Params
======
f: str
The folder containing the cases to be extracted.
sep: str
The substring separating comments from the input... | bedcc7cedd791505dbed886a539df92aa0fa3f87 | 16,001 |
import requests
def create_empty_zenodo_upload(access_token):
"""
Create an empty upload using Zenodo API.
:param access_token: Zenodo access token.
:return: requests.models.Response from Zenodo API
"""
headers = {"Content-Type": "application/json"}
r = requests.post('https://zenodo.org/ap... | 14a26a07a08b2dab1ccf55ddea8c3d4cb3d9a2d6 | 16,002 |
def slurp(name):
"""
Read the file
:param name: read the named file
:return: the content
"""
with open(name, "r") as f:
return f.read() | 2edb241b5cbb0c9298dbdc9dd5f1f89786fff036 | 16,004 |
def vec_is_void(a):
"""
Check whether a given vector is empty
A vector is considered "void" if it is None or has no
elements.
Parameters
----------
a: list[]
The vector to be checked
Returns
-------
bool
True if the vector is empty, False otherwise
"""
... | 9a9b6f78ec2ddb81990fe54a5b429413c0472742 | 16,006 |
def MergeTwoListsAsDic(keys, values):
"""
"""
dic = {}
for i in range(len(keys)):
dic[keys[i]] = values[i]
return dic | 85e7fa6fcf93c51bcdee93ff3c355f8d369fa043 | 16,007 |
import sys
def __library_name() -> str:
"""Get lattice_symmetries C library file name with correct extension."""
if sys.platform == "linux":
extension = ".so"
elif sys.platform == "darwin":
extension = ".dylib"
else:
raise ImportError("Unsupported platform: {}".format(sys.platf... | 651ece84a37221c67d6a511bb455991ebd0e88e5 | 16,008 |
import gzip
def read_gzipped_file(filepath):
"""
Opens an underlying process to access a gzip file through the creation of a new pipe to the child.
:param str filepath: path to gzip file.
:return: A bytes sequence that specifies the standard output.
"""
handle = gzip.open(filepath, "rt")
... | 4f627f8ee5be5e77e427158216be8d254586a72b | 16,009 |
def chargeandprop(aa_seq):
""" Calculates protein net charge and charged AA proportion
"""
protseq = aa_seq.upper()
charge = -0.002
cp = 0
aa_charge = {'C':-.045,'D':-.999,'E':-.998,'H':.091,
'K':1,'R':1,'Y':-.001}
for aa in protseq:
charge += aa_charge.get(aa, 0)
... | 1d967642235188090875cb35e21a9367cca9343e | 16,010 |
import os
import yaml
def save_dict_as_yaml(dictionary: dict, path: str) -> str:
"""Save a cfg dict to path as yaml
Parameters
----------
dictionary
Dictionary to be saved
path
Filesystem location where the yaml file will be saved
Returns
-------
path
Location... | 6c7fc19327e993ca4597a46e0a92efdd93f38bd5 | 16,011 |
import calendar
def _sort_order(count_items):
"""Key for sorting day counts in days of the week order."""
return list(calendar.day_name).index(count_items[0]) | 9fa5a3f37ee034a99c2c6ed428655261661210aa | 16,012 |
def load_db_class(dbtype):
"""
read subcommand from subcmds directory
:return: subcommands list
"""
pkgname = 'datafaker.dbs.' + dbtype + 'db'
classname = dbtype.capitalize() + 'DB'
module = __import__(pkgname, fromlist=(classname))
db_class = getattr(module, classname)
return db_cla... | 3dbbfeab6505cf2aa72929b16f65a6f9fa8751f5 | 16,013 |
def make_alternating_color_pattern(ctr, rgblst):
"""
Return a pattern of alternating colors from rgblst.
"""
n = len(rgblst)
return ctr.make_func_pattern(lambda i: rgblst[i % n]) | 3ff2396c390c813169e3399dd04d353c98a9f9f8 | 16,014 |
def download_input(storage_provider, parsed_event, input_dir_path):
"""Receives the event where the file information is and
the tmp_dir_path where to store the downloaded file.
Returns the file path where the file is downloaded."""
return storage_provider.download_file(parsed_event, input_dir_path) | 887ca61a40a658d172b4b77833132b73933a14ce | 16,015 |
def get_bit(val: int, bitNo: int) -> int:
"""
Get bit from int
"""
return (val >> bitNo) & 1 | 19d49512387da66e5889fc1bacc014be240be4a9 | 16,016 |
def GetChildNodesWhereTrue(node_id, tree, stop_function):
"""walk down in tree and stop where stop_function is true
The walk finishes at the leaves.
returns a list of tuples of nodes and distance.
"""
result = []
def __getChildNodes(node_id, distance):
node = tree.node(node_id)
... | 9837a8ac294b8202a6e17deecd213d25599f575b | 16,017 |
def truncate(vec, max_length, truncate_tail=True):
"""truncate vec to make its length no more than max length.
Args:
vec (list): source list.
max_length (int)
truncate_tail (bool, optional): Defaults to True.
Returns:
list: truncated vec.
"""
if max_length is None:... | 31921b3c15c8b77b74d65965b997c374bd1cafb2 | 16,019 |
def get_full_version(package_data):
"""
Given a mapping of package_data that contains a version and may an epoch and
release, return a complete version.
For example::
>>> get_full_version(dict(version='1.2.3'))
'1.2.3'
>>> get_full_version(dict(version='1.2.3', epoch='2'))
'2~1.2.3'
... | 3a8cc3731da2ef3f99e3e9f203e084c9478f48c8 | 16,020 |
def knight_tour(n, path, u, limit):
"""
Conduct a knight's tour using DFS.
Args:
n: current depth of the search tree.
path: a list of vertices visited up to this point.
u: the vertex we wish to explore.
limit: the number of nodes in the path.
Returns:
done (bool... | f11a2da4e740183a85dbd2f281c65dda77237dad | 16,021 |
def read_tags_and_datablocks(text):
""" read a file consisting of blocks of numbers which are
separated by tag lines. separate tag lines from data lines
return two lists
e.g. for pp.data file:
Atomic number and pseudo-charge
14 4.00
Energy units (rydberg/hartree/ev):
rydberg
Angular momentum of local component... | 372512010198aa401552302d45f0a0745477bec1 | 16,022 |
def convert_sensor_type(v):
"""
converts the sensor type value into something
more meaningful.
"""
if v is 0:
return "None"
elif v is 1:
return "RealPower"
elif v is 2:
return "ApparentPower"
elif v is 3:
return "Voltage"
elif v is 4:
return "Current"
else:
return "Unkn... | 7f5bd77db7a240d21728b526daae7729b0871143 | 16,023 |
def annotate_route_announce(announce, ro_rad_tree):
"""
Add a list of IRR containing valid route objects for this `announce' in "valid".
:param announce: dictionary to annotate containing "asn" and "prefix" fields
:param ro_rad_tree: radix tree containing route objects, AS nb in data["asn"]
:return... | 79ebdc487433a6b94ab098bb457263953a449a88 | 16,024 |
import argparse
def get_args():
"""! Command line parser """
parser = argparse.ArgumentParser(
description='Audio Reader, reading and manipulating Audio')
parser.add_argument("--input_path", type=str,
help="""Path for an audio file to be parsed""",
d... | fc6372e812a1af8ee1cfae8c3eb5e911da2fcf9c | 16,025 |
def create_y_range(motile_count,
non_motile_count,
auto_motile_count,
auto_non_motile_count):
"""
Generate the y range on the motility bar
:param motile_count: the amount of motile life at this frame
:param non_motile_count: the amount of non mot... | 037c3020e82bda853410e15e7c0b0f9b8d0d9be1 | 16,026 |
def area_trapezio(a, b, c):
"""a área do trapézio que tem A e B por bases e C por altura."""
area_trape = (a + b)/2 * c
return print(f'TRAPEZIO: {area_trape:.3f}') | 64fadfa67e2ef64722a016b4171e318a68765c55 | 16,029 |
def signed_up_user():
"""
pytest fixture can be a good way to share data across
your test suites using dependency injection
see link here: https://docs.pytest.org/en/latest/fixture.html#fixture
but you can decide to use pytest-datadir or pytest-datafiles
:return: a dictionary ... | 44964dc8a9c784e3a2fcce77a0d459c3ccbd02bc | 16,030 |
def karatsuba_multiply(a, b, precision=50, radix=10):
"""
Karatsuba multiplication for integers
Generalized for integers 0 <= a, b <= radix ** precision
Complexity: O(n ^ log_2(3)) where n is the precision of
multiplication desired.
"""
precision_on_2 = precision >> 1
a_1 = a // (radix ** precision_on_... | 58fdf93d4fad4d31bc60c679dad69f91a63e17a0 | 16,031 |
import subprocess
import re
def get_ck_frames(kernel):
"""
Get all of the reference frames defined in a kernel.
Parameters
----------
kernel : str
The path to the kernel
Returns
-------
ids : list
The set of reference frames IDs defined in the kernel
"""
... | f50b3ac3534767e8071f07c4fffc26057eb1f8db | 16,033 |
import bz2
def bunzip2(fileobj):
""" bunzip2 the file object. """
return bz2.decompress(fileobj) | 7da3f9b64cd0f6765860678b18be661fd42b813e | 16,034 |
def observatory_from_string(string):
"""If "jwst" or "hst" is in `string`, return it, otherwise return None."""
if "jwst" in string:
return "jwst"
elif "hst" in string:
return "hst"
else:
return None | 217cc3cf3c5b802799c0db73563f6d11b7ab4c4d | 16,035 |
def get_type(data):
"""
@param data: rosdoc manifest data
@return 'stack' of 'package'
"""
return data.get('package_type', 'package') | ee3f881ff2479dfec0ce17a8c19161407e246a1c | 16,036 |
def get_letters_pep(peptides_lst):
"""
Get letters list and letter-index dictionaries
"""
word_to_ix_ = dict((i, j) for j, i in enumerate(['<PAD>']+list(set(x for l in peptides_lst for x in l))))
ix_to_word_ = dict((j, i) for j, i in enumerate(['<PAD>']+list(set(x for l in peptides_lst for x in ... | 5c341a9cdd99a874a34c1ed967a5e95ad1c7ed6f | 16,037 |
import copy
def addAction(state, timeDifference, newAction) :
"""Adds an newAction to a state atfter timeDifference s after the current
state timestamp
"""
newState = copy.deepcopy(state)
# Sorts the nextActions array with the newAction added by their respective
# Timestamps; adds the newActio... | beacec84a43efa59f5f51e488b9e92d8acf1ee97 | 16,038 |
def seq_info(names, id2names, insertions, sequences):
"""
get insertion information from header
"""
seqs = {} # seqs[id] = [gene, model, [[i-gene_pos, i-model_pos, i-length, iseq, [orfs], [introns]], ...]]
for name in names:
id = id2names[name]
gene = name.split('fromHMM::', 1)[0].rs... | a3bfd66d77034bb96970cea7892be4694908047e | 16,039 |
def _get_lat_lon(df):
"""Get latitude and longitude from geometries."""
col = df._geometry_column_name
df["latitude"] = [latlon.y for latlon in df[col]]
df["longitude"] = [latlon.x for latlon in df[col]]
return df | 9ab4b1cb469ae88444de97ec0cb0cec008643c4a | 16,040 |
def get_list_params_with_serialized_objs(page):
"""
Search for parameters that contain a java serialized object
:param page: The page source code for search in it
:return: List of parameters found
"""
page = str(page).replace("\\n", "\n")
list_params = []
for i in page.split('\n'):
... | 502d32a920a4844d78a9a4aabe81f1d018d3f4ef | 16,041 |
def fix_fp(sequence, parallel):
"""
Fix footprints
Parameters
--------------
sequence
Sequence
parallel
Parallel
Returns
-------------
sequence
Sequence
parallel
Parallel
"""
sequence = sequence.difference(parallel)
return sequence, p... | 721021af7d9f4b07ee25861788cde878a31b6135 | 16,044 |
def apply_ratio(o_w, o_h, t_w, t_h):
"""Calculate width or height to keep aspect ratio.
o_w, o_h -- origin width and height
t_w, t_h -- target width or height, the dimension
to be calculated must be set to 0.
Returns: (w, h) -- the new dimensions
"""
new_w = t_h * o_w / o_h... | f3143e5a5ad8aeafbb913e73aab40e8e8990ddd6 | 16,045 |
def knapsack_rep(weights, values, W):
""" knapsack with repetition """
k = [0]*(W + 1)
for w in range(1, W+1):
k[w] = max([k[w-i] + values[i] if weights[i]<=w else 0 for i in range(len(weights))])
return k[-1] | 5ec8a544d6869130970d1b7194c3d7ea77b59b4b | 16,047 |
def maybe_append(usa_facts, jhu):
"""
Append dataframes if available, otherwise return USAFacts.
If both data frames are available, append them and return.
If only USAFacts is available, return it.
If USAFacts is not available, return None.
"""
if usa_facts is None:
return None
... | 4f0831a09ac36caaec6f825036e69d0f5b62b19f | 16,050 |
def stepcalc(time, duration):
"""Calculates frequency and resulting windowlength
"""
tstep = (time[1] - time[0])
freq = 1. / tstep
arr_len = duration * freq
return int(arr_len) | 5b42e281d10cb888d1dbdc8cd01422b8c6ec6979 | 16,051 |
import re
def get_platform(properties_file):
"""Finds and returns the platform version in the properties file.
Returns:
String form of the platform version if found, else "unknown".
"""
android_regex = re.compile(r'(android-\w+)')
vendor_regex = re.compile(r':(\d+)\s*$')
for line in p... | a1f765f383973251adc21725a19fe96a3bcaa2bc | 16,052 |
def evaluate(clauses, sol):
"""
evaluate the clauses with the solution
"""
sol_vars = {} # variable number -> bool
for i in sol:
sol_vars[abs(i)] = bool(i > 0)
return all(any(sol_vars[abs(i)] ^ bool(i < 0) for i in clause)
for clause in clauses) | be50aa2c8f04b6d1ac76a17aea86beedc7abff4c | 16,053 |
import base64
import sys
def xor_decode(encoded_text):
"""
Decode xor encoded text
"""
#remove initial {xor} if it exists
if encoded_text[0:5].lower() == '{xor}':
encoded_text = encoded_text[5:]
#Convert to bytes, and then pass to base64.decodebytes
try:
decoded_... | 95979e077bfbfcc43757164d89b5b9a824873214 | 16,054 |
import json
def _load_iam_data(path):
"""Builds a dictionary containing the information about all the
AWS IAM resources and the actions they relate to (for more information look
at the README.md in this directory). The keys of the dictionary are all the
possible IAM policy actions and the values are s... | 7b394285f088ade8042207fdccbb9e6dfec78314 | 16,058 |
def is_field(x):
"""
Return whether or not ``x`` is a field.
Alternatively, one can use ``x in Fields()``.
EXAMPLES::
sage: R = PolynomialRing(QQ, 'x')
sage: F = FractionField(R)
sage: is_field(F)
True
"""
return x.is_field() | 87efa719721d72df5c751d734f2f26d6641190c1 | 16,059 |
def sentence_spans(text, sentence_detector):
""" Разбиваем на предложения и генерируем разметку - для красоты """
sentences = sentence_detector(text)
spans = []
sent_start= 0
idx = 1
for sent in sentences:
sent_end = sent_start + len(sent)
spans.append((sent_... | 174c8633bfeb03e67cdba4701b23324c736423ad | 16,060 |
from typing import Optional
from typing import Dict
def create_exclusive_start_key(player_id: str, start_key: Optional[str]) -> Optional[Dict[str, str]]:
"""
Create the 'ExclusiveStartKey' parameter for the DynamoDB query, based on the user-provided 'start_key' parameter to
this Lambda function.
"""
... | 7a03434e2d52908eb4f4d68483058183913ac9bb | 16,061 |
def label_id_to_cluster_id(label_id, C, unused_labels):
"""Map the label id to the cluster id according to clustering matrix.
Args:
label_id: the label id.
C: the cluster matrix of shape L x C.
unused_labels: used to adjust the label id.
Returns:
the cluster id.
... | 61593eb822dbaf88f101b2948c02de3fc07794d1 | 16,062 |
import tarfile
import os
def unpack_tar_to_rocket(tar_path: str, rocket_folder_name: str, folder_path: str, remove_after_unpack: bool = True):
"""Unpack a tar archive to a Rocket folder
Unpack a tar archive in a specific folder, rename it and then remove the tar file (or not if the user doesn't want to)
... | c06c29d6d1f4f56fefe99afaa9d8f1f9a5e8cf9c | 16,063 |
def expand_locations_and_make_variables(ctx, attr, values, targets = []):
"""Expands the `$(location)` placeholders and Make variables in each of the given values.
Args:
ctx: The rule context.
values: A list of strings, which may contain `$(location)`
placeholders, and predefined Ma... | cb426117582161c5f32034df2cc1db29ebe37205 | 16,065 |
def swaggerFilterByOperationId(pathTypes):
"""take pathTypes and return a dictionary with operationId as key
and PathType object as value
Keyword arguments:
pathTypes -- list of types that build the model, list of yacg.model.openapi.PathType instances
"""
ret = {}
for pathType in pathTypes... | 57a2322088602f9cbde626d4ea0bb65a602cfd21 | 16,066 |
from pathlib import Path
import os
def path_resolver(source_root):
"""Construct a function to calculate paths inside source root folder.
Args:
source_root (String): Path to the root folder in which all source video files are located.
Returns:
function: Function to relativize paths to th... | 0478371a426d2d8deb2024c556dd01c96db268bf | 16,067 |
def get_result_or_raise(future):
"""Returns the ``result`` of *future* if it is available, otherwise
raise.
"""
return future.result | 8f6b2b6b6def964d48829f2b63467a6e39e3b853 | 16,071 |
def string_not(str1):
"""Apply logical 'not' to every symbol of string"""
return "".join([chr(256 + ~ord(x)) for x in str1]) | aca64e1fb4c50528ba27dceb2557291404215c42 | 16,072 |
def missing_respondents(reported, observed, identified):
"""Fill in missing respondents for the f1_respondent_id table.
Args:
reported (iterable): Respondent IDs appearing in f1_respondent_id.
observed (iterable): Respondent IDs appearing anywhere in the ferc1 DB.
identified (dict): A {... | f919a9d398898b06d4442c75cc314a8cb52e1c5f | 16,073 |
def sass_change_vars(string_sass: str, context: dict={}) -> str:
"""This function is used to change the values of variables in a sass file
:param string_sass: String with the sass code
:param context: The dictionary keys in context represent the variables that will be searched for in the sass code
... | 16d2b80b46ce66368b9ef0f539e7e21a6f2a83cd | 16,074 |
def translate_humanity(request):
"""
translates request.session['humanity'] dictionary {0: True, 1: False, ..}
into 'One, Two, Three' according to numbers that are True
@param request: Http Request
@return string
"""
numbers = []
translation = {0: 'one', 1: 'two', 2: 'three', 3: 'four'}... | 915056438673e8581cf1f762dcfefcbabb820d19 | 16,076 |
def distance(x_0, y_0, x_1, y_1):
"""Return distance between 2 points (x_0, y_0) and (x_1, y_1)
"""
x_dist = x_0 - x_1
y_dist = y_0 - y_1
return(x_dist ** 2 + y_dist ** 2) ** 0.5 | 06c250b09e2a386f1814fe9c748cad574869a741 | 16,077 |
def get_cache_encrypt_key(key):
"""Prepare key for use with crypto libs.
:param key: Passphrase used for encryption.
"""
key += (16 - (len(key) % 16)) * '-'
return key.encode('utf-8') | 86beda15822e593315fa39a19eca2dccd8968e7e | 16,078 |
from typing import Callable
from typing import Sequence
def randline(filename: str, randchoice: Callable[[Sequence[str]], str]) -> str:
"""
return a randomly-selected line from the given file
"""
with open(filename, "rt", encoding="utf-8") as fh:
return randchoice(fh.readlines()).rstrip() | 6978158b25a8702e99ee6e7f9461cd391873eee4 | 16,081 |
async def latency(ctx):
"""Returns my gateway latency."""
return f'{ctx.client.gateway.latency*1000.:.0f} ms' | f2d088adfa485bfff8da5154ce672232e4d57e1d | 16,082 |
import os
def pdir():
"""Get absolute path to parent directory.
Returns
-------
str
abs path to parent directory
"""
return os.path.realpath(os.path.pardir) | 244081bb26b8e2371c1f96b0938cef20e60a485c | 16,083 |
def str2intlist(s, delim=","):
""" create a list of ints from a delimited string
Parameters
----------
s: string
delim: string
Returns
-------
int_list: list of ints
Examples
--------
>>> str2intlist("1,2,3")
[1, 2, 3]
>>> str2intlist("1-3")
[1, 2, 3]
>>> s... | ae7a568a9e8b7c55e146515fad4dd810bee4ae46 | 16,084 |
def generate_timestamp_format(date_mapper: dict) -> str:
"""
Description
-----------
Generates a the time format for day,month,year dates based on each's
specified time_format.
Parameters
----------
date_mapper: dict
a dictionary for the schema mapping (JSON) for the dataframe f... | cd535a4fb35917517711cf149430c128e2c46b6d | 16,085 |
def get_command(line, fmt_space):
"""
Given a header line, get the possible command
Parameters
-----------
line : string
Line of the header
fmt_space : boolean
Yes = Novonix format with spaces in the commands
Returns
--------
command : string
Instruction in... | 78642fd6e98817b85ce8431774a34723ed649473 | 16,086 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.