content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def get_tag_name(tag):
"""
Extract the name portion of a tag URI.
Parameters
----------
tag : str
Returns
-------
str
"""
return tag[tag.rfind("/") + 1:tag.rfind("-")] | e24f0ae84ed096ec71f860291d1e476c75bf8370 | 704,781 |
def cbar(ni, nj, resources, commcost):
""" Average communication cost """
n = len(resources)
if n == 1:
return 0
npairs = n * (n - 1)
return 1. * sum(commcost(ni, nj, a1, a2) for a1 in resources.values() for a2 in resources.values()
if a1 != a2) / npairs | b215de30bcb019e2299edbb61591b7a1c129c58b | 704,782 |
def imap_any(conditions):
"""
Generate an IMAP query expression that will match any of the expressions in
`conditions`.
In IMAP, both operands used by the OR operator appear after the OR, and
chaining ORs can create very verbose, hard to parse queries e.g. "OR OR OR
X-GM-THRID 111 X-GM-THRID 22... | de4ef1680cd2c8370d82640ff95186ed3ea81202 | 704,783 |
def format_sources(sources):
"""
Make a comma separated string of news source labels.
"""
formatted_sources = ""
for source in sources:
formatted_sources += source["value"] + ','
return formatted_sources | f9f86f11e4dfe9ecd3fbbd5e14d3ca750a4e1a5a | 704,784 |
def _get_file_url_from_dropbox(dropbox_url, filename):
"""Dropbox now supports modifying the shareable url with a simple
param that will allow the tool to start downloading immediately.
"""
return dropbox_url + '?dl=1' | fe0256ae747826dbbe5ac3c3a4afa42e0584699a | 704,785 |
def launch_coef_scores(args):
"""
Wrapper to compute the standardized scores of the regression coefficients, used when computing the number of
features in the reduced parameter set.
@param args: Tuple containing the instance of SupervisedPCABase, feature matrix and response array.
@return: The stan... | 02423ef564b55dfcc37bddadcc813edffba05795 | 704,786 |
def create_link(url):
"""Create an html link for the given url"""
return (f'<a href = "{url}" target="_blank">{url}</a>') | 77a5375369be2be140a69a4521c50a92cee2d5ed | 704,787 |
def cummean(x):
"""Return a same-length array, containing the cumulative mean."""
return x.expanding().mean() | b5a35c56cb78e0588dd5be64a75384c4cd81ccb5 | 704,788 |
def get_syntax_errors(graph):
"""List the syntax errors encountered during compilation of a BEL script.
Uses SyntaxError as a stand-in for :exc:`pybel.parser.exc.BelSyntaxError`
:param pybel.BELGraph graph: A BEL graph
:return: A list of 4-tuples of line number, line text, exception, and annotations p... | a0f3493b88b081de3613397c997d71dabdae78be | 704,789 |
def is_valid_combination( row ):
"""
Should return True if combination is valid and False otherwise.
Test row that is passed here can be incomplete.
To prevent search for unnecessary items filtering function
is executed with found subset of data to validate it.
"""
n = len(row)
if ... | c0758c3d30debbd3fc3d5f07d6728c23bfb71145 | 704,790 |
import os
def get_out_name(subdataset_name_tuple, out_ext=""):
"""
Get output file name for sub dataset
Takes tuple with (subdataset name, description)
"""
subdataset_name = subdataset_name_tuple[0]
outname = os.path.split(subdataset_name)[-1]
outname = outname.replace(".xml","")
out... | d55b77546e579f1f0887f4e88df2ec9825991c9f | 704,791 |
def get_callback(request, spider):
"""Get request.callback of a scrapy.Request, as a callable."""
if request.callback is None:
return getattr(spider, 'parse')
return request.callback | a1f62822d812bebdeabafa14edda4462949657d8 | 704,793 |
import requests
def veryrandom(msg, min=1, max=6, base=10, num=1):
"""Los datos generados por veryrandom provienen de random.org, lo cual
es una garantía adicional de la aleatoriedad de los resultados. Se
obtendrá un número aleatorio entre los 2 definidos, ambos inclusive.
"""
url = 'http://www.ra... | 75320750423e060ba117ed8ce6bfb84a02d16411 | 704,794 |
from math import log
def calcShannonEnt(dataSet):
"""
计算香农熵,用于判断划分
Parameters
----------
dataSet:数据集(可能是原始数据集,有可能是划分子集)
Returns:数据集的信息熵,根据分类标签信息确定
-------
"""
numEntries = len(dataSet) # 数据总量
labelCounts = {} # 创建一个数据字典,用来计数各个类别
for featVec in dataSet.values: # 每次取一行
... | bdade097a799feff0cb41eb15b3438ca1e088983 | 704,795 |
def merge_values(list1, list2):
"""Merge two selection value lists and dedup.
All selection values should be simple value types.
"""
tmp = list1[:]
if not tmp:
return list2
else:
tmp.extend(list2)
return list(set(tmp)) | 9412dd28c6110bc6df70ac7d563cb19d1211beb8 | 704,798 |
import argparse
def parse_arguments():
"""Parse the command line arguments.
Returns:
Parsed arguments.
"""
parser = argparse.ArgumentParser(description='tail for BAMs')
parser.add_argument(
'filenames',
help='BAMs on which to perform the tail operation',
nargs='*',... | 4c09fecf32bcc5a4d016d012a87996f5b08b765f | 704,799 |
def format_heading(level, text):
"""Create a heading of <level> [1, 2 or 3 supported]."""
underlining = ['=', '-', '~', ][level-1] * len(text)
return '%s\n%s\n\n' % (text, underlining) | 6b8caaa134ddc32666a4d7ce62a775d6ffda7425 | 704,800 |
def get_new_size_zoom(current_size, target_size):
"""
Returns size (width, height) to scale image so
smallest dimension fits target size.
"""
scale_w = target_size[0] / current_size[0]
scale_h = target_size[1] / current_size[1]
scale_by = max(scale_w, scale_h)
return (int(current_size[0]... | e0b42eab3d35ba5c662282cab1ffa798327ad92a | 704,801 |
def get_name_component(x509_name, component):
"""Gets single name component from X509 name."""
value = ""
for c in x509_name.get_components():
if c[0] == component:
value = c[1]
return value | 6a473a96b99daa6f69fd6aac45f2594af933d4bd | 704,802 |
def song_line(line):
"""Parse one line
Parameters
----------
line: str
One line in the musixmatch dataset
Returns
-------
dict
track_id: Million song dataset track id, track_id_musixmatch:
Musixmatch track id and bag_of_words: Bag of words dict in
{word: cou... | 2108dfa037aa6293a0b3111a97c354e62c0dd2a5 | 704,803 |
def remove_st_less_than(dataframe, column='ST', less_than=0.001):
"""
Remove any entry with an ST less than specified
Args:
dataframe (pandas.Dataframe): dataframe containing sensitivity analysis output
column (str): Column name, default is 'ST'
less_than (float): Remove anything le... | 2ba052004c436f8d527ab9b5bc3e76c90aa5dce9 | 704,804 |
def count_positives_sum_negatives2(arr):
"""
More space efficient, but not as concise as above
"""
if not arr:
return arr
count = 0
total = 0
for num in arr:
if num > 0:
count += 1
else:
total += num
return [count, total] | f1f8de28dcf6669d49044a43e6a8603f0da01577 | 704,805 |
def fact(n):
"""Return the factorial of the given number."""
r = 1
while n > 0:
r = r * n
n = n - 1
return r | 7bdcdc759b49a9cd72f7bf3f12a18fc03ce50668 | 704,806 |
from datetime import datetime
import os
from shutil import copyfile
def create_logdir(directory, algorithm, env_name, config_path):
"""
Create a directory inside the specified directory for
logging experiment results and return its path name.
Include the environment name (Sharpe, etc.) in the directo... | 9b1e188e2925dec49dad4c31bba8eec9ab0ddbd0 | 704,807 |
def list_column(column, original_name):
"""Get all non nan values from column."""
if original_name == 'original_formatted':
list_filled = [[x for x in row if str(x) != 'nan'] for row in column]
else:
list_filled = [[_] for _ in column]
return list_filled | ae8b900cdcf3e59ff4ede3b3dc0321d93ea07253 | 704,809 |
def apply_functions(lst, functions):
"""
:param lst: list of values
:param functions: list of functions to apply to each value.
Each function has 2 inputs: index of value and value
:return: [func(x) for x in lst], i.e apply the respective function to each
of the values
"""
assert len(ls... | 679a2219008e438249e1227d5aab6529019c497c | 704,811 |
def location_normalize(location):
"""
Normalize location name `location`
"""
#translation_table = dict.fromkeys(map(ord, '!@#$*;'), None)
def _remove_chars(chars, string):
return ''.join(x for x in string if x not in chars)
location = location.lower().replace('_', ' ').replace('+', ' ')... | 4b8aaec23ef9763bc02fd4d3635ba930f8c3dcea | 704,812 |
def dict_is_test(data):
"""helper function to check whether passed argument is a proper :class:`dict` object describing a test.
:param dict data: value to check
:rtype: bool
"""
return (
isinstance(data, dict)
and "type" in data
and data["type"] == "test"
and "id" in... | 320b47f8f41f42f6a6554741c9b2de38b370605a | 704,813 |
from typing import Set
def GetZonesInRegion(region: str) -> Set[str]:
"""Returns a set of zones in the region."""
# As of 2021 all Azure AZs are numbered 1-3 for eligible regions.
return set([f'{region}-{i}' for i in range(1, 4)]) | e539662604eb5da2583630844dd54d11d266c827 | 704,814 |
def compare_3PC_keys(key1, key2) -> int:
"""
Return >0 if key2 is greater than key1, <0 if lesser, 0 otherwise
"""
if key1[0] == key2[0]:
return key2[1] - key1[1]
else:
return key2[0] - key1[0] | d134eaaa4ef8f218164be4e5bc6fced01c3de7eb | 704,815 |
def _GetMSBuildToolSettings(msbuild_settings, tool):
"""Returns an MSBuild tool dictionary. Creates it if needed."""
return msbuild_settings.setdefault(tool.msbuild_name, {}) | 3a2cb3e9c8910a6901be0937be18aac00d532e2b | 704,816 |
import struct
def float_2_bytes(f, is_little_endian=False):
"""
:param f:
:param is_little_endian:
:return:
"""
# 小端数据返回
if is_little_endian:
return struct.pack('<f', f)
# 大端数据返回
return struct.pack('>f', f) | cd13cfc7179baf28cda669b2c6fccdce58c63730 | 704,817 |
import requests
def load_SMI_data_from_Helmholtz():
"""
Downloading SMI topsoil data from helmholtz website
"""
url = "https://www.ufz.de/export/data/2/237851_SMI_L02_Oberboden_monatlich_1951_2018_inv.zip" # noqa: E501
response = requests.get(url)
return response | 854f6b2f398764b7afc89cc3b9ca3b95b2d9a345 | 704,818 |
import os
def find_wfss_config_filename(pathname, instrument, filtername, mode):
"""Construct the name of the WFSS configuration file given instrument parameters
Parameters
----------
pathname : str
Path where the configuration files are located
instrument : str
Instrument name (... | eb0b7cca8e0715d28dc16bd90b90d357ea612cba | 704,819 |
def convert_to_date(col):
"""Convert datetime to date."""
return col.date() | c6ac8febf4751e8f2c2c27fc740de286f2870cbe | 704,820 |
import re
from typing import Counter
def perfect_match(_clipped, _seq, offset = 0, min_nt = 2):
"""
perfect match between clipped reads and breakend sequence
for whole length
min_nt : minimal nt match is better to be larger than 2,
1 nt match is 25% change by random,
2 nt match is 0.0... | 806c0b86d3f97b71c191a2c95fb77ef16bf804e2 | 704,821 |
import argparse
def get_input_args():
"""
Retrieves and parses the command line arguments provided by the user when
they run the program from a terminal window. If the user fails to provide
some or all of the arguments, then the default values are used for the
missing arguments.
This function ... | 830f31adf1770ebcfaeb6645ce606c758f38bd0f | 704,822 |
import torch
def accuracy(output, target):
"""Computes the accuracy over the top predictions"""
with torch.no_grad():
batch_size = target.size(0)
_, preds = torch.max(output.data, 1)
correct = (preds == target).sum().item()
return correct/batch_size | 8f4dfde0e00f12d889b403265d50a379930ba3c8 | 704,823 |
from bs4 import BeautifulSoup
def get_absolute_url(body_string: str):
"""Get absolute manga mangadex url"""
parser = BeautifulSoup(body_string, 'html.parser')
for link_elements in parser.find_all('link'):
# aiming for canonical link
try:
rel = link_elements.attrs['rel']
... | 35ca71dba04c243ab7c4cfa4893326ddeb480336 | 704,824 |
from typing import Any
def isstring(var:Any, raise_error:bool=False) -> bool:
"""Check if var is a string
Args:
var (str): variable to check
raise_error (bool, optional): TypeError raised if set to `True`. Defaults to `False`.
Raises:
TypeError: raised if var is not string
R... | 897c43539099c3d0b9b38abccce88869a90b9d9e | 704,826 |
def placeholder(value, token):
""" Add placeholder attribute, esp. for form inputs and textareas """
value.field.widget.attrs["placeholder"] = token
return value | 16bb46a6e92c3a59972589ed28315e681a7580f3 | 704,827 |
def _cs_count_top_bottom(fragments):
"""Counting: top and bottom of the entire core sample"""
cs_top, cs_bottom = 1e10, 0
for fragment in fragments:
cs_top = min(cs_top, float(fragment['top']))
cs_bottom = max(cs_bottom, float(fragment['bottom']))
return cs_top, cs_bottom | 3b9a98993a837ff7c08980f644abbb6aad13f908 | 704,828 |
def get_index_from_filename(
file_name: str
) -> str:
"""
Returns the index of chart from a reproducible JSON filename.
:param file_name: `str`
The name of the file without parent path.
:returns: `str`
The index of the chart (e.g., 1) or an empty string.
"""
assembled_ind... | 2cddcbcd9bf5079d58c75f19b5d2bf5b44ded173 | 704,829 |
def notas(*num, sit=False):
"""
Essa função cria um dicionário que guarda várias informações sobre o boletim de um aluno
:param num: lista de notas do aluno
:param sit: situação do aluno (aprovado, reprovado, recuperação)
:return: retorna o dicionário completo
"""
boletim = {}
boletim['Q... | a154d39be15018ce764e71c7bc97d9b4b25575df | 704,830 |
def summarize(text):
""" Summarizes some text
"""
if len(text) > 20:
summary = text[0:10] + " ... " + text[-10:]
else:
summary = text
summary = summary.replace("\n", "\\n")
return summary | 5c37f7a50e2b533bf3e05b598ce68b2c4de88fe1 | 704,831 |
def sexastr2deci(sexa_str):
"""Converts as sexagesimal string to decimal
Converts a given sexagesimal string to its decimal value
Args:
A string encoding of a sexagesimal value, with the various
components separated by colons
Returns:
A decimal value corresponding to the sexagesimal... | 46a9d8752b05b1579ecc2b85d94c28613a08ab3c | 704,832 |
def reverb2mix_transcript_parse(path):
"""
Parse the file format of the MLF files that
contains the transcripts in the REVERB challenge
dataset
"""
utterances = {}
with open(path, "r") as f:
everything = f.read()
all_utt = everything.split("\n.\n")
for i, utt in enumerate... | c8a1aa0c8a4d0dec6626cf8e9d2491336ee42d5a | 704,833 |
def extract_qa_bits(qa_band, start_bit, end_bit):
"""Extracts the QA bitmask values for a specified bitmask (starting
and ending bit).
Parameters
----------
qa_band : numpy array
Array containing the raw QA values (base-2) for all bitmasks.
start_bit : int
First bit in the bit... | 523dc1ee149af5c5e9a494b5fe3a3c14bc3186d2 | 704,834 |
import logging
def combine_ecgs_and_clinical_parameters(ecgs, clinical_parameters):
"""
Combines ECGs and their corresponding clinical parameters
:param ecgs: List of ECGs
:param clinical_parameters: Corresponding clinical parameters
:return: Medical data for each patient including ECGs and th... | 91ca17f62ff36776980a74ecd5334ae9a55ade18 | 704,835 |
def get_question_types(container):
""" SELECTOR FOR RETURNING QUESTION TYPES """
return container.keys() | 0c667e893323c106319038d19f333d233a5d1e07 | 704,836 |
import requests
import urllib3
def uploader(dict_in):
"""Post the global dictionary to the server
This function contains a post request to the flask server. The global
dictionary in the patient GUI that saved all the information to be upload
will be posted. This function will also catch the exception... | a454bb7e0523e48d851efb2a46d877aea12dd38e | 704,837 |
def architecture_is_32bit(arch):
"""
Check if the architecture specified in *arch* is 32-bit.
:param str arch: The value to check.
:rtype: bool
"""
return bool(arch.lower() in ('i386', 'i686', 'x86')) | a0cfaef4b03bc8cf335f0d19a3e46457db7574a9 | 704,838 |
def old_func4(self, x):
"""Summary.
Further info.
"""
return x | 7417bc8b52ec36a510a73cc8669a92b3603e6169 | 704,839 |
def generate_config(context):
""" Entry point for the deployment resources. """
resources = []
project_id = context.env['project']
bucket_name = context.properties.get('name') or context.env['name']
# output variables
bucket_selflink = '$(ref.{}.selfLink)'.format(bucket_name)
bucket_uri = ... | 5ceca9cf90b5435368ffdb9bdcf1532eec31ec64 | 704,840 |
def tw_mock():
"""Returns a mock terminal writer"""
class TWMock:
WRITE = object()
def __init__(self):
self.lines = []
self.is_writing = False
def sep(self, sep, line=None):
self.lines.append((sep, line))
def write(self, msg, **kw):
... | a843503d3e360ed4412a020a4ec37f302ec4edaa | 704,841 |
def matsubtraction(A,B):
"""
Subtracts matrix B from matrix A and returns difference
:param A: The first matrix
:param B: The second matrix
:return: Matrix difference
"""
if(len(A)!=len(B) or len(A[0])!=len(B[0])):
return "Subtraction not possible"
for i in range(len(... | e10ca0e218d7995c0052928b4be96c2bae8959e7 | 704,842 |
from typing import OrderedDict
def order_keys(order):
"""
Order keys for JSON readability when not using json_log=True
"""
def processor(logger, method_name, event_dict):
if not isinstance(event_dict, OrderedDict):
return event_dict
for key in reversed(order):
... | b3ddc250dc6a7e76b8d980ab81fbf4a9de3d6268 | 704,843 |
import os
def get_backend():
"""
Returns the currently used backend. Default is tensorflow unless the
VXM_BACKEND environment variable is set to 'pytorch'.
"""
return 'pytorch' if os.environ.get('VXM_BACKEND') == 'pytorch' else 'tensorflow' | ae93dcf95c5712189d603a9a12f32298c32937b5 | 704,844 |
def mpls_label_group_id(sub_type, label):
"""
MPLS Label Group Id
sub_type:
- 1: L2 VPN Label
- 2: L3 VPN Label
- 3: Tunnel Label 1
- 4: Tunnel Label 2
- 5: Swap Label
"""
return 0x90000000 + ((sub_type << 24) & 0x0f000000) + (label & 0x00ffffff) | f0235d1cd8baaf601baf0db43b81417d3d5823ac | 704,845 |
import logging
def compare_results(out_dict, known_problems_dict, compare_warnings):
"""Compare the number of problems and warnings found with the allowed
number"""
ret = 0
for key in known_problems_dict.keys():
try:
if out_dict[key]['problems'] > known_problems_dict[key]['problems... | 96cde5d5202d62a7cf135eb6af9b84bee64e22aa | 704,846 |
import torch
def get_spin_interp(zeta: torch.Tensor) -> torch.Tensor:
"""Compute spin interpolation function from fractional polarization `zeta`."""
exponent = 4.0 / 3
scale = 1.0 / (2.0 ** exponent - 2.0)
return ((1.0 + zeta) ** exponent + (1.0 - zeta) ** exponent - 2.0) * scale | b1abced09aead7394be773d93d59a621cda98d14 | 704,847 |
def word_show(vol, guess, store):
"""
param vol: str, the word from def random_word
param guess: str, the letter user guessed
param store: str, the string showing correct letters user guessed
return: str, answer
"""
answer = ''
if guess == '':
for i in vol:
answer += ... | 65178dda52c61abbae682878dcf2439f20e51b5f | 704,848 |
def _gradual_sequence(start, end, multiplier=3):
"""Custom nodes number generator
The function gives the list of exponentially increase/decrease
integers from both 'start' and 'end' params, which can be later used as
the number of nodes in each layer.
_gradual_sequence(10, 7000, multiplier=5) gives ... | 8b42931600cb14b84621f6619ef695f1adee641c | 704,849 |
import time
def timeit(func):
"""calculate time for a function to complete"""
def wrapper(*args, **kwargs):
start = time.time()
output = func(*args, **kwargs)
end = time.time()
print('function {0} took {1:0.3f} s'.format(
func.__name__, (end - start) * 1))
... | 13a86c9475ce547a7b5e7e54ad7373f833920b41 | 704,850 |
def removeDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
if len(nums) == 0:
return 0
j = 0
len_n = len(nums)
for i in range(len_n):
if nums[j] != nums[i]:
nums[j + 1] = nums[i]
j += 1
return j + 1 | 3020be29ad6499dfcb1dcfae6a09b91a11ccfc38 | 704,851 |
def string2token(t,nl,nt):
"""
This function takes a string and returns a token. A token is a tuple
where the first element specifies the type of the data stored in the
second element.
In this case the data types are limited to numbers, either integer, real
or complex, and strings. The types... | 23fd5da01a49076b1fcf474fbe1047329ad7471a | 704,852 |
def get_div(integer):
"""
Return list of divisors of integer.
:param integer: int
:return: list
"""
divisors = [num for num in range(2, int(integer**0.5)+1) if integer % num == 0]
rem_divisors = [int(integer/num) for num in divisors]
divisors += rem_divisors
divisors.append(integer)
... | 4c40a2b2da1d9681c1d7ca69a53975dd27c7bdb8 | 704,853 |
def ifuse(inputs):
"""Fuse iterators"""
value, extent = 0, 1
for i, ext in inputs:
value = value * ext + i
extent = extent * ext
return (value, extent) | 42c65ec62e637b668125ed27aad517d3301a7aff | 704,854 |
from typing import get_origin
def is_dict_type(tp):
"""Return True if tp is a Dict"""
return (
get_origin(tp) is dict
and getattr(tp, '_name', None) == 'Dict'
) | 3b9992b7b131e936472d4d0e2994ac476f0d0f76 | 704,855 |
def sum_up_validation_dataset(dataset, batch_size, repeat=True,
number_of_repetitions=0):
"""Define how the validation dataset is suppose to behave during training.
This function is applied to the validation dataset just before the actual
training process. The characteristics... | 9bab85eba802d5198bfd39bc42bd2fae5209d356 | 704,856 |
import webbrowser
def getbrowser():
"""
Get the name of the browser currently being used
"""
# Try to find the browser
try:
# Get the browser name
webbrowser.get(using=None)
# Catch an error
except RuntimeError:
# Return nothing
return None | cc74f7db8cf82b32516a0f3b462ba91b7c48b21b | 704,857 |
def _is_large_prime(num):
"""Inefficient primality test, but we can get away with this simple
implementation because we don't expect users to be running
print_fizzbuzz(n) for Fib(n) > 514229"""
if not num % 2 or not num % 5:
return False
test = 5
while test*test <= num:
if not nu... | 090b641872d8d25d55e8f32296e3893f59518308 | 704,858 |
def cleanup_code(content: str):
"""Automatically removes code blocks from the code."""
# remove ```py\n```
if content.startswith('```') and content.endswith('```'):
return '\n'.join(content.split('\n')[1:-1])
# remove `foo`
return content.strip('` \n') | a026668f01e1641618c5b25b06396516410dbe1e | 704,859 |
def ext_s(variable, value, substitution):
"""ext_s is a helper function for eq, without checking for duplicates or
contradiction it adds a variable/value pair to the given substitution.
`unify` deals with all of the related verification.
@param variable: A LogicVariable
@param value: A value that c... | bced042fc8ea5882d4dc901e3b7df94c9b0d0893 | 704,860 |
import re
def _include_matcher(keyword="#include", delim="<>"):
"""Match an include statement and return a (keyword, file, extra)
duple, or a touple of None values if there isn't a match."""
rex = re.compile(r'^(%s)\s*%s(.*)%s(.*)$' % (keyword, delim[0], delim[1]))
def matcher(context, line):
... | b5f57a8f007870952810a591bb8e15c86af467b1 | 704,861 |
import operator
def lcs(l1, l2, eq=operator.eq):
"""Finds the longest common subsequence of l1 and l2.
Returns a list of common parts and a list of differences.
>>> lcs([1, 2, 3], [2])
([2], [1, 3])
>>> lcs([1, 2, 3, 3, 4], [2, 3, 4, 5])
([2, 3, 4], [1, 3, 5])
>>> lcs('banana', 'baraban')... | 4b5d3cb9911a6834c006e78f7b40061695c464e2 | 704,863 |
def calc_sparsity(optimizer, total_params, total_quant_params):
"""
Returns the sparsity of the overall network and the sparsity of quantized layers only.
Parameters:
-----------
optimizer:
An optimizer containing quantized model layers in param_groups[1]['params'] and non-quantized... | 92ee924239ee8d7ac97aebba2958671043aa2d89 | 704,864 |
def swapKeys(d,keySwapDict):
"""
Swap keys in dictionary according to keySwap dictionary
"""
dNew = {}
for key, keyNew in keySwapDict.iteritems():
if key in d:
dNew[keyNew] = d[key]
for key in d:
if key not in keySwapDict:
dNew[key] = d[key]
return dN... | 0d8917e224574ee0bf682fed10d367f3a5d2bc2f | 704,865 |
import torch
def getLayers(model):
"""
get each layer's name and its module
:param model:
:return: each layer's name and its module
"""
layers = {}
root = ''
def unfoldLayer(model, root):
"""
unfold each layer
:param model: the given model or a single layer
... | e1120460b35fa49fe8ad43cc9ce606c1d217a584 | 704,866 |
def buscaVizinhos(matrizCapacidades):
"""Função para buscar os vizihos de cada vertice"""
vizinhos = {}
for v in range(len(matrizCapacidades)):
vizinhos[v] = []
for v, fluxos in enumerate(matrizCapacidades):
for vizinho, fluxo in enumerate(fluxos):
if fluxo > 0:
... | 1e9ace4be94d80ae2637689b3d25ee1116714888 | 704,867 |
import json
import os
import shutil
def _check_json(out_file, status, hold_file):
"""Function: _check_json
Description: Private function for file_check function.
Arguments:
(input) out_file -> Path and file name of output file.
(input) status -> Status of check.
(input) hold_f... | 616ef16200e07975cdaedbebfa3fcf21746c367b | 704,868 |
def _prefAdj(coupling, leg):
"""Prefactor for the creation of an adjoint
Only implemented for regular three-legged tensors with an (in, in, out)
flow and their adjoints at the moment.
"""
if len(coupling) != 1:
raise NotImplementedError("Only for three-legged tensors")
flow = tuple(c[1... | e2889badba0cef27c4ce8c51ed14bda71524c3ec | 704,869 |
import socket
import logging
def get_hostname():
"""
:return: safely return the hostname
"""
hostname = "<Host Undetermined>"
try:
hostname = socket.gethostname()
except Exception as e:
logging.error(f"Could not get hostname.\nException: {e}")
return hostname | d5420b275c336b1295b16216a473557a24d54a61 | 704,871 |
def dict_get(d, key, default=None):
""":yaql:get
Returns value of a dictionary by given key or default if there is
no such key.
:signature: dict.get(key, default => null)
:receiverArg dict: input dictionary
:argType dict: dictionary
:arg key: key
:argType key: keyword
:arg default:... | 5fb6a71e507f62eb530215385c97c56a75765df7 | 704,872 |
import subprocess
def find_telomeres(seq, telomere="ACACCCTA", minlength=24):
"""Find telomere sequences with NCRF in a list of sequences
Assumes that NCRF is in the PATH.
Parameters
----------
seq : str
Sequence to be scanned
telomere : str
Sequence of the telomere repeat. D... | 3ae2e190a86b39ca21f59dba13aa98d6eb8247a5 | 704,874 |
import torch
def train_model(bert_model, dataloader_train, optimizer, scheduler, device):
"""The architecture's training routine."""
bert_model.train()
loss_train_total = 0
for batch_idx, batch in enumerate(dataloader_train):
# set gradient to 0
bert_model.zero_grad()
batc... | fafa12c999d3c2d9716298b1ae64bd2f53dd9d09 | 704,876 |
def get_date_row(repositories):
"""Generate row with dates."""
row = ["Date"]
for repository in repositories:
row.append("Sources")
row.append("Issues")
row.append("Correct")
# one more for summary
row.append("Sources")
row.append("Issues")
row.append("Correct")
... | 460b5d47e631dac4e918965eca9c11d4f6085bb1 | 704,877 |
import pytz
def as_utc(time):
"""Convert a time to a UTC time."""
return time.astimezone(pytz.utc) | 716858e88daa43b61f5cedae72e74dafcf67d423 | 704,878 |
import itertools
def encode(data):
"""Encode data using LZ78 compression.
Args:
data: A str to encode.
Returns:
A list of two-element tuples of int and str.
"""
dictionary = {}
index = itertools.count(1)
word = ''
result = []
for character in data:
new_wor... | fcfe0b294eed92812380a60d1ec1b642084c8dfe | 704,879 |
def replace_num(s):
"""Remueve los numeros de los tweets"""
for i in ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]:
s = s.replace(i, "")
return s | 8d46f3e8d44cfc80f1efbb685b4a952c253763bd | 704,880 |
def build_response(session_attributes, speechlet_response):
"""builds resopnse"""
return {
'version': '1.0',
'sessionAttributes': session_attributes,
'response': speechlet_response
} | 96bc754e1a58300b2861851be678aa0e984845a8 | 704,881 |
def insertion_sort(L):
"""Implementation of insertion sort."""
n = len(L)
if n < 2:
return L
for i in range(1, n):
tmp = L[i]
j = i
while j > 0 and tmp < L[j - 1]:
L[j] = L[j - 1]
j -= 1
L[j] = tmp | ca7cbb5c676173ad10ce98d8b9e579a65afad0fb | 704,882 |
def _do_nothing(string):
"""Makes the ConfigParser case sensitive."""
return string | 4011cbe5b00bef5fe9fc13420bbd988729641676 | 704,883 |
def is_symmetric(mat):
"""Return whether a sy.Matrix is symmetric."""
n, nc = mat.shape
return nc == n and all(mat[j,i] == mat[i,j] for i in range(n) for j in range(i+1, n)) | e23cb03ec06f16584a99c82d66770491a6635ef5 | 704,884 |
def build_dict(*param_dicts, **param_dict):
"""
Create a merged dictionary from the supplied dictionaries and keyword parameters.
"""
merged_param_dict = param_dict.copy()
for d in param_dicts:
if d is not None:
# log.info("param_dicts %r"%(d,))
merged_param_dict.upda... | 1f77e1ca81051913ed32ea5bfdb684cf468e27af | 704,885 |
def Mode(hist):
"""Returns the value with the highest frequency.
hist: Hist object
returns: value from Hist
"""
p, x = max([(p, x) for x, p in hist.Items()])
return x | 2db7d658ad58a80041c3f450104aada006b11eaf | 704,886 |
def get_img_space(wsp, img):
"""
Find out what image space an image is in
Note that this only compares the voxel->world transformation matrix to the
reference image for each space. It is quite possible for two images to be in
the same space but not be registered to one another. In this case,
... | b455dd6300cf13cbba5d8e2d44685e06d8fb4cad | 704,887 |
import os
def get_dir(algorithm, mode):
"""
Used to determine the plotting folder
Parameters
----------
algorithm: String
The name of the current ANC algorithm running
mode: String
The MODE (precorded or anc) the server is currently running
Returns
-------
path :... | 350e47f729bddbc7d85e306b6b6af5d6a14222ea | 704,888 |
def str_to_bool(string):
"""Used as a type in argparse so that we get back a proper
bool instead of always True
"""
return string.lower() in ("y", "yes", "1", "true") | ab54e7cff5721f91f78c90498c16d68f2760ee11 | 704,889 |
def new(nbits, prefix=b"", suffix=b"", initial_value=1, little_endian=False, allow_wraparound=False):
"""Create a stateful counter block function suitable for CTR encryption modes.
Each call to the function returns the next counter block.
Each counter block is made up by three parts:
+------+---------... | a0cdadcf6eb81ad323c205e08db97d094326f513 | 704,890 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.