content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def read_scalar(group, dataset_name):
"""
Read a HDF5 `SCALAR` as a dict.
All attributes will be assigned as key: value pairs, and the
scalar value will be assigned the key name 'value'.
:param group:
A h5py `Group` or `File` object from which to write the
dataset to.
:param da... | 6d9908e64f6584d0128756778679f87ffc8cb46f | 697,094 |
def ma(error, params, offset):
""" Calculate the moving average part.
:param error: list of error terms
:param params: list of coefficients
:param offset: index of last predicted value
:return: float
"""
return sum([params[i] * error[offset - i] for i in range(len(params))]) | 5ac853fca6a57dd4f349e79445b75b29f62ccbd7 | 697,095 |
import torch
def my_sample_gumbel(shape, eps=1e-20):
"""Samples arbitrary-shaped standard gumbel variables.
Args:
shape: list of integers
eps: float, for numerical stability
Returns:
A sample of standard Gumbel random variables
"""
#Sample from Gumbel(0, 1)
U = torch.rand(shape).float()
return -torch.log(ep... | 21e471bf5fca80316d93ec2a96230471ddc83a45 | 697,097 |
def _get_package_dict1(reqs: str) -> dict:
"""Helper to parse requirements str into a dict of
(package, version) k, v pairs
"""
return dict(line.split("==") for line in reqs.strip().splitlines()) | 8b851a871a2e2ef9d9c984831393bf30b29d7a02 | 697,098 |
def lowercase(lista):
"""Function to lowercase list of texts
Args:
lista ([list]): list of texts
Returns:
[list]: List of texts lowercased
"""
return [text.lower() for text in lista] | 2be877aa3b80c5e01eb4237625b426123d5b9976 | 697,099 |
import re
def get_text_between_parenthesis(string):
"""
Return a list with all the found substrings between parenthesis.
If the strings doesn't contains parenthesis the function return an empty list
:param string: a string
:return: a list
"""
try:
text_list = re.findall('\(([\d\w\... | cce6abdb5618474848d9cff0f0ace1fab01f5b84 | 697,101 |
def get_elevated_session_input(response):
"""Create input for get_elevated_session."""
return {
'aws_access_key_id': response['Credentials']['AccessKeyId'],
'aws_secret_access_key': response['Credentials']['SecretAccessKey'],
'aws_session_token': response['Credentials']['SessionToken']
} | cede7d9a695953b8b0f57c6b58e5c69bf84d7887 | 697,102 |
def reverse_array(arr):
"""
Reverse an array along all axes, so arr[i,j] -> arr[-(i+1),-(j+1)].
"""
reverse_slice = [slice(None, None, -1) for ii in arr.shape]
return arr[reverse_slice] | 659e4aea2f62287aeef6d3d4d80b3c58f937ace2 | 697,104 |
from functools import reduce
def split_camel_case(text) -> list:
"""Splits words from CamelCase text."""
return list(reduce(
lambda a, b: (a + [b] if b.isupper() else a[:-1] + [a[-1] + b]),
text,
[]
)) | 5a6f2fcfcdb378295554cc38a88679e054341068 | 697,105 |
def pageurl_template(category, pagenum, date):
"""
Function to return formatted URL given category, page number, date
"""
assert len(str(date)) == 8, 'Invalid input date format'
return f"https://news.daum.net/breakingnews/{category}?page={pagenum}®Date={date}" | e6a7c9c86c16cd775919588b918c6d49b8d3a5bd | 697,107 |
def parse_transaction_weights(config_root):
"""
Parse the transaction types and weights from the XML configuration.
Parameters
----------
config_root : xml.Element
The root of the XML config file.
Returns
-------
transaction_weights : [dict]
An array of dictionaries for... | 085a963d95d7e14fcaf688317374f33373dc6c0d | 697,109 |
def cumsum(vals):
"""Return a cumalative sum of vals (as a list)."""
lst = []
tot = 0
for v in vals:
tot += v
lst.append(tot)
return lst | e9ea4065fa7a044ae738e33dbd855cd1948e8c45 | 697,111 |
def count_measurements(report_uuid: str, database) -> int:
"""Return the number of measurements."""
return database.measurements.count_documents(filter={"report_uuid": report_uuid}) | c9f20149ec975134ad7f0abab28a2c632f5295a1 | 697,115 |
def normalize_letters(one_letter_code) :
"""Convert RAF one-letter amino acid codes into IUPAC standard codes.
Letters are uppercased, and "." ("Unknown") is converted to "X".
"""
if one_letter_code == '.' :
return 'X'
else :
return one_letter_code.upper() | ad1d80a4663859194f84a31dc03001481b477503 | 697,117 |
def is_original_process_func(clsdict, bases, base_class=None):
"""Only wrap the original `process` function.
Without these (minimal) checks, the `process` function would be
wrapped at least twice (the original `process` function from the
user's DoFn, and our wrapped/decorated one), essentially causing
... | 17598fa632fc4dc9c8e52613325e6448b3064559 | 697,119 |
def parse_identifiers(identifiers):
""" Reads identifiers, which may be a string or list/tuple/set of objects
instances with name instances as string, returning a frozen set of names.
"""
if isinstance(identifiers, str):
return frozenset(identifiers.split(','))
if not isinstance(identifiers, (list, tuple... | 285a12352607ecc6b4a0c9ceb6f0ca7e2f56988e | 697,122 |
def csc_cumsum_i(p, c, n):
"""
p [0..n] = cumulative sum of c [0..n-1], and then copy p [0..n-1] into c
@param p: size n+1, cumulative sum of c
@param c: size n, overwritten with p [0..n-1] on output
@param n: length of c
@return: sum (c), null on error
"""
nz = 0
nz2 = 0.0
for... | ab567b6b357fc7e5e1b0a961b9b66d88487a0e7f | 697,125 |
def boolean_flag(name, configurable, set_help='', unset_help=''):
"""Helper for building basic --trait, --no-trait flags.
Parameters
----------
name : str
The name of the flag.
configurable : str
The 'Class.trait' string of the trait to be set/unset with the flag
set_help : uni... | dabb654a75123a79b865c1570e6ed74568c5ae41 | 697,127 |
def LevenshteinCost(a, b):
"""Cost function for Levenshtein distance with substitutions.
Cost function for what is now thought of as the classical
Levenshtein distance, which is the minimum number of insertions,
deletions, and substitutions required to edit one sequence into
another. Returns zero for matche... | 8d82b0003d1fa00720270c33cfd4a119dd5f00c7 | 697,132 |
def pedersenOpen(n,g,h,m,r,c):
"""Open a pedersen commit. Arguments:
n modulus (i.e. Z*_n)
g generator 1
h generator 2
m message
r random
c commit generated by pedersenCommit() to verify"""
if c == g**m*h**r % n:
return True
else:
r... | 4657cd68214566f4e2e8231b61067963478af9a1 | 697,139 |
def extend_indices(segments, margin):
"""
Decrease and increase the values of the first and last elements
respectively in each list of segments by a given margin.
The first indice of the first segment and the last indice of the
last segments are not modified.
Parameters
----------
segme... | 34da9377af9342a811fb40bdadcadce174fcb605 | 697,140 |
from datetime import datetime
def datetime_to_ms(dt: datetime) -> int:
"""Convert a datetime to milliseconds."""
epoch = datetime.fromtimestamp(0, dt.tzinfo)
return int((dt - epoch).total_seconds() * 1000.0) | c14128887dfa7201d68b055c2af5be56f5f8ab37 | 697,148 |
def get_length(key_list):
"""
Get length in the TLV
:param key_list: Key to parse
:return: Length in the TLV
"""
# Find tag value
if 2 == int(key_list[0], 16): # pylint: disable=misplaced-comparison-constant
# check MSB is zero, if yes then this byte indicates length
# else ... | 70b2b2069b9cd55f49da5711cfcd816e371affb8 | 697,149 |
def get_skidl_spice_ref(skidle_element):
"""
Helper function to retrieve SKiDL element name as appears in the final netlist
Args:
skidle_element (skidl.Part.Part): SKiDl part to get the netlist name from
Returns:
returns a string with the netlist name of `skidle_element`, or th... | 4eacd423cbcdbc5171eb1f4b5ef81d6482f34843 | 697,151 |
def weighted_values(values, weights):
"""Returns paired lists of results and their GCM weights.
Args:
values: Dictionary of GCM -> result value
weights: Dictionary of GCM -> GCM weight
"""
models = values.keys()
values_list = [values[model] for model in models if model in weights]
w... | 6bd59e99d19d68535148f5bdf34bcec2f0cb4736 | 697,154 |
from typing import Tuple
def set_add(arr: Tuple[str, ...]) -> int:
"""
>>> set_add(('UK', 'China', 'USA', 'France', 'New Zealand', 'UK', 'France'))
5
"""
return len(set(arr)) | e47705878c34400e3763a887cba4568dd5d621e4 | 697,155 |
def rank_index(square):
"""Gets the rank index of the square where ``0`` is the first rank."""
return square >> 3 | d4d3f896b5a7cd8b7184320efd69a652c61ccbcf | 697,156 |
def html_summary_table(data):
"""Generate HTML table of novelty detection statistics.
data: dict
A JSON like structure of the table data that has the following format:
data = {
'modelA': {
'inlier_name': 'MNIST'
'outliers': {
'Fashion MNIST': {
... | 53162dfab20859b03408ff67c3a2421b0e84e33e | 697,157 |
def hello ( name ):
""" Say hello ."""
return " hello " + name | 3fd85b4c2f719e6c2abb7cd21bd7df2fe38c0272 | 697,158 |
def getSize(l):
"""
Returns size of list
Example
>>> getSize([0,4,32,21])
4
"""
c=0
for i in l:
c=c+1
return c | ab59a55778ed4b8034debea20d33c1cb609a4243 | 697,159 |
def _miriam_identifiers(type_, namespace, identifier):
"""
Fix the MetaNetX identifiers into miriam equivalents.
MetaNetX doesn't use correct miriam identifiers. This function maps the
known namespace and entity identifiers used by MetaNetX to valid miriam
identifiers.
Parameters
---------... | 19218dbe7e086dabf6527b26e770986462428ecb | 697,161 |
from typing import List
def add_to_rightmost_int(stack: List, x: int) -> List:
"""
Add x to rightmost int in l
if no int in l, do nothing
return modified l
"""
int_locations = [isinstance(i, int) for i in stack]
if not any(int_locations):
return stack
int_locations.reverse()
... | 84240d412539cc221edd24462f97bb84a1eca051 | 697,164 |
def mapToRange(val, src, dst):
"""
Map the given value from the range of src to the range of dst.
"""
return ((val - src[0]) / (src[1] - src[0])) * (dst[1] - dst[0]) + dst[0] | 769dd6f6c52b0c8cdc2b0358457820c0ed15a1f8 | 697,165 |
def is_true(boolstring: str):
""" Converts an environment variables to a Python boolean. """
if boolstring.lower() in ('true', '1'):
return True
return False | 466c839ff5ea25e970c9ce1a86fbcbc7d5fec3a1 | 697,166 |
import optparse
def parse_shards_into(option, opt, value, parser):
"""Parse lists of shard or shard ranges into a set().
Examples:
0-2
0,1-3,5
1,3,5
"""
def shard_range_parser(shards):
result = set()
for part in shards.split(','):
x = part.split('-')
result.update(... | 1262db211fe698f3e38b5b61e8dce1bddd2dcb21 | 697,169 |
def edits2str(edits):
"""
get a printable representation for a list of edits
"""
output_str = [edit.__str__() for edit in edits]
return output_str | 599afcd8636e0939b72ebc88ebb88743fd4fe6a6 | 697,171 |
import re
def _get_enclosed_str(text, prefix, suffix):
"""
Remove prefix and suffix from the string if the string contains both prefix and suffix.
"""
success = False
text = text.strip()
pattern = f"^{prefix}.+{suffix}$"
if re.search(pattern, text):
pattern1 = f"^{prefix}"
... | 4a4305d18308491f477ae929c4009af39f345472 | 697,173 |
def demo_app_name(name):
""" Returns a capitalized title for the app, with "Dash"
in front."""
return 'Dash ' + name.replace('app_', '').replace('_', ' ').title() | 58e39a80c1940f784daa6e0f6ee35df2757c5ca6 | 697,178 |
def parse_italic(soup):
""" Replace i tags with text:span with automatic style """
italic_tags = soup.find_all("em")
for i_tag in italic_tags:
i_tag.name = 'text:span'
i_tag.attrs['text:style-name'] = "ITALIC"
return soup | c2c58afa0a68328088900e5324f4908d74ddbb94 | 697,181 |
def to_dict(condset: set) -> dict:
"""
Create a dictionary of conditions with a unique integer value for each
condition.
:param condset: Conditions set.
:return: Dictionary of all conditions with integer values.
"""
conds = {}
index = 0
for item in condset:
conds[str(item)] =... | 3fd9953139ac3785aeb2ba527bc0365e3908f376 | 697,185 |
def GL2PL(gl):
""" Converts Genotype likelyhoods to phred scaled (PL) genotype likelyhoods. """
return -int(gl * 10) | d842a4a25ee6b095cfb456ab21965df4ccc24c1d | 697,189 |
import socket
def port_to_int(port):
"""Convert a port string to an integer."""
try:
return int(port)
except ValueError:
return socket.getservbyname(port) | 9f4ca2d80fdb70e16aaa0f0ccfa027fed772a986 | 697,191 |
def expand_markings(granular_markings):
"""Expand granular markings list.
If there is more than one selector per granular marking. It will be
expanded using the same marking_ref.
Example:
>>> expand_markings([
... {
... "selectors": [
... "descri... | 1d97c93b7953293cd71a86d06e988373f0a9150d | 697,192 |
def first_nonequal_idx(left: str, right: str) -> int:
"""
Find first string index where left and right strings do not match
In [1]: first_nonequal_idx("", "californian")
Out[1]: 0
In [2]: first_nonequal_idx("aba", "abc")
Out[2]: 2
Note, if the strings match, the first-non-... | 7bc0397dd290c6005adc96b8b45f14e04385a257 | 697,194 |
def is_viable_non_dupe(text: str, comparison) -> bool:
"""text must be longer than 2 ('""'), not 'NULL' and not in comparison.
:param text: String to be tested.
:param comparison: Dictionary or set to search for text in.
:return: bool
"""
return 2 < len(text) and text != 'NULL' and text not in ... | da575dffde2f13e849949350aabe73f40802f14a | 697,200 |
def _proc(tr, sampling_rate=10):
"""
Basic processing including downsampling, detrend, and demean.
:param tr: raw trace
:param sampling_rate:
:return tr: trace after processing
"""
# deep copy
tr2 = tr.copy()
tr2.interpolate(sampling_rate)
tr2.detrend(type="linear")
tr2.detr... | 99dab5d384b9db80b257c8bd0068f96cbc82c532 | 697,202 |
def get_neighbors(point):
"""Given a 2D point (represented as a Point object), returns a list of the
four points that neighbor it in the four coordinate directions. Uses the
"copy" method to avoid modifying the original point."""
p1 = point.copy()
p2 = point.copy()
p3 = point.copy()
p4 = poi... | 67df39fe0d6fd61fed70f1521b13754d1230ac9e | 697,203 |
from typing import Dict
def read_config(return_config: str, config: Dict):
"""
Reads the config file and goes through the config dictionary to load all of the parameters.
Depending on whether return_config is dashboard or logger it returns the necessary information to create the
dashboard or the logge... | cc91ebe633f01259fa3344f93698ab806ee9d9fc | 697,206 |
def total_yngve_depth(yngve_tree_root):
"""Returns the total depth of the ynvge tree of the sentence
Args:
yngve_tree_root (obj): The root node
Returns:
int: The total depth of the yngve tree
"""
tot_score = 0
for leaf in yngve_tree_root.leaves:
tot_score += leaf.score
return tot_s... | 9220147ed529bac780b7cb5e60ab2364af47f9f6 | 697,209 |
def is_function(f):
"""
Is it a function?
:param f: function
:return: boolean
"""
return hasattr(f, '__call__') | c330b81c3b09a0ba8e475e322df5f90d89e39e21 | 697,210 |
def inRects(R, x, y):
"""inRects returns True if (x, y) is in any of the rectangles in R.
"""
return any(x0 <= x < x1 and y0 <= y < y1 for x0, y0, x1, y1 in R) | f2e4a5c5d60e4f37ee1a8ec9d54a050b3e12b022 | 697,211 |
def load_corpus(corpus_path, proc_mode=0):
"""Load the corpus from disk."""
corpus_text=""
with open(corpus_path, 'r') as corpusFile:
corpus_text=corpusFile.read()
return corpus_text | 045ed4aa97a6e685edefaf03d8f45cd5afb51526 | 697,214 |
import token
def decompose_name(node):
"""
NOTE: Per the lib2to3 grammar:
dotted_name: NAME ('.' NAME)*
This means that dotted_name can be either dotted or not dotted, i.e. it's a generalized
form of NAME. So this function will cover both cases.
Given a dotted_name node th... | 2be377913f6dd2a13335d29b0f932de6ebe35c12 | 697,216 |
from pathlib import Path
from typing import Callable
from typing import List
def find_paths(path: Path, pattern: str, filter: Callable[[Path], bool]) -> List[Path]:
"""
Glob pattern relatively to path and filter results by predicate.
"""
return [x for x in sorted(path.glob(pattern), key=str) if filter(x)] | cce368e6dc3b97f715b3f82a5cc5837942d600b9 | 697,218 |
def abv(og, fg, from_carbonation=0):
"""Work out alcohol content from fermentation data (optionally including carbonation)
"""
value = (float(og) - float(fg)) / 1.938 + float(from_carbonation)
return float(value) | d3cf1e0c645d07bf98c70f1b087f0f1213e4bf21 | 697,221 |
def find_remote_addr(req):
"""Determine the correct IP address of the requester."""
if req.headers.get('CF-Connecting-IP'):
return req.headers.get('CF-Connecting-IP')
if req.headers.get('X-Forwarded-For'):
return req.headers.get('X-Forwarded-For')
return req.remote_addr | ddef91a116fb47a12acd71417b70af88484fd780 | 697,225 |
def get_rectangle_edges(x, y, width, height):
"""Return the 4 edges of a rectangle as a list.
Edges are in clock-wise order, starting from the top.
Each edge is returned as ``(start_point, end_point)`` and each point
as ``(x, y)`` coordinates.
"""
# In clock-wise order, starting on top left
... | e0738bd8d742eb9f9ae076e2e89031cd8eb74796 | 697,232 |
import math
def comb(n,r):
"""Combinations of n objects by r, namely picking r among n possible.
comb(n,r) = n!/(r!(n-r)!)
"""
return math.factorial(n)/(math.factorial(r)*math.factorial(n-r)) | 61944512cec3555bc15efb73e1ca90510c86caa9 | 697,234 |
import re
def safe_dag_id(s: str) -> str:
"""
Remove invalid characters for dag_id
"""
return re.sub('[^0-9a-zA-Z_]+', '_', s) | 950dd59baaea5b0a94b1d5f67e8699c8779dae15 | 697,239 |
import yaml
def unicode_representer(self, value):
"""
Represents unicode strings as regular strings.
"""
return yaml.ScalarNode(tag='tag:yaml.org,2002:str', value=value) | 7eaa92e17be6fa707cb84cdea877ee451dc48694 | 697,240 |
def rnn_args_from_config(rnn_config):
"""
Takes a Config object corresponding to RNN settings
(for example `config.algo.rnn` in BCConfig) and extracts
rnn kwargs for instantiating rnn networks.
"""
return dict(
rnn_hidden_dim=rnn_config.hidden_dim,
rnn_num_layers=rnn_config.num_l... | 54cf542122036510c70fe7a53a47dd724880a912 | 697,242 |
from typing import Any
from typing import Tuple
from typing import Dict
import json
def flask_http_response(status: int, data: Any) -> Tuple[str, int, Dict[str, str]]:
"""Create a tuple for flask to return
Args:
status: integer http status to use
data: json dumpable data for the return body
... | 33584b4c66f08174ca7ad93e1b11193707a65892 | 697,244 |
import requests
def get_response_commits(commits_url, my_token):
"""
Wrapper around the function `requests.get()`.
If my_token is supplied by me (i.e. it's not an empty string), then use authentication.
Otherwise, go ahead without authentication.
Args:
commits_url: URL with JSON metad... | 7d8350540944aef18631b9122e1180d21f9a6f8a | 697,247 |
def get_locale_parts(locale):
"""Split a locale into three parts, for langauge, script, and region."""
parts = locale.split('_')
if len(parts) == 1:
return (parts[0], None, None)
elif len(parts) == 2:
if len(parts[1]) == 4: # parts[1] is a script
return (parts[0], parts[1], ... | 6a2a5f8600470ff13323482c478dcb1494b410a7 | 697,249 |
import re
def strip_markdown_directives(line):
"""strips markdown directives from a line"""
line = line.strip()
if line.startswith("<") and line.endswith(">"):
# Let's assume it's inline HTML and skip it
return ""
# Remove URLs (assume remote starts with http and local ends with html)... | 8a1ad9076d058ecabbce0720d3c960601c14e3de | 697,250 |
import random
def pick_random_worker_set(worker_sets):
"""Pick random set of workers"""
return random.choice(worker_sets) | 86725e54659e0577ef5ff548e0b997261f876c75 | 697,251 |
import json
def is_valid_json(stuff):
"""Checks if a string is valid json."""
try:
json.loads(stuff)
except:
return False
else:
return True | f949b00d31fe682c1974e93619a79a573802a2fe | 697,253 |
def package_installed(module, package_name):
"""
Determine if the package is already installed
"""
cmd = ['pacman', '-Q', package_name]
exit_code, _, _ = module.run_command(cmd, check_rc=False)
return exit_code == 0 | 5382a160e3c55d23bcf20b6bd8d360b11cd71410 | 697,254 |
def set_ipu_model_options(opts, compile_ipu_code=True):
"""Set the IPU Model options.
Args:
compile_ipu_code: Whether or not to actually compile real IPU code for
modelling.
Returns:
The IpuOptions configuration protobuf, with IPU model options set.
"""
opts.ipu_model_config.compile_ipu_code =... | d5e9577fb9ebad81b6fedb1988561197dbd3028e | 697,255 |
def _ExtractResNetThroughput(output):
"""Extract throughput from Horovod output.
Args:
output: Horovod output
Returns:
A tuple of:
Average throuput in images per second (float)
Unit of the throughput metric (str)
"""
# Start from last line and iterate backwards.
avg_throughput = 0
fo... | 671d745b0f73e9a84fa9a8b55f45054c711329c0 | 697,256 |
from typing import Any
def map_index(x: Any, column_map: dict) -> str:
"""Makes column list index human-readable."""
return f'{column_map[x]}' | ab7c371cbcb9949e66a9a8adcc153c2e85646d01 | 697,257 |
def clsName2Ind(lbls, cls):
"""
Converts a cls name to an ind
"""
if cls in lbls:
return lbls.index(cls) + 1
else:
raise ValueError('unknown class') | 15676bb297e42562a02b7e9af0c8d9de6fb890df | 697,263 |
import six
def load_from_hparams_overrides(params, params_source, hparams_overrides):
"""Given a dictionary of hyperparameters and a list of overrides, merge them.
Args:
params: Python dict containing a base hyperparameters set.
params_source: Python dictionary to record source of hyperparameters.
hp... | 2365a3ce67d4855662912bbd865e1e731648e7b1 | 697,266 |
def flatten_report_for_csv(report):
"""
Flattens the data structure returned by `watson.report()` for a csv export.
Dates are formatted in a way that Excel (default csv module dialect) can
handle them (i.e. YYYY-MM-DD HH:mm:ss).
The result is a list of dictionaries where each element can contain t... | a7af0385bb846aa7d88e5e5ef939c40712ea5f2e | 697,267 |
import re
def postfinance_preprocess_notice(payment_notice):
"""Remove spaces from potential invoice numbers"""
return re.sub(
r"\b([0-9]{4}\s*-\s*[0-9]{4}\s*-\s*[0-9]{4})\b",
lambda match: re.sub(r"\s+", "", match.group(0)),
payment_notice,
) | ce806fda4c63030b21d3e1747d31349b3757dadb | 697,270 |
import ipaddress
def _evaluate_ip_address(ip_address):
"""Evaluate supplied IPv4 address.
Returns the supplied IPv4 address if valid and specified without a
netmask, or returns the subnet broadcast address if the supplied
IPV4 address is specified with a netmask such as '192.168.1.5/24' or
'192.1... | 67b45d1ba169c9880c68d800efb944ff05f2c51b | 697,275 |
from typing import Callable
def get_linear_anneal_func(
start_value: float, end_value: float, start_step: int, end_step: int
) -> Callable:
"""Create a linear annealing function.
Parameters
----------
start_value : float
Initial value for linear annealing.
end_value : float
Te... | affe767318be5b07dfcf23d1a3e2e58e67750611 | 697,276 |
def bump_version(base: str, index: int = -1) -> str:
"""
Increment one of the numerical positions of a version.
:param base: Version core, such as 0.1.0.
Do not include pre-release identifiers.
:param index: Numerical position to increment. Default: -1.
This follows Python indexing rule... | 48d5c85c106e87733702f33dfcdd7c654478949e | 697,279 |
import torch
def ssim(prediction: torch.Tensor, label: torch.Tensor) -> torch.Tensor:
"""
Function computes the structural similarity
Source: https://github.com/ChristophReich1996/CellFlowNet
:param prediction: (torch.Tensor) Prediction
:param label: (torch.Tensor) Label
:return: (torch.Tensor... | 2cdf069823f195f9730b13d00d48a25c13bc4884 | 697,280 |
def get_network_id(networks, name):
"""
Get network id based on name provided
"""
for network in networks:
if network["Name"] == name:
return network["Id"] | 12e53ade2d661587a674435d8c57160d740aa48c | 697,286 |
import torch
def normal_transform_pixel(shape):
""" Compute the normalization matrix from image size in pixels to [-1, 1].
"""
tr_mat = torch.tensor([[1.0, 0.0, 0.0, -1.0],
[0.0, 1.0, 0.0, -1.0],
[0.0, 0.0, 1.0, -1.0],
[0.0, ... | 8f178255108e565d9156cb01a8da5b88cd46c73a | 697,288 |
def read_messages(msg_file):
"""(file open for reading) -> list of str
Precondition: The parameter msg_file should be a message file that is
already open for reading and that file contains one message per line.
Read and return the contents of the file as a list of messages. The returned
message s... | 220cda7e055f9c3b6a483500fe3aeef7d9752b70 | 697,295 |
from typing import Dict
from typing import List
def avoid_body(my_head: Dict[str, int], body: List[dict]):
"""
my_head: Dictionary of x/y coordinates of the Battlesnake head.
e.g. {"x": 0, "y": 0}
my_body: List of dictionaries of x/y coordinates for every segment of a Battlesnake.
... | 3d7a151b694c6a6915f9c7c508cf7cd0e2e4d6f0 | 697,298 |
def get_area(a, b):
"""Calculate area of rectangle with sides a and b."""
return a * b | 2907400c82c018634daf51091b509ab65258c269 | 697,301 |
def macro_with_both(name, number = 3, *args, **kwargs):
"""Oh wow this macro has both.
Not much else to say.
Args:
name: The name of the test rule.
number: Some number used for important things
*args: Other arguments to include
**kwargs: Other attributes to include
Returns:
... | b1d1fce22662830de6ea1a9c3eee677c48c65a23 | 697,303 |
def increment_duplicates(arr):
"""Increments duplicates in an array until there are no duplicates.
Uses a hash set to keep track of which values have been seen in the array.
Runs in O(n^2) time worst case (e.g. all elements are equal),
O(n) time best case (elements are already unique).
"""
seen... | 33a456c75b7ca00ddb535a6726af3fe1944efc21 | 697,305 |
def _date(api):
"""Returns UTC YYYY.MM.DD to use in tags."""
return api.time.utcnow().strftime('%Y.%m.%d') | 91e5c4c0bafa00b33e2b9c22d28b255a50f0d091 | 697,309 |
def lreplace(a, b, string):
""" Replaces the head of the string.
"""
if string.startswith(a):
return b + string[len(a):]
return string | 73ac9d588c98350699bdcd0e2ea70035cd17c77c | 697,312 |
import torch
def one_hot_encode(y: torch.Tensor, num_classes: int) -> torch.Tensor:
"""
Creates the one hot encoding of the provided class labels.
:param y: class labels of size (batch_size,)
:return y_one_hot: one hot encoding of size (batch_size, num_classes)
"""
return torch.zeros(y.size(... | ba1cc5d556e17fa7d797efa32e697a9bdac4a3c0 | 697,313 |
def color_distance(c1, c2):
"""
Metric to define the visual distinction between two (r,g,b) colours.
Inspired by: https://www.compuphase.com/cmetric.htm
:param c1: (r,g,b) colour tuples. r,g and b are values between 0 and 1.
:param c2: (r,g,b) colour tuples. r,g and b are values between 0 and 1.
... | 1f63d563d71373d7c27e446794745bcb2631e013 | 697,314 |
def tochr(lst):
"""Converts every value of a list into a character"""
return [chr(i) for i in list(lst)] | 36bf8ead73aaf079cbf1f2d5f3cd243266f7fbd2 | 697,315 |
def find_pareto_front(population):
"""Finds a subset of nondominated individuals in a given list
:param population: a list of individuals
:return: a set of indices corresponding to nondominated individuals
"""
pareto_front = set(range(len(population)))
for i in range(len(population)):
... | 2e53edda5e3d3afd541cedff3bb3d247f913969c | 697,316 |
def __walk_chain(rel_dict, src_id):
"""
given a dict of pointing relations and a start node, this function
will return a list of paths (each path is represented as a list of
node IDs -- from the first node of the path to the last).
Parameters
----------
rel_dict : dict
a dictionary ... | 24b3bea13f7d802043b595e48bedc6da2a782370 | 697,317 |
from typing import Any
import importlib
def dynamic_import_from(source_file: str, class_name: str) -> Any:
"""Do a from source_file import class_name dynamically
Args:
source_file (str): Where to import from
class_name (str): What to import
Returns:
Any: The class to be imported
... | 90c861f727c8e6f20f89b7af24c2163bc65bd516 | 697,319 |
def findAllPerson(tx):
"""
Method that finds all the nodes Person in the data base
:param tx: is the transaction
:return: a list of nodes
"""
query = (
"MATCH (p:Person) "
"RETURN p , ID(p);"
)
results = tx.run(query).data()
return results | c5e5af2c1267b7bc057135dc4cb64e2bb2c23198 | 697,323 |
def integral_image(image):
"""Create an integral image on the first 2 dimensions from the input.
Args:
image -- ndarray with ndim >= 2
Returns an integral image where every location i,j is the cumulative sum
of all preceeding pixels.
"""
return image.cumsum(1).cumsum(0) | 567228d7089db2a58047bd5123a371c516198ab1 | 697,324 |
def hex_short(value):
"""
Give an integer in value, convert it to a hexidecial but remove the 0x
:param value: the integer
:return: the shorted version of hex
"""
hex_value = hex(value)[2:]
if len(hex_value) == 1: hex_value = f"0{hex_value}"
return hex_value | d7bb12b06001c44bdddfbe0c4f8d810c27862601 | 697,328 |
def lca(T, v, w):
"""
The lowest common ancestor (LCA) of two nodes v and w in a tree or directed
acyclic graph (DAG) T is the lowest (i.e. deepest) node that has both v and
w as descendants, where we define each node to be a descendant of itself
(so if v has a direct connection from w, w is the low... | 1f0235c6364803aae4a28a9ad72ab433f22ef2a5 | 697,330 |
import re
def is_uuid(uuid):
"""
Check if value is a proper uuid
:param uuid: string to check
:return: bool
"""
UUID_PATTERN = re.compile(r'^[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12}$', re.IGNORECASE)
if UUID_PATTERN.match(uuid):
return True
return False | 091464f66018c9913c19dcf307c1e193348c7023 | 697,331 |
from pathlib import Path
import json
def parse_annotation_background_width(bpmn_path: Path):
"""Get the width the image was resized to when annotating in the BPMN Annotator tool"""
assert bpmn_path.suffix == ".bpmn", f"{bpmn_path}"
img_meta_line = bpmn_path.read_text().split("\n")[1]
assert img_meta_l... | aa1315aa2301a823d5e6fe83089698edd7600e4b | 697,332 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.