content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def val2str(val):
"""Writes values to a string.
Args:
val (any): Any object that should be represented by a string.
Returns:
valstr (str): String representation of `val`.
"""
# Return the input if it's a string
if isinstance(val,str ): valstr=val
# Handle types where sp... | c8f26553ceeeef841239c534815f86293f91086a | 2,542 |
import glob
def getFiles(regex, camera, mjdToIngest = None, mjdthreshold = None, days = None, atlasroot='/atlas/', options = None):
"""getFiles.
Args:
regex:
camera:
mjdToIngest:
mjdthreshold:
days:
atlasroot:
options:
"""
# If mjdToIngest is de... | 8d61d2e1900413d55e2cfc590fb6c969dd31b441 | 2,544 |
def return_limit(x):
"""Returns the standardized values of the series"""
dizionario_limite = {'BENZENE': 5,
'NO2': 200,
'O3': 180,
'PM10': 50,
'PM2.5': 25}
return dizionario_limite[x] | 92d40eaef7b47c3a20b9bcf1f7fd72510a05d9b2 | 2,545 |
def npaths(x, y):
"""
Count paths recursively. Memoizing makes this efficient.
"""
if x>0 and y>0:
return npaths(x-1, y) + npaths(x, y-1)
if x>0:
return npaths(x-1, y)
if y>0:
return npaths(x, y-1)
return 1 | 487a1f35b1bf825ffaf6bbf1ed86eb51f6cf18e9 | 2,546 |
import re
def joinAges(dataDict):
"""Merges columns by county, dropping ages"""
popColumns = list(dataDict.values())[0].columns.tolist()
popColumns = [re.sub("[^0-9]", "", column) for column in popColumns]
dictOut = dict()
for compartmentName, table in dataDict.items():
table.columns = pop... | d83ee4883ba58f7090141c131c4e111a4805f15d | 2,547 |
def alias(*alias):
"""Select a (list of) alias(es)."""
valias = [t for t in alias]
return {"alias": valias} | b2ff51f33b601468b1ba4d371bd5abd6d013a188 | 2,549 |
import json
def read_json_info(fname):
"""
Parse info from the video information file.
Returns: Dictionary containing information on podcast episode.
"""
with open(fname) as fin:
return json.load(fin) | 1eed945ce2917cbca1fb807a807ab57229622374 | 2,550 |
import os
def create_output_directory(input_directory):
"""Creates new directory and returns its path"""
output_directory = ''
increment = 0
done_creating_directory = False
while not done_creating_directory:
try:
if input_directory.endswith('/'):
output_director... | b2496045e8c9fbd627c32ea40a7b77181b7f4c1d | 2,551 |
def change_box(base_image,box,change_array):
"""
Assumption 1: Contents of box are as follows
[x1 ,y2 ,width ,height]
"""
height, width, _ = base_image.shape
new_box = [0,0,0,0]
for i,value in enumerate(change_array):
if value != 0:
new_box[i] = box[i] + valu... | 960b9f2c3ab1b65e9c7a708eac700dfaf65c67ac | 2,552 |
import hashlib
def get_hash_name(feed_id):
"""
用户提交的订阅源,根据hash值生成唯一标识
"""
return hashlib.md5(feed_id.encode('utf8')).hexdigest() | edd1caf943635a091c79831cc6151ecfa840e435 | 2,555 |
def trip2str(trip):
""" Pretty-printing. """
header = "{} {} {} - {}:".format(trip['departureTime'],
trip['departureDate'], trip['origin'],
trip['destination'])
output = [header]
for subtrip in trip['trip']:
originstr = u'... | 67daf3feb6b81d40d3102a8c610b20e68571b131 | 2,557 |
def station_suffix(station_type):
""" Simple switch, map specific types on to single letter. """
suffix = ' (No Dock)'
if 'Planetary' in station_type and station_type != 'Planetary Settlement':
suffix = ' (P)'
elif 'Starport' in station_type:
suffix = ' (L)'
elif 'Asteroid' in statio... | c28c4d3f0da8401ffc0721a984ec2b2e2cd50b24 | 2,558 |
import csv
def import_capitals_from_csv(path):
"""Imports a dictionary that maps country names to capital names.
@param string path: The path of the CSV file to import this data from.
@return dict: A dictionary of the format {"Germany": "Berlin", "Finland": "Helsinki", ...}
"""
capitals = {}
... | 3c6a9c91df455cb8721371fe40b248fb7af8d866 | 2,559 |
import os
import configparser
def read_config(config_file='config.ini'):
"""
Read the configuration file.
:param str config_file: Path to the configuration file.
:return:
"""
if os.path.isfile(config_file) is False:
raise NameError(config_file, 'not found')
config = configparser.C... | 0cafb2f280e30467e833d404ac86a8cea03f050a | 2,560 |
import pathlib
def example_data():
"""Example data setup"""
tdata = (
pathlib.Path(__file__).parent.absolute() / "data" / "ident-example-support.txt"
)
return tdata | a8c9a88f8850fecc7cc05fb8c9c18e03778f3365 | 2,562 |
def add_ending_slash(directory: str) -> str:
"""add_ending_slash function
Args:
directory (str): directory that you want to add ending slash
Returns:
str: directory name with slash at the end
Examples:
>>> add_ending_slash("./data")
"./data/"
"""
if directory[-... | 2062a55b59707dd48e5ae56d8d094c806d8a2c1d | 2,563 |
def pre_arrange_cols(dataframe):
"""
DOCSTRING
:param dataframe:
:return:
"""
col_name = dataframe.columns.values[0]
dataframe.loc[-1] = col_name
dataframe.index = dataframe.index + 1
dataframe = dataframe.sort_index()
dataframe = dataframe.rename(index=str, columns={col_name: 'a... | 522c0f4ca29b10d4a736d27f07d8e9dc80cafba5 | 2,564 |
import re
def extractCompositeFigureStrings(latexString):
"""
Returns a list of latex figures as strings stripping out captions.
"""
# extract figures
figureStrings = re.findall(r"\\begin{figure}.*?\\end{figure}", latexString, re.S)
# filter composite figures only and remove captions (preserv... | 83a80c91890d13a6a0247745835e1ffb97d579f7 | 2,565 |
import re
def BCA_formula_from_str(BCA_str):
"""
Get chemical formula string from BCA string
Args:
BCA_str: BCA ratio string (e.g. 'B3C1A1')
"""
if len(BCA_str)==6 and BCA_str[:3]=='BCA':
# format: BCAxyz. suitable for single-digit integer x,y,z
funits = BCA_str[-3:]
e... | 36375e62d70995628e253ba68ba8b777eb88d728 | 2,570 |
import argparse
import os
def arg_parse(dataset, view, num_shots=2, cv_number=5):
"""
arguments definition method
"""
parser = argparse.ArgumentParser(description='Graph Classification')
parser.add_argument('--mode', type=str, default='train', choices=['train', 'test'])
parser.a... | 4758fb939584f0433fb669fd03939d54c498f375 | 2,571 |
import optparse
def ParseArgs():
"""Parses command line options.
Returns:
An options object as from optparse.OptionsParser.parse_args()
"""
parser = optparse.OptionParser()
parser.add_option('--android-sdk', help='path to the Android SDK folder')
parser.add_option('--android-sdk-tools',
... | 492894d0cb4faf004f386ee0f4285180d0a6c37d | 2,572 |
import codecs
def get_text(string, start, end, bom=True):
"""This method correctly accesses slices of strings using character
start/end offsets referring to UTF-16 encoded bytes. This allows
for using character offsets generated by Rosette (and other softwares)
that use UTF-16 native string represent... | ffe3c74a248215a82b0e0a5b105f5e4c94c8c2a8 | 2,573 |
def merge_date_tags(path, k):
"""called when encountering only tags in an element ( no text, nor mixed tag and text)
Arguments:
path {list} -- path of the element containing the tags
k {string} -- name of the element containing the tags
Returns:
whatever type you want -- th... | 2ae3bd0dada288b138ee450103c0b4412a841336 | 2,575 |
def first_item(iterable, default=None):
"""
Returns the first item of given iterable.
Parameters
----------
iterable : iterable
Iterable
default : object
Default value if the iterable is empty.
Returns
-------
object
First iterable item.
"""
if not ... | f5ebbaea7cf4152382fb4b2854f68a3320d21fdc | 2,577 |
def rank(value_to_be_ranked, value_providing_rank):
"""
Returns the rank of ``value_to_be_ranked`` in set of values, ``values``.
Works even if ``values`` is a non-orderable collection (e.g., a set).
A binary search would be an optimized way of doing this if we can constrain
``values`` to be an order... | 18c2009eb59b62a2a3c63c69d55f84a6f51e5953 | 2,579 |
def fixedcase_word(w, truelist=None):
"""Returns True if w should be fixed-case, None if unsure."""
if truelist is not None and w in truelist:
return True
if any(c.isupper() for c in w[1:]):
# tokenized word with noninitial uppercase
return True
if len(w) == 1 and w.isupper() and... | 9047866f7117e8b1e4090c8e217c3063cfd37c38 | 2,580 |
def get_salesforce_log_files():
"""Helper function to get a list available log files"""
return {
"totalSize": 2,
"done": True,
"records": [
{
"attributes": {
"type": "EventLogFile",
"url": "/services/data/v32.0/sobjects/... | 1c182898517d73c360e9f2ab36b902afea8c58d7 | 2,581 |
def remove_true_false_edges(dict_snapshots, dict_weights, index):
"""
Remove chosen true edges from the graph so the embedding could be calculated without them.
:param dict_snapshots: Dict where keys are times and values are a list of edges for each time stamp.
:param dict_weights: Dict where keys are t... | 3f833fda22710c20703aa7590eae0fd649b69634 | 2,582 |
def get_specific_pos_value(img, pos):
"""
Parameters
----------
img : ndarray
image data.
pos : list
pos[0] is horizontal coordinate, pos[1] is verical coordinate.
"""
return img[pos[1], pos[0]] | 3929b29fa307a7e8b5282783c16639cacb2ab805 | 2,583 |
import re
def mrefresh_to_relurl(content):
"""Get a relative url from the contents of a metarefresh tag"""
urlstart = re.compile('.*URL=')
_, url = content.split(';')
url = urlstart.sub('', url)
return url | 90cc3dbace5d4b001698612f9263309fa95aac8b | 2,584 |
import logging
def get_previous_version(versions: dict, app: str) -> str:
"""Looks in the app's .version_history to retrieve the prior version"""
try:
with open(f"{app}/.version_history", "r") as fh:
lines = [line.strip() for line in fh]
except FileNotFoundError:
logging.warnin... | d3a4aec5c3bc842181aa3901971774761866c3e5 | 2,585 |
def ToHexStr(num):
"""
将返回的错误码转换为十六进制显示
:param num: 错误码 字符串
:return: 十六进制字符串
"""
chaDic = {10: 'a', 11: 'b', 12: 'c', 13: 'd', 14: 'e', 15: 'f'}
hexStr = ""
if num < 0:
num = num + 2**32
while num >= 16:
digit = num % 16
hexStr = chaDic.get(digit, str(digit)) ... | b6cf482defdc9f4fcf9ce64903e7a718e096bacb | 2,587 |
import requests
def getSBMLFromBiomodelsURN(urn):
""" Get SBML string from given BioModels URN.
Searches for a BioModels identifier in the given urn and retrieves the SBML from biomodels.
For example:
urn:miriam:biomodels.db:BIOMD0000000003.xml
Handles redirects of the download page.
:p... | 9a28f4a0619ebed6f9e272d84331482442ae9fb8 | 2,588 |
from datetime import datetime
def naturalTimeDifference(value):
"""
Finds the difference between the datetime value given and now()
and returns appropriate humanize form
"""
if isinstance(value, datetime):
delta = datetime.now() - value
if delta.days > 6:
return val... | ce285358b1b99a4b2df460e6193d2a0970aa4eff | 2,589 |
import json
def process_info(args):
"""
Process a single json file
"""
fname, opts = args
with open(fname, 'r') as f:
ann = json.load(f)
f.close()
examples = []
skipped_instances = 0
for instance in ann:
components = instance['components']
if len(... | 8ade5b21db3cca57d9de91311fc57754161673de | 2,590 |
from typing import List
def min_offerings(heights: List[int]) -> int:
"""
Get the max increasing sequence on the left and the right side of current index,
leading upto the current index.
current index's value would be the max of both + 1.
"""
length = len(heights)
if length < 2:
r... | 952ea82815ecb4db6d4d0347f16b0cf5b299f7d3 | 2,592 |
import os
def get_csv_file_path(file_name: str) -> str:
"""
Get absolute path to csv metrics file
Parameters
----------
file_name
Name of metrics file
Returns
-------
file_path
Full path to csv file
"""
return os.path.join(os.getcwd(), file_name) | 67b80193a75669a0635cf70ab1325e755424d654 | 2,593 |
import re
def snake_case(name: str):
"""
https://stackoverflow.com/a/1176023/1371716
"""
name = re.sub('(\\.)', r'_', name)
name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
name = re.sub('__([A-Z])', r'_\1', name)
name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name)
return name.lower() | 4696ca3c1a50590aa6617ee3917b8364c11f3910 | 2,596 |
import glob
def get_loss_data():
"""
This function returns a list of paths to all .npy loss
files.
Returns
-------
path_list : list of strings
The list of paths to output files
"""
path = "./data/*_loss.npy"
path_list = glob.glob(path, recursive=True)
return path_lis... | bc98b0bdf60ac3f7125da82fd68956957e89a777 | 2,597 |
import string
def list_zero_alphabet() -> list:
"""Build a list: 0, a, b, c etc."""
score_dirs = ['0']
for char in string.ascii_lowercase:
score_dirs.append(char)
return score_dirs | 6cd9fc9e93257dcc7729235ac3cffa01dbd80c95 | 2,598 |
def dim_axis_label(dimensions, separator=', '):
"""
Returns an axis label for one or more dimensions.
"""
if not isinstance(dimensions, list): dimensions = [dimensions]
return separator.join([d.pprint_label for d in dimensions]) | f03e4eb02fc57890421bdcdaa0aea7d6541b8678 | 2,599 |
def _is_camel_case_ab(s, index):
"""Determine if the index is at 'aB', which is the start of a camel token.
For example, with 'workAt', this function detects 'kA'."""
return index >= 1 and s[index - 1].islower() and s[index].isupper() | c21ec7d8aa7e786d1ea523106af6f9426fea01d8 | 2,600 |
def rgb2hex(rgb: tuple) -> str:
"""
Converts RGB tuple format to HEX string
:param rgb:
:return: hex string
"""
return '#%02x%02x%02x' % rgb | 1ecb1ca68fa3dbe7b58f74c2e50f76175e9a0c5a | 2,601 |
import os
import shutil
def update_copy(src, dest):
"""
Possibly copy `src` to `dest`. No copy unless `src` exists.
Copy if `dest` does not exist, or mtime of dest is older than
of `src`.
Returns: None
"""
if os.path.exists(src):
if (not os.path.exists(dest) or
os.path... | 4f83e633d9348cf8273309707713060e5611c277 | 2,602 |
def unix_to_windows_path(path_to_convert, drive_letter='C'):
"""
For a string representing a POSIX compatible path (usually
starting with either '~' or '/'), returns a string representing an
equivalent Windows compatible path together with a drive letter.
Parameters
----------
path_to_conve... | d3c23e2c19be4b81be135ae84760430be852da41 | 2,603 |
def flatten(iterable):
"""
Unpacks nested iterables into the root `iterable`.
Examples:
```python
from flashback.iterating import flatten
for item in flatten(["a", ["b", ["c", "d"]], "e"]):
print(item)
#=> "a"
#=> "b"
#=> "c"
#=> "d"
... | 8c47de3255906fb114a13ecfec4bf4a1204a0dfd | 2,604 |
import random
def _sample(probabilities, population_size):
"""Return a random population, drawn with regard to a set of probabilities"""
population = []
for _ in range(population_size):
solution = []
for probability in probabilities:
# probability of 1.0: always 1
#... | ac781075f8437ea02b2dde3b241c21685c259e0c | 2,605 |
def decode_labels(labels):
"""Validate labels."""
labels_decode = []
for label in labels:
if not isinstance(label, str):
if isinstance(label, int):
label = str(label)
else:
label = label.decode('utf-8').replace('"', '')
labels_decode... | 36b8b10af2cd2868ab1923ccd1e620ccf815d91a | 2,606 |
from pathlib import Path
def _path_to_str(var):
"""Make sure var is a string or Path, return string representation."""
if not isinstance(var, (Path, str)):
raise ValueError("All path parameters must be either strings or "
"pathlib.Path objects. Found type %s." % type(var))
... | c5ae3ed06be31de3220b5400966866ccda29b9fc | 2,607 |
def form_cleaner(querydict):
"""
Hacky way to transform form data into readable data by the model constructor
:param querydict: QueryDict
:return: dict
"""
r = dict(querydict.copy())
# Delete the CRSF Token
del r['csrfmiddlewaretoken']
for key in list(r):
# Take first element... | 83d61f028748132803555da85f0afe0215be2edd | 2,611 |
def has_1080p(manifest):
"""Return True if any of the video tracks in manifest have a 1080p profile
available, else False"""
return any(video['width'] >= 1920
for video in manifest['videoTracks'][0]['downloadables']) | f187ff7fd8f304c0cfe600c4bed8e809c4c5e105 | 2,612 |
import os
def get_filename(filePath):
"""get filename without file extension from file path
"""
absFilePath = os.path.abspath(filePath)
return os.path.basename(os.path.splitext(absFilePath)[0]) | e9ccddf29f38f88ccd65764a2914689611b142e8 | 2,613 |
def default_k_pattern(n_pattern):
""" the default number of pattern divisions for crossvalidation
minimum number of patterns is 3*k_pattern. Thus for n_pattern <=9 this
returns 2. From there it grows gradually until 5 groups are made for 40
patterns. From this point onwards the number of groups is kept ... | 60d083ffed24987882fa8074d99e37d06748eaf3 | 2,616 |
def _cast_wf(wf):
"""Cast wf to a list of ints"""
if not isinstance(wf, list):
if str(type(wf)) == "<class 'numpy.ndarray'>":
# see https://stackoverflow.com/questions/2060628/reading-wav-files-in-python
wf = wf.tolist() # list(wf) does not convert int16 to int
else:
... | cf2bf853b3ac021777a65d5323de6990d8dc4c5c | 2,617 |
def ms(val):
""" Turn a float value into milliseconds as an integer. """
return int(val * 1000) | 97f7d736ead998014a2026a430bf3f0c54042010 | 2,619 |
def order_json_objects(obj):
"""
Recusively orders all elemts in a Json object.
Source:
https://stackoverflow.com/questions/25851183/how-to-compare-two-json-objects-with-the-same-elements-in-a-different-order-equa
"""
if isinstance(obj, dict):
return sorted((k, order_json_objects(v)) for... | 5a0459d227b0a98c536290e3e72b76424d29820c | 2,621 |
import torch
def compute_rays_length(rays_d):
"""Compute ray length.
Args:
rays_d: [R, 3] float tensor. Ray directions.
Returns:
rays_length: [R, 1] float tensor. Ray lengths.
"""
rays_length = torch.norm(rays_d, dim=-1, keepdim=True) # [N_rays, 1]
return rays_length | 9b43f9ea79708a690282a04eec65dbabf4a7ae36 | 2,623 |
import itertools
def _repeat_elements(arr, n):
"""
Repeats the elements int the input array, e.g.
[1, 2, 3] -> [1, 1, 1, 2, 2, 2, 3, 3, 3]
"""
ret = list(itertools.chain(*[list(itertools.repeat(elem, n)) for elem in arr]))
return ret | 95cf8ebb75505d2704cf957cdd709b8fa735973a | 2,624 |
def atlas_slice(atlas, slice_number):
"""
A function that pulls the data for a specific atlas slice.
Parameters
----------
atlas: nrrd
Atlas segmentation file that has a stack of slices.
slice_number: int
The number in the slice that corresponds to the fixed image
for r... | bafe5d886568203792b0f6178302f3ca5d536e5b | 2,627 |
from typing import Dict
import aiohttp
async def head(url: str) -> Dict:
"""Fetch headers returned http GET request.
:param str url:
The URL to perform the GET request for.
:rtype: dict
:returns:
dictionary of lowercase headers
"""
async with aiohttp.request("HEAD", url) as re... | b4decbfb4e92863c07c5202e2c884c02e590943f | 2,629 |
def _create_serialize(cls, serializers):
"""
Create a new serialize method with extra serializer functions.
"""
def serialize(self, value):
for serializer in serializers:
value = serializer(value)
value = super(cls, self).serialize(value)
return value
serialize._... | 522f6a14fe3e2bca70c141f14dc8b400be1ca680 | 2,630 |
def determine_if_pb_should_be_filtered(row, min_junc_after_stop_codon):
"""PB should be filtered if NMD, a truncation, or protein classification
is not likely protein coding (intergenic, antisense, fusion,...)
Args:
row (pandas Series): protein classification row
min_junc_after_stop_codon (... | 29ab7ce53ac7569c4d8a29e8e8564eab33b3f545 | 2,631 |
def encdec_model(input_shape, output_sequence_length, english_vocab_size, french_vocab_size):
"""
Build and train an encoder-decoder model on x and y
:param input_shape: Tuple of input shape
:param output_sequence_length: Length of output sequence
:param english_vocab_size: Number of unique English ... | 47fa1893cc04b491292461db6c8a3418b464ba45 | 2,632 |
def close_to_cron(crontab_time, time_struct):
"""coron的指定范围(crontab_time)中 最接近 指定时间 time_struct 的值"""
close_time = time_struct
cindex = 0
for val_struct in time_struct:
offset_min = val_struct
val_close = val_struct
for val_cron in crontab_time[cindex]:
offset_tmp = v... | 7ce04d9b4260e7ea1ed7c3e95e7c36928989024e | 2,633 |
def project_to_2D(xyz):
"""Projection to (0, X, Z) plane."""
return xyz[0], xyz[2] | c6cdb8bd6dce65f6ce39b14b9e56622832f35752 | 2,634 |
def create_updated_alert_from_slack_message(payload, time, alert_json):
"""
Create an updated raw alert (json) from an update request in Slack
"""
values = payload['view']['state']['values']
for value in values:
for key in values[value]:
if key == 'alert_id':
cont... | a685a0c0da472f055dc8860bdf09970a1ecc8aff | 2,635 |
def enforce(*types):
"""
decorator function enforcing, and converting, argument data types
"""
def decorator(fn):
def new_function(*args, **kwargs):
# convert args into something mutable, list in this case
newargs = []
for original_argument, type_to_convert in... | 217ad3adccdaa9fc83ceaf5ef2c0905b8d54f1ed | 2,636 |
from typing import List
def _get_rec_suffix(operations:List[str]) -> str:
""" finished, checked,
Parameters
----------
operations: list of str,
names of operations to perform (or has performed),
Returns
-------
suffix: str,
suffix of the filename of the preprocessed ecg s... | 270a1b3749342d05819eafef3fa5175da393b1ad | 2,639 |
def get_A_text(params, func_type=None):
"""
Get text associated with the fit of A(s)
"""
line1 = r'$A(s|r)$ is assumed to take the form:'
line2 = (r'$A(s|r) = s^{-1}\bigg{(}\frac{s}{\Sigma(r)}\bigg{)}^a '
r'exp\bigg{(}{-\bigg{(}\frac{s}{\Sigma(r)}\bigg{)}^b}\bigg{)}$')
a, b = params... | ec68c49a7912dc5630e3c96a09d667ce52f89914 | 2,640 |
def transform_to_dict(closest_list: list) -> dict:
"""
Returns dict {(latitude, longitude): {film1, film2, ...}, ...} from
closest_list [[film1, (latitude, longitude)], ...], where film1,
film2 are titles of films, (latitude, longitude) is a coordinates of
a place where those films were shoot.
... | e7c6fae73792a828d85db03e794bfb69c7b1fe87 | 2,641 |
def dms2dd(s):
"""convert lat and long to decimal degrees"""
direction = s[-1]
degrees = s[0:4]
dd = float(degrees)
if direction in ('S','W'):
dd*= -1
return dd | cb76efbf8c3b6a75bcc26593fab81a8ef3e16bbf | 2,643 |
import signal
def _signal_exit_code(signum: signal.Signals) -> int:
"""
Return the exit code corresponding to a received signal.
Conventionally, when a program exits due to a signal its exit code is 128
plus the signal number.
"""
return 128 + int(signum) | 050eee98632216fddcbd71e4eb6b0c973f6d4144 | 2,645 |
def is_contained(target, keys):
"""Check is the target json object contained specified keys
:param target: target json object
:param keys: keys
:return: True if all of keys contained or False if anyone is not contained
Invalid parameters is always return False.
"""
if not target or not key... | 948196d4b470788199506bd7768e03554fa67b40 | 2,646 |
def map(x, in_min, in_max, out_min, out_max):
"""
Map a value from one range to another
:param in_min: minimum of input range
:param in_max: maximum of input range
:param out_min: minimum of output range
:param out_max: maximum of output range
:return: The value scaled ... | 4117af35b0061df1fd271306accf198692442dac | 2,647 |
import time
import sys
def mock_tensorboard(logdir, host, port, print_nonsense, print_nothing,
address_in_use, sleep_time):
"""Run fake TensorBoard."""
if logdir is None:
print('A logdir must be specified. Run `tensorboard --help` for '
'details and examples.')
... | 26a793264fa9561fabc9fa9d2fcb1377a6b60783 | 2,648 |
def get_chord_type(chord):
"""'Parses' input for a chord and returns the type of chord from it"""
cleaned_chord = chord[1:]
cleaned_chord = cleaned_chord.replace('b', '')
cleaned_chord = cleaned_chord.replace('#', '')
mapping = {
'7': 'seven',
'9': 'nine',
'm7': 'minor7',
... | 4a753eb31f1e33340a7aa4df6942c4752b208fdd | 2,649 |
def file_base_features(path, record_type):
"""Return values for BASE_SCHEMA features."""
base_feature_dict = {
"record_id": path,
"record_type": record_type,
# "utc_last_access": os.stat(path).st_atime,
"utc_last_access": 1600000000.0,
}
return base_feature_dict | 12f16684002892d7af59a1e26e8a40501098ca4f | 2,650 |
import itertools
def node_extractor(dataframe, *columns):
"""
Extracts the set of nodes from a given dataframe.
:param dataframe: dataframe from which to extract the node list
:param columns: list of column names that contain nodes
:return: list of all unique nodes that appear in the provided data... | 7a4ab889257a0f2c5ddfe18e65d0a7f5f35d8d98 | 2,651 |
def _apply_attention_constraint(
e, last_attended_idx, backward_window=1, forward_window=3
):
"""Apply monotonic attention constraint.
**Note** This function is copied from espnet.nets.pytorch_backend.rnn.attention.py
"""
if e.size(0) != 1:
raise NotImplementedError(
"Batch atten... | 213ef514a9cff31134185e38c57d46921eba763a | 2,652 |
def _prepare_memoization_key(args, kwargs):
"""
Make a tuple of arguments which can be used as a key
for a memoized function's lookup_table. If some object can't be hashed
then used its __repr__ instead.
"""
key_list = []
for arg in args:
try:
hash(arg)
key_li... | c83e08c42886ba0e7f6e4defe5bc8f53f5682657 | 2,655 |
def day_log_add_id(day_log):
"""
その日のログにID(day_id)を割り振る
:param day_log:
:return:
"""
for v in range(len(day_log)):
day_log[v]['day_id'] = v + 1
return day_log | c4608b07e86c074a11cf78d171490ec152092eeb | 2,656 |
def brillance(p, g, m = 255):
"""
p < 0 : diminution de la brillance
p > 0 : augmentation de la brillance
"""
if (p + g < m + 1) and (p + g > 0):
return int(p + g)
elif p + g <= 0:
return 0
else:
return m | b40169e487521c146c4c0777517492205951cf16 | 2,657 |
def by_tag(articles_by_tag, tag):
""" Filter a list of (tag, articles) to list of articles by tag"""
for a in articles_by_tag:
if a[0].slug == tag:
return a[1] | 642472a89cb624ed02a6e8ec488b72856ac231a9 | 2,658 |
def dp_port_id(switch: str, port: str) -> str:
"""
Return a unique id of a DP switch port based on switch name and port name
:param switch:
:param port:
:return:
"""
return 'port+' + switch + ':' + port | 479891e41b51114744dcbb2b177180c19cd1bfd5 | 2,659 |
import csv
def read_csv(file_path, delimiter=",", encoding="utf-8"):
"""
Reads a CSV file
Parameters
----------
file_path : str
delimiter : str
encoding : str
Returns
-------
collection
"""
with open(file_path, encoding=encoding) as file:
data_in = list(csv.... | a4f1da219b0e5d752ff606614e93abbfc3d30597 | 2,660 |
import importlib
def import_activity_class(activity_name, reload=True):
"""
Given an activity subclass name as activity_name,
attempt to lazy load the class when needed
"""
try:
module_name = "activity." + activity_name
importlib.import_module(module_name)
return True
e... | b4cea3fad1f08a5758972847d3e03a41f89f223c | 2,661 |
def extract_arguments(start, string):
""" Return the list of arguments in the upcoming function parameter closure.
Example:
string (input): '(blocks, threads, 0, THCState_getCurrentStream(state))'
arguments (output):
'[{'start': 1, 'end': 7},
{'start': 8, 'end': 16},
... | 8e6e3fecc0643aa3f55108916a7c6892a96f13aa | 2,662 |
def tuple_list_to_lua(tuple_list):
"""Given a list of tuples, return a lua table of tables"""
def table(it):
return "{" + ",".join(map(str, it)) + "}"
return table(table(t) for t in tuple_list) | 71ec1a29f5e23b8bf82867617fe157fbba4a2332 | 2,664 |
def fancy_vector(v):
"""
Returns a given 3-vector or array in a cute way on the shell, if you
use 'print' on the return value.
"""
return "\n / %5.2F \\\n" % (v[0]) + \
" | %5.2F |\n" % (v[1]) + \
" \\ %5.2F /\n" % (v[2]) | 2340f22aa87da00abad30b9946c374f34b38496d | 2,665 |
def any_of(elements):
"""
Check to see if the argument is contained in a list of possible elements.
:param elements: The elements to check the argument against in the predicate.
:return: A predicate to check if the argument is a constituent element.
"""
def predicate(argument):
return a... | adacf8fd632d25452d22dab0a8a439021083ec83 | 2,666 |
def find_year(films_lst: list, year: int):
""" Filter list of films by given year """
filtered_films_lst = [line for line in films_lst if line[1] == str(year)]
return filtered_films_lst | f4c11e09e76831afcf49154234dd57044536bce1 | 2,667 |
import torch
def batch_eye_like(X: torch.Tensor):
"""Return batch of identity matrices like given batch of matrices `X`."""
return torch.eye(*X.shape[1:], out=torch.empty_like(X))[None, :, :].repeat(X.size(0), 1, 1) | 266ee5639ce303b81e2cb82892e64f37a09695ff | 2,668 |
def cal_occurence(correspoding_text_number_list):
"""
calcualte each occurence of a number in a list
"""
di = dict()
for i in correspoding_text_number_list:
i = str(i)
s = di.get(i, 0)
if s == 0:
di[i] = 1
else:
di[i] = di[i] + 1
return di | aafabc6abdf4bf1df1b8d9e23a4af375df3ac75b | 2,669 |
def booleans(key, val):
"""returns ucsc formatted boolean"""
if val in (1, True, "on", "On", "ON"):
val = "on"
else:
val = "off"
return val | f210a2ce6b998e65d2e5934f1318efea0f96c709 | 2,670 |
def ConvertVolumeSizeString(volume_size_gb):
"""Converts the volume size defined in the schema to an int."""
volume_sizes = {
"500 GB (128 GB PD SSD x 4)": 500,
"1000 GB (256 GB PD SSD x 4)": 1000,
}
return volume_sizes[volume_size_gb] | b1f90e5ded4d543d88c4f129ea6ac03aeda0c04d | 2,671 |
def get_snps(x: str) -> tuple:
"""Parse a SNP line and return name, chromsome, position."""
snp, loc = x.split(' ')
chrom, position = loc.strip('()').split(':')
return snp, chrom, int(position) | 52672c550c914d70033ab45fd582fb9e0f97f023 | 2,672 |
import torch
def compute_i_th_moment_batches(input, i):
"""
compute the i-th moment for every feature map in the batch
:param input: tensor
:param i: the moment to be computed
:return:
"""
n, c, h, w = input.size()
input = input.view(n, c, -1)
mean = torch.mean(input, dim=2).view(n... | 2ab3b7bfd34b482cdf55d5a066b57852182b5b6a | 2,673 |
import argparse
def parse_options():
"""Parses and checks the command-line options.
Returns:
A tuple containing the options structure.
"""
usage = 'Usage: ./update_mapping.py [options]'
desc = ('Example: ./update_mapping.py -o mapping.json.\n'
'This script generates and stores a file that gives the\n... | 7f7ee6a90e152023dbf6c6e163361a8c327108ae | 2,674 |
def read_plot_pars() :
"""
Parameters are (in this order):
Minimum box width,
Maximum box width,
Box width iterations,
Minimum box length,
Maximum box length,
Box length iterations,
Voltage difference
"""
def extract_parameter_from_string(string):
#returns the part ... | c78dc8e2a86b20eb6007850a70c038de5bf9f841 | 2,675 |
def get_upper_parentwidget(widget, parent_position: int):
"""This function replaces this:
self.parentWidget().parentWidget().parentWidget()
with this:
get_upper_parentwidget(self, 3)
:param widget: QWidget
:param parent_position: Which parent
:return: Wanted parent widget
... | ff010f3d9e000cfa3c58160e150c858490f2412d | 2,676 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.