content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def mysin(x):
"""
My sine. Note that this is only accurate for small x.
"""
return x | 9589b1a3106b13ff230e614dcfc1477b422c9879 | 11,091 |
import logging
def get_module_logger(module_name, level=None):
"""
Get a logger for a specific module.
:param module_name: str
Logic module name.
:param level: int
:param sh_level: int
Stream handler log level.
:param log_format: str
:return: Logger
Logger object.
... | 0fd2c8be1463da464700964c2d5ad895a40f4a9c | 11,092 |
import glob
def getAllOfAFile(file_dir, ext):
"""
Returns a list of all the files the direcotry with the specified file extenstion
:param file_dir: Directory to search
:param ext: The file extension (IE: ".py")
"""
return glob.glob(file_dir+"/*"+ext) | 876a4f4b30653bd08454db9ee425d56fe408623d | 11,093 |
def set_weight_decay(model, weight_decay, skip_list={"decoder.attention.v", "rnn", "lstm", "gru", "embedding"}):
"""
Skip biases, BatchNorm parameters, rnns.
and attention projection layer v
"""
decay = []
no_decay = []
for name, param in model.named_parameters():
if not param.requir... | 7e2702d544497b03fffda4558f4aa5fcd2dd4f43 | 11,094 |
def extract_sample_info(sample_str):
"""Extract kit, sample, and technical replicate from sample_str.
Inputs -
sample_str - string from sample name
Returns -
tuple (kit, biological sample name, technical replicate)
"""
s = sample_str.replace('Ftube', '')
# The biological sample... | f67440528391e1c463bb940cad9e59e8e61aa4c3 | 11,095 |
def OffsetPosition(in_ra,in_dec,delta_ra,delta_dec):
"""
Offset a position given in decimal degrees.
Parameters
----------
in_ra: float
Initial RA (decimal degrees).
in_dec: float
Initial DEC (demical degrees).
delta_ra: float
Offset in RA (decimal degrees).
... | 7b027a2e0bf87dba9d1136e68af258b21223cedb | 11,096 |
def get_prime_factors(n):
"""
Find all prime factors in N and return them as a list.
"""
i = 2
factors = set()
while n > 1:
if n % i == 0:
factors.add(i)
n = n / i
else:
# only increment if we did not find a factor.
i = i + 1
i... | da6f13b1c910f4b90cf84bbb7cfe6ecc2b735863 | 11,097 |
def ping(): # pragma: no cover
"""
ignore connection validation with task server (celery)
"""
"""Simple task that just returns 'pong'."""
return "pong" | 9967a01f8c509e272e7215a843e513ce4dc9a2be | 11,098 |
def get_database_user(config, credentials):
"""
Returns the database user from the credentials.
"""
return credentials.get('user', 'unknown') | 90e0a25a888e2de73ea7688a4da2e5de2ae02fbb | 11,099 |
from typing import OrderedDict
def _list_to_dict_list(list_items):
"""
Takes a list and creates a dict with the list values as keys.
Returns a list of the created dict or an empty list
"""
if list_items:
k = OrderedDict()
for item in list_items:
k["%s" % item] = ""
... | 48e3448b79530e4bc7c4674a168429208b9f62b4 | 11,100 |
def dms2deg(valin):
"""
Converts DMS input to decimal degrees.
Input can be either a string delimeted by : or spaces, or a list of [D,M,S] numbers.
Parameters
----------
valin: float
Input value in DMS. Can be either: \n
- a string delimeted by : or spaces \n
- a lis... | 3efac9d11c8a7b5933766a0610f49a884e20925b | 11,101 |
def featureScale(x, xRef=None):
"""Helper function to perform feature scaling.
INPUTS:
x: pandas DataFrame or Series.
xRef: reference pandas DataFrame.
If only x is provided, x will be normalized against itself.
If xRef is additionally supplied, x will be normalized against xRef
... | bffa3403e8083efaa8deb24e03b48d0210d39652 | 11,103 |
def EncodeRadioRowCol(container, row, col):
"""
:param container:
:param row:
:param col:
"""
RadValue = container * 100000 + row * 1000 + col
return RadValue | 92d9c8842432fded1b1b5e526ad735a9900cc219 | 11,106 |
import getpass
def get_user(prompt=None):
"""
Prompts the user for his login name, defaulting to the USER environment
variable. Returns a string containing the username.
May throw an exception if EOF is given by the user.
:type prompt: str|None
:param prompt: The user prompt or the default o... | fc392cfacc931ee915bb218a80e5db46245f2a1f | 11,108 |
from collections import OrderedDict
import os
import torch
import copy
def load_checkpoint(cfg, checkpoint_file, model, optimizer=None, active_sampling=False):
"""Loads the checkpoint from the given file."""
assert os.path.exists(checkpoint_file), "Checkpoint '{}' not found".format(
checkpoint_file
... | bc788bbd6f802ac839424d041122a77afff2fb25 | 11,109 |
import json
def load_commands(filename="commands.json"):
""" load all known command """
with open(filename) as file_:
commands = json.load(file_)
return commands | 66d90ecbcc0fcee182c0e7f25b1ff66d26c54145 | 11,110 |
def menu_item_flag(context, flag_type='', flag_iso='', flag_style='', flag_classes='', **kwargs):
"""
Templatetag menu_item_flag
:param context: Getting context
:param flag_type: Default empty, It accepts the string 'square'
:param flag_iso: Default empty, ISO language country code
:param flag_... | 2520a67ea2436743a1b5dec5a7d0321c68f31221 | 11,111 |
def _full_link(provider, word):
"""Return a website link for dictionary provider and word."""
return 'http://' + provider + word | 56681e50523910a0519e29f7446355a20d932284 | 11,113 |
def element_text(member_elt, elt_name):
"""Extract all `para` text from (`elt_name` in) `member_elt`."""
text = []
if elt_name:
elt = member_elt.find(elt_name)
else:
elt = member_elt
if elt:
paras = elt.findAll('para')
for p in paras:
text.append(p.getText(separator=u' ').strip())
ret... | 13ff356e1a584bcaa9c905c93dcafaa787ca936f | 11,114 |
import torch
def to_device(data, device):
"""Move data to device
Arguments:
data {TupleTree, tensor} -- Tensors that should be moved to device.
device {str, torch.device} -- Device data is moved to.
Returns:
TupleTree, tensor -- Data moved to device
"""
if type(da... | 9e0661951e7793a92d7f1953bfb481ccf4ec4ca9 | 11,117 |
import os
def lookUpDirTree(fileName):
"""
This is called when we are using a default name for either the
FontMenuNameDB or the GlyphOrderAndAliasDB files.
These are often located several dir levels above the font file,
as they are shared by the font family.
"""
MAX_LEVELS = 4
path = ... | 350622e51187284eaadd1ed0a588fa0efaf181d3 | 11,118 |
import argparse
import os
def get_args():
"""Get arguments."""
parser = argparse.ArgumentParser(description="""
This application translates your articles on Qiita into English ones with googletrans, and
upload them to Qiita automatically.
Requirements:
googletrans, Qiita access token(Se... | 117e638e7ad542db5a89a6e100f3e70848b4c3f3 | 11,120 |
def _convert_line(line):
"""
Parameters
----------
line: str
Returns
-------
list
"""
line = line.upper().split()
tmp = []
for i in line:
if '.' in i:
try:
tmp.append(float(i))
except:
tmp.append(i)
el... | 179b4ea803160679399195da15f147d2ff311d5f | 11,121 |
def word_list_to_string(word_list, delimeter=" "):
"""Creates a single string from a list of strings
This function can be used to combine words in a list into one long sentence
string.
Args:
word_list (list/tuple): A list (or other container) of strings.
delimeter (str, Optional): A st... | 040479df7e0d5aadda0b12dc944a53d4b380f044 | 11,122 |
def is_s3(url: str) -> bool:
"""Predicate to determine if a url is an S3 endpoint."""
return url is not None and url.lower().startswith('s3') | f1e36654ae86057fb4ae73a90648095119f1b5af | 11,123 |
def C2K(degC):
"""degC -> degK"""
return degC+273.15 | 877f52078bd0da13cd21a8665a6c89cc0fa90848 | 11,124 |
import sys
import os
def find_exe(name):
"""Finds an executable first in the virtualenv if available, otherwise
falls back to the global name.
"""
if hasattr(sys, 'real_prefix'):
path = os.path.join(sys.prefix, 'bin', name)
if os.path.isfile(path):
return path
return na... | 57837a0dd5a329441b5f7ab717c94a998d3fe9a7 | 11,125 |
def cfn_context():
""" Context object, blank for now """
return "" | a71bffc39ce00e00236667040feb156bb9a4f9a2 | 11,126 |
def hello_world():
"""Just an empty route with a string."""
return "Hello there. This route doesn't do anything." | f6dcaa52d51aab51234f51b4f7a46e6e55aeb524 | 11,128 |
def dict2tsv(condDict):
"""Convert a dict into TSV format."""
string = str()
for i in condDict:
string += i + "\t" + "{%f, %f}" % condDict[i] + "\n"
return string | c73f8e3158ade699cc4589d541f05397f559d190 | 11,129 |
import os
def createSegmentSpecificPath(path, gpPrefix, segment):
"""
Create a segment specific path for the given gpPrefix and segment
@param gpPrefix a string used to prefix directory names
@param segment a GpDB value
"""
return os.path.join(path, '%s%d' % (gpPrefix, segment.getSegmentConte... | 999ce16e3ce4d3923bd22d871a27655bd64d91af | 11,130 |
def rescale_score_by_abs(score, max_score, min_score):
"""
Normalize the relevance value (=score), accordingly to the extremal relevance values (max_score and min_score),
for visualization with a diverging colormap.
i.e. rescale positive relevance to the range [0.5, 1.0], and negative relevance to the ... | fe1df85166bb6ab34f6f30d06003d7946a92138e | 11,131 |
def calculate_percentile_rank(array, score):
"""Get a school score's percentile rank from an array of cohort scores."""
true_false_array = [value <= score for value in array]
if len(true_false_array) == 0:
return
raw_rank = float(sum(true_false_array)) / len(true_false_array)
return int(roun... | bfdc64168c10d00c33294bf05851982e0712e230 | 11,132 |
def _one_recursive_step(
list_pair,
size_task,
current_doubled_size_task):
""" """
i = 0
j = 0
a_list = list_pair[:size_task]
b_list = list_pair[size_task:]
c_list = []
for k in range(current_doubled_size_task):
#print 'i',i, 'j', j, 'size_task', size_task
... | ae0fe3440b8af38730de80fde4762f3c7fa94623 | 11,134 |
def gain_com(exp, num, value):
"""Change the pmt gain in a job.
Return a list with parts for the cam command.
"""
return [
("cmd", "adjust"),
("tar", "pmt"),
("num", str(num)),
("exp", str(exp)),
("prop", "gain"),
("value", str(value)),
] | d0bd65b62c4ef0f9f002cef9b929ec37a725389c | 11,136 |
def root():
"""Returns hola perro."""
return 'Welcome' | c83c0d159cbabdb82905595b01058d531a03ddd1 | 11,140 |
import re
def deduce_look_back(in_features, target_features):
"""From the feature names, determine how large of a look back is used.
Args:
in_features (list of str): Names of input features
target_features (list of str): Names of target features.
Returns:
int: Number of look ... | bae20baec986c888acfff159b491635e2e75a455 | 11,142 |
def round_based_player(*bot_moves):
""" A Player which makes a decision dependent on the round index
in a dict or list. (Or anything which responds to moves[idx].)
Parameters
----------
moves : list or dict of moves
the moves to make, a move is determined by moves[round]
"""
def mov... | 2c3e57aae7d6a89c76f735bd7a267ff965d67256 | 11,143 |
import argparse
def _error_rate_arg(val):
"""Validates the error_rate for the arg parser"""
try:
val = float(val)
except ValueError:
raise argparse.ArgumentTypeError(f"{val} is not a floating-point literal")
if val >= 0.0 and val <= 1.0:
return val
raise argparse.ArgumentT... | 22e985cd3df59746c364316f289b65fe7bc768d2 | 11,145 |
def permutations_exact(n, k):
"""Calculates permutations by integer division.
Preferred method for small permutations, but slow on larger ones.
Note: no error checking (expects to be called through permutations())
"""
product = 1
for i in range(n - k + 1, n + 1):
product *= i
retur... | 4244e446aad6b36185575c8c7991bd05984b0796 | 11,146 |
def get_group(machine, num):
"""
"""
cores = []
idx = 0
r = 0
while num>0:
assert r<machine.get_cores_per_node()
cores.append(idx)
idx += machine.get_cores_per_node()
if idx>=machine.get_num_cores():
r += 1
idx = r
num -= 1
retu... | 2a295b0dc11cc9e195fc54787b5355e340dce366 | 11,147 |
def attachment(url: str, filename="") -> dict:
"""
Returns a dictionary using the expected dicitonary format for attachments.
When creating an attachment, ``url`` is required, and ``filename`` is optional.
Airtable will download the file at the given url and keep its own copy of it.
All other attac... | 24564ca3e7dfb8cc35242b1d16fb7351fc9576ce | 11,148 |
def NIST_SU(results):
"""Number of segmentation errors (missed segments and
false alarm segments)
over number of reference segments.
"""
assert len(results) == 3
TPs = results[0]
FPs = results[1]
FNs = results[2]
if (FNs + FPs) == 0:
return 0.0
return ((FNs + FPs)/(TPs + ... | 3c60a612223dc247109d24be45b32739af8587ef | 11,150 |
def pathCountX(stairs: int, X):
"""number of unique ways to climb N stairs using 1 or 2 steps"""
#we've reached the top
if stairs == 0:
return 1
elif stairs < 0:
return 0
else:
validSteps = []
for num in X:
if stairs >= num:
validSteps.app... | 8ee8bf554f6176b5f666fe33eea51a3ee982deee | 11,151 |
def current_cloud_token(service):
"""Get the the current state of the account.
Args:
service: Drive API service instance.
Returns:
int
"""
response = service.changes().getStartPageToken().execute()
return response.get('startPageToken') | dc2b61c2c0e5548269a6c746cf8dc1d152ec953d | 11,152 |
def sort_stack(stack_object: list) -> list:
"""
Sorts stack.
:param stack_object: stack object, iterable object
:return: sorted stack, iterable object
"""
tmp_stack = []
while stack_object:
# complexity check
print(f'stack 1')
element = stack_object.pop(-1)
w... | ebdca3c263dfdc72bcdb0843b9e6e7d397ba2236 | 11,155 |
import torch
def calculate_interaction_nominal(genotypes_t, phenotypes_t, interaction_t, residualizer,
return_sparse=False, tstat_threshold=None):
"""
genotypes_t: [num_genotypes x num_samples]
phenotypes_t: [num_phenotypes x num_samples]
interaction_t: [1 x num_s... | f3270e7623d8c3d3e6cdd706142b43650d21a7b4 | 11,156 |
def parse_default_kv(default, default_dict):
"""parse a string in form key1=value1;key2=value2,... as used for some template fields
Args:
default: str, in form 'photo=foto;video=vidéo'
default_dict: dict, in form {"photo": "fotos", "video": "vidéos"} with default values
Returns:
di... | 4d461589118915cde5461b6b8ea7cd5e5e4d5165 | 11,157 |
def prefix_connection_id(connection_id, parent_connection_id):
"""Used to distinguish connection ids when they have the same id
as a parent_connection. """
if not len(connection_id) > len(parent_connection_id):
return parent_connection_id + connection_id
return connection_id | bdc1f92625a03c6b88dd6c81097aca0522db0929 | 11,158 |
import os
def read_tree(path):
""" Read the directory structure of a path into a dictionary where files are True values,
and subdirectories are more dictionaries."""
tree = {}
for dirpath, dirnames, filenames in os.walk(path):
d = tree
for x in os.path.relpath(dirpath, path).split(os.s... | f340ac968ad3617843c3643f9af58ef0738ab72c | 11,159 |
import os
def idl_basename(f):
"""returns the base name of a file with the last extension stripped"""
return os.path.basename(f).rpartition('.')[0] | 201756c58254c1ac70de136289a23917e86718be | 11,160 |
import re
def extract_intro_and_title(filename, docstring):
""" Extract the first paragraph of module-level docstring. max:95 char"""
# lstrip is just in case docstring has a '\n\n' at the beginning
paragraphs = docstring.lstrip().split('\n\n')
# remove comments and other syntax like `.. _link:`
... | f1ae63f112f0c4ff91ba8863313b9bd978e16eb4 | 11,162 |
import os
def get_html_directory():
"""
Returns directory for raw HTML to scrape.
"""
return os.path.join(os.path.dirname(__file__), 'html') | 9c34953712760652f42d7f5700fd9c5966061012 | 11,164 |
def is_on(S, j):
"""
Returns 1 if and only if the `j`-th item of the set `S` is on.
Examples
========
Check if the 3-th and then 2-nd item of the set is on:
>>> S = 0b101010
>>> is_on(S, 3), is_on(S, 2)
(1, 0)
"""
return (S & (1 << j)) >> j | 76034f083372ee2cbe0c711e3a09daf26634550a | 11,165 |
def _get_pil_image_dimensions(pil_image):
"""Gets the dimensions of the Pillow Image.
Args:
pil_image: Image. A file in the Pillow Image format.
Returns:
tuple(int, int). Returns height and width of the image.
"""
width, height = pil_image.size
return height, width | d191ae705df97b1729be2dd03e9a5ff4ddcb4518 | 11,167 |
import heapq
def solve(n, times):
"""
小根堆/优先队列
"""
if n == 0:
return 0
heap = []
heapq.heappush(heap, times[0][1])
for time in times[1:]:
if time[0] >= heap[0]:
# 不需要新的客服
heapq.heappop(heap)
heapq.heappush(heap, time[1])
print(heap)
r... | 064d582ef76dcae4e69b2c037d3fae07fde3b143 | 11,168 |
def wrap_list(item):
"""
Returns an object as a list.
If the object is a list, it is returned directly. If it is a tuple or set, it
is returned as a list. If it is another object, it is wrapped in a list and
returned.
"""
if item is None:
return []
elif isinstance(item, list):
... | 6b2af543af39058f7df28e7d89dbb9231cf2b247 | 11,169 |
from typing import Union
import zlib
def zlib_compress(data: Union[bytes, str]) -> bytes:
"""
Compress things in a py2/3 safe fashion
>>> json_str = '{"test": 1}'
>>> blob = zlib_compress(json_str)
"""
if isinstance(data, str):
return zlib.compress(bytes(data, "utf-8"))
return zlib... | 0e7eaf018873ce335b06c4ca4857f9bf8b58864b | 11,170 |
import functools
import logging
def logdec(func):
"""A logging decorator wrapping a function with a standard logging mechanism.
This decorator wraps a function with a standard logging mechanism, providing the following functionalities:
* Logs the calling of the function and the parameters passed to it wh... | fd1ddf475f17758c09d3f44492a8b2ff66cf38de | 11,171 |
def predict(sample, relations):
"""
Predict entities and interactions of given sample
w.r.t set of known relations.
:param sample: Dict with `id` and `text` as strings
:param relations: Set of relation tuples
:return: Sample augmented with extracted entities and interactions.
"""
text = ... | 44046de044685609cf6252f2f106a60c2ecf5f7a | 11,174 |
def get_manual_iface(manual_iface, node_class):
""" Returns standardized interface dict based on manual_iface """
iface_dict = {
"node_id": "manual",
"node_uri": None,
"node_name": None,
"node_addr": None,
"node_fqdn": None,
"node_class": node_class,
"ifac... | 070207a1ba399b660147f0d3cb95419347e0344e | 11,175 |
def travel_cost():
"""
Returns the yearly costs of travel, 22£ per week.
:return: The cost of travel.
"""
# There are 52 weeks in a year minus two for Christmas and Summer holidays.
return 22 * 50 | fa51fba03ab3db9deea7f3e075c392d4c8db6cef | 11,176 |
import string
import re
def tokenize_count(s: str) -> int:
"""
Tokenizes the given strings to count the number of words.
:param s:
:return: number of words
"""
s = s.translate(str.maketrans('', '', string.punctuation + "„“–"))
return len(re.split(r'\W+', s)) | c68822f313a2ffcab11edf0c0ce146d758cb8e3f | 11,177 |
def set_idle_override(isUserActive: bool, isScreenUnlocked: bool) -> dict:
"""Overrides the Idle state.
Parameters
----------
isUserActive: bool
Mock isUserActive
isScreenUnlocked: bool
Mock isScreenUnlocked
**Experimental**
"""
return {
"method": "Emula... | 21b51d27edef13f66818d8d72583745e6c3449e9 | 11,178 |
def format_strings(*strings):
"""Take an arbitrary number of strings and format them nicely.
Returns the nicely formatted string.
"""
accum_string = ""
for str in strings:
accum_string = "{0} {1}\n".format(accum_string, str)
return accum_string | 7785cf052ed04ce3185035b0921e98bd0d952449 | 11,179 |
def is_explicitly_rooted(path):
"""Return whether a relative path is explicitly rooted relative to the
cwd, rather than starting off immediately with a file or folder name.
It's nice to have paths start with "./" (or "../", "../../", etc.) so, if a
user is that explicit, we still find the path in the s... | bde26849889ac5c951160e441cdd0c3c60871ab1 | 11,181 |
from typing import List
def snip_out(file_str:str, start_key:str)->str:
"""From an anvil.yaml file, snips out only the string you want: the database description."""
good_string:List[str]=[]
save_this_one = False
for line in file_str.split('\n'):
if line.startswith(start_key):
good_... | 8e9ebde180fb5ff6faefcbd92629c75f260ce518 | 11,182 |
def colour_code_segmentation(image, label_values, array_type):
"""
Given a 1-channel array of class keys, colour code the segmentation results.
# Arguments
image: single channel array where each value represents the class key.
label_values
# Returns
Colour coded image for segmen... | e9a6e9d0bb705cc17e30899126ca3081369f3a99 | 11,183 |
def init_step(idx, cols):
"""Helper function to find init suffix
in a column
Parameters
----------
idx: int
Index of 'init' column in cols.
cols: list[str]
List of column names.
"""
for i in range(idx, len(cols)):
if cols[i] != 'init':
return 'init-' ... | ec056ef39c56ec9dbc534e70105d55aa9bbf7be5 | 11,184 |
def next_nuc(seq, pos, n):
""" Returns the nucleotide that is n places from pos in seq. Skips gap symbols.
"""
i = pos + 1
while i < len(seq):
if seq[i] != '-':
n -= 1
if n == 0: break
i += 1
if i < len(seq) :
return seq[i]
else :
return 'N... | dbe3d204d3399167630cf83c74b0f1742d1c8367 | 11,186 |
import numpy
def avg_3_op(array_1, array_2, array_3, nodata):
"""Average 3 arrays. Skip nodata."""
result = numpy.empty_like(array_1)
result[:] = nodata
valid_mask = (
~numpy.isclose(array_1, nodata) &
~numpy.isclose(array_2, nodata) &
~numpy.isclose(array_3, nodata))
resul... | 6e6a47b8e5e7cae065fa933275122d1f9cee7f88 | 11,187 |
import argparse
def parse_argv():
"""Parse sys.argv"""
desc = 'Convert phitar yield files to a datagen input file'
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('--nrg_of_int',
required=True,
help='beam energy of interest')
p... | caa54cdf2df15a7ce3b9bd896939b4ade2706f5d | 11,188 |
def _mt_repr(self):
"""Print mutable tuple like dict."""
return '{{{0}}}'.format(', '.join('\'{0}\': {1!r}'.format(name, getattr(self, name)) for name in self._fields)) | bc01cb22d8263ce7df77e90214d587f0553627a7 | 11,189 |
def get_k_set_interval(vec: str, k: int, to_counter_plus_one: bool = False) -> tuple:
"""return tupl
Parameters
----------
vec : str
String of {0,1}*.
k : int
????????????????????
????????????????????
## to_counter_plus_one : bool
## If True, assume vec beggins i... | ac0dcfe0e9af6dae77942ba7beb682c9d52b57f0 | 11,191 |
def load_h5(h5f):
"""
Load fiberbundles configurations from a hdf5 class
Parameters
----------
h5f : hdf5 class
h5-file or group object
Returns
-------
res : list(list(fiber)), fibers are (n,4)-arrays with (x,y,z,radii) for each fiber point
"""
fiber_bundles = []
f... | 47487b43ae375c5ade27c82ec083570ee9655e27 | 11,195 |
def fizz_buzzable(num):
"""
We're only interested in valid fizz buzz numbers.
"""
return num % 3 == 0 or num % 5 == 0 | 4eba37245525ead66f4f30370d9e3d97c05aca55 | 11,196 |
from typing import List
def load_file(file_path: str) -> List[str]:
"""
Just loader for file with lines
:param file_path: path to file
:return: list of lines of your data
"""
data: List[str] = list()
with open(file_path) as file_object:
for line in file_object:
data.a... | 9aadf5c0a90f5c65868862e4366276c448077944 | 11,198 |
def uniquify_tablewidgetitems(a):
""" Eliminates duplicate list entries in a list
of TableWidgetItems. It relies on the row property
being available for comparison.
"""
if (len(a) == 0):
tmp = []
else:
tmp = [a[0]]
# XXX: we need to compare row #s because
... | 942eb3fb5e172185fe7f857f5e6e5e523984b75c | 11,199 |
import random
def random_colors(*commands):
"""From tuple of commands, generate random but unique colors."""
colors = ["blue", "green", "red", "yellow", "magenta", "cyan", "white"]
num_colors = len(colors)
num_commands = len(commands)
if num_commands >= num_colors:
colors += colors
u... | 2f55ce480a8550d94b595b94017371e525b8a8b4 | 11,200 |
def greeting() -> str:
"""The standard greeting.
>>> assert greeting() == 'hello'
"""
return 'hello' | eba4ada1f6dd154dc8197bce0c0128fea3d7e31e | 11,201 |
import random
def mutation_chromossome(chromossomes, mutation_function, mutation_rate):
"""
:param: chromossomes -
:param: mutation_function -
:param: mutation_rate -
:return: chromossomes -
"""
number_chromossomes_to_mutate = int(len(chromossomes) * mutation_rate)
ran... | 30a9a92724a91e70d10ba5c35fef0e1aef85300d | 11,203 |
def pcmd(progressive, lr, fb, vv, va):
"""
Makes the drone move (translate/rotate).
Parameters:
progressive -- True: enable progressive commands, False: disable (i.e.
enable hovering mode)
lr -- left-right tilt: float [-1..1] negative: left, positive: right
rb -- front-back tilt: float ... | 4534ac48f00a39c944b1be01ea0818235aea2559 | 11,204 |
def b2h(n):
"""Convert bytes int into human friendly string format.
>>> b2h(10000)
'9.8 KB'
>>> b2h(100001221)
'95.4 MB'
"""
t = "{0:.2f} {1}".format
symbols = ("KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
prefix = {s: 1 << (i + 1) * 10 for i, s in enumerate(symbols)}
for s i... | 6337fa1d1c7a2e324bcbe99eac28225551f84ef5 | 11,205 |
import numpy as np
def f_calculate_thresholds(combined_uncertainties, phi=0.95):
"""
Calculates EDMF thresholds for provided target reliability of identification
Developed by : Sai G.S. Pai (ETH Singapore)
Contact : saiganesh89@gmail.com
Date: June 30, 2020
INPUTS:
... | b82feca1823c2bd772f1f6ba06a6053f6d30ad15 | 11,208 |
def addToSession(session, flaskform):
"""
Function used in the hiringmanger tab. It must keep backward compatibility
with the fields named commentOne..., commentTwo..., commentThree...,
commentFour... since the DB was built in this way at first.
"""
if 'evaluatorName' in flaskform:
sessi... | 8ecaf782373730efa6c251a4354de4355cf31884 | 11,210 |
import os
import errno
def makedirs(directory):
"""
Create a directory and any missing parent directories.
It is not an error if the directory already exists.
:param directory: The pathname of a directory (a string).
:returns: :data:`True` if the directory was created, :data:`False` if it alread... | b5eecd5e27b086f8d5619802a205c85ae697980c | 11,211 |
def check_legal_moves(board):
"""Return the legal moves on the board.
"""
return board[:, :, 0] == board[:, :, 1] | a8643c6cd06722b0110a09d8c12f34a20f03a31d | 11,212 |
from typing import List
from typing import Tuple
def plotlines(
optical_start: List[float], ratio_wanted: List[float]
) -> Tuple[List[float], List[float], List[float]]:
"""Draws the 'Distance Lines' for the main plot.
Takes inputs of desired optical and radio limits of where the distance
lines should... | 5c2b83b881c8b8101a5177709096c79dfce8c16c | 11,214 |
import tempfile
import os
import yaml
def save(config):
"""Save a clang config to a new file and returns the name of the file."""
(fd, name) = tempfile.mkstemp()
f = os.fdopen(fd, "a")
f.write(yaml.dump(config))
f.close()
return name | 39651cfc9e60547469fddebf7424e3ee9aa4e84b | 11,215 |
def get_unique_fields(fld_lists):
"""Get unique namedtuple fields, despite potential duplicates in lists of fields."""
flds = []
fld_set = set([f for flst in fld_lists for f in flst])
fld_seen = set()
# Add unique fields to list of fields in order that they appear
for fld_list in fld_lists:
... | 0e131c5b3fe695670fafb51810c674e859c29b63 | 11,217 |
def cmp_func_different_hash(request):
"""Return a comparison function that checks whether two hashes are different."""
return request.param | 5e917de2db60c03d17fc5536e5af48e0328423fc | 11,218 |
def winner(board):
"""This function accepts the Connect Four board as a parameter.
If there is no winner, the function will return the empty string "".
If the user has won, it will return 'X', and if the computer has
won it will return 'O'."""
for row in range(7):
count = 0
last = ''... | 7c7983ec33cf6aca89283a2c09b9fabf2045f1b9 | 11,219 |
import torch
def picp(target, predictions:list, total = True):
"""
Calculate PICP (prediction interval coverage probability) or simply the % of true
values in the predicted intervals
Parameters
----------
target : torch.Tensor
true values of the target variable
predictions : list
... | ef075b4cf3904a5f854ab4db3ecfbc6ba66ad674 | 11,220 |
import io
import yaml
import hashlib
def compute_parse_tree_hash(tree):
"""Given a parse tree, compute a consistent hash value for it."""
if tree:
r = tree.as_record(code_only=True, show_raw=True)
if r:
r_io = io.StringIO()
yaml.dump(r, r_io, sort_keys=False)
... | 38f5af485d6f008d46b8b4165096f30e5b004d0b | 11,221 |
def knot_vector_from_params(degree, params, periodic=False):
"""Computes a knot vector from parameters using the averaging method.
Please refer to the Equation 9.8 on The NURBS Book (2nd Edition), pp.365 for
details.
Parameters
----------
degree : int
The degree of the curve
params... | 059463258011eaa4f76dfd8c640b62aa663d8226 | 11,223 |
import re
def time_to_frame(line: str, fps=24000 / 1001) -> int:
"""
Converts a timestamp in the format <hours>:<minutes>:<seconds>.<milliseconds> into the corresponding frame number.
<hours> and <milliseconds> are optional,
and milliseconds can have arbitrary precision (which means they are no longer... | 0942ce5526592eeb8c6a858631382530ad2dccbd | 11,224 |
import torch
def get_test_dict(idx):
"""
Get FRCNN style dict
"""
num_objs = 0
boxes = torch.zeros((num_objs, 4), dtype=torch.float32)
return {'boxes': boxes,
'labels': torch.ones((num_objs,), dtype=torch.int64),
'image_id': torch.tensor([idx]),
'area': (b... | bd7e37499c30b9bd23d9b99ed187795fb9e5e6e1 | 11,225 |
import os
def here(file_name):
"""
Get the given file name relative to the working directory
"""
return os.path.abspath(os.path.join(os.path.dirname(__file__), file_name)) | 51015b8e6f7443c3980a23b7ce0a27d9b5916748 | 11,227 |
from typing import List
def checksum(rows: List[List[int]]) -> int:
"""
Solves the AOC second puzzle.
"""
check = 0
for row in rows:
minimum = min(row)
maximum = max(row)
check += maximum - minimum
return check | e95ff4418899d1f09671aac83feb4f5d35072808 | 11,228 |
def file_order(entry):
"""
For a PlaylistEntry, return its original order in the Playlist.
"""
return entry['lineno'] | 8bbd6546e120cec018c0f7628fd1473ae5926dad | 11,229 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.