content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
import torch
def gen_perturb(data, sigma_perturb=1.0, sigma_end=0.01):
"""
perturb given protein structure with gaussian noise
"""
pos_init = data.pos
step_size = 0.00002 * (sigma_perturb / torch.tensor(sigma_end)) ** 2
noise = torch.randn_like(pos_init) * torch.sqrt(step_size * 2)
pos =... | 99b2685e4c20c7a9e773aad320a3b85c8eccd154 | 17,320 |
def _sub_complete_column(column, index): # noqa: F811
"""
This function processes the `columns` argument,
to create a pandas Index.
Args:
column : str
index: pandas Index
Returns:
pd.Index: A pandas Index with a single level
"""
arr = index.get_level_values(column... | 9668c944623a038321b35796bad918af87b40e9c | 17,322 |
def paren(iterable):
"""Return generator that parenthesizes elements."""
return ('(' + x + ')' for x in iterable) | c841c9145c35a0f600a39845484176a01b6492be | 17,323 |
def all_suffixes(li):
"""
Returns all suffixes of a list.
Args:
li: list from which to compute all suffixes
Returns:
list of all suffixes
"""
return [tuple(li[len(li) - i - 1:]) for i in range(len(li))] | ff1a2cf4fa620d50ecb06e124a4c2ca192d5d926 | 17,324 |
from typing import List
from typing import Dict
from typing import Union
import warnings
def _get_group_id(
recorded_group_identifier: List[str],
column_links: Dict[str, int],
single_line: List[str],
) -> Union[str, None]:
"""Returns the group_name or group_id if it was recorded or "0" if not.
Fav... | ea8e64d8377513d00205cb8259cb01f8711bf135 | 17,325 |
import warnings
def parse_sacct(sacct_str):
"""Convert output of ``sacct -p`` into a dictionary.
Parses the output of ``sacct -p`` and return a dictionary with the full (raw)
contents.
Args:
sacct_str (str): stdout of an invocation of ``sacct -p``
Returns:
dict: Keyed by Slurm J... | 2719e08dea13305c6e6fcef19bd4320072ad7647 | 17,326 |
import socket
def get_unused_port_and_socket_ipv6():
"""
Returns an unused port on localhost and the open socket
from which it was created, but uses IPv6 (::1).
"""
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
s.bind(('::1', 0))
# Ignoring flowinfo and scopeid...
addr, port, ... | d5164fdfd9ba136c4835e8c2e49ae8e0a88c846e | 17,327 |
import pytz
def format_date(dt):
"""
Format a datetime into Zulu time, with terminal "Z".
"""
return dt.astimezone(pytz.utc).strftime('%Y-%m-%dT%H:%M:%S.%fZ') | 524ee5803e5a5e26e7b9f8a1b6b680d7d739b3b1 | 17,328 |
import random
import string
def generate_random_string(len: int):
""" Creates a randomly generated string of uppercase letters
Args:
len (int): The desired length
Returns:
random_string (str)
"""
return ''.join(random.choices(string.ascii_uppercase, k=len)) | 5414ecb7a6e212379000e43fef07e4642c0e63a0 | 17,329 |
def modular_exponentiation(b, e, m):
"""produced modular exponentiation.
https://en.wikipedia.org/wiki/Modular_exponentiation
:param b: a base number.
:param e: an exponent.
:param m: a modulo.
:return: a reminder of b modulo m.
"""
x = 1
y = b
while e > 0:
if e % 2 == 0... | 389cab70e83bb2c2972c39583edbb2bca8efeacb | 17,330 |
def load_file(cert_path):
"""Load a file"""
with open(cert_path) as cer:
cert = cer.read()
return cert | 5910e60bff0fc60aab376f47a35986df4a89e00a | 17,331 |
def expected_bfw_size(n_size):
"""
Calculates the number of nodes generated by a single BFW for a single root node.
:param n_size: <list> The number of neighbours at each depth level
:return: The size of the list returned by a single BFW on a single root node
"""
total = []
for i, d in enume... | f275af1c152c4d4704c0be5ee43f3d0f8802900b | 17,332 |
import random
import string
def username():
"""生成随机用户名"""
return "test_" + "".join(random.sample(string.ascii_letters + string.digits, 10)) | bc86aa6c38651aa29ee5debed8af10e43e20c21e | 17,333 |
import csv
def parse_csv_dict(filename):
""" Parses csv file and returns header columns and data. """
data = []
with open(filename) as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
data.append(row)
return reader.fieldnames, data | 8ffc34a6906cf59926ef618076732eb24f0561fa | 17,334 |
def combineRulesWithOperator(listOfRules, operator):
"""
Takes a list of rules and makes an overall rule that ties them together
with the AND or the OR operator
Parameters
----------
listOfRules: list
A list of string representation of rules
operator: str
Should be either AN... | 7dfc4988f9c56e05318704a7bd6990fc9b00d604 | 17,335 |
def make_product(digits, k, start):
"""
Compute k numbers product from start position.
:param digits:
:param k:
:param start:
:return: (product, next_start)
"""
index = 0
product = 1
while index < k and start + index < len(digits):
if digits[start + index]:
pr... | caa4b9da545c7c575291ed2af1ae2579a681930d | 17,340 |
def get_yearly_minutes():
"""Get yearly minutes."""
return 525600 | c2bb066c156deb105c0722bd45bdea5a27c35564 | 17,341 |
def _unroll_into_samples(out_ndim, *arrs):
"""Flatten samples, slices, and batches dims into one:
- `(batches, slices, samples, *output_shape)` ->
`(batches * slices * samples, *output_shape)`
- `(batches, samples, *output_shape)` ->
`(batches * samples, *output_shape)`
`*ar... | c7bfe261f163c528d4a3903de56b964261e50a31 | 17,342 |
from typing import List
def parse_mbr_beam(parts: List[str]):
"""
Structure: $corpus.mbr.$utility_function.beam.$length_penalty_alpha.$num_samples.$metric
Example: dev.mbr.sentence-meteor.beam.1.0.10.meteor
:param parts:
:return:
"""
corpus, decoding_method, utility_function, sample_o... | 04c36de5b2b05fd7c8b27a62f47e526527fb9404 | 17,343 |
def is_footnote_label(text):
"""
Retorna True quando text representa "label" de nota de rodapé. Padrões:
Primeiro caracter é dígito
Primeiro caracter não é alfanumérico
Uma letra, minúscula
"""
if text:
return any(
[
text[0].isdigit(),
not ... | 306caca320e46bd12e76a16a1309e46ebfe75257 | 17,344 |
def decode_topic_names(topic_name):
"""Separate topic names.
# Arguments
topic_name: byte string
subscribed topic name
# Returns
topic_names: list
a list of strings
"""
tmp_topic_name = topic_name.decode("utf-8")
return tmp_topic_name.split("/") | 5abb98c8d220f5133ab59e90ecd9e6cfc7a86c2d | 17,345 |
def _get_image_offsets(width, height, segments_x, segments_y):
"""
Gets offsets for the segments
:param width: map width
:param height: map height
:param segments_x: number of x segments
:param segments_y: number of y segments
:return: lists of x offsets, lists of y offsets
"""
offse... | 97fbde70318ca592643f99af332cfa1862da00f0 | 17,346 |
import torch
def compute_N_L(lambda_L, Gram_L, G_out):
"""Compute N_L using KRR
Parameters
----------
lambda_L: float
Last layer regularization parameter
Gram_L: torch.Tensor of shape (n_samples, n_samples)
Last layer Gram matrix
G_out: torch.Tensor of shape (n_sam... | 53ab4781898ae262e491d5a6ca577bcdd7fa8144 | 17,347 |
import re
def check_method(d, string):
"""check method is support."""
method = set(re.findall(r'[a-zA-Z0-9_]+(?=\()', string))
method_support = {'zip', 'replace', 'range', 'tuple', 'set', 'list', 'str',
'strftime', 'sorted', 'int', 'float', 'type', 'round',
'len... | 08fc7068a7d4c099c86d4bff6e0e31bcf32b1778 | 17,348 |
def Mceta(m1, m2):
"""Compute chirp mass and symmetric mass ratio from component masses"""
Mc = (m1*m2)**(3./5.)*(m1+m2)**(-1./5.)
eta = m1*m2/(m1+m2)/(m1+m2)
return Mc, eta | fa55e1cfc669f3e180aed1a3cc838ed82147ddbc | 17,349 |
import decimal
import os
import csv
def make_feature_matrix(directory_name, feature_number, num_objects, start_object=0):
"""
The function is used to parse multiple csv-files in order to create matrix with list of feature values.
Returned values are to be used in Shannon's or Kullback's methods or in met... | c197fc14c7aecef9e0161781dfa0bc70142c9693 | 17,352 |
def split_sents(notes, nlp):
"""
Split the text in pd.Series into sentences.
Parameters
----------
notes: pd.Series
series with text
nlp: spacy language model
Returns
-------
notes: pd.DataFrame
df with the sentences; a column with the original note index is added
... | 0aae3af46a2a0c29fff9c3bb5725b0ddcb8ed796 | 17,354 |
import os
import glob
def find_input_images(working_dir=os.getcwd(), image_format='jpg'):
"""Find the input images. Defaults to looking for all .jpg files in
current working directory."""
images = glob.glob(os.path.join(working_dir, '*.%s' % image_format))
if images is None:
return []
r... | 4a3760277e5333aa88892492644f8e89b05f71d7 | 17,355 |
def compute_mm_force(sim, positions):
"""compute mm forces given a position"""
sim.context.setPositions(positions)
return sim.context.getState(getForces=True).getForces(asNumpy=True) | aad2d8c5d628af33d40637bda343e3d9c8066b6a | 17,357 |
def _is_header_line(line: str) -> bool:
"""
Determine if the specified line is a globals.csv header line
Parameters
----------
line : str
The line to evaluate
Returns
-------
is_header_line : bool
If True, `line` is a header line
"""
return "kT" in line | 06f8ff10deeac60e92b2fd92059873d5abafa367 | 17,358 |
from typing import Set
def parse_modes(modes: Set[str]) -> Set[str]:
"""A function to determine which modes to run on based on a set of modes potentially containing blacklist values.
```python
m = fe.util.parse_modes({"train"}) # {"train"}
m = fe.util.parse_modes({"!train"}) # {"eval", "test", "inf... | 312467ea55d3d254f7b6cd601a2e8b999539508f | 17,359 |
def endsWith(str, suffix):
"""Return true iff _str_ ends with _suffix_.
>>> endsWith('clearly', 'ly')
1
"""
return str[-len(suffix):] == suffix | 9e052562d4f6d862fe7a1c9ff34db3465fdd2152 | 17,360 |
def _patch_center(patch, orient='v'):
"""
Get coordinate of bar center
Parameters
----------
patch : matplotlib patch
orient : 'v' | 'h'
Returns
-------
center : float
"""
if orient not in 'v h'.split():
raise Exception("Orientation must be 'v' or 'h'")
if ori... | 235da0e3fdca40d62dd0313d8e8a500a7c533b8d | 17,361 |
def _identify_shade_auth():
"""Return shade credentials"""
# Note(TheJulia): A logical progression is to support a user defining
# an environment variable that triggers use of os-client-config to allow
# environment variables or clouds.yaml auth configuration. This could
# potentially be passed in ... | d7f6b403bf956ebe894b7c3e712320fbce3e866d | 17,362 |
import os
def list_dir(path):
"""
Same as os.listdir, but remove any invisible file.
"""
files = os.listdir(path)
cleaned = []
for file in files:
if not file.startswith('.'):
cleaned.append(file)
return cleaned | e2b429861284d1d41e199862caa50d43c2579d73 | 17,363 |
import hashlib
def get_sha256_of_string(the_string):
"""Returns SHA-256 hash for given string."""
new_hash = hashlib.new("sha256")
new_hash.update(bytes(the_string, "utf-8"))
return new_hash | 1657bd433e62c9342d5474fae472fc9dff649575 | 17,364 |
import re
def decamelize(s):
"""Decamelize the string ``s``.
For example, ``MyBaseClass`` will be converted to ``my_base_class``.
"""
if not isinstance(s, str):
raise TypeError('decamelize() requires a string argument')
if not s:
return ''
return re.sub(r'([a-z])([A-Z])', r... | fc30254742bcc79047dd6803d0d7b87c951a9f10 | 17,365 |
import random
import logging
def add_break(focal_gen):
"""
adding break point to contigs
"""
# selecting contig
contig = random.sample(focal_gen.keys(), 1)[0]
contig_seq = focal_gen[contig]
# selecting split location
if len(contig_seq) < 100:
focal_gen.pop(contig, None)
... | 4e5a2dea897312d25e31fcf1ca0981ca9a706604 | 17,368 |
import base64
import os
def genkey():
"""Get a random short key name"""
return base64.b64encode(os.urandom(5)).decode("utf8") | a25748fd166b2c1acf85cf210c17dd0491d0349e | 17,369 |
import uuid
def generate_uuid_32():
"""Generate a unique ID encoded in hex.
Returns
-------
str
"""
return uuid.uuid4().hex | 9d8374e6a243c4cb90db151ffa28c9464f368cba | 17,370 |
from typing import List
def get_widxs_from_chidxs(chidxs: List[int],
offsets: List[List[int]]) -> List[int]:
"""
Find word indices given character indices
:param chidxs:
:param offsets:
:return:
"""
last_ch_idx = offsets[0][0]
assert max(chidxs) < offsets[-1][... | 210a915670bf3b834e1684d4547cd80d9e855b95 | 17,371 |
def parse_ppvid(params, names, ppvids):
"""
得到ppvid组合对应的name-value(比如处理器-Intel 酷睿 i5 6代)
:param params: 存放property信息的字典
:param names: property所有的name(例如处理器,显卡)
:param ppvids: ppvid组合
:return: name-value字典
For Example: {"处理器": "Intel 酷睿 i5 6代", "显卡": "核芯/集成显卡" ...}
"""
name_to_value =... | 791f2496929415c1c3270940dba18e093b0bdbeb | 17,372 |
def find_boyer_moore(T, P):
"""Return the index of first occurance of P; otherwise, returns -1."""
n, m = len(T), len(P)
if m == 0:
return 0
last = {k: i for i, k in enumerate(P)}
i = k = m - 1
while i < n:
if T[i] == P[k]:
if k == 0:
return i
... | 76ebcc756620177b2e2a900537e9960c9e1c75e5 | 17,373 |
import random
def columns_many():
"""Simulating many columns being returned with varying numbers of entries in each"""
def _build_cols(num_items, num_cols):
col = [{} for i in range(num_items - random.randint(0, num_items))]
cols = [col for i in range(num_cols)]
# adding one more line... | 300d97a4fb30f097748a6ff27616dc0abafb8b34 | 17,374 |
def bytes_int( seq ):
"""8-bit encoded integer as sequence of 1 to 4 bytes, little-endian.
"""
shift= 0
v= 0
for b in seq:
v += b<<shift
shift += 8
return v | 116296e4d9384b547e3823c75e1bc4399787a850 | 17,375 |
def match_with_batchsize(lim, batchsize):
"""
Function used by modify_datasets below to match return the integer closest to lim
which is multiple of batchsize, i.e., lim%batchsize=0.
"""
if lim % batchsize == 0:
return lim
else:
return lim - lim % batchsize | c37226946c51144df6192adeaf265326ee3bb701 | 17,376 |
def get_function_info(func) -> dict:
"""
return:
{
'name': str func_name,
'args': ((str arg_name, str arg_type), ...),
^ [1]
'kwargs': ((str arg_name, str arg_type, any value), ...),
'has_*args': bool, # [3]
... | 0c2f05af031a0f672fb28ce7728422fd0b71182b | 17,378 |
def superset_data_db_alias() -> str:
"""The alias of the database that Superset reads data from"""
return 'superset-data-read' | c6bab8ae745f915c442145bbc7c4bcffa4141310 | 17,380 |
def _make_particle_visible_svg(text,particles,plidx):
"""
Takes svg file and makes particle visible at specified file
location.
"""
for particle in particles:
lidx = text.find("label=\"%s\""%str(particle+1),plidx)
text = text[:lidx]+text[lidx:].replace("display:none","display:inline"... | f767fa8e88647e668d3b2aba973c5759c221e35b | 17,381 |
from typing import AnyStr
def remove_until(string: AnyStr, marker: AnyStr) -> AnyStr:
"""Remove all chars in string until string starts with marker"""
while not string.startswith(marker) and string: # While don't start with marker and string not empty
string = string[1:] # Remove first char
return string | 8a408c6d350dd818f835fb04a9b55a651ef3a6e5 | 17,382 |
def _calc_bs(tp: int, fp: int, fn: int) -> float:
"""
Calculate the brier score
:param tp:
:param fp:
:param fn:
:return:
"""
return (tp + fp) / (tp + fn) | a48a6284971d50293ba35a1191af11241c257097 | 17,383 |
def shifted_ewm(series, alpha, adjust=True):
""" calculate exponential weighted mean of shifted data
series - vector
alpha - 0 < alpha < 1
"""
return series.shift().ewm(alpha=alpha, adjust=adjust).mean() | 7661e68c9ed5bbd1342a87e0d6cb45001e00005c | 17,384 |
import os
def get_config_from_env():
"""
Retrieve the api key and secret from the envoronment.
Raises:
RuntimeError: If the key or secret is not found in the environment.
Returns:
Dict: config with "api_key" and "api_secret"
"""
api_key = os.getenv("PODCAST_INDEX_API_KEY")
... | 7c81e57c9f88f35231ee89697c0521d1830e5a72 | 17,386 |
def _fully_qualified_typename(cls):
"""Returns a 'package...module.ClassName' string for the supplied class."""
return '{}.{}'.format(cls.__module__, cls.__name__) | f290a5fb3394f151476f5cf3b4785c5935e942b1 | 17,387 |
def user_prompt(prompt_string, default=None, inlist=None):
"""
Takes a prompt string, and asks user for answer
sets a default value if there is one
keeps prompting if the value isn't in inlist
splits a string list with commas into a list
"""
prompt_string = '%s [%s]: ' % (
... | 5879c8cd7853426d9c94b763292f6b04e9f26e78 | 17,388 |
import os
def check_join(root_path: str, *args) -> str:
"""
检查合并后的路径是否在root_path当中,如果超出抛出异常
:param root_path: 根路径
:param args: 路径块集合
:return: 合并后的绝对路径
"""
root_path = os.path.abspath(root_path)
result_path = os.path.abspath(os.path.join(root_path, *args))
if not result_path.star... | 717b418f78164954ce945a6ef2f1778214124d90 | 17,390 |
def orders_service(create_service_meta):
""" Orders service test instance with `event_dispatcher`
dependency mocked """
return create_service_meta('event_dispatcher') | 7c6cc11281373ff02d3e5c4c1843ab363283376a | 17,391 |
def kml_folder(name = "",contents=""):
""" return kml folders """
kmlfolder = """
<Folder>
<name>%s</name>
<visibility>1</visibility>
%s
</Folder>
"""
return kmlfolder % (name,contents) | 3529f6ec7b311fc7290ab3263d7c26a7225c667c | 17,393 |
import os
import shutil
def delete_dir(path):
"""
Deletes the specified directory if it exists. All files inside the
directory will be deleted.
:param path: Path of the directory to delete.
:return: True if the path was a directory and was deleted.
"""
if os.path.isdir(path):
sh... | 249378e3ec2c28d649a0b85434b877d656f13d19 | 17,394 |
import re
def remove_links(text):
"""
Method used to remove the occurrences of links from the text
Parameters:
-----------------
text (string): Text to clean
Returns:
-----------------
text (string): Text after removing links.
"""
# Removing all the occurrences of l... | 0bf0208459f0c93e7bac2848476959791369b5c0 | 17,395 |
def rgb_to_hsl(rgb_array):
"""!
@brief Convert rgb array [r, g, b] to hsl array [h, s, l].
@details RGB where r, g, b are in the set [0, 255].
HSL where h in the set [0, 359] and s, l in the set [0.0, 100.0].
Formula adapted from https://www.rapidtables.com/convert/color/... | 2c197b7966f5248566fdff41a62bf3f89c222c48 | 17,396 |
import argparse
def build_parser(args):
""" A method to handle argparse.
>>> args = build_parser(None)
>>> # args = Namespace(archiveonly=False, json=False, location=False, paths=[[]], verbose=True)
>>> print args.verbose
True
"""
parser = argparse.ArgumentParser(usage=... | 7cb544e216d6578bf6aaa2e25d493efdff199fa6 | 17,397 |
import hashlib
def get_hash(a_string, algorithm="md5"):
"""str => str
Return the hash of a string calculated using various algorithms.
.. code-block:: python
>>> get_hash('prova','md5')
'189bbbb00c5f1fb7fba9ad9285f193d1'
>>> get_hash('prova','sha256')
'6258a5e0eb772911... | 5ab144e1aa2e28aa6d80501c252f392cd4ec526e | 17,398 |
def print_type(calendar_lines):
"""
Function:
print_type
Description:
Sends the lsit of all event type in csv file
Input:
calendar_lines - object for csv.reader for user's calendar file
Output:
- Sends the lsit of all event types as list and string
"""
list_t... | 889c18efa21142330125b6e38f0e6b539fbca362 | 17,399 |
def logstash_processor(_, __, event_dict):
"""
Adds @version field for Logstash.
Puts event in a 'message' field.
Serializes timestamps in ISO format.
"""
if 'message' in event_dict and 'full_message' not in event_dict:
event_dict['full_message'] = event_dict['message']
event_dict['m... | f395bc7e4a7c09cdbe9ef29c3dbfdd45a448c21e | 17,400 |
def normalise_series(series):
"""Normalise a Pandas data series.
i.e. subtract the mean and divide by the standard deviation
"""
ave = series.mean()
stdev = series.std()
return (series - ave) / stdev | 97d53c0697a56e5ab559d2564c5d7386125ed254 | 17,402 |
def daxpy(n, da, dx, incx, dy, incy):
"""
*
* -- Reference BLAS level1 routine (version 3.8.0) --
* -- Reference BLAS is a software package provided by Univ. of
* Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG
* Ltd..--
* November 2017
*
"""
#* .. Scalar Ar... | 2e88028584e54b33407afacb0b939459455cfcdf | 17,403 |
def is_empty_placeholder(page, slot):
"""A template filter to determine if a placeholder is empty.
This is useful when we don't want to include any wrapper markup in our template unless
the placeholder unless it actually contains plugins.
"""
placeholder = page.placeholders.get(slot=slot)
retur... | 032f6e1d038a10e0f6c5459648dcabaf7e4c0259 | 17,404 |
import os
import re
def find_version(*relative_path_parts):
"""
Find the version string in a file relative to the current directory.
:param relative_path_parts: list of path parts relative
to the current directory where
the file containing t... | 942f76266760c9de58d63f3ceab26aed42c3b4c7 | 17,405 |
import time
def generate_genesis_block():
"""This function passes a list to merkle_tree.py that creates the root for the genesis block"""
time_stamp = time.mktime(time.strptime('11/02/2020-07:59AM', '%m/%d/%Y-%I:%M%p')) # time.mktime() generates a time_stamp in unix time.
start_timestamp = time.strftime(... | 6072df4bfdffde3ef97aa69759349208645fad5b | 17,406 |
def get_smiles_of_user_entity_ids(cursor, unification_table, user_entity_ids):
"""
Get the smiles using their BIANA user entity ids
"""
query_smiles = ("""SELECT SM.value, DB.databaseName
FROM externalEntitySMILES SM, {} U, externalEntity E, externalDatabase DB
... | d59175807dde1ad19bb14952eed360363f262992 | 17,408 |
def anti_join(df1, df2, **kwargs):
"""
Anti-joins two dataframes.
:param df1: dataframe
:param df2: dataframe
:param kwargs: keyword arguments as passed to pd.DataFrame.merge (except for 'how'). Specifically, need join keys.
:return: dataframe
"""
return df1.merge(df2, how='left', ind... | 6fdc7481da6728b51549c072879204a6c3d2bcd6 | 17,410 |
def _print_final_result_of_plugin(
plugin, compute_ids, results, out_plugins, out_plugin):
"""Print final results of plug-in.
Keyword arguments:
plugin -- plug-in name
compute_ids -- list of compute node IDs
results -- results list
out_plugins -- list of out plug-ins
out_plugin -- u... | 6ce8f6385f13c51f4775a1e2a91c2dfe72ef8723 | 17,411 |
import functools
import six
import inspect
def map_arg(**maps):
"""
Apply a mapping on certain argument before calling the original function.
Args:
maps (dict): {argument_name: map_func}
"""
def deco(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
i... | 11f74f966c60c7baeeb516da5709f1dfdac041e7 | 17,412 |
import math
def get_n(k, e, n_max):
"""
TS 38.212 section 5.3.1
"""
cl2e = math.ceil(math.log2(e))
if (e <= (9/8) * 2**(cl2e - 1)) and (k / e < 9 / 16):
n1 = cl2e - 1
else:
n1 = cl2e
r_min = 1 / 8
n2 = math.ceil(math.log2(k / r_min))
n_min = 5
n = max(min(n1, n2... | 4129821ac4c89c47d8c5b4391a77da83cfee2505 | 17,414 |
def architecture_is_64bit(arch):
"""
Check if the architecture specified in *arch* is 64-bit.
:param str arch: The value to check.
:rtype: bool
"""
return bool(arch.lower() in ('amd64', 'x86_64')) | 4303a53c3d1c8c1e844593aed3203dbedb448d61 | 17,415 |
import re
def match(text, pattern, limit = -1):
"""
Matches all or first "limit" number of occurrences of the specified pattern in the provided text
:param text: A String of characters. This is the text in which we want to find the pattern.
:param pattern: The pattern to look for. Expected to be a reg... | 656c49ebd197e538acd1c57eb4bc1daf98e5639a | 17,416 |
import os
def rootdir() -> str:
"""The root directory of the test suite."""
return os.path.dirname(os.path.abspath(__file__)) | 953df3fca8b2a277045f283484546f36e932419f | 17,418 |
import logging
def filter_data(dfs, patient_ids):
"""
Filters the given data frames to the given patient IDs.
:param List[pd.DataFrame] dfs
:param pd.Series[int] patient_ids
:rtype List[pd.DataFrame]
"""
logging.info('Filtering visit data')
results = [df.loc[df.index.intersection(... | 8ed5ee453958304cd67e17fc9a03442be6bfdec5 | 17,420 |
def _getVersionTuple(v):
"""Convert version string into a version tuple for easier comparison.
"""
return tuple(map(int, (v.split(".")))) | 57d6c1edbfb2ec66bfcc875fe511357266ffc816 | 17,421 |
def eqn9_rule(model,g,g1,d,tm,s):
""" Distribution units balance in each grid cell."""
if tm > 1 :
return model.num_dist[g,g1,d,tm,s] == model.num_dist[g,g1,d,tm-1,s] \
+ model.num_dist_invest[g,g1,d,tm,s]
else :
return model.num_dist[g,g1,d,tm,s] == model.num_dist_invest[g,g1,d,tm,s] \
... | 09cf2bb865a69f3712712974fdd8944c762537dc | 17,422 |
def to_ssml(text):
"""Adds SSML headers to string.
"""
return '<speak>'+ text + '</speak>' | 0f2fda09507e09c5fdf64d5df2e50630b26629ec | 17,424 |
def remove_headers(markdown):
"""Remove MAINTAINER and AUTHOR headers from md files."""
for header in ['# AUTHOR', '# MAINTAINER']:
if header in markdown:
markdown = markdown.replace(header, '')
return markdown | 5e25c86c72819e42d09459d77e57fa3267748797 | 17,425 |
import time
import logging
def timed_func(process_name):
"""
Adds printed time output for a function
Will print out the time the function took as well as label this output with process_name
:param process_name: human name of the process being timed
"""
def decorator(f):
def wrapper(*a... | e07c9b9a72df8b06308de0812d07428cf18af325 | 17,426 |
def is_start_byte(b: int) -> bool:
"""Check if b is a start character byte in utf8
See https://en.wikipedia.org/wiki/UTF-8
for encoding details
Args:
b (int): a utf8 byte
Returns:
bool: whether or not b is a valid starting byte
"""
# a non-start char has encoding 10xx... | 8d27198671436c4e9accd80198dfe934c43f679b | 17,427 |
def get_s3item_md5(item):
"""
A remote item's md5 may or may not be available, depending on whether or
not it was been downloaded. If a download hasn't occurred, the checksum
can be fetched using the files HTTP ETag.
"""
if item.md5 is not None:
return item.md5
else:
# Remove... | 121c2f3b5d2159e23f37a0770b54e818a7d712bd | 17,429 |
from typing import List
def list_params(pop: list, gen: int, lamarck: bool, multicore: bool,
**extra_params: dict) -> List:
"""
Internal function to list execution parameters.
For advanced users only.
Parameters
----------
pop : list
List of individuals.
gen : int... | d08629029f24a85df1adaeeb3db865c2b4a9507f | 17,430 |
import re
def isdatauri(value):
"""
Return whether or not given value is base64 encoded data URI such as an image.
If the value is base64 encoded data URI, this function returns ``True``, otherwise ``False``.
Examples::
>>> isdatauri('data:text/plain;base64,Vml2YW11cyBmZXJtZW50dW0gc2VtcGVyIH... | 43a50554c17b1fd180a9234f2a4631689f14c823 | 17,431 |
def load_inspection_page(filename):
"""Opens the output of a previously saved query result."""
if filename == 'file':
filename = 'inspection_page.html'
with open(filename) as file:
content = file.read()
return content | 86c729703dfe62570531947a31c0ad0fbf9ba297 | 17,432 |
def list_all_items_inside(_list, *items):
"""
is ALL of these items in a list?
"""
return all([x in _list for x in items]) | 5f7f2b93d966a7e7fffeede3924a7c86309ef90f | 17,433 |
import re
from datetime import datetime
def convert_to_datetime(date_str):
"""Receives a date str and convert it into a datetime object"""
date_str = re.findall(r"\s(.+)\s", date_str)[0]
return datetime.strptime(date_str, "%d %b %Y %X") | 4d5d7f54ae54c8e9b26d446755739e562d7ff9a8 | 17,434 |
def outer(x, y):
"""Compute the outer product of two one-dimensional lists and return a
two-dimensional list with the shape (length of `x`, length of `y`).
Args:
x (list): First list, treated as a column vector. 1 dimensional.
y (list): Second list, treated as a row vector. 1 dimensional.
... | 24f912d4a3152be96d8656f5a387fa526320fd19 | 17,435 |
def _get_step_inout(step):
"""Retrieve set of inputs and outputs connecting steps.
"""
inputs = []
outputs = []
assert step.inputs_record_schema["type"] == "record"
for inp in step.inputs_record_schema["fields"]:
source = inp["source"].split("#")[-1].replace("/", ".")
# Check if ... | d2cc2002792b83d01bcdb7566332c8f37c0aae99 | 17,436 |
def get_intersect_list(lst1, lst2):
"""
Find the intersection of two lists
:param lst1: List One
:param lst2: List Two
:return: A list of intersect elements in the two lists
"""
lst3 = [value for value in lst1 if value in lst2]
return lst3 | c7895c948b3a5132bd769e9320e40139c8aac3ad | 17,437 |
def _choose_mtx_rep(adata, use_raw=False, layer=None):
"""Get gene expression from anndata depending on use_raw and layer"""
is_layer = layer is not None
if use_raw and is_layer:
raise ValueError(
"Cannot use expression from both layer and raw. You provided:"
f"'use_raw={use_... | 0998c0c74b0d9e97f4cf2485d6039f0475f9541c | 17,438 |
def count_unauth_purchases(request):
"""
Count number of recipes in a shoplist of an unauthorized user.
"""
user_ip = request.META['REMOTE_ADDR']
if request.session.get(user_ip):
return len(list(set(request.session[user_ip])))
return 0 | ec590cd823188699d1dad212ae343647e98c1494 | 17,439 |
import uuid
def is_uuid(u):
"""validator for plumbum prompt"""
if isinstance(u, str) and u.replace('-', '') == uuid.UUID(u).hex:
return u
return False | e71392315625f081172c47102415fbdabe6429cd | 17,440 |
import re
def get_urls(filename):
"""
Returns a sorted list of puzzle URLs from the given log file. The hostname
comes from the filename and puzzle URLs contain the word puzzle. If a URL is
duplicated, then we only include it once.
"""
under_index = filename.find("_")
log_index = filename.... | fd3da48638b398777c60af51db2fb46ea6dffcd5 | 17,441 |
def distribute(x, values, level):
"""Distribute elements in values on nth level of nested lists.
This creates an additional nested level of lists.
Exemple:
distribute([[[1,2], [1,3]], [[2,2]]], ['a', 'b'], 2)
--> [[
[[1,2,'a'], [1,2,'b']],
[[1,3,'a'], [1,3,'b']]
... | 0584af83a7c928552e6b560dbfab11115064e7ac | 17,444 |
import re
def normalize_layout_string(layout_string):
"""normalize a layout string such that it is characterwise identical
to the output of the 'dump' command
"""
layout_string = layout_string.replace('\n', ' ')
# drop multiple whitespace
layout_string = re.sub(r'[ ]+', ' ', layout_string)
... | e333603a21edcc52a5a648c1850d976210869d12 | 17,445 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.