content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
import os
def dstat(infile):
"""
Wrapper around os.stat(), which returns the output as a dict instead of an object
"""
fsx = os.stat(infile)
sout = {
'dev': fsx.st_dev,
'ino': fsx.st_ino,
'mode': fsx.st_mode,
'nlink': fsx.st_nlink,
... | 36779bd505a154fd63cb19724f99652d4e2457ef | 14,207 |
def xlate(vname):
"""Translate"""
if vname in ["ws_10m_nw", "ws_40m_nw", "ws_120m_nw"]:
return vname + "ht"
return vname | 8759031dcc47f5b34128f6b621f837e92e6c9b23 | 14,208 |
def reverse_spline(tck):
"""Reverse the direction of a spline (parametric or nonparametric),
without changing the range of the t (parametric) or x (nonparametric) values."""
t, c, k = tck
rt = t[-1] - t[::-1]
rc = c[::-1]
return rt, rc, k | 77c239fa8360657ed4ad4c1eb8d18493c97a84a1 | 14,209 |
import importlib
import pkgutil
def list_submodules(package, recursive=True):
"""
Recursively (optional) find the submodules from a module or directory
Args:
package (str or module): Root module or directory to load submodules from
recursive (bool, optional): Recursively find. Defaults to... | a5d69affc4cd19bd3e7c67c2d006c224bbafe80d | 14,210 |
def trainee_already_marked_training_date(trainee, training_date):
"""Check whether trainee already marked the given training date.
If trainee already has training day info it means he/she answered marked the given date.
Args:
trainee(models.Trainee): trainee instance to check whether already marke... | 138006be069201923017e0277ffec6a7c06080b4 | 14,211 |
import os
import sys
def __validate_directory__(paths):
"""
Validates the given path, it first check if it's a directory,
then validates if contains a specific identifier.
:param paths: dictionary with path and path identifier
"""
for path, file in paths.items():
if not os.path.isdir(... | 0986099a31c76992187bdcfca8e9d26605483806 | 14,212 |
def add_one(x: int) -> int:
"""
Returns input value added one
:param x: value greater than or equal to 0
:return: x + 1
:except x less than 0:
"""
assert x >= 0
return x + 1 | eaf60652a9dc210b3f4174c18873be1973c4f99e | 14,213 |
def calculate_individual_geo_mean(lines, index, geo_mean, num):
""" Calculate an individual line of parse results goe_mean """
previous_value = None
for line in lines:
line = line.split("\t")[4:]
current_value = line[index]
try:
if float(current_value) > 0:
... | 765b03379d11d2622d07086e1858ee51807bc293 | 14,215 |
def sort_hsvs(hsv_list):
"""
Sort the list of HSV values
:param hsv_list: List of HSV tuples
:return: List of indexes, sorted by hue, then saturation, then value
"""
bars_with_indexes = []
for index, hsv_val in enumerate(hsv_list):
bars_with_indexes.append((index, hsv_val[0], hsv_val... | 49a0936a04156ef1d785dea7efc95d5fffb368e0 | 14,218 |
def GetCcIds(issue):
"""Get the Cc's of an issue, whether they are explicit or derived."""
return issue.cc_ids + issue.derived_cc_ids | c5d558c4bfac4da5e501bc834e6218a44c49fbd9 | 14,219 |
def cleanupFilename( fname ):
""": Make the filename usable.
= INPUT VARIABLES
- fname Given a filename, clean-it up to make sure we can use it with
the file system.
= RETURN VALUE
- Returns a cleaned up form of the input file name.
"""
fname = fname.replace( ' ', '_' )
fname = ... | 25f727172ed9438c49510fd6703d2d56c61f85f2 | 14,220 |
import json
import ast
def parseJsonDatum(js):
"""Parse a JSON string, return parsed object or None
:rtype:
:param js A valid JSON string
:return parsed JSON as a dict
"""
if isinstance(js, dict):
return js
if not isinstance(js, str):
return None
try:
# prin... | 29d334038b9275fc822576f9670966768d02060e | 14,221 |
def continue_or_stop(question):
"""
n or y is parsed from inputs first character so it's the only part that matters
"""
while "answer not y or n":
reply = str(input(question + " (y/n): " )).lower().strip()
if reply[:1] == 'y':
return True
elif reply[:1] == 'n':
return False
else:
print("ERROR: Not ... | 3447a3b205e71270ccede9fa5608c823afa10062 | 14,222 |
import os
def data_dir_check(dir_list, woid, date):
"""Create and return transfer directory if 'model' found in dir path."""
# return NA if no transfer dir found
transfer_dir = 'NA'
# iterate over data dirs
for directory in dir_list:
# if model found, create transfer dir and return path
... | 424f0c36e6768328532676d429d690c50fbc6bd8 | 14,223 |
import json
def jsonify(val):
"""Perform a naive JSON dump."""
return json.dumps(val) | 0b52203062c031ad10fd660c96daa0459f81d367 | 14,224 |
def find_road_building_relations(voronoi, pts_line, pts_left, pts_right, road_crds):
"""
Find all road IDs facing the current road segment. Makes use of the indices
of the points between which a voronoi ridge lies. This can be used to check
if a road and building are facing each other.
"""
r_fi... | 4c023d6a93bb8a6fbdcd7565e4b191fe2b63a66a | 14,225 |
async def subnet_present(
hub,
ctx,
name,
address_prefix,
virtual_network,
resource_group,
security_group=None,
route_table=None,
connection_auth=None,
**kwargs,
):
"""
.. versionadded:: 1.0.0
Ensure a subnet exists.
:param name:
Name of the subnet.
... | 66ab96df63a1a4e0d6ba0e5380360d06afe079d4 | 14,226 |
def _layout_to_matrix(layout):
"""Create the adjacency matrix for the tree specified by the
given layout (level sequence)."""
result = [[0] * len(layout) for i in range(len(layout))]
stack = []
for i in range(len(layout)):
i_level = layout[i]
if stack:
j = stack[-1]
... | cd27cad3a7ab6f34ea2be13e5617a34dbbba834f | 14,228 |
import click
def email_arg(required, email="email", metavar="[EMAIL]", nargs=1):
"""
Email positional argument standard definition.
Use as decorator for commands.
"""
return click.argument(email, metavar=metavar, nargs=nargs, type=str, required=required) | 26e51c44f1109c0f690f243ee9d40de959570b08 | 14,229 |
def simplify_dataset_name(dataset_name):
"""In a couple of cases (BraTS and MURA) the dataset name is not quite correct
because of a mistake made earlier in the pipeline.
This function transforms the dataset names into a more readable format.
Args:
dataset_name (string): name of dataset to sim... | af0e504df0af2f250c716fb4f797970f31cbb1e1 | 14,230 |
import click
from pathlib import Path
import os
def edit_inputs(client, workflow):
"""Edit workflow inputs."""
for input_ in workflow.inputs:
new_path = click.prompt(
'{0._id}'.format(input_),
default=input_.consumes.path,
)
input_.consumes.path = str(
... | e9668f717b50786ddd3fe6375f56d17bad5ada05 | 14,231 |
import argparse
def get_parser():
"""
Returns the CLI parser to get the YAML file for the EC2 instance configuration.
Retrieve the YAML configuration file using the 'file' argument.
"""
parser = argparse.ArgumentParser(description='Creates EC2 instances from a basic YAML configuration file')
... | 2f57a88db79529e89d685a84dcdcf8101f38a833 | 14,232 |
import random
def seq_aleatoire(l_ascii):
"""Mélange une liste.
Cette fonction permet de générer une séquence alétoire de même
composition que celle passée en argument.
Parameters
----------
l_ascii : list
`l_ascii` est une liste d'entiers.
Returns
-------
l_ascii : list... | eb9c3e1d5182c4a359566e8efd1174934f415c4b | 14,235 |
def predict_linear_regression_labaled_features(fitted_model, dict_features):
"""
Calculates y ~ const + sum( parameter*value )
essentially the inner product
{ 'feature name' : value }
Does not assume you have all features present, so prediction may be off.
Assumes const parameter is not p... | b86fa00ff80e528080e473f849721a16e6f9f2a8 | 14,237 |
def parse_time(text):
""" parse time of slurm output """
# check for days
tokens = text.split('-', 1)
if len(tokens) > 1:
days = int(tokens[0])
rest = tokens[1]
else:
days = 0
rest = tokens[0]
# check for time
tokens = rest.split(':')
return days*24*60 + ... | 91a07479f02a6d428a2c45fe6b701e009a9675cf | 14,239 |
def get_video_name(image_name):
""" Extracts the video name from an image filename.
Args:
image_name: The name of the image file.
Returns:
The name of the video that the image belongs to. """
video_name = image_name.split("_")[0:3]
video_name = "%s_%s_%s" % (video_name[0], video_name[1], video_name[2]... | d2e5254dfaa650455b346cec43273cd50004b335 | 14,240 |
def estimate_reasonable_max(df, x):
"""Estimate a reasonable maximum value for the plot y axis."""
# Use 1.5 IQR of the largest group.
group = df.groupby(x)
q1 = group.Time.quantile(0.25)
q3 = group.Time.quantile(0.75)
iqr = (q3 - q1).max()
return q3.max() + 1.5*iqr | a5fd4be194ca938c7cebd1ad31128ccffcfd44bd | 14,241 |
def _add_members_to_obj(obj, data, columns):
"""Add members to obj.members
"""
i = 0
for member in obj.members:
name = 'member_' + str(i + 1)
data += ('\n'.join((f'{a}={v}' for a, v in member[i])),)
columns = columns + (name, )
i += 1
return data, columns | 6fd03824f3a17bb92fd7a42e16d3951222451cc2 | 14,242 |
def get_points(file,img_shape,mirror=False):
"""
Read wp from a YOLO style file: each wp are the upper-left and the lower-right points of the bounding box
"""
points = []
img_shape = img_shape[:-1][::-1]
file = open(file).read().split('\n')[:-1]
for r in file:
r = r.split()
... | 9648edc2aa065aceadf2128c28b5ff71ded2cb92 | 14,243 |
import json
import os
def build_feature_dict(args, examples):
"""Index features (one hot) from fields in examples and options."""
# if not args.create_vocab:
return json.load(open(os.path.join(args.vocab_dir, 'feat_dict.json')))
def _insert(feature):
if feature not in feature_dict:
... | 7be12c092f369587429e7ff0af9c05b2e6200c55 | 14,244 |
def _is_url(filename):
"""Check if the file is a url link.
Args:
filename (str): the file name or url link.
Returns:
bool: is url or not.
"""
prefixes = ['http://', 'https://']
for p in prefixes:
if filename.startswith(p):
return True
return False | cfffb3db75de4f613097c081f950d3feff079f63 | 14,245 |
import types
def list_module_versions(glob, return_dict = False):
"""
Prints the versions of all loaded modules/packages in a script or notebook.
Parameters
----------
glob : dict
output of the globals() function call.
return_dict : bool, optional
Parameter to decide if funct... | 17a51568e5bf80f8eb8dac23f1996dc5dd609c50 | 14,246 |
def get_events(trace_collection, keys=None, syscall=True):
"""Return a generator of events. An event is a dict with the key the
arguement's name.
Args:
trace_collection (babeltrace.TraceCollection): Trace from which
to read the events.
keys (dict, optional): dict of the multiple... | abc6e99c1e3cc64b45671ab6e054bb4bffcf2032 | 14,247 |
import torch
def softplus_inverse(x: torch.Tensor) -> torch.Tensor:
"""
Inverse of the softplus function. This is useful for initialization of
parameters that are constrained to be positive (via softplus).
"""
if not isinstance(x, torch.Tensor):
x = torch.tensor(x)
return x + torch.log... | aa4649368b9e8372e7a22b4ab460bf8d26a38dad | 14,248 |
def rosmac(y, t=0, r0=0.5, k=10, g0=0.4, h=2, l=0.15, e=0.6):
""" Rosenzweig-MacArthur predator prey model
"""
prey, cons = y
def r(x):
""" Growth rate """
return r0*(1 - x/k)
def g(x):
""" Grazing rate """
return g0/(x + h)
dydt = [r(prey)*prey -g(prey)*prey*c... | ec17e71cf5742b3db2b48123a63c14ae62101bee | 14,249 |
import re
def shorten(CSTAG: str) -> str:
"""Convert long format of cs tag into short format
Args:
CSTAG (str): cs tag in the **long** format
Return:
str: cs tag in the **short** format
Example:
>>> import cstag
>>> cs = "cs:Z:=ACGT*ag=CGT"
>>> cstag.shorten(cs)... | 653de1947a3cdf06103b01c1a7efc3dbc16ea4ab | 14,250 |
def dbex_eval(db, expr):
"""Evaluate a database expression"""
return db.ex_eval(expr) | 9739e2dd85fadd4d1569ddec20c6db57379a2de9 | 14,251 |
def _empty_invoke_bc(ivkbl, _stack, stack_ptr):
"""Write a warning to the screen"""
print(
"Warning: undefined primitive #%s called"
% ivkbl.get_signature().get_embedded_string()
)
return stack_ptr | 89b33c7b888560da6e8d49e432db9bc068bfaa66 | 14,253 |
import math
def lognormal_stddev(m, stddev):
""" compute std. of log x with mean and std. of x
Args:
m: mean of x
stddev: standard deviation of x
Returns: std. of log x
"""
return math.sqrt(math.log((stddev * stddev) / (m * m) + 1)) | cb3abebc2225e3b2d33bdc1b6ff12c950437a594 | 14,254 |
import aiohttp
async def get_new_bangumi_json() -> dict:
"""
Get json data from bilibili
Args:
Examples:
data = await get_new_bangumi_json()
Return:
dict:data get from bilibili
"""
url = "https://bangumi.bilibili.com/web_api/timeline_global"
headers = {
"acce... | 02d39b7535a7db7b50dc81851725ffc67653cd17 | 14,255 |
def compare_math_formula(query, formula):
"""Compares two math tuples
Parameters:
query: the query math tuple (str)
formula: the formula math tuple (str)
Returns:
same: True if tuples are considered equal (boolean)
"""
if "'*'" in query:
# break on the wild card
... | 736e9f564e4c834270fd25af7ed8252873d4c07d | 14,256 |
def interpolate(df, key):
"""Interpolate subset of MulitIndex df."""
subset = df.xs(key, level=0, drop_level=False, axis=1)
return (subset.interpolate(axis=1)
.where(subset.fillna(method='bfill', axis=1).notnull())) | 0f5fec0b891871747337194bf56a0814ee015fc0 | 14,257 |
import re
def output_name_from_topic(topic: str, prefix: str, topic_type: str) -> str:
"""
Parses an MQTT topic and returns the name of the output that the message relates to.
"""
match = re.match(f"^{prefix}/{topic_type}/(.+?)/.+$", topic)
if match is None:
raise ValueError("Topic %r does... | ca6b3eb77815eee3f779bf16e8f706532dfe42e6 | 14,258 |
def invalid_entitlements_fixture(request):
"""A parameterized pytest fixture which returns invalid entitlements.
Args:
request : Built-in pytest fixture
Returns:
[String]: A string containing invalid Entitlements.
"""
return request.param | 7f98b101bd8db303bb62a8c392689694f3a46805 | 14,259 |
def exponential(x, halflife):
""" Returns a decay factor based on the exponential function
.. math::
f(x) = 2^(-x/halflife).
:param x: The function argument.
:param halflife: The half-life of the decay process.
"""
return 2 ** (-x / halflife) | 2561d42f87c2818e82c2cc065592acf9ac8202fe | 14,260 |
def rm_strheader(images):
"""
Remove the header of the images base64 string from front-end
:param images: the input should be the base64 string of the image
:raises TypeError: if input is not a string
:returns: base64 string without data header
:rtype: string
"""
if type(images) is not... | 7466621dfa0a5bb31eb8735da89d68b885cb04ea | 14,262 |
def box_to_rect(box, width, height):
"""
:param box: center_x, center_y, bbox_w, bbox_h
:param width: image width
:param height: image height
:return: x1, y1, x2, y2(in pixel)
"""
x, y, w, h = box
x1 = (x - w * 0.5) * width
y1 = (y - h * 0.5) * height
x2 = (x + w * 0.5) * width... | 32413d14e242f2d790c5ae9c93418abb4152df46 | 14,263 |
def SqrNorm(x):
"""Square of the norm.
:param x: return sum(x*x)
:return: return sum(x*x)
"""
return sum(x*x) | 03f35a7395ba74981eace38b634a14210932cffd | 14,268 |
def new_superuser(db, new_superuser_factory):
"""Return a new superuser"""
return new_superuser_factory() | 7b0751788c9aea1cd37b7e26deb5a7f6e1d6a35f | 14,269 |
def _parse_numpy_pixeltype_from_string(s):
"""
example: "image_FLOAT_3D.nii.gz" -> 'float32'
"""
if 'UNSIGNEDCHAR' in s:
return 'uint8'
elif 'CHAR' in s:
return 'int8'
elif 'UNSIGNEDSHORT' in s:
return 'uint16'
elif 'SHORT' in s:
return 'int16'
elif 'UNSIG... | 8066c9eab8b31fa290ac68d44b6bd448a3a689de | 14,270 |
def set_zenangle(profs, zen=None):
"""Set zenith angles to a new value. If zen is missing, angles cycle in
steps of 10 degrees between 0 and 70 over the profile set."""
if zen:
zenlist = [zen]
else:
zenlist = range(0, 71, 10)
for p in range(profs['nprof']):
profs[p]['zena... | 41d7099e7eb7ac9da1532c28be00b1a574e84e6e | 14,271 |
def preprocess(X):
"""
Optional preprocessing for secondary data format.
@param X: list of lists of lists (glogs, function calls, function call + attributes)
"""
for i in range(len(X)):
for j in range(len(X[i])):
X[i][j] = ' '.join([str(x) for x in X[i][j]])
X[i] = '\n'.j... | b759c0353dfeb5c2d4292fd541c8dba507c1ccea | 14,272 |
import requests
from bs4 import BeautifulSoup
def question_info_get(qid):
"""
获取问题的标签
Parameters
----------
qid : int
question id.
Returns
-------
keywords:list
问题关键词
"""
headers = {
"User-Agent": "",
"Connection": "",
"Accept": "",
"Accept-La... | fb5f1d6bf41a267237f24d677e43c51c474a90f7 | 14,273 |
def dup(integer): # real signature unknown; restored from __doc__
"""
dup(integer) -> integer
Duplicate an integer socket file descriptor. This is like os.dup(), but for
sockets; on some platforms os.dup() won't work for socket file descriptors.
"""
return 0 | aac98f8c767d2224b3949aea4aafcb83d0c0ee1c | 14,276 |
import torch
def communities_to_labels(n_nodes, communities):
"""
For n_nodes nad a communties dictionary or list of lists returns a list with size 'n_nodes'
assigning to each node index the corresponding node community.
:param n_nodes:
:param communities:
:return:
"""
comm_labels = t... | e961568fff8959e909f0b44469a745d33ff5233d | 14,277 |
def check_intensifiers(text, INTENSIFIER_MAP):
"""
Utility function to check intensifiers of an emotion
:param text: text chunk with the emotion term
:return: boolean value and booster value for intensifiers
"""
# BOOSTER_MAP = {"B_INCR": 2,
# "B_DECR": 0.5}
intensity_word... | 2c35b6b66395bc7105b9fb1b9cf7f04b5686cb8d | 14,278 |
def get_next_code(last_code):
"""Generate next code based on the last_code."""
return (last_code * 252533) % 33554393 | 9fcf416df3448a8ca46a55073f66d12cd8fc2593 | 14,279 |
import shutil
from pathlib import Path
import os
def is_ffmpeg_installed(ffmpeg: str = "ffmpeg") -> bool:
"""
Check if ffmpeg is installed.
"""
if ffmpeg == "ffmpeg":
# use shutil.which to find ffmpeg in system path
return shutil.which("ffmpeg") is not None
abs_path = str(Path(ff... | 16fc862ab68313e6df9d41156856bf68b26b9192 | 14,280 |
import base64
def decode(b64):
"""
Decode given attribute encoded by using Base64 encoding.
The result is returned as regular Python string. Note that TypeError might
be thrown when the input data are not encoded properly.
"""
barray = base64.b64decode(b64)
return barray.decode('ascii') | 5c04c43247d1415ca8f1398c3b8206c50a7e0fa4 | 14,282 |
from typing import Counter
def session_referer_class(session):
"""Most common referer class in session (categorical)."""
referer_class = Counter([r['referer_class'] for r in session]).most_common(1)[0][0]
return referer_class | 0b4047ea63063b7535bbaea7c67756de15561522 | 14,285 |
def _compute_max_name_width(contracts: dict) -> int:
"""Return the maximum width needed by the function name column."""
return max(
len(function) for contract, functions in contracts.items() for function in functions
) | bc57c408a49182cdfb26a1955a4a3943c060af86 | 14,288 |
import logging
def get_logger(name):
"""Get the logger with a given name
Args:
name: name of the logger to create
"""
return logging.getLogger(name) | 0f02aba7f01c2aafbb7fafda0bb260d73fd240a1 | 14,290 |
def search_dicts(k, v, data):
"""
Search a list of dicts by key
"""
match = []
for row in data:
if k in row:
if v == row[k]:
match.append(row)
if len(match) == 1:
# If we only get one result: return just it as a dictr
return match[0]
else:... | c133ec1452f73e51c19af59b6fb49039dda28176 | 14,292 |
def get_type_tuple(df):
"""
Parameters
----------
df: data frame
Returns
-------
Return a list [(colunm name, datatype)]
"""
return([(c, df[c].dtype) for c in df.columns]) | a5c0568defbbd4a4fdc88bf1e1bce058bf8d8495 | 14,293 |
def decode_enums(obj, available_enums=None):
"""
Decode enums from parsed yaml file
:param obj: object to check
:param available_enums list of available enums classes to decode
:return: decoded object
"""
if isinstance(obj, dict):
new_obj = {}
for... | e8bf3cc55363fbf13ad400bbbfd3006ce23cd3d5 | 14,294 |
import itertools
def euler4(l=3):
"""Solution for problem 4."""
# simple optimisation would be an early break
return max(n for n in (i * j for i, j in itertools.combinations(range(10 ** (l - 1), 10 ** l), 2)) if str(n) == str(n)[::-1]) | 6e0d4fbeb14b61a30b78caccf4de168fdff12efb | 14,295 |
def _moffat_(r, alpha, beta, normed=False):
""" """
norm = 2*(beta-1)/alpha**2 if normed else 1
return norm * (1 + (r/alpha)**2 )**(-beta) | 6dcea83247d97c1cb52f7051fe1444c21af604c7 | 14,297 |
def label_mapping(y_data, known_labels):
"""
Maps all class index to used one. It is possible to subsample number of classes.
:param y_data: Array with labels to map
:type y_data: nd.array
:param known_labels: Labels index to map
:type known_labels: list-like
:return: label_map and y_data w... | d2db167aeb51b02167d530100652625eb44e8bbd | 14,298 |
def create_periodic_dosing(timeHigh, timeLow, highVal, lowVal=0):
"""Create a Periodic dosing profile
Create a dosing profile which oscillates between high and low values.
Remains high for timeHigh and low for lowHigh each period
:param timeHigh: Time dosing remains at highVal (float)
:param timeL... | 358723ba0187ffddb91d9aa1d2c70a1f14a774b2 | 14,299 |
import itertools
def _generate_centers_and_final_shape(img_shape,
stride,
first_center):
"""
generates final shape and centers for applying a sliding window
"""
dim_ranges = []
for dim_min, dim_max, dim_stride in zip(first... | be92aee8f844e20aa41761e6b89a9c831cd2e934 | 14,300 |
def _map_account_name_to_login_names(accounts):
"""
Maps the accounts name to the login names. this method simply groups the csv rows by the account name
:param accounts: list of accounts records
:return: dict
"""
accounts_dict = {}
for account in accounts:
columns = account.decode(... | 9553659e7a8cf4ef192e6019b603f954e242abbe | 14,301 |
def match(first_list, second_list, attribute_name):
"""Compares two lists and returns true if in both there is at least one element which
has the same value for the attribute 'attribute_name' """
for i in first_list:
for j in second_list:
if i[attribute_name] == j[attribute_name]:
... | 2b7c38ef3132c5cb9e693be2995691600ac76ec7 | 14,302 |
def get_spacing_dimensions(widget_list):
"""
will be further developed
"""
space_dimensions = space_label = 0
for widg in widget_list:
space_d = widg.get('dimensions', '')
space_l = widg.get('label', '')
if space_d:
space_d_new = len(list(space_d))
if... | 8c521b1315c120173d22ff25bf3c2b41bdab8ecd | 14,304 |
def _check_core_match(shape1, shape2):
"""Checks shape1 and shape2 are valid shapes to perform matmul"""
ndim1, ndim2 = len(shape1), len(shape2)
if ndim1 < 1 or ndim2 < 2:
return True
if shape1[-1] == shape2[-2]:
return True
raise ValueError(f'mismatch in core dimension of input oper... | 4acb2430518b2a5c682d7894991095a98d766cc7 | 14,305 |
import os
def setupCheckpoint(checkpoint_dir):
"""
Set up writing down checkpoints:
- Make checkpoint directory is it does not exist
- Find latest checkpoint
Parameter:
- checkpoint_dir -- Directory for writing down checkpoints
Returns:
"""
if not os.path.exists(checkpoint_dir):
... | 5a1518fb08688cba0f37ab7f18cab4a2c1cca4bd | 14,306 |
def LinearGainLine(x1,y1,x2,y2):
"""
returns tuple (m,b)
that satisfies the equation y=mx+b
uses two points in histogram space to determine slope
x : 0..nbins
y : 0..255
"""
if (x2 > x1):
m = -(y1-y2) / (x2-x1)
else:
m = 0
b = x1
return m,b | 71d1d321c85636e15f05e3ab26c66a48a1cc5103 | 14,307 |
def mean(num_lst):
"""
Calculates the mean of a list of numbers
Parameters
----------
num_list : list
List of numbers to calculate the average of
Returns
-------
The average/mean of num_lst
"""
Sum = sum(num_lst)
count = 0
for num in num_lst:
count += 1
return Sum / count | 4339a8f755ebb26328bbbc76b2b76034d21ea004 | 14,309 |
def find_cycle(start, graph):
"""Finds a path from `start` to itself in a directed graph.
Note that if the graph has other cycles (that don't have `start` as a hop),
they are ignored.
Args:
start: str name of the node to start.
graph: {str => iterable of str} is adjacency map that defines the graph.
... | 0ce38b4813f6a0e55898ff3c17b54d35935ce85f | 14,310 |
import numpy
def square_aspect(xlim, ylim):
"""Calculates the limits to produce a square plot if all axes are
equal scale.
"""
x0, x1 = xlim
y0, y1 = ylim
x_range = numpy.abs(x1 - x0)
y_range = numpy.abs(y1 - y0)
if x_range > y_range:
fac = (x_range - y_range) / 2
r... | 65e4c6518004a86b258d9d7084215c116ea7b733 | 14,311 |
def find_events(events, start, end, at_words=None):
"""Return (date, text, event) tuples for the events in our date range.
"""
things = set()
for event in events:
things.update(event.get_dates(start, end, at_words))
return things | 52a7250ad6ee172d52d3c563318eac3c4fd436cd | 14,312 |
def has_connected_children(bone):
""" Returns true/false whether a bone has connected children or not.
"""
t = False
for b in bone.children:
t = t or b.use_connect
return t | b88106b3ceac26987253e2995cda851f7a622d2f | 14,313 |
def create_user(first_name, last_name, email, phone_number, dob, address_id):
"""
Creates immutable user data structure
:param first_name: user's first name (string)
:param last_name: user's last name (string)
:param email: user's email (string)
:param phone_number: user's phone number (string)... | 2c6f647ac7f85fd56f4870bade01bb7a951ff4d2 | 14,314 |
import six
def ask_for_export_email():
"""Ask for a registered email address."""
print('You have not set the email variable at the top of this script.')
print('Please set this variable in the script, or enter it below. Note')
print('that you need to register your email at JSOC first. You can do')
... | 7ac8497021e71718f70c54f4c2b045fa455d65e5 | 14,316 |
def dlookup_in(d, l):
"""Return key from a dict if l in val."""
for k,v in d.iteritems():
try:
if l in v:
return k
except TypeError:
continue
return None | fa53a4e30607c783096b37eef3b3ca936de07097 | 14,317 |
def remove_duplicates_for_fetch(items: list, last_fetched_ids: list) -> list:
"""Remove items that were already sent in last fetch.
Args:
items (list): Items retrieved in this fetch.
last_fetched_ids (list): ID's of items from last fetch.
Returns:
(list) New items wi... | 705e786563206015877798e227c89a978831f97f | 14,319 |
def append_unique(the_list, new_item):
"""
append the newe_item to the_list, only if it does not exist
:param the_list:
:param new_item:
:return:
"""
exist = any(new_item == item for item in the_list)
if not exist:
the_list.append(new_item)
return the_list | 2974643e1cbbc7c0cf8dccb7ddc1fd21368eb3f8 | 14,320 |
from typing import Tuple
from typing import List
def flatten(array: Tuple[List[Tuple[int, int, int, int, int]]]):
"""
:param array:
:return:
Flattens move tuple a single level deep
"""
flat_list = []
for sublist in array:
for item in sublist:
flat_list.append(item)
... | 835f2d166a07c41d1803e2c1c4a7244990326302 | 14,323 |
def get_playoff_bracket_string(league):
"""
Creates and returns a message of the league's playoff bracket.
:param league: Object league
:return: string message league's playoff bracket
"""
bracket = league.get_playoff_winners_bracket()
return bracket | 0ac2e02493a99c830704d6651125e0c30c8f4c7c | 14,325 |
def oxygen_abundance(Z):
"""
Set the oxygen abundance.
We assume Asplund et al 2009 abundance at Zsun and that Ao scales linearly with Z. Z in solar units
"""
Ao = 4.90e-4
return Ao*Z | 1fe4ad34afbbe4c43fd883df434d9fcc7a83b9b7 | 14,327 |
def subdivide_dict(dictionary, num_subdivisions):
"""
Distributes the k: v pairs in dict to N dicts.
"""
subdicts = [{} for i in range(num_subdivisions)]
for i, k in enumerate(dictionary.keys()):
sub_index = i % num_subdivisions
subdicts[sub_index][k] = dictionary[k]
return subdi... | 6aa9abeff609115e1ecd1085d4ba0d875c59bf2d | 14,328 |
from typing import Dict
from typing import Any
import pickle
def serialize_dlv2_checkpoint(dlv2_checkpoint: Dict[str, Any]) -> bytes:
"""
Handling the checkpoint conversion from DataLoader V2 format to bytes format.
"""
return pickle.dumps(dlv2_checkpoint) | ae5c42d0daea42e61ff77c8b52aba30586657e7c | 14,331 |
import os
import imp
def _import_from(mod, path, mod_dir=None):
"""
Imports a module from a specific path
:param mod:
A unicode string of the module name
:param path:
A unicode string to the directory containing the module
:param mod_dir:
If the sub directory of "path" i... | 87318df47d4d672aeb68663cfecfc1bdebed09a6 | 14,332 |
def to_geojson(shapes, buildings):
"""Converts the shapes into geojson.
This function will combine the burn scar region and buildings into geojson.
Burn scar polygon in red, buildings polygon all in blue."""
#append burn scar region polygons to geojson
if type(shapes) == list:
results = ({
... | fb0d417ab3c049d4b89e14dea1f15a3f40f42803 | 14,334 |
import numpy
def label_ids(array):
"""
Returns (sorted ndarray of) unique positive elements of array.
Made obsolete by segment.extractIds?
"""
# get all unique elements and keep those that are positive
all = numpy.unique(array)
pos = all.compress(all>0)
return pos | 10158dbfea6e5512ee3d81f6c51cfb7a3828bdf1 | 14,335 |
def vyhodnot(pole):
"""1-D piškvorky se hrají na řádku s dvaceti políčky.
Hráči střídavě přidávají kolečka (o) a křížky (x)."""
if 'xxx' in pole and 'ooo' in pole:
return '!'
elif 'xxx' in pole:
return 'x'
elif 'ooo' in pole:
return 'o'
elif '-' not in pole:
retu... | c647d7f5891ba50d495a0aae5ead57b83594969d | 14,336 |
import re
def get_product(title):
"""Extract protein product from sequence title.
Parameters
----------
title : str
original title which reads "product [organism]"
Returns
-------
str
product
Notes
-----
NCBI protein product xyz [organism]
"""
title =... | 7754e3b90f2119716e64c6a3f60e82c5a6cf8033 | 14,337 |
def phone_brands(df):
"""
>>> import pandas as pd
>>> df = pd.read_csv(r'../data.csv')
>>> phone_brands(df)
{'others': 1912, 'Huawei': 1977, 'LG': 622, 'Apple': 2910, 'Xiaomi': 1491, 'Samsung': 4738, 'Motorola': 584, 'OPPO': 542, 'Vivo': 575}
"""
brands = {}
brands['others'] = 0
# ge... | 19bc556d0882d5efa73f88f4f58f8090f6ed3fe1 | 14,338 |
def choose_display():
"""
prompt user to choose scale bar display
"""
choices = ["d","theta","both"]
temp_choice = "false"
while temp_choice not in choices:
temp_choice = input("Please choose the scale to display.\nd, theta, both\n")
if temp_choice not in choices:
... | 8f03dbfbbf250881ecb6a27e4de332bdac4dfcd2 | 14,340 |
def getAllCombinations(cond_):
"""Returns all possible combinations of features for training on"""
lst = [
"total_bytes",
"max_bytes",
"1->2Bytes",
"2->1Bytes",
"1->2Pkts",
"2->1Pkts",
"total_pkts",
"number_ms",
"pkt_ratio",
"time_s... | 9d4324170dcb21779290398ad744dec32fff30be | 14,341 |
def reverse_bits(n, width=8):
"""Reverse bit order (not the fastest way)"""
b = '{:0{width}b}'.format(n, width=width)
return int(b[::-1], 2) | d001babf6d3219ff9de7994e2719ebafe9561208 | 14,342 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.