content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def unpack_vlq(data):
"""Return the first VLQ number and byte offset from a list of bytes."""
offset = 0
value = 0
while True:
tmp = data[offset]
value = (value << 7) | (tmp & 0x7f)
offset += 1
if tmp & 0x80 == 0:
break
return value, offset | b459327c50d806e5c4bd251fa3f849a8680b7f27 | 109,857 |
import time
import socket
def wait_for_service(host, port, timeout):
"""Waits for a service to start listening on a port.
Args:
host: Hostname where the service is hosted.
port: Port where the service is expected to bind.
timeout: Time in secs to wait for the service to be available.
... | 4cdccb02fe6b66ce2710155b229b76dd60c4087a | 109,858 |
def policy_to_mitigation(s):
"""
We have defined suppression as 1=unmitigated. For display we usually want
mitigated = (1 - suppression). This converts that string repr.
Parameters
----------
s: str
String to convert. Structure is e.g. suppression_policy__1.0
Returns
-------
... | 0634cffc5fb7fb59e57048b9bf5d32354a693f98 | 109,859 |
from typing import Tuple
def rect_area(a: Tuple[int, int, int, int]) -> int:
"""helper function for calculate rectangle area
Args:
a: <List[int]> rectangle
Returns:
<int> calculated rectangle area
"""
return a[2] * a[3] | 1f59be9abbbe58ecd66798e498f742048c9a4dd9 | 109,862 |
def cleanup_uri(uri):
"""remove angle brackets from a URI, if any"""
if uri.startswith('<') and uri.endswith('>'):
return uri[1:-1]
return uri | 7ea9fbc76216d2a599d04f0d1b7cef310bd61d94 | 109,865 |
def ndims(x):
"""
Return the ndims of a tensor.
"""
return len(x.shape) | c72af6dcd49d4ebebac7d9a346efe72d63fb9cc8 | 109,870 |
def normal_percentile_to_label(percentile):
"""
Assigns a descriptive term to the MMSE percentile score.
"""
if percentile >= 98:
return 'Exceptionally High'
elif 91 <= percentile <= 97:
return 'Above Average'
elif 75 <= percentile <= 90:
return 'High Average'
elif 25... | 7c2e92ee51b00308f10f14e89869cb339ee551b1 | 109,871 |
def total_seconds(delta):
"""Determines total seconds with python < 2.7 compat."""
# http://stackoverflow.com/questions/3694835/python-2-6-5-divide-timedelta-with-timedelta
return (delta.microseconds + (delta.seconds + delta.days * 24 * 3600) * 1e6) / 1e6 | 77984c21738879d4f201a5ce55a63d1d88de3991 | 109,872 |
def determine_duration_and_scale_factor_from_parameters(chirp_mass):
"""Determine appropriate duration and roq scale factor from chirp mass
Parameters
----------
chirp_mass: float
The chirp mass of the source (in solar masses)
Returns
-------
duration: int
roq_scale_factor: flo... | 51c8e405d95816b48fde6a071847d2cbf275868b | 109,876 |
import mpmath
def sf(x, mu=0, sigma=1):
"""
Log-normal distribution survival function.
"""
if x <= 0:
return mpmath.mp.one
lnx = mpmath.log(x)
return mpmath.ncdf(-lnx, -mu, sigma) | 1c5b801e488c5cc901b2e5d2ad0a3140540a190a | 109,877 |
def draw(cards, deck):
""" draws a single card and adds it to hand
:param cards:
:return: cards + one card
"""
cards += (deck.pop(),)
return cards | ee010f6b00094f6cde6f3e9d918746126db6a04e | 109,878 |
from typing import Tuple
def _split_sampling_rate_byte_11_2(sampling_rate_byte: int) -> Tuple[int, int]:
"""Separate sampling rate into its own byte."""
return sampling_rate_byte & 0x0F, sampling_rate_byte & 0xF0 | 126e64fe194802661e012c4d01f06a654ff96d0f | 109,879 |
def listToCol(lst):
"""
Converts list to column vector
"""
return [[item] for item in lst] | 137bb0661d54ef8e2f6f85786cb6c82434a0e772 | 109,882 |
def dimension_to_bounds(x, y, width, height):
"""
Convert a positioned rectangular section into a bounding box coordinates
indicating the top left and bottom right.
:param x: x position or rectangular section
:param y: y position or rectangular section
:param width: width of section
:param ... | 3cafaab201ae4256d7204d2f545f4e263859433c | 109,886 |
import binascii
def is_gz_file(file_path: str):
"""
Tests to see if a file is gzipped or not. This was taken from
https://stackoverflow.com/questions/3703276/how-to-tell-if-a-file-is-gzip-compressed
Returns
-------
True if it is gzipped, False otherwise.
"""
with open(file_path, 'rb')... | bd20a584877b9981cf3244453cc5ac804e620c4e | 109,887 |
def Lobify (data,group,formants):
"""
Applies Lobanov (z-score) normalization to vowels according to a grouping variable
Adds a column to original dataframe for each formant, with zsc prefixed to the formant name
--
Required parameters:
data = dataframe containing data to transform
... | 83b4a41de5267950ed56c311d19a6270ca4acc29 | 109,894 |
def dfunc(variable_x):
"""
目标函数一阶导数也即是偏导数实现
args:
variable_x: 目标函数
return:
2 * variable_x: 目标函数一阶导数
"""
return 2 * variable_x | b7caca1ba686644c8b67d958eadd3944a9ee8f12 | 109,895 |
import re
def remove_trailing_spaces(code):
"""
Removes spaces from end of lines.
For example, remove_trailing_spaces('hello \nworld \n') -> 'hello\nworld\n'.
"""
return re.sub(' +$', '', code, flags=re.MULTILINE) | b6db3b9dfe8458df540aad06f7a735e51f90224b | 109,897 |
def get_cities() -> list:
"""
Open Craigslist cities from text
Args:
None
Return: list
"""
results = []
with open('src/craigslist_cities.txt', 'r', encoding='utf8') as file:
for line in file:
results.append(line.strip())
return results | 4a53a346df2d0ab4f3839cd26a34432ea8c6bf5c | 109,901 |
def wpcsys(self, wn="", kcn="", **kwargs):
"""Defines the working plane location based on a coordinate system.
APDL Command: WPCSYS
Parameters
----------
wn
Window number whose viewing direction will be modified to be normal
to the working plane (defaults to 1). If WN is a negativ... | e1a7111da7de39623be97a513afb75bbb4849293 | 109,907 |
import socket
import errno
def checksocketfamily(name, port=20058):
"""return true if we can listen on localhost using family=name
name should be either 'AF_INET', or 'AF_INET6'.
port being used is okay - EADDRINUSE is considered as successful.
"""
family = getattr(socket, name, None)
if fami... | c9d9746a9cef28d7d4f289a77aad1c0ad84b5c4d | 109,908 |
def mean(feature_vector):
"""
:param feature_vector: List of integer/float/double..
:return: Mean of the feature vector.
"""
return sum(f for f in feature_vector)/len(feature_vector) | 5ed9dfa0d54cc6fa2a882c32e52ba41be67ff3d3 | 109,911 |
def dict_removeSafe(dict, key):
"""Tries to remove `key`. If there is no `key`, ignore"""
if (not key in dict):
return None
return dict.pop (key) | 4d2d13de4f65bc95f47476e118575fc06382bcc0 | 109,916 |
def bytedata(a):
"""Return a the raw data corresponding to a."""
if isinstance(a, (bytearray, bytes, memoryview)):
return a
elif hasattr(a, "data"):
return a.data
else:
raise ValueError(a, "cannot return bytedata") | 4702f54abae5014c7263afeb2b83c90244581c49 | 109,920 |
def kib_to_gib(size: float) -> float:
"""Convert disk space unit from KiB to GiB."""
return round(size / 2 ** 20, 2) | c3daecfef75df3051d504e0a8df03b3970dba709 | 109,923 |
def get_attr_cols(df, non_attr_cols):
"""
:param df: A data frame of model results
:param non_attr_cols: Names of columns not associated with attributes
:return: List of columns associated with sample attributes
"""
# index of the columns that are associated with attributes
attr_cols = df.co... | 2e7d01664e6338f67deb7b9c8ca53b5ba4a53220 | 109,924 |
def quaternion_conjugate(q):
"""
Computes quaternion conjugate
:param q: Quaternion
:return:
"""
return [q[0], -q[1], -q[2], -q[3]] | 5c3cb680cf5ad15c9ee7f996d3cb9ff0af93a9e4 | 109,926 |
def _cbrange_user_defined(cbrange, cbrange_user):
"""Set user-specified colorbar range.
Parameters:
cbrange (list):
Input colorbar range.
cbrange_user (list):
User-specified colorbar range. If a value is None, then use the
previous value.
Returns:
... | b9aeb3074c2a85f0e4c4859d1ffd799cceed5394 | 109,929 |
def _is_overlap(i, j, used_spans):
"""
Returns whether the span (i, j) overlaps with the interval(s) described by the items in `used_spans`
"""
minval = min([i] + [s[0] for s in used_spans]) # smallest start index among spans
maxval = max([j] + [s[1] for s in used_spans]) # largest end index among... | 883fb70917d31d0c222f630440af235dfcc12c2f | 109,934 |
import math
def distance(x1, y1, x2, y2):
"""
Given two ordered pairs calculate the distance between them.
Round to two decimal places.
"""
return round(math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2) * 1.0),2) | 5679b964d2ddf1a6b9d74a8445126b34a23e5162 | 109,938 |
def clamp(number: int, max_value: int, min_value: int) -> int:
""" Clamp value into a range """
return max(min(number, max_value), min_value) | addfdea377cdf40501ef3aeabbb421316b0083d8 | 109,950 |
def get_year_filename(file):
"""Get the year from the datestr part of a file."""
date_parts = [int(d) for d in file.split('.')[-2].split('-')]
return date_parts[0] | f546e25dccc2e51093a0215125f20b26faf092ca | 109,951 |
def format_bytes(count):
"""
Format bytes in human-readable format
"""
for unit in ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB']:
if abs(count) < 1024.0:
return f"{count:3.1f} {unit}"
count /= 1024.0
return f"{count:.1f} YiB" | f734a20584667f724af90e4fa8ce0f873f7a09a0 | 109,952 |
def get_accuracy(output, targets):
"""calculates accuracy from model output and targets
"""
output = output.detach()
predicted = output.argmax(-1)
correct = (predicted == targets).sum().item()
accuracy = correct / output.size(0) * 100
return accuracy | 692b605224f412d397bdce44a90b518800176322 | 109,954 |
from socket import inet_aton
from struct import unpack
def ip2long(ip_addr):
"""Converts an IP address string to an integer."""
ip_packed = inet_aton(ip_addr)
ip = unpack('!L', ip_packed)[0]
return ip | 7a5fd921468e388579c20e05e9afb49f9dc21302 | 109,955 |
from typing import Iterable
from typing import Dict
def get_tag(tags: Iterable[Dict[str, str]], key: str) -> str:
"""Takes a list of tags and a key name, returns the the value for the tag with the given key name."""
if not tags:
return ''
name_tag = filter(lambda t: t['Key'] == key, tags)
retu... | 597afd98294c51df6b0b863bfbce031fe54501d5 | 109,957 |
def dim_comparator(val1, val2, name1, name2, dim_string, tolerance=0):
"""
Get the string representation of the relations.
Args:
val1: dimensional value of object 1 (int).
val2: dimensional value of object 2 (int).
name1: name of object 1 (str).
name2: name of object 2 (str)... | 1dde9de76411ffbd284887e6fcb6d7611e51ba56 | 109,958 |
def ER(radius):
"""
Return equivalent radius (ER)
"""
return radius | 8c1ac8f11c9cf5ba0c3463693b1bf554f39757d8 | 109,959 |
def get_subcoll_obj_paths(coll):
"""Return paths to all files within collection and its subcollections
recursively"""
ret = []
for sub_coll in coll.subcollections:
ret += get_subcoll_obj_paths(sub_coll)
for data_obj in coll.data_objects:
ret.append(data_obj.path)
return ret | 75716ca9b949ce78f7f73749aa8e7092b367cfa1 | 109,964 |
def _is_hdf5_filepath(filepath):
"""Predicate the filepath is a h5 file."""
return (filepath.endswith('.h5') or filepath.endswith('.hdf5') or
filepath.endswith('.keras')) | 2be4518b2a83d93642373d0ec8663cba73df69cd | 109,965 |
def termlists_are_equal(terms1, terms2):
""" Check whether two given lists of terms are (syntactic-wise) equal. """
return len(terms1) == len(terms2) and all(x.is_syntactically_equal(y) for x, y in zip(terms1, terms2)) | 7aefe9150529095dfd7b588f8497e135caa99e16 | 109,968 |
from functools import reduce
def class_recall(queried_dataset, top_indices, query_image_class):
"""Computes the recall for the results of the given top distances query.
Args:
queried_dataset: the dataset that was queried. It must have the exact same classes as the query dataset.
It is used to retri... | 9df81d07d8a7c951712510d65a9d9e22a370f8c2 | 109,969 |
def evaluate_var(**context):
"""Receives 2 variables, the evaluation condition and the 2 results for the case of
result is True or False
Inputs:
templates_dict:
var_in str -- value 1 to evaluate
var_eval str -- value 2 of the condition to evaluate
op_kwargs:
... | 5c57943a78a3285989ed99f31bd5d9c8757d1ed8 | 109,974 |
def yDP2LP(dpY, dptZero, lPix = 1.0):
"""Convert device coordinates into logical coordinates
dpY - y device coordinate
dptZero - device coordinates of logical 0,0 point
lPix - zoom value, number of logical points inside one device point (aka pixel)
return coordinate in logical coo... | 178ae2bb8f9bccaf9526ce73ec4a7703791733f5 | 109,975 |
def is_box_section(title):
"""
Box sections have specific titles: "Box N | Title goes here".
This function determines whether title belongs to a box section.
"""
if '|' not in title:
return False
return 'Box' in title.split('|')[0] | 6ad00af2a5be7acf6d5a4b8289430898e8fc0e4a | 109,978 |
def email_to_uni(email):
"""parse emails to retrieve UNIs"""
return email.split('@')[0] | 1731da481c4fb3b130771e8b108fbd71e7ed0a6c | 109,981 |
def create_fmt(field_widths, keep_fields):
"""Given two lists: 1) the field widths 2) list with a 1 or 0 indicating whether or not to keep a field,
create a fmt string
Field Widths - https://docs.python.org/3.4/library/struct.html
Format C Type Python Type Standard Size
x ... | 7e2caedbadf442a3f01455241a2cfad8ab55bac7 | 109,983 |
def weekday_name(day_of_week):
"""Return name of weekday.
>>> weekday_name(1)
'Sunday'
>>> weekday_name(7)
'Saturday'
For days not between 1 and 7, return None
>>> weekday_name(9)
>>> weekday_name(0)
"""
if day_of_week == 1:
... | 839ea8ac9db8bbc46cf1ad36c93c693d55d19442 | 109,986 |
import configparser
def _read_config_file_section(section, config_file_path, items):
"""Read a configuration file section
Arguments
---------
section : str
Name of the section to read
config_file_path : str
Absolute path to the config file
items : list of str
A list of... | ad5c89c0c84f213dfc572c6a709a9460ffa98bf8 | 109,988 |
def longest_common_prefix(s1: str, s2: str) -> str:
"""
Finds the longest common prefix (substring) given two strings
s1: First string to compare
s2: Second string to compare
Returns:
Longest common prefix between s1 and s2
>>> longest_common_prefix("ACTA", "GCCT")
''
>>> long... | dfe955335bc97617755eae97714abf60fc61d731 | 109,990 |
import torch
def no_masker(batch_size, mask_shape):
"""Return a mask of all 1."""
mask = torch.ones((batch_size, *mask_shape)).byte()
return mask | 9ab65a27b98929441e8796740924997a681aed8f | 109,991 |
def wants_spousal_support(responses, derived):
""" Return whether or not the user wants an order for spousal support """
return 'Spousal support' in derived['orders_wanted'] | 42f485767d9f842975ba393d8455228dc9eaf3ce | 109,994 |
def zigbee2mqtt_device_name(topic, data, srv=None):
"""Return the last part of the MQTT topic name."""
return dict(name=topic.split("/")[-1]) | 09a4e5e71f51a6acabe54ef941c787867367bd8c | 109,996 |
def num_params(model, count_fixed=False, display_all_modules=False,
print_stats=False):
"""Counts number of parameters and layers in the model
_exclude_from_layer_count contains names that shouldn't be counted
as layers, shortcut layer, for example.
Args:
model (nn.Module):
... | fd183fc9476cd4b722f1090af64ad850da4a1e31 | 110,004 |
from typing import Any
from typing import MutableMapping
from typing import MutableSequence
def is_adjacency_list(item: Any) -> bool:
"""Returns whether 'item' is an adjacency list."""
return (isinstance(item, MutableMapping)
and all(isinstance(v, MutableSequence) for v in item.values())) | 9b0eabb451f6ab10713f55a8e08b1df76e0f7f86 | 110,005 |
def realcar(np_raster, np_filtrada):
""" Função auxiliar que incrementa um imagem filtrada de passa alta a imagem original
Args:
np_raster (np.ndarray): imagem original
np_filtrada (np.ndarray): imagem com filtro de passa alta
Returns:
(np.ndarray): imagem realçada
"""
retu... | bf0bd9af019e754db705275410e0ee48a964dfdd | 110,006 |
import torch
def one_hot_add(inputs, shift):
"""Performs (inputs - shift) % vocab_size in the one-hot space.
Args:
inputs: Tensor of shape `[..., vocab_size]`. Typically a soft/hard one-hot
Tensor.
shift: Tensor of shape `[..., vocab_size]`. Typically a soft/hard one-hot
Tensor... | 4fb16d099557c268c7854a609beb870aab97f629 | 110,008 |
def get_variables_used(string, variable_dict):
"""Returns what variables are used in the given string as a list."""
used_variables = []
for key in variable_dict:
temp_string = string.replace(key, "")
if temp_string != string:
used_variables.append(key)
string = temp_s... | 0b242da05640617f8efca9521bbfe61ce17182dc | 110,012 |
def if_(condition_func, validation_func):
""" Generates a validator to conditionally run a validation function
Args:
condition_func: a function that evaluates to a boolean
validation_func: a validation function to apply
"""
def wrapper(obj, prop):
if not condition_fu... | a1ab0648851cde955deaa826a00cb0953e3f6f37 | 110,013 |
def _is_surf(config):
"""Returns True iff we are on the surface"""
return "surface_file" in config and config["surface_file"] | 5d88b36dc14f5b293af17123f211da3082f87788 | 110,015 |
def is_int(value):
"""Check if value is an int."""
return isinstance(value, int) | a72d0367da43b3b3b6e0ca8edb1f19c3aac671cb | 110,016 |
def constructor_is_method_name(constructor: str) -> bool:
"""Decides wheter given constructor is a method name.
Cipher is not a method name
Cipher.getInstance is a method name
getS is a method name
"""
found_index = constructor.find(".")
method_start_i = found_index + 1
return ... | ee410e1c8df218235fe60ba028dd61bb93cda67b | 110,019 |
def mk_residue(name, num, restype='X', chain=None, label=None, mol='',
color='magenta', style=None):
"""Generate the PyMol code to display a residue."""
return """
create %(label)s, %(name)s and resi %(num)s %(chain)s and not (name %(bbone)s)
show %(style)s, %(label)s
color %(color)s, %(label)s
... | cccf466b281ff52b200186fc4e7f60f22878d083 | 110,022 |
import random
def large_integers(n):
""" Return sequence of N large random integers. """
return [random.randint(-50, 50) * 1000000 + random.randint(0, 10000)
for _ in range(n)] | 14dd7ea4ae9c328a872f864523b4c9fa5bf9ff6b | 110,024 |
def find_project_dir(runpath):
"""
Scans up directories until it finds the project folder.
:param runpath: pathlib.Path, where summit_core is called from.
:return: pathlib.Path, the base project directory
"""
runpath = runpath.resolve()
if runpath.name == "Summit" or runpath.name == 'summit... | bb77ab81d5b3c08baa06fdabbae6afad5b120b59 | 110,025 |
def basis(x):
"""
Return the fixed basis of ``x``.
EXAMPLES::
sage: V = VectorSpace(QQ,3)
sage: S = V.subspace([[1,2,0],[2,2,-1]])
sage: basis(S)
[
(1, 0, -1),
(0, 1, 1/2)
]
"""
return x.basis() | 6293b4df223274700da485131c4533605bf969a1 | 110,029 |
import re
def is_function_decl(index, lines):
"""Check that the line is a function declaration"""
line = lines[index]
previous_line = lines[index - 1]
types = ["char", "signed char", "unsigned char", "string", "short", "short int",
"signed short", "signed short int", "unsigned short", "u... | 0bdf490032aeb30056fe660f8615f75318aa81a3 | 110,031 |
def verse(bottle):
"""Sing a verse and account for plurality"""
next_bottle = bottle - 1
s1 = '' if bottle == 1 else 's'
s2 = '' if next_bottle == 1 else 's'
num_text = 'No more' if bottle == 1 else next_bottle
return '\n'.join([
f'{bottle} bottle{s1} of beer on the wall,',
... | 88ad36a7b51ac819ea78e50ccc49acabb899c87f | 110,035 |
def pressure_to_elevation(pressure: float, p0: float) -> float:
"""
Calculate the elevation for a given pressure.
Args:
pressure: The pressure, in hPa (mbars)
p0: P0, the pressure at sea level.
Returns: Elevation in meters
"""
return (1 - ((pressure / p0) ** 0.190284)... | 21ffca9dca1bfb1eff3690865c8f8381075e5fc8 | 110,039 |
import cmath # Can return complex numbers from square roots
def quad_roots(a=1.0, b=2.0, c=0.0):
"""Returns the roots of a quadratic equation: ax^2 + bx + c = 0.
INPUTS
=======
a: float, optional, default value is 1
Coefficient of quadratic term
b: float, optional, default value is 2
... | 665e79754a37ffca1f7c9396e4b3f0186f80022a | 110,041 |
def is_tf(df):
"""
Determines if a string is a 'boolean string': 't', 'f', 'True', or 'False'.
Args:
df (pandas.DataFrame): A dataframe that contains strings.
Returns:
pandas.DataFrame: A dataframe of booleans that is True if the entry
is any of the valid 'boolean string' val... | 18a92d3a0e0cc5f7bb7ebca5daba362e3c1abb8d | 110,042 |
def AdaptReadableDate(date_obj):
"""Adapts a datetime.date object to its ISO-8601 date notation."""
return date_obj.isoformat() | eb9a236b47819cfa469483be2551975c14d60798 | 110,047 |
def get_contract(path: str) -> str:
"""
Acquire contract content from storages.
Currently only supports file storage
Args:
path (str): File path
Returns:
str: Context string
"""
contract: str = ""
# Storage Path
with open(path, "r") as file:
contract... | 5b7d993b7ae030ebd30cd1bf272b38aec6128574 | 110,054 |
def rexists(sftp_client, path):
"""
Returns true if the remote directory or file under path exists.
"""
try:
sftp_client.stat(str(path))
except IOError as err:
if err.errno == 2:
return False
raise
else:
return True | d3ea31a42871e6f030f7786edaf7cd8faddedb0b | 110,058 |
import re
def _parse_gcs_path(gcs_path):
"""Parse GCS path into bucket and path.
Args:
gcs_path: a GCS path, e.g. gs://bucket/foo/bar
Returns:
(bucket, path), e.g. ('bucket', 'foo/bar') for gs://bucket/foo/bar'.
Raises:
ValueError: if gcs_path is not a GCS path.
"""
m = re.match("^gs://([^/]+... | 9fae5cbd3aa787350c90523416984f1da875c60d | 110,061 |
import requests
def check_pwn(email):
"""Takes a string (email address) as input and checks whether the email
address is contained within a breach registered in the Haveibeenpwnd database.
If the request is empty or generates any other errors, nothing is returned.
This is done to make it testable whether an emai... | 63c239854a573486e0da1ddee50fb3063edd5f32 | 110,062 |
def signIn(command):
""" Check if command is to Sign In (s | signin). """
return (command.strip().lower() == 's' or command.strip().lower() == 'signin') | edeef11514d7b2d1986effa9fe679c1dbd1ed0e4 | 110,066 |
def inverse_dict(original):
"""Return a dictionary that is the inverse of the original.
Given the pair original[key] = value, the returned dictionary will give
ret[value] = key. It is important to keep two separate dictionaries in case
there is key/value collision. Trying to insert a value that matches... | 6b541bf60be88f8007514c1ef95598dc005bb412 | 110,067 |
import json
def json_output(input):
"""Format JSON output."""
try:
return json.dumps(input, indent=2, sort_keys=True)
except ValueError:
return input | 3a893993bf8011514e2b4e6be36a5a78c0e4c9f1 | 110,069 |
def _sparse_ftrs_indices0(ftr_name):
"""Returns the name of the 0th axis indices for `ftr_name`"""
return f"{ftr_name}_indices0" | c78c44a69439377008398ba16ca93d924ab10a76 | 110,073 |
import random
def generate_unique_randomized_list(list_size=None):
"""
Purpose:
Generate a Randomized List with Unique Values
of a sepcified size
Args:
list_size (Int): Size of list to generate. Lists
default to 50 ints
Returns:
randomized_list (List): Unsorted ... | d642f0b0ab62f95c26c5c9a39af8f615f1d1050c | 110,081 |
from collections import defaultdict
def convert_idsw_to_heatmap_format(filepath, dest_file):
"""Convert idsw format to heatmap formats
idsw: <frame> <id1_gt> <id1> <bb1_left> <bb1_top> <bb1_width> <bb1_height> <id2_gt> <id2> <bb2_left> <bb2_top> <bb2_width> ...
heatmap: <frame> <bb1_left> <bb1_top> <bb1_... | a1654e99d581aa58f7cd5f11872083051d91fd8f | 110,082 |
def add_to_inventory(inventory, added_items):
"""Combine a list of loot with an inventory."""
for loot in added_items:
inventory.setdefault(loot, 0)
inventory[loot] += 1
return(inventory) | e8f9835f505e5e740d18995537bf90465bac8300 | 110,095 |
def gtVcf(ref, alt, gt):
""" Get genotype in VCF style string"""
if gt == ref: return "0"
if gt == alt: return "1"
return "." | e751e2d35447ffb97652a0b095b374081422af93 | 110,096 |
import socket
import time
def find_devices(find_first=False, sock_timeout=3, search_timeout=3):
"""Finds spectrometers broadcasting on the local network
Args:
find_first (bool): whether to return only the first spectrometer found
sock_timeout (int): UDP socket timeout in seconds
searc... | 7a0587cec96ce6046da84f63c0433946affd65a9 | 110,099 |
def get_geo_coordinates(tweet):
"""
Get the user's geo coordinates, if they are included in the payload
(otherwise return None)
Args:
tweet (Tweet or dict): A Tweet object or dictionary
Returns:
dict: dictionary with the keys "latitude" and "longitude"
or, if unavaiab... | a78af74152670cc29277a9b3c4f23dce4d778c7e | 110,100 |
def copy_seats(seats):
"""Create copy of seats list of list."""
return [[seat for seat in row] for row in seats] | fada667a52cdb83c09221776f9e7ad784c7a002a | 110,101 |
import torch
def noncausal_denominator(qs, ks):
"""Computes FAVOR normalizer in noncausal attention.
Args:
qs: query_prime tensor of the shape [L,B,H,M].
ks: key_prime tensor of the shape [L,B,H,M].
Returns:
FAVOR normalizer in noncausal attention.
"""
all_ones = torch.ones([ks.shape[0]]).to(k... | 723baaf4a2d471d26ac7d9728193c3cb0151c0fe | 110,105 |
import ipaddress
def cidr_stix_pattern_producer(data):
"""Convert a CIDR from TC to a STIX pattern."""
if isinstance(ipaddress.ip_network(data.get('summary'), strict=False), ipaddress.IPv6Network):
return f"[ipv6-addr:value = '{data.get('summary')}']"
return f"[ipv4-addr:value = '{data.get('summa... | 56f7d94fef6d913d6c2bd3afa48d747dc5a4c549 | 110,115 |
def processLine(line):
""" Given a string like this: '01. anime_name---------: Naruto'
This function returns a list: ['01. anime name', 'Naruto']
which is later used as key-value pairs in our data dictionary.
"""
sep_index = line.find('-:')
if sep_index == -1:
err_msg = 'Index Error... | 8134dcc0ffa4d2eedb7281f0ad8b4f6ea6b8ff87 | 110,116 |
def subdict(d, expected_dict):
"""Return a new dict with only the items from `d` whose keys occur in `expected_dict`.
"""
return {k: v for k, v in d.items() if k in expected_dict} | a6ee4fc371c7be3303770b40a8983c7dd7d2678e | 110,118 |
def gen_Datastream(temperature, position, drone_id):
"""Generate a datastream objects."""
datastream = {
"@type": "Datastream",
"Temperature": temperature,
"Position": position,
"DroneID": drone_id,
}
return datastream | 5ce2ab58a8a39f22df1fe3284f58c9b6bf26b1af | 110,120 |
def round_df_scores(df_scores, score_types):
"""Round scores to the precision set in the score type.
Parameters
----------
df_scores : pd.DataFrame
the score dataframe
score_types : list of score types
Returns
-------
df_scores : the dataframe with rounded scores
"""
df... | 0ae2eb03ccaaa76862410d4df1ea0b7c72bf44ca | 110,126 |
import torch
def get_gae(value, reward, args, is_normalize=False, eps=1e-8):
"""Compute generalized advantage estimator
Args:
value (list): Contains value function across trajectories
reward (list): Contains rewards across trajectories for specific agent
args (argparse): Python argpar... | f375f5e1756279d942b67b95a4e6bbadbd84df31 | 110,130 |
from typing import List
import click
def output_result(proc_packages: int, errors: List[str]) -> bool:
"""Output number of packages processed and errors."""
click.echo(f"Checked {proc_packages} package(s).")
if errors:
click.echo(f"{len(errors)} errors found:\n" + ("\n").join(errors))
retu... | d3bd98416fb5dc8085aa2f677ebea190cf2cc4af | 110,133 |
def prob(factor, *entry):
"""
argument
`factor`, a dictionary of domain and probability values,
`entry`, a list of values, one for each variable in the same order as specified in the factor domain.
Returns p(entry)
"""
return factor['table'][entry] | 9fd220352ffd846fd63970fec02965f3f5e322cd | 110,136 |
from typing import Union
def topic_to_bytes(topic: Union[bytes, str]) -> bytes:
"""
Return the passed topic as a :class:`bytes` object.
"""
if isinstance(topic, str):
topic = topic.encode()
return topic | c89a30ce60390cee517ef79cd1c480dcae116e99 | 110,137 |
def _extract_first_field(data):
"""Extract first field from a list of fields."""
return list(next(iter(zip(*data)))) | 1d9ab5619caef894963cc4a00626274731f792af | 110,138 |
def get_game_recap(content_feed):
""" Searches the content feed for the game recap.
Args:
content_feed (dict): NHL Content Feed
Returns:
recap (dict): Dictionary of the full recap event
nhl_video_url (string): URL pointing to the NHL Video Recap
"""
epg = content_feed["med... | ae692ba71bfc6759f5ff1e4619ede7eeaeac5e7d | 110,145 |
def add_sky(config):
"""Add sky temperature model, EoR, and foregrounds, using defaults."""
sky_config = """
sky:
Tsky_mdl: !Tsky
datafile: HERA_Tsky_Reformatted.npz
interp_kwargs:
pol: xx
eor:
noiselike_eor: {}
foregrounds:
diffuse_foreground: {}
... | 766d4e3e2642324703eabe9d9884325501527c24 | 110,146 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.