content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def getRailCoordinates(message, key):
"""Return a list of x, y coordinates of the rail in its zig zag order."""
railCoordinates = []
y = 0
direction = 'DOWN'
for x in range(len(message)):
railCoordinates.append((x, y))
if direction == 'DOWN':
y += 1
if y == ke... | 19d858aa41c8513e2da52c65d19352b2e028bb14 | 48,746 |
import subprocess
def resource_get(name):
"""used to fetch the resource path of the given name.
<name> must match a name of defined resource in metadata.yaml
returns either a path or False if resource not available
"""
if not name:
return False
cmd = ['resource-get', name]
try:
... | 34e1a69044e4b131b99ff314f00db9a866391b91 | 48,747 |
import subprocess
def call(*popenargs, **kwargs):
"""overwrite subprocess.call method to still
record outputs (former implementation do not call 'communicate()')
"""
_p = subprocess.Popen(stdout=subprocess.PIPE, stderr=subprocess.PIPE, *popenargs, **kwargs)
# this insure that we record everythhing... | 9d0e3659767d948fde5a47eb99b4d2abf9fef212 | 48,748 |
def simplify_arg_role_name(role_name: str):
"""Converts the name of the argument role to the simple form (e.g. "Time-Within" to "Time").
"""
cols = role_name.split("-")
if len(cols) > 1 and cols[0] != "Time":
print(cols)
return cols[0] | b9cba2234da2656055945da7c39896b1d4d29416 | 48,749 |
import textwrap
def wrap(to_wrap, width=70):
"""Preserve new line char in textwrap"""
out = []
for line in to_wrap.split('\n'):
if not line:
out.append('')
wrapped = textwrap.wrap(line, width=width)
for wrapped_line in wrapped:
out.append(wrapped_line)
r... | e5a8e7f4ab1935883a2e2174e8f642e27ecb3447 | 48,750 |
def get_activity_charts_data(activity_actions, sync_user):
"""Get data for Translation activity and Review activity charts."""
human_translations = set()
machinery_translations = set()
new_suggestions = set()
peer_approved = set()
self_approved = set()
rejected = set()
for action in act... | 39472e8396799654ea7fe5bf1c304161b5f3ea92 | 48,751 |
def find_nth_loc(string=None, search_query=None, n=0):
"""
Searches the string via the search_query and
returns the nth index in which the query occurs.
If there are less than 'n' the last loc is returned
:param string: Input string, to be searched
:type string: str
:param search_query:... | 1293bda0ee8a681e8b8647e10fcbadda2a788df5 | 48,755 |
from typing import Sequence
def count_number_of_depth_increases(depths: Sequence[int], window_size: int = 1) -> int:
"""Counts the number of times depth increases in a sequence of sonar measurements."""
depth_changes = (
sum(depths[i : i + window_size]) - sum(depths[i - 1 : i - 1 + window_size])
... | 8435c3ea61c204ee3db9565f929e0b510420e127 | 48,756 |
def main(*, equation: str) -> dict:
"""
Gets the result of a calculation
:param formula: Stuff on which calculation will be carried on Example: 5+7*9
:return: Dictionary
"""
try:
new_equation = equation.replace("^", "**")
new_equation = equation.replace("\\", "/")
return ... | 59166d19f1bd5aeac32f24f09060e729b75024ad | 48,757 |
import traceback
import sys
def create_schema(connection, schema_name):
"""This function add the schemas into databases"""
try:
old_isolation_level = connection.isolation_level
connection.set_isolation_level(0)
pg_cursor = connection.cursor()
pg_cursor.execute("CREATE SCHEMA %s... | 8d65a79bb880c0da45d9986f4cebdabeaa8b71a2 | 48,758 |
def get_data_label_id(label_datas):
""" 获取数据对应的标签id映射字典 """
label2id = {}
data_label_id = {}
for line in label_datas:
line = line.replace('\n', '')
data_id = line.split('\t')[0]
label_ids = line.split('\t')[1].split(',')
for label_id in label_ids:
label2id[la... | 23950255504d90b522d4ed6a19782ffcbadea1f8 | 48,759 |
def validate_tag(tag):
""" Chceks if tag is valid. Tag should not be empty and should start with '#' character """
tag = tag.strip().lower()
return len(tag) > 1 and tag.startswith("#") | 16e112376368567dee7d03faed8f37f14931328b | 48,760 |
import os
def check_database(third_party_info, third_party_evidence):
"""
Given dictionary of third party SDKs returns type of SDK
:param third_party_info: dictionary of SDK Classifications
:param third_party_evidence: evidence list of sdks
:return third_party_evidence: updated evidence list of S... | dada9c000addda6e2c7d027610255fe21c145bfd | 48,761 |
import logging
def make_url(url_no_file="https://files.rcsb.org/download/", organism_entry="2ki5"):
"""
Takes the download URL without the file of the PDB database and the organism entry
and converts it in to a download link for the PDB file.
Returns the full URL for download.
"""
logging.inf... | 6a1352b66d2657dc57d9d1a907f36f7cb4390bd7 | 48,766 |
def make_linear_part(max_score, min_score):
"""
:param bottom: the proportion of the graph used for the bottom "sigmoid"
:param middle: the proportion of the graph used for the middle linear part
:param top: the proportion of the graph used for the top "sigmoid"
:param max_score: the maximum score s... | 8151c78032fe65342459223cadcf3a03f1cc6aa6 | 48,767 |
def expose_header(header, response):
"""
Add a header name to Access-Control-Expose-Headers to allow client code to access that header's value
"""
exposedHeaders = response.get('Access-Control-Expose-Headers', '')
exposedHeaders += f', {header}' if exposedHeaders else header
response['Access-Con... | 049383730da4fbc5a6286ed072655c28ea647c1e | 48,768 |
def unique(lst):
"""
Returns a copy of 'lst' with only unique entries.
The list is stable (the first occurance is kept).
"""
found = set()
lst2 = []
for i in lst:
if i not in found:
lst2.append(i)
found.add(i)
return lst2 | 6e50803439b65a3fa71814956e947103ca2b634d | 48,769 |
import math
def pickLabelFormat(increment):
"""Pick an appropriate label format for the given increment.
Examples:
>>> print pickLabelFormat(1)
%.0f
>>> print pickLabelFormat(20)
%.0f
>>> print pickLabelFormat(.2)
%.1f
>>> print pickLabelFormat(.01)
%.2f
"""
i_log... | a91372f7b1b770531b23147a6704a20bf8a5e689 | 48,770 |
def func(x, y):
"""Documentación de la función. Hace x * y - 5"""
return x * y - 5 | 52679233c492d45933289be05854bffccf741b5b | 48,771 |
def ensure_valid_model_type(specified_type, model_type_list):
"""
Checks to make sure that `specified_type` is in `model_type_list` and
raises a helpful error if this is not the case.
Parameters
----------
specified_type : str.
Denotes the user-specified model type that is to be checked... | 6708e44d7ea381c89ea31343cb8f435f40fc279f | 48,772 |
import heapq
def top10(m):
"""Return the top 10 keys from a dict ordered by their values."""
return heapq.nlargest(10, m.keys(), key=m.get) | 3e5e5eddf6c11a4a46fcb0e3e9bc342cfa219826 | 48,773 |
from typing import Union
def find_error_character(chunk: str) -> Union[str, None]:
"""Find the first illegal character for a given chunk."""
stack = []
bracket_mapping = {")": "(", "]": "[", "}": "{", ">": "<"}
open_brackets = ["(", "[", "{", "<"]
for char in chunk:
if char in open_br... | fd5aa5360f68b2e61f7d658caedbf1ec67b9de99 | 48,774 |
import platform
def generate_user_agent(package_name: str, package_version: str) -> str:
"""Generate a user-agent string in the form <package info> <python info> <os info>.
Parameters
----------
package_name : str
Name of the package to include in the user-agent string.
package_version : ... | adb7d164de435c606a01abc35c963b0f8d5505e8 | 48,776 |
def clean_headers(headers):
"""Takes headers dict and removes irrelivant headers."""
response = dict()
for k, v in headers.items():
if k.upper().startswith('X'):
response[k] = v
return response | 6965b8c9a9850513181d0f24a6de4f48b79529f8 | 48,777 |
def summary(txt):
"""
Returns the first line of a string.
"""
lines = txt.split('\n')
return lines[0] | eb86e9a5225f2b99b500b79927ef3af1ccc7fabb | 48,778 |
def dict_no_none(*args, **kwargs) -> dict:
"""
Helper to build a dict containing given key-value pairs where the value is not None.
"""
return {
k: v
for k, v in dict(*args, **kwargs).items()
if v is not None
} | de0dbf04f0cea588f190f9ae52cf2696e0c5c6ea | 48,779 |
from typing import Any
def shortname(obj: Any) -> str:
"""Get object name (non-qualified)."""
if not hasattr(obj, '__name__') and hasattr(obj, '__class__'):
obj = obj.__class__
return '.'.join((obj.__module__, obj.__name__)) | 78a3d85ad11e8262d515fb2bead6c9d9fdbf085b | 48,780 |
import numpy
def kurtosisTest(kurt, n):
"""
@brief Transforms the kurtosis to a normal distribution
"""
n = float(n)
e = 3.*(n-1.)/(n+1.)
v = 24.*n*(n-2.)*(n-3.)/(n+1.)**2/(n+3.)/(n+5.)
mask = kurt != 0
x = (kurt[mask] - e)/numpy.sqrt(v)
b = 6.*(n**2-5.*n+2.)/(n+7.)/(n+9.)*numpy.sq... | 0b59f186dd679ca186da710853b95af20ec245d3 | 48,781 |
def unique(sequence):
"""
Returns a unique list preserve the order of original list
"""
seen = set()
return [x for x in sequence if not (x in seen or seen.add(x))] | 433bc766e21f1e0a6e983383054f51ba84cd5636 | 48,783 |
def flatten(items):
"""Removes one level of nesting from items
Parameters
----------
items : iterable
list of items to flatten one level
Returns
-------
flattened_items : list
list of flattened items, items can be any sequence, but flatten always
returns a list.
... | 5c280d08911e4fdbd32de3e20e75410e871b1d57 | 48,784 |
def get_help_text(instance, field_name):
"""
Returns help_text for a field.
inspired by https://stackoverflow.com/questions/14496978/fields-verbose-name-in-templates
call in template like e.g. get_help_text <classname> "<fieldname>"
"""
try:
label = instance._meta.get_field(field_name).... | b2432ee430744c28630efe27489c68607ca0a495 | 48,785 |
def first_column_empty_5():
"""First column is empty ... test will demonstrate this edge case can be handled"""
return [
[],
[
{"id": 5, "name": "Asparagus", "colour": "green", "count": 9, "herb": False},
{"id": 2, "name": "Basil", "colour": "green", "count": 5, "herb": T... | 6fcd16c259b838ba80257194684c71b7736536fb | 48,786 |
import inspect
import os
def rel_path(relative_filename):
"""Returns the full path of the file relative to the caller module.
:param relative_filename: target filename relative to the caller's
containing folder.
:return: the full path of the target relative file.
"""
# Extract the filename... | 8fd02357000e6b29bced6d617bf2f11cd3b389ba | 48,787 |
def _format_collider_string(colliders):
""" Write the string for the bath gas collider and their efficiencies
for the Lindemann and Troe functional expressions:
:param colliders: the {collider: efficiency} dct
:type colliders: dct {str: float}
:return: collider_str: Chemkin string w... | 4e4aa8ae46dfcf05f00222b4cf5c95384977d651 | 48,788 |
def get_bbox_limits(bbox):
"""
This module gets a bbox and transform it in this format [x_start, y_start, width, height]
and transform it into this format [x_start, y_start, x_end, y_end]
"""
bbox[:,2] += bbox[:,0]
bbox[:,3] += bbox[:,1]
return bbox | 42d066d8e028d73b60543b8f6916100c8709047d | 48,790 |
import time
import logging
def l__(msg, out=True):
"""
... starting logging msg giving a time stamp ...
"""
logging.info(' ' + msg + ' -->')
if out:
return time.time() | ea4f68158e44a9922b8b4d32feac26bad50deee7 | 48,792 |
def is_users_personal_account(context, account):
"""
Return `true` if the current path is for the user's personal account.
Used to determine which items to show in the settings submenu.
"""
request = context["request"]
return account.is_personal and (
request.path.startswith("/me/")
... | 9a5938761fb3a8c5876152bb326f008b8e607f95 | 48,793 |
from pathlib import Path
import toml
def set_fields_from_pyproject(
fields: dict,
pyproject_path: Path = Path(__file__).parents[2].joinpath("pyproject.toml"),
name: str = "inboard",
version: str = "0.1.0",
) -> dict:
"""Create a dictionary of keys and values corresponding to pydantic model fields.... | 52d2764c3286a348f6cf9a5e371c030e9df6e4fc | 48,794 |
def split_data(data):
"""
:param data: 36 * H * W
:return:
"""
x1, y1 = data[0:32 + 1:4], data[1:32 + 2:4]
x2, y2 = data[2:32 + 3:4], data[3:32 + 4:4]
return x1, y1, x2, y2 | 5728093118e0c16a90015c1af26c1124f65ba9a4 | 48,795 |
import random
import string
def _rand_id(ncar: int = 8) -> str:
"""Random hash"""
return ''.join([random.choice(
string.ascii_letters + string.digits)
for n in range(ncar)]) | 7978509db06f22713062489fd1c174fcdd82fb17 | 48,796 |
def byte_unit(file_size):
"""
バイトの単位を変換
Parameters
----------
file_size : int
ファイルのバイト数
Returns
----------
(return) : str
適切な単位に変換後の文字列
"""
if file_size < 1024:
return str(file_size) + ' B'
elif file_size < 1024**2:
return str(round(file_size... | d9df45cfd81a14d6a92403a632cac1827c4f6595 | 48,797 |
def kl_div(mean, log_var):
"""Kl divergence
Args:
mean: mean vector
log_var: log variance vector
Returns:
kl divergence
"""
loss = 0.5 * (mean.pow(2) + log_var.exp() - log_var - 1).mean(dim=0)
return loss.sum() | b91790d922c259c09103023112bbeb30a38ed67d | 48,799 |
def layer_size(X, Y):
"""
Get number of input and output size, and set hidden layer size
:param X: input dataset's shape(m, 784)
:param Y: input labels's shape(m,1)
:return:
n_x -- the size of the input layer
n_h -- the size of the hidden layer
n_y -- the size of the output layer
"""... | 81add6bf528cfe872e62f622161bb25fb7dcb1d3 | 48,800 |
from typing import Set
def done(job: str, completed: Set[str]) -> str:
"""Convert set membership into `Yes` for `No`.
:param job: The job to check if it was acted on
:param completed: The jobs acted on,
:returns: Yes or No
"""
return 'Yes' if job in completed else 'No' | 6d056f2471dafb3cab274ffb916e073c2fb62cf6 | 48,801 |
from typing import get_origin
from typing import get_args
def has_origin(typ, origin, num_args=None):
"""
Determines if a concrete class (a generic class with arguments) matches an origin
and has a specified number of arguments.
This does a direct match rather than a subclass check.
The typing c... | 9ba281ac18f1e152d9456103a61070e8e6c70e09 | 48,804 |
def sol(request):
"""Establish a small range of sols over which to test."""
return request.param | 0f001d2e4b3af6a50471e7dffb861b716dfcc13f | 48,806 |
def extend(cls, static=False):
"""Extends the cls class.
Parameters
----------
cls : class
Class to extend.
static : boolean, default = False
Wheter extend as a static method.
Returns
-------
decorator
Decorator for extending classes.
"""
if static:
... | ab3456d11b2ce7edde1a468e743fc77bcc1e3f58 | 48,807 |
def create_collector(collector_class, result_dir, test_name):
"""Return a new Collector of the given class
:param collector_class: The collector class to be used.
:param result_dir: Directory with test results
:param test_name: Test to be run
:return: A new CollectorController.
"""
return c... | 5780297706e8ee00b3e7cc7cfd5da7997fd5dd66 | 48,808 |
def class_values(names_file):
"""Get integer value of classes from .names file
Args:
names_file (type): File containing a list of classes.
Each line of the file should contain
a separate class name
Returns:
class_dict (dict): Dict that ... | 5b856853edac6b14cb3246a776d2584655b593b2 | 48,809 |
from typing import Dict
def multimodel_num_layers() -> Dict[str, int]:
"""Number of layers in each of sub-models in `multimodel` fixture."""
return {
'encoder': 2,
'forecaster': 6,
'combined': 10,
} | 115e274decf2e18f5fae31d07fca46183853f513 | 48,810 |
def sublist(list1: list, list2: list) -> bool:
"""
Check if all the element of list1 are inside list2, preserving
the order and subsequence of the elements
:param list1: list1 of element to find
:param list2: list2 target list
:return: a boolean which represent True if the statement is
respe... | 6981a35efe0bb18b9d2ca2593a9f38ea049acb28 | 48,811 |
def getstring(data):
"""convert data from file into a text string
"""
result = ''
for bytechar in data:
if bytechar == b'\x00':
continue
result += str(bytechar)
return result | 4abd5468da4878efd122bc707edb2b6a726ce1ab | 48,812 |
def read_answers(filename, sep):
"""
Read word-sense-annotated file and create data structure
that translates each word sense to an id
"""
with open(filename, 'r') as f:
words = []
senses = []
senses_id = {}
sense_count = 0
for line in f.readlines():
... | 3c69be23f3030cc777eebff094da2e4bf1e16004 | 48,814 |
from typing import Dict
from typing import List
def get_available_languages(localisation: Dict) -> List[str]:
"""Get list of languages that are available for outputting human readable
procedure descriptions.
Args:
Dict: Localisation collection, e.g. ``PlatformClass().localisation``
Returns:
... | 25506eb7a7819f89b54df05e67e65c44f58285bb | 48,815 |
def sql_number_list(target):
"""
Returns a list of numbers suitable for placement after the SQL IN operator in
a query statement, as in "(1, 2, 3)".
"""
if not target:
raise ValueError
elif not isinstance(target, list):
target = [target]
return "(%s)" % (", ".join(["%d" % (i... | 386a8d10ed9fb7f625080eb3636f9d3909cacc6a | 48,816 |
import torch
def fold(input: torch.Tensor,
window_size: int,
height: int,
width: int) -> torch.Tensor:
"""
Fold a tensor of windows again to a 4D feature map
:param input: (torch.Tensor) Input tensor of windows [batch size * windows, channels, window size, window size]
:para... | 92a68279b357f8b977d4b144fd249540de833fb5 | 48,817 |
from typing import Optional
from pathlib import Path
def to_uri(
path: str, local_basedir: Optional[Path] = None, relative_prefix: str = ""
) -> str:
"""
Given a path or URI, normalize it to an absolute path.
If the path is relative and without protocol, it is prefixed with `relative_prefix`
befo... | 6ebe76a1574fe844d808ac4889afe163d9d3131a | 48,818 |
from docutils.core import publish_string
def html(text, **kwargs):
"""Returns the text as html."""
# assuming run from the correct directory
return publish_string(source=text, writer_name='html', **kwargs) | 9aaecf69bf1f7bce109a74242df2f2901d237261 | 48,819 |
def need_depend(glyph):
""" Finds RGlyph object that needs depend attribute. """
return not glyph.name.endswith('V') and glyph.hasOverlap() | 6f253d96e90aef44baaec43a437d62f65e152782 | 48,820 |
def unscale_bb(bounding_box, shape):
"""
compute absolute bounding box
:param bounding_box: [x, y, w, h] relative bounding box
:param shape: shape of [x, y, w, h]
:return:
"""
abs_x = bounding_box[:, 0] * shape[:, 0]
abs_y = bounding_box[:, 1] * shape[:, 1]
abs_width = bounding_box[:, 2] * shape[:, 0]
abs_hei... | 71c8be2c864988c5abd4368db05ec24b411474a8 | 48,821 |
import argparse
def parse_args():
"""Generate args."""
parser = argparse.ArgumentParser()
parser.add_argument(
"--in_file", type=str, required=True, help="File to extract mentions from"
)
parser.add_argument(
"--out_file",
type=str,
required=True,
help="File... | 7ee93b3ea0badb0a4cef1c53628875cfac52cdb3 | 48,822 |
import ast
def safe_determine_type(string):
"""
Determine the python type of the given literal, for use in docstrings
Args:
string (str): The string to evaluate
Returns:
``str``: The type, or "TYPE" if the type could not be determined
"""
try:
return ast.literal_eval(... | 75d24fceeb5db3db715300ec4c74c2bd60765bfa | 48,823 |
def greatest_common_divisor(a, b):
"""Retorna o maior divisor comum (MDC) entre a e b.
Args:
a (int): primeiro valor.
b (int): segundo valor.
Returns:
int: Maior divisor comum (MDC) entre a e b.
"""
if 0 in (a, b):
return 1
if a < b:
return greatest_comm... | 72cd71b9afb763156476d70c887e41a47ca95089 | 48,825 |
def polyester_gl_input():
"""Table C3.8.1 - generica material data"""
return {
"name": "polyester",
"density": 1200,
"modulus_x": 3000000,
"modulus_xy": 1140000,
"poisson": 0.316,
} | ce5f49a707961104bfab9b181af937b3743cecfc | 48,826 |
from numpy import right_shift,bitwise_and,empty,uint8,uint16
def mono12p_to_image_ver2(rawdata,row,col):
"""Converts FLIR Mono12p flat data format (uint8) to 16 bit image (uint16)."""
arr = rawdata.reshape(-1,3)
N = 2*len(arr)
b0 = empty(N,uint8)
b1 = empty(N,uint8)
b0[0::2] = arr[:,0]
b0[... | 79453fe3ecfbdb9e43205ecd96f4562b8a138066 | 48,827 |
def normalize(data):
"""
Normalize data into interval <0, 1>
"""
total = sum(data)
normalized = []
for item in data:
normalized.append(item/total)
return normalized | d82dae78a0767d6a4519aca518d7ce27049fab41 | 48,828 |
def _jupyter_nbextension_paths(): # pragma: no cover
"""Allows commands like
jupyter nbextension install --py jupytext
jupyter nbextension enable --py jupytext
jupyter labextension install jupyterlab-jupytext"""
return [
dict(
section="notebook",
# the path is relati... | 0714407d7c9468363845bf62c478e3d5944d803c | 48,829 |
import torch
import math
def sym_diag(mat):
"""Diagonal of a symmetric matrix
Parameters
----------
mat : (..., M * (M+1) // 2) tensor
A symmetric matrix that is stored in a sparse way.
Its elements along the last (flat) dimension are the
diagonal elements followed by the flat... | 23c29d1c6429089e88720e9ba7d3d6f8968f9ca0 | 48,831 |
def borrow(sharedvar, boro=True):
"""
Gets the numpy ndarray underlying a sharedVariable
"""
return sharedvar.get_value(borrow=boro) | 02b3b8e06406320282a5058fc7a803203454166d | 48,832 |
def intersect(seq1, seq2):
"""Returns a list of elements in both seq1 and seq2."""
ret = []
for elem in seq1:
if elem in seq2:
ret.append(elem)
return ret | b7cb43616e8000427005c350b2b07a59768f2995 | 48,833 |
def code(value: int) -> str:
"""Constructs an ANSI code with the provided `value`."""
return f'\033[{value}m' | 48b499b5055d616bc7f51043e96429be123b5dd2 | 48,834 |
import difflib
def GetBestStringMatchValue(string1, string2):
"""
Return the value of the highest matching substrings between two strings.
Parameters
----------
string1 : string
First string.
string2 : string
Second string.
Returns
----------
int
Integer value representing... | a8fe07317db7ce26478b1faa0df13c3558c8fea5 | 48,835 |
def unwrap_filter(response, category):
"""
Strips one layer of aggregations (named by <category>) from
a ElasticSearch query response, leaving it still in proper ES
response format.
:param response: An Elasticsearch aggregation response dictionary.
:param category: Name of the topmost aggregati... | 82d6533edf8091e5a6b353f903f652bcb700dcde | 48,836 |
def get_longest_consecutive_chars(string):
"""
Given a string, return the longest consecutive character sequence.
"""
longest_consecutive_chars = ''
current_consecutive_chars = ''
for char in string:
if char not in current_consecutive_chars:
current_consecutive_chars += char... | 4607a1adada254c36e46a28c036cb852992544a5 | 48,837 |
import math
def root_mean_squared_error(LeadDay,df,model,observed):
"""
Args:
LeadDay: specifically applies to forecast models with lead times
if no lead day is available input None
LeadDay is desired Lead day (int)
df: data frame where Observed and Model data is found
... | 0bd5b5627fa2dda1ef444bd12c69f670daa18e44 | 48,838 |
def remap_constraint_indices(tokenized_sequence, detokenized_sequence, constraint_indices):
"""
Map the constraint indices of a tokenized sequence to the indices of a detokenized sequence
Any time there was '@@ ' in the tokenized sequence, we removed it
- the detokenized sequence has fewer spaces tha... | 787bafe4d1fa527385ec40217c2045e567a39e18 | 48,840 |
def pad_with_zeros(hist_list):
""" For each year which doesn't exist here, put 0 """
last_year = hist_list[0][0] - 1 # initialize to be less than the first year
i = 0
while i < len(hist_list):
year_item = hist_list[i]
if year_item[0] - last_year > 1:
# fill the gap
... | 3d2c2f9fba9b55039dcb4e42e27a9da9e3fb7048 | 48,841 |
from typing import Tuple
def find_prefix(root, prefix: str) -> Tuple[bool, int]:
"""
Check and return if prefix exists and how many
"""
node = root
if not root.children:
return False, 0
for char in prefix:
char_not_found = True
# search all children in present node
... | d7fd44ceecd62f94f6473b2f403e492dae1048c8 | 48,842 |
def find_phone(p_id, phone_data):
""" Finds the phone corresponding to the given user id """
if p_id in phone_data['ids']:
position = phone_data['ids'].index(p_id)
return phone_data['names'][position]
return "-" | 278e3f9141eadce0e5505b11a5240bc12a3b7820 | 48,843 |
def get_ext_domain_inurl_scheme_prefix(ext_domain, force_https=None):
"""旧版本遗留函数, 已经不再需要, 永远返回空字符串"""
return '' | d97ccdc5c5f1a13e4693d26ac60c81bc9d1a0ad6 | 48,844 |
import re
def convert_to_python_var_name(name):
"""converts a imc server variable to python recommended format
Args:
name (str): string to be converted to python recommended format
"""
pattern = re.compile(r"(?<!^)(?=[A-Z])")
python_var = re.sub(pattern, '_', name).lower()
if python_... | e2efa8e31d5446151cd89037da80a7d2447e7006 | 48,847 |
import os
def _local_filename(filename):
"""Get an absolute path to filename in the same directory as this module."""
return os.path.join(os.path.dirname(os.path.abspath(__file__)), filename) | 9e730c6b944616237645d2893d8f58de4c941d1e | 48,849 |
import os
import pickle
def read_results_and_agent_types(folder_path):
"""
Plots the pickled results in a folder from old runs
"""
results = dict()
for fname in os.listdir(folder_path):
if fname.endswith(".pkl"):
agent_name = fname.replace("-results_dict.pkl", "")
r... | 0b6bc584e99377e94a66f43ca931cb227ad1067e | 48,851 |
def full_method(apple, pear, banana=9, *args, **kwargs):
""" methody docstring """
return (apple, pear, banana, args, kwargs) | f331eb74d472b8d98b2db8119e402fe57a6a14d8 | 48,853 |
def change_series(data):
"""
Filter a pandas series to only the times when there is change.
"""
data = data.diff()
data = data[data!=0]
return data.iloc[1:] | 2de1d4ff1e2057af2e01b855f857623aeb96b667 | 48,854 |
def week():
"""
Week number for API calls
"""
return 5 | 85f55103136ad19c8bc24faa4339689eb978e381 | 48,855 |
import os
import re
def listdirs(directory = '.', dirname_regex = '.+'):
"""A utility function to list directories in a directory."""
dirnames = []
rawnames = os.listdir(directory)
for rawname in rawnames:
matchobj = re.search(dirname_regex, rawname)
if matchobj is None:
continue
fullpath = os.path.join(... | c9a2941b8983e50d2404b3a0738e1c1da76b203f | 48,856 |
def module_file(module):
"""Return the correct original file name of a module."""
name = module.__file__
return name[:-1] if name.endswith('.pyc') else name | 4fbda2b1c839690f880a6f6c1bcba2ca4168a701 | 48,857 |
def clamp(value, smallest, largest):
"""Return `value` if in bounds else returns the exceeded bound"""
return max(smallest, min(value, largest)) | 8ce129fd2bccacf7b45d9b4924f69a54bbb15e3b | 48,859 |
import os
def get_xlsx_files(path):
"""
Gets all XLSX files in a given directory
"""
list_of_files = {}
for (dirpath, dirnames, filenames) in os.walk(path):
for filename in filenames:
if '$' in filename:
continue
if filename.endswith('.xlsx'):
list_of_files[filename] = os.sep.join([dirpath, f... | d0694a9046de206b06904ae5c96dbad9d637f190 | 48,863 |
def extra_whitespaces():
"""Specially useful to remove extra whitespaces from text. Just replace
by an empty str.
"""
return r'(?<=[ ]{1})[ ]{1,}' | e95848c0dfc857fa9825140c546134b54c68ebe9 | 48,864 |
def convert_to_reverse_ip(ip):
"""A dummy function that takes some time."""
reverse_ip = ip.split('.')
reverse_ip.reverse()
reverse_ip = '.'.join(reverse_ip)
return reverse_ip | 01250f71364af25b3e2fb61e685b584fbd7c6140 | 48,865 |
def oid_outside_tree(oid1, oid2):
"""
Return True if oid2 outside of oid1 tree
Used by SNMPSession.walk
"""
try:
if oid2.startswith(oid1):
return False
return True
except:
return True | a1957c9d6b04dcd97db321f8d8779c349d14e265 | 48,867 |
def calculate_iou(bb1, bb2):
"""
Calculates the Intersection Over Union (IOU) score of the two bounding-boxes
(the overlap between two bounding boxes).
each bounding-box coordinates are in the form of: (x_min, y_min, x_max, y_max).
"""
bb1_x_min, bb1_y_min, bb1_x_max, bb1_y_max = bb1
bb2_x_m... | 5a0379085bbe428e812b2b0a39b39046cc0adefc | 48,868 |
def fastDot(A, B, C):
"""
[Added 23/9/2018]
[Updated 1/10/2018 Error in calculating which is faster]
Computes a fast matrix multiplication of 3 matrices.
Either performs (A @ B) @ C or A @ (B @ C) depending which is more
efficient.
"""
size = A.shape
n = size[0]
p = size[1] if len(size) > 1 else 1
size = B... | 22fbb77397ccae78b50e41b071da1980b6e9c75b | 48,869 |
import os
def get_full_path(filepath):
"""
Returns absolute path of file regardless of if
user YAML input contains absolute or relative path.
Will fail if path does not exist.
Args:
filepath: string path to desired file
"""
cwd = os.getcwd()
cwdpath = os.path.join(cwd, filep... | d078e5c94cb15126f8b43ce6b00495617bd45584 | 48,870 |
def _IOC(typ, nr, size, direction):
""" generic IOCTL structure """
# 32bit: 2 bit direction, 14 bit size, 8bit type 8 bit nr,
# r = ((size | (direction << 14)) << 16) | cmd
r = direction << 30 | size << 16 | typ << 8 | nr
return r | 270782255b9207eb21cb14ce72a93e41528191d3 | 48,871 |
def string_to_seq(seq_str):
"""Return a codepoint sequence (tuple) given its string representation."""
return tuple([int(s, 16) for s in seq_str.split("_")]) | 1021578ecb694ec9fc974f0b590ef0fc7c71f20a | 48,872 |
import torch
def create_pytorch_model(
number_of_features, number_of_categories_by_label, label_to_test, **kwargs
):
"""
Create a toy PyTorch model that has the right shape for inputs and outputs
"""
class TorchToy(torch.nn.modules.module.Module):
def __init__(self, number_of_features, nu... | d27a82bd581accb4fccba3c09f88f26b00127eab | 48,873 |
from typing import Counter
import collections
def numericalize_tok(tokens, max_vocab=50000, min_freq=0, unk_tok="_unk_", pad_tok="_pad_", bos_tok="_bos_", eos_tok="_eos_"):
"""Takes in text tokens and returns int2tok and tok2int converters
Arguments:
tokens(list): List of tokens. Can be a list of... | 48fafe61938203bde66edcab90ded616ed23aa82 | 48,874 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.