content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def is_subsequence_2d(subseq, seq):
"""Check if `subseq` is a subsequence of `seq`."""
n = seq.shape[0]
m = subseq.shape[0]
w = seq.shape[1]
if seq.shape[1] != subseq.shape[1]:
return False
if m > n:
return False
i = 0 # index of seq
j = 0 # index of subseq
k = 0... | 64778c888393bc52d7a72a3453f02d4c3a0ceef1 | 38,264 |
import torch
def btranspose(tensor: torch.Tensor) -> torch.Tensor:
"""Batch-wise transpose. Assumes that tensor has dimension of 3: [batch, features, samples]"""
if tensor.dim() != 3:
raise ValueError("The given shape is not supported.")
return torch.transpose(tensor, 1, 2) | 4b238672a2cfca33abb86116949acd6d392434f0 | 38,266 |
import torch
def loss_fn(T, gt_rotation, gt_translation, matches, matching_scores, point_set):
"""
Compute Loss.
Args:
T (torch.Tensor): size = (B, 3, 4)
gt_rotation (torch.Tensor): size = (B, 3, 3)
gt_translation (torch.Tensor): size = (B, 3)
matches (torch.Tensor): s... | c628bd6f3ba9d9c3e7582d6452538286834168e2 | 38,267 |
def alchemy_backend(request, data_directory):
"""
Runs the SQLAlchemy-based backends
(sqlite, mysql, postgres)
"""
return request.param(data_directory) | 6d5c3c91c9e7f580bb5adeef948fe24e9ad81715 | 38,269 |
def get_color_string_8_bit(color_id: str) -> str:
"""Return ANSI color command string for 8 bit colors"""
return color_id | b10c6d4a3e6b77baa36ce720efc241c2b1ee348b | 38,270 |
def color_ordered(group_order, group_to_color):
"""Colors in the order created by the groups"""
return [group_to_color[g] for g in group_order] | fcb16720e204e32082b2a0e2a81be7909a926db7 | 38,271 |
def is_org_context(request):
"""An organization context is a virtual private Seafile instance on cloud
service.
Arguments:
- `request`:
"""
return request.cloud_mode and request.user.org is not None | ca7b14728d1f73d1584ebb0539530aa3c71a96bf | 38,272 |
import re
def opensearch_clean(f):
"""
Some opensearch clients send along optional parameters from the opensearch
description when they're not needed. For example:
state={openoni:state?}
These can cause search results not to come back, and even can cause Solr's
query parsing to thro... | 862bf8cbb9a2629949746a92b78b3b23bdfd7c49 | 38,273 |
def key2num(key):
"""
Translates MIDI key to a number.
"""
key2num = {"C": 0, "Db": 1, "D": 2, "Eb": 3, "E": 4, "F": 5, "Gb": 6, "G": 7, "Ab": 8, "A": 9, "Bb": 10, "B": 11,
"Cb": 11, "C#": 1, "D#": 3, "F#": 6, "G#": 8, "A#": 10, "B#": 0,
"Cmin": 20, "Dbmin": 21, "Dmin": 22, "Ebmin": 23, "Emin": 24, "Fmin": ... | a11a22a62c94c84a946df710e39d2d874f3bf343 | 38,274 |
import re
def check_for_function(function: str, data: str) -> bool:
""" Checks for a function in javascript code
function: the name of the function
data: the javascript code
returns: Whether the code contains the function
"""
return bool(re.search(f'[^a-zA-Z]{function}[^a-zA-Z]', data)) | 671b3554a70407d447cac26b27f542812cbba97c | 38,276 |
def min_pie(pie):
"""Given a tuple of numbers, where each number represents the size of a
slice of pie, distribute the slices among 2 people as evenly as possible.
(i.e., minimizing the difference between the sums of two sets of values)
>>> min_pie((1, 1, 1, 1))
[((1, 1), (1, 1))]
>>> min_pie((... | 12104eb220cc207bbd634041a4e46df080b38f37 | 38,278 |
def user_discrim(user):
"""
Return the user's username and disc
in the format <username>#<discriminator>
"""
return f"{user.name}#{user.discriminator}" | 22866ad0c23a23bfbd7460844a9582916970991c | 38,280 |
import configparser
import json
def write_config_to_file(config_dict, ini_fpath):
""" Writes a configuration to an ini file.
:param config_dict: (Dict) config to write
:param ini_fpath: (str) fpath to ini file
:return: (str) ini_file written to
"""
config = configparser.ConfigParser()
config["DEFAULT"]... | 8b9c9c64e08afe64bc4fc6f9570ea84f53b9f72c | 38,281 |
import os
def get_abs_path(dir_):
""" Convert a path specified by the user, which might be relative or based on
home directory location, into an absolute path.
"""
if os.path.isabs(dir_):
return os.path.realpath(dir_)
if dir_[0] == "~" and not os.path.exists(dir_):
dir_ = os.pa... | 590e3b02fd7d7a4e8a89780a091c2d0e94d892c1 | 38,282 |
def calc_box_length(part_num, density, aspect_ratio):
""" part_num, density, aspect_ratio = [x, y, z] -> x:y:z """
box_length = (float(part_num) / float(density) /
(aspect_ratio[0] * aspect_ratio[1] * aspect_ratio[2]))**(1.0 / 3.0)
return [box_length * aspect_ratio[0], box_length * aspect_... | 58290265e2b2a8abd3e32df330b9d8c4f795223d | 38,283 |
import json
def model_comment(comment_type, text, other=None):
"""
Print a model comment. This is a base function for some functions implemented below but sometimes it is necessary to
use it directly.
:param comment_type: Comment type string.
:param text: Comment text.
:param other: Additiona... | 23b7278bd9bcf1dbe0b41e908bcd41bd792789f1 | 38,284 |
def fetch(spec, **kwargs):
"""
Fetches a file on the local filesystem into memory.
"""
with open(spec['path'], 'rb') as f:
return f.read() | 84442c8df0efa0fa095b2d8282ea9c0d4cd2995f | 38,286 |
from typing import Union
import torch
def reshape_list(flat_list: list, size: Union[torch.Size, tuple]) -> list:
"""
Reshape a (nested) list to a given shape
Args:
flat_list: (nested) list to reshape
size: shape to reshape to
Returns:
list: reshape list
"""
if len(siz... | c9c9b09bb0d91ed3229f0b5e5b28130ac2d93377 | 38,287 |
def admin2_it(x, county_d):
"""Add admin2 (County Name for US)"""
if x[1] == "United States":
return county_d.get(x[0], "None")
else:
return "None" | 404b7d2be9ce0ec0c523148c3879bf63149230b0 | 38,288 |
def prod(*x):
"""
Returns the product of elements, just like built-in function `sum`.
Example:
----------
>>> prod([5, 2, 1, 4, 2])
80
"""
if len(x) == 1 and isinstance(x[0], list): x = x[0]
p = 1
for i in x:
if hasattr(i, "__mul__"):
p *= i
return p | 94569594eab0c6823733d76d69d59d21a6b4d96b | 38,289 |
def NumberNodes(graph):
"""Returns a copy of `graph` where nodes are replaced by incremental ints."""
node_list = sorted(graph.nodes())
index = {n: i for (i, n) in enumerate(node_list)}
newgraph = graph.__class__()
for (n1, n2) in graph.edges():
newgraph.add_edge(index[n1], index[n2])
return newgraph,... | 2d7366f69707d91e9779e68c378cf54c3fe5c104 | 38,290 |
def hello(bot, update):
"""
Greet the user with their first name and Telegram ID.
"""
user_firstname = update.message.from_user.first_name
user_id = update.message.from_user.id
return update.message.reply_text(
'Hello {}, your Telegram ID is {}'.format(user_firstname, user_id)
) | e5567d6748f202093bc44c514b38d6d32c162d4b | 38,291 |
import os
def get_font_filepaths(dependency_bundle, dependency_dir):
"""Gets dependency font filepaths.
Args:
dependency_bundle: dict(str, list(str) | str). The dict has three keys:
- 'js': List of paths to js files that need to be copied.
- 'css': List of paths to css files t... | 2f94b035b632256beff346827b40b3277b1015f7 | 38,292 |
def create_price_sqm(data):
"""Create price per square meter feature."""
data['Prezzo_per_m2'] = data['Prezzo'] / data['Superficie']
return data | 6a50084f69f233374ffa4512de2653f37f749467 | 38,293 |
def convert_num(mode, num):
"""Converts a number in any given number scale
Example:
`convert_num("100K", 600000) returns 6`
Args:
- mode: (string) the scale for the conversion ("100K", "M", "10M", "100M", "B")
- num: the number to be converted
Returns:
the converted number
"... | 461d5cf0d35e43509db3cffebf5487ab85470545 | 38,294 |
import re
def stripms(stamp):
"""
Given ISO 8601 datestamp, strip out any milliseconds in representation
using a regular expression safe for either stamps with or stamps
without milliseconds included.
"""
parts = stamp.split('.')
if len(parts) == 1:
return stamp # no millisecond p... | 937136fc563f0b6084521ddd912a21bade2166cf | 38,296 |
import argparse
def check_nonnegative(value):
"""
Checks if (possibly string) value is non-negative integer and returns it.
Raise:
ArgumentTypeError: if value is not a non-negative integer
"""
try:
ivalue = int(value)
if ivalue < 0:
raise ValueError()
excep... | 498ae2cae0feb212ad97e1c84db2a84f36f6c8a8 | 38,297 |
def get_parent(vmfs):
""" From a set of VMFs, determines which one has the lowest map version
number, and is therefore the parent.
"""
# This avoids the need to subscript and slice.
vmfs = iter(vmfs)
parent = next(vmfs)
lowestRevision = parent.revision
for vmf in vmf... | bae83d2e02edc835c533873994285870246c7623 | 38,298 |
import torch
def weight_standardize(w, dim, eps):
"""Subtracts mean and divides by standard deviation."""
w = w - torch.mean(w, dim=dim)
w = w / (torch.std(w, dim=dim) + eps)
return w | d1db7d3fe98e0faf8a9161844c00c7489ba64f0c | 38,299 |
import sys
def parse_options():
"""Parses the input directory and file and the output parameters.
"""
if len(sys.argv) < 3:
print("Missing parameter!\n")
exit(1)
base_dir = sys.argv[1]
base_file = sys.argv[2]
out_file = sys.argv[3]
verbose = True if len(sys.argv) > 4 and s... | 1e0d47f213e59e9417a18d07e71acdc7563996db | 38,300 |
def gef_pystring(x):
"""Returns a sanitized version as string of the bytes list given in input."""
res = str(x, encoding="utf-8")
substs = [("\n", "\\n"), ("\r", "\\r"), ("\t", "\\t"), ("\v", "\\v"), ("\b", "\\b"), ]
for x, y in substs: res = res.replace(x, y)
return res | 69346a27e6ee1aba434d938c93fce15041419b8d | 38,301 |
import argparse
def _generate_parser(**cli_kwargs):
"""Set up an argument parser with the given expected flags as kwargs.
:param Any kwargs: Flag=Description kwarg pairs.
:rtype: argparse.ArgumentParser
"""
parser = argparse.ArgumentParser()
for flag, details in cli_kwargs.items():
de... | c0463b09977f098ed72a223c6ae2c2b0184de016 | 38,303 |
def format_parameter(*args, **kwargs):
"""Format a parameter string
>>> format_parameter(ex=['example', 'one'])
'"ex=example:one"'
>>> format_parameter('one', 'two', 'three')
'one:two:three'
You can mix the arguments und keyword arguments.
"""
parameter_list = []
for value in args:... | 77c84e3edb22de0a4cec58b9bcbeb1ef67ee2d5e | 38,304 |
def retry_get(value):
"""Return True if value is None"""
x1, x2 = value
return x1 == 'retry' | eea6128c806c49c0740a244bd6d5fb67caf4b4d1 | 38,305 |
def get_goods():
"""
Запросить данные о товаре.
"""
name = input("Название товара: ")
shop = input("Название магазина: ")
price = float(input("Стоимость: "))
# Создать словарь.
return {
'name': name,
'shop': shop,
'price': price,
} | cdfdaa4a68d3cff530479cf9ea0df4ea1b7c61bc | 38,306 |
import torch
def prep_tensor_for_vis(x):
"""Prepare tensor for visualization
If only has one channel, concatenate to produce 3 channels
Clone, detach and pass to cpu before clamping between 0 and 1
Parameters
----------
x: torch.FloatTensor
Tensor with image (CHW)
Returns
---... | 20426f0c3aef6f467ccc0b7b1bca26b30eb3bba9 | 38,307 |
import optparse
def FileGroup(parser):
"""Define the group which defines all the types of files the script can process."""
group = optparse.OptionGroup(
parser, "File options",
"These options define the types of files the script processes. "
"At least one file must be defined using t... | 17b534d3adc01ed180351eae6627b23b061b12e8 | 38,308 |
from datetime import datetime
def is_datetime(string):
"""
Check if a string can be converted to a datetime object.
:param string: the string
:return: True if the string can be converted to a datetime object, False otherwise
"""
try:
datetime.strptime(string, "%Y-%m-%d %H.%M.%S")
... | d1fa368d1b7ac45b85661bd4b72771d088c4ac6f | 38,309 |
def _compare_properties(sub_set: list, set_: list) -> bool:
"""
Check for a subset in a set of properties.
Parameters
----------
sub_set : list
The smaller set that should be contained in the 'set'.
schema : dict
The set for which to check if 'sub_set' is a part of.
Returns... | a13a29b4cb0b1728277c237b40bd4c5567beb001 | 38,310 |
def calculate_accuracy(combined_decisions, Y_test_1):
"""calculates percentage accuracy of a combined decisions array
Args:
combined_decisions: predicted values for combined model
Y_test_1: True values
Returns:
percentage accuracy of predictions
"""
total_decisions = len(comb... | 7494ef3bc017e628f9621f803c27bd2c77ccff2b | 38,312 |
def _sample_atrr(matrix_X, sub_samples):
"""
Computes the number of samples, sub samples, and the observed test statistics
:param matrix_X: is interpreted as a ``[n*p]`` data matrix, a matrix with ``n`` samples in ``p`` dimensions
:type matrix_X: 2D numpy.array
:param sub_samples: the number of su... | 5badb8c3f5fbc28d3e6bee5d506a8d3be10629ec | 38,316 |
import requests
def load_mta_archived_feed(feed='gtfs', timestamp='2014-09-17-09-31'):
"""
Returns archived GTFS data for a particular time_assigned.
Parameters
----------
feed: {'gtfs', 'gtfs-l', 'gtfs-si'}
Archival data is provided in these three rollups. The first one covers 1-6 and th... | d1d38854dbd35f2c30342b9958d0640541162dd1 | 38,317 |
from typing import Dict
from typing import Any
def _setdefault(dictionary: Dict[str, Any], key: str,
value: Any) -> Dict[str, Any]:
"""Sets the default value of `key` to `value` if necessary.
Args:
dictionary: the dictionary to add a default for.
key: The key to add a default for.
val... | d989b167769aaf6674027b68f5ec0463fea5251d | 38,318 |
def _no_op(*args, **kwargs):
"""No operation."""
return None | fa389f2d8aae0e38dd414b0294a3da948e0c9595 | 38,319 |
def batch_slice(index: int, batch_size: int) -> slice:
"""Return slice corresponding to given index for given batch_size.
Parameters
---------------
index: int,
Index corresponding to batch to be rendered.
batch_size: int
Batch size for the current Sequence.
Returns
---------... | 162d1e9990b82658861b2c5bb5f90b2f0d0646d5 | 38,320 |
def set_size(self, mode):
"""Calculates the number of samples in the dataset partition"""
return len(self.data_index[mode]) | 8337089875f70d0d4db68f1ff67bd29705774747 | 38,321 |
def is_derivatized(monosaccharide):
"""Tests whether any of the substituents attached to `monosaccharide` were
added by derivatization.
Parameters
----------
monosaccharide : Monosaccharide
The object to test
Returns
-------
bool
"""
for pos, sub in monosaccharide.subst... | f77cc01e14939b94652bb9d19f7d0729201f35bb | 38,322 |
def vis_invis(beacon, light_off=4):
""" Add 6th column to beacon file if visible or not
PARAMS
------------
beacon : DataFrame
beacons
light_off : int
how often beacon visible
Returns
------------
Data Frame with all beacon position and if visible or not
"""
vi... | d789227038e2959b4d15e3808c491a35957c8d71 | 38,323 |
def logg_to_vt_K09(logg):
""" Kirby et al. 2009 ApJ 705, 328 (uncertainty is ~ 0.05 + 0.03*logg) """
return 2.13 - 0.23 * logg | 7b98c0777ea4f9fa5139b221061c55957a4ea250 | 38,324 |
def gradient_summand(weights, lp):
"""Calculates the gradient summand for a given weight and `LabeledPoint`.
Note:
`DenseVector` behaves similarly to a `numpy.ndarray` and they can be used interchangably
within this function. For example, they both implement the `dot` method.
Args:
... | b34de095fb762aa933570ae58744772205ded5de | 38,325 |
import os
def _NonePathJoin(*args):
"""os.path.join that filters None's from the argument list."""
return os.path.join(*filter(None, args)) | c8ce83a7b0d82fd003ca8dc113826d4cb342c639 | 38,326 |
def schedule(intervals):
"""Schedule the maximum number of compatible intervals.
This uses the greedy interval scheduling algorithm to find (schedule)
the maximum number of compatible (non-overlapping) intervals.
Args:
intervals: list of intervals, each of which is a tuple (x,y)
in... | 19480ff5b24070e53e9243066c3f34f8a91d1e98 | 38,328 |
def parse_hgnc_line(line, header):
"""Parse an hgnc formated line
Args:
line(list): A list with hgnc gene info
header(list): A list with the header info
Returns:
hgnc_info(dict): A dictionary with the relevant info
"""
hgnc_gene = {}
line = line.rstr... | 9b0c373a107782d81b818b258e9c273e89b9ec12 | 38,329 |
def gluTessCallback( tess, which, function ):
"""Set a given gluTessellator callback for the given tessellator"""
return tess.addCallback( which, function ) | 0fdfd00a24c2a757ce44330fe01a28e65fa6af7d | 38,330 |
def RemoveHighNullValues(dataframe):
"""
param1: pandas.DataFrame
return: pandas.DataFrame
Function drops any feature with more then 80% of Null Values and return the Dataframe
"""
thresh = len(dataframe) * .5
dataframe.dropna(thresh = thresh, axis = 1, inplace = True)
return dataframe | 4d6ced499c288cb2aa9acff6103ade729b656857 | 38,331 |
from typing import Sequence
import subprocess
def get_output(args: Sequence[str], verbose: bool = False, **kwargs) -> str:
"""Executes a command and returns its stdout."""
if verbose:
cmd = " ".join(args)
print(f"cmd: {cmd}")
return subprocess.run(args,
check=True,
... | 01f17e3946aa8566d965c2099be74309fca633d6 | 38,332 |
import warnings
def is_insulin_sensitivity_schedule_valid(start_times, end_times, ratios):
""" Checks that an insulin sensitivity schedule is reasonable """
if any(value < 10 or value > 500 for value in ratios):
warnings.warn(
"Warning: data contains sensitivity values < 10 or > 500"
... | 6d9f4c3e3052a3a6b25b11adf090bd468be553f9 | 38,334 |
import re
def parse_query_string(query_string: str):
"""
This function will parse query string and subdivide it into following parts:
Parameters
----------
query_string : str
(see Experiment.select function for details)
Returns
-------
requirement_lesser : list
requiremen... | f0b3acaaac22b104edb1ebc913caa9fa53e2aa3d | 38,335 |
def product(seq):
"""
Calculates the result of multiplying all elements of a sequence together.
Parameters
----------
seq : iterable
"""
result = None
for val in seq:
if (result is None):
result = val
else:
result *= val
return result | 713edd96a8bcd7af4a2c7b51f07a41d7e82183d3 | 38,336 |
def get_integer(message, minimum, maximum):
"""Retrieves an integer value prompted from console,
in such a way that `minimum ≤ value ≤ maximum`
"""
while True:
try:
value = int(input(message))
if not minimum <= value <= maximum:
raise ValueError()
... | b3c0708a17b03c66555dfc41e12b2b33cab0914c | 38,337 |
import os
def config():
"""Get Watson configuration from the environment
:return: dict with keys 'url', 'username', and 'password'
"""
try:
return {
'url': os.environ['WATSON_URL'],
'username': os.environ['WATSON_USERNAME'],
'password': os.environ['WATSON_P... | ee24d002d263c66914008130728c38c8564e8300 | 38,338 |
import os
import subprocess
import locale
def RepoFiles(src_dir):
"""Return the list of files from the source git repository"""
git_bin = os.environ.get('GIT_BIN', 'git')
files = subprocess.check_output([git_bin, '-C', src_dir, 'ls-files'])
ret = files.decode(locale.getpreferredencoding()).splitlines()
ret.... | 38ab651e78d5fb3b7bf706e64a3141885aba1a2c | 38,340 |
def _resample_parameters(ihmm, states):
"""
Resample the underlying parameters of an iHMM given a state sequence; updates the HMM parameters
in-place.
"""
return None | 05db687dd68057074f488d0f7acff82557330044 | 38,341 |
import os
def read_pid_file(filepath):
"""
Return the pid of the running process recorded in the file,
and return 0 if the acquisition fails.
"""
if not os.path.exists(filepath):
return 0
try:
with open(filepath, mode='r') as f:
pid = int(f.read())
if os.pa... | 677a92ab7451557ca7428ae9a54db7437bdd7796 | 38,342 |
import pkg_resources
def lexicon_version():
"""Retrieve current Lexicon version"""
try:
return pkg_resources.get_distribution('dns-lexicon').version
except pkg_resources.DistributionNotFound:
return 'unknown' | 7e29fe046957b5f904ca5e427344d702da86a9fb | 38,343 |
def get_smallest_entry(visited, distance):
""" Returns the position of the unvisited node with the smallest
distance. Returns None if no options are left. """
smallest = None
smallest_entry = None
for i in range(0, len(visited)):
if not visited[i] and distance[i] is not None:
if... | 5097ab5587c495a7fa8c14f173f1109bea55cb4a | 38,345 |
def __cve_details(data, db):
"""
Get a CVE details.
"""
_cve = data.parameter
_query = "SELECT cve_description FROM CVE WHERE cve LIKE ?;"
res = []
res_append = res.append
# Title
res_append("[*] Detail for CVE '%s':" % _cve)
r = db.raw(query=_query, parameters=(_cve,)).fetcho... | 3bf786e84095592ca861c939c4919c68afa67d4a | 38,347 |
def test_device(tmp_path):
"""Create an AVD configuration file."""
config_file = tmp_path / ".android" / "avd" / "testDevice.avd" / "config.ini"
config_file.parent.mkdir(parents=True)
# Write a default config. It contains:
# * blank lines
# * a key whose value explicitly contains an equals sign... | 0d99da2ed0669d96a367b4fe119a7de07b8f56fc | 38,348 |
def bounce(run_and_rollback):
""" Runs an input-output test for one or more values.
"""
def f(*values):
value_list = list(values)
def assertion(data, _):
assert data == [[value_list]]
run_and_rollback("RETURN $x", {"x": value_list}, assertion)
return f | 74d9624134998ddfcb48ed58666ad5501de8415b | 38,349 |
import random
def pick_one(namelist):
"""Pick a random name from the list"""
return random.choice(namelist) | 7b85e973942951b60362d5668fb7dd66b344bd93 | 38,350 |
def main():
"""lol"""
print(
"fat lol loaksjdk"
+ "hasjdhajkshd"
+ "ajsdhajkshdja"
+ "hasjdhajkshdkajshd"
)
hej = "tja"
return hej | 2701bfe1e4a2202b629e31cc627f4e28c5441030 | 38,351 |
def get_model_family_color(model_family):
"""Returns the canonical color for a model family."""
# Derived from sns.color_palette("colorblind").
canonical_colors = {
"vit": "#0173B2",
"bit": "#DE8F05",
"simclr": "#029E73",
"efficientnet-noisy-student": "#555555",
"wsl": "#CC78BC",
... | 41e304519b13aedc0db038a24c24984291540943 | 38,352 |
def is_module_available(module_name):
"""Return True if Python module is available"""
try:
__import__(module_name)
return True
except ImportError:
return False | 527092a60534e263dd9f8e8ce43bbfcb0ba19f31 | 38,355 |
def au_to_mkm(au: float) -> float:
"""
1 AU = 149,597,870.7 KM
:param au: dist in AU
:return: dist in millions of KM
"""
return au * 141.6 | 489fcf94c5c25ca99bcdd20a7a1df3c14a4e1ab3 | 38,356 |
def clean_data(data):
"""Return the list of data, replacing dashes with zeros.
Parameters
----------
data : list or str
The data to be cleaned
Returns
-------
cleaned_data : list of str
The data with dashes replaced with zeros
"""
cleaned_data = []
for item in ... | 6395e10fdb00b1a089e2f8ae048c3d8c45f9ec85 | 38,357 |
def find_id_ind(p_id, database):
"""Finds the index of the input patient in the database
Args:
p_id (str): the input patient ID
database (list of dict): Contains all entered patients
Returns:
"""
# Get a list of IDs in database
ids = [database[i]['patient_id'] for i in range(... | c481793a05a2ed620032d1581127fcea258ea74e | 38,358 |
import os
def path_neutral(path):
"""Convert a path specified using Unix path seperator into a
platform path"""
newpath = ""
for seg in path.split("/"):
if not seg:
newpath = os.sep
newpath = os.path.join(newpath, seg)
return newpath | 395c023ececa878993cdd9bbf4c02ed451d80f34 | 38,359 |
def format_date_key(date_field):
"""
format a datetime into year-month-date format
"""
return date_field.strftime('%Y-%m-%d') | 5db1a5624cf650427e64f3322e03dc6e9bd12e4b | 38,360 |
def filter_dual_selection(sele1_atoms, sele2_atoms, idx1, idx2):
"""
Filter interactions between selection 1 and selection 2
Parameters
----------
sele1_atoms: list
List of atom label strings for all atoms in selection 1
sele2_atoms: list
List of atom label strings for all atoms... | 11acadc1c958a021aeb1d7b0cb7345851b9a00ee | 38,361 |
def live_bart_station_map(col):
"""Change the mapping for the livr bart predictions to match the
index numbers used in the ml model."""
live_bart_station_mapping = \
{"North Concord/Martinez": 0, 'Powell St.': 1,
'Civic Center/UN Plaza': 2,
'16th St. Mission': 3, 'Union City': 4, 'D... | 251bfdf64d6f140bd1b60e1d8610b8d24057aed5 | 38,363 |
import yaml
def load_config_dict_from_file(fp):
"""Function to load a dict of configuration settings from a yaml file"""
with open(fp, 'r') as config_file:
config_dict = yaml.safe_load(config_file.read())
return config_dict | 50d07ffa7fdd7ab1523d8e48248b42dbf28e5b7b | 38,364 |
def _mark_maxima(holes_array):
"""Helper function which takes an array of hole energies and returns an
array for masking those which are not maxima."""
# create array to append to
not_maxima = []
width = holes_array.shape[1]
height = holes_array.shape[0]
# handle edge cases
for band in ... | 45c286e90511153f99e44e17acc5c52739f77e6f | 38,365 |
def nav(root, items):
"""Access a nested object in root by item sequence."""
for k in items: root = root[k]
return root | 357b735c548ac2124941d5c8e8b53b73638d0d92 | 38,366 |
def ExtractDictValues(PS_coords, MIX_coords):
"""Loop through the temperatures and replace the coordinates
with the number of phase separated and the number of mixed
vacuoles at each temperature."""
## Set up a new dictionary of temperatures and counted coordinates
PS_num = {}
MIX_num = {}
## Loop through th... | 5fdc56c4957cf75ce016b92c17d9250c42a735ea | 38,367 |
def _lazy_call(self, args=(), kwargs={}):
"""
Lazy evaluation for callable.
"""
return self(*args, **kwargs) | db63526c9e86620d0eb17929eb2730e8ef488982 | 38,369 |
def adjacents(ls, f, res):
"""" Apply a function to the head and the next. """
if len(ls) == 0:
return res
first = ls[0]
if len(ls) == 1:
next = None
else:
next = ls[1]
res.append(f(first, next))
return adjacents(ls[1:], f, res) | e8661fac66d1bb74e5b81e9f91e39e3cdcce9c62 | 38,370 |
from typing import Iterable
from typing import Dict
from typing import Any
def downgrade_filters(native_filters: Iterable[Dict[str, Any]]) -> int:
"""
Move `defaultDataMask.filterState` into `defaultValue`
"""
changed_filters = 0
for native_filter in native_filters:
default_data_mask = nat... | eb7f752ec56c4a05cf32908142be5f6362c89bdc | 38,372 |
import inspect
def describe_class(obj):
""" Describe the class object passed as argument,
including its methods """
methods = []
cl = obj.__class__
print ('Class: %s' % cl.__name__)
count = 0
for name in cl.__dict__:
item = getattr(cl, name)
if inspect.ismethod(item):
... | 792bc51b4817b3c475420cdd5c50b53449a70b0f | 38,374 |
def lr_scheduler(optimizer, epoch, lr_decay=0.3, lr_decay_epoch=2, number_of_decay=5):
"""
lr_scheduler method is written for decay learning rate by a factor of lr_decay
every lr_decay_epoch epochs
:param optimizer: input optimizer
:param epoch: epoch number
:param lr_decay: the rate of reductio... | 887c013f4f1efbe4cc6ebb1479d678df58f9a00c | 38,377 |
def generate_latex_table(results, header=None, caption=None, label=None):
"""
Generates a string latex table from a sequence of sequence.
Args:
result: 2d sequence of arbitrary types.
header: optional header
Returns:
String representation of Latex table with data.
"""
b... | 83a3bd9667b2ab52d0f96a29736d59d77417552e | 38,378 |
async def startlist() -> dict:
"""Create a startlist object."""
return {
"id": "startlist_1",
"event_id": "event_1",
"no_of_contestants": 0,
"start_entries": [],
} | f66299795bfb674b7e97396200d381022c4413a2 | 38,379 |
import pathlib
def get_cache_dir(predefined_path=None):
"""Get the cache directory path and potentially create it.
If no predefined path provided, we simply take `~/.mltype`.
Note that if one changes the `os.environ["home"]` dynamically
it will influence the output of this function. this is done
... | 8c2ff5ecc40a1d3d1399b4f02ddb04759938430e | 38,380 |
import os
def make_symlink(src, path):
"""
Makes a symlink from a source file `src` into a path.
Will not overwrite real files.
Parameters
----------
src: source filename
path: path to make symlink into
Returns
-------
succeess: bool
"""
_, file... | 2a3013f1f2712e995aba94e012e875d6462ac251 | 38,382 |
import ipaddress
def ip_address(s):
"""Validate ip address input"""
return str(ipaddress.ip_address(s)) | 43a1c02482bdda3c1d9ac14bfdd89cab22b85a5c | 38,383 |
def twoValueImage(image, G, background='white'):
"""将图像变黑白
:param image: Image对象
:param G: 阈值
:param background 背景颜色, 默认为白色
:return: Image对象
"""
# 转成灰度图
image = image.convert('L')
# image.show()
for y in range(0, image.size[1]):
for x in range(0, image.size[0]):
... | 1569b704040af53e2185c18d369be7dfa4ace34b | 38,386 |
def remove_domain(hn):
"""Removes domain suffix from provided hostname string
Args:
hn (str): fully qualified dns hostname
Returns:
str: hostname left by removing domain suffix
"""
return hn.split(".")[0] | 07e5136d06f4206f7cd071cda14d3db677f7a37b | 38,387 |
def DecodeHumanMv(Human_mv: str) -> str:
"""
param:
Human_mv: str #[x, y, c]#[x, y, c]
return:
mv: list of int [x_src, y_src, x_dst, y_dst]
"""
Human_mv = Human_mv.strip() # str #[]#[]
templist = Human_mv.split('#')[1:] # list [[x, y, c], [x, y, c]]
x_src = templist[0][1:-1... | 3829c96e3005290cb9d576d02803b6559e7918d5 | 38,388 |
from pathlib import Path
def output_dir():
"""Static output directory."""
return str(
Path(__file__).resolve().parent / Path("data")
) | 3248bfabbb25612a48a19fcda30d47bd4a27f5c6 | 38,390 |
def take_while(predicate, list):
"""Returns a new list containing the first n elements of a given list,
passing each value to the supplied predicate function, and terminating when
the predicate function returns false. Excludes the element that caused the
predicate function to fail. The predicate functio... | 6da969ad692071943fa0c4b2eaf3d5f12c80cd1b | 38,393 |
def quick_sort(arr_raw, low, high):
"""
args:
arr_raw: list to be sorted
return:
arr_sort: list sorted
"""
def helper(arr, low, high):
# recurrent helper
pivtol = arr[high] # center for partition
pivtol_pos = high # record the psotion
high -= 1 # s... | 4e8dcc4a18317784096b59c0a7a10c4c6be6bb38 | 38,394 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.