content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
from typing import Iterable
def filter_array(func, arr: Iterable) -> list:
"""
Filters the arr using the given function. The function must return True or False whether
the element should be part of the result or not.
"""
res = list()
for el in arr:
if func(el):
res.append(... | 53e1db35e1876475efa1427aefc4b6728d97087e | 700,079 |
def slices(series: str, length: int) -> list:
"""slices - a.k.a Grouped Slices -
:param series: str:
:param length: int:
:returns: A list of grouped slices of n length from a string
"""
if length not in range(len(series) + 1):
raise ValueError(f'Length {length} not in range for this se... | 53a15a0b6322a22b95fc8943fbd7546da4419a77 | 700,080 |
def s2human(time):
"""Convert a time in second into an human readable string"""
for delay, desc in [(86400,'d'),(3600,'h'),(60,'m')]:
if time >= delay:
return str(int(time / delay)) + desc
return str(int(time)) + "s" | a2d2264fde357534e52444b754de81398eeacea7 | 700,081 |
def i_priority_node(g, i):
"""
Returns all nodes of priority i in game graph g.
:param g: the game graph.
:param i: the requested priority.
:return: a list of nodes of priority i in g.
"""
nodes = g.nodes # Nodes from g
# get all node indexes in node tuple (index, (node_player, node_pri... | 4d81fab7c7ea7ac75d21dfa36735b1e9a8981444 | 700,088 |
def sum_path(G, path):
"""
Calculate sum of weight in each edges of `path`
"""
sum_weight = 0
for i in range(len(path)-1):
n1, n2 = path[i], path[i+1]
sum_weight += G[n1][n2]['weight']
return sum_weight | 324c9d99c609da742ab71ad43714ec02d4f4d78c | 700,090 |
def is_ccw(signed_area):
"""Returns True when a ring is oriented counterclockwise
This is based on the signed area:
> 0 for counterclockwise
= 0 for none (degenerate)
< 0 for clockwise
"""
if signed_area > 0:
return True
elif signed_area < 0:
return False
else:
... | bd0e0d92913dcb1c895c36c6e724e454e3658a6d | 700,093 |
def age_window_hit(by_predicted, by_truth):
"""
calculates the window for a given truth and checks if the prediction lies within that window
:param by_predicted: the predicted birth year
:param by_truth: the true birth year
:return: true if by_predicted within m-window of by_truth
"""
m = -0... | 0d5903d21006f2651114affa9179cfc063b25f1d | 700,098 |
import sqlite3
def get_con_cur(db_filename):
"""Returns an open connection and cursor associated with the sqlite
database associated with db_filename.
Args:
db_filename: (str) the filename of the db to which to connect
Returns: a tuple of:
-an open connection to the sqlite database
... | 5b99bb2df4f5a59a89d842f125a04252b86aab38 | 700,099 |
def small_straight(dice):
"""Score the given roll in the 'Small Straight' category.
"""
if sorted(dice) == [1, 2, 3, 4, 5]:
return sum(dice)
else:
return 0 | 4b88652b32efd49d5d4247ce88584011a43a0b10 | 700,100 |
def format_internal_tas(row):
"""Concatenate TAS components into a single field for internal use."""
# This formatting should match formatting in dataactcore.models.stagingModels concatTas
tas = ''.join([
row['allocation_transfer_agency'] if row['allocation_transfer_agency'] else '000',
row[... | 0a1db8f1958d3ee1f06b323f9d00de66814e2a6b | 700,102 |
def form(self, lab="", **kwargs):
"""Specifies the format of the file dump.
APDL Command: FORM
Parameters
----------
lab
Format:
RECO - Basic record description only (minimum output) (default).
TEN - Same as RECO plus the first ten words of each record.
LONG - Sa... | 68c2ec60889bac22a8f97789acb1586c41c60a06 | 700,103 |
def percent(values, p=0.5):
"""Return a value a faction of the way between the min and max values in a list."""
m = min(values)
interval = max(values) - m
return m + p*interval | 80d3d291122d42e8b9936c4ef994e9ca1a7e98b5 | 700,104 |
def fns2dict(*functions) -> dict:
"""
Returns a dictionary of function name -> function,
given functions as *arguments.
Return:
Dict[str, Callable]
"""
return {f.__name__: f for f in functions} | 7ddfc5b5a99d016e13e66e4521d9f60b34051505 | 700,107 |
def maxabs(vals):
"""convenience function for the maximum of the absolute values"""
return max([abs(v) for v in vals]) | ec79fe4de1aa658b40a7495f484b26493e5d8fc2 | 700,109 |
def get_row_sql(row):
"""Function to get SQL to create column from row in PROC CONTENTS."""
postgres_type = row['postgres_type']
if postgres_type == 'timestamp':
postgres_type = 'text'
return row['name'].lower() + ' ' + postgres_type | 4efecaefa8b79bdeec7447138586cc93268c54df | 700,110 |
def resolve_relative_path(filename):
"""
Returns the full path to the filename provided, taken relative to the current file
e.g.
if this file was file.py at /path/to/file.py
and the provided relative filename was tests/unit.py
then the resulting path would be /path/to/tests/unit.py
"""... | 447df7fb94dbb3a0796c5207a99062b04dfbbf50 | 700,111 |
import torch
def normalize(x: torch.Tensor) -> torch.Tensor:
"""Normalizes a vector with its L2-norm.
Args:
x: The vector to be normalized.
Returns:
The normalized vector of the same shape.
"""
norm = x.pow(2).sum(1, keepdim=True).pow(1.0 / 2)
out = x.div(norm)
return out | f34e664a565953e46c9cb18cc66fce0dd9903bde | 700,112 |
import uuid
def label(project):
"""Label fixture for project label API resource tests."""
_id = uuid.uuid4().hex
data = {
"name": f"prjlabel{_id}",
"description": f"prjlabel1 {_id} description",
"color": "#112233",
}
return project.labels.create(data) | 61d9ca8e6a9c909f3bc97135796a2cf03de99b35 | 700,115 |
def vfid_set(session, vfid):
"""Assign a new VFDI to a session
:param session: dictionary of session returned by :func:`login`
:param vfid: new VFID to be assigned to the session
:rtype: none
"""
session['vfid'] = vfid
return "Success" | 00f17adefa2d24bfcd6a1e1f1a24acfe88873dab | 700,123 |
def bool_list_item_spec(bool_item_spec):
"""A specification for a list of boolean items."""
return {
'my_bools': {
'required': True,
'items': bool_item_spec
}
} | 8bb609015004b6eb12d182b07731368b107ec602 | 700,125 |
def class_fullname(obj):
"""Returns the full class name of an object"""
return obj.__module__ + "." + obj.__class__.__name__ | a7b5915e15122664943a181a48d3f52dff232c88 | 700,132 |
def get_model_ref(data, name_weights):
"""
Returns model reference if found by model name and model weights pair. Returns None otherwise.
data - list of tuples (model_name, model_weights_path, model_ref)
"""
for x in data:
if name_weights == x[:2]:
return x[2]
return None | 8525d77c018ec696619161afb3fbb0342ff46a27 | 700,135 |
def parse_punishment(argument):
"""Converts a punishment name to its code"""
punishments = {
"none": 0,
"note": 1,
"warn": 1,
"mute": 2,
"kick": 3,
"ban": 4
}
return punishments[argument.lower()] | 9ca9ad052c5636dd58f1b375296137de8b55712b | 700,136 |
import configparser
def get_api_config(filename):
"""
Attempt to pull in twitter app API key and secret. If the key
and secret don't exist prompt for them.
Arguments:
filename -- name of the config file to try and parse
Returns:
config_api_store -- contains the twitter API key and s... | 8723e77f2cc30b9f102d141dd46b66a147ee67ef | 700,139 |
def const(a, b):
"""``const :: a -> b -> a``
Constant function.
"""
return a | 1b3e03d98ab495d1795d3e89d0a57728b1dcef47 | 700,144 |
import torch
def sharpness(predictions:list, total = True):
"""
Calculate the mean size of the intervals, called the sharpness (lower the better)
Parameters
----------
predictions : list
- predictions[0] = y_pred_upper, predicted upper limit of the target variable (torch.Tensor)
-... | 16c4fa826e9ffd4a42a3c987fc9fe6767feb9ebb | 700,146 |
import asyncio
async def _createServer(host, port):
"""
Create async server that listens host:port, reads client request and puts
value to some future that can be used then for checks
:return: reference to server and future for request
"""
indicator = asyncio.Future()
async def _handle(r... | bbd21ede887ae93ba8127aa1bb0a9ff4264b8399 | 700,150 |
def _exclude_swift_incompatible_define(define):
"""A `map_each` helper that excludes a define if it is not Swift-compatible.
This function rejects any defines that are not of the form `FOO=1` or `FOO`.
Note that in C-family languages, the option `-DFOO` is equivalent to
`-DFOO=1` so we must preserve bo... | 9ce87f52f8829636364e2671f59a0eb9e66f5a9b | 700,152 |
import re
def hex_color_code(value: str):
"""
Hex color validator
Example Result:
[#00ff00,
#fff]
"""
_hex_color_pat = r'#(?:[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})'
return re.findall(_hex_color_pat, value) | 760db0bd1b729b62171b6964d1615546e32dbe52 | 700,154 |
import re
import logging
def parse(fqdn):
"""Parses an M-Lab FQDN into its constituent parts.
Args:
fqdn: str, an M-Lab FQDN e.g., ndt-iupui-mlab1-den05.mlab-oti.measurement-lab.org
Returns:
dict representing the constituent parts.
"""
# This regex *should* match all valid M-Lab ... | a05a7125b1818668dc681be460a326c2a5a2f065 | 700,155 |
def buffer_type(request):
"""
Fixture that yields types that support the buffer protocol.
"""
return request.param | afc79bf3ac5bfeb53fe9cb8de707b2f0a93ae6f8 | 700,156 |
def minargmin(sequence):
"""Returns the minimum value and the first index at which it can be
found in the input sequence."""
best = (None, None)
for (i, value) in enumerate(sequence):
if best[0] is None or value < best[0]:
best = (value, i)
return best | cf66ccd0dc76d3530fe7b2503bb3ed3b31c7ba61 | 700,157 |
def _is_eqsine(opts):
"""
Checks to see if 'eqsine' option is set to true
Parameters
----------
opts : dict
Dictionary of :func:`pyyeti.srs.srs` options; can be empty.
Returns
-------
flag : bool
True if the eqsine option is set to true.
"""
if "eqsine" in opts:... | 3515a75eb2c0976198700e1fe068cd15b0017d8f | 700,159 |
from typing import Callable
from typing import List
def generate_definition(cls: Callable) -> List[str]:
"""Generates a function signature from a pyDantic class object"""
# Fetch parameters
params = cls.__annotations__
return [
f"{name}: {data_type},"
if "Optional" not in data_type
... | 2e0a40875f78eb07733fa94fbadbd1d5ee06f2c7 | 700,160 |
import shutil
def get_archive_name_and_format_for_shutil(path):
"""Returns archive name and format to shutil.make_archive() for the |path|.
e.g., returns ('/path/to/boot-img', 'gztar') if |path| is
'/path/to/boot-img.tar.gz'.
"""
for format_name, format_extensions, _ in shutil.get_unpack_formats(... | 152d68ea9613d7253f78c37ce85758a2c8bc67f9 | 700,162 |
def counting_sort(values, max_value):
"""Sorts integers using the Counting Sort algorithm.
Args:
values: iterable, contains the integers to sort
should be between 0 and max_value
max_value: maximum value the numbers can take
Returns:
a sorted list of the nu... | fccf1b91bb2c300d22e316057b11dab3bb0ee86f | 700,170 |
def find_missing_integer(lst):
"""Returns the first missing integer in an ordered list.
If not found, returns the next integer.
"""
try:
return sorted(set(range(lst[0], lst[-1])) - set(lst))[0]
except:
return max(lst) + 1 | 1e8f25f1670933cf57ae042742c175aac7d905fb | 700,173 |
import logging
def parse_csv_data(csv_filename: str) -> list:
"""Takes in a csv filename and returns a list with each item being a new line of the file.
:param csv_filename: The name of a csv filename, '.csv' appendix is optional
:type csv_filename: str
:return: A list of strings with each ... | ef388507534b6e7e1b82cf5e5f0036e9dd5819dd | 700,175 |
def sort_return_tuples(response, **options):
"""
If ``groups`` is specified, return the response as a list of
n-element tuples with n being the value found in options['groups']
"""
if not response or not options.get("groups"):
return response
n = options["groups"]
return list(zip(*(r... | 14b49449d8fda6050bf4223365ba0f93918fe58a | 700,177 |
def _common_prefix(string_list):
"""
Given a list of pathnames, returns the longest common leading component
"""
if not string_list:
return ""
min_str = min(string_list)
max_str = max(string_list)
for i, c in enumerate(min_str):
if c != max_str[i]:
return min... | 4360e712c6c4d3d650a226c1fe7f3a4941861513 | 700,178 |
def qualify(func: object) -> str:
"""Qualify a function."""
return ".".join((func.__module__, func.__qualname__)) | bfda7050ff94f407a2a0d4b00b87ecb0370e9110 | 700,179 |
def dimension(dim: float, tol: int = 0, step: float = 0.4) -> float:
"""
Given a dimension, this function will round down to the
next multiple of the dimension. An additional parameter
`tol` can be specified to add `tol` additional steps to
add a tolerance to accommodate for shrinking.
"""
#... | a63b84bbc73d25da1c86c9919f61bd32071d92f9 | 700,181 |
def shortid(obsid):
"""
Compact format for the observation id, like QPT
Parameters
----------
obsid : string
Program id string
Returns
-------
shortid : string
Compact format
"""
idvals = obsid.split('-')
shortid = idvals[0][-1] + idvals[1][2:] + '-' + idv... | cb163886e7612fa46d016f2037b110526967c61f | 700,190 |
from typing import OrderedDict
def job_prep_release_status_list_table_format(result):
"""Format job prep-release-status list as a table."""
table_output = []
for item in result:
table_row = OrderedDict()
table_row['Pool Id'] = item['poolId']
table_row['Node Id'] = item['nodeId']
... | 5b93ade505b166cd45539bfde49e8f51f2ffb9fb | 700,198 |
def rinko_p_prime(N, t, A, B, C, D, E, F, G, H):
"""
Per RinkoIII manual: 'The film sensing the water is affect by environment
temperature and pressure at the depth where it is deployed. Based on experiments,
an empirical algorithm as following is used to correct data dissolved oxygen.'
Parameters
... | 482f2286819af3d147cde4dd258c36c04624a6e8 | 700,199 |
def _index(i, size, Cartesian=True):
"""If Cartesian=True, index 0 is swapped with index 1."""
if Cartesian:
if i == 1:
return 0
if i == 0:
if size >= 2:
return 1
return i | ace0ff4431b64b545f2857eddce85d555a0cf5f3 | 700,200 |
def nmap(value, fr=(0, 1), to=(0, 1)):
"""
Map a value from a two-value interval into another two-value interval.
Both intervals are `(0, 1)` by default. Values outside the `fr` interval
are still mapped proportionately.
"""
value = (value - fr[0]) / (fr[1] - fr[0])
return to[0] + value * (t... | d7968d7661c2535f5c820087b79b7a8e3667e8e8 | 700,202 |
def get_best_outputs(problem_dir, problem, user):
"""
Gets outputs of best submission.
:param problem_dir: main directory of submissions
:param problem: id of problem
:param user: user who wants to see submission for problem
:return: -1 if no file found, otherwise array of be... | a012b849ec76056067a75a71d80ea2911b2b91fc | 700,203 |
def computeFraction(feature_1, feature_2 ):
"""
Parameters:
Two numeric feature vectors for which we want to compute a ratio
between
Output:
Return fraction or ratio of feature_1 divided by feature_2
"""
fraction = 0.
if feature_1 ==... | fbce06ab1fea604a3c0e4f0e427dd6560acf80fe | 700,208 |
import base64
import json
def encode_transaction(value):
"""Encode a transaction (dict) to Base64."""
return base64.b64encode(json.dumps(value).encode('utf8')).decode('utf8') | 066fa737b9c2d474be500bf2006ce43adea8d4f8 | 700,212 |
import random
def shuffle_sequence(sequence):
"""Shuffle sequence.
Parameters
----------
sequence : str
Sequence to shuffle.
Returns
-------
str
Shuffled sequence.
"""
shuffled_sequence = list(sequence)
random.shuffle(shuffled_sequence)
return "".j... | 1acb94516a6ed491359538f2016a22fc6d613499 | 700,214 |
def enable_cloud_admin_access(session, confirm, return_type=None, **kwargs):
"""
Enables the ability of a storage cloud administrator to access the VPSA
GUI of this VPSA to assist in troubleshooting. This does not grant access
to any volume data. Enabled by default.
:type session: zadarapy.sessio... | 5444ba9f4c917a72c666908bcd4db3b8527d596c | 700,215 |
import torch
def align(src_tokens, tgt_tokens):
"""
Given two sequences of tokens, return
a mask of where there is overlap.
Returns:
mask: src_len x tgt_len
"""
mask = torch.ByteTensor(len(src_tokens), len(tgt_tokens)).fill_(0)
for i in range(len(src_tokens)):
for j in ra... | 0408ae7148c4bed9e3c24b71acdbd1a182dd6e69 | 700,220 |
from pathlib import Path
from typing import Dict
import yaml
def _load_yaml_doc(path: Path) -> Dict:
"""Load a yaml document."""
with open(path, "r") as src:
doc = yaml.load(src, Loader=yaml.FullLoader)
return doc | 4b049909c5e6eac6e7772b3311f928ccd6cf528c | 700,222 |
def getFloat (Float):
"""
Float input verification
usage: x = getFloat ('mensage to display ')
"""
while True:
try:
user_input = float(input(Float))
return user_input
except ValueError:
print('Use only numbers and separete decimals with point') | 27d9128441cadd00627d88bbfdb45144bf5a55f3 | 700,224 |
import warnings
def weight_list(spam, weights, warn=True):
""" Returns weighted list
Args:
spam(list): list to multiply with weights
weights (list): of weights to multiply the respective distance with
warn (bool): if warn, it will warn instead of raising error
Returns:
(l... | 6b2258675a5c346c50ecc8f7d8aba466a7b216ef | 700,226 |
def __extract_digits__(string):
"""
Extracts digits from beginning of string up until first non-diget character
Parameters
-----------------
string : string
Measurement string contain some digits and units
Returns
-----------------
digits : int
... | 6613e56dc33c88d9196c2ec95412155ad0aaf382 | 700,229 |
def status_in_range(value: int, lower: int = 100,
upper: int = 600) -> bool:
"""
Validates the status code of a HTTP call is within the given boundary,
inclusive.
"""
return value in range(lower, upper+1) | 43bb6f4824b7e42b6620e3ddff853aa65713f145 | 700,237 |
def _float_to_str(x):
"""
Converts a float to str making. For most numbers this results in a
decimal representation (for xs:decimal) while for very large or very
small numbers this results in an exponential representation suitable for
xs:float and xs:double.
"""
return "%s" % x | cb795b9c4778b9a3fda7398024166d86d8458bd3 | 700,239 |
def unique_cluster_indices(cluster_indx):
"""
Return a unique list of cluster indices
:param cluster_indx: Cluster index list of ClusterExpansionSetting
"""
unique_indx = []
for symmgroup in cluster_indx:
for sizegroup in symmgroup:
for cluster in sizegroup:
... | 36bc5a287d49c6abbd552b9edc0e72675ba82eca | 700,241 |
def _calculate_atr(atr_length, highs, lows, closes):
"""Calculate the average true range
atr_length : time period to calculate over
all_highs : list of highs
all_lows : list of lows
all_closes : list of closes
"""
if atr_length < 1:
raise ValueError("Specified atr_length may not be l... | f5878eda22c09fa8c428122bd013f9c6088ea0f8 | 700,242 |
import torch
from typing import Tuple
def get_tot_objf_and_finite_mask(tot_scores: torch.Tensor, reduction: str) -> Tuple[torch.Tensor, torch.Tensor]:
"""Figures out the total score(log-prob) over all successful supervision segments
(i.e. those for which the total score wasn't -infinity).
Args:
... | d09b95056c2635be22a7db1baaa64b6667955007 | 700,245 |
def traverse_file_structure(current, function, **inner_function_args):
"""Recursively traverses the given folder and applies the function to every file that it finds.
:param current: Source folder
:type current: stibnite.file_operations.FolderType
:param function: The function that will be applied to f... | 93312cb2792a27c1441a3794ca261bc67c22171a | 700,252 |
def rdist(x, y):
"""Reduced Euclidean distance.
Parameters
----------
x: array of shape (embedding_dim,)
y: array of shape (embedding_dim,)
Returns
-------
The squared euclidean distance between x and y
"""
result = 0.0
for i in range(x.shape[0]):
result += (x[i] - ... | 3caa871145b8ca68c0cd2bd23a183967b7b5b7cc | 700,261 |
import glob
def find_file(path):
"""
Search file
Parameters
----------
path : str
Path and pattern to find files.
Returns
-------
str or list of str
List of files.
"""
file_path = glob.glob(path)
if len(file_path) == 0:
raise ValueError("!!! No fil... | a5176d5caa5cef6ca2724c79e3f920cfc96aea0c | 700,262 |
import hashlib
import json
def _hasher(obj):
"""Computes non-cryptographic hash of an object."""
h = hashlib.md5(json.dumps(obj).encode())
return h.hexdigest() | 14262878ac53af8f49f7fef4c028be36e4370725 | 700,265 |
def length_str(msec: float) -> str:
"""
Convert a number of milliseconds into a human-readable representation of
the length of a track.
"""
seconds = (msec or 0)/1000
remainder_seconds = seconds % 60
minutes = (seconds - remainder_seconds) / 60
if minutes >= 60:
remainder_minut... | 7cf6674d68d118c78a2953b3fef873633673bbf0 | 700,272 |
def row_sum(lst):
""" Sum of non-missing items in `lst` """
return sum(int(x) for x in lst if x > -1) | 5fabe4d3487e502dcb82dd452854de3777e1a5a8 | 700,276 |
def compress_dataframe_time_interval(processed_df, interval):
"""
Resamples dataframe according to time interval. If data is originally in 1
minute intervals the number of rows can be reduced by making the interval 15 minutes.
To maintain data quality, an average is taken when compressing the dataframe.... | ffbb35719e33f445ba4b5c91acf8a069cd4902a6 | 700,277 |
def iseast(bb1, bb2, north_vector=[0,1,0]):
""" Returns True if bb1 is east of bb2
For obj1 to be east of obj2 if we assume a north_vector of [0,1,0]
- The min X of bb1 is greater than the max X of bb2
"""
#Currently a North Vector of 0,1,0 (North is in the positive Y direction)
#i... | 9764d373d14530fca2d26d8c7855cc0620e14496 | 700,278 |
import itertools
def concat_list(in_list: list) -> list:
"""Concatenate a list of list into a single list."""
return list(itertools.chain(*in_list)) | 5a58e8e1899fce99f8dabe681206507ae8ad4b8c | 700,279 |
def is_sale(line):
"""Determine whether a given line describes a sale of cattle."""
return len(line) == 5 | e4ff4ae2ea7ea14a2975eaf87852eed2fad0abff | 700,280 |
def _is_recipe_fitted(recipe):
"""Check if a recipe is ready to be used.
Fitting a recipe consists in wrapping every values of `fov`, `r`, `c` and
`z` in a list (an empty one if necessary). Values for `ext` and `opt` are
also initialized.
Parameters
----------
recipe : dict
Map the... | 77e438dd00ac5606c52c88518c6932a09dff75df | 700,281 |
def view_event(user, event):
"""
Check whether a user may view a specified event.
:param User user:
:param Event event:
:return: bool
"""
if event is None:
return None
return user.has_perm("booking.view_hidden_events") or event.visible is True | 0aca52c9a60449ab0711a2291c5f12f42c8b3f96 | 700,282 |
def parse_filename(fname, return_ext=True, verbose=False):
"""
Parses `fname` (in BIDS-inspired format) and returns dictionary
Parameters
----------
fname : str os os.PathLike
Filename to parse
return_ext : bool, optional
Whether to return extension of `fname` in addition to key... | 1512b50fa6d07a0bcbb69831418a935f28abe2d8 | 700,283 |
def get_ls(omega_list):
"""Return the array of the Solar longitude of each OMEGA/MEx observation in omega_list.
Parameters
==========
omega_list : array of OMEGAdata
The input array of OMEGA observations.
Returns
=======
ls : ndarray
The array of the omega_list Ls.
... | c8be1927a55ff9aac0134d52691b3b2bdd049724 | 700,284 |
import random
def miller_rabin_primality_testing(n):
"""Calculates whether n is composite (which is always correct) or prime
(which theoretically is incorrect with error probability 4**-k), by
applying Miller-Rabin primality testing.
For reference and implementation example, see:
https://en.wikip... | 6f7263f261bf20b851aa40e0c616a68e9936f16d | 700,289 |
import functools
from datetime import datetime
def busy_try(delay_secs: int, ExceptionType=Exception):
"""
A decorator that repeatedly attempts the function until the timeout specified
has been reached. This is different from timeout-related functions, where
the decorated function is called only *onc... | 0d005935ffa8b7f594da692edfa39ec4342ed4e1 | 700,290 |
def MakeDeclarationString(params):
"""Given a list of (name, type, vectorSize) parameters, make a C-style
parameter declaration string.
Ex return: 'GLuint index, GLfloat x, GLfloat y, GLfloat z'.
"""
n = len(params)
if n == 0:
return 'void'
else:
result = ''
i = 1
for (name, type, vecSize) in params:
... | 1b009bce0d6c25b25e4830b3a021dda877519ea3 | 700,291 |
def make_text_list(postings_dict, first_n_postings=100):
"""
Extract the texts from postings_dict into a list of strings
Parameters:
postings_dict:
first_n_postings:
Returns:
text_list: list of job posting texts
"""
text_list = []
for i in rang... | 0d2a4e0f2d904b246942508e03cfd97cf5d43ea0 | 700,294 |
def one_or_more(amount, single_str, multiple_str):
"""
Return a string which uses either the single or the multiple form.
@param amount the amount to be displayed
@param single_str the string for a single element
@param multiple_str the string for multiple elements
@return the string represent... | 8c3495614cd8c718e243383bcc72cc7daa8fa286 | 700,300 |
import torch
def accuracy(output, target, topk=(1,), exact=False):
"""
Computes the top-k accuracy for the specified values of k
Args:
output (ch.tensor) : model output (N, classes) or (N, attributes)
for sigmoid/multitask binary classification
target (ch.t... | cc2194bb72460ff39e3648e173d52875f64abeab | 700,301 |
import itertools
def enumerate_hyperparameter_combinations(parameter_to_options):
"""
Returns a list of dictionaries of all hyperparameter options
:param parameter_to_options: a dictionary that maps parameter name to a list of possible values
:return: a list of dictionaries that map parameter names ... | 8665ef66b7cb1467599ff0a56f47ac60042e0e9a | 700,302 |
def get_new_pvars(opvs, epvs):
"""Returns a list of new projection variables from a list of old
PVar's opvs, based on a list of existing PVar's epvs.
Args:
opvs: Old projection variables.
evps: Existing projection variables.
Returns:
A list of projection variables.
"""
... | b344e4fb60daa0452c944065b3164d90e7698a21 | 700,303 |
def suffix(pattern, k):
"""we define SUFFIX(Pattern) as the last (k-1)-mers in a k-mer Pattern"""
return pattern[-(k - 1):] | d6cec61ba024f551071a6ba9d6409963ff2ffe7d | 700,305 |
def runSingleThreaded(runFunction, arguments):
"""
Small overhead-function to iteratively run a function with a pre-determined input arguments
:param runFunction: The (``partial``) function to run, accepting ``arguments``
:param arguments: The arguments to passed to ``runFunction``, one r... | 9cdc34f5e44751667ec5a3bddcf2958b3302f4d1 | 700,306 |
def clip(num, num_min=None, num_max=None):
"""Clip to max and/or min values. To not use limit, give argument None
Args:
num (float): input number
num_min (float): minimum value, if less than this return this num
Use None to designate no minimum value.
num_max (float): maxim... | fe46f5a200ab24d517c57c5e1d93d4bf86192e13 | 700,310 |
def grid_coordinates(roi, x_divisions, y_divisions, position):
"""
Function that returns the grid coordinates of a given position.
To do so it computes, for a given area and taking into account
the number of x and y divisions which is the total amount of cells.
After that it maps the given position to the cell it ... | 1db6e8ed8b1c0abde965e3a5536867ae32ac2228 | 700,314 |
def splitmessage(message):
"""Returns a tuple containing the command and arguments from a message.
Returns None if there is no firstword found
"""
assert isinstance(message, str)
words = message.split()
if words:
return (words[0], words[1:]) | d8db56ef55097f9f8858de95ee3d7799c0dc127e | 700,315 |
def dec_to_str(total):
"""Converts decimals to strings for more natural speech."""
if total == 0.125:
return "an eighth"
elif total == 0.25:
return "a quarter"
elif total == 0.5:
return "a half"
elif total == 0.75:
return "three quarters"
else:
if total % ... | 05e170eb21f5f0b188a32a634b5c617536c64a11 | 700,317 |
def loadWorld(worldName, store):
"""
Load an imaginary world from a file.
The specified file should be a Python file defining a global callable named
C{world}, taking an axiom L{Store} object and returning an
L{ImaginaryWorld}. This world (and its attendant L{Store}) should contain
only a sing... | 801c98b5be82e9d5c9ca19db9adbe3078f500674 | 700,322 |
import math
def tan(x):
"""Get tan(x)"""
return math.tan(x) | 112b52faee2f08262515086fe59b2ff978001200 | 700,324 |
from typing import Any
import json
def is_jsonable(x: Any):
"""
Check if an object is json serializable.
Source: https://stackoverflow.com/a/53112659
"""
try:
json.dumps(x)
return True
except (TypeError, OverflowError):
return False | 3735de8bd1940d84c185142c0a4387366d7cd9c2 | 700,329 |
def _linear_transform(src, dst):
""" Parameters of a linear transform from range specifications """
(s0, s1), (d0,d1) = src, dst
w = (d1 - d0) / (s1 - s0)
b = d0 - w*s0
return w, b | 7f55a2617721fdefcc724bcb8ce9f880d7bcd846 | 700,332 |
def feature_within_s(annolayer, list_of_s):
"""Extracts all <annolayer> from all sentence-elements in list_of_s;
returns a flat list of <annolayer>-elements;
"""
list_of_lists_of_feature = [s.findall('.//' + annolayer) for s in list_of_s]
list_of_feature = [element for sublist in list_of_lists_of_fe... | df6ed3603381a4b8d2ea12fc483fa37ea3068372 | 700,333 |
def processPostMessage(post_message, status_type):
"""
Check if the message is >500 characters
If it is, shorten it to 500 characters
Ouput: a tuple of strings: read_more (empty if not shortened), post text
"""
if len(post_message) > 500:
post_message = post_message[:500]
last_sp... | 2d21ec04ef863b57f95bb4b8256f2195559e6f8e | 700,335 |
def data_for_keys(data_dict, data_keys):
"""
Return a dict with data for requested keys, or empty strings if missing.
"""
return {x: data_dict[x] if x in data_dict else '' for x in data_keys} | b844ae2dba804e179e7e8dd08166f392a90e7f7a | 700,336 |
def patch_set_approved(patch_set):
"""Return True if the patchset has been approved.
:param dict patch_set: De-serialized dict of a gerrit change
:return: True if one of the patchset reviews approved it.
:rtype: bool
"""
approvals = patch_set.get('approvals', [])
for review in approvals:
... | af7e56be45e537be9308f0031fe3923425afd48c | 700,343 |
def message_has_label(message, label):
"""Tests whether a message has a label
Args: message: message to consider.
label: label to check.
Returns: True/False.
"""
return label['id'] in message.get('labelIds', []) | 634808b2533469daa42779a3563f127d06ce1b14 | 700,348 |
def transform_case(input_string):
"""
Lowercase string fields
"""
return input_string.lower() | 4d15f33781c1b58d3a04a52fcc8e5f5042e33bdf | 700,352 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.