content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def effective_stiffness_from_base_shear(v_base, disp):
"""
Calculates the effective stiffness based on the base shear and displacement.
Typically used in displacement based assessment
:return:
"""
return v_base / disp | a6b48e4dc970c19d0cab3d3c798633512ca62d9a | 17,028 |
def expand_box(box, img_shape, scale=None, padding=None):
"""Expand roi box
Parameters
----------
box : list
[x, y, w, h] order.
img_shape : list
[width, height]
scale : float, optional
Expand roi by scale, by default None
padding : int, optional
Expand roi b... | 3fd9c97b8baa70a89b898d3e9d14e8c930d0045e | 17,029 |
def parse_by_prefix(input_string, prefix, end_char=[" "]):
"""searches through input_string until it finds the prefix. Returns
everything in the string between prefix and the next instance of
end_char"""
start = input_string.find(prefix) + len(prefix)
end = start
while input_string[end] not in... | 8cc80c9c359ae155ed4f8f197c1e9bd604cebf1d | 17,030 |
import logging
def reformat(response_query):
"""
Reformats elasticsearch query to remove extra information
"""
data = list()
for hit in response_query["hits"]["hits"]:
data.append(
{
"id": hit["_id"],
"source_url": hit["_source"]["post_url"],
... | 87ae38ce28953498bac9839e537a09ed07a106ab | 17,033 |
import yaml
def load_config():
""" Load config data from config.yaml """
with open("config.yaml", 'r') as stream:
try:
return yaml.safe_load(stream)
except yaml.YAMLError as exc:
print(exc) | 48d67ddb0049ef06827ac2de042fc9e48c4c02f4 | 17,034 |
def starrating(key):
"""Convert the A|B|C|X|L reliability rating to an image"""
ratings = {"A": u"★★★",
"B": u"★★",
"C": u"★",
"X": "X",
"L": "L"}
return ratings[key] | 4ef9f4fdafe46ca639e26267f478e0d775785453 | 17,035 |
import argparse
def _parse_args():
"""Parse Command Arguments."""
desc = 'Download SmugMug galleries'
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('download_url',
help='SmugMug galleries URL')
return parser.parse_args() | a8057f9f76b70d390fab0fb0cb802b71b2faea1e | 17,036 |
def FindPosition(point, points):
"""Determines the position of point in the vector points"""
if point < points[0]:
return -1
for i in range(len(points) - 1):
if point < points[i + 1]:
return i
return len(points) | 11ccabcade65053ccfa6751813d90a0eeaccc339 | 17,040 |
def rm_url_parts (url, remove):
"""Dynamically get the url <remove> steps before the original url"""
parts = url.split("/")
for x in range(0, remove):
del parts[-1]
url = '/'.join(map(str, parts))
return url | e569144b01770ddbb703062bfac9ff908a35c589 | 17,041 |
import requests
def package_info(package_url):
"""Return latest package version from PyPI (as JSON)."""
return requests.get(package_url).json().get('info') | cba261a0649eed30329fd479e018fba11e96d022 | 17,043 |
def check_digit10(firstninedigits):
"""Check sum ISBN-10."""
# minimum checks
if len(firstninedigits) != 9:
return None
try:
int(firstninedigits)
except Exception: # pragma: no cover
return None
# checksum
val = sum(
(i + 2) * int(x) for i, x in enumerate(rev... | 33d8da015a471e5e9f29eb4c9b2b0173979d8130 | 17,044 |
import os
def construct_makeblastdb_cmd(infile, outdir, blastdb_exe):
"""Returns a tuple of (cmd_line, filestem) where cmd_line is the BLAST
database formatting command for the passed filename, placing the result
in outdir, with the same filestem as the input filename.
The formatting assumes that the... | 79039720c175644a5332763a5e6f5979f2cb3610 | 17,045 |
def _load_captions(captions_file):
"""Loads flickr8k captions.
Args:
captions_file: txt file containing caption annotations in
'<image file name>#<0-4> <caption>' format
Returns:
A dict of image filename to captions.
"""
f_captions = open(captions_file, 'rb')
captions = f_captions.read().deco... | 89a00a5befe1162eda3918b7b6d63046fccd4c70 | 17,046 |
from typing import List
def text_to_bits(
text: str,
encoding: str = "utf-8",
errors: str = "surrogatepass",
) -> List[int]:
"""
Takes a string and returns it's binary representation.
Parameters
----------
text: str
Any string.
Returns
-------
A list of 0s and 1s.... | cc9ab6497ab3b797625016176b74a6660ed59a80 | 17,047 |
def get_the_written_file_list(writefile_cursor):
"""Return the written files (W)."""
written_files_query = '''
SELECT process, name, mode
FROM opened_files
WHERE mode == 2
'''
writefile_cursor.execute(written_files_query)
return writefile_cursor.fetchall() | 8abe57fd88d569d5cf48b13dfbcfc142fa6c1504 | 17,049 |
import os
def files(path):
"""
Gets the list of all the files
Args:
path (str): Path to the folder
Returns:
list: list of all the files
"""
files_list=[]
for root, dirs, files in os.walk(path):
for filename in files:
files_list.append(filename)
ret... | 5f9ed867df47156e9bcea194e49892cd43f677ca | 17,050 |
def final_nonzero(L):
"""
Return the index of the last non-zero value in the list.
"""
for index, val in reversed(list(enumerate(L))):
if val:
return(index)
return(0) | 1064987732146a9f6c12a2cab1dc84d2657fa321 | 17,052 |
from typing import Optional
import os
def directory(root: Optional[str], name: Optional[str]) -> str:
"""Handle name of directory."""
if name is None or not os.path.isdir(name):
name = os.getcwd()
result = os.path.abspath(name)
if root is not None:
if not result.startswith(root):
... | f0f2ec97241084a7aeec999389f3fcc57a19f251 | 17,053 |
def points_to_string(points):
""" Returns legacy format supported by Insight """
points = ["%s,%s" % (p[0], p[1]) for p in points]
csv = ", ".join(points)
return "points[%s] points1[%s] points2[%s]" % (csv, csv, csv) | 4588393ee05ddc03cb24e9638abce756521177a2 | 17,054 |
def pattern_count(text: str, pattern: str) -> int:
"""Count the number of occurences of a pattern within text
Arguments:
text {str} -- text to count pattern in
pattern {str} -- pattern to be counted within text
Returns:
int -- The number of occurences of pattern in the test
... | e6fcd2f0645141a3ddf211facb49058deb6dc1fd | 17,055 |
import time
def timestamp():
"""
The current epoch timestamp in milliseconds as a string.
Returns:
The timestamp
"""
return str(int(time.time() * 1000)) | 2d1d6bc545f5b45d5a16a636837f63d85d681a1f | 17,056 |
def expand_dates(df, columns=[]):
"""
generate year, month, day features from specified date features
"""
columns = df.columns.intersection(columns)
df2 = df.reindex(columns=set(df.columns).difference(columns))
for column in columns:
df2[column + '_year'] = df[column].apply(lambda x: x.y... | ea07a26a271f8d9be05858392e51ec28c851efdc | 17,057 |
import os
def get_stat_result(input_stat):
"""
Wrapper for os-specific stat_result instance.
Args:
input_stat (stat_result or stat_result): instance you'd like to clone.
Returns:
nt.stat_result or posix.stat_result, dependent on system platform.
"""
if os.name == "posix":
... | 90cfd2015ea8a3fce9280e4a42391be866a77794 | 17,059 |
def unquote(text):
"""Unqoute the text from ' and "
text: str - text to be unquoted
return text: str - unquoted text
>>> unquote('dfhreh')
'dfhreh'
>>> unquote('"dfhreh"')
'dfhreh'
>>> unquote('"df \\'rtj\\'"') == "df 'rtj'"
True
>>> unquote('"df" x "a"')
'"df" x "a"'
>>> unquote("'df' 'rtj'") == "'df... | 68f3498b5224e76e961d3f5e7570fc09ca334034 | 17,062 |
import re
def omit_url(text):
"""
URLを省略する
:param text: オリジナルのテキスト
:return: URLの省略したテキスト
"""
pattern = r'https?://[\w/:%#\$&\?\(\)~\.=\+\-]+'
return re.sub(pattern, 'URL省略', text) | 2d1a9b4be2aead8fef2f59dba6847b886a7ae313 | 17,064 |
import inspect
import sys
def get_all():
""" Returns a list of all aggregator classes """
temp = inspect.getmembers(sys.modules[__name__], inspect.isclass)
return [i[1] for i in temp if i[0] != "Aggregator"] | a25859ffe4871790d27e02c0c77af1244ba115d8 | 17,066 |
def _Divide(x, y):
"""Divides with float division, or returns infinity if denominator is 0."""
if y == 0:
return float('inf')
return float(x) / y | dee5ef0c4160c45ee9c8ee6aee651d60c3e70252 | 17,067 |
def get_results(m):
"""
Extract model results as dict
Parameters
----------
m : Pyomo model instance
Model instance containing solution (post-solve)
Returns
-------
results : dict
Dictionary containing model results
"""
results = {
"x": m.x.value,
... | 1dcb35bac7fe2379b096bb2fd838ed53a7ebaca4 | 17,068 |
import string
def AsciiUpper(N):
""" ascii uppercase letters """
return string.ascii_uppercase[:N] | aa62357ebe821dd4b6f359a22269916e64d29414 | 17,069 |
def check_do_touch(board_info):
"""."""
do_touch = False
bootloader_file = board_info.get('bootloader.file', '')
if 'caterina' in bootloader_file.lower():
do_touch = True
elif board_info.get('upload.use_1200bps_touch') == 'true':
do_touch = True
return do_touch | 39683a63ed2aac3624176e340825180424aa5f46 | 17,072 |
def get_weight(op, return_name=True):
""" get the weight of operators with weight."""
for inp in op.all_inputs():
if inp._var.persistable == True:
if return_name:
return inp.name()
else:
return inp | 01f5df2c93d1b8b84c1f51c9e2c6ff75b9f54c78 | 17,073 |
def get_number_coluna(janela, chuva_height):
"""Determina o numero de linhas com gotas que cabem na tela."""
availble_space_y = (janela[1] - (3 * chuva_height))
number_coluna = int(availble_space_y / (2 * chuva_height))
return number_coluna | a41c2ae23da33149c88a507cf900b9f8e2772622 | 17,074 |
import argparse
import os
def parse_arguments() -> argparse.Namespace:
"""
Parse arguments for TNT-based implied weighting branch support
Args: None
Example:
$ python ./pyiwe_runner.py
:return: argparse.Namespace
"""
parser = argparse.ArgumentParser(description='Argument parser... | 722e4304b41890af00276e8869895f1a9d90248e | 17,078 |
import torch
def sample_indices(length, proportion, generator=None, seed=None):
"""Vector indices to select ``proportion`` from a batch of size ``length``."""
if generator is None:
generator = torch.Generator()
if seed is not None:
generator = generator.manual_seed(seed)
subset... | 2a622365d2a7eb36d00a8f19fcc7448905e599fa | 17,079 |
def _readSatCatLine(line):
"""Returns the name, international designator (id), nad NORAD catalog number
(catNum) from a line in the satellite catalog.
"""
name = line[23:47].strip()
id = line[0:11].strip()
catNum = line[13:18].strip()
return name, id, catNum | 7d30ab9836f30cb7c10285ad86ca70cad7965b9c | 17,082 |
import base64
def load_image(img_path):
"""Load an image from a path"""
with open(img_path, "rb") as f:
img_bytes = f.read()
return base64.b64encode(img_bytes).decode("utf8") | 5eb56ac5e3a844481fe0975dc18500ee990f62be | 17,083 |
def n_glass(wavelength_in_nm):
"""for better data see refractive_index.py .. but this is what I'm using in
lumerical and lua, and I want to be consistent sometimes"""
data = {450: 1.466,
500: 1.462,
525: 1.461,
550: 1.46,
575: 1.459,
580: 1.459,
... | 92106735d74776402407539e99ea48d9744ca6f9 | 17,085 |
def test_accuracy(reference_src, reference_tar, aligned_src, aligned_tar, penalty_points=None):
"""
Tests aligned lists of strings against reference lists, typically hand aligned.
Args:
reference_src: list of reference source strings
reference_tar: list of reference target strings
al... | c220f9d9aa04adfdb6fa07231c9913505d54ef8d | 17,086 |
def apply_color_reduction(bgr_img):
"""減色処理を適用します。
Arguments:
bgr_img {numpy.ndarray} -- BGR画像(3ch)
Returns:
numpy.ndarray -- 処理後のBGR画像(3ch)
Notes:
入力はRGB画像でも正常に動作します。
"""
out_img = bgr_img.copy()
out_img[(0 <= out_img) & (out_img < 63)] = 32
out_img[(63 <= ou... | 55cb5cfb207e9e2f9c7f7a94f9ef8d690a8d247f | 17,087 |
def ensure_value(namespace, dest, default):
""" Thanks to https://stackoverflow.com/a/29335524/6592473 """
stored = getattr(namespace, dest, None)
if stored is None:
return default
return stored | 5f9d43131366592c0ec71913c814da41ff5c56ea | 17,088 |
def http(server):
"""Test client.
Usage:
with http as c:
response = c.get(uri)
print response.parsed_data
"""
client = server.test_client()
return client | 11ebc0ad1c4541f76270166cf82a110483d4a4d6 | 17,089 |
def _argsort(it, **kwargs):
"""
Renvoie une version triée de l'itérable `it`, ainsi que les indices
correspondants au tri.
Paramètres :
------------
- it : itérable
- kwargs
Mots-clés et valeurs utilisables avec la fonction built-in `sorted`.
Résultats :
-----------
- i... | f36e0ac863c3861ba7f1e222ac3712c977364d98 | 17,090 |
from typing import List
import re
def solution(raw: str, markers: List[str]) -> str:
"""Remove all comments from raw string as indicated by markers."""
return '\n'.join(
[re.split(r'|'.join(map(re.escape, markers)), line)[0].strip() for line in raw.split('\n')]) if markers else raw | 1b8a5b38e57d5700958dbaa9340c0c4ec93e6062 | 17,091 |
import torch
def retrieval_eval_collate(data):
"""Creates mini-batch tensors from the list of tuples (src_seq, trg_seq)."""
# separate source and target sequences
text, text_length,segmentt_ids,img, img_loc, _label = list(zip(*data))
_inputs = [torch.stack(text,dim=0),torch.stack(text_length,dim=0),t... | f3ebd19ab458b48f4c2339d2a4c7d179193f9a6a | 17,092 |
def extractdistinct(df_wide):
"""Extract and reformat to standard form for disinct point set"""
df1_distincttemp = df_wide[df_wide['DistinctRoute?'] == True]
# df1_distinct = df1_distinct.drop([x for x in df1_distinct if x.endswith('_base')], 1)
df1_distinct = df1_distincttemp.reset_index(drop=True)
... | 5fe537d1e4f3f30716c58eab147ea85be01c3f33 | 17,093 |
def check_tag_legality(tags):
"""
检查标签列表合法性: 标签id域,是否重复,父子关系
:param tags: list 标签配置列表
:return: boolean 是否合法
"""
max_id = 0
tag_code_set = set()
tag_relation_dict = dict()
for tag_item in tags:
tag_id = str(tag_item["id"])
tag_code = str(tag_item["code"])
pare... | 0094d772c5bc0967e8b7a5f3db5a28bd7d7f64b1 | 17,095 |
def _create_postgres_url(db_user, db_password, db_name, db_host,
db_port=5432, db_ssl_mode=None,
db_root_cert=None):
"""Helper function to construct the URL connection string
Args:
db_user: (string): the username to connect to the Postgres
D... | f617f7f85545fcf2a1f60db8c9c43e0209c32c4f | 17,096 |
import json
def json_format(obj):
"""Formatter that formats as JSON"""
return json.dumps(obj, ensure_ascii=False) | 1cfc2d46499dfe3a8bbd5db60200fadf9ccf0551 | 17,097 |
def to_case_fold(word: str):
"""
The casefold() method is an aggressive lower() method which
convert strings to casefolded strings for caseless matching.
The casefold() method is removes all case distinctions
present in a string. It is used for caseless matching
(i.e. ignores cases when comparin... | c917ab8661859ae29d8abecd9a7663b0b5112a63 | 17,099 |
import torch
def predict_raw(loader, model):
"""Compute the raw output of the neural network model for the given data.
Arguments
----------
loader : pyTorch DataLoader instance
An instance of DataLoader class that supplies the data.
model: subclass instance of pyTorch nn.Module
... | cb812c0792629c46d5774d9f1f4090369e047b78 | 17,100 |
import json
def _load_probably_json_substring(x):
"""
Weak method of extracting JSON object from a string which includes JSON and
non-JSON data. Just gets the largest substring from { to }
Works well for these cases, where click.CliRunner gives us output
containing both stderr and stdout.
"""
... | fd701cb47d1ca40422de8c3424b8c6dce93ae540 | 17,101 |
def funql_template_fn(target):
"""Simply returns target since entities are already anonymized in targets."""
return target | a5f95bd6b7feabb4826fff826e6638cd242e04d6 | 17,102 |
import torch
def to_tensor(im, dims=3):
""" Converts a given ndarray image to torch tensor image.
Args:
im: ndarray image (height x width x channel x [sample]).
dims: dimension number of the given image. If dims = 3, the image should
be in (height x width x channel) format; while if dims = 4, the i... | d19a0c0104f4dc9401f70235cadb7266ffd01332 | 17,103 |
def _get_size_verifier(min_x, min_y, mode):
"""
Depending on what the user wants, we need to filter image sizes differently.
This function generates the filter according to the user's wishes.
:param min_x: Minimal x-coordinate length of image.
:param min_y: Minimal y-coordinate length of image.
... | 86919399a94caa60ff780ccf5959fe2d43d6d2eb | 17,104 |
import json
def check_engine_op(op):
"""Check Engine API transaction.
"""
if op is not None and "logs" in op:
logs = json.loads(op["logs"])
if isinstance(logs, str):
logs = json.loads(logs)
if "errors" not in logs:
return True
elif logs["errors"] == ... | e33960687dd5015bc0dcaf345aab36204e7e53af | 17,105 |
import itertools
def pdist_list(rings, node_sim):
"""
Defines the block creation using a list of rings at the graph level (should also ultimately include trees)
Creates a SIMILARITY matrix.
:param rings: a list of rings, dictionnaries {node : (nodelist, edgelist)}
:param node_sim: the pairwise nod... | 7ee0e9817c048ad5f1cf7e08ae9d980408c788c9 | 17,107 |
def format_values(data):
""" Convert the data elements to their values """
for key, value in data.items():
for i in range(len(value)):
data[key][i] = float(value[i].strip().split()[0])
return data | caed50b7b6a86be19d358405260c45eb9cf02105 | 17,108 |
from typing import Tuple
from typing import Optional
from typing import List
import argparse
def parse_args(args) -> Tuple[Optional[str], Optional[int], Optional[str], bool, List[str], Optional[str]]:
"""
Parse command line arguments:
param: args: in form of --arg=value
--path, optional, is the path o... | 9efc626ecc3c8ad0a94bfa3b3fb3ac69b31d8b5e | 17,109 |
def campbell_1d_az(Fs, z_, zlu, theta_s, psi_s, b, sd):
"""Soil moisture profile from Campbell function and microtopography
See equations 4 and 5 in Dettmann & Bechtold 2015, Hydrological
Processes
"""
# PEATCLSM microtopographic distribution
if ((zlu - z_) * 100) >= (psi_s * 100):
the... | 5a22998c3277d69e0bdfdaa676f66c803b93386b | 17,111 |
import random
def weighted(objs, key='weight', generator=random.randint):
"""Perform a weighted select given a list of objects.
:param objs: a list of objects containing at least the field `key`
:type objs: [dict]
:param key: the field in each obj that corresponds to weight
:type key: str
:pa... | ea8b0ada198ae26a7ac54092c10a11daba3d18e0 | 17,112 |
def get_parameter_list_from_parameter_dict(pd):
"""Takes a dictionary which contains key value pairs for model parameters and converts it into a list of
parameters that can be used as an input to an optimizer.
:param pd: parameter dictionary
:return: list of parameters
"""
pl = []
for key i... | 38ab987fd2959c789f69a804f27e30bc86c7279b | 17,113 |
def all_accept_criteria(candidate_paraphrases, **kargs):
"""Always accept proposed words.
"""
return candidate_paraphrases, None | 745459e4fc432f666b2c763baafb69ea19a6181c | 17,114 |
import torch
def gpu_check(self):
"""[Check if GPU is available]
Returns:
[obj]: [torch.cuda.is_available()]
"""
train_on_gpu = torch.cuda.is_available()
if not train_on_gpu:
print('CUDA is not available. Training on CPU ...')
else:
print('CUDA is available! ... | 42b6b1b256c7c30239bf2ee9b40431a710827ad2 | 17,116 |
import string
def camel_to_underscore(name):
""" convert a camel case string to snake case
"""
for char in string.ascii_uppercase:
name = name.replace(char, '_{0}'.format(char))
return name.lower() | db88bd3938073ec65e58344ba7228c75fef646a5 | 17,118 |
import inspect
def get_signature(obj):
"""
Get signature of module/class/routine
Returns:
A string signature
"""
name = obj.__name__
if inspect.isclass(obj):
if hasattr(obj, "__init__"):
signature = str(inspect.signature(obj.__init__))
return "class %s%... | 9da9d7e431783b89a5e65b4940b118cd5538799c | 17,119 |
def abs(x):
"""
Computes the absolute value of a complex-valued input tensor (x).
"""
assert x.size(-1) == 2
return (x ** 2).sum(dim=-1).sqrt() | 3b3a23873923597767c35eb4b5f6da1bb054705b | 17,121 |
def gcd_looping_with_divrem(m, n):
"""
Computes the greatest common divisor of two numbers by getting remainder from division in a
loop.
:param int m: First number.
:param int n: Second number.
:returns: GCD as a number.
"""
while n != 0:
m, n = n, m % n
return m | 5b50692baa396d0e311b10f2858a1278a9366d09 | 17,122 |
def _round_bits(n: int, radix_bits: int) -> int:
"""Get the number of `radix_bits`-sized digits required to store a `n`-bit value."""
return (n + radix_bits - 1) // radix_bits | 3e03385ee69f28b11e63885a80af48faa337697a | 17,123 |
import subprocess
import json
def execute_command(*cmd: str, parse_json=False):
"""Execute a command.
Args:
*cmd (str): Parts of the command.
parse_json (bool, optional): Parse the output as JSON. Defaults to
`False`.
Returns:
str or dict: Output of command.
"""
... | 8a8882982de323093b6e62bac8d4f74ccb39dddc | 17,125 |
def format_scrub_warning(warning):
"""This function takes an internal representation of a warning and converts it into a SCRUB-formatted string.
Inputs:
- warning: Dictionary of finding data [dict]
Outputs:
- scrub_warning: SCRUB-formatted warning that can be written to the output file [st... | 3ec720da1f3a1aba8ecf605dc848636479ec5415 | 17,126 |
import functools
def ignores(exc_type, returns, when=None):
"""Ignores exception thrown by decorated function.
When the specified exception is raised by the decorated function,
the value 'returns' is returned instead.
The exceptions to catch can further be limited by providing a predicate
which ... | 0c839c73218124fb988cea95fb5ee73abe7d5833 | 17,127 |
def build_hsts_header(config):
"""Returns HSTS Header value."""
value = 'max-age={0}'.format(config.max_age)
if config.include_subdomains:
value += '; includeSubDomains'
if config.preload:
value += '; preload'
return value | 9f94d87b1949f5c9e2f898466a8f5191f2327357 | 17,128 |
def validates(*names):
"""Decorate a method as a 'validator' for one or more named properties.
Designates a method as a validator, a method which receives the
name of the attribute as well as a value to be assigned, or in the
case of a collection to be added to the collection. The function
can the... | 2ff6856aba142383c53f52b057f5ccbd1b682ebb | 17,130 |
def argv_to_module_arg_lists(args):
"""Converts module ldflags from argv format to per-module lists.
Flags are passed to us in the following format:
['global flag', '--module', 'flag1', 'flag2', '--module', 'flag 3']
These should be returned as a list for the global flags and a list of
per-mod... | 847597d09e56af4221792a9a176bddfea334e622 | 17,132 |
import os
import yaml
def get_species_categories(
benchmark_type="FullChemBenchmark"
):
"""
Returns the list of benchmark categories that each species
belongs to. This determines which PDF files will contain the
plots for the various species.
Args:
benchmark_type: str
... | 8e8111f9d232abaef8e2fbda70ccfaad241ffc5e | 17,134 |
import hashlib
def sha256(s: str) -> str:
"""
>>> sha256('abc')
'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'
"""
return hashlib.sha256(s.encode("utf8")).hexdigest() | 9bf815261c785e2061ae067b3dfa6cd3368d8f9a | 17,135 |
def cubic_equation(b):
"""Algebraic Cubic Equations"""
return lambda x : x**3 - x + b | 6248d2b8fee59d860268d7d49a4e30c49f658214 | 17,136 |
def undo(rovar):
"""Translates rovarspraket into english"""
for low, upper in zip("bcdfghjklmnpqrstvwxyz", "BCDFGHJKLMNPQRSTVWXYZ"):
rovar = f"{upper}".join(f"{low}".join(rovar.split(f"{low}o{low}")).split(f"{upper}o{low}"))
return rovar | 451560539f7e98bc1fc89c712fa9026b48ecac4a | 17,137 |
def tet_clean(s):
"""
Original code from Leighton Pritchard, leighton.pritchard@hutton.ac.uk
redistributed and modified it under the terms of the GNU General
Public License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
Ch... | 9ee39039459815da2619dbee19a0514b107a74a4 | 17,139 |
import time
def get_template_s3_resource_path(prefix, template_name, include_timestamp=True):
"""
Constructs s3 resource path for provided template name
:param prefix: S3 base path (marts after url port and hostname)
:param template_name: File name minus '.template' suffix and any timestamp portion
... | 61f1ef829cbe83e1032dd5995cedf33a4809f787 | 17,140 |
def med_all_odd(a):
"""Takes in a non-empty list of integers and returns True if all values are odd in the list."""
return all(x % 2 == 1 for x in a) | a7210b097798f2b4303a16ce02a79811e8c8ceef | 17,142 |
def index():
"""
get home page, you can define your own templates
:return:
"""
return '<h2>Welcome to Proxy Pool System</h2>' | a8d54f565198f8c12fc67658bb3e9223f9922447 | 17,144 |
import torch
def adj_to_seq(adj, device='cpu'):
"""
Convert a dense adjacency matrix into a sequence.
Parameters
----------
adj : torch.Tensor
The dense adjacency tensor.
device : str, optional
The device onto which to put the data. The default is 'cpu'.
Returns
-----... | 6b967962d5ba61a0ad45d5197ca23a7278fccca9 | 17,145 |
def combinations(c, d):
"""
Compute all combinations possible between c and d and their derived values.
"""
c_list = [c-0.1, c, c+0.1]
d_list = [d-0.1, d, d+0.1]
possibilities = []
for cl in c_list:
for dl in d_list:
possibilities.append([cl, dl])
return possibilities | 28d1c0f8d7ef9ad59cadbbf8141b73decd2d9f94 | 17,147 |
import argparse
import ast
def parse_args():
"""PARAMETERS"""
parser = argparse.ArgumentParser('MindSpore PointNet++ Eval Configurations.')
parser.add_argument('--batch_size', type=int, default=24, help='batch size in training')
parser.add_argument('--data_path', type=str, default='../data/modelnet40_... | 83cdcf29b09b7846d6ebf0277896a37b7b73a4f4 | 17,148 |
import os
def get_stem(path: str) -> str:
"""Get the stem from the given path."""
basename = os.path.basename(path)
stem, _ = os.path.splitext(basename)
return stem | 7c520c491c5061508758b5c32b10277d1d1858ff | 17,149 |
import os
def upload_to_do(files, args, logger):
"""
:param files: a list of local file paths
:param args: original command line arguments passed to pygest executable
:param logger: a python logger object
:return: 0 on success
"""
# The --upload cmdline argument is --upload do bucket-nam... | 9604a9d1ef0fdf75aab3a6ad3a0088d5363fdab4 | 17,150 |
def makeUnique(list):
""" Removes duplicates from a list. """
u = []
for l in list:
if not l in u:
u.append(l)
return u | 02834bf5633c82f5f7428c03519ca68bee8916d4 | 17,151 |
def sample_labels(model, wkrs, imgs):
"""
Generate a full labeling by workers given worker and image parameters.
Input:
- `model`: model instance to use for sampling parameters and labels.
- `wkrs`: list of worker parameters.
- `imgs`: list of image parameters.
Output:
1. list ... | 1abd2d0d087f7ce452db7c899f753366b148e9e6 | 17,152 |
from typing import List
def get_balanced_grouping_allocation(
w: int, min_value: int, max_value: int
) -> List[int]:
"""
This algorithm is much less costly in terms of time complexity, but
will result in less randomness. It will always prefer the balanced
or nearly-balanced group configuration, wh... | 9171b5c1c6759a08fc799ca9073cd3a2ee22b6b4 | 17,153 |
def all_equal(lst):
"""
Returns True if all elements of lst are the same, False otherwise
ex.
all_equal(['S,'S','S']) returns True
"""
return len(set(lst)) == 1 | 221f90cb763f35ddde3fa0a3e33cb03c9dfae0bc | 17,154 |
import zipfile
import re
import os
def zipfile_to_dictionary(filename):
"""
Takes in a zip file and returns a dictionary with the filenames
as keys and file objects as values
Inputs: ::\n
file: the concerned zip file
Outputs: ::\n
result: the returned dictionary
"""
zf = ... | 04a105618e272e77c62221a4a009fe14a013ad05 | 17,155 |
def default_state_progress_report(n_steps, found_states, all_states,
timestep=None):
"""
Default progress reporter for VisitAllStatesEnsemble.
Note that it is assumed that all states have been named.
Parameters
----------
n_steps : int
number of MD fra... | b0f740d18218dd9542704d03edcd4b6575a2c14e | 17,159 |
import pandas
def integrate(s1, s2):
"""Integrate two records of feature subsets.
Parameters
----------
s1 : pandas.Series
First records.
s2 : pandas.Series
Second records.
Returns
-------
pandas.Series
Integrated records.
Examples
--------
>>> s1... | 34fd3bfdea613b09a4fdc6054de35a755656c01e | 17,160 |
import collections
def mut_type(WT, A, T, G, C):
""" returns number of each type of mutation as columns
Used on one sequence position at a time so only one of the four wtNT
will not be 0 for an individual function call, but combining all outputs
for all sequence positions gives the total number of eac... | de3e5e99c11d8f86047c667a6f51eaee0522c5ff | 17,161 |
def childrenList(cursor,cd_tax):
"""
Retrieve all the children of a taxon in the database
Parameters:
----------
cursor: Psycopg2 cursor
cursor for the database connection
cd_tax: Int
idenfier of the taxon for which we search the children taxa
Returns:
-------
all_c... | ca50ac590674d19321144f77b54ec57d8dd49bb4 | 17,162 |
def path_sum(root, target_sum):
"""
Given a binary tree and a sum, determine if the tree has
a root-to-leaf path such that adding up all the values along
the path equals the given sum.
"""
def is_leaf(node):
return node.left is None and node.right is None
def leaf_nodes(node, paren... | 0971227d42abb3a0cde1c9050dcca39731858679 | 17,164 |
def IsAioNode(tag):
"""Returns True iff tag represents an AIO node."""
return tag.startswith('aio_nodes.') | 6603f4bca75a463ca651b44615a11c3dd29ca487 | 17,168 |
import re
def regex_from_rule(rule):
"""为一个 rule 生成对应的正则表达式
>>> regex_from_rule('/<provider>/songs')
re.compile('^/(?P<provider>[^\\\/]+)/songs$')
"""
kwargs_regex = re.compile(r'(<.*?>)')
pattern = re.sub(
kwargs_regex,
lambda m: '(?P<{}>[^\/]+)'.format(m.group(0)[1:-1]),
... | dcc90a75875f80271da7333c1f378ff81b9aaf0b | 17,169 |
def _parse_name(wot_identifier):
"""
Parse identifier of the forms: nick
nick@key
@key
:Return: nick, key. If a part is not given return an empty string for it.
>>> _parse_name("BabcomTest@123")
('BabcomTest', '123')
"""
... | 7a33f5247e345175bad92fc8bf040eddc8b65804 | 17,171 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.