content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def watch_pyramid_from_above(characters):
"""String pyramid implementation view from above."""
if not characters:
return characters
str_len = len(characters)
count = str_len + (str_len - 1)
container = []
max_count = count
min_count = 0
if count == 1:
print(characters)
... | e6395a3365db2e1e5bfcb1609e7b20ce8b5afd93 | 33,992 |
def emft(self, **kwargs):
"""Summarizes electromagnetic forces and torques.
APDL Command: EMFT
Notes
-----
Use this command to summarize electromagnetic force and torque in both
static electric and magnetic problems. To use this command, select the
nodes in the region of interest and make ... | 77e4321d607a991565f4d55fc661ce9777b8bb1c | 33,994 |
def encontrar_repetidos(jogadas):
""" Recebe uma lista de jogadas e conta
quantas series de numeros adjacentes iguais
ocorrem nas faces dos dados jogados
list -> int """
series = 0
inicio_serie = None
for i in range(len(jogadas)-1):
numero = jogadas[i]
prox_num = jogadas[i + 1]
if numero == prox_num... | c57fc7a1665d8272a97140c358b3445c15254656 | 33,995 |
def _sec_to_min(seconds):
"""converts seconds to minutes,
assuming that input is a number representing seconds"""
return seconds/60.0 | 82365fa70735592f21deea11183f65aac620fad6 | 33,996 |
def lines_for_reconstruction(unicode_text):
"""Split unicode_text using the splitlines() str method,
but append an empty string at the end if the last line
of the original text ends with a line break, in order
to be able to keep this trailing line end when applying
LINE_BREAK.join(splitted_lines).
... | 228a94218c1dc0babf984f488e38184483530675 | 33,997 |
def normalize(entries):
"""Normalizes the input by stripping any special characters or capital
letters present in the input data.
This method does an in-place normalization for the entries stored in
memory.
Args:
entries {list of Entry}: The entries to be shuffled.
Returns:
{list of Entry} A list... | 00ae3bbc14181fd5b20d347993ee78932ef26280 | 33,998 |
def bool_to_text(b):
""" Changes a provided boolean into a 'Yes' or 'No' string
No test is performed on whether or not the provided variable is boolean or
not, only an 'if b: / else:' test is performed.
Parameters
----------
b: any
Object that will be tested for its evaluation to a boo... | 3b07f22f61c26a87499e794ea9c85c3eda90bb0d | 33,999 |
def PyObject_Type(space, w_obj):
"""When o is non-NULL, returns a type object corresponding to the object type
of object o. On failure, raises SystemError and returns NULL. This
is equivalent to the Python expression type(o). This function increments the
reference count of the return value. There's rea... | d3faeeb6c119711340bc95972e5e96a038451f26 | 34,001 |
def make_desc_dict(ecfp):
"""
Format tuple of fingerprint information into dictionary
:param ecfp: Tuple of fingerprint features and values
:return: dictionary of fingerprint features and values
"""
ecfp_feat, ecfp_val = zip(*ecfp)
return ecfp_feat, ecfp_val | 5925cda8d428fad5c9bfd46a7a26276e34256569 | 34,002 |
def checkRules(puzzle):
""" this function receives a sudoku puzzle as a 9x9 list.
and checks if it satisfies the rules of Sudoku, specifically
(i): if all the numbers in rows are unique.
(ii): if all the numbers in columns are unique
(iii): if all the numbers in cells are unique"""
# Check... | 804d97b4badc6e95d08c09e5fc91ac2e9b4061b5 | 34,003 |
def extract_tags(tags):
""" Extract the tag names from tag list"""
return [tag['display_name'] for tag in tags] | 2c07a66ac3ddf1291fd0dab803fd4310c2e80941 | 34,004 |
def get_orders(value):
"""
Return a list of orders for context tiers.
Parameters
----------
value : int or string
The maximum context length or a string in the set "bigram" (for
context 1, and 2), "trigram" (for context 1, 2, and 3), or
"fourgram" (for contexts 1, 2, 3, and ... | 7f473e50a9fbb0ec0927016994367150aee7aa70 | 34,005 |
def serialize_string(input_string):
"""apply a serial counter to a string"""
s = input_string.strip().split()
last_token = s[-1]
all_other_tokens_as_string = input_string.replace(last_token, '')
if last_token.isdigit():
value = '%s%s' % (all_other_tokens_as_string, int(last_token) + 1)
... | b95003285ecb25dcd0025e32479e2c4a50fc1cbd | 34,006 |
def clean_env(env):
"""Make a copy of env without game."""
new_env = env.copy()
del new_env["game"]
return new_env | dc7356a271c6f82ba8fe06a600302f6bc1eae963 | 34,008 |
def get_nodes_keys(nodes: list) -> set:
"""Получить ключи узлов из списка узлов"""
return set(z.key for z in nodes) | 343d47e04e1ec3359ffc04edd2aea23f9190734e | 34,009 |
def _num_clips(
duration_sec: float,
fps: float,
stride_frames: int,
window_size_frames: int,
backpad_last: bool = True,
) -> int:
"""
Utility to calculate the number of clips for a given duration, fps, stride & window_size
"""
num_frames = round(duration_sec * fps)
N = num_frame... | f13cec1dd9ced5a4a446b24524646a2e6db3479e | 34,010 |
import csv
def load_review_data(path_data):
"""
Returns a list of dict with keys:
* sentiment: +1 or -1 if the review was positive or negative, respectively
* text: the text of the review
"""
basic_fields = {'sentiment', 'text'}
data = []
with open(path_data) as f_data:
for dat... | e19e51a37007ad308893c190a3629beef9e57f90 | 34,011 |
def swap(a: int, b: int) -> tuple[int, int]:
"""
Return a tuple (b, a) when given two integers a and b
>>> swap(2,3)
(3, 2)
>>> swap(3,4)
(4, 3)
>>> swap(67, 12)
(12, 67)
"""
a ^= b
b ^= a
a ^= b
return a, b | 3475e93eb62398cc912f5f7d528de704799747a2 | 34,012 |
def days_per_month(leap=False):
"""Return array with number of days per month."""
ndays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if leap:
ndays[1]+= 1
return ndays | e8efeab08bc82344792a3956df91e53767be81c9 | 34,013 |
def generate_discrete_distribution(random_state, N, distribution_type,
distribution_args=None):
"""
Generates a sequence of distrete random variables for the
degree distribution given the parameters for the distribution
and the type that is used.
Currently suppor... | e07548969e1486ada45a7aa47e4faa8cc8723390 | 34,014 |
def parserun(runpath, maxrank=20):
"""constructs a run from a trec run"""
#initialize
#ranked lists go in a dict of lists
#rl[query]=[doc1,doc2,...]
rl = dict()
name = None
#read the ranked list into a dict of dicts
#rawlist[query][doc]=score
r... | a42712d3c014b2b88a3191ddd6518f1b7220c67b | 34,016 |
def linear_annuity_mapping_func(underlying, alpha0, alpha1):
"""linear_annuity_mapping_func
calculate linear annuity mapping function.
Annuity mapping function is model of $P(t, T) / A(t)$
so that it's value is positive.
linear annuity mapping function calculates following formula:
.. math::
... | 3c4f780c8bc90ac2e6e2b3a1f9b930cbd291c9a7 | 34,017 |
def buffer_polygons(polys_in, buff):
""" """
poly_num = len(polys_in)
polys_out = [None]*poly_num
# buffer polygons
for i in range(0,poly_num):
polys_out[i] = polys_in[i].buffer(buff)
return polys_out | 363283f61021f457c21040c3feb5fefacc55476b | 34,018 |
def formatted_search_results(result):
"""
Create a curated list of the results we want to see on the search page.
"""
entry = result[0]
return [
{
'title': 'Publisher',
'value': entry['dc']['publisher'],
},
{
'title': 'Format',
... | 848662c8eeb01177569b51205d0d86bdbeb01070 | 34,019 |
def not_square(patients_dcm):
"""
This function tells us if all the slices that make up a scan are squares.
Parameters:
patients_dcm (list): A list containing the MRI scans. Each MRI scan is a list of the slices that make up the scan
Returns:
scans_not_square (list): A list contain... | 2e29ad8463d3ba2307a58672912bb6bded9cb412 | 34,020 |
def xy_to_wcs(xy, _w):
"""
Convert pixel coordinates (xy) to astronomical
coordinated (RA and DEC)
"""
_radec = _w.wcs_pix2world(xy, 1)
return _radec[:, 0], _radec[:, 1] | 0d82fadee33a783ec6f1f202b74f9e6345ff827e | 34,021 |
import re
def is_senior_area_chair_from(role):
"""
Computes if the role description corresponds to a senior area chair, and
also return the track(s) in which they are an area chair
SACs are discinguishable from everyone else via the "manager" suffix.
E.g. committee:Speech:Speech (manager 1)
... | 2d46f5d679e3b53cd8d6de585566fd6186c5d12e | 34,022 |
import io
import sys
def capture_stdout(function, *args, **kwargs):
"""capture and return the standard output from a function"""
io_stdout = io.StringIO()
sys.stdout = io_stdout
function(*args, **kwargs)
sys.stdout = sys.__stdout__
return io_stdout.getvalue() | a4b2f60fba88d28f12aef0f8a88187a1c2d167ad | 34,023 |
def format_month_day(dt, month_fmt="%b"):
"""
Formats the month and day of a datetime
Args:
dt (datetime.datetime): The datetime to be formatted
month_fmt (Optional[str]): The strftime-compatible month format
Returns:
str: The formatted month and day
"""
# NOTE: This fu... | 19e7862e49d998b48b1c2f404e24af4eaf5bf73c | 34,024 |
def capitalize(text):
"""capitalizes a word, for use in rendering template
Args:
text (str): word to capitalize
Returns:
capitalized (str): capitalized word
"""
return text[0].upper() + text[1:] | 63248f2f0477c56ca1032aaefde69dd3398970fd | 34,025 |
import sys
import json
from typing import OrderedDict
def read_in():
"""
Parse JSON passed via standard input
"""
lines = sys.stdin.readlines()
return json.JSONDecoder(object_pairs_hook=OrderedDict).decode(lines[0]) | 5ab26fa31cfd5082f16691c762b853222bdb651d | 34,026 |
def string_to_maya_value(string):
""" Convert a value saved in string to a numerical type understood by maya
"""
if string.isdigit():
return int(string)
if '.' in string or ',' in string:
if string.replace(',', '').replace('.', '').isdigit():
return float(string)
return s... | eeac4948225f496c3ad224f149b7eca2b1572e9e | 34,027 |
def get_library_name():
"""
Get the name for the pyLabLib library (the one containing current the module).
"""
module_name=__name__
return ".".join(module_name.split(".")[:-3]) | c6058efbf0240c98e58cb6a1ff7e69f8b659111e | 34,028 |
import re
def split_sentences(text):
"""
Funcao para quebrar o texto em uma lista de sentenças.
"""
sentence_delimiters = re.compile(u'[\\[\\]\n.!?,;:\t\\-\\"\\(\\)\\\'\u2019\u2013]')
sentences = sentence_delimiters.split(text)
return sentences | cd6fb82f58f021951bb7bb252170951ea60dd8f9 | 34,029 |
import itertools
def _get_columns_(term_list, required, dont_cares):
"""
term_list -- full list of terms
required -- integers for terms that are essential prime implicants . . .
each required int will appear in the source list for only 1 item in needed
"""
ignore = []
keep = []
fo... | 6f244243d54f8b83e9300c681187765c79721af7 | 34,030 |
def get_outgoing_edges(graph, node):
"""
Get all outgoing edges from a given node in
a graph.
Includes logic for choosing the ordering of the edges.
"""
return [(node, neighbor, edge_key)
for neighbor, edge_keys
in graph[node].iteritems()
for edge_key in edge_... | b48910fbb2146fc60f9a726aa65200795dc5b73a | 34,031 |
def get_arg(*args, index: int):
"""Get the argument at index."""
if args:
return args[index]
return None | 7f0e3ad04affdceb4ed02cb88a79f1c7b00e6ad2 | 34,033 |
import torch
def sqrt(x):
"""Apply sqrt function."""
return torch.sqrt(x) | e6e7421f27ba44dc91d3c2162d6846d2b6427626 | 34,034 |
def dec2hex(value, delim=''):
""" 12648430 -> 'c0ffee' ; (255, 255) -> 'ffff' ; (256 * 256 - 1, 10) -> 'ffff0a' """
if type(value) == int:
s = hex(value)
return '0' * (len(s) % 2) + s[2:]
else:
return delim.join(dec2hex(item, delim) for item in value) | 23549c552fc5ac2340bd76c4ea3418704fa677c6 | 34,035 |
import functools
def operate(type_id, operands):
""" Apply the operation specified in the type_id to the operands, returning the result
"""
result = None
match type_id:
case 0: #sum
result = sum(operands)
case 1: # product
result = functools.reduce(lambda x, y: ... | a3e9d2f7becc3be018bf2e7b85d9a6d23d37d622 | 34,036 |
def vector_sequence_to_words(sequence, w2v_model):
"""
Reconstructs a sentence from an array of word vectors.
:param sequence: np array of word vectors (matrix)
:param w2v_model: word embedding model
:return: str
"""
return " ".join([w2v_model.most_similar(positive=[vect], topn=1)[0][0] fo... | c0a491521ce9ea6166e6f5c3ba63f82f756fdea8 | 34,037 |
def tile_in_roi(conn, g, roi, tile_pkey):
"""
Checks if the given tile_pkey is at a location within the specified roi
"""
c = conn.cursor()
c.execute(
"""
SELECT name FROM phy_tile WHERE pkey =
(SELECT phy_tile_pkey FROM tile WHERE pkey = ?)
""", (tile_pkey, )
)
tile, = c.fetchone()
... | 136e63a9b1fa2d426350607998a064cd5d363a85 | 34,038 |
def check_api_key(tmdb) -> bool:
"""
Checks for the presence of the TMDB API Key.
"""
return False if not tmdb.api_key or "" else True | 8a6c4c59448c761d548de3ba66b089beb814f839 | 34,040 |
def read_fastq(filename):
"""This function reads a FASTQ file storing the read and its ID in a dictionary where keys are IDs and read value.
This function does not consider + and score lines.
Key Arguments:
filename -- name of FASTQ input file.
"""
reads_dict = dict()
with open(file... | 85ba5987ad709ba5da5276b6ee6ed056e13ca884 | 34,042 |
def f_score(p, r, beta=1):
"""
F-score
"""
return (1 + beta ** 2) * ((p * r) / (((beta ** 2) * p) + r)) | 3afae02a2bba0b34485eac09fcb8af068cae5410 | 34,043 |
def represent_dictionary_order(self, dict_data):
""" instantiates yaml dict mapping """
return self.represent_mapping('tag:yaml.org,2002:map', dict_data.items()) | c7817bc2e35e675b997e9c9e22b47d9484d61891 | 34,045 |
def getQuadratic(A, b, c=0):
"""
Given A, b and c, this returns a quadratic, Q
.. math::
\mathbf{Q( x ) = 0.5 x A x + b x} + c
"""
def Quadratic(x, return_g=True, return_H=True):
f = 0.5 * x.dot( A.dot(x)) + b.dot( x ) + c
out = (f,)
if return_g:
... | 9dec83acec6eeaf55573ea7f6c315ac5c16813eb | 34,046 |
from datetime import datetime
def start_and_end_of_the_month(dt: datetime):
"""Get first of month and first of next month for a given datetime.
"""
start = dt.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
if start.month == 12:
end = start.replace(year=start.year + 1, month=1, day=1... | 9f1001c325d04a4754b666477292788f620596f7 | 34,047 |
def dict_scale(d, scl):
"""scales all values in dict and returns a new dict"""
return dict([(k, v * scl) for k, v in d.items()]) | 64ddc09fe1b038e69f6c8200e7906e78d7373cd6 | 34,051 |
def has_any_permissions(user, permissions):
""" Retuns `True` if the user has any of the permissions """
for perm in permissions:
if user.has_perm(perm):
return True
return False | 2de21fcb3f5a4984365185216f45ed2814fd13e4 | 34,053 |
def weighing_function(orig_length, cur_length):
"""
Function to generate the weight value given the predicted text-length and the expected text-length
The intuition is that if the predicted text-length is far from the expected text-length then weight should be
small to that word-bbox.
:param orig_length: Length o... | 09afb649952039e0d7f7b776d43cc0b0307329ee | 34,054 |
import torch
def sinkhorn_unrolled(c, a, b, num_sink, lambd_sink):
"""
An implementation of a Sinkhorn layer with Automatic Differentiation (AD).
The format of input parameters and outputs is equivalent to the 'Sinkhorn' module below.
"""
log_p = -c / lambd_sink
log_a = torch.log(a).unsqueeze(dim=-1)
log_b = t... | 6732a0c82ea2a896d1064711cffc48a571ec5bc7 | 34,056 |
def _parse_text_with_command(text: str):
""" Parse string that is passed when bot command is invoked. """
if after_bot_name_text := text.split('</at>')[-1].rstrip().strip():
return after_bot_name_text.split()
else:
return '', [] | 03559b81e696064fee90c8818cb2825a93cbe719 | 34,057 |
import os
def replay_test_dir():
"""Fixture to test directory."""
return os.path.join(os.path.abspath(os.path.curdir), 'test-replay') | bbab9932f8506f5b2a74f2b7d8b49c81ec134831 | 34,058 |
def top_xticks(ax, minor=None, major=None, labels=None):
"""
Add top axis to ax with custom major / minor ticks.
args:
minor # list() or np.ndarray() minor xtick locations
major # None, list() or np.ndarray() major xtick locations
labels # None, list... | 8244af4c50ac5a66601e79d312c6cbca5119498d | 34,059 |
from typing import Mapping
from typing import Optional
def _parse_obsolete(obsolete_file_path: str) -> Mapping[str, Optional[str]]:
"""Parses the data file from PDB that lists which pdb_ids are obsolete."""
with open(obsolete_file_path) as f:
result = {}
for line in f:
line = line.strip()
# Fo... | c4e3f3a04d3349d6752d133d079a1bb3aa34e13f | 34,060 |
def compact_date(date):
"""
Converts an ISO 8601 format date string into a compact date.
Parameters
----------
Date: a string date in iso format.
Returns
----------
A string date without hyphens.
"""
return date.replace('-', '') | e377096d2f0ce9404835968627e9b4e3f9d4b252 | 34,062 |
from typing import Sequence
def recursive_flatten(seq: Sequence) -> Sequence:
""" """
if not seq: # is empty Sequence
return seq
if isinstance(seq[0], Sequence):
return (*recursive_flatten(seq[0]), *recursive_flatten(seq[1:]))
return (*seq[:1], *recursive_flatten(seq[1:])) | 017b1ab6df950a599d3521a5cd372114a54ab63d | 34,063 |
import torch
def calculate_accuracy(inputs: torch.Tensor, targets: torch.Tensor) -> float:
"""
A function that calculates accuracy for batch processing.
Returns accuracy as a Python float.
Args:
inputs (torch.Tensor): shape == [N, n_class]
targets (torch.Tensor): shape == [N]
Ret... | 53eff3901d675370a9ed0f260d1230c2c5badb79 | 34,064 |
from datetime import datetime
def epoch_to_utc_timestamp(epoch):
""" convert epoch to utc_timestamp """
epoch = float(epoch)
utc_timestamp = datetime.utcfromtimestamp(epoch).replace(tzinfo=None)
return utc_timestamp | 791c4b3ee48090c44d57730abd6109a8ca4cae8d | 34,067 |
import base64
def base64_untoken(base64_bytes):
"""base64: untoken."""
token_bytes = base64.b64decode(base64_bytes)
untoken = token_bytes.decode('ascii')
base64_user = untoken.split(":", 1)[0]
base64_pass = untoken.split(":", 1)[1]
return base64_user, base64_pass | 20b1f2383889eccce5cf03d23fc50105d4371f2d | 34,068 |
import hashlib
def hash100(s: str):
"""
Hash a string into 1~100.
Useful when you split a dataset into subsets.
"""
h = hashlib.md5(s.encode())
return int(h.hexdigest(), base=16) % 100 + 1 | 0686d599e42c104d487462682340f04bd3fe94b4 | 34,069 |
def precond_grad_scaw(Ql, qr, Grad):
"""
apply scaling-and-whitening preconditioner
"""
return (Ql.t().mm(Ql)).mm(Grad * (qr * qr)) | e10ae14eeb6da4fc5f45ce9284f04431a737665b | 34,070 |
def _get_union_type_name(type_names_to_union):
"""Construct a unique union type name based on the type names being unioned."""
if not type_names_to_union:
raise AssertionError(
"Expected a non-empty list of type names to union, received: "
"{}".format(type_names_to_union)
... | f72f6a5212aa97eba32a3da7249087c97ce471b3 | 34,071 |
def is_clinical_in_cases(clinical_obj, cases):
"""Checks to see if clinical object representation is part of cases to assess
Example:
>>> clin_obj = xml_to_raw_clinical_patient("Test_Data/nationwidechildrens.org_clinical.TCGA-MH-A562.xml")
>>> cases = set(["ad7ba244-67fa-4155-8f13-424bdcbb12e5"... | ecff8e7e4697b0b89f5cf5e45de8e6515e2c0ea9 | 34,072 |
import os
import pathlib
def autoversion(filename):
""" Returns a string matching the filename and a query param of the file's
last modification time in milliseconds
Useful for agressive caching of static assets like app JavaScript and CSS.
Args:
filename (str): the name of the file receivin... | 9607b827979837838782f31db91e464bf18b1933 | 34,073 |
def get_blanks(nrows, ncols, plot_set):
"""Return a list of plot locations that should remain blank."""
assert type(plot_set) == set
nplots = nrows * ncols
plot_numbers = range(1, nplots + 1)
return list(set(plot_numbers) - plot_set) | e2049d16b7ff1f3e5d9d3628881f2574febffe16 | 34,074 |
def _qualified_names(modname):
"""Split the names of the given module into subparts
For example,
_qualified_names('pylint.checkers.ImportsChecker')
returns
['pylint', 'pylint.checkers', 'pylint.checkers.ImportsChecker']
"""
names = modname.split(".")
return [".".join(names[0 : i... | 97c614bbcc0997ab95a8535bf02489291d9d1c11 | 34,075 |
import numpy
def overall_mean(pollruns, data, default=0, round_to=1):
"""Return the mean of data values for each pollrun."""
padded_data = [data.get(pollrun.pk, default) for pollrun in pollruns]
return round(numpy.mean(padded_data), round_to) | b2b3d3ac8a5779c06ab0c07a561d7d64ff10594c | 34,076 |
import logging
def select_common_data(original_df, loading_df, df):
"""
Selects common measurements in the given original data, loadings, and data
to project.
:param pd.DataFrame original_df
:param pd.DataFrame loading_df
:param pd.DataFrame df
:rtype Tuple[pd.DataFrame, pd.DataFrame, ... | d51498bf3c3cf78bab5cd32c2762ee3c64068d63 | 34,077 |
def __is_allow_module(scope, endpoint):
"""是否有完整模块访问权"""
# endpoint -> 'blue_name.red_name+func_name'
splits = endpoint.split('+')
if len(splits) != 2:
return False
return splits[0] in scope.allow_module | ae1bb8d44e15a6f15ef2dea0b922ff5f881fbfca | 34,078 |
import re
def tokenize_sentences(text):
"""Simple tokenizer."""
print('starting tokenization')
text = re.sub('\n', ' ', text)
sentences = re.split('(?<!\w\.\w.)(?<![A-Z][a-z]\.)(?<=\.|\?)\s', text)
# Filter out too long sentences.
sentences = [t for t in sentences if len(t) < 150]
return sentences | a1cd49a08be1a06cd77c227b9cf69b6c1fdb2205 | 34,082 |
def find_index(x,y):
"""
find the index of x in y, if x not in y, return -1
"""
for index, item in enumerate(y):
if x == item:
return index
return -1 | 2e454c97155bd9d52851a1e20a0c795e8a485a46 | 34,083 |
def fixed_cation_oxidation_states():
"""
Args:
Returns:
dictionary of {element (str) : oxidation state (int) for cations with likely fixed oxidation states}
"""
plus_one = ['H', 'Li', 'Na', 'K', 'Rb', 'Cs', 'Fr', 'Ag']
plus_two = ['Be', 'Mg', 'Ca', 'Sr', 'Ba', 'Ra']
plus_thr... | 0b2a77a6351730778fc722f2cbb8a8aea7a3a0df | 34,084 |
def grad_refactor_1(a, b):
""" if_test """
def inner(x, y):
return x * y
return inner(a, b) | 95f4cbe713d695601f7252d0043ac36e95a3f1a2 | 34,086 |
def get_user_action(message, options):
"""
Reads user input and returns value specified in options.
In case user specified unknown option, returns default value.
If default value is not set, returns None
:param message: The message for user.
:type message: string
:param options: Options ma... | 207e0a64ff1b5e9e638fc449c6782ae3bf3b8f5f | 34,087 |
def vforms_weights(vform_choice, repeats, nqubits):
"""
Returns the number of weights a certain circuit has with 1 repeat and
without any trailing gates.
@vform_choice :: String of the choice of variational form.
"""
switcher = {
"two_local": lambda: nqubits * (repeats + 1),
}
n... | 893d7833627322956a882a4d5aed16a736afdec5 | 34,088 |
def use_proxy(browser, proxy, url):
"""
Open browser with proxy.
:param browser:
:param proxy:
:param url:
:return:
"""
profile = browser.profile
profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy.http', proxy[0])
profile.set_preference('net... | 6bd95c2fd2245366f855bc240b78b8371b11219d | 34,089 |
def getTrainTimes(t1,
testTimes):
"""SNIPPET 7.1 PURGING OBSERVATION IN THE TRAINING SET
Given testTimes, find the times of the training observations.
—t1.index: Time when the observation started.
—t1.value: Time when the observation ended.
—testTimes: Times of testing observations... | 8ddcef5c9d283565bd33a3f90ca0eca6b387416e | 34,090 |
import re
def clean_output(gold, predictions):
"""
Utility function to clean generated output from BART
"""
label = gold.replace("<eos>", "").strip()
labels = [int(id_[2:-1]) for id_ in label.split()]
# handle cases when output is empty
if len(predictions) == 0:
return labels... | f3442be89dea3f32f31d269e30a38d0021708e19 | 34,091 |
def byte_pos(text, line, col):
""" Return position index of (line, col)
line is line index, col is column index
The returning byte position __includes__ all '\n's.
Text is unicode.
"""
if type(text) != list:
lines = text.splitlines(True)[:line+1]
else:
lines = text[:line+1... | 8bd545b76569861a0c23d6a23cb70fdfcbad0475 | 34,092 |
def format_client_name(dataframe, client_name_column='client'):
"""takes a dataframe containing client Name in DWH format :
the client name column must *not* be called clientName
* add the clientName column using refactoring rules from DI
* rename the former client name column to clientNameDWH"""
da... | 369eb2166e872a269acc1e275826bc0c7ca82833 | 34,094 |
from typing import Optional
import os
import logging
def get_artifact_data(artifact_folder, artifact_relative_path: str) -> Optional[str]:
"""
Retrieves artifact data according to the artifact relative path from 'ARTIFACTS_FOLDER' given.
Args:
artifact_folder (str): Full path of the artifact root ... | 509d5f2f6af9b1b321f0859b59e81f703f0a2c9a | 34,095 |
import re
import copy
def _select_allowed_items(item_dict, allow_patterns, disallow_patterns):
"""
Creates the dictionary of items selected from `item_dict` such that item names
satisfy re patterns in `allow_patterns` and not satisfy patterns in `disallow_patterns`.
The function does not modify the di... | c56d9b6bf7db0f7a26da42c6da808de8fb8b7341 | 34,096 |
def scale_lr_and_momentum(args, cifar=False, skip=False):
"""
Scale hyperparameters given the adjusted batch_size from input
hyperparameters and batch size
Arguements:
args: holds the script arguments
cifar: boolean if we are training imagenet or cifar
skip: boolean skipping the... | abe65febe2538218db67470b1c2919ae7dd08cb2 | 34,097 |
def _py_lazy_or(cond, b):
"""Lazy-eval equivalent of "or" in Python."""
return cond or b() | 965c831da37e79cc22caaf20bc9edd8677e86be6 | 34,098 |
def get_printable_table(class_name: str, class_info: dict) -> str:
"""
Creates and returns a string displaying the class info in a
format that is easily read in a table.
:param class_name: The name of a class owning the data.
:type class_name: str
:param class_info: The data in the class to dis... | 7734537c4f68df0cc755c51661fd63d5ddb46978 | 34,099 |
def get_geometry_type(gi):
""" Return the geometry type from a __geo_interface__ dictionary """
if gi["type"] == "Feature":
return get_geometry_type(gi["geometry"])
elif gi["type"] in ("FeatureCollection", "GeometryCollection"):
return get_geometry_type(gi["geometries"][0])
else:
... | 6e1292863dd45933c59e84cc465d3ade53248c08 | 34,102 |
def allLongestStrings(inputArray):
"""
https://codefights.com/arcade/intro/level-3/fzsCQGYbxaEcTr2bL
Given an array of strings, return another array containing all of its longest strings.
Example
For inputArray = ["aba", "aa", "ad", "vcd", "aba"], the output should be
allLongestStrings(inputArr... | c1011b8cb5a9f9a52d532c405070b75a69f8fe87 | 34,103 |
def check_pattern(patterns, pattern_dic):
"""
desc check if the your input on the pattern exist in the pattern file
Input patterns, pattern_dic
output True or False
"""
# print(patterns, pattern_dic)
for pattern in patterns:
try:
pattern_dic[pattern]
except... | d197aa9c7db60da61356193d0400905bf53891ac | 34,104 |
def ListToString(alist, useAssert=False):
"""Convert a list of strings into a single string
alist is the list to be converted into a string
if useAssert is True, then the function checks whether all elements of alist are strings before proceeding"""
if useAssert:
assert all([isinstance(x, str) for x in alist]), "... | 29b4329df4f4e97c571240076f7f3571e91f970e | 34,105 |
def is_number_offset(c_offset):
"""
Is the offset a number
"""
return 0x66 <= c_offset <= 0x6f | 6606048314047de7f59e77e01f48e438d4113159 | 34,107 |
def filter_stems_prob(stem_dic, CUTOFF_PROB):
""" Function: filter_stems_prob()
Purpose: Create new dictionary which stores stems with high probability.
Input: A dictionary of stems.
Return: An new dictionary of stems.
"""
stems_ib = stem... | a8ed07583300c3da92e44f733dc5995ea3999c7c | 34,108 |
def group_songs(songs):
"""Groups a sequence of songs per dirname.
The value order is the same as with the passed in songs.
"""
dirs = {}
for s in songs:
dirs.setdefault(s("~dirname"), []).append(s)
return dirs | 82dc2e440fde8031dc818079f63ca99058d43f0d | 34,109 |
def inbound_degrees(adj_list: dict) -> dict:
"""Calculate the inbound degree of each node in a graph.
Args:
adj_list (dict): An adjacency list. Can be from an undirected or directed graph.
Returns:
dict: A dictionary where the key is a graph node \
and the value is the number of in... | 0580e29e4f21dcc33ee6ef74717bda4250dca8c7 | 34,111 |
def is_present(actual, expected):
""" evaluates if all params in actual exist in expected """
if expected is None:
notfound = actual
else:
notfound = filter(lambda x: x not in actual, expected)
return notfound | ba407d30bec2b7ff9c8bc4fe5ecd089be8a30d89 | 34,112 |
def sizes (im):
"""
Return the dimensions of an image as a list.
Arguments:
im the image whose dimensions are to be returned
"""
return im.shape | 3bddd044a103b11a7c2e3eef46efb8b83c7f44d6 | 34,113 |
def _range_to_number(bucket_string):
"""Converts "X-Y" -> "X"."""
return int(bucket_string.split('-')[0]) | 1bc40f88cfabec19d8f9e5e14e7de03cec825f58 | 34,114 |
import torch
def compute_input_lengths(padded_sequences: torch.Tensor) -> torch.Tensor:
"""
Parameters
----------
padded_sequences
(N, S) tensor where elements that equal 0 correspond to padding
Returns
-------
torch.Tensor
(N,) tensor where each element corresponds to the... | 44640410704c2118a09b3c0490bc854fde93269a | 34,115 |
import re
def train(text, model):
"""generate or update a word model (dictionary of word:frequency)"""
words = lambda text : re.findall('[a-z]+', text.lower())
for word in words(text):
model[word] += 1
return model | d821d4228453c43c0f423d2e3e125452d64b054b | 34,117 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.