content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
import builtins
def no_matplotlib(monkeypatch):
""" Mock an import error for matplotlib"""
import_orig = builtins.__import__
def mocked_import(name, globals, locals, fromlist, level):
""" """
if name == 'matplotlib.pyplot':
raise ImportError("This is a mocked import error")
... | 681ba8c0e70387e46ad7ed42ffb11ce8aa7f23bc | 703,154 |
import tqdm
def create_tqdm_reader(reader, max_reads=None):
"""Wrap an iterable in a tqdm progress bar.
Args:
reader: The iterable to wrap.
max_reads: Max number of items, if known in advance.
Returns:
The wrapped iterable.
"""
return tqdm.tqdm(reader, total=max_r... | 29bd93b85ace167f5586ac275510e82f7bbe8223 | 703,155 |
import math
def get_sequence_of_considered_visits(max_num_considered_actions,
num_simulations):
"""Returns a sequence of visit counts considered by Sequential Halving.
Sequential Halving is a "pure exploration" algorithm for bandits, introduced
in "Almost Optimal Explorati... | f0081ae5bfe25d6a3eaad9f032cfb88a403fbb45 | 703,157 |
def _validate_int(
setting, value, option_parser, config_parser=None, config_section=None
) -> int:
"""Validate an integer setting."""
return int(value) | 9036b1b043bd2463cad4f26780d47e80aa404f73 | 703,161 |
def sub(arg1, arg2):
"""
Function that subtracts two arguments.
"""
return arg1 - arg2 | fb3694bc0827f62befe67cb58c1edb9de1adb808 | 703,165 |
def query_for_data(driver):
"""Grab all relevant data on a jobs page.
Return:
------
job_titles: list
job_locations: list
posting_companies: list
dates: list
hrefs: list
"""
job_titles = driver.find_elements_by_xpath(
"//span[@itemprop='tit... | d3a44ec2e66f9c8ba09dac45dc253c2dd67303c4 | 703,166 |
import typing
def split_line(line: str) -> typing.Tuple[str, str]:
"""
Separates the raw line string into two strings: (1) the command and (2) the
argument(s) string
:param line:
:return:
"""
index = line.find(' ')
if index == -1:
return line.lower(), ''
return line[:ind... | 964877ebe0e63161f449a1d60542fbcab451de28 | 703,167 |
from dateutil.parser import parse
def is_datetime_string(string: str) -> bool:
"""
Check if the string is date-like.
Parameters
----------
string : str
Returns
-------
is_date: bool
"""
try:
parse(string)
return True
except ValueError:
return Fal... | ec26eab5d25c2b130efbf32304b2b79f8292a6e1 | 703,174 |
def _fspath(path):
"""Return the path representation of a path-like object.
If str or bytes is passed in, it is returned unchanged. Otherwise the
os.PathLike interface is used to get the path representation. If the
path representation is not str or bytes, TypeError is raised. If the
provided path i... | dfffc592e8e03095c91653327d673e424480dfcf | 703,180 |
def hcolor(data, thresholds):
""" Multicolor a graph according to thresholds
:param data: the data
:type data: list of tuples (info, value)
:param thresholds: dict of thresholds, format
{<threshold>: <color>,}
:type thresholds: dict
:return: the colored graph
:rtype: list of arrays
... | 00b18c204ea97a7f5d919122b08488c42a25e9da | 703,181 |
def euler_problem_6(n=100):
"""
The sum of the squares of the first ten natural numbers is,
1^2 + 2^2 + ... + 10^2 = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)^2 = 55^2 = 3025
Hence the difference between the sum of the squares of the first ten natural numb... | 550d29deea17b3047bc869a134837d4f5c1baf95 | 703,182 |
def get_num_classes(dataset_name: str) -> int:
"""
Get the number of supervised loss given a dataset name.
:param dataset_name: dataset name
:return: number of supervised class.
"""
if dataset_name == "cifar10":
return 10
elif "cifar100" in dataset_name:
return 100
else:
... | dc699aeaef87b1763c9986cda596b920156e2478 | 703,187 |
def get_bsse_section(natoms_a, natoms_b, mult_a=1, mult_b=1, charge_a=0, charge_b=0):
"""Get the &FORCE_EVAL/&BSSE section."""
bsse_section = {
'FORCE_EVAL': {
'BSSE' : {
'FRAGMENT': [{
'LIST': '1..{}'.format(natoms_a)
},
{
... | 61c9398ed35eaaf2212c2c1a66e2cf43b9bbe029 | 703,189 |
import re
def load_placement(placement_file):
"""
Loads VPR placement file. Returns a tuple with the grid size and a dict
indexed by locations that contains top-level block names.
"""
RE_PLACEMENT = re.compile(
r"^\s*(?P<net>\S+)\s+(?P<x>[0-9]+)\s+(?P<y>[0-9]+)\s+(?P<z>[0-9]+)"
)
... | 72b534b5c8597f4a42d02e041c69a8fc3c92e8f7 | 703,190 |
def license_path(licenses):
"""Get license path."""
# return license if there is exactly one license
return licenses[0] if len(licenses) == 1 else None | b8194e099c4516627edab6c4538e5dfcdc6600a3 | 703,192 |
from datetime import datetime
def complete_month(year, month):
""" Return a string with the month number padded with zero if the month has
only one digit. It is also necessary to provide a year.
:param year:
:param month:
:return: Month number padded with zero.
:rtype: str
"""
return ... | 03915be101c0f418caa78ae6bc423273ad3af24c | 703,194 |
def scrub_email(address):
"""
Remove the local-part from an email address
for the sake of anonymity
:param address: <str>
:return: <str>
"""
if '@' in address:
domain = address.split('@')[1]
return 'user@{}'.format(domain)
else:
return address | 90b54f3a06f3fe50b354138113c27e980c01c59c | 703,197 |
def symm_area(col, n):
"""
returns n + (n - 1) + ... + (n - col + 1)
i.e., the number of matrix elements below and including the diagonal and
from column 0 to column `col`
"""
return col * (2 * n - col + 1) // 2 | e5c7970ee2b612f4678952056be0358c968e06b3 | 703,200 |
def find_device(p, tags):
"""
Find an audio device to read input from
"""
device_index = None
for i in range(p.get_device_count()):
devinfo = p.get_device_info_by_index(i)
print("Device %d: %s" % (i, devinfo["name"]))
for keyword in tags:
if keyword in devinfo["n... | 41428447dc39be8fa06ede59816a7aca9d5bffee | 703,202 |
def normalize_lons(l1, l2):
"""
An international date line safe way of returning a range of longitudes.
>>> normalize_lons(20, 30) # no IDL within the range
[(20, 30)]
>>> normalize_lons(-17, +17) # no IDL within the range
[(-17, 17)]
>>> normalize_lons(-178, +179)
[(-180, -178), (179... | c0d58aa7be8409d6337f0fa8b753f5ef30f531e5 | 703,203 |
from typing import Tuple
def _unmerge_points(
board_points: Tuple[int, ...]
) -> Tuple[Tuple[int, ...], Tuple[int, ...]]:
"""Return player and opponent board positions starting from their respective ace points."""
player: Tuple[int, ...] = tuple(
map(
lambda n: 0 if n < 0 else n,
... | 25965e023030266cc92e6b1456483204ad2c863a | 703,206 |
import json
def from_json_string(my_str):
"""Returns an object (Python data structure) represented by
a JSON string:
Arguments:
my_str (obj) -- json str
Returns:
obj -- object
"""
return json.loads(my_str) | cb013514b62456d6c628cf4ebea475b54851dfa4 | 703,208 |
def get_bse(da, da_peak_times):
"""
Takes an xarray DataArray containing veg_index values and calculates the vegetation
value base (bse) for each timeseries per-pixel. The base is calculated as the mean
value of two minimum values; the min of the slope to the left of peak of season, and
the min of... | 3edaf6156bd9fdae15c3bf845eb3deb293489cfb | 703,210 |
def get_dict_key_by_value(val, dic):
"""
Return the first appeared key of a dictionary by given value.
Args:
val (Any): Value of the key.
dic (dict): Dictionary to be checked.
Returns:
Any, key of the given value.
"""
for d_key, d_val in dic.items():
if d_val ==... | d01522a61d7a0549ed54bfcb620da10857d67ae7 | 703,212 |
import json
def isJson(var=''):
""" Check json
>>> isJson(var='')
False
>>> isJson('')
False
>>> isJson('{}')
True
"""
result = True
try:
json.loads(var)
except Exception as e:
result = False
return result | dc146fff1449df844ce0ac00607d77b5e2dc4370 | 703,213 |
def count_ontarget_samples(df, human_readable=False):
"""
Function to count usable samples.
Parameters
----------
df: DataFrame
human_readable: Boolean, optional
default=False
Returns
-------
ontarget_counts: DataFrame
MultiIndexed if human_readable, otherwise
... | 3bb2532017089ab08ac53422baaa55a5b38ee4e3 | 703,214 |
import csv
def _read_file_to_dict(path):
"""
Load the problems and the corresponding labels from the *.txt file.
:param path: The full path to the file to read
:return: The dictionary with the problem names as keys and the true class labels as values
"""
label_dict = {}
with open(path, 'r'... | 83bd3b04afc995176dc4dfefb9863b9f1ba09888 | 703,216 |
def trace(fn):
"""Decorator that marks a function to be traced."""
fn.should_trace = True
return fn | 598d81b2f4050b78cd42c835c5ce3bcc41c87541 | 703,218 |
def get_sm_tag_from_alignedseg(aln):
"""Get 'sm' tag from AlignedSegment."""
try:
return aln.get_tag('sm')
except Exception as e:
raise ValueError("Could not get 'sm' tag from {aln}".format(aln=aln)) | ca23604f724f75bf4c399374547f1468c6c5df9b | 703,222 |
def specific_gravity(temp, salinity, pressure):
"""Compute seawater specific gravity.
sg = C(p) + β(p)S − α(T, p)T − γ(T, p)(35 − S)T
units: p in “km”, S in psu, T in ◦C
C = 999.83 + 5.053p − .048p^2
β = .808 − .0085p
α = .0708(1 + .351p + .068(1 − .0683p)T)
γ = .003(1 − .059p − .012(1 − .... | 37ee32d3842cd5f9645449b23feb4d8315536fe2 | 703,227 |
def reverse_bits(num):
"""
reverses the bits representing the number
:param num: a number treated as being 32 bits long
:return: the reversed number
"""
result = 0
for i in range(32):
result <<= 1
result |= num & 1
num >>= 1
return result | 262e589cf366065018a57cd6a6c443bdd8eb638e | 703,235 |
import requests
def convert_using_api(from_currency, to_currency):
""" convert from from_currency to to_currency by requesting API """
convert_str = from_currency + '_' + to_currency
options = {'compact': 'ultra', 'q': convert_str}
api_url = 'https://free.currencyconverterapi.com/api/v5/convert'
result = request... | f261dcf6c97a8e5697e6b1005513b34f755f541f | 703,239 |
import re
def remove_brackets(s):
"""Remove brackets [] () from text
"""
return re.sub(r'[\(\(].*[\)\)]', '', s) | 82685dfa66c2b1185a3e106f7289af5856c8e56e | 703,244 |
def can_embed_image(repo, fname):
"""True if we can embed image file in HTML, False otherwise."""
if not repo.info.embed_images:
return False
return ("." in fname) and (
fname.split(".")[-1].lower() in ["jpg", "jpeg", "png", "gif"]
) | 40bfdd8c32ddd5f3d3bd2ae074494ba34e6fc1f1 | 703,247 |
def datetime_to_isoformat(dt):
#=============================
"""
Convert a Python datetime to an ISO 8601 representation.
:param dt: A Python :class:~`datetime.datetime`.
:return: A string representation of the date and time formatted as ISO 8601.
"""
iso = dt.isoformat()
if iso.endswith('+00:00'): retu... | 508ce4ea3e0905aab0b16c6b28fa4e9304e18b08 | 703,249 |
def get_mode_from_params(params):
"""Returns the mode in which this script is running.
Args:
params: Params tuple, typically created by make_params or
make_params_from_flags.
Raises:
ValueError: Unsupported params settings.
"""
if params.forward_only and params.eval:
raise ValueError(... | 35564684eef73adf821989dea27bfdc7de0443ae | 703,258 |
def quote_logvalue(value):
"""Return a value formatted for use in a logfmt log entry.
The input is quoted if it contains spaces or quotes; otherwise returned unchanged
"""
s = str(value)
if " " in s or '"' in s:
s = s.replace('"', "\\" + '"')
return f'"{s}"'
return s | 15dd0789b5a7ce4e18eece37ad0cac59d9cd2332 | 703,259 |
def flatten(master):
"""
:param dict master: a multilevel dictionary
:return: a flattened dictionary
:rtype: dict
Flattens a multilevel dictionary into a single-level one so that::
{'foo':
{'bar':
{
'a': 1,
'b': True,
... | d31325219e43ee5c047c1a78589d94e2d7c62709 | 703,260 |
def m21_midievent_to_event(midievent):
"""Convert a music21 MidiEvent to a tuple of MIDI bytes."""
status = midievent.data + midievent.channel - 1
return (status, midievent.pitch, midievent.velocity) | 3950b4e6715ac4de2dbdcc2d87d5cf51387a220c | 703,261 |
import copy
def merge_dict(d1, d2, overwrite=False):
"""Merge contents of d1 and d2 and return the merged dictionary
Note:
* The dictionaries d1 and d2 are unaltered.
* If `overwrite=False` (default), a `RuntimeError` will be raised when
duplicate keys exist, else any existing keys in d1 are s... | d680dcc3039804c340fc488a488fae1d891a8d1b | 703,263 |
def add_month(year, month, delta):
"""
Helper function which adds `delta` months to current `(year, month)` tuple
and returns a new valid tuple `(year, month)`
"""
year, month = divmod(year * 12 + month + delta, 12)
if month == 0:
month = 12
year = year - 1
return year, month | 8f509bba44bb27579b948c3b26e5f7c027be445c | 703,269 |
import json
def __get_job_obj(profile):
"""Return the 'job' object in the profile."""
with open(profile, 'rt') as json_fobj:
data = json.load(json_fobj)
return data['jobs'][0] | 2af6658f8a54987229dffe35efe37d2dace9f0bb | 703,270 |
import torch
def model_fn(batch, model, criterion, device):
"""Forward a batch through the model."""
mels, labels = batch
mels = mels.to(device)
labels = labels.to(device)
outs = model(mels)
loss = criterion(outs, labels)
# Get the speaker id with highest probability.
preds = outs.... | 2b9907e8f0fbec50b955082efb30d8cddc88b663 | 703,271 |
def get_context(canvas):
"""Get ``cairo.Context`` used to draw onto the canvas."""
return canvas.renderer._get_context() | 1d68e6eb742dff906b6e64c85d9609e34f508b77 | 703,274 |
def fahrenheit_from(celsius):
"""Convert Celsius to Fahrenheit degrees."""
try:
fahrenheit = float(celsius) * 9 / 5 + 32
fahrenheit = round(fahrenheit, 3) # Round to three decimal places
return str(fahrenheit)
except ValueError:
return "invalid input" | e31ac8c62f108652fe3cc2ee1516a5b3a1a9e568 | 703,276 |
def big_endian_to_int(value):
"""
Ethereum RLP Utils:
Convert big endian to int
:param value: big ending value
:return: int value
"""
return int.from_bytes(value, byteorder="big") | 57c9b05471e3558cae1a0d36dd3089b4d180faeb | 703,277 |
def _read_files(file_names):
"""
Reads content from all specified file names
Args:
file_names: set of file names
Returns:
list of lines from all files
"""
all_lines = []
for file_name in file_names:
try:
with open(file_name) as f:
lines = f... | 98fabeeaeaf6dd142acaf7cf84c0ac25583bcdbf | 703,278 |
def create_track_log(db, sessionID):
"""
Instantiate the Track History Collection.
:param db: The database object.
:param sessionID: Current user's session ID.
:return: The Track History Collection object.
"""
collection_name = 'track_history_' + sessionID
track_collection = db[collecti... | 5fb72ae83e5a805ad8e35f62c9474e51170d3fb2 | 703,279 |
def detect_api_mismatch(ref_api, other_api, *, ignore=()):
"""Returns the set of items in ref_api not in other_api, except for a
defined list of items to be ignored in this check.
By default this skips private attributes beginning with '_' but
includes all magic methods, i.e. those starting and ending ... | 4353f3f6b825570e3193b57dbb08c3a26c7f59b9 | 703,282 |
from typing import Iterable
import torch
def fuse_single_qubit_operators(
qubits: Iterable[int],
operators: Iterable[torch.Tensor],
):
"""Multiply together gates acting on various single qubits.
Suppose that we have a sequence of single-qubit gates that
should act, one after the other, on... | 640541a3b0a79deb819bafad5734aca3e0dde23d | 703,291 |
def tag_index(idx):
"""Return a mapping of tag names to index items.
"""
tagidx = dict()
for i in idx:
for t in i.tags:
if t not in tagidx:
tagidx[t] = set()
tagidx[t].add(i)
return tagidx | df3ee2a934bfe3c814a9c1ded8d83314064f38bd | 703,294 |
import math
def dist(p1, p2):
"""
Determines the straight line distance between two points p1 and p2 in euclidean space.
"""
d = math.sqrt(math.pow(p1[0] - p2[0], 2) + math.pow(p1[1] - p2[1], 2))
return d | 8a72ba5966452e7ac2e44f4c1f61d78071423ace | 703,298 |
from typing import List
import glob
def get_l10n_files() -> List[str]:
"""取得所有翻譯相關檔案列表,包括.pot .po .mo。
Returns:
List[str]: 翻譯相關檔案列表,包括.pot .po .mo。
"""
po_parser = 'asaloader/locale/*/LC_MESSAGES/asaloader.po'
pot_file = 'asaloader/locale/asaloader.pot'
po_files = glob.glob(po_parser)... | a783679261e7c9bd617728946d01a440b51cfb6a | 703,302 |
def filter_value(entry, values=None):
"""
Returns True if it should be filtered.
Only take calls with filter values in the list provided
if None provided, assume that filter_value must be PASS or blank '.'
"""
if values is None:
return len(entry.filter) != 0 and 'PASS' not in entry.filte... | 57ee5ab67fa07cb8c1379d303e9d636718025f45 | 703,303 |
def make_song_title(artists: list, name: str, delim: str) -> str:
"""
Generates a song title by joining the song title and artist names.
Artist names given in list format are split using the given delimiter.
"""
return f"{delim.join(artists)} - {name}" | 341db19af517c09633a6ebe37726c79c020f4780 | 703,305 |
def authorizeView(user, identifier):
"""
Returns True if a request to view identifier metadata is authorized.
'user' is the requestor and should be an authenticated StoreUser
object. 'identifier' is the identifier in question; it should be a
StoreIdentifier object.
"""
# In EZID, essentially all iden... | c831d74a229043a308226d6ae8078e5630507ded | 703,306 |
def clean_keyword(kw):
"""Given a keyword parsed from the header of one of the tutorials, return
a 'cleaned' keyword that can be used by the filtering machinery.
- Replaces spaces with capital letters
- Removes . / and space
"""
return kw.strip().title().replace('.', '').replace('/', '').replac... | eb8ab983bf60f5d1ca2996dc9568ded252d00479 | 703,307 |
from typing import Union
from pathlib import Path
import hashlib
def compute_md5(path: Union[str, Path], chunk_size: int):
"""Return the MD5 checksum of a file, calculated chunk by chunk.
Parameters
----------
path : str or Path
Path to the file to be read.
chunk_size : int
Chunk ... | 9e718630323b002307a54e7d3bbf936b6b94637a | 703,308 |
def denormalize(images, min_, max_):
"""scales image back to min_, max_ range"""
return [((i + 1) / 2 * (max_ - min_)) + min_ for i in images] | 3071e3c76754bda8ea2ce9607003cfd1b4f97e48 | 703,309 |
def version_is_locked(version):
"""
Determine if a version is locked
"""
return getattr(version, "versionlock", None) | b2f76d89c2d0082ad13d5d896e5360d394c83ee1 | 703,310 |
def mockup_return(*args, **kwargs):
"""Mockup to replace regular functions for error injection."""
return False | 92172e58a11e48a09c8f181ac55aa717b5fbb94d | 703,312 |
import re
def parse_life_105(file):
"""Parse a Life 1.05 file, returning a tuple:
positions: list of (x,y) co-ordinates
comments: all comments in file, as a list of strings, one per line.
"""
lines = file.split("\n")
comments = []
positions = []
ox, oy = 0, 0
x, y = ox, oy... | 3faf204bb52f5c1dd5b350401afdaa2a021f80d4 | 703,317 |
def index_of_spaces(text):
"""
Given text, return all space indices
@param text is the string to analyze
@returns a list of integers representing the indices
"""
res = []
for i in range(0, len(text)):
if text[i] == ' ':
res.append(i)
return res | 97b3618ffa54ee6d1b50c5bca3e196d3a6ae7f2a | 703,321 |
def insert_at_midpoint(item, iterable):
"""
Inserts an item at the index of the midpoint of a list
Returns that list with the item inserted
"""
midpoint = int(len(iterable) / 2)
iterable.insert(midpoint, item)
return iterable | 9801e2f4cd1011914f15634898ed4d502edfee34 | 703,325 |
def get_filenames_request(products, download_directory):
"""Get local files url corresponding to a Copernicus request (must be already downloaded).
:param products: (dict) Copernicus Hub query
:param download_directory: (str) Url of folder for downloaded products
:return: (list) List of strings with lo... | 5591948ce2445399d06da6c84f3fe1f6b8b4b128 | 703,326 |
def create_stream(data_type, transaction_id):
"""
Construct a 'createStream' message to issue a new stream on which data can travel through.
:param data_type: int the RTMP datatype.
:param transaction_id: int the transaction id in which the message will be sent on.
"""
msg = {'msg': data_type,
... | 6ceb6f259c590bdb21589c57ba053fad5c7e1851 | 703,327 |
def _version_string_to_tuple(version_string):
"""Convert a version_string to a tuple (major, minor, patch) of integers."""
return (int(n) for n in version_string.split('.')) | d2fe2a3d9f6f23d1d80c2808436386c18893828f | 703,328 |
from typing import Any
def is_action(value: Any) -> bool:
"""Returns ``True`` if the value is an action."""
return isinstance(value, dict) and "action" in value | 46c691c7afd221c0f77869428535f6b943332905 | 703,330 |
def name_to_components(name):
"""Converts a name to a list of components.
Arguments:
name - Name in the format /name1=value1/name2=value2/..
Returns: list of (name, value) tuples
"""
ret = []
components = [x for x in name.split('/') if x]
components = [x.split('=') for x in componen... | 5683e3c4fdce53b53431484a46cd23c8959d20a2 | 703,334 |
import re
def fixupAnchor(anchor):
"""Miscellaneous fixes to the anchors before I start processing"""
# This one issue was annoying
if anchor.get("title", None) == "'@import'":
anchor["title"] = "@import"
# css3-tables has this a bunch, for some strange reason
if anchor.get("uri", "").st... | ba352cc5b18f82000be3943cf03db8ebcb41ddff | 703,336 |
def has_trailing_character_return(str_multiline: str) -> bool:
"""
>>> has_trailing_character_return('jhgjh\\n')
True
>>> has_trailing_character_return('jhgjh\\ntestt')
False
"""
if len(str_multiline) and str_multiline[-1] == '\n':
preserve_trailing_linefeed = True
else:
... | 21e6a7c9bb76e37ee05ed61b2012ec3a92413540 | 703,338 |
import random
import string
def get_random_file_name(length: int) -> str:
"""Returns a random file name.
File name consists of lowercase letters, uppercase letters, and digits.
:param length: File name length.
"""
return ''.join(random.choice(string.ascii_lowercase
... | c6a7b2f58bc6d2eb457cee2c01222757c50f7eb9 | 703,348 |
def _iterations_implicit_bwd(res, gr):
"""Runs Sinkhorn in backward mode, using implicit differentiation.
Args:
res: residual data sent from fwd pass, used for computations below. In this
case consists in the output itself, as well as inputs against which we
wish to differentiate.
gr: gradients... | 8617b6bd8cab2535409e863dae31a928f4de81db | 703,353 |
import torch
def huber_loss_temporal(dvf):
"""
Calculate approximated temporal Huber loss
Args:
dvf: (Tensor of shape (N, 2, H, W)) displacement vector field estimated
Returns:
loss: (Scalar) huber loss temporal
"""
eps = 1e-8 # numerical stability
# magnitude of the d... | 12329846e15c18ff9d59aee2f27377ce38eb8208 | 703,354 |
def _get_valid_filename(string):
"""Generate a valid filename from a string.
Strips all characters which are not alphanumeric or a period (.), dash (-)
or underscore (_).
Based on https://stackoverflow.com/a/295146/4798943
Args:
string (str): String file name to process.
Returns:
... | 93777a5458c00a0a751f77953d718080cf51088e | 703,362 |
def parse_output(filename):
"""
This function parses the output of a test run.
For each run of the test, the program should print the following:
## ID: result: [OK|FAIL]
## ID: cycles: N_CYCLES
## ID: instructions: N_INSTR
## ID: Key: Value
Multiple runs are allowed.
... | e24e961e5222d952e79369d22365723919cc3bfa | 703,363 |
from typing import Any
from typing import List
def ensure_list(data: Any) -> List:
"""Ensure input is a list.
Parameters
----------
data: object
Returns
-------
list
"""
if data is None:
return []
if not isinstance(data, (list, tuple)):
return [data]
ret... | 58016feaf49d63255944fa615e7e2e1dac6dcc76 | 703,372 |
def init_split(df, featname, init_bins=100):
"""
对df下的featname特征进行分割, 最后返回中间的分割点刻度
为了保证所有值都有对应的区间, 取两个值之间的中值作为分割刻度
注意这里的分割方式不是等频等常用的方法, 仅仅是简单地找出分割点再进行融合最终进行分割
注意, 分出的箱刻度与是否闭区间无关, 这个点取决于用户,这个函数仅考虑分箱的个数
同时, 分箱多余的部分会进入最后一个箱, 如101个分100箱, 则最后一个箱有两个样本
Parameters:
----------
df: dataframe,... | 172f48bb019fd4cf4941b2ff0fefcb24709fe7a4 | 703,375 |
from typing import OrderedDict
def filter_excluded_fields(fields, Meta, exclude_dump_only):
"""Filter fields that should be ignored in the OpenAPI spec
:param dict fields: A dictionary of of fields name field object pairs
:param Meta: the schema's Meta class
:param bool exclude_dump_only: whether to ... | a39a7665052cde0ba9f694696a57f2b1f6ca0603 | 703,378 |
def findNearestNeighbourPixel(img, seg, i, j, segSize, fourConnected):
"""
For the (i, j) pixel, choose which of the neighbouring
pixels is the most similar, spectrally.
Returns tuple (ii, jj) of the row and column of the most
spectrally similar neighbour, which is also in a
clump of size... | e205652d7b39c922a203162f3cdc58672347b938 | 703,379 |
from typing import List
def readFile(filename: str) -> List[str]:
"""
Reads a file and returns a list of the data
"""
try:
with open(filename, "r") as fp:
return fp.readlines()
except:
raise Exception(f"Failed to open {filename}") | a5817ab563b83d5cf4999290d10a14a0b68954b6 | 703,381 |
def get_trunc_hour_time(obstime):
"""Truncate obstime to nearest hour"""
return((int(obstime)/3600) * 3600) | 8379aafc76c1987f537ea294c7def73ad32f1b23 | 703,384 |
import re
def normalize_package_name(python_package_name):
"""
Normalize Python package name to be used as Debian package name.
:param python_package_name:
The name of a Python package as found on PyPI (a string).
:returns:
The normalized name (a string).
>>> from py2deb impor... | 47a850c601e64b570470a339769742d8f3732e28 | 703,385 |
def url_join(*args):
"""Join combine URL parts to get the full endpoint address."""
return '/'.join(arg.strip('/') for arg in args) | 2b8409910186d3058c2e49bbf6f974a7cfceeffb | 703,389 |
def is_pairwise_disjoint(sets):
"""
This function will determine if a collection of sets is pairwise disjoint.
Args:
sets (List[set]): A collection of sets
"""
all_objects = set()
for collection in sets:
for x in collection:
if x in all_objects:
retur... | 4d5c434b2db2cb167f51aa4c04534a9b12239547 | 703,391 |
def format_timedelta(days: int = 0, hours: int = 0, minutes: int = 0,
seconds: int = 0) -> str:
"""Returns a simplified string representation of the given timedelta."""
s = '' if days == 0 else f'{days:d}d'
if hours > 0:
if len(s) > 0:
s += ' '
s += f'{hours:... | 6414e2be5a01f178d6515ab6f21ea7c5ab4d5004 | 703,402 |
def accuracy(letters, target_string):
""" Comparing accuracy to the correct answer.
Args:
letters(np.array): (num_chars, )
target_string(str)
Return:
float: accuracy.
"""
count = 0
assert len(letters) == len(target_string)
for i in range(len(target_string)):
... | 5898a086997d3b9ff9f9bcf84b747dd553a0e4cb | 703,404 |
def relu(attrs, inputs, proto_obj):
"""Computes rectified linear function."""
return 'relu', attrs, inputs | d45c7f517c2cef57206db56b1ed7402127e72a01 | 703,407 |
import random
import string
def random_string(length=16):
"""Generate a random string of the given length."""
result = ""
while len(result) < length:
result += random.choice(string.ascii_letters + string.digits)
return result | 04bf92658ce8d9535aa91c751c5d9f1746827eaf | 703,412 |
def numpy_unpad(x, pad_width):
"""Unpad an array.
Args:
x (numpy.ndarray): array to unpad
pad_width (tuple): padding
Returns:
numpy.ndarray
"""
slices = []
for c in pad_width:
e = None if c[1] == 0 else -c[1]
slices.append(slice(c[0], e))
return x[tu... | 31f41a7a741d7efa870670c95a8acf8be365975a | 703,416 |
def validate_spec(index, spec):
""" Validate the value for a parameter specialization.
This validator ensures that the value is hashable and not None.
Parameters
----------
index : int
The integer index of the parameter being specialized.
spec : object
The parameter specializa... | 3612d927ef7e61613e0991ffc04ea76555d1b115 | 703,418 |
def _replace_suffix(string, old, new):
"""Returns a string with an old suffix replaced by a new suffix."""
return string.endswith(old) and string[:-len(old)] + new or string | 4e487f62126b130d973f249cd34abc5a75df3eaa | 703,422 |
def is_empty_json_response_from_s3(context):
"""Check if the JSON response from S3 is empty (but not None)."""
return context.s3_data == {} | 6ec3a41646de74d82f3786e772228da55d91b63a | 703,423 |
def mock_validator_execute_validator(*args, **kwargs):
"""
Mock method to just return the builded command line without
executing it.
"""
cls = args[0]
command = args[1]
return command | d03cc70f1f0a5bd59e7a116e3774b99aa8db5a03 | 703,424 |
import logging
def _set_logger(
logger_file_path: str,
logger_name: str = "default_logger",
write_to_console: bool = True,
) -> logging.Logger:
"""Set logger to log to the given path.
Modified from https://docs.python.org/3/howto/logging-cookbook.html
Args:
logger_file_path (str): Fi... | 338999fbcd34367f1dc4140143688965663bf486 | 703,426 |
import torch
def dagger(x: torch.Tensor) -> torch.Tensor:
"""Conjugate transpose of a batch of matrices. Matrix dimensions are
assumed to be the final two, with all preceding dimensions batched over."""
return x.conj().transpose(-2, -1) | 672d26333182803b18f3d1d10e49ef393e216f5f | 703,428 |
def find_left_anchor_index(fragment_info, fragments):
"""
Description:
Use the fragment information to find which fragment is the left anchor
:param fragment_info: [list[dict]] the list of fragment information
:param fragments: [list] the list of fragments being searched
:return: left_anchor_ind... | 502473f7fee00a5ccd1ed3d6cf5c938e8c4d2041 | 703,430 |
def get_all_preconditions(action_set):
"""
Returns a set of all preconditions for the actions in the given set
"""
all_precons = set()
for a in action_set:
all_precons.update(a.precondition)
return all_precons | 1697c2d013b07bbfc24ca6273d16523eb1d83acf | 703,431 |
def f_line(x, m, b):
"""
Line fit with equation y = mx + b
Parameters
----------
x : array
x values
m : float
slope
b : float
y-intercept
Returns
-------
y : array
y values
"""
y = m*x + b
return y | daf437461c2e8723a824e4083794d1f6ea6b368b | 703,432 |
def getDistance(sensor):
"""
Return the distance of an obstacle for a sensor.
The value returned by the getValue() method of the distance sensors
corresponds to a physical value (here we have a sonar, so it is the
strength of the sonar ray). This function makes a conversion to a
distance value ... | d00b1d201fb59939d2b8a2e57bfa35588780b6d5 | 703,433 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.