content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def start(update, context):
"""Envia un mensaje cuando se emita el comando /start."""
return update.message.reply_text('Hola, Geeks!') | 540371823768d422d7e7d3a773c5f3a3bfdf8a7b | 75,365 |
import string
def is_printable(bytes_):
"""Test whether a byte sequence is a printable ASCII string."""
return all(chr(b) in string.printable for b in bytes_) | 4237a23513fcfa15cd87c1c47e1a9d3b2f17e120 | 75,366 |
def deep_update(original, update):
"""Update default runconfig dict with user-supplied dict.
Parameters
----------
original : dict
Dict with default options to be updated
update: dict
Dict with user-defined options used to update original/default
Returns
-------
origina... | 8d190334faeb7b8ac0ab3a4b899fc23f13f044ad | 75,368 |
import torch
def batch_index_select(input, dim, index):
"""batch version of ``torch.index_select``.
Returns a new tensor which indexes the input tensor along dimension ``dim``
using the corresponding entries in ``index`` which is a ``LongTensor``.
The returned tensor has the same number of dimension... | 3708aab64f952085a7c43717c38b134a91973f9a | 75,371 |
def get_xr_crs(ds):
"""
Read dataset and get crs from attributes. If attributes don't
exist, thrown an error.
Parameters
----------
ds: xarray dataset, dataarray
A single xarray dataset with variables and x and y dims.
Returns
----------
crs : int
A int containing ... | 0c67f5db7e8ca8493e233bde90ef52d25df65f7d | 75,378 |
def decode_session_payload(payload):
"""
decode a serialized session payload to kwargs
inverse of ``encode_session_payload``
:param payload: dict with encoding compatible with `encode_session_payload`
:returns payload: dict with legacy/readble format.
"""
return {
"managed_dict": pa... | bba54b40f54d334203c840468a1200c270bfbe65 | 75,381 |
def extract_todays_change(string):
"""
Extract number from string following this pattern:
$300(3.00%) -> [300, 3]
-$123(-3.2%) -> [-123, -3.20]
Also will round to 2 decimal places
"""
trimmed = string.strip().replace(" ", "")
strings = trimmed.split("(")
for i in range(len(strings)):... | 730a3f29e8decb5c456ffc841a7628a6119684ca | 75,385 |
def projectLogsFileName(id, config):
"""
Returns the filename of the log zip file created by calling
syscfg.projectLogs(id)
"""
return config['converter.project_logs_name'] % id | 3579ca53525b64bb9ba030a1aa921e3b54792d7e | 75,387 |
from datetime import datetime
def get_hour_from_date_time(ts: datetime) -> float:
"""Returns the hours (in number) of the given time slot"""
return float(ts.hour + ts.minute / 60) | 8c1471a523620bcd2ab38cdf9a08f396d58b7512 | 75,389 |
def get_origin(tp):
"""
Simplified getting of the unsubscripted version of a type. Should be replaced with typing.get_origin from Python >= 3.8
"""
if hasattr(tp, '__origin__'):
return tp.__origin__
return None | 8f070f9d129ed1e26978f77bb51c469e8d870765 | 75,391 |
def _llvm_get_installation_options(repository_ctx):
"""Returns a tuple with build options of the LLVM installation:
whether RTTI and EH are enabled as well as the list of
supported targets.
Implementation notes: the method uses the
"lib/cmake/llvm/LLVMConfig.cmake" file and reads the
... | 09671dc98cd42e3d003401a56bae2cd520f88deb | 75,392 |
def split_link_string(config, link_string):
"""Fields of type 'link' are represented in the CSV file using a structured string,
specifically uri%%title, e.g. "https://www.lib.sfu.ca%%SFU Library Website".
This function takes one of those strings (optionally with a multivalue subdelimiter)
and r... | 97f889b4ac65a0e4549e7e9f6f02b3df8c14bdc0 | 75,396 |
def window_function(u):
"""
params:
- u: an iterable
return:
- 1 if u_i < 1/2 for all i ∈ {1,2, ... , d}, and 0 otherwise
"""
for u_i in u:
if abs(u_i) >= 0.5:
return 0
return 1 | 4dfa6a9220aa1b9262e703a468228cd8354c6497 | 75,402 |
import re
def alphanum_order(triples):
"""
Sort a list of triples by relation name.
Embedded integers are sorted numerically, but otherwise the sorting
is alphabetic.
"""
return sorted(
triples,
key=lambda t: [
int(t) if t.isdigit() else t
for t in re.s... | 5c2843295c92e63d899c6ec330ecd5917147df8f | 75,404 |
import functools
def rgetattr(obj, attr, *args):
"""
Applies a dotted attribute string to given object and returns the value
obj - Python object (ex: 'BankTransaction | ID: 1')
attr - dotted attribute string (ex: 'block.sender')
"""
def _getattr(_obj, _attr):
return getattr(_obj, _at... | 1b9dcad26a135ab836775223eace34db1c1a3edc | 75,406 |
def describe_interval(secs):
"""
Return a string describing the supplied number of seconds in human-readable
time, e.g. "107 hours, 42 minutes".
"""
if secs <= 0:
return 'no time at all'
hours = secs // 3600
minutes = (secs - (hours * 3600)) // 60
parts = []
if hours > 0:
... | fd12f86099b83591cd44a73d6b0185535b48c75d | 75,408 |
def _get_or_set_default_time(d, key, default):
"""
Dictionary helper. If the key is not in the d dictionary or the value is set to -1 it will set the key to default
and return default otherwise returns the value from d.
:param d: dictionary
:param key: key we are interested in
:param default: t... | 703c13e21055471770c97e74591d18c6550c4ef7 | 75,412 |
def read_config_params(item):
"""
Read ints and booleans from config files
Use for user_params and flag_options only
Parameters
----------
item : str
config dictionary item as a string
Return
------
config dictionary item as an int, bool or str
"""
try:
ret... | 11c4104f4c8e4db91f4728bc466ea7accbaa842e | 75,414 |
def question5(ll, m):
""" Find the element in a singly linked list that's m elements from the end """
# get linked list length
if ll.root:
node = ll.root
ll_length = 1
while node.next:
ll_length+=1
node = node.next
else:
return None
# calcula... | f4987d6fe7ac04df19debe62159062d6730ffcf4 | 75,416 |
def bubblesort(arr, randomized_image):
"""
Performs bubblesort on a given list of randomized one-pixel wide
columns of an image in order to remake said image.
Parameters
----------
arr: list
A list of randomized one-pixel wide columns of an image
to perform bubblesort on.
r... | 9948ca5f6649e063f367845c089b1fb752343fea | 75,420 |
def _sparse_ftrs_indices1(ftr_name):
"""Returns the name of the 1st axis indices for `ftr_name`"""
return f"{ftr_name}_indices1" | 6d9cbb3195493e99a9132427b85a3eecda89c442 | 75,421 |
def query_package(module, pkgin_path, name):
"""Search for the package by name.
Possible return values:
* "present" - installed, no upgrade needed
* "outdated" - installed, but can be upgraded
* False - not installed or not found
"""
# Use "pkgin search" to find the package. The regu... | 6ced619284193a58eeb5fb7371b138d9c67b52bf | 75,423 |
import random
def word_dropout(dropout_prob: float) -> bool:
""" Toss a biased coin and return bool if to drop this token"""
if random.random() < dropout_prob:
return True
return False | 6c339aaa58afee13971efc26bda7b6a2bcbb2531 | 75,424 |
def create_legend(axis, text, fontsize='small', legframeon=False,
location='upper right', legncol=1, legshadow=True,
legtitle="", lwd=0.5):
"""
Function to create legends on matplotlib plots.
:param matplotlib.Axis axis: the axis object to associate the legend with.
... | c44955e1d10575e0801624e582b8a02b149d9864 | 75,426 |
import json
def load_dict(path):
"""
Loads a dictionary from a json file
:param path: (str)
:return: (dict)
"""
with open(path, 'r') as file:
return json.load(file) | 2c31d8c9b3c92ef837b11083e0fa3e825674848b | 75,427 |
import logging
def _get_root_handler(name):
""" Get root logger Handler by name
Parameters
----------
name: str
Handler name
Returns
-------
logging.Handler
"""
root_logger = logging.getLogger('')
for handler in root_logger.handlers:
if handler.name == name:... | 10005d6a2094fb399ad0a1688c775925628c27a3 | 75,428 |
import csv
def csv_to_list(csvfile, sep=","):
"""Parses a csv file into a 2d array, ignoring the header"""
with open(csvfile, "r") as f:
lines = list(csv.reader(f, delimiter=sep))
# skip header
return lines[1:] | 5d3066494cd19cf1a7716b4a003a98a3218bcb13 | 75,432 |
def max_headroom_energy_rule(mod, s, tmp):
"""
**Constraint Name**: Stor_Max_Headroom_Energy_Constraint
**Enforced Over**: STOR_OPR_TMPS
Can't provide more reserves (times sustained duration required) than
available energy in storage in that timepoint. Said differently,
must have enough energy ... | b0322b1160dd39faa3b9dc25d9128415d8cd1dc1 | 75,433 |
from datetime import datetime
def get_query(query: str) -> dict:
""" Return a usefull query informatión from the following format
date time headers hexadecimal ip_from host_queried query_class ...
18-May-2021 16:34:13.003 queries: info: client @0x55adcc672cc0 45.231.61.2#80
(pizzaseo.com): query: pi... | d4380e8910645bce7580118c0a21b077ac0b9e5d | 75,434 |
def resize_bbox_list(label_list, img_w, img_h, outp_img_size):
"""
Resizes a list of bboxes to the desired output size. If an image is resized, should also the corresponding bboxes be
resized. The img_w and img_h specify the original image size. Outp_img_size specifies the image size after resizing.
:pa... | 79206ed4b88ed0e64b9be9b90482710747a501dc | 75,437 |
def select_relevant_profiles(all_profiles):
"""Select relevant profiles
criteria:
* is public
* region is selected region
* AGE specified
* GENDER SPECIFIED
"""
public_condition = all_profiles["public"] == 1
age_condition = all_profiles["AGE"] > 14
gender_condition = all_profiles... | 08c4980ec96ac836806f44ea7d4dfb8e09d6265c | 75,440 |
def extract_doi_links(urls):
"""
Try to find a DOI from a given list of URLs.
:param urls: A list of URLs.
:returns: First matching DOI URL, or ``None``.
"""
doi_urls = [url for url in urls if "/doi/" in url]
if len(doi_urls) > 0:
return ("http://dx.doi.org" +
doi_ur... | 2076949fdf96c27e0d80644319d9583811620744 | 75,441 |
def predictor_tiff_decode(stream: bytes, columns: int, colors: int) -> bytes:
"""Decode a stream encoded with the TIFF predictor.
:param stream: The byte sequence to decode
:type stream: bytes
:param columns: Number of columns
:type columns: int
:param colors: Number of bytes for one pixel (ie.... | ff4743c35d8c5bd548fa4086e3201413cb2d2be3 | 75,443 |
import re
def basename(url):
"""
Return the name of the folder that you'd get if you cloned 'url' into the
current working directory.
"""
# It's easy to accidentally have whitespace on the beginning or end of the
# url.
url = url.strip()
url, _sep, _fragment = url.partition('#')
#... | d1feeddde8e9f6a1434ab595e23b4ca2e449ef55 | 75,445 |
def parse_keywords(medline):
"""Parse keywords from article, separated by ;
Parameters
----------
medline: Element
The lxml node pointing to a medline document
Returns
-------
keywords: str
String of concatenated keywords.
"""
keyword_list = medline.find('KeywordLis... | 132ebc6efc2e84abde7d691640a28820c86c5fa7 | 75,446 |
def is_very_long(password):
"""Return True if password is very long."""
return len(password) >= 13 | 7be381aa079c5b70a2fce82143c70b6242a6c5ec | 75,447 |
def strip_regex_metachars(pattern):
"""Strip ^ and $ from pattern begining and end.
According to http://www.w3.org/TR/xmlschema-0/#regexAppendix XMLSchema
expression language does not contain the metacharacters ^ and $.
:returns: stripped pattern string
"""
start = 0
till = len(pattern)
... | 8625d10a9bb2c50e7b84b7ecc394f50625ef882d | 75,448 |
def split_leading_comment(inputstring):
"""Split into leading comment and rest."""
if inputstring.startswith("#"):
comment, rest = inputstring.split("\n", 1)
return comment + "\n", rest
else:
return "", inputstring | d97fe429cd99c3651f3b9465b8f051f4c7670cd2 | 75,449 |
def split_list(listcont, limit, glue='\n'):
"""
Splits a list of items in chunks to be sent in messages
:param listcont: The item list
:param limit: The character limit
:param glue: The string that will join every list item
:return: A list of strings with the items joined given the glue paramete... | ad52d678cf49cc985be60b422a781803a2974eaa | 75,450 |
def contestant_pick_again_same(adjusted_stage, contestant_first_pick):
"""Degenerate case, contestant stays with their initial pick."""
return contestant_first_pick | f2effe83b7c013037705e2c1c5e7f3449ee2cec8 | 75,453 |
def human_time(time_s):
"""
Converts a time in seconds to a string using days, hours, minutes and seconds.
"""
time_s = int(time_s) # Ensure int
out = []
days = time_s // 86400
if days == 1:
out.append("%i day" % days)
time_s -= days * 86400
elif days >= 1:
out... | e9b508d4e5d0d9a07cc643537edf3391408d0c5b | 75,456 |
def compute_promo_lead(df, shift=-1):
"""Compute leading indicator for promo."""
promo_lead = df.groupby("store")["promo"].shift(shift)
return promo_lead.fillna(0) | aa84ccec41229526c633939d55c825e653bca49c | 75,460 |
def normalize_whitespace(text, to_space=u'\u00a0', remove=u'\u200b'):
"""Normalize whitespace in a string, by replacing special spaces by normal
spaces and removing zero-width spaces."""
if not text:
return text
for each in to_space:
text = text.replace(each, ' ')
for each in remove:... | f90193ea01b3505ec7667afafe874f5cc08570d7 | 75,462 |
def get_request_header() -> dict:
"""
Common functionality of forming header for further requests
:return: Header as dictionary
"""
# Sample user agent
user_agent = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0'
headers = {'User-Agent': user_agent}
return... | 4720463f62c18fe38ada9059ed4514c68e4b143c | 75,464 |
def hostportjoin(host, port=None):
"""Join a host and optionally port into a hostinfo-style host:port
string"""
if ':' in host:
host = '[%s]' % host
if port is None:
hostinfo = host
else:
hostinfo = "%s:%d" % (host, port)
return hostinfo | 642d01f49c8e909150c8e34c2bac987745e5878b | 75,466 |
import logging
def _filter_databases(databases, include=None, exclude=None):
"""Filter a list of databases given an inclusion/exclusion list"""
dbs = []
if include is not None:
for db in include:
if db in databases:
dbs.append(db)
else:
msg ... | ce41de929d729fc5269ba911d7450faacb554676 | 75,468 |
def invert_dict(input_dict: dict, sort_keys: bool = False) -> dict:
"""Create a new dictionary swapping keys and values.
Invert a given dictionary, creating a new dictionary where each key is
created from a value of the original dictionary, and its value is the
key that it was associated to in the orig... | 9e10b4f95d71157e0da80b2e4271a8ef9c1c50df | 75,470 |
def DotProduct(v,u):
"""Dot product of two vectors
Returns int
Attributes
----------
v: Vector
First Vector
u: Vector
Second Vector
"""
return v.x*u.x + v.y*u.y + v.z*u.z | 6e27d1d0c2fe5ef05eee9f4cd8f2d72e9cf87a5d | 75,476 |
def n_xx_n_mod_k(n, k):
""" Compute n ** n mod k. """
return pow(n, n, k) | 00235f1b4e1e7636deb67aadeef47a7647d41b1e | 75,479 |
import json
def _serialize_to_json(shell_var):
"""Serializes the python variable into a JSON string.
Args:
shell_var: ipython shell python object.
Returns:
A JSON string.
Raises:
ValueError: When serializing a type other than str, dict, or list.
JSONDecodeError: When unable to encode the va... | 21f609f6009336d63778b92c10d361f9f641a297 | 75,480 |
from datetime import datetime
def get_default_bucket_prefix(cluster_name):
"""Get default keypath to store logs under in an s3 bucket for the given cluster."""
return "{cluster_name}-logs-{timestamp}".format(cluster_name=cluster_name, timestamp=datetime.now().timestamp()) | 37a712b4257be355082c0ca75ba2b8354ff29abe | 75,481 |
def get_line_count(filepath: str) -> int:
"""Returns count of number of lines in the given file"""
num_lines = sum(1 for _ in open(file=filepath, encoding="utf8"))
return num_lines | 21e26382d1165eaba0d0567ac20079e19b7859f0 | 75,483 |
def ordered_uniks(iterable):
"""Unique values of iterable in the order they are encountered in arr
>>> iterable = [4, 2, 6, 1, 2, 2, 7]
>>> ordered_uniks(iterable)
[4, 2, 6, 1, 7]
"""
found = set()
# Note: (found.add(x) is None) is a trick so that it the expression is always evaluated.
r... | bc8b1bc3fca9ce1d15b32582193eb9d2942ca2ce | 75,486 |
import re
def log_lines_match(a_line: str, b_line: str) -> bool:
"""Compares two lines from two git log files to see if they match.
Ignores varying content in the 3 commit header lines.
Arguments:
a_line {str} -- line from a git log
b_line {str} -- line from another git log
Returns:
... | dcb12a9d090de3b4d30bf74db7b9d4eb60501dbf | 75,489 |
def deprecated_custom_evalf_wrapper(func):
"""
This is used while pickling old symbolic functions that define a custom
evalf method.
The protocol for numeric evaluation functions was changed to include a
``parent`` argument instead of ``prec``. This function creates a wrapper
around the old cus... | e0db65809272114a296c3771a6da9f7821c076f4 | 75,495 |
import re
def remove_escapes(word):
"""
Removes escape backslashes that are created by various security mechanisms
Args:
word (str): Word to sanitize
Returns:
Sanitized string
"""
return re.sub(r'\\', '', word) | 4c0d94c9fa12a1e56bf1931981bf6e19fa19bee8 | 75,498 |
import requests
import json
import logging
def get_member_id(token: str, members_api_url: str, site_name: str, **kwargs):
"""
This simple function requests information about local Goodwills, as described in a
secure API managed by GII. The API uses a basic auth flow, in which we use a client key to
r... | cd293e5b7e03026415dc8142ccc6cb61f888b08a | 75,500 |
def AddFactor(endpoint, factor):
"""
Add a factor.
"""
msg = {}
msg['request'] = 'addFactor'
msg['payload'] = factor.dict()
return(endpoint.SendRequest(msg)) | e049000a4ce979b6013afbc90d428f0aab6130ff | 75,501 |
import re
def guess_type_from_name(name):
"""Make an educated guess about the type of a variable based on common naming conventions.
Arguments:
name {str} -- variable name
Returns:
{str} -- string of the builtin type or None if one cannot be found
"""
if re.match("(?:is|has)[A-Z_... | 59d1b5b80e03d73af8ac99935018266efec4e455 | 75,504 |
def parse_value_or_iterable(arg):
"""
If arg is a single value, return it as a string; if an iterable, return a
;-joined string of all values
"""
if str(arg) == arg:
return arg
if type(arg) == int:
return str(arg)
return ";".join(arg) | 16ff8220d431fe88c29051de88615bd8f24b2fc8 | 75,510 |
def fzmatch(haystack, needle, casesensitive=None):
"""Very simple fuzzy match, checks to see if all the characters in needed
are in the haystack in left-to-right order.
The function will attempt to match a space character, if no match is found
space is ignored and moves on to matching the next characte... | eb0077b06447cf4053e049d8f5c916bd4a33eec3 | 75,525 |
def identify_degenerate_nests(nest_spec):
"""
Identify the nests within nest_spec that are degenerate, i.e. those nests
with only a single alternative within the nest.
Parameters
----------
nest_spec : OrderedDict.
Keys are strings that define the name of the nests. Values are lists
... | 5b093ff8a33628b2f26481be12d2d2ca839ace56 | 75,526 |
def count_fq(zz):
""" x is a sorted list with repeats. returns a list of [count,value]
where count is the number of times value is repeated in the list"""
res = []
s = 0
z = list(zz)
z.append(-100000)
for i in range(len(z)-1):
if not z[i] == z[i+1]:
v = [s+1,z[i]]
... | 242274b2722ea657f83c881399c0d2f31560d59b | 75,527 |
import logging
from typing import Counter
def supported(aln):
"""Get only the supported consensus residues in each column.
Meaning:
- Omit majority-gap columns
- Omit columns where no residue type appears more than once
- In case of a tie, return all the top-scoring residue types
(no priori... | ed976b04383d616e73254b50b9b1db9dfa398daa | 75,529 |
def get_value_from_settings_with_default_int(wf, value, default_value):
"""Returns either a value as set in the settings file or a default as specified by caller"""
try:
ret = wf.settings[value]['value']
return int(ret)
except KeyError:
return default_value | 72364be43499aad50f1ecaeef558013b11fb3428 | 75,538 |
import requests
def fetch_problem_graphql(hostname, title_slug):
"""
Fetch problem properties via LeetCode GraphQL endpoint.
:param hostname: hostname of LeetCode site
:type hostname: str
:param title_slug: Problem name in lower snake_case.
:type title_slug: str
"""
req_json = {
... | d86e1d10eacf003575c8c2dd5a361a47cbe2d9c6 | 75,542 |
def EasterDate(year):
"""EASTER DATE CALCULATION FOR YEARS 1583 TO 4099
This algorithm is an arithmetic interpretation of the 3 step
Easter Dating Method developed by Ron Mallen 1985, as a vast
improvement on the method described in the Common Prayer Book
from: https://www.assa.org.au/ed... | d4d6989638691f85c3daa858e4c04b189a2e581f | 75,545 |
from typing import List
def largest_common_subsequence(sequence_1: List[int], sequence_2:List[int]) -> int:
"""
For two p-sequences of numbers it returns the length of the largest common subsequence.
If there is no common subsequence, it returns 0.
Note: a subsequence is not a substring.
For sequ... | 6e262e510d507f5907a82641bbbfbc9db98233b7 | 75,547 |
def _TransformOperationState(metadata):
"""Extract operation state from metadata."""
if 'status' in metadata:
return metadata['status']['state']
elif 'state' in metadata:
return metadata['state']
return '' | 2f3842735d25babb111c6308cd9d447ef778f3a1 | 75,558 |
def escape_binary(message):
"""
Escape the binary message using the process described in the GDB server
protocol documentation.
Most bytes are sent through as-is, but $, #, and { are escaped by writing
a { followed by the original byte mod 0x20.
"""
out = ""
for c in message:
d ... | 607fd9d7ca4bc624719e5c96f389fa68af6c338c | 75,560 |
import ast
def _get_expr_string(expr: ast.expr) -> str:
"""
Builds a string based on traversing `ast.Attribute` and `ast.Name` expressions.
Args:
expr: Expression node of the the AST tree. Only handles `ast.Attribute` and `ast.Name` expressions.
Returns:
String based on the expressio... | 5152a791261cda23fd21787dfdf5f1f483321a80 | 75,571 |
import json
def get_response_package(response_info: object) -> object:
"""Generates a response package in line with API Gateway requirements.
Args:
response_info: a json object containing any custom information.
Returns:
A package in the format specified by API Gateway return requirement... | b3cba0bc75edf9c1aec38b1fc5060a20f37e8a1f | 75,575 |
from typing import Counter
def to_hist(phoneme_list):
"""
Takes a list of all phonemes in a corpus and constructs a histogram from it.
:param phoneme_list: a list of all phonemes
:return: labels, hist, ticks
where labels is an ordered sequence of the phoneme labels (x-axis)
where hist... | 1a54be0487cc6fb1856d6ebff098d1153adbb540 | 75,577 |
def remove2(str_lst: list, sub: str) -> tuple:
"""Write a function that accepts a list of strings and another string that removes that string from the list
without list iteration or list methods (aka only string methods).
It should return a tuple with the updated string, number of deletions, and the indexes of the ... | 5e181706d398d6db93d76e625aa2ab710072e175 | 75,585 |
def nmea_checksum(data: str) -> str:
"""
Return calculated NMEA checksum.
"""
check_sum: int = 0
for char in data:
num = bytearray(char, encoding='utf-8')[0]
# XOR operation.
check_sum = (check_sum ^ num)
# Returns only hex digits string without leading 0x.
hex_str: s... | 60eafcd37470df182b614a56a14be947a6ddbcc0 | 75,586 |
def find_nb_for_cna(nb_wraps, client_adpt, vswitch_map):
"""Determines the NetworkBridge (if any) supporting a client adapter.
:param nb_wraps: The network bridge wrappers on the system.
:param client_adpt: The client adapter wrapper.
:param vswitch_map: Maps the vSwitch IDs to URIs.
... | ededc51c02fd90f3439193159015bce1fbd000d9 | 75,593 |
import pickle
def _read_python_plot_info(filename):
"""
Read the information required for a python plot for the given filename. The data for this are assumed to be in:
./data/results/filename_mse.p, ./data/results/filename_mse_test.p, ./data/results/filename_correct_results.p and
./data/results/filen... | 75d970385bc92ab4d874832b72f442608677f57f | 75,595 |
def allocation_num(number_of_bytes: int, partitions: int) -> list[str]:
"""
Divide a number of bytes into x partitions.
:param number_of_bytes: the total of bytes.
:param partitions: the number of partition need to be allocated.
:return: list of bytes to be assigned to each worker thread
>>> al... | d84a100fa1b8a46884ca8523ba9d0b7b8586da68 | 75,598 |
def dot_product(a, b):
"""Computes dot product between two vectors writen as tuples or lists"""
return sum(ai * bj for ai, bj in zip(a, b)) | 25006a536afcf28c8b4676bf6b3c48fec90a60b3 | 75,601 |
def remove_single_lines(text):
"""
Replaces single line breaks with spaces. Double line breaks
are kept as they are. If the text param is None, it is substituted with
an empty string.
"""
# To make line sizes a bit easier to handle, we remove single line breaks
# and replace them with a spac... | 42c88deafddee4954050e58d8f89a972a9d5941b | 75,603 |
def transform_int(val, base=None, mode=None):
"""
Transform to an int with optional base notation
<dotted>|int int(val)
<dotted>|int:<base> int(val, base=<base>)
<dotted>|int::force int(val) or raises
"""
try:
return int(val, base=base or 10... | 12049cc0ef95cf422b33a84deb49271a00ec20d5 | 75,604 |
import torch
def check_accuracy(
loader, model, input_shape=None, toggle_eval=True, print_accuracy=True
):
"""
Checks accuracy of a PyTorch model on a dataloader. It assumes the model
input is same as data input shape but will reshape if you specify a input_shape.
It will set the data to the same ... | e8142bee5c5f32a8010410c0eb2f819f9f187af4 | 75,605 |
def bool_conv(x):
"""bool_conv(x: str) -> bool
Converts a string to boolean.
"""
s = str(x).upper()
if s == 'TRUE':
return True
if s == 'FALSE':
return False | 79cbffae86f5925dc928f6e873b125798f6de3cb | 75,607 |
def depthpredicate(maxdepth):
"""Create a predicate that only descends the tree to a maximum depth.
"""
def predicate(it):
return it.repLength < maxdepth
return predicate | d77332fe99c2c6ce2fd5911f612202257ee9d0d2 | 75,609 |
def bbox_from_bbr(bbox_XYWH, rescale=1.2, detection_thresh=0.2, imageHeight= None):
#bbr: (minX, minY, width, height)
"""Get center and scale for bounding box from openpose detections."""
center = bbox_XYWH[:2] + 0.5 * bbox_XYWH[2:]
bbox_size = max(bbox_XYWH[2:])
# adjust bounding box tightness
... | ad0cbb8c8be08da18ef5a5e15e6be2005ae02400 | 75,611 |
def make_footer() -> str:
"""Makes a footer to be appended to the bottom of other, actionable
responses.
"""
return (
"To make your next move, respond to Chess Bot with\n\n"
"```do <your move>```\n\n"
"*Remember to @-mention Chess Bot at the beginning of your "
"response.... | 26fc865fbab9bda2bd3094324aa5a1ba9a38f15b | 75,617 |
def init_mat(li, co):
""" initialise la matrice li x co avec des zéro
:param li:
:param co:
:return: matrices de 0
"""
return [[0 for i in range(co)] for j in range(li)] | a3043560c858d0ca11e54c427f19d03f501fa76a | 75,622 |
from pathlib import Path
import yaml
def yaml_to_dict(filepath):
"""Get a dictionary from a yaml file.
:param str filepath: the file path to the yaml file.
:return: dictionary representation of the yaml file.
:rtype: dict
"""
with Path(filepath).open('r') as f:
return yaml.safe_load... | 411435694fd8bc2f107decace982a46854d5b437 | 75,625 |
def sparsifyElementMatrix(K,numbering1,numbering2=None):
"""Convert the element stiffness matrix into COO format for assembling."""
if numbering2 is None: numbering2=numbering1
IArray=[]
JArray=[]
VArray=[]
for i in range(2*len(numbering1)):
for j in range(2*len(numbering2)):
... | 765922e444ccbbb6cdb40075a52b0aa990f3a7b6 | 75,630 |
def parse_number(string):
"""
Retrieve a number from the string.
Parameters
----------
string : str
the string to parse
Returns
-------
number : float
the number contained in the string
"""
num_str = string.split(None, 1)[0]
number = float(num_str)
... | 67fc6f4f2d6ab6e99578bdc0906bbb7328d0fdb2 | 75,633 |
from typing import List
def create_kdist_data(knn_distances: List[float]):
"""Get kdist data that can be plotted to determine EPS param for DBScan algorithm.
Args:
knn_distances: A sorted list of knn distances.
Returns:
kdist data.
"""
data = []
for i, distance in enumerate(... | 0664aabe682be0df0379d4dc860b203522c65f19 | 75,639 |
def is_seemingly_identical(stripped: str, original: str) -> bool:
""" Determine whether a stripped text has the same line count and
number of characters as the original text.
"""
return (len(stripped) == len(original)
and stripped.count('\n') == original.count('\n')) | c5040c23639349be6cd968a2be64d90df0a6decc | 75,641 |
def length_limits_filter(trail, minlen=2, maxlen=10000):
""" Filter out shorter trails
"""
return trail if minlen < len(trail) < maxlen else None | b30ddf85de67b6a16a56fbb6d77c600336aa25a4 | 75,642 |
def get_signals_dict_from_db(dbc_db):
"""
Get dictionary of signals from db where keys are signal names.
Parameters
----------
dbc_db : cantools.db.Database
The dbc database which contains the messages and signals.
Returns
-------
signals : :obj:`dict` of cantools.database.can.... | 1d18e3de8ca1d0b9ed68f78216e187560695547f | 75,645 |
def overlapping_windows(sequence, L):
"""
Returns overlapping windows of size `L` from sequence `sequence`
:param sequence: the nucleotide or protein sequence to scan over
:param L: the length of the windows to yield
"""
windows = []
for index, residue in enumerate(sequence):
if (in... | feac35e08423551a26e76d3290cd53f5f0a1da11 | 75,651 |
def combine_extractor_and_dimension_name(extractor, dim):
"""Joins the duckling extractor name with a dimension's name."""
return "{} ({})".format(extractor, dim) | 0fd1ecd43b68876121ea65627340876b8bab5851 | 75,653 |
def parse_cfg_bool(value: str):
"""
Parse a string config option into a boolean
This method ignores capitalisation
:param value: the string to be parsed
"""
return value.lower() == "true" | e2a44591ca1d5a2e0f19c22e30393b494efd74d7 | 75,655 |
def _gate_sequence_product_with_expansion(U_list, left_to_right=True):
"""
Calculate the overall unitary matrix for a given list of unitary operations.
Parameters
----------
U_list : list
List of gates(unitaries) implementing the quantum circuit.
left_to_right : Boolean
Check i... | 45038b9e9a09924dfc0cbee4d5605160f3d862b9 | 75,660 |
def split_list(sequence, nb_splits):
""" Split l in n_split. It can return unevenly sized chunks.
Parameters:
sequence: iterable
Iterable object to be split in `nb_splits`.
nb_splits: int
Number of splits.
Returns:
iterable
`sequence` splits in `nb_splits`.
.. c... | 3443dcd1e007d244f2e1d4cb7a923409c4f4d06b | 75,662 |
from typing import Any
from typing import get_origin
from typing import Union
def _is_union(t: Any) -> bool:
"""Determine if this type is defined as a Union[...] type."""
return get_origin(t) is Union | ec5e87903aff6ee1ebf1eb22a74384d27e3f9147 | 75,663 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.