content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def length(x):
"""Get length of elements"""
return x.size | 70310b7b09173ece02db4c4aff4c14d53fc22f78 | 35,210 |
def error_func(guess, x, data, data_model):
"""
@param guess : parameter list::
an estimate of the model parameters of the final solution
@param x : numpy array of float::
x-values
@param data : numpy array of y-values
@param data_model : function to be fitted
@return: numpy array of float::
... | 7ee32c6ec8738a46936205c7235e789ea7d2bd5f | 35,211 |
def parse_file(filename):
"""
Parses file for error messages in logs
Args:
filename
Returns:
error_count: count of error messages in file
error_msgs: list of error messages
"""
# Initialize return vals
error_count = 0
error_msgs = []
with open(filenam... | 855ad9411646961b3afdec14e7b3547af81fae84 | 35,214 |
import pickle
def pickle_dump(obj, path):
"""
Dump a pickle
"""
with open(path, 'wb') as outfile:
return pickle.dump(obj, outfile) | 9fb609bcbee03f2294bd4b76bdbc1b0f0ad93875 | 35,217 |
def _strip_right(str, suffix):
"""Returns str without the suffix if it ends with suffix."""
if str.endswith(suffix):
return str[0: len(str) - len(suffix)]
else:
return str | fdf03a237c353cc1579aec89fcc18b69ca2af8da | 35,219 |
def repeat_tensor_for_each_element_in_batch(torch_tensor, n):
"""
Repeats a certain torch tensor n times for each element in a batch.
:param torch_tensor: given torch tensor
:param n: number of repeats
:return: new tensor, where every row of torch_tensor is repeated n times
"""
data_shape =... | 1fef4542e953a49c483c81c6094d5677092e5b66 | 35,223 |
def dig_deeper(entry, field, res, depth=10):
"""A helper function for :func:`get_wiktionary_field_strings`.
It recursively locates the target field.
Args:
entry (dict or list): the entity to investigate
field (str): the field to look up
res (list): the list of found entities to upda... | 6332ed989b2815a7a4e5247e7b9f28f3a88b11be | 35,225 |
def ranges_to_indices(range_string):
"""Converts a string of ranges to a list of indices"""
indices = []
for span in range_string.split('/'):
if ':' in span:
start_idx, stop_idx = [int(idx) for idx in span.split(':')]
stop_idx += 1 # add 1 since end index is excluded in rang... | 7f3fe841c9f0c2e309013184ffcb6a35c1dab42b | 35,226 |
def is_error_start(line):
"""Returns true if line marks a new error."""
return line.startswith("==") and "ERROR" in line | a76fb0b424098c1f60c1b63a1fc36ef08a9fb8f2 | 35,228 |
import torch
def soft_reward(pred, targ):
"""
BlackBox adversarial soft reward. Highest reward when `pred` for `targ`
class is low. Use this reward to reinforce action gradients.
Computed as: 1 - (targ pred).
Args:
pred: model log prediction vector, to be normalized below
targ: tr... | d6a420b49d22d87c2d5eb4662a1ac3d1c3175660 | 35,235 |
def check_py_file(files):
"""
Return a list with only the python scripts (remove all other files).
"""
py_files = [fich for fich in files if fich[-3:] == '.py']
return py_files | 942f4f2560eaeab540be59a88d5e8211efc787a0 | 35,241 |
def create_demand_evaluator(data):
"""Creates callback to get demands at each location."""
_demands = data['demands']
def demand_evaluator(manager, node):
"""Returns the demand of the current node"""
return _demands[manager.IndexToNode(node)]
return demand_evaluator | 30f18d8ae57eda136c7a0d2114c38a7e5e378f47 | 35,253 |
def xywh2xyxy(bbox):
"""
Coordinate conversion xywh -> xyxy
"""
bbox_ = bbox.clone()
if len(bbox_.size()) == 1:
bbox_ = bbox_.unsqueeze(0)
xc, yc = bbox_[..., 0], bbox_[..., 1]
half_w, half_h = bbox_[..., 2] / 2, bbox_[..., 3] / 2
bbox_[..., 0] = xc - half_w
bbox_[..., ... | 6111f1a6c1a35390d853ce72fe21e0a8123bdcde | 35,259 |
def is_backbone(atom, element, minimal=False):
"""
Whether `atom` is a protein backbone atom or not.
Parameters
----------
atom : str
The atom name.
element : str
The element name.
minimal : bool
If `True` considers only `C` and `N` elements.
`False`, consi... | 29def3cf99de683f8dee48f534661b89ae22d2b2 | 35,260 |
import math
def rotate(x, y, beta):
"""
Rotate vector(x,y) by beta radians counterclockwise
https://matthew-brett.github.io/teaching/rotation_2d.html
"""
x2 = math.cos(beta)*x - math.sin(beta)*y
y2 = math.sin(beta)*x + math.cos(beta)*y
return (x2, y2) | c42a52d2225814601a13d80d7a875bd6d1bf6862 | 35,263 |
def references(name, tag):
"""Provides suggested references for the specified data set
Parameters
----------
name : str
Instrument name
tag : str
Instrument tag
Returns
-------
refs : str
Suggested Instrument reference(s)
"""
refs = {'tec':
... | 9452192d5cac1097c59ff0521fbeb7e62f4ab7e3 | 35,265 |
def _make_alias_docstring(new_name, func_or_class):
"""Make deprecation alias docstring."""
if func_or_class.__doc__:
lines = func_or_class.__doc__.split('\n')
lines[0] += ' (deprecated)'
else:
lines = ['DEPRECATED CLASS']
first_line = lines[0]
notice_lines = [
('Warning: THIS CLASS IS DEPRE... | 7f28908e09d690937a55d2bf1cc392857eb2c0ac | 35,267 |
def adj_r2(r2: float, sample_size: int, n_features: int) -> float:
"""
>>> round(adj_r2(0.8, 100, 5), 3)
0.789
>>> round(adj_r2(0.8, 20, 5), 3)
0.729
"""
return 1 - ((sample_size - 1) / (sample_size - n_features - 1)) * (1 - r2) | 9496b8263427ee5e879d838422d5c2c152daf33b | 35,271 |
def remove_quotes(string):
"""
This function is used here to remove quotes from
paths used in this script.
:param string: Path with quotes.
:return: Path without quotes.
"""
if string.startswith('"'):
string = string[1:]
if string.endswith('"'):
string = string[:-1]
... | acc09bcf6ecfaf5a26332abbb2632be6cb671286 | 35,272 |
def split_route(route):
"""
Split a full route into single nest to nest subroute
"""
routes = []
i = -1
for node in route:
if node.id == 0:
# start a new subroute in position i
if i != -1:
# close the old subroute
routes[i].append(... | 98e8c167dadeff4825fdffee571277e7b8ec5bcb | 35,275 |
def split_variant(variant):
"""
Splits a multi-variant `HGVS` string into a list of single variants. If
a single variant string is provided, it is returned as a singular `list`.
Parameters
----------
variant : str
A valid single or multi-variant `HGVS` string.
Returns
-------
... | aeaa13400333b5ee0a02b88f54399ed3ba40cc04 | 35,277 |
def stack_follow(deck_size, position, *_):
"""Get new position after stacking deck."""
return deck_size - position - 1 | 3d766864097a96c76b646a6a3b982ed879526af3 | 35,288 |
import re
def CleanText(text):
"""Cleans provided text by lower casing words, removing punctuation, and
normalizing spacing so that there is exactly one space between each word.
Args:
text: Raw text to be cleaned.
Returns:
Cleaned version of text.
"""
pretty_issue = text.lower().strip()
quo... | 573bab3645a774096959b7957e02cba07539a74d | 35,296 |
def sum_even_fibonacci(n):
"""sum of the even-valued terms of the fibonacci sequence not exceeding n"""
result = 0
if n >= 2:
x, y = 1, 1
for _ in range(n):
x, y = y, x + y
if x > n:
break
if x % 2 == 0:
# print(x, y)
... | 0cfc53863115aa462f6d0558cc3a5018507c737f | 35,298 |
def bin_frequencies(df, how='max', bin_size=5, n_bins=None):
"""
bins spectral data frequencies to the specified bin size or number of bins
:param df: dataframe of spectral data from single sensor
:param how: how to aggregate the intensities for each bins. Any numpy aggregate function, default is max
... | 0929e1539d43a379c4ff1a3e348056dfa2e333eb | 35,302 |
import torch
def squash(inputs, axis=-1):
"""
The non-linear activation used in Capsule. It drives the length of a large vector to near 1 and small vector to 0
:param inputs: vectors to be squashed
:param axis: the axis to squash
:return: a Tensor with same size as inputs
"""
norm = torch.... | ff639bec8d0c9acbc1daf6f7f7918c517cc6642f | 35,303 |
def convert_sec_to_time(duration_in_sec: float):
"""converts time in seconds to HH:MM:SS
Args:
duration_in_sec (float): duration in seconds
Returns:
(str): the time in the format: HH:MM:SS
"""
hours = int(duration_in_sec/3600)
remainder = duration_in_sec%3600
minutes = int(... | fcc96b55843555425048e36274656f19b2a879df | 35,306 |
import json
import requests
def start_stream(project, location, token, s_config):
"""
This function will start the stream in Google Cloud DataStream
:param project: Google Cloud project id mentioned in variables.py
:param location: Google Cloud resource location, for example us-central1
:param tok... | d9b2e74582f0ae2ae66219e5b121801116f70078 | 35,307 |
import re
def strip_json(string_value):
"""Strip a string containing a JSON document and remove all redundant white-space symbols.
:param string_value: String containing a JSON document
:type string_value: str
:return: String containing a JSON document without redundant white-space symbols
:rtyp... | c8f6b37d5ca72dcfcfb70dbe9b156727752bdf0e | 35,310 |
import builtins
def _is_valid_padding(kernel_sdims, strides, padding):
"""Returns True if `padding` corresponds to "VALID" padding for a transposed convolution."""
# This is simply the padding == 'VALID' part of lax._conv_transpose_padding.
for (begin, end), k, s in zip(padding, kernel_sdims, strides):
pad_... | 8e3351110a8b7b06eff6432e0cbb705d172ccd88 | 35,313 |
def normalize_application_tags(app_original, app_updated):
""" Simple function to normalize application tags when application is created or updated.
It aims to ensure that required tags are always well defined.
:param app_original string: The ghost "app" object before modification.
:param... | 0a3e69f38cc0d5dfbcbec07dc224ecfba4cc02b6 | 35,317 |
def grelha_nr_linhas(g):
"""
grelha_nr_linhas: grelha --> inteiro positivo
grelha_nr_linhas(g) devolve o numero de linhas da grelha g.
"""
return len(g) | ac1b0b730b5bd139dc238d80283a5dfcc7a2dd57 | 35,318 |
def counter2val(counter):
"""Extract current value of an `itertools.count()` w/o incrementing it."""
return counter.__reduce__()[1][0] | 1c3f2929422974a2a0e38763c9fa20251804bf3d | 35,320 |
def replace_recursive(text, to_match, repl=''):
"""
Works the same as str.replace, but recurses until no matches can be found.
Thus, ``replace_recursive('hello_wooorld', 'oo', '')`` would replace
``wooorld`` with ``woorld`` on the first pass, and ``woorld`` with
``world`` on the second.
Note th... | fcf58b9b5f54b0bc1e152b4a4686012ff6cc7506 | 35,322 |
def get_sim_time_span(n_interval, step_size):
"""Calculate the time span of the simulation.
:param n_interval: number of intervals
:type n_interval: integer
:step_size: length of one time step in minutes
:type step_size: number
:return: time delta in minutes
:rtype: number
"""
retur... | 3cb0b573ad504593479a853ddd04465e3abd11ea | 35,328 |
def f2f1(f1, f2, *a, **k):
"""
Apply the second function after the first.
Call `f2` on the return value of `f1`.
Args and kwargs apply to `f1`.
Example
-------
>>> f2f1(str, int, 2)
2
"""
return f2(f1(*a, **k)) | f19730807cfdd74c1b2b895ff1a034597988907a | 35,330 |
def getBounds(lvls_arr: list, n_lvl: float):
"""
A helper function to calculate the BN interpolation
@param lvls_arr: The corruption levels list
@param n_lvl: The current level to interpolate
@return: Returns the post and previous corruption levels
"""
lower = lvls_arr[0]
upper = lvls_ar... | a478437834a5774e572015f51a15499fde516a25 | 35,331 |
def income_tax(wage):
"""
:param wage: 到手的月收入
个税速算:全月应纳税所得额(Taxable Income) × 适用税率(Tax Rate) - 速算扣除数(Quick Deduction)
# Ti Tr Qd
-----------------------
1 ~1500 3% 0
2 1500~4500 10% 105
3 4500~9000 20% 555
4 9000~35000 25% 1005
5 35000~55000 30... | ed18d667bcd0f75a840b62a231f76e227a70a4ba | 35,335 |
def correlate(x, y):
"""Pearson's correlation
"""
# Assume len(x) == len(y)
n = len(x)
sum_x = float(sum(x))
sum_y = float(sum(y))
sum_x_sq = sum(xi*xi for xi in x)
sum_y_sq = sum(yi*yi for yi in y)
psum = sum(xi*yi for xi, yi in zip(x, y))
num = psum - (sum_x * sum_y/n)
den ... | 12d8aeb4698b43b0a51d7131423e273a8c3d8d8d | 35,336 |
import re
def list_from_file (file_name, separator = '\\s+', convert_to = int):
"""Returns a 2-D list which contains the content of a file, with lines
corresponding to sublists and elements being converted with function
convert_to.
separator is used (as a regexp) as a separator for each element."""
... | 37ada18a3c6e4bfede93d65db0cef359b520767a | 35,341 |
import re
def is_method_name(text):
"""
>>> is_method_name('hello')
False
>>> is_method_name('hello()')
True
>>> is_method_name('Foo::Bar')
False
>>> is_method_name('Foo::Bar#baz')
True
>>> is_method_name('Foo::Bar#baz()')
True
>>> is_method_name('user/repo#14')
Fal... | f495caaf05419c369cc81d9debf576152c153f7a | 35,343 |
def create_answer_mapping(annotations, ans2cat):
"""Returns mapping from question_id to answer.
Only returns those mappings that map to one of the answers in ans2cat.
Args:
annotations: VQA annotations file.
ans2cat: Map from answers to answer categories that we care about.
Returns:
... | a0ca05f057f635084c8407326b0e843a8fac6fc6 | 35,346 |
def clean_join(separator, iterable):
"""
Filters out iterable to only join non empty items.
"""
return separator.join(filter(None, iterable)) | f52f2a6be0f1ebdd6feb9346ccc89918c833485c | 35,347 |
def bed_get_chromosome_ids(bed_file):
"""
Read in .bed file, return chromosome IDs (column 1 IDs).
Return dic with chromosome ID -> count mapping.
>>> test_file = "test_data/test6.bed"
>>> bed_get_chromosome_ids(test_file)
{'chr1': 2, 'chr2': 2, 'chr3': 1}
"""
ids_dic = {}
with ope... | 77400731e30e8a0313c77aaaf726f5d35216a676 | 35,351 |
def get_intersections(path1, path2):
"""returns a list of the intersection points between the two paths
Args:
path1: one path (list of tuples with consecutive integer x, y coords)
path2: second path (see above)
Returns:
a list of all overlapping tuples from the two paths
""... | 91add11e62f898beb3faefa3b73b6bee53f2948d | 35,354 |
from typing import Tuple
def mean_grad(x: Tuple[float, float]) -> Tuple[float, float]:
"""A manually calculated gradient of the mean with respect to the inputs."""
return 6 * x[0], 3 * x[1] ** 2 | 459f9b1c0500080acd6097b905a4825c2dd4b80f | 35,362 |
import re
def process_arguments(raw_arguments: list):
""" Process the arguments from CLI. The value of sys.argv """
arguments = {}
for argument in raw_arguments:
# catch the arguments with associated values
matches = re.search(r"^([a-z][a-z0-9-]+?)=['\"]?(.+?)['\"]?$", argument)
i... | 2a8249af500c25b869ec68f7402a0e9130656a91 | 35,366 |
def combineImagePaths(centerImagePath, leftImagePath, rightImagePath, centerMeasurement, leftMeasurement, rightMeasurement):
"""
combines cnter/left/right images and measurements to one list
"""
# combine measurements
measurements = []
measurements.extend(centerMeasurement)
measurements.exte... | 3c8e1dbe16bc25d9efcd029c0c28f194f275e5f8 | 35,367 |
import shutil
def check_valid_shell_command(cmd):
"""
Determine if a shell command returns a 0 error code.
Args:
cmd (string or list): Shell command. String of one command or list with arguments.
Returns:
bool
"""
if isinstance(cmd, list):
return shutil.which(cmd[0])... | 97d2ac7a24d15217481454fdd0a2c2b7ef11fa70 | 35,373 |
def _file_read(filename):
"""Read file and return text"""
# Open and read file to get text.
with open(filename, 'r') as f:
text = f.read()
return text | a5422d174c964f2fe5fd4a1847d4fd1b95431749 | 35,381 |
def split_words(text : str) -> list:
""" Breaks up a command input such as 'hello foo bar' into individual words"""
command_text = text.strip()
commands = command_text.split(' ')
return commands | 1bc27d5ec5f4c805eb22b84d9b916d1dca0f9312 | 35,385 |
def response(hey_bob):
"""
Bob is a lackadaisical teenager. In conversation,
his responses are very limited.
Bob answers 'Sure.' if you ask him a question,
such as "How are you?".
He answers 'Whoa, chill out!' if you
YELL AT HIM (in all capitals).
He answers 'Calm down, I know what I'... | 5e1e58f9a2bd44961a6b569cd52085958b0b7422 | 35,386 |
def rgb_to_hsv(image):
"""
Wrapper function to convert a landsat 4,5 or 5 image from RGB to HSV.
:param image: Landsat Image to convert to the HSV color space
:return: Image containing three bands, representing the hue, saturation and value.
"""
image_hsv = image.select(['B3', 'B2', 'B1']).mult... | 788551ff5af5237779df41a52f138d75f2a8e3b2 | 35,387 |
def GetUnixErrorOutput(filename, error, new_error=False):
"""Get a output line for an error in UNIX format."""
line = ''
if error.token:
line = '%d' % error.token.line_number
error_code = '%04d' % error.code
if new_error:
error_code = 'New Error ' + error_code
return '%s:%s:(%s) %s' % (filename, ... | 5689b28ea0475f08802c72a48b733e4625e6d9d5 | 35,392 |
def left_child_index(i):
"""
:param i: int
Index of node in array (that is organized as heap)
:return: int
Position in array of left child of node
"""
return 2 * (i + 1) - 1 | 323106fbc8aa1a12144bde5c6e43cd6870c6b1da | 35,394 |
def add(bowl_a, bowl_b):
"""Return bowl_a and bowl_b added together"""
return bowl_a + bowl_b | e12bb4d5f4d21f4ae113f064d62d0db2ea6f8014 | 35,396 |
from typing import Tuple
from typing import List
def _get_value_name_and_type_from_line(*, line: str) -> Tuple[str, str]:
"""
Get a parameter or return value and type from
a specified line.
Parameters
----------
line : str
Target docstring line.
Returns
-------
value_name... | d2095fa2bc34a7086f60b40373a351f7c984dc96 | 35,399 |
def cut_tag_preserve(tags, tag):
"""
Cuts a tag from a list of tags without altering the original.
"""
tag_list = tags[:]
tag_list.remove(tag)
return ",".join(tag_list) | 691412fc466498413c32edd30eaca2d677d7e35a | 35,405 |
def is_related(field):
"""
Test if a given field is a related field.
:param DjangoField field: A reference to the given field.
:rtype: boolean
:returns: A boolean value that is true only if the given field is related.
"""
return 'django.db.models.fields.related' in field.__module__ | fff8bbc5f945e7f0ee576e4b501b2c9ca808541d | 35,409 |
import torch
def attention_score(att, mel_lens, r=1):
"""
Returns a tuple of scores (loc_score, sharp_score), where loc_score measures monotonicity and
sharp_score measures the sharpness of attention peaks
"""
with torch.no_grad():
device = att.device
mel_lens = mel_lens.to(device... | ccdce864a91c9816143f414c2cde99b5f67c89c4 | 35,411 |
def sort_lists(reference, x):
"""
Sorts elements of lists `x` by sorting `reference`
Returns sorted zip of lists
"""
# sort zip of lists
# specify key for sorting the ith element of `reference` and `x` as the first element of the tuple of the sorted zip object, e.g. pair[0] = (reference[i]... | 581e01f21902a029570dc45e5c6401696b80ee15 | 35,412 |
def pos_of(values, method):
"""Find the position of a value that is calculated by the given method.
"""
result = method(values)
pos = [i for i, j in enumerate(values) if j == result]
if len(pos) > 1:
print('Warning: The %s of the list is not distinct.' % (method,))
return pos[0] | 5300511a1dd8f76de51f58021cf011a4aa5ca757 | 35,416 |
def crop_frame(img, width, height, x, y):
"""
Returns a crop of image (frame) based on specified parameters
Parameters
----------
img : array, required
Array representing an image (frame)
width : int, required
Width of the crop
height : int, required
Height of th... | 1cbc34aed421cf67cef57b8fb53b47015911f701 | 35,420 |
import math
def sigmoid(x):
"""
sigmoid function
Args:
x: number
Returns: sigmoid(number)
"""
return 1 / (1 + math.exp(-x)) | 3f4fc16c99af2cdf71aea9f108382e6464f50e6f | 35,421 |
def parse_releases(content):
"""
Parse latest releases of a manga
Parameters
----------
content : BeautifulSoup
BeautifulSoup object of the releases page content.
Returns
-------
releases : list of dicts
List of latest releases of a manga.
List is ordered latest... | 9f1e99cf0e6e96cb60c6764c68052e94d341d196 | 35,423 |
def extract_instance_name(url):
"""Given instance URL returns instance name."""
return url.rsplit('/', 1)[-1] | 333c6f12ae44b0a5de0ed80d9e01c87dffeb18d2 | 35,430 |
def salt_run_cli(salt_master):
"""
Override salt_run_cli fixture to provide an increased default_timeout to the calls
"""
return salt_master.salt_run_cli(timeout=120) | 10d2d04d83ae747e0898a34823d3403a374381a9 | 35,434 |
def getDaySuffix(day):
"""Return st, nd, rd, or th for supplied day."""
if 4 <= day <= 20 or 24 <= day <= 30:
return 'th'
return ['st', 'nd', 'rd'][day % 10 - 1] | 4023b97164cbb7c73a1a3ddb2a3527fa2c297a1d | 35,439 |
import bisect
def find_le(array, x):
"""Find rightmost value less than or equal to x.
Example::
>>> find_le([0, 1, 2, 3], 2.0)
2
**中文文档**
寻找最大的小于等于x的数。
"""
i = bisect.bisect_right(array, x)
if i:
return array[i - 1]
raise ValueError | dfa67df6fadbdead10821c4aceb027b0c5f5d90a | 35,440 |
def flatten(array: list):
"""Flatten nested list to a single list"""
return [item for sublist in array for item in sublist] | 65692535197b946d5d5a39e657ff07c3424e7652 | 35,441 |
def _transaction_sort_key(txn):
"""
If there are payments and invoices created on the same day
we want to make sure to process the payments first and then
the invoices. Otherwise the transaction history on an
invoice will look like a drunk cow licked it, that's bad.
:param txn:
:return: sort... | c6e74a6c87ec7c46dba0507bf144bfddac954e3c | 35,447 |
def cleanup_column_names(df,rename_dict={},do_inplace=True):
"""This function renames columns of a pandas dataframe
It converts column names to snake case if rename_dict is not passed.
Args:
rename_dict (dict): keys represent old column names and values point to
newe... | 2ee32d7742c20b9eeeffb9481d940f1e4c036937 | 35,451 |
import math
def returnNewDelta(delta_old):
"""returns the side of the new polygonal approximation.
Arguments:
delta_old -- the side of the previous approximation
"""
return math.sqrt( 2. * (1. - math.sqrt(1. - 0.25 * delta_old**2) ) ) | 7ffececdc6affb3b7f9aa215415077bc14baa9e3 | 35,452 |
def max_contig_sum(L):
""" L, a list of integers, at least one positive
Returns the maximum sum of a contiguous subsequence in L """
sizeL=len(L)
max_so_far,max_ending_here=0,0
for i in range(sizeL):
max_ending_here+=L[i]
if max_ending_here<0:
max_ending_here=0
el... | 356c87a66ff1071e729e3de379550a0a61a2f4f4 | 35,457 |
def test_module(unifi_session):
"""
Test Module for Demisto
:param unifi_session: Unifi Session from Unifi class
:return: Return 'OK' if success
"""
result = False
if unifi_session.base_url:
result = "ok"
return result | e375b8f673499c093cdfb691e154e5f7ba9f1737 | 35,462 |
import requests
import json
def post_request(url, json_payload, **kwargs):
"""
post_request function is used to send a POST request in order to interact
with remote services through rest apis
url: url to the remote service
json_payload: json object containing remote service input parameters
k... | 8c9de68163df2c056f317aafd6affc79e49ce2cc | 35,465 |
def tokenise_table_name(table_name):
"""Given a feature class or feature dataset name, returns the schema (optional) and simple name"""
dot_count = table_name.count(".")
if dot_count == 2:
dot_pos = [pos for pos, char in enumerate(table_name) if char == "."]
return {
"database... | 7664bd8099cea88c8d0313c62ce5d4da38fcf947 | 35,467 |
def ConvertTokenToInteger(string, location, tokens):
"""Pyparsing parse action callback to convert a token into an integer value.
Args:
string (str): original string.
location (int): location in the string where the token was found.
tokens (list[str]): tokens.
Returns:
int: integer value or None... | f0332c672156bb95b0d14d0af94d197464ab70a0 | 35,472 |
def midpoint(imin, imax):
"""Returns middle point
>>> midpoint(0, 0)
0
>>> midpoint(0, 1)
0
>>> midpoint(0, 2)
1
>>> midpoint(1, 1)
1
>>> midpoint(1, 2)
1
>>> midpoint(1, 5)
3
"""
middle_point = (int(imin) + int(imax)) / 2
return middle_point | 389058bb50f0e1f3d31498edcac2469a97545a3f | 35,474 |
def get_num_image_channels(module_or_spec, signature=None, input_name=None):
"""Returns expected num_channels dimensions of an image input.
This is for advanced users only who expect to handle modules with
image inputs that might not have the 3 usual RGB channels.
Args:
module_or_spec: a Module or ModuleS... | ade88e40833749b48461d7f996ab8824258ad7df | 35,475 |
import warnings
def check_case(name):
"""
Check if the name given as parameter is in upper case and convert it to
upper cases.
"""
if name != name.upper():
warnings.warn("Mixed case names are not supported in database object names.", UserWarning)
return name.upper() | 8e973c6c087e3bb9b3abd076e2d97b3770f3589c | 35,477 |
from typing import List
def listToCSV(lst: List) -> str:
"""
Changes a list to csv format
>>> listToCSV([1,2,3])
'1,2,3'
>>> listToCSV([1.0,2/4,.34])
'1.0,0.5,0.34'
"""
strings = ""
for a in lst:
strings += str(a) + ","
strings = strings[0:len(strings) - 1]
return s... | 89fc272c4b9fc0a3a406f67d7b655b2c72755d07 | 35,479 |
def fibonacci(n):
"""
This function prints the Nth Fibonacci number.
>>> fibonacci(3)
1
>>> fibonacci(10)
55
The input value can only be an integer, but integers lesser than or equal to 0 are invalid, since the series is not defined in these regions.
"""
if n<=0:
return "Incorrect input."
elif n==1:
ret... | 165a6bf1fc73d24e0b3c25599040c26a56afdcd9 | 35,480 |
def _CreatePatchInstanceFilter(messages, filter_all, filter_group_labels,
filter_zones, filter_names,
filter_name_prefixes):
"""Creates a PatchInstanceFilter message from its components."""
group_labels = []
for group_label in filter_group_labels:
... | 7692812fe66b8db42bd76550281c7751d7648b1c | 35,481 |
def filter_on_cdr3_length(df, max_len):
"""
Only take sequences that have a CDR3 of at most `max_len` length.
"""
return df[df['amino_acid'].apply(len) <= max_len] | abe853dd0a5baeb3a178c41de9b15b04912e2033 | 35,494 |
def calc_array_coverage(solid_angle, number_of_bars):
"""
Calculate the coverage for an entire array
:param solid_angle: The solid angle in sr
:param number_of_bars: The number of solids in the array.
:return:
"""
return number_of_bars * solid_angle | 1d071116dea5f6a9e91c37168681b5386df0ac76 | 35,495 |
import mmap
import pickle
def load(path):
"""Load serialized object with out-of-band data from path based on zero-copy shared memory.
Parameters
----------
path : pathlib.Path
Folder used to save serialized data with serialize(). Usually a folder /dev/shm
"""
num_buffers = len(list(p... | 6c0ccc1d4941a6073b9f005774f53e3428dfc276 | 35,496 |
import torch
def secondary_sequence_metrics(x, ss_num=7):
"""
Compute metrics associated with with secondary structure.
It counts how many times a secondary structure appears in the proteins, and the median length of a sequence of
secondary structure, e.g. H, H, ..., H.
Parameters
----------... | 8ddc8df86438e0dee3aec45c2e573f4b39cca114 | 35,499 |
import re
def clean_text(text):
"""
Remove code blocks, urls, and html tags.
"""
text = re.sub(r'<code[^>]*>(.+?)</code\s*>', '', text, flags=re.DOTALL | re.MULTILINE)
text = re.sub(r'<div[^>]*>(.+?)</div\s*>', '', text, flags=re.DOTALL | re.MULTILINE)
text = re.sub(r'<blockquote[^>]*>(.+?)</block... | 91934ecd7e5d037be1198bc645da8e507b5955ce | 35,503 |
def list_string_to_dict(string):
"""Inputs ``['a', 'b', 'c']``, returns ``{'a': 0, 'b': 1, 'c': 2}``."""
dictionary = {}
for idx, c in enumerate(string):
dictionary.update({c: idx})
return dictionary | 0d9e3516e32bc69ee24d6afb19a7babcdba528f9 | 35,506 |
def bytes_leading(raw_bytes, needle=b'\x00'):
"""
Finds the number of prefixed byte occurrences in the haystack.
Useful when you want to deal with padding.
:param raw_bytes:
Raw bytes.
:param needle:
The byte to count. Default \x00.
:returns:
The number of leading needl... | f57a4eef0bbf28df31c5a1f49d3e681f056403a9 | 35,512 |
def ir(x):
"""
Rounds floating point to thew nearest integer ans returns integer
:param x: {float} num to round
:return:
"""
return int(round(x)) | 3ef85ede1dd773e2b9f67138a9448e9b47fd9610 | 35,522 |
def setup_with_context_manager(testcase, cm):
"""
Use a contextmanager in a test setUp that persists until teardown.
So instead of:
with ctxmgr(a, b, c) as v:
# do something with v that only persists for the `with` statement
use:
def setUp(self):
self.v = setup_with_context_ma... | e1996c9650f02c89e8516ca9ae030f1a50576eda | 35,530 |
def point_interval(ref_features, sec_features, disp):
"""
Computes the range of points over which the similarity measure will be applied
:param ref_features: reference features
:type ref_features: Tensor of shape (64, row, col)
:param sec_features: secondary features
:type sec_features: Tensor ... | 22f1477ec4ef86f343969f6316771f3ebb21d085 | 35,533 |
def _remove_pageoutline(text: str):
"""
Remove any TracWiki PageOutline directives
"""
return text.replace('[[PageOutline]]', '') | 72642413d11b5251c4f981a48ce7eb582cc9baf7 | 35,535 |
import tempfile
def get_temp_dir(prefix='tmp-cegr-', dir=None):
"""
Return a temporary directory.
"""
return tempfile.mkdtemp(prefix=prefix, dir=dir) | 3abd323f97e72edb66d6bc00c6d08459a37f962a | 35,537 |
def _cafec_coeff_ufunc(actual,
potential):
"""
Vectorized function for computing a CAFEC coefficient.
:param actual: average value for a month from water balance accounting
:param potential: average potential value from water balance accounting
:return CAFEC coefficient
... | 9e0b4201dff2acb6170b9719558da494f15ad6e7 | 35,538 |
from typing import List
import random
def sample_floats(low: float, high: float, k: int = 1) -> List[float]:
"""Return a k-length list of unique random floats in the range of low <= x <= high."""
seen = set()
for _ in range(k):
x = random.uniform(low, high)
while x in seen:
x =... | 9dcbef61809e1cfc3cc3748338137e4d48a95059 | 35,539 |
def escape_invalid_characters(name, invalid_char_list, replace_with='_'):
"""
Remove invalid characters from a variable and replace it with given character.
Few chars are not allowed in asset displayname, during import/export
Escape those chars with `replace_with` and return clean name
Args:
... | 47359202f0cee82426d35ec5a85d315d96ece1d7 | 35,545 |
def _estimate_step_number(n_points: int, batch_size: int) -> int:
"""Estimates which step this is (or rather how many steps were collected previously, basing on the ratio
of number of points collected and the batch size).
Note that this method is provisional and may be replaced with a parameter in the conf... | c097140107c458f0517d9f616b20d88ef0268e15 | 35,547 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.