content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def select_color_marker(i):
""" Return index-based marker/color format for plotting """
colors = ['b', 'g', 'r', 'c', 'y', 'k']
style = ['-', '--', '-.', ':']
ci = i % len(colors)
si = (i // len(colors)) % len(style)
return '%s%s' % (colors[ci], style[si]) | 9b06ecc6de31e8c2a0dbf423233640752fe09110 | 39,198 |
import argparse
def setup_train_args():
"""
设置训练参数
"""
parser = argparse.ArgumentParser()
parser.add_argument('--device', default='0,1,2,3', type=str, required=False, help='设置使用哪些显卡')
parser.add_argument('--no_cuda', default=False,
action='store_true', help='不使用GPU进行训练'... | fc283002e1687a2a6cb0e76e1c0dd93e5441f07c | 39,199 |
import pickle
def get_mct_frame(site):
"""Serves up a dataframe of micro-CT SSA data for a given site"""
# Load a dictionary of dataframes stored as a pickle file
# The pickle file itself is generated by notebook: CheckOutCT.ipynb
frames = pickle.load(open('../data/microCT/processed_mCT.p', 'rb'))
... | ace2697ff9833ca0392815e16741b77d416de3ef | 39,200 |
def yield_node_names(nodes):
"""Yield either ``op.name`` or ``str(node)``."""
return (getattr(n, "name", n) for n in nodes) | 05be07232a2b8b18d5b66a06fe7cbf04d7d76808 | 39,202 |
def get_memory_limit(component_limit, overall_limit):
"""
Return the minimum of the component and overall limits or None if neither is set.
"""
limits = [limit for limit in [component_limit, overall_limit] if limit is not None]
return min(limits) if limits else None | 50c8372dca1bacaa3e408abaf5e03659d01e1eea | 39,203 |
def _isQuoted(string, substring, idx):
"""returns True if position i of string is in a quoted region"""
bfr = string[:idx]
aft = string[idx + len(substring):]
if (bfr.count('"') % 2 or aft.count('"') % 2 or
bfr.count("'") % 2 or aft.count("'") % 2):
return True
else:
retu... | 2adbc0ca6e61440c5f3e3070d4cfe5cab305d4ec | 39,204 |
def is_tag(t):
"""Is `t` a tag?
"""
return t.strip().startswith('{%') | a7e4f55925844d8e6e881dcad8d20bfc2f5968bf | 39,208 |
import argparse
def parse_args(args):
"""
Uses argparse to return a parser of all given arguments when running KoalaBot.py
:param args: sys.argv[1:]
:return: parsed argparse
"""
parser = argparse.ArgumentParser(description='Start the KoalaBot Discord bot')
parser.add_argument('--config', ... | f2efef59864a2f96f93bb4a9a838155b44e3c868 | 39,212 |
import locale
def amountToCurrency(amount):
"""
Shows an amount in the user currency locale or default to `$`
"""
try:
return locale.currency(amount, grouping=True)
except ValueError: # If the locale does not support currency formatting
return '$' + str(round(amount, 2)) | 9ec10e4919fe35d1a2938c15d5a7c0c8ee809a24 | 39,215 |
def strip_library(name):
"""
>>> strip_library("fuchsia.device/MAX_DEVICE_NAME_LEN")
'MAX_DEVICE_NAME_LEN'
>>> strip_library("SomethingGreat")
'SomethingGreat'
"""
return name[name.rfind('/') + 1:] | 608c77cc36dae623c80f791704b1737cfed61390 | 39,216 |
def str_to_list(str, def_val=[]):
"""
try to return a list of some sort
"""
ret_val = def_val
try:
ret_val = str.split(",")
finally:
try:
if ret_val is None:
ret_val = [str]
except:
pass
return ret_val | 41f6771123f0e42b82183f13d6ca0930906d19c5 | 39,217 |
def parse_cdr_annotations_pubtator(entity_type, subset):
"""Get each annotation in the BC5CDR corpus with documents in PubTator format.
Requires:
entity_type: is str, either "Chemical" or "Disease"
subset: is str, either "train", "dev", "test" or "all"
Ensures:
annotations: is ... | 0476628a01db6cd936132838d025ceb3838a9c30 | 39,219 |
def nan_to_str(x) -> str:
"""Change from np.nan to a str of choice."""
if isinstance(x, str):
return x
else:
return 'Not Spell' | 6906fa894e18b631f441a68fcbb841a6e957f232 | 39,221 |
import copy
def deeplist(x: list) -> list:
"""
Deep copy a list. This is needed because list() by itself only makes a shallow copy.
See https://stackoverflow.com/questions/5105517/deep-copy-of-a-dict-in-python
Convenience function.
:param x: List to copy
:return: Deep copy of the list provide... | c4161510ddf150e7b57c4d9681a8221b8325b312 | 39,222 |
import time
def QA_util_date_stamp(date):
"""
explanation:
转换日期时间字符串为浮点数的时间戳
params:
* date->
含义: 日期时间
类型: str
参数支持: []
return:
time
"""
datestr = str(date)[0:10]
date = time.mktime(time.strptime(datestr, '%Y-%m-%d'))
return... | fe099714e023bad48d104b9ba5dff704f76faf10 | 39,223 |
def get_layer_index(model, name):
"""Get index of layer by name"""
for idx, layer in enumerate(model.layers):
if layer.name == name:
return idx | 5c57fad4cbb28ab8b6605be669e4cb75024ee977 | 39,224 |
import os
import json
def get_abi_json():
"""
Returns FITCOIN ERC20 token ABI
:return:
"""
root_dir = os.path.dirname(os.path.abspath(__file__))
abi_path = os.path.join(root_dir, 'erc20', 'abi.json')
with open(abi_path) as f:
fitcoin = json.load(f)
return fitcoin | 9409dfbf10e8a36f2222eb99e2a64639ba6c0779 | 39,225 |
import gzip
def encode_gzip(data, compresslevel=6):
"""Encode the passed in data with gzip."""
return gzip.compress(data, compresslevel=compresslevel) | 2693956c15924194e1151d2c04eadf97167cc08b | 39,226 |
def isImage(url):
"""Check if url is related to an image
Args:
url (string): string
Returns:
boolean: return true if url is referring to an image
"""
return \
url.endswith(".png") or \
url.endswith(".jpg") or \
url.endswith(".jpeg") or \
url.endswith(".... | f55b0ba05fa115b8a7d8d85219bd05e465b18854 | 39,228 |
def _get_separator(num, sep_title, sep_character, sep_length):
"""Get a row separator for row *num*."""
left_divider_length = right_divider_length = sep_length
if isinstance(sep_length, tuple):
left_divider_length, right_divider_length = sep_length
left_divider = sep_character * left_divider_len... | 0e10658e11580264a7722f59390a9dfcfaf0a71b | 39,229 |
def parse_pages(pages):
"""
Give a string possibly containing a start and end page, return the start and end page if any
:param pages:
:return: list with start and end pages
"""
if '-' in pages:
k = pages.find('-')
start = pages[0:k]
end = pages[k + 1:]
else:
... | 4ccf0dd8409d50c89dde3951eadd679e3009ffd8 | 39,230 |
import os
def create_adapter_code_dict():
"""Turn TSV-file to dict.
Read tab seperated file with numbered seqI7 and seqI5.
Return dict with sequence as key and number as value.
"""
basedir = os.path.dirname(os.path.abspath(__file__))
adapterdict = dict()
with open(os.path.join(basedir, 'd... | 9f0842ea71658880cf024e24ab5faa40c2b16e9d | 39,231 |
import json
def jchars(*args):
"""
.. function:: jletters(text) -> character jpack
Splits an input text into its composing characters.
Examples:
>>> sql("select jchars('this is a text')")
jchars('this is a text')
---------------------------------------------------------
["t","h","i"... | 63e2d47861f82f1b01cd9db58c91e7f54d95e81b | 39,233 |
def asymmetric_extend(q1, q2, extend_fn, backward=False):
"""directional extend_fn
"""
if backward:
return reversed(list(extend_fn(q2, q1)))
return extend_fn(q1, q2) | e91189299fb99096d05193b7c66c7a39803de053 | 39,235 |
def last_chars(sort_table):
"""Append end marker and generate rotation table."""
return ''.join([s[-1] for s in sort_table]) | 59e3162dd1cd9f090c4c3b1a2bce58d93595a953 | 39,236 |
from datetime import datetime
def data_extenso() -> str:
"""
transforma a data de numeral para extenso
:return: str
"""
mes = 'janeiro', 'fevereiro', 'marco', 'abril', 'maio', 'junho',\
'julho', 'agosto', 'setembro', 'outubro', 'novembro', 'dezembro'
return f'Colatina-ES, {datetime.... | 7937429571a5a512cc3669152d9761aadad46b40 | 39,237 |
def _ll_subvoxel_overlap(xs, x1, x2):
"""For an interval [x1, x2], return the index of the lower limit of the
overlapping subvoxels whose borders are defined by the elements of xs."""
xmin = min(x1, x2)
if xmin <= xs[0]:
return 0
elif xmin >= xs[-1]:
ll = len(xs) - 1
return l... | 5563642767d626f9bc516b90930432b2d5692442 | 39,238 |
from typing import Mapping
from typing import Sequence
from typing import Any
def to_key_value(data: Mapping) -> Sequence[Mapping[str, Any]]:
"""
converting dict to a form that will be used in visualizer (form: {"key": "name", "value", "hello"})
:param data: data to be converted
:return: converted dat... | ea2e96dd7c3493cee80e71e8eb6320fe16e5a244 | 39,239 |
def _end_format(header, ender, dat_str):
""" Write a block with an end
"""
return (
header + '\n' +
dat_str + '\n' +
ender
) | 3676a7fe25e41f021fea4bc2e5debc99b9b3c771 | 39,240 |
import json
def _read_notebook_data_dict(notebook_path: str) -> dict:
"""
Read a dictionary of notebook data.
Parameters
----------
notebook_path : str
Path of target notebook.
Returns
-------
notebook_data_dict : dict
A dictionary of notebook data.
"""
with o... | c74fabb3ad1ff7d0e5d002791b1aef08a353199a | 39,241 |
import itertools
def _binary_count(n):
"""Count `n` binary digits from [0...0] to [1...1]."""
return list(itertools.product([0, 1], repeat=n)) | 0b21fc49763a7c09bd1ac84c4c823a0239a31db9 | 39,246 |
def bdev_compress_get_orphans(client, name=None):
"""Get a list of comp bdevs that do not have a pmem file (aka orphaned).
Args:
name: comp bdev name to query (optional; if omitted, query all comp bdevs)
Returns:
List of comp bdev names.
"""
params = {}
if name:
params[... | 4723929303c27388870ed7d9a2339e7e832b41d1 | 39,248 |
import json
def message_to_json(message):
"""
This function tranforms the string message to a json
string, this is to make all REST responses
to be in JSON format and easier to implement
in a consistent way.
"""
#if message is alreay in json then do not do anything
mesage_dict = {... | bf20d028068d2716c5b40807e6b17a6ffb8b1073 | 39,249 |
import networkx
def graph_search(nx_graph, target_species):
"""Search nodal graph and generate list of species to remove
Parameters
----------
nx_graph : obj
networkx graph object of solution
target_species : list
List of target species to search from
Returns
-------
... | 0b5d41bb0b87ca0835984465b1cbfadbb7bedbc8 | 39,250 |
def recursive_replace(steps: int, to_expand: str, rules: dict) -> str:
""" Replace the given string with a new replacement string, according to the rules.
Args:
steps (int): How many iterations. Decremented with each recursion. Recursion ends when step=0.
input (str): Input str. The str to be r... | 2104ccfbc89d60aa09235a2933aee0bf15dea0a3 | 39,251 |
def set_override_certificate_errors(override: bool) -> dict:
"""Enable/disable overriding certificate errors. If enabled, all certificate error events need to
be handled by the DevTools client and should be answered with `handleCertificateError` commands.
Parameters
----------
override: bool
... | 7dbf9d025ae80139befa1f32323f2d95327cecf3 | 39,253 |
def nonzeros(u):
"""Return number of non-zero items in list `u`."""
return len([val for val in u if val != 0]) | 77180e06c9e82bcb4ca19a289514a92334ad62cd | 39,254 |
def match_fields(exp_fields, fields):
"""
Check field names and values match the expected ones.
- exp_fields:
A list of dictionaries with field name/value pairs.
- fields:
SPARKL event fields as returned by the listener.
[
{'attr': {'name':'n',... | 1a260f344ca42c480069b6951e037320fb6a63aa | 39,255 |
def address_domain(address):
"""
取得 email 地址的域名
"""
return address.split('@')[-1] | 7d98b5a0649e0e90586b330eceec41634ea490f8 | 39,256 |
def makeFooter(namestub, path, verbose):
"""Print the footer."""
linestring=str("(define-layer! -1 \
(cons 'filename \"%s/\")\
(cons 'visible #f)\
(cons 'color #(0 0 0)))\n" % path )
linestring+=str("(set-render-type! 3)\n")
return linestring | 18eb7f2efd4e3eef81aa95236cf44613e28ea757 | 39,257 |
import os
def tar(path):
"""
Tar the path and write output to stdout.
:param path: All contents under path are 'tar'ed.
"""
if not os.path.exists(path):
raise ValueError("Invalid argument: 'path' doesn't exist")
path = path.rstrip(os.sep)
parent, base = os.path.split(path)
return "tar -C %s ... | 120200b4d4a7ffb9b74dd8b461fb6e25f1f2d609 | 39,258 |
def merge_xml(xmls,output_file):
"""
merge xml files
Parameters:
-----------
xmls: list
List of paths of the xml files
output_file: str
Path of the merged xml
"""
if len(xmls) <2 :
raise Exception("Need two or more xml files to merge")
xmls = " ".join(xmls)
... | b574f3edb777f4a48f5209173baf7f74a465377e | 39,261 |
def archivo_valido(archivo, archivo_dict):
"""Confirma que el archivo exista y tenga notas escritas
Recibe el archivo CSV
Devuelve booleano"""
if archivo_dict != {}:
return True
print("El archivo no existe o está vacío")
return False | 6c4114963686232b1ad109616e16eb94621f6c25 | 39,263 |
def isNewPhase(ds1, ds2):
"""
Check if two dynamicsState have the same contacts
:param ds1:
:param ds2:
:return: True if they have the same contacts, False otherwise
"""
assert ds1.effNum() == ds2.effNum(), "The two dynamic states do not comes from the same model."
for i in range(ds1.ef... | b6bf21106024991256a3a53b887bf73f83e7c037 | 39,264 |
def add_orphan_settings_to_tool_dependencies( tool_dependencies, orphan_tool_dependencies ):
"""Inspect all received tool dependencies and label those that are orphans within the repository."""
orphan_env_dependencies = orphan_tool_dependencies.get( 'set_environment', None )
new_tool_dependencies = {}
i... | ee2aea9ee8b38643eada77dfc1c03a399797c4af | 39,265 |
def create_events_model(areas, virus_states):
"""Create events for the model.
Parameters
----------
virus_states : list of strings
List containing the names of all virus variants.
Returns
-------
events: dict
Dictionary that contains the event names as keys
and dici... | b1e8394f2a57e89372844cbb2b456d702d7b5c59 | 39,266 |
def _escape_cmd_arg(arg):
"""quote/escape and argument for a command line call so that it can
be safely used even if it has special charaters"""
arg = str(arg)
if ' ' in arg or '"' in arg:
return '"' + arg.replace('"', '""') + '"'
return arg | 502b0d3435cbed4e9601a407946479500d56455f | 39,267 |
import os
def _rrd_exists(self):
"""
.. versionadded:: 0.2
:returns: True if the RRD file already exists, False otherwise
You can also use a RRD object directly for comparision in
boolean expression, to check whether the RRD file exists
or not. Thus ``MyRRD("my.rrd").exis... | a928f75a660bb267ccd18fa756ab36f066b0461b | 39,268 |
def _generate_math_operator(operator_name):
"""Helper function for _Vector operators."""
def operator(self, other):
return type(self)(self._operator(operator_name, other))
return operator | aa722432092092e6599c4c9d08ca0803a5c6e4ae | 39,269 |
def pad(text, bits=32):
"""
Pads the inputted text to ensure it fits the proper block length
for encryption.
:param text | <str>
bits | <int>
:return <str>
"""
return text + (bits - len(text) % bits) * chr(bits - len(text) % bits) | 5b7b77bc6fef64121cf3fb0c127a83ddabf5dd11 | 39,271 |
def build_hexagonal_position(index_matrix):
"""Computes the position of the pixels in the hexagonal grid from the index matrix.
Args:
index_matrix (tensor): The index matrix representing the index of each pixel in the axial addressing system.
"""
pix_positions = []
for i in range(index_matr... | 1b177c455b9945fb7d4b60764436c416a3e55503 | 39,272 |
def setup_dims(dataset, output_global_dim=None):
"""Extract dimes from dataset
"""
input_sample = dataset[0]['graph_input']
output_sample = dataset[0]['graph_target']
input_node_dim = input_sample['nodes'].shape[-1]
input_edge_dim = input_sample['edges'].shape[-1]
if input_sample['globals'] ... | 12cb66d71bb7ea39410283d223675d8fa2c3f937 | 39,274 |
import subprocess
import sys
def hoa_to_dot(hoa):
"""
Converts an HOA automaton into its DOT representation.
Works only for nondeterministic automata.
"""
autfilt = subprocess.Popen(['autfilt', '--dot'],
stdin=subprocess.PIPE,
stdout=subprocess... | 0c87730e6fc91a520501c33e517962b75606eced | 39,275 |
def is_valid(box):
"""Check that a bounding box has valid coordinates"""
return (box[..., 2] > box[..., 0]) and (box[..., 3] > box[..., 1]) | ca622196ac6710494fc052682dca5c2dde4af4ee | 39,277 |
from typing import OrderedDict
def parse_authors(file):
"""Parse authors TSV file"""
authors = OrderedDict()
metadata = OrderedDict()
for line in file:
line_split = line.rstrip().split("\t")
author, affiliations = line_split[0:2]
mdata = line_split[2:]
affiliations = af... | e08e3815514b7aa02a74f1078b6377616fbaf863 | 39,279 |
def mask_last_dim(tensor, binary_mask):
"""Pick the elements of tensor in the last dimension according to binary_mask."""
return tensor[..., 0] * binary_mask + tensor[..., 1] * (1 - binary_mask) | ca1b40d8b90184c18979443483361987e49ec370 | 39,280 |
def minimum(ints):
"""
Return the minimum in a list of integers. If the list is empty,
return None.
"""
if ints == ():
return None
else:
head, tail = ints
min = minimum(tail)
if min is None or head <= min:
return head
else:
return ... | ff4e4eab86e2efa0a01b7e254e7d10556284a6d3 | 39,281 |
def clean_name(name: str):
"""Clean name by stripping whitespace and newline."""
return name.splitlines()[0].strip() | 1df5c654bc52ecbe33b98fe9a32eb812abec4e0f | 39,282 |
def lib_version_satisfied(current_ver: str, mini_ver_limited: str,
newest_ver_limited: str = ""):
"""
Check python lib version whether is satisfied.
Notes:
Version number must be format of x.x.x, e.g. 1.1.0.
Args:
current_ver (str): Current lib version.
... | 9afb7d30ecfea1ac7067f48d61bae1e5f7d7bd12 | 39,283 |
import os
def get_free_disk_space(p):
"""
Returns the number of free bytes on the drive that ``p`` is on
"""
s = os.statvfs(p)
return s.f_frsize * s.f_bavail | b3debb923591194752cf3f2398d192a5e4e75e65 | 39,284 |
def datetime_to_list(date):
"""
convert a datetime object into a list [year,month,day,hour,minute,second]
Arguments
---------
date: datetime object
"""
return [date.year,date.month,date.day,date.hour,date.minute,date.second] | 5a581680793172bede720aa9c144203e843beb31 | 39,286 |
def get_profitrate_log(fpath):
"""ログから利益率取得
"""
result_dict = {}
with open(fpath, 'r', encoding='utf_8') as f:
lines = f.readlines()
for line in lines:
parse_line = line.split(':INFO:')
key = parse_line[0]
value = parse_line[1].replace('利益率=', '').replace('\n', '')
... | 57327413e5af5261a39799c9c4842e6adb6bf52a | 39,287 |
def ignore_formatter(error):
"""
Formatter that emits nothing, regardless of the error.
"""
return '' | 1d2d3b145e43d9d5840ad5dc3851331d5d67a23d | 39,288 |
from typing import OrderedDict
def data_info_factory(names, funcs):
"""
Factory to create a function that can be used as an ``option``
for outputting data object summary information.
Examples
--------
>>> from astropy.utils.data_info import data_info_factory
>>> from astropy.table import ... | a6a128c0b85dd018abe0dec6c5101ce31b3feed1 | 39,289 |
import six
def _encode_metadata(metadata):
"""
UTF8 encode any unicode keys or values in given metadata dict.
:param metadata: a dict
"""
def encode_str(item):
if isinstance(item, six.text_type):
return item.encode('utf8')
return item
return dict(((encode_str(k), ... | 4b953a42b714f9729ae3ca41c413b295f012d72e | 39,292 |
import os
import pickle
def load_char_mapping():
""" Loads the character mapping object """
fpath = os.path.join("processed", "unq_chars.pkl")
with open(fpath, "rb") as fin:
ret = pickle.load(fin)
return ret | 11ee482bf84029a93784dffa2c8015d5dc5e1431 | 39,293 |
import argparse
def chkint(number):
"""
Sanity check integer to use as a depth level for creating test directories.
"""
try:
number = int(number)
except ValueError:
msg = "{} is not a valid integer.".format(number)
raise argparse.ArgumentTypeError(msg)
if number < 1:
... | 1f4237fba44b09d081d23b25bce131de38f98bef | 39,296 |
import torch
def get_means(tensors_list):
"""
Calculate the mean of a list of tensors for each tensor in the list. In our case the list typically contains
a tensor for each class, such as the per class z values.
Parameters:
tensors_list (list): List of Tensors
Returns:
list: List... | b99b0dc2f0ab19c5ae55170d59b69b6f714f3db2 | 39,297 |
def deltatime_format(a, b):
""" Compute and format the time elapsed between two points in time.
Args:
a Earlier point-in-time
b Later point-in-time
Returns:
Elapsed time integer (in s),
Formatted elapsed time string (human-readable way)
"""
# Elapsed time (in seconds)
t = b - a
# Elapsed t... | 0478dd50d7d8e4673058b4096cb0247352a80f6f | 39,299 |
import os
def gen_clf_output(output, classifier_type, depth):
"""
generate path to output clf pickl based on output_csv and depth of the tree
"""
out_pkl = os.path.join(
os.path.dirname(output),
os.path.basename(output).replace('.csv', f'.{classifier_type}.tree_max_depth_{depth}.pkl')
... | acb8ac40f4673c766e90c65d2db1f2ea12b0dcc2 | 39,300 |
def pks_from_iterable(iterable, unique_output=False):
"""
Return pks list based on iterable
:param iterable: list of django model objects OR django queryset
:param unique_output: if True returned list will be unique
:return: list of int
"""
pks = list()
for obj in iterable:
try:
... | 7112b2da95d09fb7fc54626b0aa374d3304af87d | 39,302 |
import hashlib
def sha1_hash_from_text(text: str) -> str:
"""Return sha1 hex digest as string for text.
Parameters
----------
text: str
The text to be hashed
Returns
-------
str
the hash of the text
"""
return hashlib.sha1(text.encode()).hexdigest() | 999a00131adbc207af990a80404887694845da86 | 39,303 |
import tempfile
import os
import shutil
def model_to_bytes(model):
"""
Serialize the Keras model to HDF5 and load the file as bytes.
This saves the Keras model to a temp file as an intermediate step.
:return: str containing the model data
"""
temp_dir = tempfile.mkdtemp()
temp_path = os.pa... | fa4c5e6c49fe9690ca49b4ce52a9ccab009909c2 | 39,304 |
import click
def os_options(f):
"""Aggregate multiple common options into one.
This decorator should be used by CLI commands that need an
Openstack client."""
f = click.option('--os-username', help='Openstack Username', required=True,
envvar='OS_USERNAME')(f)
f = click.optio... | f38a646a45055d4b23e22d887b9d703fb804c868 | 39,305 |
import re
def match_skills(skills, ad):
"""
Find elements in a text through regex
:param skills: Set
:param ad: String
:return: Print item, start position, end position
"""
set_to_print = set()
for skill in skills:
my_regex = r"(^|\s|/|-)" + re.escape(skill) + r"(or|ar|er|r|n|e... | 67599019fb63e451dfb2deb68fd3821657148b30 | 39,306 |
def is_ob_site_html(html):
"""Check if some HTML looks like it is from the overcomingbias site.
Parameters
----------
html : bs4.BeautifulSoup
An HTML page, possibly from the overcomingbias site.
Returns
-------
is_ob_site_html : bool
True if the input HTML "looks like" it ... | ae3e21320858044772532e74fe94d0cfd0e1cb1b | 39,307 |
import os
def get_pip_script_name() -> str:
"""Return expected pip script name for os pipwatch is currently running on."""
script_name = "pip"
if os.name == "nt":
script_name += ".exe"
return script_name | e5db6b4c0b5d9f3589780bc4c9d4414a3f69fca5 | 39,309 |
def authorized_owners(group):
""" Return authorized owners """
owners = []
try:
for owner in group.get_related_owners(include_group=True):
owners.append(owner.owner)
except AttributeError:
# group is None
pass
except TypeError:
# group.get_users returns ... | 4050cba27884f97cbbc27335f8b12c4edfd2da5a | 39,311 |
def _2DprintInxRow(inxRow, lSpacesIndR):
"""
Function prints one index of a row of a 2D array
Input:
- 1 **inxCol** (*int*) Index of the row to be printed
- 2 **lSpacesIndR** (*list*) A list with spaces which should be added
to indices of row... | f108007a9fcb25a6aa32e22297a654d6d262e247 | 39,312 |
def _DepsToLines(deps):
"""Converts |deps| dict to list of lines for output."""
if not deps:
return []
s = ['deps = {']
for _, dep in sorted(deps.iteritems()):
s.extend(dep.ToLines())
s.extend(['}', ''])
return s | c413197b7cdb5585c3df1f93168613d507f9e0ce | 39,313 |
def calculate_deepest_drawdown(df):
"""
3. Считает максимальную просадку по стратегии за время торгов
:param df: - датафрейм с колонкой '<PERFORMANCE>'
:return: - максимальную просадку стратегии
"""
return min(df.dropna()['<PERFORMANCE>'].values) | 4ce1af9c13bfae8f369db8c88bc1ce26eb36e67f | 39,314 |
import math
def SSphere(r):
"""
Surface of a sphere of radius r.
"""
return 4. * math.pi * r * r | 161b43f95ccf02349b66ac5035457dd962e3ba11 | 39,315 |
def create(hdf5, name, dtype, shape=(None,), compression=None,
fillvalue=0, attrs=None):
"""
:param hdf5: a h5py.File object
:param name: an hdf5 key string
:param dtype: dtype of the dataset (usually composite)
:param shape: shape of the dataset (can be extendable)
:param compression... | b9000aa26a0f1ebcb86ba61704e8634e081d29c6 | 39,316 |
def sep_join(sep, sequence, begin="", end=""):
"""
Separator join each elements of sequence,
if begin/end is True, insert the sep after
or before the txt.you can also given some
txt as head/tail of txt.
:param sep: separator string
:param sequence: string sequence
:param begin: head of ... | c723bed6fe00dbb9d3a0ad4aeb02ee74582b0148 | 39,317 |
def retrieve_positions(position_file):
"""
This function returns a list of strings in the right format representing
the positions that will be read out. [spatialfrequency,xi,xf,y].
Args:
position_file (str): The path of the position file.
Returns:
positions (list,str): List representing the positio... | 832d77e894c92b70edbcf330ad37bbaaf0cc3ed2 | 39,318 |
def children_matching(node, fn):
"""
Returns generator of child element nodes matching a predicate.
"""
return (n for n in node.childNodes
if n.nodeType == n.ELEMENT_NODE and fn(n)) | ec9b6e6239acc395947f9088610fcda192927665 | 39,320 |
def pow__mod_c(a, k, c):
"""computes a^k (mod c),
we assume a,k>=1, c > 1 integers"""
if (k == 0):
return 1
elif (k & 1):
return ((a * pow__mod_c(a, k//2, c)**2) % c)
else:
return ((pow__mod_c(a, k//2, c)**2) % c) | ab21e214e2f6aae2b32825db3e4e67b8d6a51efe | 39,322 |
from typing import List
from typing import Tuple
def get_triple(numbers: List[int], target: int) -> Tuple[int, int, int]:
""" get the triple from the list that adds up to the target number """
for x in numbers:
for y in numbers:
if x + y < target:
for z in numbers:
... | 7e319328cebddb21861ae2ef52b0f036e271bb63 | 39,323 |
import os
def get_destination_path(current_path: str) -> str:
"""Get the destination directory path of the copied test files."""
return os.path.join(current_path, "destination") | 33c309630d86e33382207466f61aac5194c7563a | 39,324 |
import torch
def group_hidden_by_segs(h, seg_ids, max_len):
"""
:param h: [B, T, H]
:param seg_ids: [B, T]
:return: h_ph: [B, T_ph, H]
"""
B, T, H = h.shape
h_gby_segs = h.new_zeros([B, max_len + 1, H]).scatter_add_(1, seg_ids[:, :, None].repeat([1, 1, H]), h)
all_ones = h.new_ones(h.... | 0ce74e7b042613490ddbead4a658461552a38697 | 39,326 |
import math
def _log2(n):
"""Returns the log base 2 of an integer."""
return math.log(n)/math.log(2) | 76921c835801e489d648482eadb5f1b52525a21b | 39,327 |
def get_bottom_right(left, right):
"""
Get bottom right on the screen
"""
x = right.x - (right.x - left.x) / 8
y = right.y - (right.y - left.y) / 8
return (x, y) | 681f6a3f3b7fe935ef36991bc040b998e9786633 | 39,328 |
def mask(seq, keep_start, keep_end):
"""Mask the sequence leaving only [keep_start, keep_end) unmasked"""
return 'N' * keep_start + seq[keep_start:keep_end] + 'N' * (len(seq) - keep_end) | 8df0b7d14e1ab2b2a5b9901539e2d2fa210f0eb4 | 39,331 |
def _getBuildObject(buildTypesModule, buildType):
"""Get the build object for the given build type string."""
if buildType.startswith('acceptance'):
build = buildTypesModule.GetBuildType('default' + buildType[10:])
elif buildType.startswith('longacceptance'):
build = buildTypesModule.GetBuil... | 5a46385fb6c1063ed89257731eb36069baaa9dd0 | 39,332 |
import requests
def read_changes(jenkins_url, build_url, build_id):
"""Read changes for the cause why the e2e job has been started."""
api_query = "{jenkins}/{job}{build}/api/json".format(jenkins=jenkins_url,
job=build_url, build=build_id)
response ... | b500cc1e5e3465c01569c53efa54f13671443312 | 39,333 |
import numpy
def training(inputs, minvar=0.1):
"""Trains a naive-bayes classifier using inputs
Returns means and variances of the classifiers
"""
return numpy.mean(inputs, axis=0), numpy.maximum(minvar, numpy.var(inputs, axis=0)) | dafbf883e99e53257e33021a2f917115bf303cbf | 39,334 |
import locale
def make_currency_format(input_list):
"""Wandelt alle Integer-Werte in einer Liste ins Währungsformat um"""
output_list = []
for item in input_list:
if type(item) == int or type(item) == float:
output_list.append(locale.currency(item, grouping=True))
else:
... | 14b1bac66f07d86e0f61fd2fb8259e630677d4be | 39,336 |
def player_turn_to_board_location(move):
"""Convert the players move to a board location."""
move -= 1
row, column = divmod(move, 3)
return row, column | 7b7a29775842f6224ba9c161bdfc17215e5079cd | 39,337 |
def semihardneg_triplet_loss_from_S(S, margin):
"""
Input: Similarity matrix S
Output: The one-way triplet loss from rows of S to columns of S. Impostors are taken
to be the most similar point to the anchor that is still less similar to the anchor
than the positive example.
You would need to run... | db4657eb1da34799b0b9ae5f79b64fdb811e0a4b | 39,338 |
def left(n):
"""Is node n a left descendant of the root in a zero-indexed boolean tree?"""
while n > 2:
n = (n-1)//2
return n == 1 | 52c81381bddd048cfb1e07f67f6028a3cfc15514 | 39,339 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.