content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def positions_at_t(points, t):
"""
Given a list of Points and a time t, find their positions at time t
:param points: the list of Points
:param t: the time t
:return: a list of pairs indicating the position of the points at time t
"""
return [p.at_time(t) for p in points] | 750379504392e10994614ec0952d91782c073a58 | 46,826 |
import unicodedata
import re
def reduce_display_name(name):
"""Return a reduced version of a display name for comparison with a
username.
"""
# Strip out diacritics
name = ''.join(char for char in unicodedata.normalize('NFD', name)
if not unicodedata.combining(char))
name =... | 82d4163ff2a3c73eece890d5c94aee1af6ff0a92 | 46,833 |
def is_in(val, lvals):
""" Replace the standard 'in' operator but uses 'is' to check membership.
This method is mandatory if element to check overloads operator '=='.
Args:
val: Value to check
lvals: List of candidate values
Returns:
True if value is in the list of values (pr... | e667c756e16f35d8dbba8311fa98f193f02a05b9 | 46,837 |
def base_digits_decoder(alist: list, b: int) -> int:
"""
The inverse function of 'to_base'. This
function will take a list of integers, where each
element is a digit in a number encoded in base 'b',
and return an integer in base 10
"""
p = 0
ret = 0
for n in alist[::-1]:
ret... | ae136b738716245b93f40668e4045df2ffd38a01 | 46,839 |
import torch
def pytorch_preprocess(batch):
"""
The scaling procedure for all the pretrained models from torchvision is described in the docs
https://pytorch.org/docs/stable/torchvision/models.html
"""
batch = (batch + 1) * 0.5 # [-1, 1] -> [0, 1]
batch_color_transformed = []
batch = tor... | 008573834a0348cae5229c9d42d7293eb58242ca | 46,843 |
def bed_map_region_id_to_seq_id(in_bed_file):
"""
Read in .bed file, and store for each region ID (column 4) the sequence
ID (column 1)
Return dictionary with mappings region ID -> sequence ID
>>> test_bed = "test_data/test3.bed"
>>> bed_map_region_id_to_seq_id(test_bed)
{'CLIP2': 'chr1', '... | cc0adee384b954b1a33e61ed76f560026b0303e2 | 46,844 |
def is_abundant(number):
"""Determine if sum of divisors of number is greater than number."""
factors = [x for x in range(1, (number // 2) + 1) if number % x == 0]
if sum(factors) > number:
return True
return False | d895d562c359cd36e9ee3f7f1785c716475ae736 | 46,859 |
def summarize_repos(events):
"""Generate list of all repos in the iterable of events."""
repos = set(event.repo for event in events)
tmpl = '[{0}/{1}](https://github.com/{0}/{1})'
return [tmpl.format(*repo) for repo in sorted(repos)] | 524000f40ae6f637fcbb809e110a1b36dee9a103 | 46,860 |
def parse_noun_line(line):
"""
For a Leo dictionary noun entry line:
(aktive) Langzeitverbindung {f}
returns a list of the form:
['Langzeitverbindung', 'f']
"""
gender_start = line.find('{') + 1
gender_end = line.find('}')
word_end = line.find('{') - 1
paren_end = line... | f993cd786229a6d02a61ede833bd280300f7550a | 46,862 |
def filter_seq2seq_output(string_pred, eos_id=-1):
"""Filter the output until the first eos occurs (exclusive).
Arguments
---------
string_pred : list
A list containing the output strings/ints predicted by the seq2seq system.
eos_id : int, string
The id of the eos.
Returns
... | fbf3a8900c83dfdd7d8309e1daa262e2d193d3b0 | 46,864 |
import random
def _random_subset(seq, m):
"""Taken from NetworkX
Given a sequence seq, return a ransom subset of size m.
Parameters
----------
seq : list
The population
m : int
The sample size
Returns
-------
set
The sample from seq of size m
"""
#... | a5c29c4503bab87e193c23f3942642728232b6df | 46,867 |
def mean_of_targets(dataset):
"""
Returns the mean of the targets in a dataset.
Parameters
----------
dataset : DenseDesignMatrix
Returns
-------
mn : ndarray
A 1-D vector with entry i giving the mean of target i
"""
return dataset.y.mean(axis=0) | 20f2a8dc05b2747440b388268d05493930599459 | 46,868 |
import sqlite3
def create_connection(db_file):
""" create a database connection to a SQLite database """
try:
connection = sqlite3.connect(db_file)
print("Opened database successfully", type(connection))
except Exception as e:
raise e
return connection | c414a49ee3e559869d995ac666a8fc409d5f23be | 46,869 |
def populate(d, allow_overwrite=True):
"""
Create a decorator that populates a given dict-like object by name.
Arguments
---------
* d: a dict-like object to populate
* allow_overwrite: if False, raise a ValueError if d already has an
existing such key (default=True)
... | d0d4c254980787f43313dd3d6bd3655975bdf1f9 | 46,870 |
def sequence_generator(n):
"""
Generates sequence of numbers for a given positive integer 'n' by iterative process as specified in Goldbach
conjecture.
:param n: positive
:return: list of numbers in the generated sequence, boolean indicating whether last element of sequence is 1
"""
if not i... | b70d7820883ab41c1d41b2d5d8bfa7d4671f612c | 46,872 |
import pyflakes.api
import pyflakes.reporter
def undefined_names(sourcecode):
"""
Parses source code for undefined names
Example:
>>> print(ub.repr2(undefined_names('x = y'), nl=0))
{'y'}
"""
class CaptureReporter(pyflakes.reporter.Reporter):
def __init__(reporter, warnin... | f1124db4af4ee2a37ba5949660073b4f8b3e651b | 46,873 |
import math
def solar_radius_vector_aus(eccentricity_earth_orbit, solar_true_anomaly):
"""Returns the Solar Radius Vector.
Measured as distance in Astronomical Units, (AUs).
With Eccentricity of Earth's Orbit, eccentricity_earth_orbit, and Solar
True Anomaly, solar_true_anomaly.
"""
solar_ra... | 13f2458bea1d878e09cf207629621d812c5e7550 | 46,874 |
def _CppName(desc):
"""Return the fully qualified C++ name of the entity in |desc|."""
return '::'+desc.fqname.replace('.', '::') | bd5985321918850bfb1f095c1587028194e9739b | 46,875 |
def parse_geneseekr_profile(value):
"""
Takes in a value from the GeneSeekr_Profile of combinedMetadata.csv and parses it to determine which markers are
present. i.e. if the cell contains "invA;stn", a list containing invA, stn will be returned
:param value: String delimited by ';' character containing ... | e0ac1772f540b207272875f544f461ac633422b7 | 46,877 |
def _follow_path(json_data, json_path):
"""Get the value in the data pointed to by the path."""
value = json_data
for field in json_path.split("."):
value = value[field]
return value | 6c453125ba06a560b77d3f89ec4816a8393cd919 | 46,880 |
def epoch_timestamp_to_ms_timestamp(ts: int) -> int:
""" Converts an epoch timestamps to a milliseconds timestamp
:param ts: epoch timestamp in seconds
:return: timestamp in milliseconds
"""
return int(ts * 1000) | 485035d7effc0adfa6bbe8bff22df0b3480ec7f3 | 46,882 |
def fst(pair):
"""Return the first element of pair
"""
return pair[0] | f31a63338a07548691d7354b6f948399cb9cfae5 | 46,885 |
def read_input(datafile, classfile):
"""Read the data points file and class id of each point.
Args:
datafile (str): Data points file.
classfile (str): Point class file.
Returns:
tuple: Returns a tuple containing a list of points and a list
containing the class of... | 49ed27b048d754bddd50fd59b521f6f564dc6a95 | 46,889 |
def map_to_range(x: int, from_low: int, from_high: int, to_low: int, to_high: int) -> int:
"""
Re-map a number from one range to another.
A value of fromLow would get mapped to toLow, a value of fromHigh to toHigh, values in-between to values in-between.
Do not constrain values to within the range, be... | ab69a069c9544b8a2546f849f8544e81631a6870 | 46,890 |
import re
def has_cyrillic(text):
"""
This is ensuring that the given text contains cyrllic characters
:param text: The text to validate
:return: Returns true if there are cyrillic characters
"""
# Note: The character range includes the entire Cyrillic script range including the extended
... | 9556007206003534e8da7e6aa73a3d3a10962c55 | 46,891 |
def str_aligned(results, header=None):
"""
Given a tuple, generate a nicely aligned string form.
>>> results = [["a","b","cz"],["d","ez","f"],[1,2,3]]
>>> print str_aligned(results)
a b cz
d ez f
1 2 3
Args:
result: 2d sequence of arbitrary types.
header:... | 8945813211548884193fd54a2e939eaabbb75f18 | 46,893 |
def make_prev_next(seg_table):
"""
Function to make two column table into a four column table with prev/next seg
:param seg_table: Input table of form:
They They
don't do|n't
know know
:return: Four column table with prev/next group context columns:
_ don't They They
They know don... | f867755e079583c09a6aa47a6f8fc80f56066b07 | 46,895 |
def _coerce_to_number(value):
"""Attempt to coerce to a 'number' value.
Since json schema spec is loose here, we'll return the int value
if it's equal to the float value, otherwise give you a float.
"""
if int(value) == float(value):
return int(value)
return float(value) | ec04e8116db7571f9d7edc38df785be49d8ed6fa | 46,898 |
import re
def getTopBillLevel(dirName: str):
"""
Get path for the top level of a bill, e.g. ../../congress/data/116/bills/hr/hr1
Args:
dirName (str): path to match
Returns:
[bool]: True if path is a top level (which will contain data.json); False otherwise
"""
dirName_parts = dirName.spli... | 9d6622ad45fa78b80a3aa3e8e59418fe4e6bfbee | 46,899 |
import socket
def record_exists(record: str) -> bool:
"""
Determines whether a DNS record exists
"""
try:
socket.getaddrinfo(record, None)
except socket.gaierror:
return False
return True | c9aaa2aaf855aa6e12363acc4da359f8597c9531 | 46,907 |
def convert_to_float(tensor, half=False):
"""
Converts the tensor to either float32
or float16 based on the parameter.
"""
return tensor.half() if half else tensor.float() | ff8ccfbc8de91c6eb059cc26c963c438a4adb0a5 | 46,913 |
def generate_words(words):
"""Create a list of words with appended integers from a list of provided words"""
return ["{}{}".format(word, number) for word, number in zip(words, range(len(words)))] | 946a0558541230d9902540e865da7a3c9eb797fa | 46,917 |
from typing import Sequence
from typing import Tuple
def get_range(shape: Sequence[int], itemsize: int, strides: Sequence[int]) -> Tuple[int, int]:
"""
Given an array shape, item size (in bytes), and a sequence of strides,
returns a pair ``(min_offset, max_offset)``,
where ``min_offset`` is the minimu... | 40e9deb664941dec91cdd5bb08af5ff2de487f69 | 46,919 |
def escape(s):
"""Escape content of strings which will break the api using html entity type escaping"""
s = s.replace("&", "&")
s = s.replace("\r\n", " ")
s = s.replace("\n", " ")
s = s.replace("\r", " ")
s = s.replace("(", "(")
s = s.replace(")", ")")
s = s.repla... | efbc4820078d5e7f703c2443c531f01aa5b2d983 | 46,925 |
def add_domain(user):
"""
Helper function that appends @linaro.org to the username. It does nothing if
it is already included.
"""
if '@' not in user:
user = user + "@linaro.org"
return user | 505561ae6506226e16373b611a4e296351278b68 | 46,935 |
import re
from typing import OrderedDict
def split_tags(tags, separator=','):
"""
Splits string tag list using comma or another separator char, maintain
order and removes duplicate items.
@param tags List of tags separated by attribute separator (default: ,)
@param separator Separator char.
@... | 8a5c850146201a801c74c4c102f141c193a20ea9 | 46,940 |
def is_string(atype):
"""find out if a type is str or not"""
return atype == str | 222398429f641e65b04867f7ef9a130d52881fc8 | 46,942 |
from textwrap import dedent
from datetime import datetime
def generate_header(model_name: str, use_async: bool) -> str:
"""Generates the header for a Python module.
Args:
model_name (str): The name of the system model the header is generated for.
use_async (bool): True if asynchronous code sh... | ce1d06f5c41cc6aaf15d3f9ef4bbb474e07327de | 46,943 |
from typing import Sequence
def default_cleaner(quotes: Sequence[str]) -> Sequence[str]:
"""
Default cleaner function used by bot instance.
:param quotes: Sequence of quotes which are to be pre-processed.
:return:
processed quotes.
"""
quotes = [q.strip() for q in quotes if q]
ret... | 354b912e9074342c704a176ecec2d8661d209eb4 | 46,944 |
def group_days_by(days, criterion):
"""
Group the given vector of days according to the given criterion.
Parameters
----------
days: pd.DatetimeIndex
criterion: str
Indicates how to group the given days. It can be either "year" or "month" or "season".
(The meteorological seasons... | 46e71c3ecdd4dc3b62ddae02a323c214258bc30e | 46,945 |
def urlpath2(url:bytes) -> bytes:
""" Get url's path(strip params) """
return url.split(b'?', 1)[0] | b5464b3617cbd6303f4438c92fd8f5271f6906e1 | 46,949 |
def leading_zeros(val, n):
""" Return string with "n" leading zeros to integer. """
return (n - len(str(val))) * '0' + str(val) | eb4d55caf41f71c4d953398c17c8980070892a0c | 46,953 |
def get_vaf(mutations):
"""
Given the list of mutations in the form
<TRANSCRIPT_1>_X123Y#0.56,<TRANSCRIPT_2>_X456Y#0.91,etc -> for SNVS
<5'TRANSCRIPT_1>-<3'TRANSCRIPT_1>_FUSION_Junction:X-Spanning:Y,\
<5'TRANSCRIPT_2>-<3'TRANSCRIPT_2>_FUSION_Junction:A-Spanning:B,etc -> for FUSIONS
... | a736f3b40c8de59508f66a9db35833344ef873ca | 46,956 |
def ishexdigit(c):
"""
>>> ishexdigit('0')
True
>>> ishexdigit('9')
True
>>> ishexdigit('/')
False
>>> ishexdigit(':')
False
>>> ishexdigit('a')
True
>>> ishexdigit('f')
True
>>> ishexdigit('g')
False
>>> ishexdigit('A')
True
>>> ishexdigit('F')
... | b450b243bc40ea4f5c84ddfdeddcd8022839def3 | 46,959 |
import time
def get_day_num(dayname) -> int:
"""Converts dayname to 0 indexed number in week e.g Sunday -> 6"""
return time.strptime(dayname, "%A").tm_wday | 29e2b00066b6a0ca207ae3cced3f7efb7ce2c190 | 46,965 |
def clean(s):
"""Clean up a string"""
if s is None:
return None
s = s.replace("\n", " ")
s = s.replace(" ", " ")
s = s.strip()
return s | e706b68c7ed5b78ca54a3fd94af5de35ee142d43 | 46,968 |
def leapdays(y1, y2):
"""
Return number of leap years in range [y1, y2]
Assume y1 <= y2 and no funny (non-leap century) years
"""
return (y2 + 3) / 4 - (y1 + 3) / 4 | c7e7c3b4650ef1236fc70ba94240f7119d9397c0 | 46,973 |
def truncate_column(data_column, truncation_point):
"""
Abstraction of numpy slicing operation for 1D array truncation.
:param data_column: 1D np.array
:param truncation_point: int of truncation index to test
:return: np.array
"""
assert (len(data_column.shape) == 1) # Assert data_column is... | bc444517953228d003fc18851f5c22b2b70f6e55 | 46,984 |
import math
def asinh(x):
"""Get asinh(x)"""
return math.asinh(x) | e0086dd83ca8a4dd005deed4ef0e58d11c306d0a | 46,990 |
import io
def export_python(palette):
"""
Return a string of a Python tuple of every named colors.
Arguments:
palette (dict): Dictionnary of named colors (as dumped in JSON from
``colors`` command)
Returns:
string: Python tuple.
"""
# Open Python tuple
python_... | b32b97412612d36096aab088d6e3671e5059a32b | 46,994 |
import json
def getStatus(response):
"""
Get the status of the request from the API response
:param response: Response object in JSON
:return: String - statuse
"""
resp_dict = json.loads(response.text)
try:
status = resp_dict["status"]
except KeyError:
print('Retrieva... | a72a056ef574fdf0fb8f5744073d351836c6db07 | 46,997 |
import itertools
def flatten_metas(meta_iterables):
"""
Take a collection of metas, and compose/flatten/project into a single list.
For example:
A: pkg1, pkg2a
B: pkg2b, pkg3
Flattened([A, B]) => [pkg1, pkg2a, pkg3]
Flattened([B, A]) => [pkg1, pkg2b, pkg3]
The resul... | 4125a7bea44989140909e91392cd3adb740e26f1 | 47,004 |
def plural(singular, plural, seq):
"""Selects a singular or plural word based on the length of a sequence.
Parameters
----------
singlular : str
The string to use when ``len(seq) == 1``.
plural : str
The string to use when ``len(seq) != 1``.
seq : sequence
The sequence t... | 352d8fca4b2b7fb8139b11296defd65796e0e712 | 47,005 |
def static_feature_array(df_all, total_timesteps, seq_cols, grain1_name, grain2_name):
"""Generate an arary which encodes all the static features.
Args:
df_all (pd.DataFrame): Time series data of all the grains for multi-granular data
total_timesteps (int): Total number of training samples ... | 58f4664fa318f1026a1c3e48616431f51b224704 | 47,007 |
import re
def check_for_title(line):
"""
Check the current line for whether it reveals the title of a new entry.
:param srtr line: the line to check
:return: tuple (the entry title, the entry type) or (None, None)
"""
re_title = re.compile(
'^(?P<title>.+) \\((?P<type>EPHEMERA OBJECT|... | 73d7b73d29e51b87a37810d434582c975c6d0c07 | 47,015 |
def rotate_right(arr):
"""
Rotate a copy of given 2D list
clockwise by 90 degrees
and return a new list.
:param arr: A 2D-list of arbitrary
dimensions.
:return: A list that is "arr" rotated
90 degree clockwise by its center.
"""
n = len(arr)
m = len(arr[0])
res = [[Non... | 2d393acbb8accaae90dd562b5360199698a032a9 | 47,017 |
def get_dl_dir(cd, t, chan):
"""Get the cached download destination directory for file
Get the path for the destination directory for channel for GOES 16 ABI L1B
is downloaded. It does not check if the destination directory exists.
Args:
cd (pathlib.Path): Root path for cache directory
... | 33a315189feffe33a3c4ecc9d1851164b5b70e1c | 47,019 |
def can_receive_blood_from(blood_group):
"""Return allowed blood groups given a specific blood group."""
can_receive_from = {
'A+': ['A+', 'A-', 'O+', 'O-'],
'O+': ['O+', 'O-'],
'B+': ['B+', 'B-', 'O+', 'O-'],
'AB+': ['A+', 'O+', 'B+', 'AB+', 'A-', 'O-', 'B-', 'AB-'],
'A-': ['O-', ... | 34c956f829a14c9b1ebe6f664c44d554451b11e0 | 47,021 |
def replace_ref_nan(row):
"""Function to replace nan info values of some references coming from references without PubMed id
with their reference id."""
if isinstance(row["combined"], float):
return row["reference_id"]
else:
return row["combined"] | 76f5effe6613178055e38721f8a09d459ab0a019 | 47,023 |
def list4ToBitList32(lst):
"""Convert a 4-byte list into a 32-bit list"""
def intToBitList2(number,length):
"""Convert an integer into a bit list
with specified length"""
return [(number>>n) & 1
for n in reversed(range(length))]
lst2 = []
for e in lst:
... | ac95e68927b703292913229f7a1d0316941f570e | 47,024 |
def IpBinaryToDecimal(bin_ip):
"""
:param bin_ip: IPv4 in binary notation, e.g. 00001010000000000000000000000001
:return: IPv4 in decimal notation, e.g. 167772161
"""
return int(bin_ip, 2) | 20366a1667fd1f9c1f17e7c13c2292bd4a7e74b0 | 47,027 |
def _rescale_0_1(batch):
"""
Rescale all image from batch, per channel, between 0 and 1
"""
for image_id in range(batch.size(0)):
for channel_id in range(batch[image_id].size(0)):
pix_min = batch[image_id][channel_id].min()
pix_range = batch[image_id][channel_id].max() - ... | 65e70cb6b3779f9ec776568a65fee13f56f0ca21 | 47,031 |
import re
def __safe_file_name(name: str) -> str:
"""
This helper is responsible for removing forbidden OS characters from a certain string.
:param name: String to be converted
:return: Safe string
"""
return re.sub(r'<|>|/|:|\"|\\|\||\?|\*', '', name) | 6b52ededba763fa48c3e8c1d3f64c1487269e457 | 47,034 |
from pathlib import Path
def get_modality_from_name(sensor_path: Path):
"""Gets the modality of a sensor from its name.
Args:
sensor_path (Path): the Path of the sensor. Ex: CAM_FRONT_RIGHT, LIDAR_TOP, etc.
Returns:
str: the sensor modality
"""
sensor_name_str = str(sensor_path)
... | 4d37ea2bf096032eb824f7c951099fc7caea09fd | 47,036 |
def constant(value=0):
"""A flat initial condition. Rather boring, you probably want a source or some interesting boundary conditions
for this to be fun!
Args:
value (float): The value the function takes everywhere. Defaults to 0."""
return lambda x: value | 9286cfe97bdf0a19831fab3fc7d69268e6660674 | 47,037 |
def _csstr_to_list(csstr: str) -> list[str]:
"""
Convert a comma-separated string to list.
"""
return [s.strip() for s in csstr.split(',')] | 88b2197a6c86839426daf35bbddb212519ef1659 | 47,041 |
import requests
def get_header_contents() -> str:
"""
Get js_ReaScriptAPI header from GitHub as raw string.
Returns
-------
str
"""
root_raw = 'https://raw.githubusercontent.com/'
header = (
'juliansader/ReaExtensions/master/js_ReaScriptAPI/' +
'Source%20code/js_ReaScr... | b2272dfbc131a422ec2aeb6e57d17a0ad6b41ae2 | 47,044 |
def actions(board):
"""
Returns set of all possible actions (i, j) available on the board.
"""
moves = set()
for row in range(len(board)):
for col in range(len(board[0])):
if board[row][col] == None:
moves.add((row,col))
return moves | 639a4c6fbf701b7d3afc09198911ab3a1a587460 | 47,046 |
import shutil
def executable_path(*tries):
"""Find path to executable, or throw."""
path = None
for ex in tries:
path = shutil.which(ex)
if path:
break
if not path:
raise Exception(f"Unable to find path to {tries[0]}")
return path | 825bb53c9b44678e43cdd2b9d68d905932027737 | 47,049 |
def sdp_term_p(f):
"""Returns True if `f` has a single term or is zero. """
return len(f) <= 1 | 1fbefa0f751d0583f4c20b81289df2b4ca4dfca6 | 47,063 |
def coding_problem_46(str):
"""
Given a string, find the longest palindromic contiguous substring. If there are more than one with the maximum
length, return any one. Examples:
>>> coding_problem_46("aabcdcb")
'bcdcb'
>>> coding_problem_46("bananas")
'anana'
"""
for length in range(... | af4033333274b23961edc048fdba034b29b801a7 | 47,066 |
def tostring(s):
"""
Convert to a string with quotes.
"""
return "'" + str(s) + "'" | 90c1cd55ecbf0e5562810399ab737f7b53b13305 | 47,067 |
def wifi_code(ssid, hidden, authentication_type, password=None):
"""Generate a wifi code for the given parameters
:ssid str: SSID
:hidden bool: Specify if the network is hidden
:authentication_type str: Specify the authentication type. Supported types: WPA, WEP, nopass
:password Optional[str]: ... | a479a2ea8c9a3aed40556e0c94f6dd5c8d67eca7 | 47,070 |
def calculate_polygon_area(corners):
"""Calculate 2D polygon area with given corners. Corners are assumed to be ordered.
Args:
corners (Nx2 array): xy-coordinates of N corner points
Returns:
float: polygon area"""
# Use the shoelace algorithm to calculate polygon's area
psum = 0
nsum = 0
npoin... | 87ed4e4c0c8e6655e70b6addf0588c37454f4968 | 47,071 |
def get_global_stats(df):
"""Compute the metadata statistics of a given DataFrame and put them in a 2D list."""
stats = []
stats.append(["Number of rows", df.shape[0] ])
stats.append(["Number of columns", df.shape[1] ])
stats.append(["Number of duplicates", len(df) - len(df.drop_duplicates())])... | bf08c620e5937d73f1f0ce3a9ce251253919a516 | 47,075 |
def factorial_zeroes(n):
"""Consider a factorial like 19!:
19! = 1*2* 3*4* 5*6*7*8*9* 10* 11* 12* 13*14*15* 16* 17*18*19
A trailing zero is created with multiples of 10
and multiples of 10 are created with pairs of 5-multiples and 2-multiples.
Therefore, to count the number of zeros, we only need t... | f60b8be459cba3af795d360a51754fbc43959a63 | 47,076 |
def rootsearch(f, a, b, dx):
""" x1,x2 = rootsearch(f,a,b,dx).
Searches the interval (a,b) in increments dx for
the bounds (x1,x2) of the smallest root of f(x).
Returns x1 = x2 = None if no roots were detected.
"""
x1 = a
f1 = f(a)
x2 = a + dx
f2 = f(x2)
#
while f1*f2 > 0.0:
... | f6bb3ed2183850b2add575953ad6acee298f1a1f | 47,086 |
def eq_55_activation_of_heat_detector_device(
u: float,
RTI: float,
Delta_T_g: float,
Delta_T_e: float,
C: float
) -> float:
"""Equation 55 in Section 8.9 PD 7974-1:2019 calculates the heat detectors temperature rise.
PARAMETERS:
:param u: m/s, velocity of gases in p... | 480e33a54b769dce6d2167291c6058a8750418d0 | 47,087 |
def unique(hasDupes):
"""
Removes duplicate elements from a list
@param hasDupes : a list with duplicate items
@return: list with duplicates removed
"""
ul = list(set(hasDupes))
ul.sort()
return ul | 88d3dc491a3519a46b95138f514d57319ccc3f3b | 47,091 |
def get_matrix_stride(mat):
"""Get the stride between lines of a C matrix"""
itemsize = mat.itemsize
stride = mat.strides[0] // itemsize
assert mat.strides == (stride * itemsize, itemsize)
return stride | eec8e2f79b6ff9df449079298829413cdc3d248f | 47,096 |
from pathlib import Path
def pathwalk(dir: Path) -> list[Path]:
"""Obtain all file paths in a directory and all it's subdirectories.
Function is recursive.
Args:
`dir` (`Path`): The starting, top-level directory to walk.
Returns:
(list): Containing Path objects of all filepaths in `... | e0cefd65166fb28b9c7c39acaf03978e9608c809 | 47,102 |
def kataSlugToKataClass(kataSlug):
"""Tranform a kata slug to a camel case kata class"""
pascalCase = ''.join(x for x in kataSlug.title() if not x == '-')
# Java don't accept digits as the first char of a class name
return f"Kata{pascalCase}" if pascalCase[0].isdigit() else pascalCase | 92698e9002f42dd6f9abea1f6970b530575e54ef | 47,104 |
def least_significant_set_bit(n):
"""
Returns least-significant bit in integer 'n' that is set.
"""
m = n & (n - 1)
return m ^ n | 7813a92e53be724c14cbd68dc0cffd49490dc05e | 47,105 |
def natural_key_fixed_names_order(names_order):
"""Convert symbol to natural key but with custom ordering of names.
Consider a QAOA ansatz in which parameters are naturally ordered as:
gamma_0 < beta_0 < gamma_1 < beta_1 < ...
The above is an example of natural_key_fixed_names_order in which name 'gam... | 74e20a7e19305716d501da8ced49ec28bf85eac1 | 47,113 |
def find_set(x):
"""Finds representant of the given data structure x."""
if x.parent is None:
return x
x.parent = find_set(x.parent)
return x.parent | 47b332938e6a648f0d353d027979b63b0c1e8826 | 47,116 |
def not_submitted_count(drafts):
"""
Get count of not-submitted services
Defaults to 0 if no not-submitted services
:param drafts:
:return:
"""
return drafts.get('not-submitted', 0) | dda309998234be6c560cf3b4ecafda41c43d20e3 | 47,119 |
def unpack_args(args, num):
"""
Extracts the specified number of arguments from a tuple, padding with
`None` if the tuple length is insufficient.
Args:
args (Tuple[object]): The tuple of arguments
num (int): The number of elements desired.
Returns:
Tuple[object]: A tuple co... | 9f0a2ab601a7974f7ae5ba5dc008b04ee07f0678 | 47,121 |
from typing import Iterable
def _variable_or_iterable_to_set(x):
"""
Convert variable or iterable x to a frozenset.
If x is None, returns the empty set.
Arguments
---------
x: None, str or Iterable[str]
Returns
-------
x: frozenset[str]
"""
if x is None:
return frozenset([])
if isinst... | 36ab763a3a4341c49fefb6cb3b10d88bef040fa8 | 47,123 |
import re
def workdir_from_dockerfile(dockerfile):
"""Parse WORKDIR from the Dockerfile."""
WORKDIR_REGEX = re.compile(r'\s*WORKDIR\s*([^\s]+)')
with open(dockerfile) as f:
lines = f.readlines()
for line in lines:
match = re.match(WORKDIR_REGEX, line)
if match:
# We need to escape '$' sinc... | 33a927626a023ba988534afe5b3f8885e18db471 | 47,126 |
import pickle
def load_database(filename):
"""Read in pickled database file."""
with open(filename, 'rb') as fin:
return pickle.load(fin) | ee9f55e626585624f75eb17663b7393628941ece | 47,131 |
import logging
def get_video_bitrate(dict_inf, stream_video):
"""Bitrate search. It may be in one of the 2 possible places.
Args:
dict_inf (dict): video metadata
stream_video (dict): video stream data
Raises:
NameError: If Bitrate is not found in any of the possible places
R... | cc7e2423c3288c9f392776cd5b6477973492874c | 47,134 |
def logic(number: int) -> int:
"""Perform logic for even-odd transformation.
Each even-odd transformation:
* Adds two (+2) to each odd integer.
* Subtracts two (-2) to each even integer.
"""
# Determine the modifier based on number being even or odd.
modifier = -2 if number % 2 == 0... | 64d10c9a605f09a1ecaaec695320a98094a63bc3 | 47,142 |
def get_label(timestamp, commercials):
"""Given a timestamp and the commercials list, return if
this frame is a commercial or not. If not, return label."""
for com in commercials['commercials']:
if com['start'] <= timestamp <= com['end']:
return 'ad'
return commercials['class'] | 72d96f35c63d5f6e8859b2c5bc3a0b8dab37fc39 | 47,147 |
import io
def config_to_string(config):
"""
Convert ConfigParser object to string in INI format.
Args:
config (obj): ConfigParser object
Returns:
str: Config in one string
"""
strio = io.StringIO()
config.write(strio, space_around_delimiters=False)
return strio.getva... | 264159206b7367ed584c25ec36c2232a1a558880 | 47,149 |
def count_fn(true_fn_flags, ground_truth_classes, class_code):
"""
Count how many true FN are left in true_fn_flags for class given by class_code
Args
true_fn_flags: list of flags that are left 1 if ground truth has not been detected at all
ground_truth_classes: list of classes correspondin... | bb68474afe5d60fd30db59a9dc8e640f5ab3f00e | 47,150 |
def read_IMDB(file_name):
"""
:param file_name: Takes as input the IMDB dataset file name as a string
:return: and outputs a list of lists containg datapoins consisting of a sentence (string) and a target (an integer)
"""
with open(file_name, 'r', encoding="latin-1") as text_file:
l = []
... | 72638f65ff1d6f220f299f996ed59b5d24bd6c16 | 47,151 |
def toHexByte(n):
"""
Converts a numeric value to a hex byte
Arguments:
n - the vale to convert (max 255)
Return:
A string, representing the value in hex (1 byte)
"""
return "%02X" % n | e6a7ceab39731f38d1c3fdaa4cba847d1ad41929 | 47,154 |
def conj(coll, to_add):
"""
Similar to clojure's function, add items to a list or dictionary
See https://clojuredocs.org/clojure.core/conj for more reading
Returns a new collection with the to_add 'added'. conj(None, item) returns
(item). The 'addition' may happen at different 'places' depending ... | 62cca3766c3a4467db73372209d6f173647ed3af | 47,155 |
import collections
def _format_expand_payload(payload, new_key, must_exist=[]):
""" Formats expand payloads into dicts from dcids to lists of values."""
# Create the results dictionary from payload
results = collections.defaultdict(set)
for entry in payload:
if 'dcid' in entry and new_key in e... | ae9af5400f0bf38954c99afca62914e30f42ec32 | 47,158 |
def to_float_list(a):
"""
Given an interable, returns a list of its contents converted to floats
:param a: interable
:return: list of floats
"""
return [float(i) for i in a] | 8576c649802c9a88694097ceefb55c86ab845266 | 47,161 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.