content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def pad_table_to_rectangle(table, pad_value=''):
"""
Take any table and ensure it is entirely rectangular.
Any missing entries will be filled with pad_value.
Returns: The table passed in.
"""
max_len = max([len(x) for x in table])
for row in table:
row += [pad_value for _ in range(... | 90de99e0c7ead6a15d8f99922677e5b3f659af56 | 694,849 |
def encode_ebv(value):
"""
Get 01-encoded string for integer value in EBV encoding.
Parameters
----------
value : int
"""
def _encode(value_, first_block):
prefix = '0' if first_block else '1'
if value_ < 128:
return prefix + format(value_, '07b')
return ... | c5708244ca5ee6489657ef9d3a1083f516f3f086 | 694,850 |
def plot_evoked_topomaps(epochs, events, average_method, times):
"""
Plot evoked topomaps.
One figure is generated for each event.
Parameters
----------
epochs : mne.epochs.Epochs
Epochs extracted from a Raw instance.
events : list[str]
Events to include.
average_method... | 83e040930cc8971aeb045b4accaa315fcb53cc4f | 694,851 |
def my_diffusion_constant(vacf,h):
""" Calculate the diffusion constant from the
velocity-velocity auto-correlation function (vacf).
Args:
vacf (np.array): shape (nt,), vacf sampled at
nt time steps from t=0 to nt*dt. dt is set to 0.032.
Returns:
float: the diffusion constant calcula... | e1907e43c5039b5373dc2f040001f6552dcdc930 | 694,852 |
def healthz():
""" Healthz endpoint """
return '' | 5bbcd5aecd646b192ebac6c98a3277a89551410f | 694,853 |
def CheckDoNotSubmitInDescription(input_api, output_api):
"""Checks that the user didn't add 'DO NOT ''SUBMIT' to the CL description.
"""
keyword = 'DO NOT ''SUBMIT'
if keyword in input_api.change.DescriptionText():
return [output_api.PresubmitError(
keyword + ' is present in the changelist descript... | c2ac7c263db43897933120fac475a5a2fc6774bc | 694,854 |
def replaceEmojis(text):
"""Turn emojis into smilePositive and smileNegative to reduce noise."""
processedText = text.replace('0:-)', 'smilePositive')
processedText = processedText.replace(':)', 'smilePositive')
processedText = processedText.replace(':D', 'smilePositive')
processedText = proces... | d4e9fbb6ff7ea531464fad375d0a6e0dcaf0c293 | 694,855 |
import math
import itertools
def permutate(k, l_exp):
"""
Generate the permutations for all exponents of y
:param k: number of meaningful directions
:param l_exp: expansion order
:return perms: array of permutations
"""
Nt = int(math.factorial(l_exp + k) / (math.factorial(l_exp) * math.f... | c0de0d2964299e2956ba4e04fe3ad5df9cafbc2d | 694,856 |
import random
def randomize_seed(n_clicks):
"""
randomize the seed input.
"""
return random.randint(100, 2**31-1) | 3c69cbd2cf02c076e257ea5e78ac6b4f492dcebc | 694,857 |
import math
def ebob(a,b):
"""
Returns the greatest common divisor of a and b.
"""
return math.gcd(a,b) | 43039a85b7a1e5065f7365c17c308a1c9d9df37d | 694,858 |
def remove_planet(name):
"""Remove the trailing b, c, d, etc in the stellar name"""
planets = 'abcdefghijB'
for planet in planets:
if name.endswith(' %s' % planet):
return name[:-2].strip()
# some exoplanets have .01 or .02 in the name
if name.endswith('.01') or name.endswith('.... | adc3b62a6df6e4e26f76c382b06a8462a9c5b8bf | 694,859 |
def convert_comma_separated_integer_to_float(comma_separated_number_string):
"""Converts a string of the form 'x,xxx,xxx' to its equivalent float value.
:param comma_separated_number_string: A string in comma-separated float form to be converted.
:returns: A float representing the comma-separated number.
... | daddeaa78a3efb8ffd2d5eac122757f041da5f97 | 694,860 |
from datetime import datetime
import json
import requests
def send_metrics(
uuid,
data,
solution_id,
url="https://metrics.awssolutionsbuilder.com/generic",
):
"""sends metric to aws-solutions
Args:
uuid (string): unique id to make metrics anonymous
data (dict): usage metrics f... | ab29d0c8830cb6ead501e84fa09ec9c0c28c9dcd | 694,861 |
import os
def setup_env(mode, test_dir):
"""Define directories."""
mode = "ref" if mode is None else mode.lower()
ref_dir = (
os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"support",
"ref_images{0}".format("_{0}" if mode == "test" else ""),
... | d1cb1041b60c0c70897d94ebf091e487bb1da7e5 | 694,862 |
import logging
def cache_and_log(rdd_name, rdd, show_items=1, info_func=logging.info, warn_func=logging.warning):
"""Cache and pretty log an RDD, then return the rdd itself."""
rdd = rdd.cache()
count = rdd.count()
if count == 0:
warn_func('{} is empty!'.format(rdd_name))
elif show_items =... | 21c0512b0aff8bc2a9b9f5cf05bfce2b6854d8b1 | 694,863 |
def duplicate_string(text):
"""
Try to get a fresh clone of the specified text:
new object with a reference count of 1.
This is a best-effort: latin1 single letters and the empty
string ('') are singletons and cannot be cloned.
"""
return text.encode().decode() | 4a69e3ff34abe7bfa01824fe4ab44ae163e94bd8 | 694,864 |
def _encode_Bool_Flag(bBoolFlag : bool) -> int:
"""
Description
-----------
Method encoding a bool value into an integer flag.
Parameters
----------
`bBoolFlag` : bool
Boolean flag which should be converted into an integer value
Return
------
`iEncodedFlag` : int
... | 1df72f50b6b3e8206a09634386cd14f308f931f5 | 694,865 |
import os
import pdb
def get_path(fname):
"""Return file's path or empty string if no path."""
pdb.set_trace()
head, tail = os.path.split(fname)
return head | 62fd5c0e9bf8251589530495a0d3b93aa644bd8b | 694,866 |
def dataToTuple(stringData):
"""
Formats string to tuple ("id:data" -> (id,data))
"""
splitLine = stringData.split(": ")
result = (splitLine[0],splitLine[1].strip("\n"))
return result | dce23300746935541822cd9e6924fca84bc702d4 | 694,867 |
def login(client, secret_id, rresp):
"""logging in as 'secret_id' with 'g-recaptcha-response'
client (class Flask.testing.FlaskClient): the client
secret_id (str): the secret_id to login
rresp (str): the recapctha response code. can be empty in testing
"""
return client.post('/auth',... | fdcf5a8646638fb14ec11a1a3e35c4f8aa71b96c | 694,868 |
def aggregate_count(keyname):
"""
Straightforward sum of the given keyname.
"""
def inner(docs):
return sum(doc[keyname] for doc in docs)
return keyname, inner | 431896d1c8d8c1f773b684b5235919ce1728a8ce | 694,869 |
import collections
def group_trend_item_by_name(trends):
"""This method grouops a list of topics by its name, to avoid duplicates on the list.
Once the topic could be the same for different locations on brazil, we could group it as the same trend.
** It must receive a list of trending topics that was already clea... | 2d1b718d3d8f3bc765a3e31fb861cc3cd3ec2747 | 694,871 |
import hashlib
import os
def get_hash_of_dirs(directory):
"""
Recursively hash the contents of the given directory.
Args:
directory (str): The root directory we want to hash.
Returns:
A hash of all the contents in the directory.
"""
sha = hashlib.sha512()
if not os.path.e... | 249ce35549b972964654bc55ef6a5c3f1b13eb80 | 694,872 |
def degTodms(s):
"""
"""
#s = s.split(',')
num = s[0]
signo = s[1]
point = num.find('.')
d = num[:point-2]
m = num[point-2:]
m = float(m) / 60
numero = float(d) + m
if signo in ['S','W']:
return numero * (-1)
return numero | 3b035222ed4c26479dcb2fc59b7fa60708178e28 | 694,873 |
def new_version_entry(version):
"""
Returns a new entry for the version index JSON schema.
"""
return {
"allOf": [
{"properties": {"version": {"oneOf": [{"const": version}]}}},
{
"$ref": "https://raw.githubusercontent.com/deepset-ai/haystack/master/json-sc... | 7198e859b1634ebfbf181a4ff0a9f488f29afd32 | 694,875 |
import cProfile
def profilewrapper(func):
""" This is a decorator to profile a function.
Args:
func: function pointer
args: arguments to the function
kwargs: named arguments not defined in advance to be passed in to the function
"""
def profiler(*args, **kwargs):
profil... | d1962d5f496d064eedd61f2432fe67bd2bed4001 | 694,876 |
def fourier(framearray):
""" Fourier transforms all waves from array.
(Real values only)
:param framearray: array of waves (frames)
:return: array of FFT waves (spectrums)
"""
fourier_frame = []
for frame in framearray:
index = frame.make_spectrum()
fourier_frame.append(in... | 0f97ec9bd3f9ceda8d449a35623e9a2beea0ccda | 694,877 |
def start_bench_scenarios(wdis):
"""
Return all combinations of start, backups for all players in wdis.
"""
return [{
'starter': player,
'bench': [x for x in wdis if x != player]
} for player in wdis] | a50aa1c74333fdb1346e65493b0f742d69198bbc | 694,878 |
def get_media_stream(streams):
"""Returns the metadata for the media stream in an MXF file,
discarding data streams."""
found = None
for stream in streams:
# skip 'data' streams that provide info about related mxf files
if stream['codec_type'] == 'data':
continue
if f... | 563ef35c2be3e9787340d7527e7fd0f27b6db036 | 694,879 |
import re
import os
def get_relative_module_path(full_path: str) -> str:
""" Get relative module path """
full_path_without_suffix = re.sub(r'\.py$', '', full_path)
project_root = os.getcwd()
if project_root not in full_path_without_suffix:
raise FileNotFoundError('Cannot get relative module ... | 261f2862e7b747ceee10024fd6ecd0d5c0781038 | 694,880 |
def validate_iyr(issue_year: str) -> bool:
"""iyr (Issue Year) - four digits; at least 2010 and at most 2020."""
return len(issue_year) == 4 and int(issue_year) >= 2010 and int(issue_year) <= 2020 | b30614523c1633ecf40a4f68556dcc820e1aefef | 694,882 |
def drawAsInfinite(requestContext, seriesList):
"""
Takes one metric or a wildcard seriesList.
If the value is zero, draw the line at 0. If the value is above zero, draw
the line at infinity. If the value is null or less than zero, do not draw
the line.
Useful for displaying on/off metrics, such as exit c... | 8cb8273d57abca57600071101f6bd9b4a595ea38 | 694,883 |
import time
def download(item):
"""下载"""
print('download item ', item)
time.sleep(0.1)
return item | fdea636eb655e50a05585d334a196ad36ebaa585 | 694,884 |
def parentChainContainsCycle(term):
"""
Check if the chain of parents from an item contains a cycle by navigating along the sequence of parents
:param term: The ontology term to check
:type term: pronto.Term
:return: Whether the parent chain contains a cycle
:rtype: bool
"""
seen = set()
toProcessed = [term]... | 162267808cfbafee1c1c4d07467d1b50eddcb58f | 694,885 |
def _make_dict(my_tup, lang):
"""Make tuple in a dictionary so can be jsonified into an object."""
labels = ['comment_text', 'course_code', 'learner_classification', 'offering_city',
'offering_fiscal_year', 'offering_quarter',
'overall_satisfaction', 'stars', 'magnitude', 'nanos']
results = {key: val for ... | b7f010b4486889fe938a7a69513b0d5ca6e6cb86 | 694,886 |
def weighted_score(sim, size, ovl):
"""
Unite the similarity measures and make a score
return (2*sim + 1*size + 1*ovl) / 3.0
"""
return (2 * sim + 1 * size + 1 * ovl) / 3.0 | cbb39a914c08e4071e7f91364c81584ab132a04e | 694,888 |
import copy
import random
def ContractionRun(List, Size):
""" Function that runs 1 contraction iteration to find a MinCut starting from random choice of vertex pair"""
# Deepcopy required because List is a "nested list"
# Each item in List = [item1 = starting vertex, item2 = list of ending vertices]
InLis... | 219c74c32995d5847964dbba70ded3e19c55fc67 | 694,889 |
import re
def __static_case_string(list_cfg_regex, base_name):
"""
Convert the case of a string inside the base name of a file.
"""
for item in list_cfg_regex:
spec_chars = "\\?*+$.:;^|()[]{}"
for char in spec_chars:
item = item.replace(char, "")
regex = re.com... | ff2eda860a7fb97c9f9acfcb4bce5c4ce24ba601 | 694,892 |
import typing
import re
def split_sentences(text:str) -> typing.List[str]:
"""Split multiple sentences in one string into a list. Each item being a sentence.
Args:
text (str): Incoming string with multiple sentences.
Returns:
typing.List[str]: list of sentences.
"""
SEP_REGEX = r... | b748311fb4b9c0b5249782ceb140a9f64b17fa15 | 694,893 |
def get_apim_nv_secret(client, resource_group_name, service_name, named_value_id):
"""Gets the secret of the NamedValue."""
return client.named_value.list_value(resource_group_name, service_name, named_value_id) | 186030bca5285a82e133c8fc3acbf617d7247eb5 | 694,894 |
import numpy as np
def __dataset__pixelData__(self, index=0, storedvalue=False):
"""Returns pixel values in this DataSet.
Args:
index (int): pixelData return index'th image if dataset holds multiframe
data.
storedvalue (bool): True for get stored values; pixel values before LUT
... | 00e5d3a7f5b0a1d2219f677a36c137375b23f64b | 694,895 |
from socket import socket, AF_INET, SOCK_STREAM
def tcpConnect(proxy):
"""
TCP 三次握手
:param proxy:
:return:
"""
s = socket(AF_INET, SOCK_STREAM)
ip, port = proxy.split(':')
result = s.connect_ex((ip, int(port)))
return True if result == 0 else False | 426bfbab57e5cac96d3a12041663eab62c15f51b | 694,899 |
def extract_condition_disease(condition):
"""Extracts the disease encoded in the Condition resource.
Example resource:
{
...
"code":{
"coding":[
{
"code":"Yellow Fever",
"system":"http://hl7.org/fhir/v3/ConditionCode"
}
]
}
...
}
Args:
cond... | a3adcf89c58c5a95790e8c9ea9089ccd6e8818af | 694,900 |
import os
def list_subfloders(path='./', s_prefix=None):
"""List sub folders.
Subfolder name starts with given s_prefix ('_starting_with_certain_name_prefix')
"""
if s_prefix is None:
l_sf = [d for d in os.listdir(path) if os.path.isdir(d)]
else:
l_sf = [d for d in os.listdir(path)... | 2b564a91a557c6cb747fa86e08aef08ee452fae7 | 694,901 |
def bound_ros_command(bounds, ros_pos, fail_out_of_range_goal, clip_ros_tolerance=1e-3):
"""Clip the command with clip_ros_tolerance, instead of
invalidating it, if it is close enough to the valid ranges.
"""
if ros_pos < bounds[0]:
if fail_out_of_range_goal:
return bounds[0] if (bou... | 6d241ff973c088e1ea8a3b152f73c5ebfe951588 | 694,902 |
def get_train_na_percentages(train):
"""
Return a Series with the percentage of Na values per columns in train dataframe.
Must be called just after impute_train_missing_data().
Keyword arguments:
train -- the train dataframe
"""
na_cols_pctg_train = train[train.columns[train.isna().sum() > 0]].isna()... | 4de1d8f509a6a94a7ef73de3f17fb4d218791a7b | 694,903 |
def list_tags_to_dict_tags(tags):
"""
:type tags: typing.List[typing.Dict[str, str]]
:rtype: typing.Dict[str, str]
"""
return {
dct["Key"]: dct["Value"]
for dct in tags
} | f18d768fbe42fe3f18954874dcd251c63ec8c1a1 | 694,904 |
from datetime import datetime
import os
import json
def load_trend(file_dir, file_name="trend.json"):
"""Load and return trend list from JSON file.
Return list of summaries loaded from tests trend JSON file.
If the file is broken, empty or not found then create and return a new dummy trend.
Trend is ... | 1a8e0f4261e66fcac53c7763a29b66f392db33e8 | 694,905 |
def cut_array_to_table(data,collumns):
"""
Example I have 14 items and I need to cut them to rows of 7 items in each, i use the data array and parameter 7
"""
result = []
row = []
collumn_index = 0
for x in data:
oid, value = x[0].prettyPrint(), x[1].prettyPrint()
if value ==... | 704b72677b33bca3667bc3a4e22fd336ab228253 | 694,906 |
def backtrace3(node):
"""
assumes a node is (word, seg-label, node) etc
"""
hyp = [(node[0], node[1])]
while node[2] is not None:
node = node[2]
hyp.append((node[0], node[1]))
return hyp[-2::-1] | c2b50ea93acc9e7a1f1093a928a2c0492d1f537f | 694,907 |
def GetDocumentNumberForKeyword(keyword, inverted_index_table):
"""Gets the number of documents which contains the keyword."""
inverted_index = inverted_index_table.Get(keyword)
if not inverted_index:
return 0
return inverted_index.n_of_doc | 1bfea4ced59f86c520bd7224d1e1736a74686a5e | 694,908 |
import os
def get_extension(filename: str) -> str:
"""
Returns the extension from a filename / path
:param filename: filename or file path to the file which extension is required
:return: The files extension (with .)
"""
return os.path.splitext(filename)[1] | d9f62523a3d5775ee50e9a8f4cda60b6c4a67032 | 694,910 |
import json
def parse_node_file(filename):
"""
Parses a node file and creates the following variables:
graph = {child:{None}, child:{Parent1, Parent2}, ...}
prior = {node: [prior values]}
lambdas = {parent:{child1:lambda1, child2:lambda2, leak_node:lambda0}}
Those can then be used with the s... | 736786825bf9a3f44bc641b4ccdc1d2b46fe9816 | 694,911 |
import socket
def isip(id):
"""
is the string an ipv4 address?
"""
try:
socket.inet_aton(id)
return True
except:
return False | 258b0f09f5471ea276ee136ebfc7833c3e54fd04 | 694,912 |
def parameters_property(parameters):
"""Given the list of parameters this function constructs a property that simply
returns the given list. It doesn't provide a setter so that the list of parameters
cannot be overridden."""
def getter(self):
return parameters
return property(fget=getter) | 65aa43e925d07ace01705234bb4130251c50adda | 694,913 |
async def get_tz_offset(client, user_id):
"""
Retrieve the (seconds as an integer) time zone offset from UTC for a user.
Outputs an integer in the range [-43200, 43200]. (-12h, +12h.)
client: the client from the context object.
user_id: the human-opaque Slack user identifier.
"""
# https://... | 02bcfd0cb21cc35eb331951e77bca41d8a58722c | 694,915 |
def choose_date_slice(l_list,start_date,end_date):
""" Find start and end point of date in list """
first_slice = 0
last_slice = len(l_list)
l_list.sort()
if start_date != None:
count=0
while count < len(l_list):
if l_list[count][1] == start_date:
first_sl... | 5434b3ad1049f44dc312086e0e24b8685941b879 | 694,916 |
import numpy
def update_scale_moment_residual(smresidual, ssmmpsf, lhs, rhs, gain, mscale, mval):
""" Update residual by subtracting the effect of model update for each moment
"""
# Lines 30 - 32 of Algorithm 1.
nscales, nmoment, _, _ = smresidual.shape
smresidual[:, :, lhs[0]:lhs[1], lhs[2]:lhs[... | 3badfee6701bd2926ea65e7313158c6747ae9ed8 | 694,917 |
def test_jpeg(h, f):
"""JPEG data in JFIF format"""
if h[6:10] == 'JFIF':
return 'jpeg' | 18becefd465859dd353d55bd6d7af93070e9acea | 694,918 |
def feature_normalize(X, mean=None, sigma=None):
"""
returns a normalized version of X where
the mean value of each feature is 0 and the standard deviation
is 1. This is often a good preprocessing step to do when
working with learning algorithms.
the normalization is processed separately for ea... | 81342428799f5ac8d1815b54400e8eb4d7cc302b | 694,919 |
def periodic_ordering(amin, amax, bmin, bmax):
"""Figures out the order of the permutation that maps the minima and
maxima to their order, in canonical form (amin<amax, bmin<bmax if
possible).
Parameters
----------
amin : float
minimum of first range
amax : float
maximum of ... | ec81f998ea9abe2f23825f0de1890b6b2d62ba0e | 694,920 |
def strip_comments(string, markers):
"""
Complete the solution so that it strips all text that follows any of a set of comment markers passed in.
Any whitespace at the end of the line should also be stripped out.
:param string: a string input.
:param markers: list of characters.
:return: a new s... | 0ab980996897a7c42254a318ed325a9108033f97 | 694,921 |
def encode_schedule(schedule):
"""Encodes a schedule tuple into a string.
Args:
schedule: A tuple containing (interpolation, steps, pmfs), where
interpolation is a string specifying the interpolation strategy, steps
is an int array_like of shape [N] specifying the global steps, and pmfs is
an... | d660bc6826dcef2bbc5fbfca0eafaf2d72ab061f | 694,922 |
def ansi(num: int):
"""Return function that escapes text with ANSI color n."""
return lambda txt: f'\033[{num}m{txt}\033[0m' | 88297df114c3670a24e5ffa248d5756de09183cb | 694,923 |
from typing import Union
def compound_interest(
capital: float,
application_time: float,
fess: float,
*,
ret_dict=False,
ret_text=False,
) -> Union[tuple, dict, str]:
"""
Function to apply compound interest.
>>> from snakypy import helpers
>>> helpers.calcs.compoun... | a70b75c867fc1795e9f2491751b6a93e2bea92ec | 694,924 |
import torch
def _edge_error(y, y_target, mask):
"""
Helper method to compute edge errors.
Args:
y: Edge predictions (batch_size, num_nodes, num_nodes)
y_target: Edge targets (batch_size, num_nodes, num_nodes)
mask: Edges which are not counted in error computation (batch_size, num... | 900ce7bcf61a0f40cc9a36dd930a72c7d6f9cc51 | 694,926 |
import re
def get_url_jk_part(urlpart):
"""given a url substring containing the jk id from the job detail page - strip out the jk id and return it
string urlpart: a url substring containing the jk id
returns (str): the jk id param only e.g. jk=886c10571b6df72a which can be appended to a working job detail... | 97f1e5366f7ded9da84793fc39dbff965e3381d5 | 694,927 |
def is_angle_between(first_angle, middle_angle, second_angle):
"""Determines whether an angle is between two other angles.
Args:
first_angle (float): The first bounding angle in degrees.
middle_angle (float): The angle in question in degrees.
second_angle (float): The second bounding an... | e4dea61cfea1938e627edd46258d22dc2899aa70 | 694,928 |
def _PN_ROF(x,w,y, **kwargs):
""" Proximal Newton Method for the ROF (TV+L2) model """
#info = np.zeros(_N_INFO) # Holds [num iterations, gap]
#_call(lib.PN_ROF, x, w, y, info, np.size(x), kwargs['sigma'], ffi.NULL)
return 1 | 1dd967e84db48421e224369e13ebac997a3750e7 | 694,929 |
import torch
def binary_cross_entropy_cls(predictions: torch.Tensor, labels: torch.Tensor):
"""
https://pytorch.org/docs/stable/nn.html#torch.nn.BCELoss
Parameters
----------
predictions: (B, ) must be in [0, 1]
labels: (B, )
size_average
check_input
Returns
-------
"""
... | 6f1168613d4382a68ec303d67b2ca49eca4e2a70 | 694,930 |
def unique_nonzero(ngb):
"""Return unique non-zero values from vector."""
uni = list()
for n in ngb:
if n > 0 and n not in uni:
uni.append(n)
return uni | 88ab425a2e8fa85a733fcd0887772219beae0403 | 694,931 |
import argparse
def get_arguments() -> argparse.Namespace:
"""
parse all the arguments from command line inteface
return a list of parsed arguments
"""
parser = argparse.ArgumentParser(
description="generate ground truth arrays for boundary regression."
)
parser.add_argument(
... | 77b4d3498ba1f1b06607a26aeafe947d812a7f6a | 694,932 |
def list_to_string(the_list):
""" converts list of ints to string """
a = ''
for secondary_list in the_list:
a += ' '
for item in secondary_list:
a += str(item)
a += ','
a += ' '
return a | 6e50ff18cbdc29fdbe1153e208a8544ed7b7b0be | 694,935 |
def check_value(val, fields):
""" Checks if a value is valid for every field."""
valid_fields = []
for ranges in fields.values():
# if value is in any range of the field, then True, else False
valid_ranges = [(l <= val <= h) for (l, h) in ranges]
valid_fields.append(any(valid_ranges)... | d7530f8381df8e050ce407b972235a319dc5df36 | 694,936 |
def is_current_connection(context, connection):
"""Returns True if connection named name is the default connection"""
if context.pywbem_server_exists():
current_connection = context.pywbem_server
else:
current_connection = None
if current_connection and current_connection.name == connec... | 44cf36d4d389e9416ed469d76b63e46241c3eece | 694,937 |
def complement_interval(intervals, domain_min, domain_max):
"""Compute the union of intervals: domain - union(intervals).
We assume that intervals is sorted in increasing order.
"""
if len(intervals) == 0:
return [(domain_min, domain_max)]
complement = []
if intervals[0][0] > domain_min... | e569bffd89630336ca04847eae57e3a47588667a | 694,939 |
def corr():
"""Input aberration correction."""
return 'NONE' | ede5b1eef8efee46fb2700593768a03d88770a13 | 694,940 |
import os
import errno
def mtime(path, default=0):
"""
Returns the mtime of the file at the specified path. Returns default if
file does not exist. An OSError is raised if the file cannot be stat'd.
"""
try:
return os.stat(path).st_mtime
except OSError as e:
if e.errno == errno... | b9b62b272272a3c98b9a4a00d067f7c5c4e2fa94 | 694,941 |
def round_to_nearest(number, nearest=5):
"""@see https://stackoverflow.com/questions/2272149/round-to-5-or-other-number-in-python"""
return int(nearest * round(float(number) / nearest)) | 6fdb79ec92d54f12c4e3cc2675e762e57aee737a | 694,942 |
import os
def interactive_testing_requested() -> bool:
"""
Certain tests are only useful when run interactively, and so are not regularly run.
These are activated by this funciton returning True, which the user requests by
setting the environment variable `PYTORCH3D_INTERACTIVE_TESTING` to 1.
"""
... | 4615b1e2254d60c303a4fedbda7f185ec6b4a731 | 694,943 |
def get_supervisor_info(self):
"""Return data for Supervisor
This method return a coroutine.
"""
return self.send_command("/supervisor/info", method="get") | 759a74c5e786d329ea8bfdf2c5cb677823ee047e | 694,944 |
def to_dero(value):
"""Convert number in smallest unit to number in dero"""
return value/10**12 | b4a48ca750ec9f40c826d5dec3eb6209b54ccf24 | 694,945 |
def get_absolute_import_name(dir_path: str, import_name: str) -> str:
"""Joins a relative import path with an import name."""
return f'{dir_path}:{import_name}' | 5cebf043df64b2f0160f5d7230c2a1eca94ce7a8 | 694,946 |
def install_start_end_marker(name: str, length: float) -> str:
"""Method to add start and end marker to the lattice.
Parameters
----------
name : str
lattice name
length : float
length of the lattice
Returns
-------
str
MADX install string.
"""
# define ... | 58dd4a789d4a12efdc454741ac8c9cafc40e22fe | 694,947 |
def trips_frequencies(gtfs):
"""
Get the frequency of trip_I in a particular day
"""
query = (
" SELECT q1.stop_I as from_stop_I, q2.stop_I as to_stop_I, q1.trip_I as trip_I, COUNT(*) as freq FROM"
" (SELECT * FROM stop_times) q1,"
" (SELECT * FROM stop_times) q2"
" W... | 6c9e4fe9f50cca8f345c866b83e33945ba4bfaf2 | 694,948 |
def dictfetchall(cursor):
"""
Return all rows from a cursor as a dict
"""
columns = [col[0] for col in cursor.description]
return [dict(zip(columns, row)) for row in cursor.fetchall()] | f9e7c5dfd23358db7b4cfc9417185ac70abc5b3c | 694,949 |
import torch
def remove_edge_cells(mask: torch.Tensor) -> torch.Tensor:
"""
Removes cells touching the border
:param mask: (B, X, Y, Z)
:return: mask (B, X, Y, Z)
"""
left = torch.unique(mask[:, 0, :, :])
right = torch.unique(mask[:, -1, :, :])
top = torch.unique(mask[:, :, 0, :])
... | c5370d9f8519ba4e0b76c3069f72601f3c0e90f4 | 694,952 |
def strategy(history, memory):
"""
Orannis's punitive detective:
Cooperate but when the other player defects, cooperate one more turn to
see if they defect again. If they do, defect for 10 turns.
Cooperate twice more and if they defect the second time, defect forever.
memory is a tu... | 6d3b4a1b7029a8eb43eac935531603cff7c865dc | 694,954 |
import os
def parent_dir(path):
"""
Return the parent of a directory.
"""
return os.path.abspath(os.path.join(path, os.pardir)) | 3c65af3ee7ccaef0b142bdddb6649db321b32f18 | 694,955 |
from typing import List
import os
def find_validate_dirs(base_dirs: List[str]) -> List[str]:
"""Construct a list of validation directories by searching for
validate.sh scripts."""
all_validation_dirs = []
for base in base_dirs:
for root, _, files in os.walk(base):
if 'validate.sh'... | f8c81a226df1b2f7a0ab882e6ba463a630763b33 | 694,956 |
def main(*, left, right):
"""entrypoint function for this component
Usage example:
>>> main(left = pd.Series(
... {
... "2019-08-01T15:20:12": 1.2,
... "2019-08-01T15:44:12": None,
... "2019-08-03T16:20:15": 0.3,
... "2019-08-05T12:00:3... | 4656d789a5a705fee7d6e552a64542e22ab1e73e | 694,957 |
def _extract_jinja_frames(exc_tb) -> str:
"""
Extract all the frames in the traceback that look like jinja frames
Returns:
A multiline string with a formatted traceback of all the Jinja
synthetic frames or an empty string if none were found.
"""
lines = []
while exc_tb:
... | 170ede7e5fed4292c9e375555b6152ea4c8927bd | 694,960 |
import mmap
def get_lines(file_path):
"""
return an integer representing the number of lines
in the given file
:param file_path: Path to the given file
:return: The number of lines in a file
"""
with open(file_path, 'r+') as file:
line_count = 0
buffer = mma... | 9f135ded40890a62fd99a24ee72943d12b21f6e8 | 694,961 |
def get_log_file_data(log_file):
"""
get the resilient circuits log file
:param log_file:
:return: all lines for the log file
"""
with open(log_file, "r") as f:
return f.readlines() | 8eb7e451ab4c0e388703f285e176f8453fe8a8f2 | 694,962 |
import subprocess
def read(id, loc):
"""
Read from window id's loc file
runs
9p read acme/id/loc
returns
utf-8 encoded string with contents of acme/id/loc
"""
s = subprocess.check_output(['9p', 'read', 'acme/'+str(id)+'/'+loc])
return s.decode('utf-8') | bf9cb36915d12600dbdea8b3ab7da3f2e05b6fd7 | 694,963 |
def load_data(filename):
"""Open a text file of numbers & turn contents into a list of integers."""
with open(filename) as f:
lines = f.read().strip().split('\n')
return [int(i) for i in lines] | 2baf679166eb1ee36f2b36c3e18f4f1d6a5272d9 | 694,964 |
def create_help(header, options):
"""Create formated help."""
return "\n" + header + "\n" + \
"\n".join(map(lambda x: " " + x, options)) + "\n" | 6643a5de137e22a5f00fd62ef0f27745bb60a8ad | 694,965 |
def get_first(*values, condition=None, default=None):
"""
Permet de renvoyer le premier élément qui valide la condition parmi l'ensemble des valeurs
:param values: Liste d'éléments
:param condition: Fonction de filtrage conditionnel (non nul par défaut)
:param default: Valeur par défaut si non trouv... | 5109dc7b6ee399e6ff96e08c40d813569e7d0f6b | 694,966 |
import math
def _compute_page(offset: int, items_per_page: int) -> int:
"""Compute the current page number based on offset.
Args:
offset (int): The offset to use to compute the page.
items_per_page (int): Nimber of items per page.
Returns:
int: The page number.
"""
return... | 94a0a0c18b8090cf0a1a8ac3eacdc2bcff6643b6 | 694,967 |
def dim_returns(k, inverse_scale_factor):
"""
A simple utility calculation method.
Given k items in posession return the benefit of a K + 1th item given some
inverse scale factor.
The formula used is utility = 100% if no items are in posession or
utility = 1 / inverse_scale_factor * (k + 1)
... | 05d8b9cfe690737fc03b2d2fa9410bafae06bd2b | 694,968 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.