content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def augmentCrlStatus(msg):
"""Augment CRL message with status of ``COMPLETE`` or ``INCOMPLETE``.
Check the CRL message for completeness.
Will add a ``status`` field to the message with a value of
``COMPLETE`` or ``INCOMPLETE``.
``COMPLETE`` messages meet the following criteria:
- Doesn't hav... | bd35db88259f2b4e1dad08a98973ef5413829542 | 21,666 |
def check_if_hits(row, column, fleet):
"""
This method checks if the shot of the human player at the square represented by row and column
hits any of the ships of fleet.
:param row: int
:param column: int
:param fleet: list
:returns result: bool - True if so and False otherwise
"""
r... | 2f62285d68c190b63a0934698cc209a59f15d445 | 21,668 |
def get_codon_dictionary(codon_dictionary, string):
""" Returns a dictionary with codon as key and its frequency as value """
# iterates on every 3th item; remove remainders by: len(string) - len(string) % 3
for i in range(0, len(string) - len(string) % 3, 3):
codon = "{first}{second}{third}".f... | 32301f29b580d04f967d3714fae762b680c6049e | 21,672 |
def concat_fm(fm):
"""
Concatenates Directional feature maps as shown in original paper.
This function is used for visualization purposes only.
:param fm: 12 ltrp feature maps
:return: list of 4 concatenated feature maps
"""
d1 = fm[0]+fm[1]+fm[2]
d2 = fm[3]+fm[4]+fm[5]
d3 = fm[6]+... | bb6d6b1f9c6d0441be78e1b04d31e1eb24a6ce28 | 21,676 |
def _bound(color_component: float, minimum: float=0,
maximum: float=255) -> float:
"""
Bound the given color component value between the given min and max values.
The minimum and maximum values will be included in the valid output.
i.e. Given a color_component of 0 and a minimum of 10, the r... | 15f335051d228069e7ca0be3c0768e99b009b3e6 | 21,677 |
def orange(text):
""" Return this text formatted orange (olive) """
return '\x0307%s\x03' % text | aff6e5495b8e9c8f8b763539c6d9308236e313fe | 21,678 |
def position(table, _seat, postflop=False):
""" Returns how many seats from the button the seat is. """
# Raise an exception if the button is not set
if postflop:
seats = table.get_players(hascards=True)
else:
seats = table.get_players()
return len(seats) - seats.index(_seat) - 1 | 253b7685a42db9c4b344f8492fdd9710c8f24585 | 21,681 |
def fact(number):
"""
Calculating the factorial of a number
"""
result = 1
for number in range(1, number + 1):
result *= number
return result | 59f766f57ca71c487b640cd6d08841884657c8fd | 21,692 |
import random
def one_run(wr: float, fr: float, ranks: dict, start_rank: int, end_rank: int,
max_battles: int) -> int:
"""
Simulate battles required to complete ranked season.
:param wr: win rate
:param fr: first place rate
:param ranks: information on stars in each rank
:param st... | fb655a374696430d80668ae79423b7400cfc94c8 | 21,696 |
def _shift_parts(family_parts, subfamily_parts, stop_fn):
"""Iterate over subfamily parts, removing from
subfamily and appending to family, until stop_fn(part)
returns true. If subfamily_parts is empty, add
'Regular'. This works because for both original and
wws subfamilies the order of parts is such that a... | 29c45bcaf667e42d5edf1602302649fb58661359 | 21,701 |
from typing import Dict
import gzip
def read_fasta(filename: str) -> Dict[str, str]:
"""
Reads a file containing multiple FASTA sequences and returns a dictionary of the header: sequence
:param str filename: should be the name of the open file to be read
:return: dict containing the header: the sequen... | 2e14ec124ec0a9c3273fe8f6d3d23da0a7da9b2a | 21,702 |
def char_replacement(list_smiles):
"""
Replace the double characters into single character in a list of SMILES string.
Parameters
----------
list_smiles: list
list of SMILES string describing a compound.
Returns
-------
list
list of SMILES with character replacement.
... | b0a7e2a09cb966b826ee1cb9cf5afa734a2d2ed1 | 21,704 |
def _edge_match(edge_a_attr, edge_b_attr):
"""
Compares attributes of the edges for equality.
:param edge_a_attr: Attributes of first edge.
:param edge_b_attr: Attributes of second edge.
:return: True is equal - otherwise False
"""
if edge_a_attr == edge_b_attr:
return True
retu... | 0afa7dd6402f1c954753c27e0ab4244740eb5ffe | 21,708 |
from typing import List
def _encode_strings(strings: List[str]) -> List[bytes]:
"""
Encodes a list of strings as bytes
Parameters
----------
strings : list
List of any-codification strings
Returns
-------
strings: list
List of ASCII encoded bytes
"""
return [... | 58e4aafa7aca4a65f1d62fde37023f7f1a638b33 | 21,710 |
def box_sizing(keyword):
"""Validation for the ``box-sizing`` property from css3-ui"""
return keyword in ('padding-box', 'border-box', 'content-box') | 42666cee49ba77d3089633a923872d2064e8f080 | 21,711 |
import random
def RANDBETWEEN(low, high):
"""
Returns a uniformly random integer between two values, inclusive.
"""
return random.randrange(low, high + 1) | 6382801f41af2b05304b7fbf1c8d22b6f10b90a8 | 21,712 |
import re
def unindent(value):
"""Remove indentation from string."""
return re.sub("\n +", "\n", value) | f455d1d7b24d708e73a0307af6ee333cfffe91f2 | 21,713 |
from typing import List
from typing import Tuple
def bono_tasa_fija(
start_time: float,
yf: float,
num_cupones: int,
valor_tasa: float) -> List[Tuple[float, float]]:
"""
Retorna los plazos y flujos de un bono a tasa fija bullet con nominal = 1.
params:
- start_time: fecha (ex... | a3d792762458b7b30facf7ead74e2899e545425f | 21,716 |
from datetime import datetime
def find_todays_file(dir_list=None):
"""Identifies filename of most recent Sierra report"""
fhdate = datetime.strftime(datetime.now(), '%Y%m%d')
if dir_list is not None:
# grab the latest file with date
for fh in sorted(dir_list, reverse=True):
if ... | 789040c743375bc85c5ac2f8eaed4fec11c46158 | 21,718 |
def format_location(text):
"""Replace all the spaces with plus signs."""
return text.replace(' ', '+') | e95002ae4b385e346628cf363f27b4db2475465d | 21,721 |
def url_remove_user_pwd(url):
"""
Given a URL, remove the username and password if any::
print(url_remove_user_pwd("https://user:password@host:port/path"))
https://host:port/path
"""
_url = url.scheme + "://" + url.hostname
if url.port:
_url += ":%d" % url.port
if url.path:
... | 0713a0973e6fac666198462145eab3d15179b6e0 | 21,728 |
def _remove_unwanted(args):
"""
Lower cases tokens and removes numbers and possibly names.
Parameters
----------
args : list of tuples
The following arguments zipped.
text : list
The text to clean.
words_to_ignore : str or list
Strings that ... | 3031b24e4581adf3ed701c999e995e2779e48cf2 | 21,733 |
def merge_none(a, b):
"""
Compare two sequences elementwise and merge them discarding None entries.
Raises ValueError exception if the two sequances do not have the same
length or if they have different non-None elements.
Parameters
----------
a, b : sequences
The sequences to be c... | e25747cb2c8aeaa647ed9f3b19fbf311a7b0b701 | 21,738 |
def _identifier_split(identifier):
"""Return (name, start, end) string tuple from an identifier (PRIVATE)."""
id, loc, strand = identifier.split(":")
start, end = map(int, loc.split("-"))
start -= 1
return id, start, end, strand | 9fa8f1850fe628b7a26c5813b6d738e72c0d7ae5 | 21,741 |
import re
import time
import requests
def check(url, regexp=None):
"""
Make a get request to a given url and return some metrics about the request.
If the regexp parameter is present,
check if this regular expression is present within the page returned by the request.
:param url: url to be check... | 879069e2763e3be793e77bdcc540005adcec1435 | 21,750 |
def partition(arr, low, high):
""" Partition is a helper function for the quicksort. It takes a pivot and
places lower values to the left and higher values to the right
"""
i = (low-1)
pivot = arr[high]
for j in range(low, high):
if arr[j] <= pivot:
i = i+1
arr[i... | 1bacd1c407542087bd161253e129f4fff098f05d | 21,762 |
def deep_update_dict(origin_dict, override_dict):
""" update origin dict with override dict recursively
e.g. origin_dict = {'a': 1, 'b': {'c': 2, 'd': 4}}
override_dict = {'b': {'c': 3}}
return: {'a': 1, 'b': {'c': 3, 'd': 4}}
"""
for key, val in override_dict.items():
if isinstance... | 09c0f8bb1656aef387a4a8a96f756a520d1dc23d | 21,766 |
def get_coordinates_from_kml(coordinates):
"""Returns list of tuples of coordinates.
Args:
coordinates: coordinates element from KML.
"""
if coordinates:
return [tuple(float(x.strip()) for x in c.split(',')) for c in str(coordinates[0]).split(' ') if c.strip()] | 921741e0e157a7d635f59cf75800fb32fcdd4ba2 | 21,769 |
def isArray(v, N=None):
"""Check if v is an array or a vector, with optional size.
Examples
--------
>>> import pygimli as pg
>>> print(pg.isArray([0, 1]))
True
>>> print(pg.isArray(np.array(5)))
True
>>> print(pg.isArray(pg.Vector(5)))
True
>>> print(pg.isArray(pg.Vector(5)... | 32b05b6810a9cfc2d97fbfcfdbdc2da0c1b47104 | 21,770 |
def filter_collections_exist(hsp, collection_names):
"""
Filters a list of collections to return only those that do exist
"""
filtered = []
for entry in hsp.collections.apiget('list'):
if entry['name'] in collection_names:
filtered.append(entry['name'])
return filtered | 54122ca77d6cb4acd5bd1492d1dcd15d6406c1a7 | 21,773 |
def anagram_solution_1(s1, s2):
"""
解法一:冒泡检查
检查第一个字符串是不是出现在第二个字符串中,如果可以检验到每一个字符,
那这两个字符串一定是乱序。
可以通过用 None 替换字符来了解一个字符是否完成检查。
但是,由于 Python 字符串是不可变的,所以第一步是将第二个字符串转换为列表。
检查第一个字符串中的每个字符是否存在于第二个列表中,如果存在,替换成 None。
T = O(n^2)
"""
if len(s1) != len(s2):
return False
alis... | e45ba0e0607c57a9b21ca1dd59a86b98dcac6f89 | 21,776 |
def has_argument(command: str) -> bool:
"""
Check if command has an argument.
This is helper function for process_command
:param command: an alphabetic string
:precondition: command must be an alphabetic string and part of the list returned by get_command_list
:postcondition: returns True if c... | 50bc475fa910ab0637f19bb07819fcc4fb78e325 | 21,780 |
from datetime import datetime
def convert_date(timestamp):
"""Converts API timestamp to publication-ready dateline"""
day = timestamp[5:7]
month = datetime.strptime(timestamp[8:11], '%b').strftime('%B')
year = timestamp[12:16]
date = month + ' ' + day + ", " + year
return date | 661e91a9c037d65db7ea9621bb47e0230a833c31 | 21,782 |
def _check_before_comment(commented_map, key_to_check, first=False):
"""Check if commented_map has a comment before key_to_check or not.
All our default comments are before a key, so we just check for that.
:param commented_map:
:type commented_map: ruamel.yaml.comments.CommentedMap
:param key_to_... | 92997028120026e3ae604704510c082f9b201543 | 21,783 |
import re
def is_comment(line):
"""Determines if a string is entirely a fortran comment."""
return bool(re.match('\A\s*!', line)) | 942bf9b780f7c890c75a18aac0a4380d96825c04 | 21,789 |
def header(table):
"""
Return the header row for the given table. E.g.::
>>> from petl import header
>>> table = [['foo', 'bar'], ['a', 1], ['b', 2]]
>>> header(table)
['foo', 'bar']
See also :func:`fieldnames`.
"""
it = iter(table)
return ... | c4e772b40cdda2ffcbaf383dc4787f2e146a97e1 | 21,791 |
import six
import base64
def is_base64(s):
"""
is_base64 tests whether a string is valid base64 by testing that it round-trips accurately.
This is required because python 2.7 does not have a Validate option to the decoder.
"""
try:
s = six.ensure_binary(s, "utf-8")
return base64.b6... | 8c869fd96217e70dd896d8309719d3b0c754c388 | 21,793 |
def _n2(a, b):
"""Return (a - b).evalf(2) if a and b are comparable, else None.
This should only be used when a and b are already sympified.
"""
# /!\ it is very important (see issue 8245) not to
# use a re-evaluated number in the calculation of dif
if a.is_comparable and b.is_comparable:
... | bb1c3ebcea8af5ddf248bd90ef9810093840bbcf | 21,795 |
def create_non_dupe(base_name: str, opt_num: int, comparison) -> str:
"""Makes sure base_name is not in comparison, and if it is it's renamed.
:param base_name: Name to check/make unique.
:param opt_num: Number of the option base_name belongs to, used in making it unique.
:param comparison: Dictionary ... | cb12092838d6e0482f28b7b00682a3390fcac790 | 21,797 |
def get_min_value_from_matrix(matrix_filename):
"""
Returns the minimum value of a matrix file
:param matrix_filename: str
:rtype: float
"""
matrix = []
with open(matrix_filename) as file:
for line in file:
matrix.extend([float(val) for val in line.rstrip().split()])
... | 69413010834b4e4fb903e164e41677619ac88bb3 | 21,799 |
def interpret_instruction(instruction, parameter):
""" Interprets an instruction and returns offset to next command and accumulator value.
:param instruction: acc, jmp or nop
:param parameter: signed integer
:return: (jump_offset, accumulator_offset)
"""
if instruction == 'acc':
return ... | 4f1b0ba7b1d92256e299a3f2dab9eb6c42a5314b | 21,800 |
import re
def _contains_expression(repr_str: str) -> bool:
"""
Checks whether or not a `repr_str` contains an expression. (Single unary expressions are excluded)
"""
repr_str = re.sub(r"\s+", "", repr_str)
repr_str = repr_str.replace("(", "")
repr_str = repr_str.replace(")", "")
symbols =... | af758c8874d22ea1cfa25bb73c7605ed5e4d2d75 | 21,801 |
def issafe(arg):
"""Returns False if arg contains ';' or '|'."""
return arg.find(';') == -1 and arg.find('|') == -1 | f6746d5290e21eb84d7343792d277bce4c1871ff | 21,804 |
def _bisect_blocks(web3, timestamp, use_left_bound=True):
"""
Perform a binary search on the blockchain for the block that matches the
given timestamp. The `use_left_bound` parameter determines whether to
return the block to the left or right of the timestamp in the event that no
block matches the ... | 9eb011ca488b7262e78efd29fe11f3c0136a5933 | 21,809 |
def chunks(l, n):
"""
Successive n-sized chunks from l.
"""
res = []
for i in range(0, len(l), n):
assert len(l[i:i + n]) == n
res += [l[i:i + n]]
return res | 148467d681e545487ea1a52c3b4d548726c77f6c | 21,815 |
def update_max_speed(driver, speed):
"""
Updates the max speed of the driver
:param driver: driver
:param speed: new max speed
:type driver: DriverProfile
:return: updated driver profile
"""
return driver.update_max_speed(speed) | 73987703b584099538d865dde9d7d25f48080283 | 21,817 |
import torch
def evaluate_nll(confidences: torch.Tensor,
true_labels: torch.Tensor) -> float:
"""
Args:
confidences (Tensor): a tensor of shape [N, K] of predicted confidences.
true_labels (Tensor): a tensor of shape [N,] of ground truth labels.
Returns:
nll (... | d1c5aa5d69e788ee835d8b94b6dd9d6895656e53 | 21,831 |
def train_test_column_split(x, y, df_column):
"""Function for splitting dataset into train/test partitions w.r.t. a column (pd.Series).
Args:
x (pd.DataFrame): DataFrame containing predictors.
y (pd.DataFrame): DataFrame containing target variable.
df_column (pd.Series): Series for trai... | a28b536be57e04870ae9e6f1e1abc854838e24ae | 21,833 |
def triplo(n=0):
"""
-> Calcula o triplo de um número
:param n: número
:return: triplo do número
"""
return n * 3 | e612051944215b2491958005cadaac9eff5ba3b6 | 21,835 |
def calculateXVertice(termA, termB):
"""
Calculates the value of the vertice X.
"""
vertice = ((-termB)/(2*termA))
return vertice | aafeb34baad2c5361ad6f1c49088984708cdffee | 21,838 |
def _search(left, right, predicate):
"""Simple binary search that uses the ``predicate`` function to determine direction of search"""
if right >= left:
mid = left + (right - left) // 2
res = predicate(mid)
if res == 0:
return mid
elif res > 1:
return _s... | 80a8ae96468fa4a13e42dc5b45920123c1eb8833 | 21,841 |
def getPadding(sField, cchWidth):
""" Returns space padding for the given field string. """
if len(sField) < cchWidth:
return ' ' * (cchWidth - len(sField));
return ''; | 895d3cde1daf0045cb434cc2fcdef6c9ca8808ff | 21,843 |
def get_data_file_path_list(data_file_list_path):
"""Get mappting of video id to sensor data files.
video id to (original video id, [file 1, ..., file n])
where file 1, ..., file n are one series data.
Note.
- Original video id in input files sometimes mixed lower and upper case.
- To treat se... | 7655c27105b1ce051bf1942655daabc2dfce9bd0 | 21,851 |
def snake_case_to_pascal_case(input_string):
"""
Converts the input string from snake_case to PascalCase
:param input_string: (str) a snake_case string
:return: (str) a PascalCase string
"""
input_list = input_string.split('_')
input_list = [i.capitalize() for i in input_list]
output = '... | 6c6344fb052dc6c1a712b838d58266ce8ea9b5c0 | 21,854 |
import socket
def check_port(ip, port, timeout=None):
"""
Checks if the port is open on a specific IP
@param ip: IP of the remote host
@param port: The port to check
@param timeout: Timeout, in seconds
@return bool: True if the port is open, False if closed
"""
so... | 43a4696ca002f96e9b6c28d67326dd4c0c285e5e | 21,860 |
def make_collision_handler(collider, maplayer):
"""Returns ``f = collider.collide_map(maplayer, ...)``
Returns:
f : ``(last, new, vx, vy)`` -> ``(vx, vy)``
Utility function to create a collision handler by combining
Arguments:
maplayer : tells the objects to collide with.
collid... | df59b7eb4b74fe803f1b13fcac7dabc29e06a62b | 21,862 |
def conv_out_shape(in_shape, layers):
"""
Calculates output shape of input_shape going through a list of pytorch convolutional layers
in_shape: (H, W)
layers: list of convolution layers
"""
shape = in_shape
for layer in layers:
h_out = ((shape[0] + 2*layer.padding[0] - layer.dilation... | b75fb479f47304be03aef20a36583ad8a2edc0de | 21,870 |
import collections
import json
def load_json(files):
"""Load all json files as a list of dictionaries"""
config = []
for file in files:
with open(file, 'r') as data_file:
config.append(collections.OrderedDict(json.load(data_file)))
return config | 63174b3fd1ce208a347c6cf7b4904873a97e7136 | 21,871 |
from datetime import datetime
def print_start_time(message: str) -> datetime:
"""Print start time.
Args:
message (str): Message to print.
Returns:
start (datetime): Start time.
"""
start = datetime.now()
print(f'{message} {start}')
return start | a8f7f07da5c72bea88cf8e48a8d3f651a7662e0e | 21,875 |
def ispalindrome(s):
"""
Returns true if s is a palindrome
There are two ways to define a palindrome:
1. s is a palindrome if it reads the same backward
and forward.
2. s is a palindrome if either
(1) its length is <= 1 OR
(2) its first and last chars are the same a... | 5ad5aaef785be935ab6494cf0a1653a265b680ab | 21,887 |
def prefer_insertions_at_309_and_315(mb):
"""Prefer alternatives that include 309.1C or 315.1C over others.
There are two multi-C runs at the beginning of the 300's and by
convention, any insert in one of those runs is pushed to the end.
Mostly, the other rules will pick these, but in some circumstance... | 92152d8de90617ce4a21da680bd34e96d7df98cc | 21,896 |
def get_patch_centered(img, x, y, radius):
"""
Extracts a patch from an image centered at (x, y) with a given radius.
"""
return img[x - radius : x + radius + 1, y - radius : y + radius + 1] | 6ad8c8ee8b737fcbe036c8d5a1fb0b00a76e4014 | 21,899 |
def is_for_ast_eval(test_str: str):
"""
Is the test string a valid list of dict string,
such as "[1, 2]", that can be evaluated by ast eval.
Arguments:
test_str (str): Test string
Returns:
bool: Is test_str a valid list of dict strings
"""
return ('[' in test_str and ']' in... | e3f30a6b27f9d66e91a2c122cc9b3fc5ae1f948f | 21,905 |
def _ap(relevances, scores, topn=None):
"""Returns the average precision (AP) of a single ranked list.
The implementation here is copied from Equation (1.7) in
Liu, T-Y "Learning to Rank for Information Retrieval" found at
https://www.nowpublishers.com/article/DownloadSummary/INR-016
Args:
rel... | e856a98630548313362aa1bf49749a0b32208e61 | 21,910 |
def _get_env_var(rctx, name, default):
"""Find an environment variable in system. Doesn't %-escape the value!
Args:
rctx: rctx
name: environment variable name
default: default value to return if env var is not set in system
Returns:
The environment variable value or the def... | 1e98d7b65f1b7323caff51d897e7c5b5bedae3cf | 21,913 |
def filter_for_sprl(c):
"""
Given a BIDSFile object, filter for sprl type file
"""
try:
val = "sprlcombined" in c.entities["acquisition"]
except KeyError:
return False
else:
return val | 6f05313701ecc01512fedf05709e5e13629c467d | 21,920 |
def roll(lst, shift):
"""Roll elements of a list. This is similar to `np.roll()`"""
return lst[-shift:] + lst[:-shift] | 4805c646d4d6025b0ebcd660a020a58fb6078036 | 21,922 |
def count_distinct_occurence(calls, texts):
"""Return the count of distinct occurence of number
Args:
calls: list of calls
texts: list of texts
Returns:
number of distinct number
"""
number_set = set()
for record in calls+texts:
number_set.add(record[0])
n... | 4acf40c50bbd32b23735aaad2c581559829bb664 | 21,923 |
def get(sarif_struct, *path):
""" Get the sarif entry at PATH """
res = sarif_struct
for p in path:
res = res[p]
return res | f4c1eb9f98acb5e795d65ac427079748a9b89a6f | 21,926 |
def swift_module_name(label):
"""Returns a module name for the given label."""
return label.package.lstrip("//").replace("/", "_") + "_" + label.name | e10dee81c5bbd3d5a1fc15ae94aebe74e8de94c6 | 21,927 |
def remove_duplicate_values(array_like, tol=0.0):
"""
Removes duplicate values from list (when tol=0.0) or remove approximately duplicate
values if tol!=0.0.
"""
unique_values = [array_like[0]]
for element in array_like:
element_is_duplicate = False
for uval in unique_values:
... | afdad5db2aa00858aa9bcd29e1b64b744b2fb963 | 21,932 |
from pathlib import Path
def create_job(
create_job_header,
create_job_body,
create_job_tail,
job_name_prefix,
scenario_name,
job_name_suffix,
queue_name,
ncores,
work_dir,
run_dir,
#
config_file,
):
"""
Cr... | acc38ee8dc0169173f71e1fa5f81e75b340250e1 | 21,934 |
def toUnicode(articles):
"""Convert a list of articles utf-8 encoded to unicode strings."""
return tuple([art.decode('utf_8') for art in articles]) | 6924a837d5a093b3e0ea358381d67a1fc011519c | 21,936 |
def update_parent_child_relationships(links_dict, old_id, new_id):
"""
Update the parent-child relationships after clustering a firework
by replacing all the instances of old_id with new_id
Args:
links_dict (list): Existing parent-child relationship list
old_id (int): Existing id of the ... | a08201e455ed87ebaae52542c99ff500df523367 | 21,938 |
def normalize_name(name):
"""Returns a normalized version of the given algorithm name."""
name = name.upper()
# BouncyCastle uses X.509 with an alias of X509, Conscrypt does the
# reverse. X.509 is the official name of the standard, so use that.
if name == "X509":
name = "X.509"
# PKCS5... | 77858e7217c3a17e3b041781f117e7b53dd4c57d | 21,939 |
import torch
def upfeat(input, prob):
""" A function to compute pixel features from superpixel features
Args:
input (tensor): superpixel feature tensor.
prob (tensor): one-hot superpixel segmentation.
Returns:
reconstr_feat (tensor): the pixel features.
Shape:
input... | 8b1515d7e3c7cfbf656f4e60e4c5e7899e48dbbf | 21,942 |
def remote(obj):
""" Return the remote counterpart of a local object.
:param obj: the local object
:return: the corresponding remote entity
"""
try:
return obj.__remote__
except AttributeError:
return None | adf85d39797c158bd16f874f6ce9cf3867d6fb8b | 21,948 |
import requests
def download_pac(candidate_urls, timeout=1, allowed_content_types=None,
session=None):
"""
Try to download a PAC file from one of the given candidate URLs.
:param list[str] candidate_urls: URLs that are expected to return a PAC file.
Requests are made in order, on... | ba1554e01c0a3b2cf9251d686d946459aef40f2d | 21,952 |
from io import StringIO
def list_to_string_io(list_of_entries:list):
"""
Return file like object of the type StringIO from a given list of list of strings.
Argument:
- list_of_entries {list} - list of list of strings to transform to StringIO
Example:
[
['AR8IEZO1187B99055E... | b71528876a2fd65264c1f77bdea96ab112616894 | 21,954 |
import re
def parse_quast_result(path_to_quast_result):
"""
Args:
path_to_quast_result (str): Path to the QUAST result file.
Returns:
dict: Parsed QUAST report
For example:
{
"contigs_count": 72,
"largest_contig": 692871,
"N50": 299446,
... | d7a620a1dedbcbdf00b82a6b03c816ac963503cb | 21,957 |
def is_digit(c) -> bool:
"""Checks if given char is a digit."""
try:
return ord(c) >= 48 and ord(c) <= 57
except TypeError:
return False | 81eb6d9a3b73e567dff9b5c040309073db4ed3eb | 21,958 |
def stations_by_river(stations):
"""Find stations which are by the same river
Args:
stations (list): list of MonitoringStation objects
Returns:
dictionary: river name as key to a list of station names
"""
dic_stations_river = {}
for station in stations:
key = st... | f094ee7cae07a0b6037aac75559b68b09e88c26d | 21,963 |
from typing import Iterable
from typing import Tuple
from typing import Any
from typing import List
def unzip(tuples: Iterable[Tuple[Any, ...]]) -> List[Iterable[Any]]:
"""The inverse of the `zip` built-in function."""
return [list(x) for x in zip(*tuples)] | 10dd4755c501f64f6b98dea8abd7677d6fa23535 | 21,964 |
def clean_unicode(text):
"""A function to clean unsee unicode character like \\u2xxx
Args:
text (str): Can be news title or news body
Returns:
[str]: A unicode-free string
"""
clean_text = text.encode("ascii", errors="replace").strip().decode("ascii")
clean_text = clean_text.repl... | ed62e2644818120ea8417e2549bac76870447e55 | 21,967 |
import math
def make_divisible(x, divisor, ceil=True):
"""
Returns x evenly divisible by divisor.
If ceil=True it will return the closest larger number to the original x, and ceil=False the closest smaller number.
"""
if ceil:
return math.ceil(x / divisor) * divisor
else:
retur... | 02df42d8c490ac0c85d7ad983c0c9c838bdfa088 | 21,968 |
def color_mapping_func(labels, mapping):
"""Maps an label (integer or string) to a color"""
color_list = [mapping[value] for value in labels]
return color_list | da1f4f5432a28ef972bdcd74bd351ab4d5d09aad | 21,969 |
def bytes_to_str(b):
"""Converts a byte string argument to a string"""
if isinstance(b, str):
return b
return str(b, 'latin1') | 1494de161b7a9b4ef7743627bbbeba7624c7fa1c | 21,975 |
def _dict_key_to_key(dictionary):
"""creates a dummy map from the nominal key to the nominal key"""
return {key : key for key in dictionary.keys()} | 9feed672c1f678ed58a4d29fea5fbb0848b8b483 | 21,981 |
def seconds_to_nanoseconds(seconds):
"""Convert the specified number of seconds to nanoseconds
:param seconds: an integer representing a certain number of seconds
:returns: an integer (or float) representation of the specified number of seconds as nanoseconds
"""
return seconds * 1000000000 | d9f4687335b263a73f7f22065bfbbebb12468ce3 | 21,982 |
def get_board_copy(board):
"""Make a duplicate of the board list and return it the duplicate."""
return list(board) | 36aa2bd0719dc73602fd1fda68b120ea9c6a4a4c | 21,984 |
def map_challenge_set(x):
"""
Map a SQLAlchemy ChallengeSet model object into a generic map.
:param x: SQLAlchemy ChallengeSet model.
:return: Generic map containing relevant details for REST API.
"""
return {"id": x.id, "slug": x.slug, "name": x.name, "description": x.description} | 5a70a8d14a486c9ee57475d8b4c11b8d956430b1 | 21,985 |
import requests
def get_session(username, password):
"""
Returns a request session for the SANtricity RestAPI Webserver
"""
request_session = requests.Session()
# Default credentials
request_session.auth = (username, password)
request_session.headers = {'Accept': 'application/json', 'Conte... | 42f896195f714bad3928146b49bac88564b4a477 | 21,986 |
from typing import List
import re
def lexLine(line : str) -> List[str]:
"""Tokenizes a code line
Args:
line (str): A line of VLang code
Returns:
List(str): A list of tokenized strings
"""
if line == "\n":
return ["\n"]
elif line.startswith('#'):
return ["#"]
... | 3f8c3633300275e43c93381c91202ac02aeca01b | 21,987 |
def parse_http_header(header, header_key):
"""
**Parse HTTP header value**
Parse the value of a specific header from a RAW HTTP response.
:param header: String containing the RAW HTTP response and headers
:type header: str
:param header_key: The header name of which to ext... | 993b8190d631accf7c63e259aa5f4f4c4b657c0e | 21,988 |
def is_dictable(obj):
"""Returns ``True`` if `obj` has a ``to_dict()`` method."""
return hasattr(obj, "to_dict") | 0a12ccae0a0d3242db0bb7ad6537f2ff34ee7c48 | 21,994 |
def _mean(values:list)->float:
"""
Return mean
"""
return sum(values)*1.0/len(values) | dc433357122e84523200a6e932c787f96ff66185 | 21,995 |
def get_name(i):
"""
Return the name of i-th component of a sensor sample
"""
assert i >= 0 and i <= 5, f"Component {i} is not supported, must be between 0 and 5"
names = ["x_acc", "y_acc", "z_acc", "x_gyro", "y_gyro", "z_gyro"]
return names[i] | 9775b41ecfb28a5cefaee0bbf83569f9d115d4ea | 21,996 |
from datetime import datetime
def datetime_to_str(dt: datetime) -> str:
"""Get a timestamp string from a datetime object.
Args:
dt: The datetime object.
Returns:
The timestamp string.
"""
return dt.strftime("%Y_%m_%d_%H_%M_%S") | 9b604c18e648ce6783cd0ff8897842a8576225ab | 22,003 |
import errno
def _retry_if_file_already_exists(exception):
"""Retry if file already exist exception raised."""
return (
isinstance(exception, OSError) and
exception.errno == errno.EEXIST
) | d0094c155cc43f8172f85b1aa1fa42d7348330c2 | 22,005 |
def no_deprecated_adapter(adapter):
"""Modify an adapter to disable deprecated symbols.
``no_deprecated_adapter(adapter)(name, active, section)`` is like
``adapter(name, active, section)``, but unsets all deprecated symbols
and sets ``MBEDTLS_DEPRECATED_REMOVED``.
"""
def continuation(name, act... | 2c18bf3d059a1a2d7555f09662509688023b61ed | 22,007 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.