content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
import argparse
def valid_write_option(string):
"""
This method checks whether the string is one of the valid write options and if not raises an error.
:param string: The write option
:type string: str
:return: str
"""
valid_options = ["w", "a"]
if string not in valid_options:
... | 8784d7af1bf4c35172bf61e8c08f08eed2ce68fa | 700,496 |
from typing import List
from typing import Tuple
from typing import Any
def min_w_ind(lst: List) -> Tuple[int, Any]:
"""
Returns the min value and its index
:param lst: The list to get the max value in
:return: Min value and its index
"""
val = min(lst)
ind = lst.index(val)
return ind,... | d0da7d1ab1c762f1af2333de6e8b829f8218fd25 | 700,498 |
def count(iterable):
"""
Returns the number of items in `iterable`.
"""
return sum(1 for whatever in iterable) | a9bb4ac70cef36613372c1225202f97f70a642cf | 700,499 |
import torch
def xy_to_cxcy(xy):
"""
Convert bounding boxes from boundary coordinates (x_min, y_min, x_max, y_max) to center-size coordinates (c_x, c_y, w, h).
:param xy: bounding boxes in boundary coordinates, a tensor of size (n_boxes, 4)
:return: bounding boxes in center-size coordinates, a tensor... | 46eef5bb63c85a84050a57a2fb27618721b31eaa | 700,500 |
def calculate_p_b(*args):
"""
Determines how difficult a text is according to the number of words that are, most likely, unknown to readers.
The other formulas we referred to based the score on the number of words and sentences only
"""
words_count, sentences_count, diff_words_count = args[0... | 420b8269390f50b163c89e97f95b27a282f6f829 | 700,501 |
def part1(entries: tuple) -> int:
"""part1 solver"""
card_key, door_key = entries
loop_size = 0
key = 1
while key not in (card_key, door_key):
loop_size += 1
key = (key * 7) % 20201227
if key == card_key:
return pow(door_key, loop_size, 20201227)
return pow(card_key,... | cb4e38704229c3a67a67d7ffd7d8a7e0d2d72628 | 700,502 |
def selection(triple, variables):
"""Apply selection on a RDF triple"""
bindings = set()
if variables[0] is not None:
bindings.add((variables[0], triple[0]))
if variables[1] is not None:
bindings.add((variables[1], triple[1]))
if variables[2] is not None:
bindings.add((variab... | 7f237f271d7c980e5ece21eacde671ee0f8a1d05 | 700,503 |
def daily_std_error(merged_data):
"""Calculates daily seasonal standard error of the timeseries data in a DataFrame
Parameters
----------
merged_data: DataFrame
A pandas DataFrame with a datetime index and columns containing float type values.
Returns
-------
DataFrame
A p... | 11b5f72ff1a68425cd17d7638590290f5ac883d8 | 700,504 |
def tanimoto_sparse(str1, str2):
"""!
Calculate the tanimoto coefficient for a pair of sparse vectors
@param str1 str: String of 1s and 0s representing the first compound fingerprint
@param str2 str: String of 1s and 0s representing the second compound fingerprint
@return Returns float
"""
n... | 2a7a6e7c585ceb3aaaa4dfed7e98b01f151e7c06 | 700,505 |
from bs4 import BeautifulSoup
import codecs
def get_saml_response(html):
"""
Parse SAMLResponse from Shibboleth page
>>> get_saml_response('<input name="a"/>')
>>> get_saml_response('<body xmlns="bla"><form><input name="SAMLResponse" value="eG1s"/></form></body>')
'xml'
"""
soup = Beauti... | 24800c318f7f5f6000c6652d15421c68a97a04a6 | 700,506 |
def _is_namespace_visible(context, namespace):
"""Return true if namespace is visible in this context"""
if context.is_admin:
return True
if namespace.get('visibility', '') == 'public':
return True
if namespace['owner'] is None:
return True
if context.owner is not None:
... | 4f3119684681aa2f3c34a62e1674aaa58d26105e | 700,507 |
def _exception_to_dict(exception):
"""Convert exception to an error object to be sent as response to APIs."""
return {"error": {"type": type(exception).__name__,
"message": exception}} | 4abb81516b604bdfd2f6360a1272556b0b6f6932 | 700,508 |
def _any_none(*args):
"""Returns a boolean indicating if any argument is None"""
for arg in args:
if arg is None:
return True
return False | fadb9330fc1f4ffca2cf0105d8513d0be0d5fae1 | 700,510 |
def precision(judged_data):
"""
Our relevance judgments are on a graded scale of 0-3, where scores of 1-3 are considered
relevant, and less than 1 is irrelevant. We compute precision of the result set based on
this quanitization.
Args:
judged_data (pandas.DataFrame): A DataFrame with at a m... | 6d4c4ee7793625e4590c01120318afe33cba0b0c | 700,511 |
def filter_cycles(cycle_list, **filters):
"""Puts cycles through filters to meet specific requirements.
cycle_list is a list of tuples where the first item is an intake and
the second action is a placement or drop.
filters are the specifications that certain data points inside the
cycles must fit t... | 1abdcf76365cbaced4ac1dcfff96a91282c38370 | 700,512 |
def ansi_escape(text):
"""
Replace characters with a special meaning.
"""
return text.replace('\x1b', '?').replace('\b', '?') | 86ff3e7cfce8fcc17e826896e32c28e0d30ee83c | 700,513 |
def _GetAndroidVersionFromMetadata(metadata):
"""Return the Android version from metadata; None if is does not exist.
In Android PFQ, Android version is set to metadata in master
(MasterSlaveLKGMSyncStage).
"""
version_dict = metadata.GetDict().get('version', {})
return version_dict.get('android') | e1d1ed9d0bbf2f65d646c11007739f6b5a9b78ec | 700,514 |
from functools import reduce
def get_in(d, t, default=None):
"""
look up if you can get a tuple of values from a nested dictionary,
each item in the tuple a deeper layer
example: get_in({1: {2: 3}}, (1, 2)) -> 3
example: get_in({1: {2: 3}}, (2, 3)) -> {}
"""
result = reduce(lambda d, t: d... | f92e6c94e3485f4b02a8487f832064de7a42eba5 | 700,515 |
def divisible_by_five(n: int) -> bool:
"""Return True if an integer is divisible by 5, and false otherwise."""
if n % 5 > 0:
return False
return True | e4cd2adf7067000f10aa655bb9fd819e525527d2 | 700,516 |
def _should_package_clang_runtime(ctx):
"""Returns whether the Clang runtime should be bundled."""
# List of crosstool sanitizer features that require packaging some clang
# runtime libraries.
features_requiring_clang_runtime = {
"asan": True,
"tsan": True,
"ubsan": True,
}
... | 7f54b903f4acc288abca294d857e774ce3daa8b3 | 700,517 |
import math
def round_nearest_towards_infinity(x, infinity=1e+20):
""" Rounds the argument to the nearest integer.
For ties like 1.5 the ceiling integer is returned.
This is called "round towards infinity"
Args:
x: the value to round
infinity: the model's infinity value. All values a... | e3edd7dfca255648f02eb9845f411f52c24d3120 | 700,518 |
def create_html_popup(friends: list) -> str:
"""creates html popup for markrer
Args:
friends (list): list of names
Returns:
str: html in string format
"""
html_template = "Friends:"
for friend in friends:
html_template += f"""<br>
<p>{friend}</p><br>
"""... | 54b1ac02cf59a086a711dcb0b47f14c0ea4e782d | 700,519 |
def euler_step(theta,dtheta,ddtheta,dt):
"""
Euler Step
Parameters
----------
theta (tf.Tensor):
Joint angles
(N,nq)
dtheta (tf.Tensor):
Joint velocities
(N,nq)
ddtheta (tf.Tensor):
Joint accelerations
(N,nq)
dt (float):
Delta t
... | 402b30a3f24440707ef56b7113b545eb827c704e | 700,520 |
import subprocess
def git_diff_files(oldrev, newrev):
"""Get list of files in diff."""
files_modified = subprocess.check_output(["git",
"diff",
"--name-only",
oldrev + ".."... | 4bfe2982a66b2bdb2c186cced1f4619965f58064 | 700,521 |
def beta1() -> float:
"""Mock beta1."""
return 0.9 | 1152a45a891c749b196cab780f8f76afc70c2a65 | 700,522 |
import base64
def b64s_to_s(b64s: str) -> str:
"""convert base 64 strting to string
:param b64s: input base 64 string
:type b64s: str
:return: output string
:rtype: str
"""
s = base64.b64decode(b64s.encode('utf8')).decode('utf8')
return s | beb49deb87d45da43cc8f12b3aacec37d7bfd1ed | 700,523 |
from typing import Counter
def counter(data, n=None):
"""counter方法用于统计元素数量
Parameters
----------
data : list
列表数据
n : int
前n个元素
Returns
----------
"""
ret = Counter(data)
if not n:
ret = ret.most_common(len(ret))
else:
ret = ret.most_common(... | 6fed62dd1478992c13c8dee5dd2cbb7556a5d0fe | 700,524 |
def col255_from_RGB(red,green,blue):
""" returns a term256 colour index from RGB value
found at :
https://unix.stackexchange.com/questions/269077/
"""
if red > 255:
red = 255
if green > 255:
green = 255
if blue > 255:
blue = 255
if red < 75:
red = 0... | 6d896f557d5903708f5072d1a875313633cea6b4 | 700,525 |
def first_or_default(iterable, predicate=None, default=None):
"""First the first value matching a perdicate otherwise a default value.
:param iterable: The items over which to iterate.
:param predicate: A predicate to apply to each item.
:param default: The value to return if no item matches.
:retu... | 94ee1c97cc752b1f5bb0ac4cc7c3a6a8f3fe4675 | 700,526 |
def image_md(image_location, caption="", link=None, tooltip=""):
"""
Returns the html code for the individual plot
"""
image = f"""
<a href="{link}" name="gallery-href">
<img src="{image_location}" name="gallery-image" alt="{tooltip}"
style="width:100%" id="{"".join(image_location.split("-... | 3e847459f14d8cfd2c66bed633640bbbb0442321 | 700,527 |
def fix_models_py(models_py):
"""
The output of inspectdb is pretty messy, so here we trim down
some of the mess, add mandatory ID field and fix the bad
conversion to CharField (we use TextField instead).
"""
lines = models_py.split("\n")
fixed_lines = []
for line in lines:
# Pos... | 428cce3315a2e47d44e35889e0cccd7d840794aa | 700,529 |
def sum_of_years_digits(year):
"""Calculate the sum of years' digits.
Arguments:
year (``int``): The year to calculate up to.
Returns:
int: The sum of years' digits.
"""
if year <= 0:
return 0
return year + sum_of_years_digits(year-1) | aa3d67cde4af6c8565ef6fdcd8becb0cb3b1fa95 | 700,531 |
import subprocess
def resolve_ref(repo_url, ref):
"""
Return resolved commit hash for branch / tag.
Return ref unmodified if branch / tag isn't found
Notes
-----
Author: Yuvi Panda
Copied from https://github.com/yuvipanda/repo2charliecloud/blob/
44a508b632e801d3b1f0dd1360e... | 4def5ab1e791ab0d3179418070580a11ac82f75f | 700,532 |
def get_values():
"""
Retrieves two values to multiply
"""
user_values = input("On the next line, enter the values to multiply,\
separated by commas. \n>> ")
input_list = user_values.split(",")
final_list = []
#We've split the user's input into a list, but have no idea if it's any good.
... | ea0fb353d61514e67970d673bbe9fb45a9b20123 | 700,533 |
def parse_simple_expression_list(l):
"""
This parses a comma-separated list of simple_expressions, and
returns a list of strings. It requires at least one
simple_expression be present.
"""
rv = [ l.require(l.simple_expression) ]
while True:
if not l.match(','):
break
... | 8c3772e1bd4cc9587c8095dcba640878c01fc0f4 | 700,534 |
from typing import Iterable
from typing import Any
from typing import List
import itertools
def flatten(val: Iterable[Iterable[Any]]) -> List[Any]:
"""
Flatens a list of list into a list
>>> flatten( [['abc','def'],[12,34,46],[3.14, 2.22]])
['abc', 'def', 12, 34, 46, 3.14, 2.22]
"""
return li... | cd9ae9e393569ba7800735d09c8621f0d64beed3 | 700,535 |
import io
import csv
def to_csv(members):
"""Convert JSON data structure to CSV string."""
with io.StringIO() as fp:
cw = csv.writer(fp)
if len(members):
cw.writerow(members[0].keys())
for member in members:
cw.writerow(member.values())
value = fp.getval... | 0ed85a10417dee1ca98a28e05e1ae2d24dcebfe0 | 700,536 |
def split_sentences(inp_text, nlp_model):
"""
Splits an input string into sentence determined by spacy model
:param inp_text: string with input text
:param nlp_model: sciSpacy model
:return: list of sentences in string format
"""
doc = nlp_model(inp_text)
sentences_list = [sentence.text ... | b5617d9334509edf09bf4a0360d3030e67ddf800 | 700,537 |
def _point(x,index=0):
"""Convert tuple to a dxf point"""
return '\n'.join([' %s\n%s'%((i+1)*10+index,float(x[i])) for i in range(len(x))]) | b5d2b3345b53bf2bd5e7fb93ee57fa9eb2a599b9 | 700,539 |
def get_video_dimensions(lines):
"""Has it's own function to be easier to test."""
def get_width_height(video_type, line):
dim_col = line.split(", ")[3]
if video_type != "h264":
dim_col = dim_col.split(" ")[0]
return map(int, dim_col.split("x"))
width, height = None, No... | 7df1dbc3e190908852684735bc1242db4e3c456b | 700,541 |
def _check_selection(selection):
"""Handle default and validation of selection"""
available = ["counts", "exposure", "background"]
if selection is None:
selection = available
if not isinstance(selection, list):
raise TypeError("Selection must be a list of str")
for name in selecti... | 454b36833a5117b2d1bab377094e8e3ec0c06969 | 700,542 |
def force(value):
"""
This helper function forces evaluation of a promise. A promise
for this function is something that has a __force__ method (much
like an iterator in python is anything that has a __iter__
method).
"""
f = getattr(value, '__force__', None)
return f() if f else value | eccdbfe927eeac54246ac777ed16864a7da38ca7 | 700,543 |
import array
def remove_glyf_instructions(tt) -> int:
"""Removes instruction set bytecode from glyph definitions in the glyf table."""
glyph_number: int = 0
for glyph in tt["glyf"].glyphs.values():
glyph.expand(tt["glyf"])
if hasattr(glyph, "program") and glyph.program.bytecode != array.ar... | 1b73d9b2fd53a2568f953faab65d5bfae5351189 | 700,544 |
import sys
def tweet_with_image(twtr, filename, msg, force=False):
""" tweet する """
if "ipy" in sys.argv[0] and not force:
return
#print(msg)
with open(filename, "rb") as imagefile:
imagedata = imagefile.read()
params = {"media[]": imagedata, "status": msg + " #COVID19"}
... | 094983d5469a740a63e2f4c74929cce316b1abf0 | 700,545 |
from typing import Dict
from typing import Any
def _make_version_config(version,
scaling: str,
instance_tag: str,
instances: int = 10) -> Dict[str, Any]:
"""Creates one version config as part of an API response."""
return {scaling: {in... | 1d4f613f35ace2f540629e6c79b3f571b3c2a255 | 700,546 |
import os
def calculate_destination(prefix, cuda, lib, lib_ver):
"""Calculates the installation directory."""
return os.path.join(prefix, ".data") | c7b471fb191daa345ddb44ef033d18d96198455c | 700,547 |
def sec_from_hms(start, *times):
""" Returns a list of times based on adding each offset tuple in times
to the start time (which should be in seconds). Offset tuples can be
in any of the forms: (hours), (hours,minutes), or (hours,minutes,seconds).
"""
ret = []
for t in times:
cur = 0
... | 4c279736f173cbec4170880cfdf279e801847b5a | 700,548 |
def remove_missing_targets(this_data,target_var):
"""
Gets raw data and removes rows with missing targets
Parameters
----------
this_data : dataframe
The raw data which has been compiled from Yahoo!Finance
target_var : string
Column name of target variable
Returns
-----... | 82d9d5f77821c7ee1b6eec53d3b9bb474922beac | 700,550 |
def tee(iterable, n=2):
"""Return n independent iterators from a single iterable.
:param iterable: the iterator from which to make iterators.
:param n: the number of iterators to make (default is 2)
"""
return [iter(iterable) for _ in range(n)] | cb35d518b90ddf66627e171b00e977823d4d3d17 | 700,551 |
import pandas as pd
def pandas_extract_rows(data_frame, ugridtype_str, index_names):
"""removes the t2-t6 for S and E points"""
letter_dims = [
('G', 6),
('E', 1),
('S', 1),
('H', 6),
('L', 6),
]
cat_keys = []
for (letter, dim) in letter_dims:
if let... | 2b297aa5e6944d9eaa6b18031045d3b03e7c6d9f | 700,552 |
def reverse_grammar(pgrammar):
"""reverses the order of the keys appearing in the parsed grammar."""
pgrammar = dict(reversed(list(pgrammar.items())))
return pgrammar | f4f1b6a5e9f8ad062dde6f6322cec771e792bc6d | 700,553 |
import fileinput
def read_input() -> str:
"""Reads Brainfuck application from file or stdin"""
return "".join(line for line in fileinput.input()) | 7d3b8776cf95a254a414e91ff9e236575ddfc2ea | 700,554 |
def is_search_in_version(search, version):
"""
Determine if the given version is a valid member of the given version search
text.
"""
search_segments = search.split('.')
seg_count = len(search_segments)
version_segments = version['full'].split('.')
full_version_count = len(version_segmen... | 0a7bc028985d6d18bb4fd1eb745082756be4707f | 700,555 |
def parse_live_msg(user, msg, title, game):
"""Turns the bot's <user> <title> etc format into a readable message"""
msg = str(msg)
user = str(user)
word = ""
words = []
r = 0
for i in range(len(msg)):
if msg[i] == "<" or msg[i] == ">":
if r == 1:
if "every... | 07a4269d24df3f69d5ab215c0e9579a3bb691b63 | 700,556 |
def remove_child_items(item_list):
"""
For a list of filesystem items, remove those items that are duplicates or children of other items
Eg, for remove_child_items['/path/to/some/item/child', '/path/to/another/item', '/path/to/some/item']
returns ['/path/to/another/item', '/path/to/some/item']
I... | 02f92094cb697be40a4c16d90e8ee6b33f965438 | 700,557 |
def isen_nozzle_mass_flow(A_t, p_t, T_t, gamma_var, R, M):
"""
Calculates mass flow through a nozzle which is isentropically expanding
a given flow
Input variables:
A_t : nozzle throat area
gamma_var : ratio of specific heats
p_t : pressure at throat
T_t : temperature at throat
M : Mach num... | d2cb14d099167c4dbca4ce51a67d248bd15a4a88 | 700,558 |
def calc_overturning_stf(ds,grid,doFlip=True):
"""
Only for simple domains, compute meridional overturning streamfunction
Parameters
----------
ds : xarray Dataset from MITgcm output, via
e.g. xmitgcm.open_mdsdataset
must contain 'V' or 'VVELMASS'... | d7d25368268dc16c4603a88a3a11607772f04da4 | 700,559 |
from typing import List
def ways_to_fill(amount: int, containers: List[int]) -> int:
"""The number of ways to pour amount of liquid into containers.
All containers used must be filled up entirely."""
if amount == 0:
# Reached an acceptable configuration.
return 1
if amount < 0 or not ... | 098a4b22d29f9527dfcf04d48e2f58784903101d | 700,561 |
def value_at_diviner_channels(xarr):
"""Return value of xarr at each diviner channel."""
dwls = [
3,
7.8,
8.25,
8.55,
(13 + 23) / 2,
(25 + 41) / 2,
(50 + 100) / 2,
(100 + 400) / 2,
] # [microns]
return xarr.interp({"wavelength": dwls}) | 4897ed8250e2f02409205c02a26d63cfafb50a52 | 700,562 |
from typing import List
def txt2list(path: str) -> List:
"""
Opens a text file and converts to list by splitting on new lines
"""
with open(path, "r") as f:
txt = f.read()
return list(filter(None, txt.split("\n"))) | 02feac063537e3434e053556f19cf8bf66b5df68 | 700,563 |
def obtain_value(entry):
"""Extract value from entry.
The entries could be like: '81.6', ': ', '79.9 e', ': e'.
"""
entry = entry.split(' ', maxsplit=-1)[0] # Discard notes.
if not entry or entry == ':':
return None
return float(entry) | cabb8c9314716fe988102a6226734dd7408be736 | 700,564 |
def time_str_fixer(timestr):
"""
timestr : str
output
rval : str
if year is 2006, hysplit trajectory output writes year as single digit 6.
This must be turned into 06 to be read properly.
"""
if isinstance(timestr, str):
temp = timestr.split()
year = str(int(temp[0])).zf... | 546ede251de8a8e30831851d645cbb0143fc01db | 700,565 |
import torch
def psnr_compute(img_batch, ref_batch, batched=False, factor=1.0, clip=False):
"""Standard PSNR."""
if clip:
img_batch = torch.clamp(img_batch, 0, 1)
if batched:
mse = ((img_batch.detach() - ref_batch) ** 2).mean()
if mse > 0 and torch.isfinite(mse):
retur... | e507e4ae1aa3034319421d8e8bf156f67646fec2 | 700,566 |
def extend_dict(d1, d2):
"""Extends d1 with d2, removing duplicates from d1"""
d1_keys = set(d1.keys())
d2_keys = set(d2.keys())
intersect_keys = d1_keys.intersection(d2_keys)
return dict(**{o: d1[o] for o in d1_keys - intersect_keys}, **d2) | fdbcb83e1f14098d51a6ca77d6b0085dd6ad915c | 700,567 |
import re
def RemoveTime(output):
"""Removes all time information from a Google Test program's output."""
return re.sub(r'\(\d+ ms', '(? ms', output) | 1269b502fdf7d46165b0c0dca3dab50cd2e36550 | 700,568 |
def IsInclude(line):
"""Return True if line is an include of another file."""
return line.startswith("@include ") | 42278a2d0ea3582111a9cbae26860e1f229398b3 | 700,569 |
import heapq
def largest_n_element(m_dict, n):
"""Get the largest n words from the dict
Args:
m_dict (dict): the dict with word as key and the count of word as value
n (int): the number of elements we have to return
Returns:
list_: the n largest pairs in the dict order by value
... | 80723dd91aae6ffa837b1c3794a730331798de55 | 700,570 |
def err_ratio(predict, dataset, examples=None, verbose=0):
"""Return the proportion of the examples that are NOT correctly predicted.
verbose - 0: No output; 1: Output wrong; 2 (or greater): Output correct"""
examples = examples or dataset.examples
if len(examples) == 0:
return 0.0
right = 0... | 9159fdb65e47a817381fe08dfdee77f967a47ef5 | 700,571 |
def _get_label_from_dv(dv, i):
"""Return label along with the unit of the dependent variable
Args:
dv: DependentVariable object.
i: integer counter.
"""
name, unit = dv.name, dv.unit
name = name if name != "" else str(i)
label = f"{name} / ({unit})" if unit != "" else name
r... | fd18e3d4b5f61bec6febc27b1d7d86b378205a0a | 700,572 |
def get_land_only(dtset, tolerance=0.5):
"""
Returns True where land.
:param dtset:
:return:
"""
if 'LANDFRAC' in dtset:
mask = dtset['LANDFRAC']>tolerance
if 'time' in mask.dims:
return mask.isel(time=0).squeeze()
else: return mask
else:
print('LA... | 2d9ae86edbb43f8dcd0402e263b6d732e7e02c03 | 700,573 |
def get_seconds(value, scale):
"""Convert time scale dict to seconds
Given a dictionary with keys for scale and value, convert
value into seconds based on scale.
"""
scales = {
'seconds': lambda x: x,
'minutes': lambda x: x * 60,
'hours': lambda x: x * 60 * 60,
'days': lambda x: x * 60 * 60 *... | 92245d0568ea44eb5a906021badcb888535dc5a0 | 700,574 |
def points_2_inches(points) -> float:
"""
Convert points to inches
"""
return points / 72 | 8744659807046c892f2d1f36c3dc47a44417ca96 | 700,576 |
import os
import wave
def estimate_recording(path):
"""
Args:
Take the path to the folders
Return:
Number of voice recording and total voice recording made.
"""
waves = []
for path , _ , files in os.walk(path):
for record in files:
if record.endswith... | 398a95a6958cb944dca69987dd1da7b022e5fb26 | 700,577 |
import importlib
def my_import(class_name):
"""Return a python class given a class name.
Usage example::
Report = my_import('myclass.models.Report')
model_instance = Report()
model_instance.name = 'Test'
model_instance.save()
:param str class_name: Class name
:retur... | 214bf9efed78a9e2dcc9897a28f389ef40918063 | 700,578 |
import sys
import subprocess
import os
def spawn_command(*command):
"""
Run the given command, without waiting for completion. Return the Popen
object (which provides .send_signal, .kill(), .wait(), etc), or None
if the command couldn't be run at all.
The command is created with its own process ... | 6e0757379eee2ccb79a2b104f45c40e6705719f2 | 700,579 |
def rename_motifs(motifs, stats=None):
"""Rename motifs to GimmeMotifs_1..GimmeMotifs_N.
If stats object is passed, stats will be copied."""
final_motifs = []
for i, motif in enumerate(motifs):
old = str(motif)
motif.id = "GimmeMotifs_{}".format(i + 1)
final_motifs.append(motif)... | bcc7ea61f7791b3c6f9d5b26cde1f8a7ac79bb9b | 700,580 |
def _get_region(zone):
"""
Get region name from zone
:param zone: str, zone
:return:
"""
return zone if 'gov' in zone else zone[:-1] | aa272e6e6e00b444f29ffbe821b2d255196d55f6 | 700,581 |
def conv_bright_ha_to_lib(brightness) -> int:
"""Convert HA brightness scale 0-255 to library scale 0-16."""
if brightness == 255: # this will end up as 16 which is max
brightness = 256
return int(brightness / 16) | 45782f53a41605b20230c71c7e2ccf713d10c6dc | 700,582 |
def findIntersection3(p1, p2, p3, p4):
"""
p1, p2 on the same line
p3, p4 on the another line
"""
px = ((p1[0]*p2[1] - p1[1]*p2[0]) * (p3[0]-p4[0]) - (p1[0]-p2[0]) * (p3[0]*p4[1] - p3[1]*p4[0])) / ((p1[0]-p2[0]) * (p3[1]-p4[1]) - (p1[1]-p2[1]) * (p3[0]-p4[0]))
py = ((p1[0]*p2[1] - p1[1]*p2[0]) *... | 6605f2756d1812c42b6793468366071f4ed4abb8 | 700,583 |
def retrieve_item(item_id):
"""
This is a stubbed method of retrieving a resource. It doesn't actually do anything.
"""
return {
"id": item_id,
"brand_name": "Clean Breathing",
"name": "Air Purifier",
"weight": 12.3,
} | eedeca7580bd74244c62da798ac19d6b815ba445 | 700,584 |
from datetime import datetime
def log_file_name(extension):
"""
Create a file name in the logfiles directory, based on current data and time
Requires the computer to have an RTC or synched clock
"""
now = datetime.now()
# Linux
file_name = '%0.4d%0.2d%0.2d-%0.2d%0.2d%0.2d' % (now.year, now... | 795ab0623ee6a563cfc4e2531cd8745f0ff2fac3 | 700,585 |
def TreeImportanceArray(reg):
"""Get important array if `reg` is tree regression."""
return reg.feature_importances_ | 59f3b0bcc9a4c60af71b62163e3e087137c64f49 | 700,586 |
from typing import Any
from typing import Dict
def _check_headers(headers: Any) -> Dict:
"""Check headers format an validate content type.
:param headers: configured headers
:return Dict: request headers
"""
if headers is None:
headers = {}
if 'Content-Type' not in headers.keys():
... | f7dc965ffd740ea94ca3485f455cf6427ebc16d8 | 700,587 |
def get_middle_value(my_list):
"""Return the middle value from a list after sorting.
:param list my_list: List of sortable values"""
return sorted(my_list)[len(my_list) // 2]
"""Convert an integer resolution in base-pairs to a nicely formatted string.
:param int window_size: Integer resolution ... | 53e8724f1709429707766db45c34ebd0db62a686 | 700,588 |
def rip_svgi(content: str, embed_styles: bool = False) -> str:
"""
Rips SVG content (single diagram) and scripts for interaction out of HTML
:param content: HTML page content in text format
:param embed_styles: If specified as True then mentioned styles would be downloaded and embedded into SVG
... | d5472b86be70e138128ff527f388a9b1ffa2602d | 700,590 |
import numpy
def _image_to_ground_plane_perform(r_tgt_coa, r_dot_tgt_coa, arp_coa, varp_coa, gref, uZ):
"""
Parameters
----------
r_tgt_coa : numpy.ndarray
r_dot_tgt_coa : numpy.ndarray
arp_coa : numpy.ndarray
varp_coa : numpy.ndarray
gref : numpy.ndarray
uZ : numpy.ndarray
R... | d325471ce2f21562dfd38e536ce77eb215069349 | 700,591 |
def encode_string_text(text):
"""Replace special symbols with corresponding entities or magicwords."""
text = text.replace("<", "<")
text = text.replace(">", ">")
text = text.replace("[", "[")
text = text.replace("]", "]")
text = text.replace("{", "{")
text = text.replace(... | c7887934983efda3a0d1e06451ccd85cab529a30 | 700,592 |
def _params_to_ints(qs):
"""Convert a (string) list of string ids to a list of integers"""
return [int(str_id) for str_id in qs.split(',')] | 7568eeb6cf28f1c8e696e2fab6e7a89dcbbc07fc | 700,593 |
from typing import List
def est_croissante2(l : List[float]) -> bool:
""" ... cf. ci-dessus ...
"""
# Résultat
b : bool = True
# Indice courant
i : int = 0
while (i < len(l) - 1) and b:
b = l[i] < l[i + 1]
i = i + 1
return b | 74357fe91d42b3cb0d95e09346504b0701ab7164 | 700,594 |
def compose(f, g):
"""
Compose two filter f and g.
:param f: Outer filter function.
:type f: filter function.
:param g: Inner filter function.
:type g: filter function.
:return: lambda x: f(g(x))
:rtype: filter function.
"""
def filter_fn(df):
df = g(df)
if len... | d90cda63eb365219ce5f454265036c7d977da216 | 700,595 |
def stop_list_to_link_list(stop_list):
"""
[a, b, c, d] -> [(a,b), (b,c), (c,d)]
"""
return list(zip(stop_list[:-1], stop_list[1:])) | 49046e60664cd9c19ab55c1254684932d937531a | 700,596 |
def compare_metrics(best_eval_result, current_eval_result):
"""Compares two evaluation results."""
return best_eval_result["exact_match"] < current_eval_result["exact_match"] | ce3880c2cc271d9c8c766a2dfbd95d31f5fb651c | 700,597 |
from typing import Dict
import requests
from bs4 import BeautifulSoup
import re
def scrap_allrecipes_recipe(url: str) -> Dict:
"""This function scraps a recipe of Allrecipes, given its URL,
and prepare a JSON file to index in Elasticsearch.
:param url: the URL of the recipe
:return: the recipe as a J... | 0c060ba40e784b7dad6ab2af40dd6f0aa4600173 | 700,598 |
def segmentPlaneIntersection(s0 = "const Dim<3>::Vector&",
s1 = "const Dim<3>::Vector&",
point = "const Dim<3>::Vector&",
normal = "const Dim<3>::Vector&",
tol = ("const double", "1.0e-8")):
"""Inters... | eb68974937de575702069565fc3ee34dfadf89cc | 700,599 |
def maybeName(obj):
""" Returns an object's __name__ attribute or it's string representation.
@param obj any object
@return obj name or string representation
"""
try:
return obj.__name__
except (AttributeError, ):
return str(obj) | 2b83918c49fc6cd19a027c1d2db07fcb0d57166a | 700,601 |
from typing import List
import os
import subprocess
import glob
def ped_datasets() -> List[str]:
"""Returns paths after downloading pedestrian datasets."""
if not os.path.exists("datasets"):
subprocess.call(
["wget", "https://www.dropbox.com/s/8n02xqv3l9q18r1/datasets.zip"]
)
... | b322580b0ef544d0705d792c4be4f7cb13f2824e | 700,602 |
import math
import random
def generate_random_pose():
"""
generate a random rod pose in the room
with center at (0, 0), width 10 meters and depth 10 meters.
The robot has 0.2 meters as radius
Returns:
random_pose
"""
def angleRange(x, y, room, L):
"""
Compute rod an... | 81c26bbabb6b4386b4086b20a09fe8691add2fed | 700,603 |
def constant_schedule_with_warmup(epoch, warmup_epochs=0, lr_start=1e-4, lr_max=1e-3):
""" Create a schedule with a constant learning rate preceded by a warmup
period during which the learning rate increases linearly between {lr_start} and {lr_max}.
"""
if epoch < warmup_epochs:
lr = (lr_max - ... | e780c3946f0207f94065c3ce8333896c3513f25a | 700,604 |
def nSpecies():
""" Returns the total number of species in the model. """
return 62 | b9e77841cb46bba4faa1fab3c1ea00875753aaf1 | 700,605 |
def rom(a, b,f, eps = 1e-8):
"""Approximate the definite integral of f from a to b by Romberg's method.
eps is the desired accuracy."""
R = [[0.5 * (b - a) * (f(a) + f(b))]] # R[0][0]
#print_row(R[0])
n = 1
while True:
h = float(b-a)/2**n
R.append((n+1)*[None]) # Add an empty r... | 3dfd00652837b999187a30ace3c3143fa381cb2a | 700,606 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.