content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
import platform
def is_win_platform():
"""
Checks if the current platform is Windows.
"""
WIN_PLATFORMS = ["windows", "cygwin", "cygwin_nt-10.0"]
return platform.system().lower() in WIN_PLATFORMS | c1e0eb0f57f69349c70470e6da13e687c1d72126 | 13,801 |
def get_full_name(participant):
"""Returns the full name of a given participant"""
return participant['fields']['First Name'].strip() + \
' ' + participant['fields']['Last Name'].strip() | 4292ea595d13e8093f6d221c40634e8fe74b8e91 | 13,802 |
import re
def join_list_item_to_content(snts):
"""
Evaluates a list of sentences to determininne if an itemized list is
present and then puts the number and list time into the same element of
the list.
:param snts: list of report sentences.
:return: List of sentences where list item and number... | 4cc33b7e9ab65c18b9dc0d587838bd5d56e9ffb6 | 13,803 |
def find_new_values(data, values, key):
"""Identify any new label/description values which could be added to an item.
@param data: the contents of the painting item
@type data: dict
@param values: the output of either make_labels or make_descriptions
@type values: dict
@param key: the type of v... | db56c07aedb38458be8aa0fc6bc4b5f4b49b4f4d | 13,804 |
import re
def _remove_handles_from_text(text: str) -> str:
"""
removes userhandles. ex: @JohnDoe
"""
return re.sub(r'(@[\w]*)', '', text) | c8f507d58d32ee3c1f38301255cd68fc2e36c666 | 13,805 |
import typing
from typing import OrderedDict
def order_by_dependencies(dependency_mapper: typing.Dict[str, typing.Set[str]]) \
-> typing.Tuple[typing.List[str], typing.List[str]]:
"""
You have to make sure there's no cycle dependency.
"""
ordered_dict = OrderedDict()
for _ in range(1000):
... | 23bc887549a722612180b6720adaf4925e886752 | 13,806 |
def getattritem(o,a):
"""
Get either attribute or item `a` from a given object `o`. Supports multiple evaluations, for example
`getattritem(o,'one.two')` would get `o.one.two`, `o['one']['two']`, etc.
:param o: Object
:param a: Attribute or Item index. Can contain `.`, in which case the final value ... | 7b928b2405691dcb5fac26b7a3d7ebfcfa642f6d | 13,807 |
def wgan_generator_loss(gen_noise, gen_net, disc_net):
"""
Generator loss for Wasserstein GAN (same for WGAN-GP)
Inputs:
gen_noise (PyTorch Tensor): Noise to feed through generator
gen_net (PyTorch Module): Network to generate images from noise
disc_net (PyTorch Module): Network to ... | 090de59ebc8e009b19e79047f132014f747972e7 | 13,809 |
def getDeploymentSections(deploymentInfos, nodesInformation):
"""
Combine deployments to the same nodes into lists in order to save on connect/disconnect time
:param deploymentInfos: deployment infos
:type: :class:`~storm.thunder.configuration.DeploymentInfos`
:param nodesInformation: nodes informa... | 3630f5ca0d7237fd2bdc0ce80026922eae20718f | 13,813 |
def find_val_percent(minval, maxval, x):
"""Find the percentage of a value, x, between a min and max number.
minval -- The low number of the range.
maxval -- The high number of the range.
x -- A value between the min and max value."""
if not minval < x < maxval:
print("\n" + " ERROR: X mu... | 13661bb2b6b230fa212ddd3ceb96c5b362d52f19 | 13,814 |
def name(who):
"""Return the name of player WHO, for player numbered 0 or 1."""
if who == 0:
return 'Player 0'
elif who == 1:
return 'Player 1'
else:
return 'An unknown player' | a553b64c7a03760e974b5ddeac170105dd5b8edd | 13,815 |
def mean(nums):
"""
Gets mean value of a list of numbers
:param nums: contains numbers to be averaged
:type nums: list
:return: average of nums
:rtype: float or int
"""
counter = 0
for i in nums:
counter += i
return counter / len(nums) | d3ea7af8792f4fdd503d5762b5c0e54765ce2d99 | 13,816 |
def process_data(dr): # 统一输入单词的长度,不足补0,此方法会增加训练时间
"""
:param dr: class data reader
:return: process X, Y
"""
return dr.XTrain, dr.XTest, dr.YTrain, dr.YTest # 这是为了统一一个表达方式,和之前的章节一样 | cc05605d77e25ed7363da3de9407d1f51b7dbf4b | 13,817 |
def threshold1(x, col, thresh):
""" 1-dimensional classification using a threshold function.
"""
return x[:, col] <= thresh | 5814ab93fe41e2e92f4648bfee1f8033ff0864b6 | 13,818 |
import torch
def compute_rank(predictions, targets):
"""Compute the rank (between 1 and n) of of the true target in ordered predictions
Example:
>>> import torch
>>> compute_rank(torch.tensor([[.1, .7, 0., 0., .2, 0., 0.],
... [.1, .7, 0., 0., .2, 0., 0.],
... | 0aed5b14ef9b0f318239e98aa02d0ee5ed9aa758 | 13,819 |
def udfize_lambda_string(code: str):
"""Return a string with the code as a function"""
return "lambda input: ({})".format(code)
# return "lambda input: (%s)" % code | c519c8ec408b00f033878b6083d4a922f32d2ac9 | 13,820 |
import json
def load_scalabel_frames( scalabel_frames_path ):
"""
Loads Scalabel frames from a file. Handles both raw sequences of Scalabel frames
as well as labels exported from Scalabel.ai's application.
Raises ValueError if the data read isn't of a known type.
Takes 1 argument:
scalab... | 7e5467d0f184dba1e3efc724391931ed4053a683 | 13,821 |
def ovs_version_str(host):
""" Retrieve OVS version and return it as a string """
mask_cmd = None
ovs_ver_cmd = "ovs-vsctl get Open_vSwitch . ovs_version"
with host.sudo():
if not host.exists("ovs-vsctl"):
raise Exception("Unable to find ovs-vsctl in PATH")
mask_cmd = host.r... | 607ffbb2ab1099e86254a90d7ce36d4a9ae260ed | 13,822 |
def maximum_displacement(initial_velocity):
"""Derived from s = 0.5 u + u t + 0.5 a t^2 at t = u and a = -1.
The (0.5 u) term comes from the order of rules of the motion of the
probe, the displacement changes before the velocities are
updated."""
return int(0.5 * initial_velocity * (1 + initial_vel... | c4b71ad83d787cae9ad9abe7d044b0e2d66b9cc0 | 13,823 |
from typing import List
def csv_rows(s: str) -> List[List[str]]:
"""Returns a list of list of strings from comma-separated rows"""
return [row.split(',') for row in s.split('\n')] | 7a6ea8c0f69801cfb1c0369c238e050502813b63 | 13,824 |
def GetMatchURL(soup):
"""Gets the ongoing match URL"""
live_match_url = soup.find("a", attrs={"class": "match-status-3"})["href"]
return live_match_url | bae3658c46976c7d43234e063d78eeea027d3095 | 13,825 |
import calendar
def create_disjunctive_constraints(solver, flat_vars):
"""
Create constrains that forbids multiple events from taking place at the same time.
Returns a list of `SequenceVar`s, one for each day. These are then used in the first
phase of the solver.
"""
events_for_day = [[] for _... | f7f8592ac00c8cac9808bb80d425ff1c1cf10b9e | 13,827 |
import os
import ntpath
def get_file_info(file_path : str) -> dict:
"""it takes a file path and returns information about the file like:
'directory': the directory path where the file resides
'base_file_name': the file name without extentation example.zip -> example
'flag_name' : 'base_file_name' + .f... | e46992217ee3869fae117a530fd020d644d9b1c4 | 13,828 |
def get_body(request):
"""
Return the body of a concrete publication.
"""
context = request['context']
entities = request['entities']
feed = context['feed']
ordinal = entities['ordinal'][0]['value']
body = feed[ordinal]['summary_detail']['value']
context['body'] = body
return con... | 53080b1727f0230a30b9fc4435d455a06e927be3 | 13,829 |
def get_default_snapshot_id(project):
""" Generate a snapshot id from data on the given project.
:param project: project object
:return: snapshot id
"""
def snapshot_id_from_branch_name(name):
return "{}:HEAD".format(name.replace('/', ':'))
default_branch = project.git.get_default_branc... | 2c542678036541372fa675e61b4f5a969cd5ab0f | 13,830 |
import random
def filter_shuffle(seq):
"""
Basic shuffle filter
:param seq: list to be shuffled
:return: shuffled list
"""
try:
result = list(seq)
random.shuffle(result)
return result
except:
return seq | 3f2dce2133ba32d8c24d038afaecfa14d37cbd4e | 13,831 |
def get_package_list_from_file(path):
"""
Create a list of packages to install from a provided .txt file
Parameters
__________
path: Filepath to the text file (.txt) containing the list of packages to install.
Returns
______
List of filepaths to packages to install.
Notes
... | 91ef3e634e98afd116d2be9c803620f672acd950 | 13,832 |
def parse_jcamp_line(line,f):
"""
Parse a single JCAMP-DX line
Extract the Bruker parameter name and value from a line from a JCAMP-DX
file. This may entail reading additional lines from the fileobj f if the
parameter value extends over multiple lines.
"""
# extract key= text f... | 84061c3f4bc42a62e308d5f93877e5c55d85efc1 | 13,833 |
def unwrapText(text):
"""Unwrap text to display in message boxes. This just removes all
newlines. If you want to insert newlines, use \\r."""
# Removes newlines
text = text.replace("\n", "")
# Remove double/triple/etc spaces
text = text.lstrip()
for i in range(10):
text = text.repl... | f37aafa3a003b3b06b8e9e1a03c833d05c5c0deb | 13,834 |
import argparse
def get_argparser():
"""Manage user parameters"""
parser = argparse.ArgumentParser()
parser.add_argument(
help="evaluation file generated by evaluate_stacks_results.py",
dest="input",
)
parser.add_argument(
help="yaml file with expected values",
dest... | 59816f23ae0ae834a78363ccac870484b4c154dc | 13,835 |
def getSubNode(prgNode, NodeName):
""" Find Sub-Node in Programm Node
Arguments:
prgNode {ua PrgNode} -- Programm node to scan
NodeName {[type]} -- Name of Sub-Node to find
Returns:
ua Node -- Sub-Node
"""
for child in prgNode.get_children():
if child.get_display_na... | 2da431eff566d7e2c76d4ca4646e15f762c00d4d | 13,837 |
import subprocess
def git_diff_pre_commit(fname):
"""Git diff for a pre-commit hook."""
diff = subprocess.check_output(["git",
"diff",
"--cached", fname])
return diff.splitlines() | f067b9bdcfdc0010f3840751722e1c5308a62592 | 13,839 |
def stations_by_river(stations):
"""This function returns a Python dict (dictionary) that maps river
names (the key) to a list of station objects on a given river."""
y = {}
for n in stations:
if n.river not in y:
y[n.river] = [n.name]
else: y[n.river].append(n.name)
ret... | 1e1023cdad87a3fdd5921d08448a4a2e9ceb311c | 13,840 |
def doTest(n):
"""Runs a test. returns score."""
score = 0
l = list(range(1,16))
for i in l:
if input("what is {} to the power of 3? ".format(i)) == str(i**3):
score += 1
print("Correct.")
else:
print("Wrong, the correct answer is {}".format(i**3)... | 83f32bec718e7459218b8863e229d5ecbd479d2c | 13,841 |
import numpy
def best_dice(l_a, l_b):
"""
Best Dice function
:param l_a: list of binary instances masks
:param l_b: list of binary instances masks
:return: best dice estimation
"""
result = 0
for a in l_a:
best_iter = 0
for b in l_b:
inter = 2 * float(numpy.... | d00c668fe8c97fa2a78a62ac94492c665dc4a311 | 13,843 |
def preorder(root):
"""Preorder depth-first traverse a binary tree."""
ans = []
stack = [root]
while stack:
node = stack.pop()
if node:
ans.append(node.val)
stack.extend([node.right, node.left])
return ans | e322df77a973f30b0745b36540a0f66b2ce29e6d | 13,844 |
import subprocess
def resolve_name(name):
"""Return the v4/v6 IP addresses for a given name, using local resolver"""
args = ['dig', '+short', name, 'A', name, 'AAAA']
return subprocess.check_output(args).decode().splitlines() | 2f63d2949bf6e66afa979b00fcb0c1b5a6ea2aed | 13,846 |
def joinfields(words, sep = ' '):
"""joinfields(list [,sep]) -> string
Return a string composed of the words in list, with
intervening occurences of sep. The default separator is a
single space.
(joinfields and join are synonymous)
"""
res = ''
for w in words:
res = res + (sep + w)
return res[len(sep):] | 0941a43811c992417a24ea59c77b4172117d3510 | 13,847 |
import socket
import fcntl
import struct
def get_ip_address(ifname):
"""
Get the ip address from the specified interface.
>>> get_ip_address('eth0')
'192.168.0.7'
@type ifname: string
@param ifname: The interface name. Typical names are C{'eth0'},
C{'wlan0'}, etc.
@rtype: string
@retu... | 731575a6b642884d7aa74a950ed109fca1e2086a | 13,849 |
from typing import Counter
def percentile(data: list, p=0.5):
"""
:param data: origin list
:param p: frequency percentile
:return: the element at frequency percentile p
"""
assert 0 < p < 1
boundary = len(data) * p
counter = sorted(Counter(data).items(), key=lambda x: x[0])
keys, c... | ac0a3a4705579c1b6a5165b91e6dcad65afcd1f4 | 13,851 |
def _get_path_from_parent(self, parent):
"""
Return a list of PathInfos containing the path from the parent
model to the current model, or an empty list if parent is not a
parent of the current model.
"""
if hasattr(self, 'get_path_from_parent'):
return self.get_path_from_parent(parent)
... | 8f213fcbe3612790d4922d53e0e2a4465b098fe6 | 13,852 |
def strdigit_normalize(digit):
"""Normalizes input to format '0x'. Example: '9' -> '09'"""
assert type(digit) is str, 'Invalid input. Must be a string.'
s = int(digit)
assert s >= 0, 'Invalid input. Must be string representing a positive number.'
if s < 10:
return '0' + str(s)
return digit | 41b119b4b8b19f978bf4445fc81273f7e62af59a | 13,853 |
import requests
def request_url(url):
"""
Function to send https or http request to this url and return code result.
Parameters
----------
url : string
This variable contain url must be checked
Returns
-------
status_code : int
Code result
"""
try:
ur... | 884d20d33f02110b31e47a29077cb4e093e93536 | 13,854 |
import os
def get_geant_installation():
"""
By checking low energy data ftom G4 installation,
return path to the G4 setup, typically in /opt/Geant/vXXXX
:returns: formatted string
:rtype: str
"""
try:
g4ledata = os.environ["G4LEDATA"]
except KeyError:
raise RuntimeErr... | b3d64d41c519c8d8538348024dc442a6d2cdfa12 | 13,855 |
def pad(array, n):
"""
ISO/IEC 9797-1 pad array to blocks of size n
"""
pads = len(array) % n
return array + [0]*(n - (len(array)%n)) | cc128428a8c446c1437b5b87d563d67bb2d11f48 | 13,858 |
import hashlib
def hash_file(pathname):
"""Returns a byte string that is the SHA-256 hash of the file at the given pathname."""
h = hashlib.sha256()
with open(pathname, 'rb') as ifile:
h.update(ifile.read())
return h.digest() | bdd82aa57abacee91a4631d401af35f0274eb804 | 13,859 |
import importlib
def convert(string, convert_type):
"""Execute convert.
This module call convert module selected from choices.
"""
module = importlib.import_module("converter." + convert_type)
return module.convert(string) | b0d89172b813df3f009b904339fe6af672917419 | 13,860 |
def get_resized_size(org_h, org_w, long_size=513):
"""get_resized_size"""
if org_h > org_w:
new_h = long_size
new_w = int(1.0 * long_size * org_w / org_h)
else:
new_w = long_size
new_h = int(1.0 * long_size * org_h / org_w)
return new_h, new_w | 699b91a1fbdb1e5228872d3ea5812dcc29cfbaa5 | 13,863 |
import random
def is_prime(number, test_count):
"""
Uses the Miller-Rabin test for primality to determine, through TEST_COUNT
tests, whether or not NUMBER is prime.
"""
if number == 2 or number == 3:
return True
if number <= 1 or number % 2 == 0:
return False
d = 0
r = ... | 49b0149dad5f053bbf813845a10267766784c775 | 13,864 |
def filter_entry(line, min_obs, min_indiv):
"""
Check the samples and filter
returns a bit flag with
0 - pass
1 - too-few observations
2 - too-few individuals
"""
data = line.strip().split('\t')
fmt = data[8].split(':')
dp_idx = fmt.index("PAD")
obs = 0
n_indivs = 0
f... | 5e8e98b256c8f07aa106dbf7a33df21a797d4bab | 13,868 |
import math
def data_to_sorted_xy(data, logx):
"""
Return a list of (x, y) pairs with distinct x values and sorted by x value.
Enter: data: a list of (x, y) or [x, y] values.
logx: True to return (log10(x), y) for each entry.
Exit: data: the sorted list with unique x values.
"""
i... | 7e84a3f684dc9a82bf5fd48256e5f5c18a5eedb6 | 13,870 |
def is_catalog_record_owner(catalog_record, user_id):
"""
Does user_id own catalog_record.
:param catalog_record:
:param user_id:
:return:
"""
if user_id and catalog_record.get('metadata_provider_user') == user_id:
return True
return False | bb5e649b4cfd38ee17f3ab83199b4736b374d312 | 13,871 |
import requests
def get_transmem_from_uniprot(uniprot_id):
"""
Retains transmembrane regions from Uniprot (first and last residue each).
This function requires internet access.
Parameters
----------
uniprot_id : str
The UNIPROT ID of the protein.
Returns
-... | 3fb8b5061d3ce051d108784a0b9e8d83c875feb3 | 13,872 |
def groupfinder(userid, request):
"""
find the user attached to the current user
"""
# result = None
# user = request.user
# if user is not None :
# result = GROUPS.get(user.email,['group:editors'])
# whatever every body is an editor
return ['group:editors'] | f23bab45b4170a2897bbd34a1068564b53e10a67 | 13,873 |
import random
def init(size):
"""Creates a randomly ordered dataset."""
# use system time as seed
random.seed(None)
# set random order as accessor
order = [a for a in range(0, size)]
random.shuffle(order)
# init array with random data
data = [random.random() for a in order]
return (order, data) | 975ab66f4e759973d55a0c519609b6df7086d747 | 13,874 |
def format_permissions(permission_bound_field):
"""
Given a bound field with a queryset of Permission objects, constructs a
list of dictionaries for 'objects':
'objects': [
{
'object': name_of_some_content_object,
'add': (add_permission_for_object... | 6b4b6f3488af1c5b47d8ae23e0e87d53ac1a925f | 13,875 |
def Unzip(iterable, container=None):
"""
iterable >> Unzip(container=None)
Same as izip(*iterable) but returns iterators for container=None
>>> [(1, 2, 3), (4, 5, 6)] >> Unzip(tuple) >> Collect()
[(1, 4), (2, 5), (3, 6)]
:param iterable iterable: Any iterable, e.g. list, range, ...
:para... | 86a05b353f5fa27aa17282c79e0441166c856f17 | 13,876 |
def v(n):
"""compute u value of the lhs matrix"""
return ((n ** 2) * (n + 1)) / 2 | 897f905b04812711841f06599565343d65af013e | 13,877 |
def greedy_set_cover(universe, subsets, costs):
"""Approximate greedy algorithm for set-covering. Can be used on large
inputs - though not an optimal solution.
Args:
universe (list): Universe of elements
subsets (dict): Subsets of U {S1:elements,S2:elements}
costs (dict): Costs of e... | aef8aa0b345d5ba01db841bdfb6485661d245d5d | 13,882 |
def bounding_rect(mask, pad=0):
"""Returns (r, b, l, r) boundaries so that all nonzero pixels in mask
have locations (i, j) with t <= i < b, and l <= j < r."""
nz = mask.nonzero()
if len(nz[0]) == 0:
# print('no pixels')
return (0, mask.shape[0], 0, mask.shape[1])
(t, b), (l, r) = [... | 850db378abb0a8e1675e0937b66dfb4061ced50b | 13,885 |
from os.path import isfile
def isFile(path: str):
""" Check whether path points to a file """
return isfile(path) | 44808693af570ebe18526830c96276522e5ad4ff | 13,886 |
import csv
def get_return_fields(filepath):
"""Extract the returnable fields for results from the file with
description of filters in ENA as a dictionary with the key being the field
id and the value a list of returnable fields
filepath: path with csv with filter description
"""
returnable_fi... | d70efe68de8cbd100b66cee58baf6ca542cb81a8 | 13,887 |
def generic_sum(algorithm):
"""compute digest based on algorithm passed in parameter
:param algorithm: hashlib algorithm to use
:return: digest returned by the algorithm
"""
def hash_sum(fileobj):
"""compute digest by chunks multiple of the block_size
:param fileobj: Open file(-l... | 5f3f3e00b9a1878d416491a06453cfeed4e0884c | 13,888 |
from typing import Any
def encode_voltage(value: Any) -> bytes:
"""Encode voltage value to raw (2 bytes) payload"""
return int.to_bytes(int(value * 10), length=2, byteorder="big", signed=True) | f970783eb7d84b61d9db8c230a6a5622b571635d | 13,890 |
def merge_dict(x,y):
"""
将字典x合并入字典y
"""
for k,v in x.items():
if k in y.keys():
y[k]=str(y[k])+";"+str(v)
else:
y[k] = v
return y | 2251af1fe611ba7c2bf9978094ad0f649bd4d4d7 | 13,891 |
import random
def roll_damage(dice_stacks, modifiers, critical=False):
"""
:param dice_stacks: Stacks of Dice to apply
:param modifiers: Total of modifiers affecting the roll
:param critical: If is a critical damage roll
:return: Total damage to apply.
"""
if critical:
for dice_sta... | 2627f1de0fe0754a4bfc802378ea1950b2b078a2 | 13,892 |
def get_audio_bitrate(bitrate):
"""
Get audio bitrate from bits to human easy readable format in kbits.
Arguments:
:param bitrate: integer -- audio bitrate in bits per seconds
:return: string
"""
return "%s kbps" %(bitrate/1000) | 847d74e08e8f75b24be1fc144fb3896f5e141daf | 13,893 |
def _mesh_to_mat_cards(mesh, divs, frac_type):
"""Prepares the material cards for mesh_to_geom."""
mat_cards = ""
idx = mesh.iter_structured_idx('xyz')
for i in idx:
mesh.mats[i].metadata['mat_number'] = int(i + 1)
mat_cards += mesh.mats[i].mcnp(frac_type=frac_type)
return mat_cards | 2d3cbd8d4a371244938ce1b9aa1e2532801e705d | 13,894 |
def output_prefix(prefix):
"""Decorate a function to add a prefix on its output.
:param str prefix: the prefix to add (must include trailing whitespace if
desired; Sopel does not assume it should add anything)
Prefix will be added to text sent through:
* :meth:`bot.say <sopel.b... | 8f7e333b3fd40725b3d9681cfdf432d01cb8d24e | 13,896 |
import collections
def load_manifest(manifest_path):
"""Extract sample information from a manifest file.
"""
# pylint: disable=I0011,C0103
Sample = collections.namedtuple("Sample", "id status path")
samples = []
with open(manifest_path, "r") as manifest_file:
for line in manifest_fi... | 21e15fa8de75d963f8d35c4b5f939d3fcee45c99 | 13,898 |
def _get_ascii_token(token):
"""Removes non-ASCII characters in the token."""
chars = []
for char in token:
# Try to encode the character with ASCII encoding. If there is an encoding
# error, it's not an ASCII character and can be skipped.
try:
char.encode('ascii')
except UnicodeEncodeError:... | e77f9fe9d59cbcee8cd1893e56a988b70a15542a | 13,899 |
import json
def list_response():
"""JSON:API list pytest fixture."""
return json.load(open('tests/responses/example_list.json')) | f4e815f452ae3e0eb806bbd816c429ad0a63c413 | 13,900 |
def _get_all_osc(centers, osc_low, osc_high):
"""Returns all the oscillations in a specified frequency band.
Parameters
----------
centers : 1d array
Vector of oscillation centers.
osc_low : int
Lower bound for frequency range.
osc_high : int
Upper bound for frequency ra... | 9199283080bd0111d8ca3cb74f4c0865de162027 | 13,903 |
def keras_decay(step, decay=0.0001):
"""Learning rate decay in Keras-style"""
return 1.0 / (1.0 + decay * step) | b922e999ff678127535988eaf04b35e2be2a9117 | 13,904 |
def PublicAPI(obj):
"""Annotation for documenting public APIs.
Public APIs are classes and methods exposed to end users of RLlib. You
can expect these APIs to remain stable across RLlib releases.
Subclasses that inherit from a ``@PublicAPI`` base class can be
assumed part of the RLlib public API a... | 62f5567fe67e6a7048ae9c6fc11ae58bcec49fb5 | 13,905 |
def get_dtd_menu_texts(has_dtd):
"""determine text to update dtd menu with
"""
# how to use in gui.<xx>.py:
# def adjust_dtd_nemu(self):
# label, helpstr = shared.get_dtd_menu_texts(self.dtdmenu.has_dtd)
textdict = {'label': '{} &DTD', 'help': '{} the Document Type Declaration'}
re... | 359a91ec3b0bfe5cc28f1b3cf0ec44e9f34bd210 | 13,907 |
from typing import OrderedDict
def load_section(cp, section, ordered=True):
"""
Returns a dict of the key/value pairs in a specified section of a configparser instance.
:param cp: the configparser instance.
:param section: the name of the INI section.
:param ordered: if True, will return a <colle... | 9b819efb75082138eb9e13405ac256908112c744 | 13,908 |
def match_task(question: str, keywords: list):
"""Match question words with the keywords.
Return True and the matched word if at least one word is matched.
"""
for word in question.split(" "):
for kw in keywords:
if word == kw:
return word
return "" | 52b5f3188cd4d3faffcebf66572c3d3a40a43de8 | 13,909 |
import json
def open_json(path):
"""Open the db from JSON file previously saved at given path."""
fd = open(path, 'r')
return json.load(fd) | c0c0c4857b4582091a145a71767bc0168808593a | 13,911 |
import torch
def prep_fft_channel(x):
""" Rotates complex image dimension from channel to last position. """
x = torch.reshape(x, x.shape[:-3] + (x.shape[-3] // 2, 2) + x.shape[-2:])
return x.permute(*range(x.ndim - 3), -2, -1, -3) | ad6be1660239a87b60cf6be838caf37988ef19ca | 13,912 |
def consolidate_events(ev_list):
"""
Consolidates the busy times of multiple calenders so there is no overlap in busy events
"""
consolidated = []
for i in range(len(ev_list)-1):
ev = ev_list[i]
next = ev_list[i+1]
#If the next busy event starts before the current ev... | 612015c2200eb29c3f2303807e449da465354927 | 13,913 |
def convert_resolv_conf(nameservers, searchdomains):
"""Returns a string formatted for resolv.conf."""
result = []
if nameservers:
nslist = "DNS="
for ns in nameservers:
nslist = nslist + '%s ' % ns
nslist = nslist + '\n'
result.append(str(nslist))
if searchdo... | 47175fb2dddac151a94b99b1c51942a3e5ca66a1 | 13,915 |
def password_okay_by_char_count(pwd_row):
"""
Process list of rows from a file, where each row contains pwd policy and pwd.
Pwd is only valid if the indicated character is found between x and y times (inclusive) in the pwd.
E.g. 5-7 z: qhcgzzz
This pwd is invalid, since z is only found 3 times, bu... | 4571d1d6e47aef1c31257365cd0db4240db93d6c | 13,917 |
import itertools
def tee():
"""Duplicate a sequence by making independent iterators."""
duplicates = itertools.tee('ABC', 2)
duplicates = [''.join(copy) for copy in duplicates]
return duplicates | 33ce3884589c14b789243eb50d74b1f19e942356 | 13,918 |
def _getSubjectivityFromScore( polarity_score ):
"""
Accepts the subjectivity score and returns the label
0.00 to 0.10 - Very Objective
0.10 to 0.45 - Objective
0.45 to 0.55 - Neutral
0.55 to 0.90 - Subjective
0.90 to 1.00 - Very Subjective
"""
status = "unknown"
if ( 0... | 16e126032fea92d0eac2d4e6b35c9b6666196ad1 | 13,919 |
import base64
def extract_basic_auth(auth_header):
"""
extract username and password from a basic auth header
:param auth_header: content of the Authorization HTTP header
:return: username and password extracted from the header
"""
parts = auth_header.split(" ")
if parts[0] != "Basic" or l... | 8f3830bc78b0e9fb6182f130e38acea4bd189c86 | 13,920 |
def xor(b1, b2):
"""Expects two bytes objects of equal length, returns their XOR"""
assert len(b1) == len(b2)
return bytes([x ^ y for x, y in zip(b1, b2)]) | 3376df85b52cea276417e29ae81c80208dc28b86 | 13,921 |
def setOfWordsToVecTor(vocabularyList, smsWords):
"""
SMS内容匹配预料库,标记预料库的词汇出现的次数
:param vocabularyList:
:param smsWords:
:return:
"""
vocabMarked = [0] * len(vocabularyList)
for smsWord in smsWords:
if smsWord in vocabularyList:
vocabMarked[vocabularyList.index(smsWord)... | f14d8fed8a59deb44fc14161de8ae1eaf3ee8b00 | 13,922 |
import re
def is_valid_file(filename):
"""
Validates file is of type obj
:param filename: str
"""
return re.match(r'^.+\.?(obj|asm)$', filename) is not None, filename[-3:] | 6f0032693f0097f85ec09e802a2ab870095a232e | 13,923 |
import re
def clean_description(text):
"""The original datasource introduces some common, incorrect encodings.
Fix them here"""
text = text.replace("\u00c2\u00bf", "'")
text = re.sub(r"<\s*br\s*/?>", "\n", text, flags=re.IGNORECASE)
text = re.sub(r"</\s*br>", "", text, flags=re.IGNORECASE)
ret... | 6778c32058137c7af1d99bf52baaa0889a559e95 | 13,924 |
def LinearTransformation(translation, rotation, x, y):
"""
Apply linear transformations to a set of positions in 2 dimensions.
INPUTS
translation : translation vector
rotation : rotation matrix
x : x-coordinates
y : y-coordinates
OUTPUTS
x : transformed x coo... | e674f215c46ecc6f46da0c1e7074210583f59088 | 13,925 |
def get_safe(dic, *keys):
"""
Safely traverse through dictionary chains
:param dict dic:
:param str keys:
:return:
"""
no_d = dict()
for key in keys:
dic = dic.get(key, no_d)
if dic is no_d:
return None
return dic | 17f810ba995314088f93152179e988df436adb47 | 13,926 |
import random
import string
def random_string(length=1, unicode=False):
"""
Returns random ascii or unicode string.
"""
if unicode:
def random_fun():
return chr(random.choice((0x300, 0x2000)) + random.randint(0, 0xff))
else:
def random_fun():
return random.c... | 45760b3e3c42e484d51abf76f9eb2ae0c8132fd1 | 13,928 |
import os
import subprocess
def is_mysql_running():
"""
Returns True if mysql is running, False otherwise.
"""
# We need to check whether or not mysql is running as a process
# even if it is not daemonized.
with open(os.devnull, 'w') as os_devnull: # lint-amnesty, pylint: disable=bad-option-v... | 56aa092863f9de700952c423901326660bd29383 | 13,929 |
import math
def probability(ec, en, t):
"""
Probability function
:param ec: current energy
:param en: next energy
:param t: temperature ratio
:return: probability value
"""
return math.exp((ec - en) / t) | c055081cd93473ecf4abeab1c8b5cc36fb38f0a4 | 13,930 |
def getGamesListUrl(user_name, page, block_size=100):
"""Returns lichess url for downloading list of games"""
URL_TEMPLATE = "https://en.lichess.org/api/user/{}/games?page={}&nb={}"
return URL_TEMPLATE.format(user_name, page, block_size) | 314bc8771628944dde1e52299697362482afd9b1 | 13,932 |
def add_ext(name, ext, seq=-1):
"""add_ext constructs file names with a name, sequence number, and
extension.
Args:
name (string) - the filename
ext (string) - the file extension
seq (int) - the number in a sequence with other files
(Default -1) means that it is a standalone
file
"""
#add peri... | 650eee088ae58d182c49f35f37e5b8deac57fa1d | 13,933 |
def get_coding_annotation_fasta(seq_record):
"""
When passed a sequence record object returns an array of FASTA strings for each annotation.
:param seq_record: A Biopython sequence record object.
:return: A FASTA file string containing all sequences record object CDS sequence features.
"""
fasta = []
features =... | 4fa24279ebb89ea7c61eeae6614c1fa309ffad87 | 13,936 |
from typing import Union
def bars_to_atmospheres(bar: float, unit: str) -> Union[float, str]:
"""
This function converts bar to atm
Wikipedia reference: https://en.wikipedia.org/wiki/Standard_atmosphere_(unit)
Wikipedia reference: https://en.wikipedia.org/wiki/Bar_(unit)
>>> bars_to_atmospheres(3... | d460021395af77acda01296710f145e9b52d8594 | 13,937 |
def get_ast(token):
"""
Recursively unrolls token attributes into dictionaries (token.children
into lists).
Returns:
a dictionary of token's attributes.
"""
node = {}
# Python 3.6 uses [ordered dicts] [1].
# Put in 'type' entry first to make the final tree format somewhat
# ... | 3074b6a64061dd5cfb2209d803ab060203dfec06 | 13,938 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.