content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def sample_from_simplex(rng, dim):
"""Uniformly samples a probability vector from a simplex of dimension dim."""
alpha = [1] * dim
return rng.dirichlet(alpha) | d034c4502634678874f89e17f2fde28eb8c28e0b | 13,206 |
import math
def getDistance(p1, p2):
"""Return the distance between p1 and p2."""
return math.sqrt(sum([(p1[i] - p2[i])**2 for i in range(max(len(p1), len(p2)))])) | 28d8156ad1eb5557a3fb3fa8bc7a94a66d06db3e | 13,208 |
def file_is_pdf(filename: str) -> bool:
"""
Check if `filename` has the .pdf extension.
Args:
filename (str): Any filename, including its path.
Returns:
True if `filename` ends with .pdf, false otherwise.
"""
return filename.endswith(".pdf") | ba9a540a1f0edd33e48010a001de4493bdff80d9 | 13,217 |
import torch
def torch_hilbert(x_real, n_fft=None):
"""
Obtain imaginary counterpart to a real signal such that there are no negative frequency
components when represented as a complex signal. This is done by using the Hilbert transform.
We end up with an analytic signal and return only the imaginary ... | 33bb230c78beb84ca5569c5fca8ebb61a36fd7c5 | 13,221 |
import math
def calcCirclePos(robotIdx, numRobots, radius=3, center=(0,0)):
"""
Helper function to distribute robot positions on a circle.
"""
gamma = 2*math.pi / numRobots
x = radius * math.cos(gamma * robotIdx) + center[0]
y = radius * math.sin(gamma * robotIdx) + center[1]
phi = gamma *... | 393c044dcb4016c34b8efe2a7acd185b45c52467 | 13,224 |
import re
def is_valid_vlive_url(url: str) -> bool:
"""Uses a regex to check if the given url is a valid 'vlive.tv./video/' address."""
# VLIVE videos are only identified by numbers in the url (unlike Youtube IDs,
# for example)
vlive_url_regex = r"(vlive\.tv\/video\/[0-9]*)"
if not re.search(vl... | 35c741ea512cad5edd791ebbb8acef99b19d84d3 | 13,227 |
import torch
def embedding_similarity(
batch: torch.Tensor,
similarity: str = 'cosine',
reduction: str = 'none',
zero_diagonal: bool = True
) -> torch.Tensor:
"""
Computes representation similarity
Example:
>>> from pytorch_lightning.metrics.functional import embedding_similarity
... | dda82b8fa4dc4f3760a5c7ec329c77b980f3860c | 13,234 |
def _compute_input_padding(size, bcount, bsize, boffset, bstride):
"""Computes the padding for the operation.
:param size: `[SZH, SZW]` list-like of ints, size of image
:param bcount: `[BCH, BCW]` list of ints
:param bsize:
:param boffset:
:param bstride:
:returns: `pad_h, pad_w` for _pad_inputs function... | bce6ed06406f0d259d029c745e3c9f5ff015959e | 13,242 |
from typing import Union
import string
def _strip_unwanted_chars(price: Union[int, str]) -> str:
"""Returns price text with all unnecessary chars stripped (nonnumeric etc).
Examples:
"100" should return "100"
"100 yen" should return "100"
"10,000" should return "10000"
Args:
price: The raw val... | 18679bbd7e53fcea7cadd3343fc82a3dd875f8af | 13,243 |
import warnings
def update(data):
"""Update the data in place to remove deprecated properties.
Args:
data (dict): dictionary to be updated
Returns:
True if data was changed, False otherwise
"""
updated = False
if 'include' in data:
msg = ("included configuration files... | 2e604cde4455bb1ab784651798fb3be0cd3733db | 13,247 |
def _default_filter(line):
"""Default bad header filter.
Filters out lines that start with ">From" or "From " (no colon).
"""
line = line.strip()
return (False if line.startswith('>From') or line.startswith('From ') else
True) | 4867ba376914d7d688038c8471f09405b0a17c24 | 13,253 |
def parse_starlog(path_to_log):
"""Parse star logfile into a dict.
Args:
path_to_log: filepath containing the star run log
Returns:
dict that contains metrics from star log
"""
qc_dict = {}
with open(path_to_log) as f:
for line in f:
if "|" in line:
... | ced4f91846a4c658c1801eeeb75430cdecafb32d | 13,258 |
def get_universe_id_from_script(universe_script):
""" Get the id of a universe given the universe script """
return int(universe_script.split('.')[0].split('_')[1]) | a714d1de25f4972c1cccd6c70453d01e2938af2b | 13,260 |
def _cytomine_parameter_name_synonyms(name, prefix="--"):
"""For a given parameter name, returns all the possible usual synonym (and the parameter itself). Optionally, the
function can prepend a string to the found names.
If a parameters has no known synonyms, the function returns only the prefixed $name.
... | 4d8d58571b03182cf31546c370fda81e2caf5800 | 13,262 |
def read_prot(filepath):
"""
This function accepts the filepath of a protein to align, ignores the first line
(proceeded by '>' char), strips newlines, and returns the protein as a single string.
"""
seq = ""
with open(filepath) as f:
for line in f:
if not line.startswith(">"... | e09fab92fca28601d5c92d927ceddccaaf1f5569 | 13,264 |
def _create_table_query(table_name: str) -> str:
"""Build SQL query to create metrics table."""
return (
f"CREATE TABLE IF NOT EXISTS {table_name}("
f" id SERIAL PRIMARY KEY,"
f" page_url TEXT,"
f" http_code SMALLINT,"
f" response_time INT,"
f" time... | 427bf61a475c0f012b0242880400d1573ae8bbd1 | 13,268 |
def to_binary(df, variable_names):
"""
Recode specified variables of dataframe to binary; any positive value is
set to 1 and all other values are set to 0. This replaces the existing
column(s).
Parameters
----------
df : pandas DataFrame
dataframe containing variables to be reco... | 604b5a84a7ade73b9e569fa4d238f32e9039acee | 13,271 |
def get_http_body(http_request):
"""Given a HTTP request, return the body."""
return http_request.split("\r\n\r\n")[1] | 4a11c97f0eeddac933e8b311d9c1cfda6e61674c | 13,273 |
def parse_gn_flags(gn_lines):
"""
Parse lines of GN flags into dictionary
"""
gn_args = {}
for line in gn_lines:
name, var = line.strip().partition("=")[::2]
gn_args[name.strip()] = var.strip()
return gn_args | 98d8f91e9defea1484a569deb70fb7cc62b2c743 | 13,275 |
def floor(x,unit=1):
""" Returns greatest multiple of 'unit' below 'x' """
return unit*int(x/unit) | b289bf714eb3ecf23072533a51badeac43743686 | 13,279 |
import hashlib
import io
def calculate_file_checksum(path):
"""
Calculate the MD5 sum for a file:
Read chunks of a file and update the hasher.
Returns the hex digest of the md5 hash.
"""
hasher = hashlib.md5()
with io.FileIO(path, 'r') as fp:
while True:
buf = fp.read(6... | 6bddfd83a8bc326fcfea8fb69affde45f3cb1dd8 | 13,282 |
import torch
def get_position(lens, maxlen, left_pad=False):
""" transform sequence length to a series of positions. e.g., 3 -> 1,2,3"""
batch_size = lens.size(0)
pos = torch.zeros((batch_size, maxlen), dtype=torch.long, device=lens.device)
for i, input_len in enumerate(lens):
if not left_pad:... | 48c2ac5c0bde1f554b3b44c82177945ab2c667ab | 13,283 |
def convert_bxd_name(name: str) -> str:
"""
the names of BXDs are not consistent across all metadata
and VCF files, so we sometimes have to convert their names
>>> convert_bxd_name("4512-JFI-0469_BXD100_RwwJ_phased_possorted_bam")
"BXD100_RwwJ_0469"
>>> convert_bxd_name("4512-JFI-0410_BXD013_T... | 577f936d81fdd7a87bd02fec069ff5f09e3b1412 | 13,284 |
import torch
def makeInp(inputs):
"""Move tensors onto GPU if available.
Args:
inputs: A dict with a batch of word-indexed data from DataLoader. Contains
['brk_sentence', 'bs_inp_lengths', 'style', 'sentence', 'st_inp_lengths', 'marker', 'mk_inp_lengths']
Returns:
inputs: The dict with same structure but s... | af00b78f33627f45e505a6b8c75fb07ef29b94e6 | 13,285 |
import warnings
def rename_internal_nodes(tree, names=None, inplace=False):
""" Names the internal according to level ordering.
The tree will be traversed in level order (i.e. top-down, left to right).
If `names` is not specified, the node with the smallest label (y0)
will be located at the root of t... | d5df42023afe184af41d7553b2e1491b09d5edc1 | 13,286 |
def headers(mime, length):
"""Returns a list of HTTP headers given the MIME type and the length of the
content, in bytes (in integer or sting format)."""
return [('Content-Type', mime),
('Content-Length', str(length))] | da5f73591bf9d4bbc8b1d01f4d6babf0de54ce00 | 13,287 |
import statistics
def run_stats(this_set):
""" Find standard deviation and mean (average) for the data set. """
# Simply calculate Mean & StdDev for this set.
# Return TUPLE of FLOATS
return statistics.mean(this_set), statistics.stdev(this_set) | 35ce499654bf7e8fe43d862b5456b0578a093fc7 | 13,289 |
def generate_csv_url(sheet_url):
"""
Utility function for generating csv URL from a google sheets link
This function generates a link to a csv file from a link used to edit a google sheets file.
The gid must be present in the URL.
Parameters
----------
sheet_url : str
The URL for the... | d941ef98f3400175b9db4f7ef5da858fc6426caf | 13,291 |
def byte_array_declaration(data: bytes, name: str) -> str:
"""Generates a byte C array declaration for a byte array"""
type_name = '[[maybe_unused]] const std::byte'
byte_str = ''.join([f'std::byte{{0x{b:02x}}},' for b in data])
array_body = f'{{{byte_str}}}'
return f'{type_name} {name}[] = {array_b... | 015f0cb1a4dfd94b6f488b4eae0b58860da4d1dc | 13,295 |
def shorten(s: str, max_len: int = 60) -> str:
"""Truncate a long string, appending '...' if a change is made."""
if len(s) < max_len:
return s
return s[:max_len-3] + '...' | 8bafe69253e12a67fdb4c476a2d4b55f6ad4d2af | 13,302 |
import json
def elasticsearch_bulk_decorate(bulk_index, bulk_type, msg):
""" Decorates the msg with elasticsearch bulk format and adds index and message type"""
command = json.dumps({'index': {'_index': bulk_index, '_type': bulk_type}})
return '{0}\n{1}\n'.format(command, msg) | e215ab15b347046b22dcc46317632c68fa9d36c0 | 13,303 |
import itertools
def get_hp_fold_iterator(hp_grid, num_folds):
""" Create an iterator over all combinations of hyperparameters and folds
"""
hp_grid = list(hp_grid)
folds = list(range(num_folds))
hp_fold_it = itertools.product(hp_grid, folds)
hp_fold_it = list(hp_fold_it)
return hp_f... | ea16c3b3867dc87a18f2dc1dc2f59e5a48f7c04d | 13,304 |
def sub_dir_algo(d):
""" build out the algorithm portion of the directory structure.
:param dict d: A dictionary holding BIDS terms for path-building
"""
return "_".join([
'-'.join(['tgt', d['tgt'], ]),
'-'.join(['algo', d['algo'], ]),
'-'.join(['shuf', d['shuf'], ]),
]) | 73d91f4f5517bbb6966109bd04f111df5f6302e4 | 13,307 |
def _get_words(data_dir):
"""Get list of words from history file.
Parameters
----------
data_dir : pathlib.Path
Directory where data is saved.
Returns
-------
word_list : list of str
List of words.
"""
words_file = data_dir.joinpath("words.txt")
word_list = []
... | 40728b61ed4af05d26a8ece678661cddf838602a | 13,308 |
def containsAll(target, keys):
"""Returns true iff target contains all keys.
"""
result = ((i in target) for i in keys)
return all(result) | 75fda44a515e2249bd4c6ee1146c36eb91657b56 | 13,312 |
import re
def parse_log_entry(msg):
"""
Parse a log entry from the format
$ip_addr - [$time_local] "$request" $status $bytes_sent $http_user_agent"
to a dictionary
"""
data = {}
# Regular expression that parses a log entry
search_term = '(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+\-\s+\[(... | f237696e8215793b4cf17e7b20543ac01494b686 | 13,325 |
import tempfile
def get_logprop_file(logger, template, pattern, project):
"""
Return the filename of file with logging properties specific for given
project.
"""
with open(template, 'r') as f:
data = f.read()
data = data.replace(pattern, project)
with tempfile.NamedTemporaryFile... | 061254a5e65a08c7e5ee8367c94abaee04238e61 | 13,335 |
def Iyy_beam(b, h):
"""gets the Iyy for a solid beam"""
return 1 / 12. * b * h ** 3 | 8912b769b1bf8f91d2bb7eefad261c0e4f9f4026 | 13,336 |
def read_user_header(head):
"""
The 'User-Id' header contains the current online user's id, which is an integer
-1 if no user online
:param head: the request's header
:return: online user's id, abort type error if the header is not an integer.
"""
try:
return int(head['User-Id'])
... | 95586f32b698283f33c9271b5ffdf61a934dbb4a | 13,341 |
def y_intercept_line(slope, point):
"""
Calculate a y-intercept of a line for given values of slope and point.
Parameters
----------
slope : float
A value of slope line.
point : tuple
A tuple with xy coordinates.
Returns
-------
y-intercept : float
A vaule o... | 839cdaa4b4646ebbdc5a2b941e5e14b45587cd24 | 13,345 |
import itertools
def _groupby_leading_idxs(shape):
"""Group the indices for `shape` by the leading indices of `shape`.
All dimensions except for the rightmost dimension are used to create
groups.
A 3d shape will be grouped by the indices for the two leading
dimensions.
>>> for key, idxs... | cc71304b9da4df2c9a32e009e3159bc9777d3e70 | 13,353 |
def _recvall(sock, size):
"""
Read exactly the specified amount of data from a socket. If a
``recv()`` call returns less than the requested amount, the
``recv()`` is retried until it either returns EOF or all the
requested data has been read.
:param sock: A socket from which bytes may be read.... | 6a456ee4925b7faa25646e9bc6e702848d047783 | 13,354 |
def get_expected_name(logfile):
"""get the name of the file with the expected json"""
return logfile.with_name(logfile.stem + "-expected.json") | 7bc886fdbc23a53610817391db3fccbe53fbab81 | 13,359 |
def get_free_symbols(s, symbols, free_symbols=None):
"""
Returns free_symbols present in `s`.
"""
free_symbols = free_symbols or []
if not isinstance(s, list):
if s in symbols:
free_symbols.append(s)
return free_symbols
for i in s:
free_symbols = get_free_sym... | 873d0bac2fa24db3b4ded6d9d867ca703d0a2314 | 13,362 |
def zeropad_1501(name):
""" Arxiv IDs after yymm=1501 are padded to 5 zeros """
if not '/' in name: # new ID
yymm, num = name.split('.')
if int(yymm) > 1500 and len(num) < 5:
return yymm + ".0" + num
return name | d2a46fccf649a59194b55ff0542bd6bfbe0d8629 | 13,364 |
def __labels(known_labels, trans, labels):
"""Convert list of label names to label dictionaries with all info.
"""
return {
lbl: {
"title": trans.gettext(known_labels[lbl]['title']),
"description": trans.gettext(known_labels[lbl]['description']),
"severity": known... | 55652386496f1312ae66f64ae7673ad43d1e1879 | 13,365 |
import binascii
def hexlify(data):
"""The binascii.hexlify function returns a bytestring in
Python3, but sometimes we want to use its output to
show a log message. This function returns an unicode
str, which is suitable for it."""
return binascii.hexlify(data).decode('ascii') | a24bf82a71a15dab12b2f683833c8a250a63097e | 13,366 |
def command_eval(expr: str):
"""Evaluates a given expression."""
# Command callbacks can return values which will be passed to the caller of `dispatch()`
return eval(expr) | 0664e4c3f6f0aad320642b000e4bbf242a5b219a | 13,381 |
import requests
def get_episode_data(cfg, episode_id):
"""
Requests episode information from Opencast.
:param episode_id: Unique identifier for episode
:param cfg: Opencast configuration
:return: Tuple of episode title, parent seriesId and parent series title
"""
url = cfg['uri'] + "/api/... | 41aa3053312827d7081776fcb3c414e358f0cc61 | 13,385 |
def isempty(prt_r):
"""Test whether the parent of a missingness indicator is empty"""
return len(prt_r) == 0 | 167e6cb0a63116c6157291a6ba225b14fbfebe11 | 13,386 |
import math
def vortex_feldtkeller(beta, center, right_handed=True, polarity=+1):
"""
Returns a function f: (x,y,z) -> m representing a vortex
magnetisation pattern where the vortex lies in the x/y-plane (i.e.
the magnetisation is constant along the z-direction), the vortex
core is centered around... | 4714dcdfb2b96413562a6f531be944963a3a3b2f | 13,389 |
from typing import Union
from typing import Optional
import re
def convert_to_int(value: Union[str, float]) -> Optional[int]:
"""
Converts string and float input to int. Strips all non-numeric
characters from strings.
Parameters:
value: (string/float) Input value
Returns:
... | 15036374ca499edfa58e2865d4f5fb70c3aecb40 | 13,393 |
def format_describe_str(desc, max_len=20):
"""Returns a formated list for the matplotlib table
cellText argument.
Each element of the list is like this : ['key ','value ']
Number of space at the end of the value depends on
len_max argument.
Parameters
----------
desc: dict
... | 9d172ea7afc7fbcb10b4fdc3e120cd955b9eb196 | 13,395 |
def minutes_to_seconds(minutes):
"""A function that converts minutes to seconds
:param minutes: The number of minutes do be converted
:return: The number of seconds in a give number of minutes
"""
return 60 * minutes | b9dee8e669f7659fe669e5b97ef79e8e035b63bf | 13,399 |
def escapes_sub(match):
"""Substitutes escaped characters."""
return match.group(1) | f9d535bfdeea2cf4791301c348d513b606ed258d | 13,403 |
def read_data_line(line):
"""Process a line from data file.
Assumes the following format:
WORD W ER D
i.e. word tab separated with pronunciation where pronunciation has space
separated phonemes
Args:
line: string representing the one line of the data file
Returns:
chars:... | 66a840e2f2dfbc5e6c9d4a62c938b1bc60454a1f | 13,406 |
def formatted_constituent_array(constituent_array):
"""
Given a constituent array of Species, return the classic CALPHAD-style interaction.
Parameters
----------
constituent_array : list
List of sublattices, which are lists of Species in that sublattice
Returns
-------
str
... | b1e60d21c28b66620eaffed1cda20abcb394a833 | 13,411 |
def calc_automated_readability_index(
n_letters: int,
n_words: int,
n_sents: int,
a: float = 6.26,
b: float = 0.2805,
c: float = 31.04,
) -> float:
"""
Вычисление автоматического индекса удобочитаемости
Описание:
Чем выше показатель, тем сложнее текст для чтения
Резу... | d2a49044749dc93bb8684b27a81f47ff1498cc46 | 13,412 |
def FirstFree(seq, base=0):
"""Returns the first non-existing integer from seq.
The seq argument should be a sorted list of positive integers. The
first time the index of an element is smaller than the element
value, the index will be returned.
The base argument is used to start at a different offset,
i.e... | 42323664c7bb2c59506ed3b24115a38bc0fcf63d | 13,413 |
from typing import Iterable
def flatten(nested):
"""Flatten a nested sequence where the sub-items can be sequences or
primitives. This differs slightly from itertools chain methods because
those require all sub-items to be sequences. Here, items can be primitives,
sequences, nested sequences, or any c... | 464cd221dfaf6f842bf6da0d96ad8322d1c84e71 | 13,415 |
def calculadora(x = 1, y = 1):
# Docstring
"""
Calculadora
-----------
Cria um dicionário com as principais operações matemáticas, dado dois números.
args
----
x : int ou float
Primeiro número de entrada
y : int ou float
Segundo número de entrada
re... | 6fad4c8c1d388cb5b77c52d68f63a37070379657 | 13,418 |
def move_by_month(month, offset):
"""Get the month with given offset raletive to current month."""
return (((month - 1) + offset) % 12) + 1 | 38229d5a45b4643dfeb64e0e311949b9e26625ef | 13,421 |
def is_image_file(filename):
"""Checks if a file is an image.
Arguments:
filename {str} -- File path.
Returns:
bool -- True if the path is PNG or JPG image.
"""
return any(filename.endswith(extension) for extension in [".png", ".jpg", ".jpeg"]) | d2971a57cd4fda456384f1e2f839dc32b3c897a6 | 13,423 |
def break_up_sink_info(sink_info:str) -> dict:
"""Break up the info into a dictionary.
Parameters
----------
sink_info: str
The sink info from pulsemixer.
Returns
-------
dict
A dictionary of sink information.
"""
pieces = sink_info.split(",")
if "\t" in pieces[... | 790c757500528af28a6a01bc0cea2b7772d2ea55 | 13,434 |
def project_content_url(project, **kwargs):
"""
Get the URL for a file path within a project.
This can significantly reduce the number of queries instead
of fetching the project and account for every file in a list
which happens when using `{{ file.download_url }}`.
"""
return project.conte... | 91a6a927b3fa88f4b9e976093965a1176657532e | 13,435 |
def mavlink_latlon(degrees):
"""Converts a MAVLink packet lat/lon degree format to decimal degrees."""
return float(degrees) / 1e7 | 20d883e45f99cca3c99eeb9d7c5fae96db03fd5a | 13,436 |
import itertools
def _merge_dicts(first, second):
"""Merge two dicts into a new one
Args:
first (dict): Primary dict; if a key is present in both, the value from this
dict is used.
second (dict): Other dict to merge.
Returns:
dict: Union of provided dicts, with value fr... | 85b3377d25d730b32c9bf925bfde375db5c49450 | 13,439 |
def accuracy(actual_y: list, predicted_y: list) -> float:
"""
Calculate the value of accuracy based-on predictions
:param actual_y:a list containing initial Y values generated by 'y_generator'
function
:param predicted_y: a list containing predicted Y values generated by
'predict_y_value... | 7082d0e5505fc58e9ba80883b63bec98f4632676 | 13,443 |
def dict2columns(data, id_col=None):
"""Convert a dict-based object to two-column output.
Also make sure the id field is at top.
"""
if not data:
return ({}, {})
else:
if id_col is not None and id_col in data:
keys = [id_col]
[keys.append(key) for key in sort... | 24917339d53febc4239e21ebb8b39e487f45a370 | 13,444 |
def resolve_int_list_arg(arg):
"""Resolve a CLI argument as a list of integers"""
if arg is None:
return None
if isinstance(arg, int):
return [arg]
if isinstance(arg, str):
return [int(arg)]
if isinstance(arg, tuple):
# Interpret as range (ignore any other items in tu... | 5201d191946c69e10253e476341ab70c76b3a67d | 13,445 |
def groupwise_normalise(gs):
"""
Normalises each group of GeoSeries
:param gs: GeoSeries
:return: normalised GeoSeries
"""
return gs.groupby(level=0).apply(lambda x: x / x.sum()) | e0c87701658481ccea01828c75244b7a1043ee29 | 13,447 |
from typing import OrderedDict
def read_populations(flname):
"""
Read populations from a file.
We assume that the file has one population per line. The population name
comes first and is followed by a comma. The name of each sample follows,
also separated by comma.
For example:
pop1,s... | 9467bf2e882a2de0ebfb1ecfb566baeab16a1500 | 13,455 |
from datetime import datetime
def get_unix(str_ts, date_format):
"""Get unix timestamp from a string timestamp in date_format.
Args:
str_ts: string timestamp in `date_format`
date_format: datetime time stamp format
Returns:
int: unix timestamp
"""
return datetime.strptim... | 6d0c591734fa78defed11cd5ed8c66da63ad3b5b | 13,457 |
def replace_underscore_with_space(original_string):
"""
Another really simple method to remove underscores and replace with spaces for titles of plots.
Args:
original_string: String with underscores
Returns:
replaced_string: String with underscores replaced
"""
return original_... | 27bea63c33c2ffe44b1ddc591a7813d8830e9f76 | 13,462 |
def is_submod(mod_obj):
"""
Find out whether module has a parent or not.
:param mod_obj: module object
:return: module status
"""
try:
bt = mod_obj.get('belongs-to')
if not bt:
return False
return True
except Exception as e:
return False | 274d985b3b7b07f02e919af20ed7fd4531136ccc | 13,464 |
def CCW_ps(Pxx, Pyy, Pxy):
"""Counter clockwise power spectrum."""
QS = Pxy.imag
return (Pxx + Pyy + 2*QS)/2. | 76710ff31e4fead278afc9eb37691f2178f45def | 13,472 |
def check_interval(child_span, parent_span):
"""
Given a child span and a parent span, check if the child is inside the parent
"""
child_start, child_end = child_span
parent_start, parent_end = parent_span
if (
(child_start >= parent_start)
&(child_end <= parent_end)
):
... | 6c6a8e636ad181af821d185ba35f18db41d0ce77 | 13,473 |
def calc_bpe_bulk_electrolyte_resistance(characteristic_length, sigma):
"""
The area specific charge transfer resistance through the bulk electrolyte
units: Ohm*m2
Notes:
Adjari, 2006 - "(area specific) bulk electrolyte resistance"
Squires, 2010 - does not explicitly define this... | f6a08cd5997de8954faa41d69e7abca1541e3fa0 | 13,476 |
def count_correl_above(correl_mat,limit):
"""
count numbers of correlation matrix elements above a certain threshold
Args:
correl_mat (array): Matrix correlation values
limit: Threshold for counting
Returns:
(float): Percentage of correlations above the limit
"""
... | 00fb1f0aea268a9333c3741255a2fd7cafcb43ee | 13,480 |
def testdat(testdir):
"""Path to the testdat directory"""
return testdir / "testdat" | d7c278fba718164d50863e3fb353155a1ff00eee | 13,483 |
def parity(self, allow_rescaling_flag=True):
"""
Returns the parity ("even" or "odd") of an integer-valued quadratic
form over `ZZ`, defined up to similitude/rescaling of the form so that
its Jordan component of smallest scale is unimodular. After this
rescaling, we say a form is even if it only re... | 12c68f6dfb447cd88d59367ad1fed9c2ba9aedde | 13,487 |
from pathlib import Path
def strings_to_paths(strings: list[str]) -> list[Path]:
"""Converts a list of filenames in string form into a list of paths"""
return [Path(string) for string in strings] | 660e5f0fe72f32a4c4f2b218386e4c640c038846 | 13,489 |
def meta(str1, str2, ratios, weights):
"""A meta ratio function. Returns a weighted meta ratio.
The Wiesendahl ratio is a meta ratio which combines a weighted
ratio of given ratio functions.
Args:
str1 (str): first string
str2 (str): second string
ratios (list(function(str... | b694216cce7b78e15065788497985416537ea95c | 13,495 |
import warnings
def get_unique_schema_name(components, name, counter=0):
"""Function to generate a unique name based on the provided name and names
already in the spec. Will append a number to the name to make it unique if
the name is already in the spec.
:param Components components: instance of th... | 68086fc7a8e523322f5a1745996b6dc8056833a1 | 13,496 |
def _nobarrier(ts_dct):
""" Determine if reaction is barrierless
"""
print('cla', ts_dct['class'])
rad_rad = bool('radical radical' in ts_dct['class'])
low_spin = bool('low' in ts_dct['class'])
return rad_rad and low_spin | 393831d8b0af5085f8ff0f42d54bf8d14faca680 | 13,503 |
import torch
def pad_collate_func(batch):
"""
This should be used as the collate_fn=pad_collate_func for a pytorch DataLoader object in order to pad out files in a batch to the length of the longest item in the batch.
"""
vecs = [x[0] for x in batch]
labels = [x[1] for x in batch]
x = torch.n... | 89d4f2c2adb7295457afe7f6a3235bbc4d9c8155 | 13,506 |
from typing import Any
import random
def getKeyByWeights(array: dict, item: int = 0) -> Any:
"""
Returns a weighted random key from array
:param array: dict[Any: int | float]
:param item: int
:return:
- key - Any
"""
return random.choices(list(array.keys()), weights=list(array.valu... | 8f1d474c97466407ff643abce1ea0b12b3ebd951 | 13,512 |
def solucion_c(imc: float) -> str:
"""Devuelve una categoría de acuerdo al imc
:param imc: Índice de masa corporal
:imc type: float
:return: Categoría
:rtype: str
"""
categorias = {
imc < 16 : "criterio de ingreso hospitalario",
16 <= imc < 17 : "infrapeso",
17... | ca05b9b7af9df3237e8aa1170638e7e695e6bcad | 13,515 |
def splitter(model):
"""
Splits model parameters into multiple groups to allow fine-tuning
"""
params = list(model.parameters())
return [
# weights and biases of the first linear layer
params[:2],
# weights and biases of the second linear layer
params[2:],
] | 2ac16b536bd50884c50ade3fb67f6ca43a16799d | 13,517 |
def parse_id(text):
""" Parse and return the <job>:<id> string.
Args:
text String to parse
Returns:
This node's job name, this node's id
"""
sep = text.rfind(":")
if sep < -1:
raise ValueError("Invalid ID format")
nid = int(text[sep + 1:])
if nid < 0:
raise ValueError("Expected non-negat... | 23dbc417abf7fb799da78e63acf18b2d0ffc450f | 13,526 |
def substr_match(a, b):
"""
Verify substring matches of two strings.
"""
if (a is None) or (b is None):
return False
else:
return a in b | 9b98d14b6ec5f2ab433eea92d377b5e1477fef64 | 13,535 |
def replace_negative(l, default_value=0):
"""
Replaces all negative values with default_value
:param l: Original list
:param default_value: The value to replace negatives values with. Default is 0.
:return: Number of values replaced
"""
n_replaced = 0
for i in range(len(l)):
if l[i] < 0:
l[i... | 431781a48a36a00329537b92b589cf223b945ca4 | 13,536 |
def getClassAttendance(moduleCode):
"""
Will take in the module code and use the code to open the file of the specified module and read it to created
the list of names, presents, absents and excuses. To be return for future use
:param moduleCode:
:return: (list)
"""
classData = open(f"{modul... | a618b90bd6be84fbe23c28ab8d71a57c108b76dc | 13,540 |
import yaml
def get_config(config):
"""Loads a yaml configuration file."""
with open(config, 'r') as stream:
return yaml.load(stream, Loader=yaml.FullLoader) | 58937acf5984b08193c78877fbb94c07c6d779df | 13,542 |
def is_rgb(image):
"""
Return True if image is RGB (ie 3 channels) for pixels in WxH grid
"""
return len(image.shape) == 3 and image.shape[-1] == 3 | f0452fc5f9b6eb69917f8b5de76329eb2e4f03b2 | 13,543 |
def _attr_list_to_dict(attr_list):
"""
_attr_list_to_dict -- parse a string like: host:ami, ..., host:ami into a
dictionary of the form:
{
host: ami
host: ami
}
if the string is in the form "ami" then parse to format
{
default: ami
}
raises ValueError if lis... | 378b1a55d908750eea2b457e35abce0a17364a41 | 13,547 |
def humansize(nbytes):
"""
Translates a size in bytes to a human readable size format
:param int nbytes: integer of size of torrent file
:return: size in bytes in a human readable format
:rtype: str
"""
suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
i = 0
while nbytes >= 1024 and i < len(su... | 98390c0f5c471b501caf2fa2bba1e593c8a17eb6 | 13,549 |
def pad_sents(sents, padding_token_index):
"""
Pad the sents(in word index form) into same length so they can form a matrix
# 15447
>>> sents = [[1,2,3], [1,2], [1,2,3,4,5]]
>>> pad_sents(sents, padding_token_index = -1)
[[1, 2, 3, -1, -1], [1, 2, -1, -1, -1], [1, 2, 3, 4, 5]]
"""
... | 0063d8716f7081644e4353de662d58f0dc04e8fe | 13,550 |
def clamp(minimum, n, maximum):
"""Return the nearest value to n, that's within minimum to maximum (incl)
"""
return max(minimum, min(n, maximum)) | a3db191a733041196b8a3e0cfc83731e839a14aa | 13,552 |
def get_vehicle_mass(vehicle_info):
"""
Get the mass of a carla vehicle (defaults to 1500kg)
:param vehicle_info: the vehicle info
:type vehicle_info: carla_ros_bridge.CarlaEgoVehicleInfo
:return: mass of a carla vehicle [kg]
:rtype: float64
"""
mass = 1500.0
if vehicle_info.mass:
... | 216f109e9f963ba6de92cf168055b1a7e516d777 | 13,555 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.