content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def SumCoeffsOverSet(summing_set, A):
"""Returns the sum of coefficients corresponding to the summing set."""
return sum(A[i - 1] for i in summing_set) | 2fa61493d4abd07cf24670a56d4a56d08b5a602b | 14,479 |
def camel_split(string):
# test: (str) -> str
"""
>>> print('(%s)' % ', '.join("'%s'" % s for s in camel_split('theBirdsAndTheBees')))
('the', 'Birds', 'And', 'The', 'Bees')
>>> print('(%s)' % ', '.join("'%s'" % s for s in camel_split('theBirdsAndTheBees123')))
('the', 'Birds', 'And', 'The', 'Be... | f7d0d27e25a26b6e4135bb6d83dc35f5d1cd2374 | 14,480 |
def snake_to_camel(snake_case_string: str) -> str:
"""
Takes in a `snake_case` string and returns a `camelCase` string.
:params str snake_case_string: The snake_case string to be converted
into camelCase.
:returns: camelCase string
:rtype: str
"""
initial, *temp = snake_case_string.spli... | 4ef8fa72580739dbedfbac5bf9f95247f5ea69c3 | 14,481 |
def formatsGenres(genres_list):
""" Formats Genres for Web app template. """
genres = ""
try:
for item in genres_list:
print(item.genre_type)
except:
genres = "Unknown"
else:
for genre in genres_list:
print(genre, genres_list[-1])
if l... | e9ba9a9388ba7b19c97f1f9959c3c828d1a15219 | 14,484 |
def parse_int_list(text):
"""Parse a string into a list of integers
For example, the string "1,2,3,4" will be parsed to [1, 2, 3, 4].
Parameters
----------
text : str
String to parse
Returns
-------
List[int]
Parsed integer list
"""
result = [int(i) for i in te... | f83b21c9038e5ea8eb2c0d53ad94479cab9258f3 | 14,485 |
def to_python(value):
"""Converts Whispy Lispy types to Python types """
return value.values[0] | 1ffd36443e04b8aeb823e8eb932e4abf888975a2 | 14,487 |
def call_api(query, service):
""" calls api and returns result """
result = service.data().ga().get(**query).execute()
return result | 9816a2e4a0e38d25a376eb43325bf51982a921ce | 14,488 |
def build_popularity_dict(game):
"""Return a Dict of how proportionally popular each player count is"""
popularity = {}
for x in game.player_suggestions:
if (
x.numeric_player_count >= game.min_players and
x.numeric_player_count <= game.max_players
):
... | 9718fca6f6ccb76f378e088c2aa2e16387f2383a | 14,489 |
def to_python(path):
"""Translates a `Path` object to a string of the form `MontyCarlo.module1`.
"""
res = path.name
while path != path.parent:
path = path.parent
res = path.name + "." + res
res = res[1:][11:]
return res + ".*" if res != "" else "*" | 24b7a669e0fc1e40113044f2da79e29d42f04c81 | 14,491 |
def cal_error(array, typeb = 0):
"""Calculate all errors of the input array.
Args:
array (numpy.array): The data measured directly for a single
physical datus. We use the mean value as the reliable
measurement for that and get type-A error meanwhile.
typeb (float): The t... | f0fc8832f730189e4f2a0597e1342f94ed2d8717 | 14,492 |
def navigation(obj):
"""
Goes through json file and shows its structure
"""
if isinstance(obj,dict):
print()
print("This object is dictionary")
keys = list(obj.keys())
print()
print(keys)
print()
user_choice = input("Here are keys of this dictionar... | a2b3b556b38082ba06e6f3d1b3ce79d9f0c4de3e | 14,493 |
def device_mapper(os_type: str, proto: str = "netmiko"):
"""
map an os type to a netmiko device_type
:params os_type: type str
:params proto: type str, default "netmiko"
:returns: device_type string
"""
if proto == "netmiko":
device_types = {
"ios": "cisco_ios",
... | 81ad4c4dd86c7e6930cf0fb070681872783a5fb8 | 14,495 |
def strip_to_category(category):
"""Strip prefix and postfix from category link.
Parameters
----------
category : str
Returns
-------
stripped_category : str
String with stripped category
"""
if category.startswith('[[Kategori:'):
category = category[11:-2]
eli... | d4a274757aed9b3fbe2e9c5c187949a19b53e3ad | 14,496 |
import struct
def read_rom_address_list(rom, offset, count):
"""Reads a list of addresses in Wolf3D's weird storage method.
01 35 03 CC 00 -> 0xc0335
"""
rom.seek(offset)
offsets = []
for x in range(count):
zb = rom.read_ubyte()
assert 1 <= zb <= 3, 'zb is {}'.format(zb)
... | 4e9b0fff0d64a03901d4731c8165bb34fd98e8b5 | 14,497 |
import os
from unittest.mock import patch
def no_file(filename):
"""Context manager that disallows access to a file."""
def side_effect(filename_):
"""Return False for the specified file."""
if filename_ == filename:
return False
return isfile_original(filename_)
# Sto... | 029d087266d08a5aaa72006a80b841339168596c | 14,499 |
def clean_for_doc(nb):
"""
Cleans the notebook to be suitable for inclusion in the docs.
"""
new_cells = []
for cell in nb.worksheets[0].cells:
# Remove the pylab inline line cells.
if "input" in cell and \
cell["input"].strip().startswith("%pylab inline"):
... | 2cec552f8c2d2ae4437f7460db4f8bd4919c9f65 | 14,500 |
import argparse
def parse_arguments():
"""Parse command line arguments."""
parser = argparse.ArgumentParser(description="Make a custom GTF file.")
parser.add_argument("-i", "--input", help="Input GTF file.", required=True)
parser.add_argument("-o", "--output", help="Output GTF file.", required=True)
... | 8d6603bc932b66df485fa2c3af6a35f267a41b6a | 14,502 |
from typing import Union
from typing import Dict
def _resource_dict(mem: Union[str, int], cpu: Union[str, int]) -> Dict[str, str]:
"""
Private helper function to create a resource dictionary for deployments. Currently only supports the creation
of the requests/limits directory that is needed for a V1Resor... | dc00bcba7442f655e0f56e6390b1675078ca9e4f | 14,503 |
def is_hexstring(string):
"""
Determines if a string is a hexstring.
:param Union[ByteString, str] string: A string.
:return: Whether the string's length is even and all of its characters
are in [0-9a-fA-f].
"""
if isinstance(string, str):
string = string.encode()
return not ... | 7263cbbb464d805b6e5f0142a2ff6772894c4837 | 14,504 |
def min_ind_of_anch(anchor_info):
""" Finds the index of min ID. """
anch_id = list(anchor_info.keys())
min_id_ind = anch_id.index(min(anch_id))
return min_id_ind | 89e77679a21f36016174cf8a52ec4b210e1ad295 | 14,506 |
def pkcs5_pad(data, block_size):
"""使用 RFC 2898 描述的 PKCS #5 算法补齐。
许多对称加密算法会要求要加密的信息长度需要是多少字节(例如 8
字节)的整倍数,因此需要有某种算法对不符合要求的信息进行补齐。
Args:
data (bytes): 需要补齐的报文。
block_size (int): 块长度。
Returns:
bytes: 补齐后的信息。
"""
if not isinstance(data, bytes):
raise ValueErro... | 3d4e941e844bf4be2bcc9b9318a3472c4b8bbe8e | 14,507 |
def name_from_id(id):
"""Hash the id into a run name
Construct the name of the run from the id dictionary
Args:
id (dict): id associated to the run
Returns:
str: name of the run associated to the dictionary ``id``
"""
keys = list(id.keys())
keys.sort()
name = ''
for ... | ad8eeed94e7f22e96c197753ed59652dcbfcda8e | 14,508 |
def calculate_clinker(annual_production, clinker_cement_ratio):
"""
Calculate annual clinker production based on given cement/clinker ratio
:param annual_production: Reported annual production
:param clinker_cement_ratio: Amount of clinker produced per cement output
:return: Clinker per year
"""... | f08f4757ee27c2f4e54fd7acbbdaea398bee1a6e | 14,509 |
def make_generator_instance(int_model_def):
"""Returns instance of a <Model>Run.
"""
return int_model_def.RunClass(int_model_def) | 7acd0def22a92b6ea5a997a5f0d90e1ab06218af | 14,510 |
def accuracy(task_preds, task_targets):
"""Computes the accuracy of a given task.
:param task_preds: Predicted labels.
:param task_targets: Ground-truth targets.
:return: a float metric between 0 and 1.
"""
assert task_preds.size > 0
assert task_targets.size > 0
assert task_targets.siz... | ed8bdef02253c952213b87ee39a86505315e4077 | 14,511 |
import struct
def b2f(b):
"""
32bit int to float
"""
return struct.unpack('f', struct.pack('I', b))[0] | d14dbc6182edb9947e4a5416114906a9c09a5751 | 14,514 |
def strip(table, col):
"""Removes column col from the given table
Preconditions: table is a (non-ragged) 2d List,
col valid column"""
n_row = len(table)
n_col = len(table[0])
assert col < n_col, repr(col) + "要删除的列大于总列数!"
for row in range(n_row):
table[row] = table[row][:col]+table[ro... | 09171295b7ed46d12188eb8c882a60f5fce80647 | 14,516 |
def _parse_aggregation_feat(aggregating_in, features):
"""Parse aggregation information and format in a correct standard way.
Parameters
----------
aggregating_in: tuple
the information for aggregating features
features: pst.BaseFeatures
the features we want to aggregate.
Retur... | e909cb032d97f5598ceb4321b44a8ecb4f0463fd | 14,517 |
def get_description():
""" Return a dict describing how to call this plotter """
desc = dict()
desc['data'] = True
desc['cache'] = 86400
desc['description'] = """This chart shows the number of VTEC phenomena and
significance combinations issued by a NWS Forecast Office for a given year.
Plea... | 0aa6fe9db51641479006e2bd31a5df926bb43d06 | 14,518 |
def reinterpret_latin1_as_utf8(wrongtext):
""" :see:recode_unicode """
newbytes = wrongtext.encode('latin-1', 'replace')
return newbytes.decode('utf-8', 'replace') | e17e709dba7dacd4ae38c0787dafaef278610074 | 14,520 |
import os
def dir_size(path):
"""Sum all files' size in a directory
Returns
-------
int
The total size of all files in the directory.
"""
return sum(d.stat().st_size for d in os.scandir(path) if d.is_file()) | c82ba8990cb82eb8004f14b518beb6f752796811 | 14,521 |
def _get_updated_display_names(attr_name, new_val, old_val):
"""Get difference between old and new display names data"""
new_links = set()
old_links = set()
for val in new_val:
new_links.add(val.get("display_name", ""))
for val in old_val:
old_links.add(val.get("display_name", ""))
return (
at... | 4dc2c6502758822f4ff9d416c13fcf9f925dfd23 | 14,522 |
def exc_isinstance(exc_info, expected_exception, raise_not_implemented=False):
"""
Simple helper function as an alternative to calling
`~.pytest.ExceptionInfo.errisinstance` which will take into account all
the "causing" exceptions in an exception chain.
Parameters
----------
exc_info : `py... | 7e53dd94b7326faea1fe5accdc60b1b3b003f0af | 14,524 |
def g2c(tensor):
"""
Reshape from groups, channels to groups*channels
"""
if len(tensor.shape) == 5:
b, c, g, h, w = tensor.shape
tensor = tensor.reshape(b, c*g, h, w)
return tensor | 18517b066dfad91c9e8708fb94058b2780ddab9c | 14,525 |
def max_column_width(column):
"""
Max width of a column, looping over all column elements
"""
return column \
.apply(lambda x: len(str(x))) \
.max() | 30dadff91586ed8c270a78aa44ab3fc875ef706e | 14,526 |
from typing import List
def readfile(filename: str) -> List[str]:
"""Wrote by: Nicholas Garth 101227727
Reads file from filename and returns a list of every line of the file
>>> readfile(hi.txt)
['Hi']
"""
infile = open(filename, "r",encoding="UTF-8")
records = []
for line in infile:
... | 5e71dd5b23221e509ee7d7feeff0241e0177298e | 14,527 |
import torch
def collate_dataset(batch, test=False):
"""
Preprocessing for given batch.
It will use for the Torch DataLoader(collate_fn=collate_dataset).
Args:
batch(Torch.Tensor)
return:
List(Torch.Tensor)
"""
drug_batch = []
protein_batch = []
y_batch =... | 9eec71d5fe994bd6bb6742d2eb667ad0dda1bae1 | 14,528 |
def CalculatePlatt(mol):
"""
Calculation of Platt number in a molecule
Parameters:
mol: RDKit molecule object
Returns:
Platt: Platt number
"""
cc = [x.GetBeginAtom().GetDegree() + x.GetEndAtom().GetDegree() - 2 for x in mol.GetBonds()]
return sum(cc) | 4a960308487fea60857a3ed2268efcd5342099d2 | 14,529 |
def remove_trailing_hyphens(s):
"""
:param s:
:return:
"""
arr = s.split('.')
try:
if arr[0][-1] == '-':
arr[0] = arr[0][:-1]
return '.'.join(arr)
else:
return s
except:
return s | 412387e6d916322fdcf3a5fb6e61636cc93dba4b | 14,531 |
def get_cli_kwargs(**kwargs):
"""
Transform Python keyword arguments to CLI keyword arguments
:param kwargs: Keyword arguments
:return: CLI keyword arguments
"""
return ' '.join(
[
f'--{k.replace("_", "-")} {str(v).replace(",", " ")}'
for k, v in kwargs.items()
... | 7357516968952e13d8fe2edf07dc51c3a29e7673 | 14,532 |
def calc_tf_idf(tf_matrix, idf_matrix):
"""
creates dict of doc dict, each doc dict has key:val pais of: word : tf*idf value
:param tf_matrix: returned by calc_tf
:param idf_matrix: returned by calc_idf
:return: dict of dict with word and tf*idf score for each doc in corpus
"""
tf_idf_matrix... | 0e69d66499121f0aad8f2991cabaa6fe643e841a | 14,533 |
def find_active_sites(activeSites, targetName):
"""
Find an active site in a list of AS's given the name
Input: list of active sites, name of target
Output: list of indeces of matched active sites
"""
return [i for i, j in enumerate(activeSites) if j.name==targetName] | 544cc215f378eccc5aaa655482c0b3c03fed8974 | 14,534 |
import math
def sinc(x):
""" Incomplete sine """
if (x == 0):
return 1
else:
pix = math.pi*x
return (math.sin(pix)/pix) | 9f5983fb37ea9c049cc8a77375dc59a9bb78474a | 14,537 |
def friends():
"""
Returns friendships for given player.
Parameters: `key`, `uuid`
Example Response:
```json
{
'success': True,
'records': [
{
'_id': '************************',
'uuidSender': '********************************',
... | 00873cc71183008be186665c306d625a03709176 | 14,538 |
from typing import Dict
def get_email_to_names_table(email_to_names_filename: str) -> Dict[str, str]:
"""Get a mapping of emails to names from the input file.
Args:
email_to_names_filename: Path to file with emails and corresponding
names, where each email-name pair is on a separate line an... | 856ce53a0abee1721b60603c468e5b66a484f7c8 | 14,539 |
def print_tb(traceback, limit=0, file=None):
"""Print up to *limit* stack trace entries from *traceback*. If *limit* is omitted
or ``None``, all entries are printed. If *file* is omitted or ``None``, the
output goes to ``sys.stderr``; otherwise it should be an open file or file-like
object to ... | 5d7fb403676aa7836430c1f6518b081d13c80e2c | 14,540 |
def create_actions_file_msg(second_run: bool):
"""Actions File Message"""
article = "another" if second_run else "an"
return "Do you want to create %s action file?" % article | b3029285ac076049ea150155932044942ea3f5f7 | 14,542 |
import subprocess
def _run_git(cmd):
"""Run git with the given arguments, returning the output."""
p = subprocess.Popen(['git'] + cmd, stdout=subprocess.PIPE)
output, error = p.communicate()
ret_code = p.poll()
if ret_code:
raise subprocess.CalledProcessError(ret_code, 'git')
return ... | b33854f361bbe4e0be7c223e620d6eccdc7e85eb | 14,545 |
def get_list_of(key, ch_groups):
"""
Return a list of values for key in ch_groups[groups]
key (str): a key of the ch_groups[groups] dict
ch_groups (dict): a group-name-indexed dict whose values are
dictionaries of group information (see expand_ch_groups)
Example: get_list_of('system', ch_g... | f5bbc32c836d0de5e9aa2c055d97bacdfc794d0e | 14,546 |
def _middle(values):
"""Lower bound of median, without using numpy (heavy reqs)"""
n = len(values)
is_odd = n % 2
middle_idx = int((n + is_odd) / 2) - 1
return sorted(values)[middle_idx] | 2b3f342c700ecfde20eb7ce41d0d071b8be6e281 | 14,548 |
def multiindex_col_ix(df, col):
"""Get the index into df.index.levels[] corresponding to a given "column
name" in a multiindex."""
return df.index.names.index(col) | b3c8df1e9d0b36e871fbfaece537704ad13ab7f1 | 14,549 |
def get_be_time(encoded_date):
"""
Returns a reversed list.
@param encoded_date: NetworkList encoded time value.
"""
# Divides the provided value into a four sized element.
time_units_hex_le = [encoded_date[inx:inx + 2] for inx in range(0, 16, 2)]
# Reverse the list and the bytes.
... | fe5aa25adb4590a606a5671557ac9876b7b07c5b | 14,551 |
def error(Y, X):
"""
Calculates mean squared error (MSE) of the reconstructed data (X) relative
to the original data (Y). In theory, this number should decrease as the
order of the markov process increases and/or the number of components
involved in the original projection (if used) increases.
... | 16e392f3ee4bece24ff736e47dcb7cae242a1997 | 14,552 |
def normalize_keys(data):
"""Convert keys to lowercase"""
return {k.lower(): v for k, v in data.items()} | b23e2aff374d9413a5c9a63db1fdd955ae7f24a6 | 14,553 |
def accuracy(y_pred, y, tags):
"""
Returns the accuracy of a classifier
"""
o_id = tags.index("O") if "O" in tags else None
correct = ignore = 0
for i, tag_id in enumerate(y):
if y_pred[i] == y[i]:
if tag_id == o_id:
ignore += 1
else:
... | 950108d475220dc7e16e62b873c4a5d7dbff0e97 | 14,554 |
def frac_year(hour, leap_year=False):
"""
This function calculates the fraction of the year.
Parameters
----------
hour : integer, float
The hour of the day. Could be a decimal value.
leap_year : boolean
Indicates if the year is a leap year. Default
is False.
Return... | fe66678278a2257e5b8fc34af042b5a72b29596f | 14,555 |
def int_wrapper(string):
"""A helper function."""
if string.startswith('#$'):
return int(string[2:], base=16)
elif string.startswith('$'):
return int(string[1:], base=16)
return int(string, 0) | 909ed1ab0d3a2f6909ae5fb819e63a4658e7a521 | 14,557 |
def box_calc(size_xyz, pallet_xyz):
"""Calculates a list of points to store parts in a pallet"""
[size_x, size_y, size_z] = size_xyz
[pallet_x, pallet_y, pallet_z] = pallet_xyz
xyz_list = []
for h in range(int(pallet_z)):
for j in range(int(pallet_y)):
for i in range(int(pall... | 0ed2b14e117b1f66be67579136f0f25432367284 | 14,558 |
import argparse
def add_fp16_config_args(parser: argparse.ArgumentParser):
"""Mixed precision arguments."""
group = parser.add_argument_group("fp16", "fp16 configurations")
group.add_argument("--fp16", action="store_true",
help="Run model in fp16 mode.")
return parser | 5827702ac159f8689551328f7282fff6989018da | 14,559 |
def coverage_test(hce_list, nhce_list, conservative=True):
"""
Run the coverage test on employees.
Note: This is assuming we calculate based on 1.410(b)(1)(b).
Source: https://www.law.cornell.edu/cfr/text/26/1.410(b)-2
"""
if conservative:
hce_benefit_percentage = (
len([hc... | d9ee09fdd5232cc280a1a7a1670633eb43235347 | 14,561 |
def function_intercept(intercepted_func, intercepting_func):
"""
Intercepts a method call and calls the supplied intercepting_func with the result of it's call and it's arguments
Example:
def get_event(result_of_real_event_get, *args, **kwargs):
# do work
return result_of_re... | 28cfa1e873500cc9ca87a9c07275683cf41a33ae | 14,562 |
def is_ref(prop):
"""
Returns True if prop is a reference.
"""
return list(prop.keys()) == ['$ref'] | 3c52ba784d3d490cf44a60d5d35b2251b640eeff | 14,563 |
def get_models(ctx_cmip5, var, table, expts, nens):
"""
Get a list of all models for a given variable for each experiment and store them in a dictionary
:param ctx_cmip5: a esgf-pyclient context of all cmip5
:param var: variable to test
:param table: corresponding cmor_table for var... | 34f04c1d65c4c64e4f945a45c2f956477f6a40c5 | 14,564 |
from typing import List
import collections
def molecular_formula_from_symbols(symbols: List[str], order: str = "alphabetical") -> str:
"""
Returns the molecular formula for a list of symbols.
Parameters
----------
symbols: List[str]
List of chemical symbols
order: str, optional
... | 82142bcae734f89c46e9fce854fdf6de080d8fd7 | 14,565 |
def dump(widget, *a, **kw):
"""Dump a TTWidgets WIDGET, showing info about the parent Frame and all child
Label widgets used to represent the compound TTWidgets WIDGET.
See each TTWidget's custom dump method for details.
"""
try:
return widget.dump(*a, **kw)
except AttributeError:
... | cc5c316890317e80c737e98383a7c686b828d435 | 14,566 |
def emission_counts(tokenlists, taglists):
""" Function to find emission counts for each word and their associated POS tag. It returns a dictionary
containing the corpus' emission counts for each token/tag pair. This function specifically caters to files
with the format of the Brown corpus. This fun... | cc1de55a14a906557f8d873bc7def47dcdc52732 | 14,567 |
def is_anonymous_argument(c):
"""Test if one argument is anonymous (unnamed)
In the declaration `void f(int x, int);` the second argument is unnamed
"""
return c.spelling is None or c.spelling == '' | 1b262e4539b89c81dc21eebc585af8a4dfc9d342 | 14,569 |
def unsplit(t):
"""
Make a RI from a split RI(5-tuple).
"""
s = ''
if t[0] is not None:
s += t[0]
s += '://'
if t[1] is not None:
s += t[1]
if t[2] is not None:
s += '/'
s += t[2]
if t[3] is not None:
s += '?'
s += t[3]
if t[4] is not None:
s += '#'
s += t[4]
return s | 4ab5e703f98920522b626dd84d3a41805b46248a | 14,570 |
def find_error_file(view, error_line):
"""Returns the filename that comes just before the given error line region."""
error_files = view.find_by_selector("entity.name.filename.error")
if not error_files:
return None
error_eol = view.line(error_line).end()
for i, file_region in enumerate(error_files):
... | 30c4781d6f04e090bafa4222c28579c3364c835c | 14,571 |
def divide_round_up(a, b):
"""Calculates a / b rounded up to the nearest integer"""
if a % b < b / 2:
return a // b
else:
return (a // b) + 1 | 7ec28dfbe05c006e4e2cad340002a39c9b23f4b9 | 14,572 |
def univcrest():
"""Returns a constant, the University College Crest number (1249 digits long - year of founding)"""
crest = """11111111111111111111111188111111111111111111111111
11111111111111111111881888818811111111111111111111
11111111111111111111118888881111111111111111111111
1111188... | 9c397c666b211fcfd741bc1df49cc9c0726da2e9 | 14,574 |
def get_open_descriptions(get_open, initial_state, current_state):
"""
Get all 'open' descriptions from the current state (if any).
Parameters
----------
get_open: function
Function that gets the drawer or the door which is opened.
initial_state: nd.array
Initial state of the env... | cc4abab0cbfc8cb38db7cb46003ec6e80b1df634 | 14,575 |
def parse_extended_entities(extended_entities_dict):
"""Parse media file URL:s form tweet data
:extended_entities_dict:
:returns: list of media file urls
"""
urls = []
if "media" in extended_entities_dict.keys():
for item in extended_entities_dict["media"]:
# add static i... | 9fc1ccdf57ac236f6fbca219bb74c96026dac0c2 | 14,576 |
def get_cycle_stats(data_list):
"""
Calculates cycle statistics for test run.
Returns min, max, avg cycle count.
"""
cycles = [data[0] for data in data_list]
min_cycles = min(cycles)
max_cycles = max(cycles)
avg_cycles = sum(cycles) / len(cycles)
return min_cycles, max_cycles, avg_cy... | e8fc1a7b3619ed0f9b63995ded217a4037bdf618 | 14,577 |
def LBtoKG(mlb):
"""
Convertie une masse en lb vers kg
note: 1 kg = 2.20462 lb
:param mlb: masse [lb]
:return mkg: masse [kg]
"""
mkg = mlb / 2.20462
return mkg | 41c4a4a38f4f10b8b1a006ef6da8f9d5f76934fc | 14,578 |
import itertools
def expand_alt_section(alt_section, max_expansions=None):
"""Helper function for refilter_ctm."""
spans = [['']]
alt_separator_line = ''
for line in alt_section.strip().split('\n'):
if '<ALT_BEGIN>' in line:
spans.append([''])
elif '<ALT_END>' in line:
... | 77ec3e274d5b435994cce2e9e9c289a09c336cc8 | 14,579 |
def get_value_from_aligned_membuf(buf, valtype):
"""Returns the value held in a __gnu_cxx::__aligned_membuf."""
return buf['_M_storage'].address.cast(valtype.pointer()).dereference() | 09ff1861e1c6c0a5b484be59572ff12cea01878b | 14,580 |
def compute_mask(cpu):
"""
Given a CPU number, return a bitmask that can be used in /proc/irq to set
the processor affinity for an interrupt.
"""
return 1<<cpu | a393c663e5426ecde752aa107c97c7c429aa589a | 14,581 |
def _prefix_linear(s, op, false, true):
"""Apply associative binary operator linearly.
@param s: container
@param op: operator
@param false, true: values if treating `op` as disjunction
"""
if not s:
return false
u = s[0]
for v in s[1:]:
# controlling value ?
if ... | 85f799e826297c8478bb03c2d4dd26643247a9e1 | 14,582 |
def decode_string(val: bytes) -> str:
"""Decodes a possibly null terminated byte sequence to a string using ASCII and strips whitespace."""
return val.partition(b'\x00')[0].decode('ascii').strip() | 1e963040a41ae16ba1bb7750ecf17b5e5cdb680f | 14,584 |
def product_id_attrs(obj):
"""A ``choice_attrs`` function to label each item with its product ID."""
return {"data-product-id": obj.product.id} | 89a710104bdc907fcfecfc6359469986a7649989 | 14,585 |
import re
def bqtk_default_context(request) -> str:
"""Generate unique id by using pytest nodeid.
Args:
request: pytest fixture which provide tests context info.
Returns:
str: unique id matching big query name constraints
"""
invalid_bq_chars = re.compile('([^a-zA-Z0-9_]+)')
... | 5f486f625ae0ff2670dd457a25043ad61193af90 | 14,586 |
def sort_list(this_list):
""" Lamda Function sorts pairs in list by 2nd-part (Shannon Entropy). """
# Sort the domain tuples (Entropy, FQDN) pairs high entropy items.
# Return SORTED LIST
return sorted(this_list, key = lambda pairs: pairs[0]) | 75f4def632b330c392f7a4f4db416262585c432b | 14,587 |
import os
import subprocess
def find_repos(path):
"""
Finds repositories within the given path.
:param path: Path to search for repositories.
:return: List of strings with found repository paths.
"""
try:
with open(os.devnull, 'w') as devnull:
data = subprocess.check_outpu... | 268b19747fe86ee3c9f49d17f8c8178acb0d0fba | 14,588 |
from os import system
from typing import List
def type_checks(paths_to_check: List[str]) -> bool:
"""
Run typing checks using mypy on the supplied list of files
Args:
paths (List[str]): List of paths to check with mypy
Returns:
bool: True if it failed the checks, False otherwise
... | 36db43367ac89af5172c36ac6732ae10bcbad8ae | 14,589 |
def ascii(str):
"""Return a string with all non-ascii characters hex-encoded"""
if type(str) != type(''):
return map(ascii, str)
rv = ''
for c in str:
if c in ('\t', '\n', '\r') or ' ' <= c < chr(0x7f):
rv = rv + c
else:
rv = rv + '\\' + 'x%02.2x' % ord(c)... | 7224579507cc9e0efb0bb1700e2b8b0096422532 | 14,590 |
def right_shift(number, n):
"""
Right shift on 10 base number.
Parameters
----------
number : integer
the number to be shift
n : integer
the number of digit to shift
Returns
-------
shifted number : integer
the number right shifted by n digit
Examples
... | e6d23b5bd630449aba54cb38c2c6d9be174386c0 | 14,591 |
def get_interconnector_index(data) -> list:
"""Get interconnector index"""
return [i['@InterconnectorID'] for i in (data.get('NEMSPDCaseFile')
.get('NemSpdInputs')
.get('PeriodCollection')
... | 9cb2a8a09e98ad308b23d670283d2b358abc9856 | 14,592 |
def check_sched(sched):
"""Parse the YAML for the resulting schedule of a scheduling algorithm.
.. literalinclude:: ../../wikipedia-sched.yaml
:language: yaml
:linenos:
:param task_list: List of sched descriptors, as in the example above.
:type task_list: List of dictionaries.
:re... | 7eb2e00813d38993072ae326da16069b607faea2 | 14,593 |
def binarygap(u):
"""maximal sequence of consecutive zeros
>>> binarygap(6)
1
>>> binarygap(9)
2
>>> binarygap(129)
6
"""
s = format(u, 'b').split('1')
return 0 if len(s) < 3 else len(max(s)) | 3909779446dd500f6d3897c9fabd2628371d8f08 | 14,594 |
import torch
import math
def log_lerp(x: torch.Tensor, b: float):
"""
Linearly extrapolated log for x < b.
"""
assert b > 0
return torch.where(x >= b, x.log(), math.log(b) + (x - b) / b) | c09eef11de46a3bf6905627f619df35e9de6e37f | 14,595 |
import argparse
def parse_args():
""" Parses command line arguments.
"""
parser = argparse.ArgumentParser()
parser.add_argument('--in', dest='inout',
action='store', type=str, required=True, default=True,
help="Stay in? (True/False)")
parser.add_argument('--s', dest='season',
... | 3d91e030efe98093632d03f6f2c4447364ac5a89 | 14,596 |
def fast_multiply(matrix, value):
"""
Fast multiply list on value
:param matrix: List of values
:param value: Multiplier
:return: Multiplied list
"""
for ix in range(0, matrix.shape[0]):
matrix[ix] *= value
return matrix | 8a9eb29b1c6c0cc56b35f43f128e2595b45e1ff6 | 14,598 |
def freeze(x):
"""Freezes a dictionary, i.e. makes it immutable and thus hashable."""
frozen = {}
for k, v in x.items():
if isinstance(v, list):
frozen[k] = tuple(v)
else:
frozen[k] = v
return frozenset(frozen.items()) | fc3bf21419057563f2389ab7e26279bb1f37436b | 14,599 |
def humanize(seconds):
"""
Convert a duration in seconds to an human-readable form
"""
assert type(seconds) is int
if seconds >= 86400:
res = seconds // 86400
return '%s day' % res if res == 1 else '%s days' % res
if seconds >= 3600:
res = seconds // 3600
return '... | 2a32c7b54b1be58ce571910edbf8d5383db66aa2 | 14,600 |
import requests
import json
def getNLP(url = "http://nlp.ailab.lv/api/nlp", data = { "data" : { "text":"change me"}, "steps": ["tokenizer", "morpho", "parser", "ner"], "model": "default", "config": None}, headers = {'content-type': 'application/json'}):
"""Gi... | cb63deaa4a0a98cf6641eae56ad5fb9fd81173ca | 14,601 |
def schema_input_type(schema):
"""Input type from schema
:param schema:
:return: simple/list
"""
if isinstance(schema, list):
return 'list'
return 'simple' | cdcc9b724005083995f26a767d9b2ab95645ad79 | 14,602 |
def integrator_RK(x,step_size,function_system):
"""
Integrate with Runga Kutta
Parameters
x : state
step_size
function_system
"""
k1 = function_system(x)
k2 = function_system(x + step_size * k1 / 2)
k3 = function_system(x + step_size * k2 / 2)
k4 = function_system(x + step_s... | 97380328a9bf1c3e91f161a3a39d7a06c479690c | 14,603 |
def _jwt_decode_handler_with_defaults(token): # pylint: disable=unused-argument
"""
Accepts anything as a token and returns a fake JWT payload with defaults.
"""
return {
'scopes': ['fake:scope'],
'is_restricted': True,
'filters': ['fake:filter'],
} | 9374f03065a8592448ae3984e56bb9cae962059f | 14,604 |
def seconds_to_time(seconds):
"""Return a nicely formatted time given the number of seconds."""
m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
d, h = divmod(h, 24)
return "%d days, %02d hours, %02d minutes, %02d seconds" % (d, h, m, s) | bf87da51527af08f60b3425169af1f696ecc9020 | 14,605 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.