content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def parse_cfg(filename):
"""
Inputs:
- cfg's file name, e.g. 'yolov3.cfg'
Returns:
- a list of NN blocks, each block is represented as a dictionary
"""
file = open(filename, 'r')
lines = file.read().split('\n')
lines = [x.rstrip().lstrip() for x in lines if len(x) > 0 an... | f953dfa6304732572c058a01b42de83f1dbc9eb5 | 695,598 |
def _cnx_is_empty(in_file):
"""Check if cnr or cns files are empty (only have a header)
"""
with open(in_file) as in_handle:
for i, line in enumerate(in_handle):
if i > 0:
return False
return True | 1f5706e3b3733527baedd4df240f0be88adb80a5 | 695,603 |
def from_none(exc):
"""Emulates raise ... from None (PEP 409) on older Python-s
"""
try:
exc.__cause__ = None
except AttributeError:
exc.__context__ = None
return exc | 1cf96c58c7ef601a98a6891d2f969da8799f99b2 | 695,604 |
def error_503(_):
"""Maintenance."""
return 'PixyShip is down for maintenance', 503 | 3acecece1da3191d699fd58ebcd840494cf31b4c | 695,605 |
def cleanup_time_string(t):
"""
convert from microseconds to seconds, and only output 3 s.f.
"""
time_in_seconds = float(t) / 1e6
if time_in_seconds < 1:
time_in_seconds = round(time_in_seconds, 5)
else:
time_in_seconds = int(time_in_seconds)
timestring = str(time_in_seconds... | dccbab566aa4112468cfa7ea0d059475ad76d65b | 695,606 |
def anyfalse(bools):
"""Returns True iff any elements of iterable `bools` are False
>>> anyfalse([True, True])
False
>>> anyfalse([True, False, True])
True
>>> anyfalse(None)
False
"""
if bools is None: return False
for b in bools:
if not b:
return True
r... | 1d846b588705349b8fb8f0fd8593c0c87809bd5d | 695,610 |
def hexify(env, req):
"""
Convert integer parameter to hex
"""
return str(hex(int(req.match.group(1)))) | ea70d5df380e08cad60247345aa6b22c5eb6bb66 | 695,614 |
def corners_to_center_scale(p0, p1):
"""Convert bounding boxes from "corners" form to "center+scale" form"""
yx = 0.5 * (p0 + p1)
hw = p1 - p0
return yx, hw | ea313fbe774d29c4b05a886323425730a1b409af | 695,616 |
def wait(method):
"""
Decorator to wait for previous timers and to start a new one on exit
:param:
- `method`: method to wrap with a timer.wait call
:return: wrapped method
"""
def _method(self, *args, **kwargs):
# wait if timer is running but only up until the time-limit
... | c02bede214a3891ea50bc317db123dd3d32e8044 | 695,617 |
def condition_domain_reduction(csp, var) :
"""Returns True if var should be enqueued under the all-reduced-domains
condition, otherwise False"""
return True | 968c44431058d9c1007bb11f4f247c70e6865a71 | 695,618 |
def log_url(ip, port, project, spider, job):
"""
get log url
:param ip: host
:param port: port
:param project: project
:param spider: spider
:param job: job
:return: string
"""
url = 'http://{ip}:{port}/logs/{project}/{spider}/{job}.log'.format(
ip=ip, port=port, project=... | 2e61796b213698bc70b1ebf968d31fa678e8258e | 695,620 |
def format_for_null(value):
"""If a Python value is None, we want it to convert to null in json."""
if value is None:
return value
else:
return "{}".format(value) | 004ada8d8496705c2afd42b82feef3c7a6e38079 | 695,627 |
def getIIsum(data, U, B):
"""
Compute summed area as:
A=U Bi=U[0],B[1]
+----------+
| |
| |
+----------+
C=B[0],U[1] D=B
\sum = I(D) - I(A) + I(Bi) + I(C)
"""
if (U == B):
return data[U]
else:
return (data... | 25f1b937036323a17465382df6a076f3269775fd | 695,629 |
def _addHeaderToRequest(request, header):
"""
Add a header tuple to a request header object.
@param request: The request to add the header tuple to.
@type request: L{twisted.web.http.Request}
@param header: The header tuple to add to the request.
@type header: A L{tuple} with two elements, the... | a42f99b922b5234671360b93d0a6326ca24cf6a2 | 695,631 |
import click
def _validate_month(ctx, param, val):
"""Helper function to validate a month coming from the CLI."""
if val < 1 or val > 12:
raise click.BadParameter('Month must be between 1 and 12')
return val | a38de3a9d62a38f90e12fad675a810eadf9fee22 | 695,632 |
def softmax_est_crossentropy_deriv(y_est, y):
"""
Compute the gradient of the multiclass softmax cross-entropy
with respect to its input variables, given only the output
of the softmax function
Parameters
----------
y_est: ndarray(N)
Output of the softmax function
y: ndarray(N)
... | f2519967529c3fe79322898391a347eaf306c804 | 695,633 |
def nvl(value, default=''):
"""Get specified value, or an empty string if value is empty
:param object value: value to be checked
:param object default: default value to be returned if value is *false*
:return: input value, or *default* if value is *false*
>>> from pyams_utils.unicode import nvl
... | 5334bc6e5a142e217bc40600bd493bd0c39b037c | 695,641 |
def njit_time_point_thresh(wf_in, threshold, tp_max, tp_out):
"""
Find the last timepoint before tp_max that wf_in crosses a threshold
wf_in: input waveform
threshold: threshold to search for
tp_max: time of a maximum of a waveform that the search starts at
tp_out: final time that waveform i... | cebeecb4bc176bb72015b28aedaf6b0ddca8e1b6 | 695,644 |
def _path_to_release(path):
"""Compatibility function, allows us to use release identifiers like "3.0" and "3.1"
in the public API, and map these internally into storage path segments."""
if path == "v3":
return "3.0"
elif path.startswith("v3."):
return path[1:]
else:
raise R... | 84ea8a22e3a1d82df249161fd76b12c370f70742 | 695,654 |
def bitwise_or(first_value, second_value):
"""Perform a bitwise or operation."""
return first_value | second_value | 21cd3ba65fded59c152183445e59f1aa99b4c72e | 695,659 |
import warnings
def assert_warns(wtype, f, *args, **kwargs):
"""Check that a function call `f(*args, **kwargs)` raises a warning of
type wtype.
Returns the output of `f(*args, **kwargs)` unless there was no warning,
in which case an AssertionError is raised.
"""
# Check that f() raises a warn... | aa27979e2c9bba268a676ed070296e52add7b210 | 695,664 |
import hashlib
def get_fingerprint(contents: str) -> str:
"""
Generate a fingerprint for the contents of a virtual relation.
This fingerprint is used by the server for caching purposes.
:param contents: The full contents of a tsv file
:returns: md5 sum representing the file contents
"""
... | 65dd77ca873b8928af5af1f3ea036555e835c418 | 695,667 |
def crop_image(frame, bbox):
"""Return the cropped image from frame specified by bbox"""
x_start, x_end = int(bbox[0]), int(bbox[2])
y_start, y_end = int(bbox[1]), int(bbox[3])
crop_img = frame[y_start:y_end, x_start:x_end, :].copy()
return crop_img | 702477cd6c98a6170d254b3837d2dfbd605d8ae3 | 695,669 |
import math
def GeometricMean(values):
"""Compute a rounded geometric mean from an array of values."""
if not values:
return None
# To avoid infinite value errors, make sure no value is less than 0.001.
new_values = []
for value in values:
if value > 0.001:
new_values.append(value)
else:
... | bd1bb53943c8db09c18f1e4710c36000fa07671d | 695,670 |
from typing import Tuple
import string
def return_c_values(cardinality: int) -> Tuple[list, list]:
"""Return categorical values for C+ and C-.
Create string values to be used for the categorical variable c.
We build two sets of values C+ and C-. All values from C+ end with
"A" and all values from C-... | 7b25599b2fb9efb1f053317d19f94f73b5889a36 | 695,671 |
import torch
def mat2euler(mat):
""" Convert rotation matrix to euler angles.
https://github.com/pulkitag/pycaffe-utils/blob/master/rot_utils.py#L283
Args:
mat: rotation matrix in zyx format -- size = [B, 3, 3]
Returns:
angle: rotation angle along 3 axis (in radians, it's not uni... | a940f61fd00ce28c01bce7704920a49cf8bab8eb | 695,674 |
import json
def read_shapefile_data(path,file_name):
"""
Reads in a json file containing the path to shapefiles,
on regional, province and municipality level
and crs foe encoding
"""
d=json.load(open(path+file_name))
path_shapefiles=d["path_shapefiles"]
regions=d["regions"]
provi... | b209b594debabcd26f5cd8dd6a8f41fac0207560 | 695,676 |
def zstrip(chars):
"""Strip all data following the first zero in the string"""
if '\0' in chars:
return chars[:chars.index("\0")]
return chars | 0c03f677008b6195723f3d62e55f108d4d265742 | 695,678 |
from typing import Tuple
def channel_error(input_shape: Tuple[int, int, int]) -> ValueError:
"""
Value Error Message for Channel Error
:param input_shape: Three Int Tuple
:return: Custom text Value Error
"""
return ValueError(
f"The input must have 3 channels; got `input_shape={str(inp... | a74db84d57f95524fd95e7f2d7225308949369cd | 695,679 |
import json
def _json_dumps(value):
"""
json.dumps parameters for dumping unicode into JS
"""
return json.dumps(value, separators=(",", ":"), ensure_ascii=False) | 79a9d8b51df110ce19baa6a022d38a24a8492591 | 695,680 |
def _extended_gcd(a, b):
"""Returns (g, x, y) such that a*x + b*y = g = gcd(a, b)"""
x, x_old, y, y_old = 0, 1, 1, 0
while a != 0:
(q, a), b = divmod(b, a), a
y, y_old = y_old, y - q * y_old
x, x_old = x_old, x - q * x_old
return b, x, y | e96a65990cc9e6165867ccfd7756dcf0ae2b33d8 | 695,681 |
def guess_type(text):
"""
Guess the type of a value encoded in a string.
"""
# int
try:
int(text)
return int
except:
pass
# float
try:
float(text)
return float
except ValueError:
pass
# string
return str | bd2c7fa52ff4ee79f87d9018493ccb3f1394daa6 | 695,682 |
import math
def list_values_approx_equal(num_list, rel_tol):
"""
Check if all values in a list are within a relative tolerance of each other
:param num_list: List of numbers
:param rel_tol: The relative numerical tolerance
:return: Truth value
"""
for i in range... | 02007cbdbc5591cf33f64946f9d80bb8eb69b4ee | 695,685 |
def sqlobj_from_dict(obj, values):
"""
Merge in items in the values dict into our object if it's one of our columns.
"""
for c in obj.__table__.columns:
if c.name in values:
setattr(obj, c.name, values[c.name])
# This return isn't necessary as the obj referenced is modified, but ... | 2aa65226f5bc5abb9870ab4a9e414dff691beaa7 | 695,688 |
def _get_working_shape_and_iterations(requested_shape, max_power_of_two=13):
"""Returns the necessary size for a square grid which is usable in a DS algorithm.
The Diamond Square algorithm requires a grid of size n x n where n = 2**x + 1, for any
integer value of x greater than two. To accomodate a reques... | c5f61347c17cc584d68dc6cccae7cd78c4a15906 | 695,689 |
def unmap_from_unit_interval(y, lo=0., hi=1.):
""" Linearly map value in [0, 1] to [lo_val, hi_val] """
return y * (hi - lo) + lo | 35a6dfbad855f80fa2034eb88cb41fcedc9a00d5 | 695,691 |
def parse_raw(sqlContext, input, user):
"""Parses the raw json for a user"""
df = sqlContext.read.json(input + "/" + user + "/" + user + ".json", multiLine=True)
return df | f8ff9544e222d92aa3825d9739ddec7d5970e8e5 | 695,693 |
def get_run_id_keys(json_results, run_id_list):
"""This function finds the key used in the json_results dictionary
for a given run ID. These dictionary keys are the files names and
there are potentially many keys that are associated with a run ID.
For the intended purposes of this function (metadata com... | c3550508576fe595b01c2569c64d889f2edf07dc | 695,696 |
def make_uniform(planes_dict, uniques, padding):
""" Ensure each section has the same number of images
This function makes the output collection uniform in
the sense that it preserves same number of planes across
sections. It also captures additional planes based
on the value of the padding variab... | 8f67f7226dcf8846707f9d190eb9b15ccb1b27e9 | 695,700 |
import contextlib
import wave
def read_wave(path):
"""Reads a .wav file.
Takes the path, and returns (PCM audio data, sample rate).
"""
with contextlib.closing(wave.open(path, 'rb')) as wf:
num_channels = wf.getnchannels()
# print(num_channels)
assert num_channels == 1
... | 6c2aa73a313147f99992a2d2523a1ce1d7c5252b | 695,703 |
def calc_install(runs, cost_index, system_index, tax_rate):
"""
Calculate total install cost for a manufacturing job.
:param runs: Number of runs in the job.
:param cost_index: Cost Index for the item.
:param system_index: Cost Index for the star system where construction
would occur.
... | bf0b9da1f07e6e10008f4a1e1e498d1d3d6845bd | 695,719 |
def end_game(game, *args):
"""Ends the game."""
end_message = args[0]
print(end_message)
return True | 71b1aaa0d5c24e5a16c7f6acd2226a5042401f0e | 695,721 |
def is_boundary(horizon, x):
"""
Function which marks displacement boundary constrained particles
2 is no boundary condition (the number here is an arbitrary choice)
-1 is displacement loaded IN -ve direction
1 is displacement loaded IN +ve direction
0 is clamped boundary
"""
# Does not ... | 0e8252be537ab72b2a469e2d3eadb0d1336b6326 | 695,722 |
from math import floor, log10
def sci_notation(num, decimal_digits=1, precision=None, exponent=None):
"""
Returns a string representation of the scientific
notation of the given number formatted for use with
LaTeX or Mathtext, with specified number of significant
decimal digits and precision (numb... | 4990887697d86a5ce5453f289c559991652c5269 | 695,723 |
import re
def split_hostname_index(name, default=None):
"""
Split the index out of a hostname.
E.g. splits "test^1" into ("test", 1). If no index is present, returns
(name, default).
"""
match = re.match(r'^(.*)~(\d+)$', name)
if match:
return match.group(1), int(match.group(2))
... | eb4d036e0cdc96d43d1a23946a56f48f88d887c8 | 695,725 |
from datetime import datetime
def footer_datetime(timestamp: str) -> datetime:
"""Takes an embed timestamp and returns a timezone-aware datetime object."""
return datetime.fromisoformat(timestamp) | a7c26eb6c4855af55eaaaee1f28a46d9a14934bf | 695,726 |
def v6_int_to_packed(address):
"""Represent an address as 16 packed bytes in network (big-endian) order.
Args:
address: An integer representation of an IPv6 IP address.
Returns:
The 16-byte packed integer address in network (big-endian) order.
Raises:
ValueError: If address is... | 5f4bb8cbed9f1cddace9c0257efc6f5ec2e2d78d | 695,732 |
def tokenizer(x):
""" Trivial tokenizer """
return x | 49b9559363def5686c254164d9038087c29d3e66 | 695,735 |
def binary_to_decimal(binary):
"""Converts a binary number(str) into a decimal(int)"""
reversed_binary = binary[::- 1]
# i = corresponds to power of 2 when reversed
decimal = 0 # keep track of sum
for i, value in enumerate(reversed_binary):
if value == "0":
continue # ignore 0 ... | c5a25cc9594f52e886b1b2a7d10667de709e5d0b | 695,742 |
def short_hex(value):
"""
Convert to a nice hex number without the 0x in front to save screen space
:param value: value
:return: short string hex representation
"""
hex1 = hex(value)
hex2 = hex1[2:]
if len(hex2) == 1: hex2 = "0" + hex2
return hex2 | 8d8c0b28c02dc3ba6a13c12fb4e44cb3e1229c7c | 695,743 |
def find_subtractive_combinations(string):
"""
Finds subtractive combination pairs in string.
PARAMETERS:
string : str
RETURNS: ( (str pair, int index), ... )
Tuple containing all ordered subtractive combination pairs found and the respective index at which they start
"""
ivxlc... | b3fdc589e98d69ac4af9be219853a8e82f24a43a | 695,744 |
def swap_columns(a, b, array):
"""
Function that swaps columns of a given matrix
:param a: int
:param b: int
:param array: numpy array
:return: array_swapped: numpy array with the columns swapped
"""
array_swapped = array.copy()
array_swapped[:, a] = array[:, b]
array_swapped[:, ... | 40b848b24c6047d6faf7f07c0e9a5e18d78101fc | 695,745 |
import string
import random
def random_string(length):
"""Generate random string of the given length."""
pool = string.ascii_letters + string.digits
return "".join(random.choice(pool) for _ in range(length)) | f5e83dd2215d708b0ce5f8bd3e344b8fed12277d | 695,746 |
def parse_zone_groups(player):
"""Creates a list of all Zones with attrbute
whether they are a group or a single player"""
all_zones = []
for group in player.all_groups:
if len(group.members) > 1:
all_zones.append({"kind":"G", "master":group.coordinator})
else:
al... | c5074a3b88f661dcc0e310e2447071348ecf346f | 695,748 |
def get_default_memory_overhead(memory):
"""
The default memory overhead (related to both driver and executor) depends on how much memory is used: 0.10*memory,
with minimum of 384 MB.
:param memory: driver or executor memory
:return: default memory overhead
"""
MINIMUM_OVERHEAD = 384 << 20 ... | 25db1cfe67651cf0b32371e2d8a056b5215e264a | 695,749 |
def _difference(idxs):
""" Returns the chained difference of the indexes given.
Parameters
----------
idxs : list
List of pandas.Index objects.
Returns
-------
idx : pandas.Index
The result of the chained difference of the indexes
given.
"""
idx = idxs[0]
... | d48e491f0c145d4286bf6c7675e0b511d39b87a4 | 695,752 |
def load_stopwords( inpath = "text/stopwords.txt" ):
"""
Load stopwords from a file into a set.
"""
stopwords = set()
with open(inpath) as f:
lines = f.readlines()
for l in lines:
l = l.strip()
if len(l) > 0:
stopwords.add(l)
return stopwords | 5e733e97a3f56867d80edeb3db5a392362a23fe1 | 695,754 |
def ppr(b2, b3):
"""
Plant Pigment Ratio (Metternicht, 2003).
.. math:: PPR = (b3 - b2)/(b3 + b2)
:param b2: Blue.
:type b2: numpy.ndarray or float
:param b3: Green.
:type b3: numpy.ndarray or float
:returns PPR: Index value
.. Tip::
Metternicht, G. 2003. Vegetation indic... | 77a071d3c437dc3f202f6c7a35147c7473e17749 | 695,756 |
def get_file_extension(file_name):
"""e.g.: "/home/j/path/my.video.mp4" -> ".mp4"
Throws an exception, ValueError, if there is no "." character in file_name
:param file_name: <str> any string or path that is the name of a file
:return: the file extension of the param
"""
return file_name[file_na... | 03789c21b6478f8cfa2707697e74f8d51995923b | 695,764 |
def pg_utcnow(element, compiler, **kw):
"""
Postgres UTC timestamp object
"""
return "TIMEZONE('utc', CURRENT_TIMESTAMP)" | 3deb31b98b8c75417ff0ecf5c7b5fa9eb0b91df9 | 695,769 |
def assign_value_if_none(value, default):
"""
Assign a value to a variable if that variable has value ``None`` on input.
Parameters
----------
value : object
A variable with either some assigned value, or ``None``
default : object The value to assign to the variable ``value`` if
``... | 5034a65741bb763e632bb8493eb661229e75279a | 695,770 |
def get_dict_val(dictionary, path, splitchar='/'):
"""
Return the value of the dictionnary at the given path of keys.
----------
INPUT
|---- dictionary (dict) the dict to search in.
|---- path (str) path-like string for key access ('key1/key2/key3' for ex.).
|---- splitchar (str)... | eb58e42edc705f05d9e046e65f4ed823f42c9aac | 695,771 |
def find_non_base_case_job(jobs):
"""Return a job that is not a base case."""
for job in jobs:
if job.model.base_case is not None:
assert not job.model.is_base_case
return job
raise Exception("Did not find a non-base-case job") | ab80ca1ad2e5293876ffa7973112bf19ae8ab308 | 695,775 |
def _get_new_steplist(reqs_to_keep, old_step_data, req_ids):
"""Returns a list similar to `old_step_data` but with unwanted requests removed.
Uses the requests and request components in `old_step_data` and the entitiy ids in `req_ids` to determine which elements in `old_step_data` to keep.
Parameters
----------
... | 61e3c88dda3fae29a10c91b4abfc02ed4762f22e | 695,776 |
def slon_e(lon_e, precision=0):
"""East longitude string.
Parameters
----------
lon_e: float
Input east longitude (degE).
precision: int, optional
Displayed float precision.
Returns
-------
str
Formatter longitude (`180°|90°W|0°|90°E|180°|`)
"""
return ... | 1968def96ac276e23e19991672653acdc00d65d2 | 695,777 |
from math import log
def is_power_of_two(x):
"""
Returns true if x is a power of two, false otherwise.
"""
if x <= 0:
return False
log2 = int(log(x, 2))
return x == 2 ** log2 | 092c13924e076c31c85ff93906c0947b61708c5a | 695,779 |
import pathlib
def make_report_file_names(proj_full_path):
"""
make the directory and file names for a report
Args:
proj_full_path (string): the path of the results directory
Returns:
report_dir (pathlib.Path)
html_outfile (pathlib.Path)
hash_fil... | 8d995bb15c2b8710ad2fb16e2476b5a96421f379 | 695,780 |
import time
import math
def __project_gdf(gdf, to_crs=None, to_latlong=False):
"""
Project a GeoDataFrame to the UTM zone appropriate for its geometries'
centroid.
The simple calculation in this function works well for most latitudes, but
won't work for some far northern locations like Svalbard a... | 6b3e67285ff9229fb96d609ffd222296dc1d7ae2 | 695,781 |
import re
def is_valid_rvpsa_id(rvpsa_id):
"""
Validates a remote VPSA ID, also known as the remote VPSA "name". A valid
remote VPSA name should look like: rvpsa-00000001 - It should always start
with "rvpsa-" and end with 8 hexadecimal characters in lower case.
:type rvpsa_id: str
:param rv... | aabe9e64dbc9003f3cc5f18842b91f4a3e34c8a8 | 695,782 |
def compute_prior_probability(alpha):
"""
Calculate the probability of the node being a LeafNode (1 - p(being SplitNode)).
Taken from equation 19 in [Rockova2018].
Parameters
----------
alpha : float
Returns
-------
list with probabilities for leaf nodes
References
-------... | 664734536a8a973bf77e6d9e723dc2954f663e21 | 695,786 |
def lat_opposite(side):
"""
Returns the lateral opposite as defined by the keyword pair {"Right", "Left"}
"""
if side == 'Right': return 'Left'
elif side == 'Left': return 'Right'
else: raise ValueError("Lateral side error, (%s)" % side) | 2273b4e43e37fd206cac52d81591afa12ecf68ee | 695,787 |
def count_col_nans(col):
"""
Returns the number of NaNs of a specific column in the dataset.
Parameters:
col (pandas Series): Column in the dataset
Returns:
col_count_nans (float): Count of NaNs in col
"""
col_count_nans = col.isna().sum()
return col_count_nan... | ea055c003805112dbebd11fa5b9beea8ecc4c127 | 695,790 |
def parse_headers(env):
"""Parse HTTP headers out of a WSGI environ dictionary
Args:
env: A WSGI environ dictionary
Returns:
A dict containing (name, value) pairs, one per HTTP header
Raises:
KeyError: The env dictionary did not contain a key that is required by
PE... | 31c2d2eac9a888535d57ecaf57c91748173bd948 | 695,791 |
def get_node_proto(graph_proto, node_name):
"""Get a `NodeProto` from `GraphProto` by node name.
Args:
graph_proto: A `GraphProto`.
node_name: Name of the node.
Returns:
A `NodeProto` or None.
"""
for node_proto in graph_proto.nodes:
if node_proto.name == node_name:
return node_proto
... | ddc1aebeb3450de8dd6dfa85b988997a163601b4 | 695,798 |
import warnings
def warn(action):
"""Set warnings filter"""
warnings.simplefilter(action)
return action | 143fb081685769b9d189c1600ca6a51c4a084d70 | 695,799 |
def fetch_project(api, project_name=None, project_id=None):
"""
fetch a project from the sb api.
:param api: API object generated by sevenbridges.Api()
:type api: Sevenbridges API Object
:param project_name: name of a project to return e.g. 'forsure'
:type project_name: string
:param project... | f33d70367bd4a52ae0099a83110182afdb8862d5 | 695,800 |
def filter_any_answer(group):
"""Filter questions answered by anyone in group."""
answers = set()
for person in group:
for question in person:
answers.add(question)
return answers | 5dca4f80e069bb3e9d9541145cbbc18eb22daf3f | 695,804 |
from typing import Iterable
def clean_key(k: Iterable[str]) -> str:
"""
Utility function for formatting keys.
This is a no-op if the input is a string, otherwise expects an iterable
of strings, which it joins with a period.
"""
return k if isinstance(k, str) else '.'.join(k) | 78f241056141a2549ae981a7ab18268e23fd2b0a | 695,807 |
def getFieldShortName(field_name):
""" Simplifies `field_name` in the exported dataframe by removing Watson Assistant prefixes """
return field_name.replace('request.','').replace('response.','').replace('context.system.','').replace('context.','') | 42c05ebef5d6ec0fe23ffa789f67a8aa37f364bd | 695,809 |
def hyperlink_title(body, docpath, docname):
"""
Hyperlink titles by embedding appropriate a tag inside
h1 tags (which should only be post titles).
"""
body = body.replace("<h1>", '<h1><a href="%s.html">' %
(docpath + docname), 1)
body = body.replace("</h1>", "</a></h1>", 1)
retu... | ae316226ef64a45c97cd6d094617edc2624d1cc8 | 695,810 |
import toml
def get_version(poetry="pyproject.toml") -> str:
"""Get the version of the package from pyproject file"""
with open("pyproject.toml", "r", encoding="utf-8") as f:
data = toml.loads(f.read())
return data["tool"]["poetry"]["version"].strip() | 56c4d658dbca656bd5964080036c9ca3df079f0d | 695,817 |
def cp_lt_stage_aware(cp0, cp1):
""" Less-than comparison of two CriticalPath objects in stage-aware mode """
if cp0.stage is None:
# CriticalPath with None stage is always shorter than any other
# critical path
return True
elif cp1.stage is None:
return False
return (cp0... | 783ee58a893bb52cd515605728ab4df743661052 | 695,818 |
def mul(value, arg):
"""Multiplication
>>> mul(2, 2)
4
"""
return value * arg | 50e8f39e52c754c8448f5ce32c040e3e5106af75 | 695,822 |
from typing import Optional
from typing import Dict
def get_first_api_gateway(api_gateway_client, api_gateway_name: str) -> Optional[Dict]:
"""
Get the first API Gateway with the given name. Note, that API Gateways can have the same name.
They are identified by AWS-generated ID, which is unique. Therefore... | fee768f319f2670ecaf9f8c6c66fffc62bcd66f3 | 695,823 |
def is_sorted(items):
"""Return a boolean indicating whether given items are in sorted order.
Running time: O(n) because at most loop through the entire array
Memory usage: O(1) because not creating any new space and everything is done in place"""
for i in range(len(items) - 1):
# if next item i... | 59094cd421c104509e54d7c8a40e27b4fcb97d63 | 695,825 |
def remove_empty(data):
"""Removes empty items from list"""
out = []
for item in data:
if item == '':
continue
out.append(item)
return out | 9ef46381bb76846c92375f47eb481a26359b1d92 | 695,827 |
import re
def MatchPattern(file_path, pattern):
"""Looks for matching specified pattern in the file line by line.
Args:
file_path: file path.
pattern: pattern for matching.
Returns:
the match or None.
"""
try:
with open(file_path, "r") as f:
prog = re.compile(pattern)
for line i... | 1ab4f7cf675c3be72bd6b01fb6f6c7fee2668275 | 695,830 |
def rem_item_from_list(item, string):
""" Removes all occurrences of token from string. If no occurrences of
items are in string, nothing is removed."""
return string.replace(item, "") | 5b0406c57aed3b786c4f20501be80e18f945928f | 695,833 |
from bs4 import BeautifulSoup
def strip_html(string: str):
"""
Use BeautifulSoup to strip out any HTML tags from strings.
"""
return BeautifulSoup(string, "html.parser").get_text() | 796fc52ddd303906c7fd217275cb2a897e76767c | 695,836 |
def email_sort(email):
""" Split the given email address into a reverse order tuple, for sorting i.e (domain, name) """
return tuple(reversed(email[0].split('@'))) | d841ea1f468d11e89df5d493ac74c28705bd6c27 | 695,837 |
from typing import List
import math
def euclidian_distance(a: List[float], b: List[float]) -> float:
""" Returns the euclidian distance between two N-dimensional points """
return math.sqrt(sum((x - y) ** 2 for (x, y) in zip(a, b))) | 57aac940e12c64978c7ecc4aea567653d6ee780a | 695,838 |
def cu_gene(obj):
"""Extracts the gene name from a codon usage object in std. format"""
return str(obj.Gene).lower() | 5df9facb6de7b954efe8e273f83c4f9cc9b2725a | 695,840 |
import json
def load_config(config_filename):
"""
Load the population config for this simulation.
Args:
config_filename (str): Filename for the simulation's config.
Returns:
Dict containing data from the config file.
"""
if not config_filename:
return {}
config_... | fffa9ceade1f83ff142da2b8de6484647e165dd8 | 695,841 |
import torch
def extract_slice_from_mri(image, index_slice, view):
"""
This is a function to grab one slice in each view and create a rgb image for transferring learning: duplicate the slices into R, G, B channel
:param image: (tensor)
:param index_slice: (int) index of the wanted slice
:param vie... | 84b6120aab497f03347f5a76ba7a42abe8bb4741 | 695,843 |
def get_buildings_in_buffer(buf, buildings, ids, idx):
"""
Input the buffer polygon and building geometries to check
if the building intersects with the buffer. Return all
buildings within the buffer (based on ID). An R-tree
is used to speed up things.
"""
bld_in_buffer = {}
for i in id... | ffb55879125997f824965998999225311c221c33 | 695,844 |
def needs_escaping(text: str) -> bool:
"""Check whether the ``text`` contains a character that needs escaping."""
for character in text:
if character == "\a":
return True
elif character == "\b":
return True
elif character == "\f":
return True
e... | 43110dacad107ab835e76997edc56bba113694b8 | 695,854 |
import torch
def _update_mem(inp_tokens, memory):
"""This function is for updating the memory for transformer searches.
it is called at each decoding step. When being called, it appends the
predicted token of the previous step to existing memory.
Arguments:
-----------
inp_tokens : tensor
... | ef4dc9ed0fd32d207cf584a3c180bf0bb3d6082f | 695,856 |
def CalculateBoxSize(nmol, molwt, density):
"""
Calculate the size of a solvent box.
Parameters
----------
nmol : int
Number of molecules desired for the box
molwt : float
Molecular weight in g/mol
density : float
Estimated density in kg/m3 (this should be about ... | 9508b740c07edd78e33be9cf6f30414e32ab8953 | 695,858 |
def tril_count_from_matrix_dim(matrix_dim: int):
"""Computes the number of lower triangular terms in a square matrix of a given
dimension `(matrix_dim, matrix_dim)`.
Args:
matrix_dim (int): Dimension of square matrix.
Returns:
int: Count of lower-triangular terms.
"""
tril_count... | d1e350986a09c239959de77b821003b5189f6c98 | 695,859 |
def sgd(l_rate, parameters, grads):
"""
Stochastic Gradient Descent.
Parameters
----------
:type lr: theano.tensor.scalar
:param lr: Initial learning rate
:type parameters: theano.shared
:params parameters: Model parameters to update
:type grads: Theano variable
:params grads: Gradients of cost w.r.t t... | aaa1d11788669801b4edd89aca29b38258043ff1 | 695,861 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.