content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
import re
def get_puppetfile_tags(puppetfile):
"""
obtain tags from Puppetfile
:return: tuple(list, list)
"""
regex_vcs = re.compile(r"^:(git|svn)\s+=>\s+['\"](.+)['\"]\,", re.I)
regex_tag = re.compile(r"^:(ref|tag|commit|branch)\s+=>\s+['\"](.+)['\"]\,?", re.I)
vcss = []
tags = []
... | 6beec37d4c8a3a3b9a2c845cea0f5e12e18af620 | 6,147 |
def organize_array_by_rows(unformatted_array, num_cols):
"""Take unformatted array and make grid array"""
num_rows = int(len(unformatted_array) / num_cols)
array = []
for row in range(num_rows):
array.append(unformatted_array[row * num_cols:(row + 1) * num_cols])
return array | 8a7d74ea593bfcc5c4d3a92d1c192b2bf628f641 | 6,148 |
def infer(model, text_sequences, input_lengths):
"""
An inference hook for pretrained synthesizers
Arguments
---------
model: Tacotron2
the tacotron model
text_sequences: torch.Tensor
encoded text sequences
input_lengths: torch.Tensor
input lengths
Returns
-... | e7937395956e2dcd35dd86bc23599fbb63417c22 | 6,149 |
def other_language_code():
"""Language code used for testing, currently not set by user."""
return 'de-DE' | 2cbac23cd7a13e71991be6516a3a38dee19ae690 | 6,151 |
def _is_course_or_run_deleted(title):
"""
Returns True if '[delete]', 'delete ' (note the ending space character)
exists in a course's title or if the course title equals 'delete' for the
purpose of skipping the course
Args:
title (str): The course.title of the course
Returns:
... | c32c69e15fafbc899048b89ab8199f653d59e7a8 | 6,156 |
from typing import OrderedDict
def map_constructor(loader, node):
"""
Constructs a map using OrderedDict.
:param loader: YAML loader
:param node: YAML node
:return: OrderedDictionary data
"""
loader.flatten_mapping(node)
return OrderedDict(loader.construct_pairs(node)) | 21bf92d0c3975758ae434026fae3f54736b7f21d | 6,157 |
def quadratic_bezier(t, p0, p1, p2):
"""
:return: Quadratic bezier formular according to https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Quadratic_B%C3%A9zier_curves
"""
return (1 - t) * ((1 - t) * p0 + t * p1) + t * ((1 - t) * p1 + t * p2) | ac9319683afb5b156ac40ba24865d9bc04531917 | 6,159 |
def usage_percentage(usage, limit):
"""Usage percentage."""
if limit == 0:
return ""
return "({:.0%})".format(usage / limit) | 7caf98ddb37036c79c0e323fc854cbc550eaaa60 | 6,162 |
from typing import Dict
def strip_empty_values(values: Dict) -> Dict:
"""Remove any dict items with empty or ``None`` values."""
return {k: v for k, v in values.items() if v or v in [False, 0, 0.0]} | 982814edbd73961d9afa2e2389cbd970b2bc231e | 6,164 |
def wtr_tens(P, T):
"""Function to Calculate Gas-Water Interfacial Tension in dynes/cm"""
#P pressure, psia
#T temperature, °F
s74 = 75 - 1.108 * P ** 0.349
s280 = 53 - 0.1048 * P ** 0.637
if (T <= 74):
sw = s74
elif(T >= 280):
sw = s280
else:
sw... | acbf649a8dfe1302350b35f141afc09198470d8d | 6,165 |
import math
def get_line_equation(segment_point0, segment_point1):
"""
Ax + By + C = 0
:param segment_point0: Point
:param segment_point1:
:return: A, B, C
"""
x0, y0 = segment_point0.px, segment_point0.py
x1, y1 = segment_point1.px, segment_point1.py
a, b, c = y1 - y0, x0 - x1, x... | 9e0b35f2cac4c7a5835755878fd8aa5d32735699 | 6,166 |
def keep_lesser_x0_y0_zbt0_pair_in_dict(p, p1, p2):
"""Defines x0, y0, and zbt0 based on the group associated with the
lowest x0. Thus the new constants represent the point at the left-most
end of the combined plot.
:param p: plot to combine p1 and p2 into
:param p1: 1st plot to combine
:param p... | 4dc7c008e86606b4257980f59b12fc6a183e060f | 6,167 |
def two_sum_v1(array, target):
"""
For each element, find the complementary value and check if this second value is in the list.
Complexity: O(n²)
"""
for indice, value in enumerate(array):
second_value = target - value
# Complexity of in is O(n). https://stackoverflow.com/questions/... | 0dcc3b4a10ac4c04cabd4ab09a9e71f739455f55 | 6,168 |
import yaml
def python_packages():
"""
Reads input.yml and returns a list of python
related packages
"""
with open(r"tests/input.yml") as file:
inputs = yaml.load(file, Loader=yaml.FullLoader)
return inputs["python_packages"] | 91889c21b1553f9b09c451913e658b458c4502d0 | 6,169 |
def metric_wind_dict_to_beaufort(d):
"""
Converts all the wind values in a dict from meters/sec
to the corresponding Beaufort scale level (which is not an exact number but rather
represents a range of wind speeds - see: https://en.wikipedia.org/wiki/Beaufort_scale).
Conversion table: https://www.win... | b26ddb5e9c0423612a9c7086030fd77bbfa371ad | 6,170 |
def str_igrep(S, strs):
"""Returns a list of the indices of the strings wherein the substring S
is found."""
return [i for (i,s) in enumerate(strs) if s.find(S) >= 0]
#return [i for (s,i) in zip(strs,xrange(len(strs))) if s.find(S) >= 0] | bae8afdb7d0da4eb8384c06e9f0c9bc3f6a31242 | 6,171 |
import base64
def is_base64(s):
"""Return True if input string is base64, false otherwise."""
s = s.strip("'\"")
try:
if isinstance(s, str):
sb_bytes = bytes(s, 'ascii')
elif isinstance(s, bytes):
sb_bytes = s
else:
raise ValueError("Argument mus... | 6ce7bc4ddc79d5d50acce35f7995033ffb7d364a | 6,175 |
def get_mod_from_id(mod_id, mod_list):
"""
Returns the mod for given mod or None if it isn't found.
Parameters
----------
mod_id : str
The mod identifier to look for
mod_list : list[DatRecord]
List of mods to search in (or dat file)
Returns
-------
DatRecord or Non... | 1fac309e4dfadea6da34946eb695f77cbbd61f92 | 6,177 |
import math
def distance(point1, point2):
""" Return the distance between two points."""
dx = point1[0] - point2[0]
dy = point1[1] - point2[1]
return math.sqrt(dx * dx + dy * dy) | 7605d98e33989de91c49a5acf702609272cf5a68 | 6,178 |
import math
def order_of_magnitude(value):
"""
Returns the order of magnitude of the most significant digit of the
specified number. A value of zero signifies the ones digit, as would be
the case in [Number]*10^[Order].
:param value:
:return:
"""
x = abs(float(value))
offset = 0 ... | 53a4b1be76199864fee69d4333049fb1f2371e46 | 6,179 |
def cumulative_sum(t):
"""
Return a new list where the ith element is the sum of all elements up to that
position in the list. Ex: [1, 2, 3] returns [1, 3, 6]
"""
res = [t[0]]
for i in range(1, len(t)):
res.append(res[-1] + t[i])
return res | 14b2ef722f72e239d05737a7bb7b3a6b3e15305f | 6,180 |
def has_active_lease(storage_server, storage_index, now):
"""
:param allmydata.storage.server.StorageServer storage_server: A storage
server to use to look up lease information.
:param bytes storage_index: A storage index to use to look up lease
information.
:param float now: The curre... | 544b17489bc766a15bf2eca5cddab55c1bf473dd | 6,183 |
import os
def revision_pattern_from_build_bucket_path(bucket_path):
"""Get the revision pattern from a build bucket path."""
return '.*?' + os.path.basename(bucket_path) | b7db362eb47531413397f0dc2079f4f7fd931d94 | 6,184 |
def img_to_square(im_pic):
""" 把图片处理成正方形
:param im_pic:
:return:
"""
w, h = im_pic.size
if w >= h:
w_start = (w - h) * 0.618
box = (w_start, 0, w_start + h, h)
region = im_pic.crop(box)
else:
h_start = (h - w) * 0.618
box = (0, h_start, w, h_start + w)... | ae672ea715cb982272eddaff0417d4f64926894c | 6,185 |
import random
def particle_movement_x(time):
"""
Generates a random movement in the X label
Parameter:
time (int): Time step
Return:
x (int): X position
"""
x = 0
directions = [1, -1]
for i in range(time):
x = x + random.choice(directions)
return x | 0dff68080dbfd56997cffb1e469390a1964a326f | 6,187 |
def find_match_characters(string, pattern):
"""Find match match pattern string.
Args:
params: string
pattern
Returns:
Raises:
"""
matched = []
last_index = 0
if not string or not pattern:
return matched
if string[0] != pattern[0]:
return matc... | 6d3bc3844c20584038e41c22eeead7325031b647 | 6,188 |
import os
def fq_classification(fqclass, verbose=False):
"""
Read the fastq classification file
:param fqclass: the classification file that has the file name and then arbitrary classifications separated by tabs
:param verbose: more output
:return: a dict of the classification. Guaranteed that all... | 84f71e91ad9b20c5781377b05f3a72c05a6d28b5 | 6,190 |
def remove_keys_from_array(array, keys):
"""
This function...
:param array:
:param keys:
:return:
"""
for key in keys:
array.remove(key)
return array | 3143b8e42eb1e1b2f5818a254bcec3631c30f5ea | 6,191 |
def _format_td(timedelt):
"""Format a timedelta object as hh:mm:ss"""
if timedelt is None:
return ''
s = int(round(timedelt.total_seconds()))
hours = s // 3600
minutes = (s % 3600) // 60
seconds = (s % 60)
return '{:02d}:{:02d}:{:02d}'.format(hours, minutes, seconds) | 071f25c3c8cfc75cacf2fedc7002527897362654 | 6,193 |
def data_index(data, key):
"""Indexing data for key or a list of keys."""
def idx(data, i):
if isinstance(i, int):
return data[i]
assert isinstance(data, dict)
if i in data:
return data[i]
for k, v in data.items():
if str(k) == str(i):
... | f2b6d18bcd83eb0ffd9b355643e79b40459d8d6a | 6,197 |
def extract_protein_from_record(record):
"""
Grab the protein sequence as a string from a SwissProt record
:param record: A Bio.SwissProt.SeqRecord instance
:return:
"""
return str(record.sequence) | a556bd4316f145bf23697d8582f66f7dcb589087 | 6,198 |
import torch
def calc_IOU(seg_omg1: torch.BoolTensor, seg_omg2: torch.BoolTensor, eps: float = 1.e-6) -> float:
"""
calculate intersection over union between 2 boolean segmentation masks
:param seg_omg1: first segmentation mask
:param seg_omg2: second segmentation mask
:param eps: eps for numerica... | 6586b1f9995858be9ab7e40edd1c3433cd1cd6f4 | 6,199 |
def td_path_join(*argv):
"""Construct TD path from args."""
assert len(argv) >= 2, "Requires at least 2 tdpath arguments"
return "/".join([str(arg_) for arg_ in argv]) | 491f1d50767a50bfbd7d3a2e79745e0446f5204c | 6,200 |
import torch
def calculate_segmentation_statistics(outputs: torch.Tensor, targets: torch.Tensor, class_dim: int = 1, threshold=None):
"""Compute calculate segmentation statistics.
Args:
outputs: torch.Tensor.
targets: torch.Tensor.
threshold: threshold for binarization of predictions.... | ccc017dd5c7197565e54c62cd83eb5cdc02d7d17 | 6,201 |
def get_finger_distal_angle(x,m):
"""Gets the finger angle th3 from a hybrid state"""
return x[2] | f93b1931f3e4a9284ccac3731dfeea21526ea07c | 6,202 |
def merge(pinyin_d_list):
"""
:rtype: dict
"""
final_d = {}
for overwrite_d in pinyin_d_list:
final_d.update(overwrite_d)
return final_d | 512f551620ccedae8fb53f0c60f7caf931aae249 | 6,203 |
import torch
def polar2cart(r, theta):
"""
Transform polar coordinates to Cartesian.
Parameters
----------
r, theta : floats or arrays
Polar coordinates
Returns
-------
[x, y] : floats or arrays
Cartesian coordinates
"""
return torch.stack((r * theta.cos(), ... | c13225a49d6435736bf326f70af5f6d4039091d8 | 6,204 |
import torch
def sum_log_loss(logits, mask, reduction='sum'):
"""
:param logits: reranking logits(B x C) or span loss(B x C x L)
:param mask: reranking mask(B x C) or span mask(B x C x L)
:return: sum log p_positive i over all candidates
"""
num_pos = mask.sum(-1) # B... | 88a312f74e7d4dce95d8dcadaeeaa1a136fceca6 | 6,206 |
def backoff_linear(n):
"""
backoff_linear(n) -> float
Linear backoff implementation. This returns n.
See ReconnectingWebSocket for details.
"""
return n | a3a3b3fc0c4a56943b1d603bf7634ec50404bfb3 | 6,207 |
def check_dna_sequence(sequence):
"""Check if a given sequence contains only the allowed letters A, C, T, G."""
return len(sequence) != 0 and all(base.upper() in ['A', 'C', 'T', 'G'] for base in sequence) | 2f561c83773ddaaad2fff71a6b2e5d48c5a35f87 | 6,209 |
import os
import base64
def decode_json(filepath="stocks.json"):
"""
Description: Generates a pathname to the service account json file
needed to access the google calendar
"""
# Check for stocks file
if os.path.exists(filepath):
return filepath
creds = os.environ.get("GOOGLE_SER... | 095dabf2a397576289bf1754f4eae4406e6648c1 | 6,210 |
import argparse
def args_parser_test():
"""
returns argument parser object used while testing a model
"""
parser = argparse.ArgumentParser()
parser.add_argument('--architecture', type=str, metavar='arch', required=True, help='neural network architecture [vgg19, resnet50]')
parser.add_argument('--dataset',type=... | 77ce5f9cacd8cd535727fa35e8c9fb361324a29a | 6,211 |
def page(token):
"""``page`` property validation."""
if token.type == 'ident':
return 'auto' if token.lower_value == 'auto' else token.value | 5b120a8548d2dbcbdb080d1f804e2b693da1e5c4 | 6,212 |
import os
def create_fsns_label(image_dir, anno_file_dirs):
"""Get image path and annotation."""
if not os.path.isdir(image_dir):
raise ValueError(f'Cannot find {image_dir} dataset path.')
image_files_dict = {}
image_anno_dict = {}
images = []
img_id = 0
for anno_file_dir in ann... | 346e5a331a03d205113327abbd4d29b9817cc96c | 6,213 |
def dest_in_spiral(data):
"""
The map of the circuit consists of square cells. The first element in the
center is marked as 1, and continuing in a clockwise spiral, the other
elements are marked in ascending order ad infinitum. On the map, you can
move (connect cells) vertically and horizontally.... | a84a00d111b80a3d9933d9c60565b7a31262f878 | 6,215 |
def skin_base_url(skin, variables):
""" Returns the skin_base_url associated to the skin.
"""
return variables \
.get('skins', {}) \
.get(skin, {}) \
.get('base_url', '') | 80de82862a4a038328a6f997cc29e6bf1ed44eb8 | 6,216 |
import random
def random_tolerance(value, tolerance):
"""Generate a value within a small tolerance.
Credit: /u/LightShadow on Reddit.
Example::
>>> time.sleep(random_tolerance(1.0, 0.01))
>>> a = random_tolerance(4.0, 0.25)
>>> assert 3.0 <= a <= 5.0
True
"""
valu... | abe631db8a520de788540f8e0973537306872bde | 6,217 |
def find_scan_info(filename, position = '__P', scan = '__S', date = '____'):
"""
Find laser position and scan number by looking at the file name
"""
try:
file = filename.split(position, 2)
file = file[1].split(scan, 2)
laser_position = file[0]
file = file[1].split(date... | f98afb440407ef7eac8ceda8e15327b5f5d32b35 | 6,218 |
import os
def get_circuitpython_version(device_path):
"""
Returns the version number of CircuitPython running on the board connected
via ``device_path``. This is obtained from the ``boot_out.txt`` file on the
device, whose content will start with something like this::
Adafruit CircuitPython 4... | ce4d407062566cd42473d2cef8d18024b0098b69 | 6,221 |
def reverse_preorder(root):
"""
@ input: root of lcrs tree
@ output: integer list of id's reverse preorder
"""
node_list = []
temp_stack = [root]
while len(temp_stack) != 0:
curr = temp_stack.pop()
node_list.append(curr.value)
if curr.child is not None:
... | 06a53756db0f5c990537d02de4fcaa57cc93169d | 6,225 |
def run_services(container_factory, config, make_cometd_server, waiter):
""" Returns services runner
"""
def _run(service_class, responses):
"""
Run testing cometd server and example service with tested entrypoints
Before run, the testing cometd server is preloaded with passed
... | df7d1c3fdf7e99ebf054cfc6881c8073c2cf4dee | 6,226 |
import requests
def cleaned_request(request_type, *args, **kwargs):
""" Perform a cleaned requests request """
s = requests.Session()
# this removes netrc checking
s.trust_env = False
return s.request(request_type, *args, **kwargs) | b6c99c85a64e5fd78cf10cc986c9a4b1542f47d3 | 6,227 |
import yaml
def load_config_file(filename):
"""Load configuration from YAML file."""
docs = yaml.load_all(open(filename, 'r'), Loader=yaml.SafeLoader)
config_dict = dict()
for doc in docs:
for k, v in doc.items():
config_dict[k] = v
return config_dict | d61bb86e605a1e744ce3f4cc03e866c61137835d | 6,228 |
def empty_filter(item, *args, **kwargs):
"""
Placeholder function to pass along instead of filters
"""
return True | d72ac5a0f787557b78644bcedd75e71f92c38a0b | 6,231 |
def RAND_egd(path): # real signature unknown; restored from __doc__
"""
RAND_egd(path) -> bytes
Queries the entropy gather daemon (EGD) on the socket named by 'path'.
Returns number of bytes read. Raises SSLError if connection to EGD
fails or if it does not provide enough data to seed PRNG.
... | 5ef4e3e065c44058996c1793541cd9f2a599b106 | 6,232 |
from typing import List
from typing import Dict
from typing import Any
def get_types_map(types_array: List[Dict[str, Any]]) -> Dict[str, Dict[str, Any]]:
"""Get the type name of a metadata or a functionality."""
return {type_["name"]: type_ for type_ in types_array} | 9354eff434b589a19360ee13d8bf7d9ab9e1002d | 6,233 |
def dice_loss(pred, target, smooth=1.):
"""Dice loss
"""
pred = pred.contiguous()
target = target.contiguous()
intersection = (pred * target).sum(dim=2).sum(dim=2)
loss = (1 - ((2. * intersection + smooth) / (pred.sum(dim=2).sum(dim=2) + target.sum(dim=2).sum(dim=2) + smooth)))
return los... | 5879769ac379395e35f9accda9d917094aa07301 | 6,234 |
import re
def remove_mentions(text):
"""Remove @-mentions from the text"""
return re.sub('@\w+', '', text) | 5cbdd40a602f24f8274369e92f9159cbb2f6a230 | 6,235 |
def _flat(l):
"""Flattens a list.
"""
f = []
for x in l:
f += x
return f | 9b2e432d79f08840d417601ff950ff9fa28073ef | 6,236 |
def axesDict(T_axes):
"""Check connectivity based on Interval Vectors."""
intervalList = [
T_axes[0],
T_axes[1],
T_axes[2],
(12 - T_axes[0]),
(12 - T_axes[1]),
(12 - T_axes[2])]
return intervalList | 6b1e8c59d12a3c2c548b95f3bcd8d7a3de4ef931 | 6,237 |
def is_no_entitled(request):
"""Check condition for needing to entitled user."""
no_entitled_list = ["source-status"]
no_auth = any(no_auth_path in request.path for no_auth_path in no_entitled_list)
return no_auth | feee0962568b20c685fd85096ce00dbb91b91fe5 | 6,238 |
from typing import Union
from pathlib import Path
def find_mo(search_paths=None) -> Union[Path, None]:
"""
Args:
search_paths: paths where ModelOptimizer may be found. If None only default paths is used.
Returns:
path to the ModelOptimizer or None if it wasn't found.
"""
default_m... | 4657e15649692415dd10f2daa6527cade351d8fc | 6,241 |
import math
def point_in_wave(point_x, frequency, amplitude, offset_x, offset_y):
"""Returns the specified point x in the wave of specified parameters."""
return (math.sin((math.pi * point_x)/frequency + offset_x) * amplitude) + offset_y | 5a91c9204819492bb3bd42f0d4c9231d39e404d8 | 6,245 |
def map_to_docs(solr_response):
"""
Response mapper that only returns the list of result documents.
"""
return solr_response['response']['docs'] | 2661b9075c05a91c241342151d713702973b9c12 | 6,246 |
def get_config_type(service_name):
"""
get the config type based on service_name
"""
if service_name == "HDFS":
type = "hdfs-site"
elif service_name == "HDFS":
type = "core-site"
elif service_name == "MAPREDUCE":
type = "mapred-site"
elif service_name == "HBASE":
type = "hbase-site... | 96793f932334eb8e4a5460767a80ee6a989cee22 | 6,247 |
def sync_filter(func, *iterables):
"""
Filter multiple iterable at once, selecting values at index i
such that func(iterables[0][i], iterables[1][i], ...) is True
"""
return tuple(zip(*tuple(i for i in zip(*iterables) if func(*i)))) or ((),) * len(
iterables
) | 7a2ab5e6356dadff0fe78d3f2bb0da584e0ff41b | 6,249 |
import json
def generate_prompt(
test_case_path, prompt_path, solutions_path, tokenizer, starter_path=None
):
"""
Generate a prompt for a given test case.
Original version from https://github.com/hendrycks/apps/blob/main/eval/generate_gpt_codes.py#L51.
"""
_input = "\nQUESTION:\n"
with ope... | ecd3218839b346741e5beea8ec7113ea2892571e | 6,252 |
def copy_emb_weights(embedding, idx2word, embedding_weights, emb_index_dict, vocab_size):
"""Copy from embs weights of words that appear in our short vocabulary (idx2word)."""
c = 0
for i in range(vocab_size):
w = idx2word[i]
g = emb_index_dict.get(w, emb_index_dict.get(w.lower()))
i... | e5d361efd342cc7e194ee325fdf4a98831121576 | 6,255 |
def format_header(header_values):
"""
Formats a row of data with bolded values.
:param header_values: a list of values to be used as headers
:return: a string corresponding to a row in enjin table format
"""
header = '[tr][td][b]{0}[/b][/td][/tr]'
header_sep = '[/b][/td][td][b]'
return ... | 5b7cd734a486959660551a6d915fbbf52ae7ef1e | 6,258 |
import importlib
def load_attr(str_full_module):
"""
Args:
- str_full_module: (str) correspond to {module_name}.{attr}
Return: the loaded attribute from a module.
"""
if type(str_full_module) == str:
split_full = str_full_module.split(".")
str_module = ".".join(split_full[:... | f96dd56c73745e76ccc9c48dda4ba8a6592ab54b | 6,259 |
def sort_dictionary_by_keys(input_dict):
"""
Sort the dictionary by keys in alphabetical order
"""
sorted_dict = {}
for key in sorted(input_dict.keys()):
sorted_dict[key] = input_dict[key]
return sorted_dict | 225df2c16d2b21740603c224319ad4b0eaa0899d | 6,260 |
def quick_sort(seq):
"""
Реализация быстрой сортировки. Рекурсивный вариант.
:param seq: любая изменяемая коллекция с гетерогенными элементами,
которые можно сравнивать.
:return: коллекция с элементами, расположенными по возрастанию.
Examples:
>>> quick_sort([0, 5, 3, 2, 2])
[0, 2, 2, 3,... | 46b56b5d29ca31a872e1805b66f4529a8bf48c6b | 6,261 |
def normalize_query_result(result, sort=True):
"""
Post-process query result to generate a simple, nested list.
:param result: A QueryResult object.
:param sort: if True (default) rows will be sorted.
:return: A list of lists of RDF values.
"""
normalized = [[row[i] for i in range(len(row))... | 1df57ef889be041c41593766e1ce3cdd4ada7f66 | 6,262 |
from typing import List
def count_jobpairs(buildpairs: List) -> int:
"""
:param buildpairs: A list of build pairs.
:return: The number of job pairs in `buildpairs`.
"""
counts = [len(bp['jobpairs']) for bp in buildpairs]
return sum(counts) | 30c345698400fd134456abcf7331ca2ebbfec10f | 6,263 |
from typing import Any
from typing import get_args
def make_hetero_tuple_unstructure_fn(cl: Any, converter, unstructure_to=None):
"""Generate a specialized unstructure function for a heterogenous tuple."""
fn_name = "unstructure_tuple"
type_args = get_args(cl)
# We can do the dispatch here and now.
... | a1ffa13bcf6488a79c6aacafd6f1e12112f99bb2 | 6,265 |
def calc_water(scenario, years, days_in_year):
"""Calculate Water costs Function
Args:
scenario (object): The farm scenario
years (int): The no. of years the simulation will analyse
days_in_year (float): The number of days in a year
Returns:
cogs_water (list): Cost of Goods So... | ed23060e64c928a545897edef008b8b020d84d3c | 6,266 |
def interpolate_force_line2(form, x, tol=1E-6):
"""Interpolates a new point in a form polyline
Used by the `add_force_line` function
(I think it is assumed that the )
"""
if len(form) < 1:
raise ValueError('interpolate_force_line2 : form must not be an empty list')
form_out1 = [form[0]]
... | 82a0eac9132b7e631fd395bddf87595385cae574 | 6,267 |
import json
def enqueue_crawling_job(delegate_or_broadcast_svc, job_id, urls, depth):
"""
Used to enqueue a crawling job (or delegate a sub-url on a current job)
to the worker pool.
:type delegate_or_broadcast_svc: ZeroMQDelegatorService or
ZeroMQBroadcastService.
:param delegate_or_broad... | 6a211346edd6f921bf26ed08adcee98cff066764 | 6,268 |
import pytz
def getLocalTime(utc_dt, tz):
"""Return local timezone time
"""
local_tz = pytz.timezone(tz)
local_dt = utc_dt.replace(tzinfo=pytz.utc).astimezone(local_tz)
return local_dt | 70789f61a90d991714fafe3c15917d1f1113fe8f | 6,269 |
import re
def camel_to_snake(text: str) -> str:
"""
A helper function to convert `camelCase` to `snake_case`.
- e.g. `bestBigBrawlerTime` -> `best_big_brawler_time`
### Parameters
text: `str`
The text to restructure from `camelCase` to `snake_case`.
### Returns
`str`
The ... | b9ac748bf0cc345c7cfb0bade1e4b1e9cbdf712c | 6,272 |
def dict_to_config_str(config_dict):
"""Produces a version of a dict with keys (and some values) replaced with
shorter string version to avoid problems with over long file names in
tensorboard"""
key_abrv = {
"embedding_dimension": "ed",
"loss_type": "lt",
"initialize_uniform": ... | da7d4ae8a58c2dab2d07616ae25438c8c0e0252d | 6,274 |
import ast
def extract_ast_class_def_by_name(ast_tree, class_name):
"""
Extracts class definition by name
:param ast_tree: AST tree
:param class_name: name of the class.
:return: class node found
"""
class ClassVisitor(ast.NodeVisitor):
"""
Visitor.
"""
de... | 011f1cb8d965db8e30e6f4281704a6140103946b | 6,276 |
def default_tiling():
"""Return default tiling options for GeoTIFF driver.
Returns
-------
dict
GeoTIFF driver tiling options.
"""
return {"tiled": True, "blockxsize": 256, "blockysize": 256} | c2d78f2d87478121cc52124d0b33edde5850a10a | 6,277 |
def quantize_sequences(sequences, alphabet):
"""Giving prescribing alphabet, quantize each caracter using index in alphabet
in each sequence.
input:
sequences: [str]
return:
[[int]]
"""
print("quantizing sequences...")
new_sequences = []
for sequence in sequences:
... | 7b8a870d72d6b0a9568fba8d96a1d3c2e422ff59 | 6,279 |
from typing import Callable
def _scroll_screen(direction: int) -> Callable:
"""
Scroll to the next/prev group of the subset allocated to a specific screen.
This will rotate between e.g. 1->2->3->1 when the first screen is focussed.
"""
def _inner(qtile):
if len(qtile.screens) == 1:
... | e778b6ef8a07fe8609a5f3332fa7c44d1b34c17a | 6,280 |
def check_players(instance):
""" Checks to see if any of the starting players have left.
Args:
instance: The GameInstance model for this operation.
If a player has left the game, they are invited back and
a ValueError is raised.
Raises:
ValueError if a player has left the game.
"""
if len(insta... | d3a31f17cf5d3dee2e3fd075cea2e31d8a806952 | 6,281 |
import sysconfig
def shared_libraries_are_available():
"""
check if python was built with --enable-shared or if the system python (with
dynamically linked libs) is in use
default to guessing that the shared libs are not available (be conservative)
"""
# if detection isn't possible because sysc... | 65306cc5bda77f07cc6dc118637d3fec7cae47c0 | 6,285 |
import torch
def decorate_batch(batch, device='cpu'):
"""Decorate the input batch with a proper device
Parameters
----------
batch : {[torch.Tensor | list | dict]}
The input batch, where the list or dict can contain non-tensor objects
device: str, optional
'cpu' or 'cuda'
... | a0bd4a5dff0b5cf6e304aede678c5d56cb93d1dd | 6,286 |
import io
def read_bytes(n: int, reader: io.IOBase) -> bytes:
"""
Reads the specified number of bytes from the reader. It raises an
`EOFError` if the specified number of bytes is not available.
Parameters:
- `n`: The number of bytes to read;
- `reader`: The reader;
Returns the bytes rea... | bb3d00fc7667839864f4104a94a26e682f058fdc | 6,287 |
import json
def _format_full_payload(_json_field_name, _json_payload, _files_payload):
"""This function formats the full payload for a ``multipart/form-data`` API request including attachments.
.. versionadded:: 2.8.0
:param _json_field_name: The name of the highest-level JSON field used in the JSON pay... | feacd27be3e6fcbd33f77fa755be513a93e3cdeb | 6,288 |
import os
def make_output_dirs(model_name, dat, let):
"""
Generate output directories of the run corresponding to
- model_name
- dat
- let
0 - output_dir
1 - samples_output_dir
2 - enkf_output_dir
"""
output_dir = (os.environ['HOME'] + "/shematOutputDir/" + model_name +
... | 2804bff3d1da0aae85e133e985bb526859116388 | 6,289 |
from typing import Any
from typing import Union
import torch
def tocuda(vars: Any) -> Union[str, torch.Tensor]:
"""Convert tensor to tensor on GPU"""
if isinstance(vars, torch.Tensor):
return vars.cuda()
elif isinstance(vars, str):
return vars
else:
raise NotImplementedError("i... | b7be275fe7e909fa54fc62ed9e5fbe61d3ff4863 | 6,290 |
def read_slug(filename):
"""
Returns the test slug found in specified filename.
"""
with open(filename, "r") as f:
slug = f.read()
return slug | e1882d856e70efa8555dab9e422a1348594ffcaf | 6,291 |
def preprocess_img(img):
"""Preprocessing function for images."""
return img/255 | 11651a809288d5c3aa776b318099b7eb750d28ec | 6,292 |
import os
def _get_next_traj_id(root_data_dir='data'):
""" Resolve what is the next trajectory number """
if not os.path.exists(os.path.join(root_data_dir, 'screens')):
return 0
return 1 + max([
int(x) for x in os.listdir(os.path.join(root_data_dir, 'screens'))
]) | d321af4c90d9de78942e2526c0720b3019fff479 | 6,293 |
def munge_av_status(av_statuses):
"""Truncate and lowercase availability_status"""
return [a[20:].lower() for a in av_statuses] | 52a00fc6733015c3618a2a394371ea9387d92fc0 | 6,294 |
def cdf(vals, reverse=False):
"""Computes the CDF of a list of values"""
vals = sorted(vals, reverse=reverse)
tot = float(len(vals))
x = []
y = []
for i, x2 in enumerate(vals):
x.append(x2)
y.append((i+1) / tot)
return x, y | 3cc64dcb8876f7620f02da873e29569e77477823 | 6,295 |
import os
def get_not_repeated_file_name(path_with_file):
"""
Returns file_name if file_name does not exist. If it exists, it appends an underscore until
this new file name does not exist, returning it. For example if "/home/mine/file.txt" exists,
it will return "/home/mine/_file.txt".
@para... | 7da491a3cd0261d99142905e4e7d2690c3be0d06 | 6,296 |
def negative(num):
"""assumes num is a numeric
returns a boolean, True if num is negative, else False"""
return num < 0 | dc8b789b6dbd4d158482de6d4af26f48f9e8cc5b | 6,297 |
import time
def get_framerate(has_already_started,
start_time,
frame_counter,
frame_rate,
frame_num=5,
decimal_round_num=2):
""" Returns current framerate of video based on
time elapsed in frame_num frames.
Works in... | 61db421be9e8d5a0e810a79875eac2b776be99ca | 6,298 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.