content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def get_height_of_objects(tet_file):
"""Return the height of the test object."""
mesh_lines = list(open(tet_file, "r"))
mesh_lines = [line.strip('\n') for line in mesh_lines]
zs = []
for ml in mesh_lines:
sp = ml.split(" ")
if sp[0] == 'v':
zs.append(float(sp[3]))
ret... | 9e763feb24a774cdcbc4c0a1ee13a8f0a4253989 | 57,001 |
def add_element_to_dict(dictionary, element):
""" Adds an element to a dictionary. If not in dictionary, adds a new key to dictionary.
:param dictionary: dictionary
:param element: string
:return: updated dictionary
"""
if len(element) == 1:
return dictionary
if element not in dict... | d55e0124e9b940b3cfcbf94674a2009ae46b1f55 | 57,005 |
def generate_range(min: int, max: int, step: int) -> list:
""" This function generates a range of integers from min to max, with the step. """
return [i for i in range(min, max + 1, step)] | e0d0871d52b6ae671bfdcefb15c7bf55bc71fcfa | 57,012 |
import math
def rotate_image_point(x, y, xmid, ymid, angle):
""" rotate image point about xm, ym by angle in radians
Arguments:
x: x coordinate of point to rotate
y: y coordinate of point to rotate
xmid: x coordinate of center point to rotate about
ymid: y coordinate of ce... | 242cd09ac90ce0a7c4faf8c595232ee1a7f74441 | 57,016 |
def train_model(model, feature_matrix, train_values):
"""
Train classifier model
:param model: classifier model
:param feature_matrix: feature matrix
:param train_values: values to train the model on
:return: trained model
"""
model["classifier"].fit(feature_matrix, train_values)
ret... | f77819fba153c9dca0b397db7ad3c4c0d840083a | 57,017 |
def make_bigrams(bigram_mod, texts):
"""Form bigrams in text
Args:
bigram_mod (gensim.models.phrases.Phraser): Gensim bigram model
texts (list): 2-dimensional list of words
Returns:
(list): bigrams formed from texts
"""
return [bigram_mod[doc] for doc in texts] | 8a1aafb0c51852ee98432012743aa21494fb86c0 | 57,018 |
def deg_to_hms(deg):
"""Convert decimal degrees to (hr,min,sec)"""
h = int(deg)//15
deg -= h*15
m = int(deg*4)
s = (deg-m//4)/15.
return h,m,s | 6e400d79b7c74fb0dd27e24cb10e67fd79be11cb | 57,020 |
def logical_not(s):
"""
Return the logical negation of the given binary string
:param s: the string to convert
:type s: str
:return: str
"""
ns = ''
for c in s:
if c == '0':
ns += '1'
elif c == '1':
ns += '0'
else:
raise Excepti... | 196ec5da894f46988116a6fda3c9df195a50eda6 | 57,024 |
def substring_search(word, collection):
"""Finds all matches in the `collection` for the specified `word`.
If `word` is empty, returns all items in `collection`.
:type word: str
:param word: The substring to search for.
:type collection: collection, usually a list
:param collection: A collect... | dd200f02a7fe9ed09f01ad267c498d6bf32f6024 | 57,031 |
import math
def std_periodic_var(p, mid=0.0, pi=math.pi):
"""
Transform a periodic variable into its range.
>>> std_periodic_var(math.pi)
-3.1415...
>>> std_periodic_var(2*math.pi + 0.01)
0.0...
:param p: Value
:param mid: The middle value
:param pi: Half-range
:return: The ... | 4b7840e6dcc4c5d947c64e08c2a4555881c69013 | 57,035 |
import bz2
import gzip
def open_output(output, opts):
"""Open output file with right compression library
"""
if opts.bzip:
return bz2.open(output, 'wt')
elif opts.gzip:
return gzip.open(output, 'wt')
else:
return open(output, 'w') | 9f830afb3422f0707ef6b49c9b2000a35b4bc0a0 | 57,036 |
def setup_info_args(parser, parent):
"""Helper function to set up a subparser for the `info` command.
:param parser: argparse parser to add the `info` command to
:type args: argparse.ArgumentParser
:param parent: argparse parser parent of the newly added subcommand.
used to inherit s... | ef5b920fea2b00833b3194e90c38e881ce88b4ae | 57,042 |
def _splitstrip(string, delim=u','):
"""Split string (at commas by default) and strip whitespace from the
pieces.
"""
return [s.strip() for s in string.split(delim)] | 26b62cd6ff9f23908efa0e1be839f9171dbe9a78 | 57,045 |
from re import match
def valid_input(instructions):
"""
Validate input to be a multi-line string containing directions [UDLR]+
:param instructions: Multiline string input
:return: Boolean value whether input is valid
"""
m = match(r'[UDLR]+', ''.join(instructions))
return m is not None and... | 5e94b803c2a4659c217d5f42511de79140d52c6b | 57,056 |
def get_member_by_name(slack_client, user_name):
"""
Return the member matching the given user_name.
"""
memberList = slack_client.api_call("users.list")
if memberList and memberList['members']:
for member in memberList['members']:
if member['name'] == user_name:
... | 1e96454663e7b1f453e1433efff46d61f633045c | 57,070 |
def _remove_tags(tags, removals):
""" In all tags list, remove tags in removals. """
for tag in removals:
while tag in tags:
tags.remove(tag)
return tags | 0b194437d16935a11fe867309ffc3944b56506cf | 57,071 |
def extract_data_values(data, value_key):
"""Extract value from a pandas.DataFrame
Parmeters
---------
data : dict
The raw data.
value_key : string
A column in data which contains the values we are to extract.
Returns
-------
values : dict
A dict where the keys ... | 42d713bb7b3970c965e2c5f503032cd6fd66baf6 | 57,077 |
def get_deletions_x(parsed_mutations, max_mutations_per_pos_dict):
"""Get x coordinates of deletion markers to overlay in heatmap.
These are the linear x coordinates used in the Plotly graph object.
i.e., the indices of data["heatmap_x_nt_pos"]
:param parsed_mutations: A dictionary containing multiple... | 1e1b1042580e8260bfe1ae798fbcf38e85b76f0a | 57,083 |
from typing import List
from typing import Dict
def get_phrases(buckets: List, data: Dict) -> Dict[float, List[str]]:
"""
Returns a dictionary of (timestamp, words) where words contains the phrases spoken at `timestamp`.
:param buckets: Python list of bucket timestamps (from GT).
:param data: Dictionary of tim... | 48aa35198407fd2b562ef81a7fed5e8a2db8219e | 57,086 |
import json
import requests
def parse_github(username):
"""
This function allows, according to a Github username, to return its node_id, its id as well as its name
Example:
parse_github("av1m") # ["MDQ6VXNlcjM2NDU2NzA5", 36456709, "Avi Mimoun"]
:param username: corresponds to the username Github... | c33ff1411fd72d388ea6fb86c4f74961e2fa1479 | 57,089 |
def is_single_word_predicate(node):
"""
Return true iff the node represents a single-word, non-implicit, predicate
"""
return node.isPredicate \
and (len(node.text) == 1) \
and (not node.is_implicit()) | b78f1dcdbf75dbf03ff22d3d14c6831cfc5f322a | 57,090 |
def has(l , key, value):
"""Check if list has dict with matching key-value pair
Parameters
----------
l : List[Dict[str, Any]]
List to check for matches
key : str
Key to find in list's dictionaries
value : Any
Value to be compared with value in suitable key-value pair in... | a11685f4fa5b2a9932260db16e96cbc0ca240326 | 57,093 |
def update_server_size(tests_dataframe):
"""
Creates a new column, server_size, set all values to 0.
Parameters:
tests_dataframe: DataFrame
pandas dataframe object
Returns:
tests_dataframe: DataFrame
dataframe object with server_size column
"""
tests_dat... | 115c1830362d58bfc371335078a2a2cbc17d2446 | 57,094 |
import re
def replace_term(text, old_term, new_term):
"""Replaces term in the text with another term"""
result = re.sub(old_term, new_term, text)
return result | 8c3e692ba90cf14c580ecd64a3a9030d85fdd2b3 | 57,099 |
import torch
from typing import List
def named_tensor_split(tensor: torch.Tensor, split_size: int, dim: str) \
-> List[torch.Tensor]:
"""
As working in torch.split but added list()
Args:
tensor (): the tensor to split
split_size (): the size of the splits
dim (): the dimens... | 0734623c159ad73c99bb4ba8cd5df675d5e2e063 | 57,107 |
def tzy_flatten(ll):
"""
Own flatten just for use of this context.
Expected outcome:
> flatten([1, 2, [3, 4], [5]])
[1, 2, 3, 4, 5]
Only goes 1 depth so should be O(n) time, but also O(n) space
"""
ret = []
for item in ll:
if isinstance(item, list):
for su... | 279fb4c3dec69d386e66ab3f56662dfa99e15079 | 57,109 |
def num_elements(num):
"""Return either "1 element" or "N elements" depending on the argument."""
return '1 element' if num == 1 else '%d elements' % num | 56c48771cba2c5b51aaf0a9ff58cd9aa7a8a81e6 | 57,112 |
def elements_adjacent(elements, index1, index2):
"""Check if two elements are adjacent."""
return (
elements[0, index1] == elements[0, index2]
or elements[0, index1] == elements[1, index2]
or elements[0, index1] == elements[2, index2]
or elements[1, index1] == elements[0, index2]... | 16a2d2d0cbd93199ffa21867dd4f4b6913f9b62a | 57,113 |
import torch
def mixture_consistency(mixture, est_sources, src_weights=None, dim=1):
""" Applies mixture consistency to a tensor of estimated sources.
Args
mixture (torch.Tensor): Mixture waveform or TF representation.
est_sources (torch.Tensor): Estimated sources waveforms or TF
... | 2ef8aa26b9c61edf989bbc3a211c6dd09f1e9bf2 | 57,115 |
def format_time(time, unit, delimiter=False):
"""
A function to format a unit of time, so it is readable when it is
output to Discord.
"""
if time > 0:
if time > 1:
unit += 's'
elapsed = f"{time} {unit}"
if delimiter:
elapsed += ','
return ... | 46a21aae69dd77d082b1440a4cbe7416ce974d7c | 57,116 |
def how_many_days(month_number):
"""Returns the number of days in a month.
WARNING: This function doesn't account for leap years!
"""
days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
result = days_in_month[month_number - 1]
return result | aceab5f5fb72caff832a8a188189a5d3ba194413 | 57,117 |
def batch_to_device(batch, target_device):
"""
send a batch to a device
:param batch:
:param target_device:
:return: the batch sent to the device
"""
features = batch['features']
for paired_sentence_idx in range(len(features)):
for feature_name in features[paired_sentence_idx]:
... | 1b069ad110c06cf2a0bf8c0a9385937955228499 | 57,120 |
def get_email_template(
plugin_configuration: list, template_field_name: str, default: str
) -> str:
"""Get email template from plugin configuration."""
for config_field in plugin_configuration:
if config_field["name"] == template_field_name:
return config_field["value"] or default
r... | 0fca7997b9747a50c881da556610dae3ef2cf342 | 57,123 |
def circular_between(start, bet, end):
"""Finds if bet is in between start and end
Arguments:
start {Integer}
bet {Integer}
end {Integer}
Returns:
Boolean -- True if it is in between, else False
"""
if end > start:
return (bet > start and bet < end)
... | bd9d06ce42795e8d32f21b0c07fb9aef1f67b88b | 57,128 |
import typing
def flatten_catalog(catalog: typing.List[dict]) -> dict:
"""Turn the raw service catalog into a simple dict."""
return {
service['type']: {
endpoint['region']: endpoint['url'] for endpoint in service['endpoints']
} for service in catalog
} | 0450e7a354f33ae4e133c4a3e250a7861cd2264f | 57,130 |
def lyambda_fact_bot(m_distrib, R, P_mol, F_mol, phi):
"""
Calculates the the factor of masstransfer.
Parameters
----------
m_distrib : float
The distribution coefficient, [dismensionless]
R : float
The reflux number, [dismensionless]
P_mol : float
The flow rate of di... | 36af45afe68f14ea648df15efc1ef4e555d94e5c | 57,131 |
def run(action, *args, **kwargs):
"""
:doc: run
:name: renpy.run
:args: (action)
Run an action or list of actions. A single action is called with no
arguments, a list of actions is run in order using this function, and
None is ignored.
Returns the result of the first action to return a... | 924227a1d182c7abc99419830605c0f278ba0dd8 | 57,133 |
def get_csv_header(
reviews_per_paper, num_similar, area_chairs=False, is_global=False
):
"""
Get the csv output header fields, based on the number of assigned and
similar reviewers
Args:
reviews_per_paper (int): Number of reviews received by each paper
num_similar (int): The number... | 7dc2ffafcec0fc05b56bb8ab11d210691df75f06 | 57,135 |
def tobytes(s):
"""force_bytes(s) -> bytes
Ensures the given argument is of type bytes
Example:
>>> force_bytes(b'abc')
b'abc'
>>> force_bytes('abc')
b'abc'
>>> force_bytes(1)
Traceback (most recent call last):
...
TypeError: Expecting a... | 911061e1be21e2237ba65dc271d8e576e4823b23 | 57,137 |
import socket
def is_server_alive(host, port):
"""
Attempts to connect to a given host and port. If the connection is successful then True is returned. Otherwise,
False is returned.
:param host: the target host name or ip address.
:param port: the target port.
:return: True if the connection ... | 9bf276e42c69e471b532049939e1192b7600cd32 | 57,139 |
import math
def dist(p: list, q: list) -> float:
"""
Returns the Euclidean distance between points p and q. Tries to emulate
Python 3.8's math.dist(p, q) function.
Citation: https://docs.python.org/3/library/math.html
:param p: A multi-dimensional (dimension >= 1) point in the form of a list
:... | 7690d02fcbc9e2d18a94324e6e3c95bad56d279e | 57,140 |
def dataframe_series_summary(series_summaries: dict) -> dict:
"""Aggregate certain statistics from the series summary
Args:
series_summaries: mapping from series to summary
Returns:
A aggregated summary based on the statistics of individual series
"""
summary = {"na_count": 0, "n_v... | db1c1e2d27b5c95782759e9b67f372ef86a6aebe | 57,141 |
def cpu_usage_for_process(results, process):
"""
Calculate the CPU percentage for a process running in a particular
scenario.
:param results: Results to extract values from.
:param process: Process name to calculate CPU usage for.
"""
process_results = [
r for r in results if r['met... | 8fc962cf9f7d1fcab1b8a223b4c15dd2eb0e51f4 | 57,146 |
import ast
def get_nth_argument_name(arguments: ast.arguments, n: int) -> str:
"""Return the name of the nth positional argument, or Ɛ if out-of-range."""
_arguments = arguments.args
if len(_arguments) == 0:
return ""
if not (0 <= n < len(_arguments)):
return ""
return _argument... | 913c869a894413d8a715455e967e89f9ab29626b | 57,148 |
def _build_gcs_destination(config):
"""Builds a GcsDestination from values in a config dict.
Args:
config: All the user-specified export parameters. Will be modified in-place
by removing parameters used in the GcsDestination.
Returns:
A GcsDestination containing information extracted from
conf... | 54eeb5fbc747a7bee52fe286f0b4e7fe1a055143 | 57,150 |
def bytes_from(path):
"""
Return the bytes from a file.
:param path: file path string
"""
with open(path, "rb") as fp:
return fp.read() | 04addff5f07ee3714d51d125bdc0f5917238a812 | 57,156 |
def get_drug_dcid(row):
"""Returns dcid of a drug.
If the ChEMBL ID of the drug was not found, then a new dcid for the drug is
created based on the pharmGKB id.
"""
if row['ChEMBL ID']:
return 'bio/' + row['ChEMBL ID']
return 'bio/' + row['PharmGKB Accession Id'] | a8b5b5d639e4aa07a6778f589b23415106658b45 | 57,157 |
import hashlib
def filehash(filepath):
"""Compute the hash of a file.
Args:
filepath (str): Path to the file.
"""
hasher = hashlib.md5()
with open(filepath, 'rb') as f:
hasher.update(f.read())
return hasher.hexdigest() | 28419c227ccea3cd23960c59abe1dfc981bf9ed2 | 57,161 |
import asyncio
def synchronize_generator(async_generator, *args, **kwargs):
"""
Returns a synchronous generator from an asynchronous generator
"""
ag = async_generator(*args, **kwargs)
async def consume_generator(stop_signal):
r = await ag.asend(stop_signal)
return r
loop = ... | c301b333491d35cf654ac2eccbc6d4226485e805 | 57,163 |
def coverage(index_seq, segment_list, qseqseq):
"""
Coverage of an index_seq, which is just the ratio of the length of the concatenation to the
length of the original string.
"""
return (segment_list[index_seq[-1]][2] - segment_list[index_seq[0]][1]) / len(qseqseq) | a1d0666bfed13adf308fa7362c7c4653d325a422 | 57,165 |
def mk_scan_mapper(condition_map, dflt=None):
"""Make function implementing an if/elif/.../else logic from a {bool_func: x, ...} map"""
def scan_mapping(x):
for condition, then in condition_map.items():
if condition(x):
return then
return dflt
return scan_mappin... | 8787cf7783b124029ce28f908c5a49c25ef5de33 | 57,173 |
def do_while_loop(printer, ast):
"""Prints "do {body} while (cond)"."""
cond_str = printer.ast_to_string(ast["cond"])
body_str = printer.ast_to_string(ast["body"])
return f'do {body_str} while ({cond_str});' | ef98227dc3f405000fdbc49b29eee8ad571818b6 | 57,176 |
def fibonacci(n):
"""
Generate a list of fibonacci numbers up to and including n.
"""
result = [1, 1]
if n <= 2:
return result[0:n]
counter = 2
while True:
next_fib = result[counter-2] + result[counter-1]
if next_fib > n:
break
result.append(next_f... | e497f204720106d56d6dffee34d8ad39e7409d08 | 57,178 |
def get_video_file_paths(input_dir):
"""From a directory, return a list of video file paths, sorted based
on commonly used video file exstensions.
Args:
input_dir (Path): The folder in which we'll search for videos.
Returns:
List: Video file paths found in directory
"""
# Get ... | b9264fe02e2d06b4b07b27636bfe0a253e1fe8f1 | 57,179 |
import io
def parse(stdin: io.TextIOWrapper) -> list:
"""
Parse the input into a list of tuples: string direction and int distance.
"""
return [
(line[0], int(line[1:]))
for line in stdin.read().strip().splitlines()
] | 7513285adb9fc5dca2d69b1b4d920589ecc15df4 | 57,181 |
def cantor(a, b):
"""Cantor pairing function, used to give unique int name to each observation"""
a = int(a)
b = int(b)
return (a + b) * (a + b + 1) / 2 + b | 04eeb7caef77516b6e1efca5731427a2e1a3c63e | 57,187 |
def inputs_vocabulary(vocabulary):
"""Get the inputs vocabulary.
Args:
vocabulary: Vocabulary or (inputs_vocabulary, targets_vocabulary) tuple.
Returns:
a Vocabulary
"""
if isinstance(vocabulary, tuple):
vocabulary = vocabulary[0]
return vocabulary | 2c816dd32d5d7a0afba111e052c55153ce4a189e | 57,190 |
def convert_distance_to_weight(dist_matrix):
"""
Translate raw distance-to-edge data into weight using parabolic equation.
Used to give higher priority to pixels located closer to an edge.
:param dist_matrix: matrix of distances to edges from the distance transform
:return: adjusted dist_matrix
... | 84cc4e1ceca167c19d57b580880043b97517ccd8 | 57,192 |
import inspect
def GetFileAndLine(component):
"""Returns the filename and line number of component.
Args:
component: A component to find the source information for, usually a class
or routine.
Returns:
filename: The name of the file where component is defined.
lineno: The line... | 892710e43ffd60b196dd8121dd215aa3c1806770 | 57,193 |
import re
def unsupported_arguments(doc, args):
""" Mark unsupported arguments with a disclaimer """
lines = doc.split("\n")
for arg in args:
subset = [
(i, line)
for i, line in enumerate(lines)
if re.match(r"^\s*" + arg + " ?:", line)
]
if len(s... | ea357b7fcc8101aba1fc811a07cd89287958d9a7 | 57,195 |
def geometric_series(common_ratio, number_of_images, first_term=1):
"""
This will provide the geometric series for the integration.
Last values of the series has to be less than or equal to number
of images
ex: number_of_images = 100, first_term =1
common_ratio = 2, geometric_series = 1, 2, 4, ... | f0951f3a54aba71df109a15d07637d2cea01117a | 57,198 |
def wrap(x, vmin, vmax):
"""Wrap a value x within bounds (vmin,vmax)"""
return (x-vmin) % (vmax-vmin)+vmin | fb0556ccf8d9df3cf96f663aef54ad1a43384d77 | 57,199 |
def _match_stack(selector, stack):
"""Match stacks using selector as the comparison var.
Strings prefixed with ^ will be treated as negative
Args:
selector (str|list[str]): String tokens or list used for matching
stack (:obj:`stackformation.BaseStack`): stack used for comparison. Will match... | b909fe8fe41820c00b1c48b46fe49910031eac11 | 57,200 |
def day2dekad(day):
"""Returns the dekad of a day.
Parameters
----------
day : int
Day of the date.
Returns
-------
dekad : int
Number of the dekad in a month.
"""
if day < 11:
dekad = 1
elif day > 10 and day < 21:
dekad = 2
else:
de... | 2a6d0918da008ed81f4f97bf1146a4e0e13c0a56 | 57,202 |
def calc_max_quant_value(bits):
"""Calculate the maximum symmetric quantized value according to number of bits"""
return 2**(bits) - 1 | 0cd845c06aef8742cf62132b6569ed725fae4147 | 57,206 |
def enumerate_ids(locationlist):
"""For a given list of locations, give them all an ID"""
counter = 1
for location in locationlist:
location.insert(0,"LOCID%s" % (counter))
counter+=1
return locationlist | 14ec2972881e48904736be658c56456b8bb14b85 | 57,209 |
def substitute_rpath(orig_rpath, topdir, new_root_path):
"""
Replace topdir with new_root_path RPATH list orig_rpath
"""
new_rpaths = []
for path in orig_rpath:
new_rpath = path.replace(topdir, new_root_path)
new_rpaths.append(new_rpath)
return new_rpaths | eb69a0807558b5b7d122c4d4149069b04c05e8ec | 57,211 |
def clean_dict(target, keys):
"""Rebuild a new dictionary from requested keys.
Args:
target (dict): Dictionary to extract keys from.
keys (list): List of keys to extract. If one key cannot be found in
target, it will be ignored.
Returns:
dict: Dictionary with requested ... | 2efa7797b475af7fd7aa23cba6a133844395f05a | 57,214 |
def is_set_policy(policy):
""" Checks if the current policy action is a set action. """
return 'setIamPolicy' in policy['action'] and not 'metadata' in policy | 33bf358ec78a1ddf023b2fb890f4b067b6263273 | 57,216 |
def least_larger(arr: list, idx: int) -> int:
""" This function returns the index of the least number larger than the element at the given index, or -1 if there is no such index. """
if len(arr) < 0:
return -1
my_element = [i for i in arr if i > arr[idx]]
if len(my_element) > 0:
return a... | e181cd9cbe8bf5f49c400125b04d1028ff79880e | 57,217 |
def get_yaml_version(fd, token):
"""
A YAML token is found, so see if the YAML version can be parsed.
Parameters
----------
fd : GenericFile
token : bytes
The YAML token
Return
------
yaml_version: tuple
"""
offset = fd.tell()
while True:
c = fd.read(1)
... | ac6375e698f40c15f2e7f87a8bcd1d1dd5a8c2a7 | 57,227 |
def safe_dict(obj_or_func, **kwargs):
"""
Create a dict from any object with all attributes, but not the ones starting with an underscore _
Useful for objects or function that return an object that have no __dict__ attribute, like psutil functions.
"""
if callable(obj_or_func):
res = obj_or_... | a0c7118f1a1d4144e635b295f0bb8bde36424eec | 57,243 |
def view_exists(spark_session, view_name):
"""Return True if the specified view exists"""
try:
_ = spark_session.read.table(view_name)
return True
except:
return False | c21998d87c9cc5715d1b3ef93bfea0b9cfecc19d | 57,248 |
def sum_all_but_dims(dims_to_keep, da):
"""Sum a xr.DataArray along all dimensions except those specified."""
dims_to_sum = [dim for dim in da.dims if dim not in dims_to_keep]
return da.sum(dim=dims_to_sum) | eb9412d29666076935537c9c385adf9088cd5464 | 57,249 |
def pam4_decision(x,l,m,h):
"""produces pam4 symbol from analog voltage
Parameters
----------
x : float
the analog voltage
l: float
voltage threshold between 0 and 1 symbol
m: float
voltage threshold between 1 and 2 symbol
h: float
volt... | dbfed2709ab87f138384a6edd9a1b679b6516001 | 57,251 |
def create_slack_attachment(fallback,
color=None,
pretext=None,
author_name=None,
author_link=None,
author_icon=None,
title=None,
... | cea633beffa534f896506ab239c2c67866157efa | 57,253 |
def length(segments):
"""Computes length of segments.
Args:
segments (numpy array or torch tensor): shape [N, 2] holding N
segments.
Returns:
a numpy array (or torch tensor) with shape [N] representing segment
length.
Note:
it works with time, it would be off... | a8411448358eb96324771dcf2cd33dfd4345375a | 57,256 |
def report_status_cell(i):
"""Make and return the report_status cell at Column F."""
return "F{}".format(str(i)) | ace90193326ecdf4e11dfe016d393cdaf9d1ff88 | 57,257 |
import math
def angle(p):
"""
p = (x, y), return angle from y axis
"""
x, y = p
p = x, -y
a = math.pi / 2 - math.atan2(*reversed(p))
if a < 0:
a += 2 * math.pi
return a | 41114deb7de3d93159b4d219ce5c129b160e7a53 | 57,258 |
def _Pairs(data):
"""dictionary -> list of pairs"""
keys = sorted(data)
return [{'@key': k, '@value': data[k]} for k in keys] | d2627a21cfa34efccb68fe977780d33e9024173c | 57,260 |
def calculate_calibrated_value(image_mean, vector):
"""
Solves the calibration equation that finds the optimal low bound value for
the saturation and value.
:param image_mean: the mean if the image of which
:param vector: the dictionary containing the coefficients and group mean.
Calcu... | 71a379eca4a3c2a6889058a0fbdcf2a8b0f779ae | 57,265 |
def edit_title(ax, text, prepend=False, append=False):
"""
Adds text to beginning or end of existing title on axes
Args:
ax (plt.Axes): Axes with title to edit
text (str): Text to add to beginning or end of title
prepend (bool): Prepend text (can't do both at same time)
appe... | a238c07a07fc9dc1e31096b00dbeddd68802fb28 | 57,273 |
import torch
def logsumexp(x, dim=None, keepdim=False):
"""Numerically stable logsumexp.
from https://github.com/pytorch/pytorch/issues/2591
Args:
inputs: A Variable with any shape.
dim: An integer.
keepdim: A boolean.
Returns:
Equivalent of log(sum(exp(inputs), dim=... | f7e63a2a297352aeeb4bd4d2a3d73eb1ceacd22f | 57,274 |
import decimal
def format_coordinate(number: decimal.Decimal) -> str:
"""Returns decimal in the format required by task.
2.0000 -> 2
2.104 -> 2.1
"""
return "{:.2f}".format(number).rstrip("0").rstrip(".") | 012e651b512e6fa280ca1c34a0a06e44a41c2632 | 57,275 |
def errs_tab(n):
"""Generate list of error rates for qualities less than equal than n."""
return [10**(q / -10) for q in range(n + 1)] | dbece04706ec9d319ee3ce1a81648f34998180c7 | 57,279 |
def _GetGcsPath(source, error_log):
"""Get the path to the folder on Google cloud storage."""
batch_sim_bucket = 'gs://makani/batch_sim/'
gcs_folder = batch_sim_bucket + source
if not error_log:
gcs_folder += '/h5_logs/'
else:
gcs_folder += '/error/'
return gcs_folder | 0e33a3f04f3edf55d9eed4b77357c08c9957ff50 | 57,282 |
def _progress_bar(count, total):
"""
Get a simple one-line string representing a progress bar.
Arguments:
count (int): Current count. Starts at 0.
total (int): Total count.
Returns:
pbar_string (str): The string progress bar.
"""
bar_len = 60
filled_len = int(round(ba... | 31af780be8486145afc5a2a81d73eae3fb50f841 | 57,292 |
def get_depth(string):
"""Calculates amount of whitespaces leading the given string and returns int"""
# expected input (example):
# string = [' 09140 Cellular Processes']
#
# expected output (example):
# depth = 13
depth = len(string) - len(string.lstrip(' '))
return depth | c2e8c2b8c480c2c990d3e7a3f06578e26b9440bb | 57,293 |
import itertools
def list_product(*args):
"""
Generate a list containing all combinations of the input lists. Outputs a list rather than an
annoying generator.
Parameters
----------
*args : list, tuple
Returns
-------
list
Combined list.
"""
return list(itertools.... | f5c45ddbb87821f8776faa1f83eaae673c83b696 | 57,295 |
def get_classes(classes_path):
""" Loads classes from text file
Input:
classes_path (string) - The path of classes
Output:
class_names (list) - Class names in list format
class_mappings(dict) - Dictionary mapping class names with id e..g {"aeroplan": 4, "apple":... | 2df39a806573288cf90c53ea9d9e040568ca556a | 57,296 |
from typing import Dict
from typing import Callable
def transform(data: Dict, *modifiers: Callable[[Dict], None]) -> Dict:
"""
Generic functions that allows to generate new dictionary
by applying any number of modifications on the input dictionary
:param data: original dictionary
:param modifiers... | f0916c9123ac90990329f90f9e732018bd307eea | 57,300 |
def resize_image(image, resize_width, resize_height):
""" Resizes image to the given dimensions in pixels.
Args:
image (Image): The image to be resized.
resize_width (int): The width in pixels of the new image.
resize_height (int): The height in pixels of the new image.
Returns:
... | 3b8c2b86ac2f6e4ac80357dc1bc66f3b70010b50 | 57,301 |
def strip(cc):
"""Strip all non numeric characters.
@type cc: str
@param cc: String.
@rtype: str
@return: Stripped string.
"""
return ''.join([c for c in cc if c.isdigit()]) | 041bd83f1b87854122916780d3ac975c32ae58ef | 57,304 |
def normalize_column_to_midi_range(column, target_range, target_min_value):
"""
Normalizes the values to the values range used by the MIDI format
:param column: A list with the values that should be sonified
:param target_range: The target range
:param target_min_value: The target minimum value
... | 7aaefa83655baf11e2472f25b302f7623db4aa9d | 57,305 |
def optimizer_kwargs_gf(parsed_args):
"""
Build kwargs for optimizer in optimizer.py from
the parsed command-line arguments.
"""
return {
'optim': parsed_args.optim,
'lr': parsed_args.lr_gf,
'weight_decay': parsed_args.weight_decay,
'momentum': parsed_args.momentum,
... | 87489bfb50ff34df7f58b3b6178cff71f169cdb5 | 57,314 |
def clean_doc(doc):
"""Remove spurious end-lines and such from the doc-string specified in
the comment preceding the C++-python functions.
"""
# Replace regular enter (i.e. mere comment formatting in cpp file)
# with space
doc = doc.replace("\n", " ")
# The removal can cause a "hard enter"... | 43b9df1c888f509ca85c6e82696f287c47c8c8ed | 57,317 |
def getDescribe(series, percentiles = [.25, .5, .75]):
"""Get describe of series
Args:
series (Series): data series
percentiles: the percentiles to include in the output
Returns:
Series: the describe of data include mean, std, min, max and percentiles
"""
d = series.describ... | ce95f06081617a591ca94de9d2025983efcaea68 | 57,318 |
def calculate_tax(price, tax_rate):
"""Calculates tax given a price and tax rate"""
total = price + (price*tax_rate)
my_price = 10000
print("my_price (inside function) =", my_price)
return total | f189ae14dc5cd171111b5822f1c60bc81ca9fded | 57,319 |
def ultimoNome(string: str) -> str:
"""
Devolve a última palavra de uma string (sobrenome)
Parameters
----------
string : str
texto (nome completo)
Returns
-------
string : str
texto (sobrenome)
"""
string = string.replace('.','').replace(',',' ').split(... | c3e30d069bcf6afccf7cc8730c2596b285b8a2c1 | 57,324 |
import textwrap
def catalog_file(tmpdir_factory):
"""Prepare a single-entry catalog that points to actual data on pangaea.de."""
catalog_str = textwrap.dedent(
"""
metadata:
version: 1
plugins:
source:
- module: intake_pangaeapy
sources:
... | 81a4e3b317e21c320275409e5049fc31810365ec | 57,328 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.