content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def filter_values(dictionary):
# type: (dict) -> dict
"""
Remove `None` value entries in the dictionary.
:param dictionary:
:return:
"""
return dict([(key, value)
for key, value in dictionary.items()
if value is not None]) | 614cec351146341c900b6e6ba1b5ba0bbdd67923 | 76,238 |
import uuid
def store_mail(content):
"""Saves mail as file to send it to cortex analyzers.
arguments:
- content: mail payload to write on disk
returns:
- eml_path: path on disk
"""
eml_path = "/wip/{}.eml".format(uuid.uuid4())
with open(eml_path, "wb") as f:
f.write(content)
... | 92f7efd7288f145596832ab884da087453cc890a | 76,240 |
def format_as_diagnostics(lines):
"""Format the lines as diagnostics output by prepending the diagnostic #.
This function makes no assumptions about the line endings.
"""
return ''.join(['# ' + line for line in lines]) | 533dd8b013ccd1aaa6ec3ce4ec4bfd19ca3fc165 | 76,242 |
from typing import List
def match_prompt_list(target_str: str, prompt_list: List[str]) -> bool:
"""
Matches any of the prompt candidate strings.
"""
for prompt_str in prompt_list:
if target_str == prompt_str:
return True
return False | aa2b3369199d0d269d0eaf01c02b42cd346578af | 76,244 |
def filter_intron(df_in, min_size):
"""Filter intron regions to remove those smaller than min_size."""
# remove regions shorter then min_size
df_out = df_in[df_in.end - df_in.start >= min_size].copy()
return df_out | eb3a28be141d062f00c7c2b088d67c78107f4afa | 76,247 |
def merge_feed_dict(*feed_dicts):
"""
Merge all feed dicts into one.
Args:
\**feed_dicts: List of feed dicts. The later ones will override
values specified in the previous ones. If a :obj:`None` is
specified, it will be simply ignored.
Returns:
The merged feed... | 9c8a0314dec75f484d86926737dd98ff7a54784d | 76,249 |
def word_phone_split(line:list, corpus_name:str):
"""
Splits the input list line into the word and phone entry.
voxforge has a middle column that is not used
"""
if corpus_name == "voxforge":
word, phones = line[0], line[2:]
else:
try:
word, phones = line[0], line[1:]... | c313439553728344ac8153b67076eacc04b20de0 | 76,250 |
def check_temperature(Tpp, Tmax = 0.0, Tmin = -10.0):
"""
Sets the precipitation temperature and snow temperature.
Args:
Tpp: A numpy array of temperature, use dew point temperature
if available [degrees C].
Tmax: Thresholds the max temperature of the snow [degrees C].
... | 8d5ca6e1dffc1e159ed2e9576c14d9e958b37d2b | 76,253 |
def ktmetric(kt2_i, kt2_j, dR2_ij, p = -1, R = 1.0):
"""
kt-algorithm type distance measure.
Args:
kt2_i : Particle 1 pt squared
kt2_j : Particle 2 pt squared
delta2_ij : Angular seperation between particles squared (deta**2 + dphi**2)
R : Radius paramete... | 4a725910f39e136204a0d3fc3f7b1abcd69da0e4 | 76,254 |
def build_model(cfg):
"""
Build the whole model architecture, defined by ``cfg.MODEL.META_ARCHITECTURE``.
Note that it does not load any weights from ``cfg``.
"""
meta_arch = cfg.MODEL.META_ARCHITECTURE
return globals()[meta_arch](cfg) | 373fbbb9a08112215dc20f474296ec56062531f4 | 76,258 |
import re
def oneline(s):
"""Converts a multi-line string to one line and removes extra spaces"""
return re.sub("[\s]+", " ", s).strip() | 18658d39f61ddf70d0688e407ce73484ae08fdde | 76,261 |
import ast
def handle_operator_code(self, opcode):
"""
Parses an operator code and returns its string representation.
Returns an empty string on error.
"""
if isinstance(opcode, ast.Add):
op = "+"
elif isinstance(opcode, ast.Sub):
op = "-"
elif isinstance(opcode, ast.Mult):... | 701cac1ad4485115b3aca94246e06bd1fee504dc | 76,264 |
def flatten_list(to_flat):
"""
Flattens 2D-list to 1d
:param to_flat: List to flatten
:return: 1D list
"""
return [row for rows in to_flat for row in rows] | 00d1e0bae24da120d757518c30a06da9d5ccbe89 | 76,265 |
def entitydata_delete_confirm_form_data(entity_id=None, search=None):
"""
Form data from entity deletion confirmation
"""
form_data = (
{ 'entity_id': entity_id,
'entity_delete': 'Delete'
})
if search:
form_data['search'] = search
return form_data | df473118ea31df991d65395f2e55dfdc350a24ed | 76,267 |
def mag_to_flux(mag, zeropoint=27.0):
"""Convert magnitude into flux unit.
"""
return 10.0 ** ((zeropoint - mag) / 2.5) | d2da31466b0141fb4a2eb7ec6a45b865bc122931 | 76,270 |
def split(range, upper):
"""
>>> split((0, 127), False)
(0, 63)
>>> split((0, 63), True)
(32, 63)
>>> split((32, 63), False)
(32, 47)
>>> split((32, 47), True)
(40, 47)
>>> split((40, 47), True)
(44, 47)
>>> split((44, 47), False)
(44, 45)
>>> split((44, 45), Fals... | 926aae870f69dcd8215d2ae37f1a2998dc40de69 | 76,273 |
import json
def load_json_data(json_data, encoding='utf-8'):
"""Load JSON contents from binary data.
Parameters
----------
json_data : bytes
Binary data encoding JSON contents.
encoding : str (optional, default 'utf-8')
Encoding that was used.
Returns
---... | be1e9d9a1feab3d07247ab2990c9f4bbf898f1da | 76,275 |
import unicodedata
def remove_accented_chars(text):
"""
Removes accented characters from the test
"""
new_text = unicodedata.normalize('NFKD', text).encode('ascii', 'ignore').decode('utf-8', 'ignore')
return new_text | b3a4e5b2bed54b17ed1d406f37009cacfe029217 | 76,277 |
from typing import Tuple
import re
def split_line(s: str, *, pattern: str) -> Tuple[str, str]:
"""
Splits a line into two parts and tests the first part against pattern.
Splits a line on the first white space.
If the first word matches the specified pattern, then it returns
a tuple containing the... | 4516fce664aef456a0596b4fc3bd76e14f2b93a1 | 76,281 |
def delete_session_mock(mocker):
"""Mock for patching DELETE request"""
return mocker.patch("hydra_agent.agent.Session.delete") | 26c3073e2d51dec1f3dcd9bfee3db311fdcf6a66 | 76,284 |
import base64
def decode_string(string: str) -> str:
"""Base64 decode a string.
Args:
string: String to decode
Returns:
Decoded string
"""
decoded_bytes = base64.b64decode(string)
return str(decoded_bytes, "utf-8") | 0075efafbcd3c48f3586ba11132a8aa51056fbc1 | 76,287 |
def create_error_response(code, jrpc_id, msg):
"""
Creates JSON RPC error response.
Parameters :
code: Error code
jrpc_id: JSON RPC id
msg: Error message
Returns :
JSON RPC error response as JSON object.
"""
error_response = {}
error_response["jsonrpc"] = "2.... | f5939b5ace7449d1f14321b1a902847d88f0d2db | 76,288 |
from datetime import datetime
def generate_filename(instance, filename):
"""Generate the path of the tool-picture"""
return 'users/{email}/tools/{stamp}-{file}'.format(email=instance.owner.email,
stamp=datetime.now().timestamp(),
... | 597c96da2d55e5119f629938c67400cf916a33a6 | 76,290 |
from typing import Optional
def filter_dictionary(dictionary: dict, fields_to_keep: Optional[tuple], sort_by_field_list: bool = False) -> dict:
"""
Filters a dictionary and keeps only the keys that appears in the given list
:param dictionary: the origin dict
:param fields_to_keep: the list which conta... | c8196c43bd49a593060093fc49c668c47b950946 | 76,296 |
def NOT_IS(attribute, val):
"""
Check if two values are not equal
"""
return attribute != val | 3567a3789bc3ab9176ee9ba4a5d1eb0a4c4dec48 | 76,299 |
def _build_task_dependency(tasks):
"""
Fill the task list with all the needed modules.
Parameters
----------
tasks : list
list of strings, containing initially only the last module required.
For instance, to recover all the modules, the input should be ``['fourier']``.
Returns
... | 6da74f01badfc395c3be7daf8ae30df9e2837c63 | 76,300 |
def volume_flow(p, G, R, T, Z):
"""
:param p: Absolute pressure, Pa
:param G: Mass flow, kg/s
:param R: Gas constant, J/(kg*K)
:param Z: Compressibility factor
:return: Volume flow of the natural gas, m3/s
"""
return Z * G * R * T / p | 25fd7d076272f8747390824a922b5808e312e4ad | 76,302 |
def level_from_severity(severity):
"""Converts tool's severity to the 4 level
suggested by SARIF
"""
if severity == "CRITICAL":
return "error"
elif severity == "HIGH":
return "error"
elif severity == "MEDIUM":
return "warning"
elif severity == "LOW":
retur... | 25fe348a39a7a26b507bde84fb94eba4c9d554bf | 76,304 |
def get_paths(corpus, x, y, pattern):
"""
Returns the paths between (x, y) term-pair
:param corpus: the corpus resource object
:param x: the X entity
:param y: the Y entity
:param pattern: path patterns to exclude (e.g. satellites)
:return: all paths between (x, y) which do not match the pat... | ede98e4aafdc17802298bf2f99de15fd871f4cab | 76,305 |
def setCompare(iter1, iter2):
"""
Compares two groups of objects, returning the sets:
onlyIn1, inBoth, onlyIn2
"""
s1 = set(iter1)
s2 = set(iter2)
intersect = s1 & s2
return s1 - intersect, intersect, s2 - intersect | bca09656503a13e693a7f8c9b9eb0e11cb867d49 | 76,312 |
def consolidate_headers(header_offsets):
"""
This takes the array of headers and returns just the starting character of
each header. These character offsets are used to section the document
"""
return [x[0] for x in header_offsets] | 4f0e080795eff168065304a35ea3836db798112b | 76,315 |
def max_o(x, n, prevent=False):
"""
Ensures that x fits on n bits (not bytes).
- If prevent is True then an exception is raised
- Otherwise just set all bits to 1
Parameters
----------
x
Number to test
n
Number of bits available
prevent
If true then an excep... | c40f53f12a4c6301cd378c0c61375c376e5d53ae | 76,316 |
def pingponglet(value):
"""Return a value unchanged"""
return value | 254330478eb52c9c498d4f716cf8c7c488b43358 | 76,320 |
import math
def get_chain_stats(embedding):
""" Embedded chains account for the number of qubits used per
variable in the source.
Arg:
embedding (dict):
Mapping from source graph to target graph as a dict of form
{s: {t, ...}, ...}, where s is a source-model variable and t... | 7788f3103016aa6173a8bb4ef43ea87378d7ebb1 | 76,323 |
def get_db_img_name(img_name, processing):
"""Creates image name given processing type
Args:
img_name (str): image name
processing (str): processing applied
Returns:
str: Created image name
"""
img_name, filetype = img_name.split('.')
return img_name + processing + "." ... | a2062110cb0356ae75e9ab87b1272849b1e6cf82 | 76,324 |
def find_3D(index,
header,
max_distance,
quality=5):
"""
Return the list of USArray 3-D EMTF keys (for repository
:class:`Index` *index*) that are less than *max_distance* (in km)
from the magnetometer location specified in *header*. Only include
*quality* or grea... | 28c4a5d29518cf129d502bb3090007b7884d34e0 | 76,325 |
def get_slot(grps, k):
"""
Given array of match groups, return first key matching
:param grps:
:param k:
:return: tuple matching.
"""
for g in grps:
key, v, x1, x2 = g
if key == k:
return g
return None | 4fb55d4a6dbb5960bef1590a2cd2131f276507e0 | 76,326 |
from typing import List
from typing import Tuple
def _format_list(input_list: List, evals_per_gen: int) -> Tuple:
"""
_format_list() takes as input data collected from multiple algorithm runs.
Then, an average is computed and horizontal axis scaling is applied.
The return value is a tuple of two list,... | 6ef9a11e13ceaeaae4fc9793aada1f43eb558659 | 76,329 |
import re
def testPasswordStrength(password):
""" check for at least eight characters long, contains both uppercase and lowercase characters, and has at least one digit
Args:
password (str): password as string
Returns:
strong (bool): True if password is strong else
"""
eightCharsL... | 3d743195fb585e6beec8d7c39696548393edf04a | 76,330 |
from functools import reduce
def checksum(bytes):
"""Return the simple checksum of a sequence of bytes."""
return reduce(lambda a, b: a + b % 2**16, bytes) | c44047a3a2e522d9ed8072fd703d939d5436ebd9 | 76,335 |
from typing import Callable
from typing import Any
def lazy_property(f: Callable[..., Any]) -> Any:
""" Decorator to make lazy-evaluated properties"""
attribute = '_' + f.__name__
@property # type: ignore
def _lazy_property(self: object) -> Any:
if not hasattr(self, attribute):
s... | dda3e142dd7d0414c604e114efb9c06632c4343a | 76,336 |
def escape_like(v: str) -> str:
"""
Escape a string for the use in `LIKE` condition.
:param v: A string.
:return: Escaped string.
"""
def esc(c):
if c == "\\":
return r"\\\\"
elif c == "%":
return r"\%"
elif c == "_":
return r"\_"
... | c657e8bc59f18ce1adb4991f7eefa8e84ae55195 | 76,339 |
import torch
def compute_logits(cluster_centers, data):
"""Computes the logits of being in one cluster, squared Euclidean.
Args:
cluster_centers: [K, D] Cluster center representation.
data: [B, N, D] Data representation.
Returns:
log_prob: [B, N, K] logits.
"""
k = cluster_centers.shap... | ec0f7c69654b4e233a0d98582d06f9cf169f2378 | 76,342 |
from pathlib import Path
def list_files(path='.', extension=''):
"""Return list of files with specific extension in path.
- by default, return all files with any extension.
- directories are excluded
- results are sorted by name
"""
folder = Path(path)
pattern = '*' + extension
paths ... | 2852e4edd32858605df1bddf3d2716576ab69a7f | 76,346 |
def get_info_file_path(path):
"""
example:
path=/000001/000001493.png
returns /000001/000001493.gt_data.txt
"""
return path[:16] + '.gt_data.txt' | 5a97beb5e313730c6ad46a24af2aebf2e76e67c5 | 76,347 |
def largest_prime_factor_even_optimized(number):
"""
We know that, excluding 2, there are no even prime numbers.
So we can increase factor by 2 per iteration after having found the
"""
factors = []
factor = 2
if number % factor == 0:
number = number // factor
factors.append(... | 36269bc3fc68af504d85adae6069fb98469be9d3 | 76,348 |
from typing import Optional
from typing import Any
def save_file(
file_path: Optional[str] = None,
content: Any = None,
mode: str = "w",
encoding: str = "utf-8",
newline: str = "\n",
writer: Any = None,
) -> None:
"""
Save a file.
:param file_path: The path to the file to save.
... | b1ff348e661485884f3a7a8cdb80766ea9241a19 | 76,355 |
def parse_events(artifact: dict):
"""
Parses events from the compiled contract,
and stores them in the global events variable.
:param json artifact: the artifact json object compiled contract loaded
"""
events = [] # list of event names
event_input_types = {} # map event name to tuple... | 159b81b8e55ecec055ee8f3da864c30412b8247e | 76,356 |
def string_parse(input_str):
"""
Converts passed string, into *args, **kwargs:
Args:
input_str(str): input string in format -
"1, 2, 3, a\nvalue3=4, value1=arg1, value2=arg2"
Returns:
tuple(*args, **kwargs): parsed args, and kwargs values... | 3c1dc3d81c0539019c6095c00741f0daf0f5c188 | 76,360 |
def calc_tanimoto(Na, Nb):
"""Calculates the Tanimoto similarity coefficient between two sets NA and NB."""
Nab = len(set(Na).intersection((set(Nb))))
return float(Nab) / (len(Na) + len(Nb) - Nab) | e76a77c8b1b72ecaba59fe575e6dab6be21bf1d5 | 76,366 |
def create_infertility_feature(diagnosis):
"""
Creates the one-hot encoded infertility diagnosis feature from a given
diagnosis.
Parameters:
-----------
diagnosis : str,
The infertility diagnosis, must be one of Ovulatory disorder,
Male factor, Endometriosis or Unexplained.
... | 746d80464f5951de1376ade1d3595f8310a58a2c | 76,372 |
def get_clean_text(html):
"""
Removes extra blank spaces and nbsp from html text.
"""
return " ".join(html.text_content().split()) | df0f789ddbbaee51ea807465bf7e286b2a2a4096 | 76,375 |
from datetime import datetime
def convert_time(time):
"""Convert a time string into 24-hour time."""
split_time = time.split()
try:
# Get rid of period in a.m./p.m.
am_pm = split_time[1].replace('.', '')
time_str = '{0} {1}'.format(split_time[0], am_pm)
except IndexError:
... | 4bd59b2e10f4a15260dd2cef840dd6cea97475f6 | 76,376 |
def pad(data: bytes, size: int, value: int = 0) -> bytes:
"""Padds given data with given value until its length is not multiple by size
Parameters:
data: bytes
Data to pad
size: int
Required size data length must be multiple to
value: int
Va... | 3879930d6516daa751dcd310c93055b30c36b852 | 76,377 |
import collections
def parse_chrom_size(path, remove_chr_list=None):
"""
support simple UCSC chrom size file, or .fai format (1st and 2nd columns same as chrom size file)
return chrom:length dict
"""
if remove_chr_list is None:
remove_chr_list = []
with open(path) as f:
chrom... | 97770cc856d9dc1e6c90c8dda4caf9abac87e893 | 76,378 |
def split_data(X, Y):
"""splits data into 80 % training and 20 % test data."""
return X[:400], X[400:], Y[:400], Y[400:] | 393430717026706a68d98dc6955d7902c3833ad1 | 76,380 |
def write_ps_hdf5(file, spec_name, l, ps, spectra=None):
"""Write down the power spectra in a hdf5 file.
Parameters
----------
file: hdf5
the name of the hdf5 file
spec_name: string
the name of the group in the hdf5 file
l: 1d array
the multipoles (or binned multipoles... | 232b6d539d1d2420e7d785713efe7ec8a50f882b | 76,383 |
def calc_resize_with_apect(size, min_dimension):
"""calculate the dimensions needed to resize an image with the minimum dimension on one side
while preserving the aspect ratio.
size: tuple containing the original image size in pixels (w,h)
min_dimension: min pixel size on one size
"""
w = size[0... | fd52f50a2ce759fe4d510f6ae6b403ab2cb523e3 | 76,388 |
def find_text_idx(sentence):
"""
Return the index of the # text line or -1
"""
for idx, line in enumerate(sentence):
if line.startswith("# text"):
return idx
return -1 | f3edb255e715ab7607802448ef750318d7b79e29 | 76,393 |
def parseLecturer(line):
"""Parses the line with lecturer's information
Splits the line appropriately to firstName, lastName, specialization,
preferedDates and residence
"""
logicalChunks = line.split(':')
name = logicalChunks[0].split(' ')
subjects = logicalChunks[1].split(',')
prefe... | 7bc1f01b0656209d08ea08277745d7aa9b55fde2 | 76,398 |
from typing import Union
def index_for_wavelength(wls, w) -> Union[None, int]:
"""Return the index for a particular wavelength or None if not present
"""
try:
idx = wls.index(w)
except ValueError:
return None
return idx | 3c8e8a921609151acd671fd0d9c47732a7425ffd | 76,399 |
def get_inner_text(element):
"""
Get the inner text of the specified XML element.
"""
buffer = []
for node in element.childNodes:
if node.nodeType == node.TEXT_NODE:
buffer.append(node.data)
elif node.nodeType == node.ELEMENT_NODE:
buffer.append(get_inner_text(node))
return "".join(buffer).strip() | f40af274dbb4cf5e78f5db77082abbd0dd618e4b | 76,401 |
def _uniq(iterable):
"""Returns a list of unique elements in `iterable`.
Requires all the elements to be hashable.
Args:
iterable: An iterable to filter.
Returns:
A new list with all unique elements from `iterable`.
"""
unique_elements = {element: None for element in iterable}
... | 64a18b7865ac6d709e0732e5536eac7b7b08b433 | 76,403 |
def is_sub_seq(full_seq, sub_seq):
"""Return true if sub_seq is a sub-sequence of full_seq.
"""
if len(sub_seq) == 0:
return True
for idx0,x0 in enumerate(full_seq):
if x0 == sub_seq[0]:
if is_sub_seq(full_seq[idx0+1:], sub_seq[1:]):
return True
return Fa... | fded0c65cdc7a817fdbf34a53469fc540f16d9b0 | 76,405 |
def aggregate_log_dict(agg_dict, new_dict) -> dict:
"""
Aggregate the statistics of a log dict
:param agg_dict: aggregation dictionary
:param new_dict: dict with new stats
:return: new aggregation dict with aggregated
"""
for k in new_dict:
# init new if not present
if k not ... | 206c1ed2b2bf5218e42b97ad57583c61e72319f3 | 76,407 |
def read_file(filename, mode='rU', stripChar='\n', replaceChar='', lines=False):
"""
Basic implementation of reading a text file into a list. Default is to read one line at a time.
If lines=True, uses read.readlines() and return each line of the file as is (includes all whitespace and newline chars)
... | b3d0ef838f97ba6a38f0d056f27ac98bc5a38e26 | 76,415 |
def RGBToHTMLColor(rgb):
"""
Convert an [R, G, B] list to #RRGGBB.
:param: rgb - The elements of the array rgb are unsigned chars (0..255).
:return: The html color.
"""
hexcolor = "#" + ''.join(['{:02x}'.format(x) for x in rgb])
return hexcolor | 2b19dd68f8e23a095c5244eb2a1bdf59a932df97 | 76,418 |
from datetime import datetime
def format_date_for_mongo(time_str):
"""
Reformat a time string into YYYY-MM-ddTHH:mm:ss.
"""
return datetime.strptime(time_str, '%y_%m_%d_%H_%M_%S')\
.strftime('%Y-%m-%dT%H:%M:%S') | 382d4236eaa6d2057bb16284c9c863eae12afe49 | 76,421 |
def _process_y(dtype, data):
"""Returns the MPL encoding equivalent for Altair y channel
"""
return ('y', data) | cf72825eebe3f5ab0c79f7b7fa47d4b40732c895 | 76,427 |
def distribute_particles_across_tiles(particle_lons, particle_lats, tiles):
"""
Splits a list of particle longitudes and a list of particle latitudes into `tiles` equally sized lists.
Args:
particle_lons: List of particle longitudes.
particle_lats: List of particle latitudes.
tiles:... | d887e622d18cbaadee3adce542ae80bc5a4da4a3 | 76,433 |
def _extract_element(xml, element_name, namespace):
"""
An internal method provided to extract an element from the given XML.
:type xml: :class:`str`
:param xml: The XML string from which the element will be extracted.
:type element_name: :class:`str`
:param element_name: The element that nee... | 83feee17192407d25f77aedff475843e5df3ee33 | 76,435 |
def smart_encode(content: str, encoding: str) -> bytes:
"""Encode `content` using the given `encoding`.
Unicode errors are replaced.
"""
return content.encode(encoding, 'replace') | 4e51aee004b2646f6f907335b883eb2fa5acbd59 | 76,436 |
def somatorio(n):
"""
Função recursiva que recebe um valor inteiro n >= 0, e devolve o somatório de 0 até n.
Exemplos:
------------
somatorio(0) deve devolver 0;
somatorio(2) deve devolver 3, pois 0+1+2 = 3;
somatorio(5) deve devolver 15, pois 0+1+2+3+4+5 = 15;
Retorno:
-----------
int: soma dos números int... | 4a3852afa1f04d77fbd6b1581802ed47a9ff1950 | 76,438 |
import re
def parse_env(env_in):
"""
Parses all environment variables into a map.
"""
env_out = {}
reg = re.compile(r'^(?P<var_name>[A-Z0-9_\-]+)=(?P<var_value>.+)$')
env_all = env_in.split(" ")
for e in env_all:
if e == "":
continue
match = reg.match(e.lstrip(... | 317319048db163f2352324db20622e9491fdc6fd | 76,439 |
def _is_str(text):
"""Checks whether `text` is a non-empty str"""
return isinstance(text, str) and text != "" | 0ad979fd01f241bcb521f095061d7739f85cdfb4 | 76,440 |
def f_score(precision, recall, beta=1):
"""Compute F beta score
Args:
precision (float): precision
recall (float): recall
beta (float): the weight of recall, default=1
Returns:
float: f score
"""
if recall + precision*beta**2 == 0:
return 0
... | 5a213cf0c8e23d6f43e25ad63cc099d64ff36341 | 76,445 |
import torch
import math
def bbox_iou(box1, box2, x1y1x2y2=True, giou=False, diou=False, ciou=False, eps=1e-9):
"""Compute the IoU of box1 to box2. box1 is 4, box2 is nx4
:param box1: box1
:param box2: box2
:param x1y1x2y2: xyxy or xywh
:param giou: giou
:param diou: diou
:param ciou: cio... | 3a53910414f2352a0953446603b4fed071f44edd | 76,447 |
def convertHLABack(h):
"""Takes format HLA-A*12:34 and returns A_1234"""
return h[4:].replace('*', '_').replace(':', '') | 5da352ff4dd740d3e6813db3883fc36c3effdd57 | 76,448 |
import math
def split_list_by_percentage(
list_to_split: list, percentage_to_split: float
) -> "tuple[list, list]":
"""
Split a list into two sub lists
the second sub list has the length 'len(list) * percentage_to_split'
"""
split_index = math.floor(len(list_to_split) * percentage_to_split)
... | 29be2e6c3af170c36ac8763af28d882a511cc8bf | 76,453 |
import six
def _downsample(rng, xs, k):
"""Uniformly choose a maximal at-most-`k`-subsequence of `xs`.
If `k` is larger than `xs`, then the contents of `xs` itself will be
returned.
This differs from `random.sample` in that it returns a subsequence
(i.e., order is preserved) and that it permits ... | c9156a1fec1ebffcffcd1e83f4891b4afd695170 | 76,461 |
from datetime import datetime
def make_test_run(
testinstance,
exec_date='',
exec_time='',
duration='0',
status='Passed'
):
"""
Create a RunInstance in QC.
"""
run = testinstance.RunFactory.AddItem("Run {}".format(datetime.now()))
run.Status = status
run... | ec8f747fc2c2fcfff8e86b4402f016de5bb9f4ad | 76,462 |
import pkg_resources
def parse(version):
"""Parses a ``version`` string.
Currently a simple wrapper around ``pkg_resources.parse_version()``,
for API purpose. Parsing could change later.
"""
return pkg_resources.parse_version(version) | 54db2805667b946d719536b64dc4733806261e00 | 76,463 |
import json
def load_json(file_path):
""" Loads in a JSON file as a dict
Args:
file_path (str): path to JSON file
Returns:
dict: Data in file
"""
data = {}
with open(file_path, 'r') as file:
data = json.load(file)
return data | 24da94219f22240c043eff19ff68d4585306288f | 76,468 |
from typing import TextIO
import json
def load_mb_tags(fhandle: TextIO) -> dict:
"""Load track metadata
Args:
fhandle (str or file-like): path or file-like object pointing to musicbrainz metadata file
Returns:
Dict: metadata of the track
"""
return json.load(fhandle) | 2e53983bf743fd284095a017b1d6e277db80e69c | 76,469 |
def norm1(m):
"""
Return the L1-norm of the point m
"""
s = 0.0
for (name, value) in m.items():
s += abs(value)
return s | a6a74882cc86a8ca1b1a0e6dfbcdf5b9c3b11569 | 76,471 |
def is_isogram(string):
"""
Check if the text passed in is an isogram.
:param string string - Text to check
:return bool - Isogram, or not.
- Filter for alpha
filter + list will convert the string to a list
- Count occurences of each charater
if theres more than 1 then it's not... | 185c66c4f3da9eeaf71c3b5089931fbc60ffd403 | 76,473 |
def entity_resource_file(entity, resource_info):
"""
Return a file object that reads out the content of a resource attached to a specified entity.
"""
return entity.resource_file(resource_info["resource_path"]) | b126fbbad79e87c9c20390e02e2c134a4bfb539c | 76,474 |
import itertools
def _split_into_words(sentences):
"""Splits multiple sentences into words and flattens the result"""
return list(itertools.chain(*[_.split(" ") for _ in sentences])) | 458e1eeac7d05c1646057af9ab8a039b22568b87 | 76,477 |
import itertools
def peek_next(iterable):
""" Peek next element of iterable.
Parameters
----------
iterable
Iterable to peek the next element from.
Returns
-------
next_item
Element peeked from `iterable`.
new_iterable
Iterable behaving like if the original `i... | 8b249a5159c2c88188c3daa75c9ad37f2a4cbf2b | 76,481 |
def gen_rel_xsd_path(branch_path, xsd_path):
"""Generate the relative part of the XSD path that follows under `branch_path`.
Args:
branch_path: str
Absolute path to a branch holding all the XSD files for a single formatId.
xsd_path: str
Absolute path to an XSD file unde... | 50730daa795d44f3b9ad887c50cb2297dd24ebeb | 76,485 |
import inspect
def for_own_methods(method_decorator):
""" Decorates all the methods in a class.
This function takes a function decorator and returns a class
decorator that applies the function decorator to all of the
methods in a class. The function decorator will only be applied
to methods that ... | e5458a9d304f02598ab6ac51edd967e97c6af4b0 | 76,486 |
def gen_DroneLog(drone_id, log_string):
"""Generate a Drone log object from log string."""
dronelog = {
"@type": "DroneLog",
"DroneID": drone_id,
"LogString": log_string
}
return dronelog | 806efd33b5cca988cf0ef78d65553a3a49d8fe58 | 76,489 |
from typing import Optional
import random
def random_product(
*iterables,
repeat: int = 1,
rng: Optional[random.Random] = None,
):
"""
>>> from random import Random
>>> random = Random(1)
>>> suits = 'CDHS'
>>> ranks = list(range(2, 11)) + ['J', 'Q', 'K', 'A']
>>> card... | 3bfa4e6cd7942da29cae396865547946bb4fc175 | 76,491 |
from urllib.parse import quote as urlquote
import re
import string
def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
"""Converts any URLs in text into clickable links.
If trim_url_limit is not None, the URLs in link text longer than this limit
will truncated to trim_url_limit-3 cha... | 6e69864ab2fd7c3f7df23b3266ee9f497b6126d8 | 76,493 |
def to_dict_with_custom_fields(instance, custom_fields):
""" Convert an object to a dictionary with only some of the fields that
exist on the object. Some fields also require some manual handling.
:param instance: Object to be converted.
:param custom_fields: List of fields to include in dict.
:retu... | aba609da188821e47cccb5eebb1d936d0960ba5e | 76,497 |
def get_if_exist(data, keys):
""" Recursively get a value from a nested dictionary
Parameters
----------
data : dict
The (nested) dictionary
keys : list
The list of keys to fetch
Returns
-------
any or None
The value at data[keys[0]][keys[1]] etc. or None if a k... | 35e463473a4f85abe63b23876c1fc372e13f2072 | 76,499 |
import json
def build_keyboard(items):
"""
Build a keyboard from the notes showing each note id in a row,
and return the required json to display it
@items: dictionary with notes to display
"""
keyboard = [[str(key)] for key in items.keys()]
reply_markup = {"keyboard": keyboard, "one_t... | 28b37fb501169fa4dfb9aa6462c5f33d52451f69 | 76,500 |
def readFile(filename):
"""Read a file into memory
Args:
filename: Name of the file to be read
Returns:
Variable wholeFile containing the entire file
"""
# home = expanduser("~")
# cwd = os.getcwd()
# print ("$HOME:%s | CWD:%s" % (home,cwd))
f = o... | 9d3620525a35882c30abb088e4b3b3daad00ef94 | 76,501 |
import torch
def multi_quantile_huber_loss(quantiles: torch.Tensor,
target: torch.Tensor,
delta: float = 0.1) -> torch.Tensor:
"""Multi-quantile Huber loss
The loss for simultaneous multiple quantile regression. The number of quantiles
n is ``qu... | b4385668e83ce5bb424cea07f38253042a397a95 | 76,504 |
def pair_hexvalue(value, delimiter=":"):
"""
Pair hex values (string) using delimiter.
e.g. abcdef -> ab:cd:ef
:param value:
:param delimiter:
:return:
"""
return delimiter.join(
["{}{}".format(a, b) for a, b in zip(value[::2], value[1::2])]
) | 1cd1349bd9cc419e15e365bd243a9a5b46d5470c | 76,507 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.