content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def proc_avrgs(lst):
"""[summary]
Arguments:
lst {[list]} -- [list of avrg fitness]
Returns:
[list] -- [mult every el by 100 in avrg fitness]
"""
return list(map(lambda x: x * 100, lst)) | 594641841d7fd2cd5500fc133be459104b099a80 | 17,713 |
from typing import OrderedDict
import re
import os
def read_properties(prop_file_path, recognize_vars=False):
"""Read a file of name=value pairs and load them into a dictionary.
Name and value must be separated by =.
Spaces are stripped around both name and value.
Quotes around value are removed.
... | 3b3f91d32accce9c9cfcfb20ab0e4d3259bd4bda | 17,714 |
def make_bwa_map_cmds(mapping_ob, ngsLib, cores,
samtools_exe, bwa_exe, genome_fasta,
add_args='-L 0,0 -U 0 -a', logger=None):
""" make bwa sys commands. maps PE and S reads separately,
then combines them into a X_mapped.bam file
return a list of commands to run.
... | 77c0d6d40a8ec0995fbfbe8558e479e464fd392b | 17,716 |
import zipfile
import os
def extract_zip(zip_path, extract_path=None, password=None):
""" Opens Zip Archive in order to extract files """
zip_status = True
try:
zip_archive = zipfile.ZipFile(zip_path, 'r')
if password is not None:
zip_archive.setpassword(password)
if ... | 2166f5465fb28181a230634409b870a019a21b51 | 17,717 |
import hashlib
def hash_large_file(file, chunk_size=1280000000, digest=True):
"""fast hashing of file
see https://stackoverflow.com/a/1131238/5172579
"""
with open(file, "rb") as f:
file_hash = hashlib.sha1()
chunk = f.read(chunk_size)
while chunk:
file_hash.updat... | 7603d2464e48fac70bc74cd3af8c5748ebeb2760 | 17,719 |
from pathlib import Path
def path_exists(filename: str) -> bool:
"""
Checks for the given file path exists.
"""
return Path(filename).exists() | 689c20e3417923e3538a62e35c861d2fd0cc11c5 | 17,721 |
def get_segments_between_timestamps(data_array, tag_timestamps, pre_and_post_event_marker_len=60*60, segments=[]):
"""
Extract sensor segment for the not-stress class between event markers. For a given event marker
timestamp we extract sensor segment until one hour before the event marker and one h... | 4113634f8f3be987b377fc98911b0f1b0d7e62ee | 17,722 |
def checker(z):
"""
:param z: a 2d array of complex type.
For each entry in z, it lies in an unique unit square with left-bottom corner
at lattice site (m, n) where (m, n) are both integers. Return a bool array of
the same shape with its corresponding entry is True if m, n have the same parity
e... | 3c5e17272441c5d33380ee217e1e518de67199b2 | 17,723 |
def compute_daily_returns(df):
"""Compute and return the daily return values."""
daily_returns = df.copy() # copy given dataframe to match size and column names
# compute daily returns starting from row 1 as no data present for day before day 0
# another way to do this is: (df[1:]/df[:-1].values) - 1
... | 2b73673dab8bcb0dee4e8a890d720ca933b8981d | 17,724 |
def _literal_to_r_str(value):
"""Convert a python value to a corresponding R string.
>>> _literal_to_r_str(True)
"TRUE"
>>> _literal_to_r_str(6)
"8"
>>> _literal_to_r_str("test")
"'test'"
"""
_literal_to_str = {True: "TRUE", False: "FALSE", None: "NULL"}
try:
return _lit... | 6fc6445fb4295458973dd977363536f741ab05f1 | 17,725 |
def weight_height_score(lists):
"""
Score table.
:param x: object list of Class Horse or Cat.
:return: avg_weight_score, avg_height_score, least_height, most_height in a tuple.
"""
# I am aware that two of these vars are not being used.
# This is only for future scalability.
total_weight... | ee14dae891afa9a1de2101e0063239e68c7928dc | 17,726 |
def drop_quasi_zero(df, thresh=0.05):
"""
Drop Quasi Zero Features
Returns a passed pandas DataFrame without columns containing too few
non-zero values.
Parameters
----------
df : pandas DataFrame
Dataset whose columns will be dropped.
thresh : float, optional
Minimum p... | 187254b59b34f7c788ea5a3c162d6b869e852e9a | 17,728 |
def append_ordering_info_to_docstring(fields):
"""Class decorator factory which creates viewset decorator adding documentation on ordering of viewset results.
Documentation is displayed either via Browseable API or upon receiving OPTIONS request.
Parameters:
- fields #list: The list of field names wh... | 9065cbdeb13e80275363ef8848eb4d73e8dfa3c8 | 17,729 |
def _tokenize_with_entity_markers(tokens, tokenizer, e1, e2):
"""Apply wordpiece tokenization with entity markers around entities."""
def tokenize(start, end):
return tokenizer.tokenize(" ".join(tokens[start:end]))
if e1[0] < e2[0]:
return (tokenize(0, e1[0]) + ["[E1]"] + tokenize(e1[0], e1[1] + 1) +
... | 3dd49697366b24855711a4e46c6f9e944cf9fc61 | 17,731 |
import pkg_resources
import json
def get_MWDD_info(name):
""" Retourne un dict avec les parametres de l'etoile donnee en input """
MWDD_table = pkg_resources.resource_stream(__name__, 'MWDD_table.json')
data = json.load(MWDD_table)
for entry in data['data']:
try:
namelist = entry['... | 1a8d0ba084f91c4f9b7e7d5dd0c6dc940e5936a0 | 17,732 |
import os
def checkPath():
"""Create a path name for config file depending on location of the program"""
currentPath = os.getcwd()
if ("/usr" or "/opt") in currentPath:
pathName = os.path.expanduser("~/.config/tuxle-triad/config.txt")
else:
pathName = os.path.join(os.getcwd(), "co... | 02a96f46a55af2a845ce7e3780cf58e5b74dad85 | 17,733 |
def parseHeaderText(header):
"""
parseHeaderText(): Go through our parsed headers, and create text descriptions based on them.
"""
retval = {}
if header["qr"] == 0:
retval["qr"] = "Question"
elif header["qr"] == 1:
retval["qr"] = "Response"
else:
retval["qr"] = "Unknown! (%s)" % header["qr"]
if header[... | 9fea4101de686bb86b89abfb82cde7a212e4b8e2 | 17,734 |
import os
def write_service(service_name, contents):
"""Write a service file in a "safe" manner.
If the contents of the file are the same as what is desired to be written,
do nothing.
First writes to a temporary file in the same directory as the target, them
move that temporary file into plc... | 5ba3e1bc4edad239e17d2daeaa198f395bab7c5c | 17,735 |
import re
def pascal_to_snake(string: str) -> str:
"""
Converts pascal-case to snake-case.
>>> pascal_to_snake(string="HelloAndGoodMorning") # Returns "hello_and_good_morning"
"""
words = re.findall(pattern="[A-Z][^A-Z]*", string=string)
words_lower_cased = list(map(str.lower, words))
retu... | 2ef5f0056d099194ffbd1aa8062fefea7664f4eb | 17,737 |
def fluid_properties(fluid_str):
"""
Return the physical density and kinematic viscosity for the prescribed
fluid.
"""
fluid_lib = {'water':(1000., 1.0e-6),
'glycol':(965.3,0.06/965.3),
'glycerin':(1260.0,1.49/1260.0)}
if fluid_str in list(fluid_lib.keys()):
... | ea2784b5b9c9767e43dba787910fd5c32da8a266 | 17,739 |
def reduce_datetimes(row):
"""
Receives a row, converts datetimes to strings.
"""
row = list(row)
for i, iterrow in enumerate(row):
if hasattr(iterrow, 'isoformat'):
row[i] = iterrow.isoformat()
return tuple(row) | 8cf4c4bee5e3a0f656c0a883a5325de3dea4e8fe | 17,740 |
def losocv_split(subjectIDs):
"""Create leave-one-subject-out cross-validation train/test splits.
Args:
subjectIDs (list): subjectID corresponding to each example.
Returns:
splits (list of lists): each fold's train and test indices.
subjectIDset (list): unique IDs, in held-out-test... | 9f7d5051e34669a5c085cf08e65bcfd66eaaa9c7 | 17,741 |
def get_isilon_smartquota_parameters():
"""This method provides parameters required for the ansible Smart Quota
module on Isilon"""
return dict(
path=dict(required=True, type='str'),
user_name=dict(type='str'),
group_name=dict(type='str'),
access_zone=dict(type='str', default... | 88bf752234bd7280550753f60e8510ade98b34c7 | 17,742 |
def unauthenticated_json():
"""Return a failed authentication response."""
return {"statusCode": 2, "message": "Not Authenticated !"} | e1ebd455f60534eb9b9609024d45d1fc324bca41 | 17,743 |
import string
def letter_for(index):
"""Convert an index into a letter (or letter pair). a-z, then aa-az-zz"""
if index < 26:
return string.ascii_lowercase[index]
return (string.ascii_lowercase[(index // 26) - 1] # First letter in pair
+ string.ascii_lowercase[index % 26]) # Seco... | aad7edbbd8941339e93b8a732857258d28d73033 | 17,744 |
def KJKGtoBTULB(hkjkg):
"""
Convertie l'enthalpie en kJ/kg vers btu/lb
Conversion: 1 kJ/kg = 0.429923 Btu/lb
:param hkjkg: Enthalpie [kJ/kg]
:return hbtulb: Enthalpie [btu/lb]
"""
hbtulb = hkjkg * 0.429923
return hbtulb | 3b26742b2e56c7e265bf94d0af15f485e091f395 | 17,745 |
def getOperation(value, operations):
"""Get an L{Operation} from an C{int} representation.
@param value: The C{int} operation value.
@param operations: A sequence of possible L{Operation}s to match.
@return: The matching L{Operation} or C{None} if one isn't available.
"""
for operation in opera... | 34d2ef3cf0965285d2e694d8e5ea2df41cfe5892 | 17,746 |
import argparse
def get_parser():
"""
get_parser - a helper function for the argparse module
"""
parser = argparse.ArgumentParser(description="Spell correct and create PDF")
parser.add_argument(
"-i",
"--input-dir",
required=True,
type=str,
help="path to dir... | 80a2786ffb93198d4de7dab2494567ee9a9c5198 | 17,747 |
def convert_date_time(date, time=None):
""" The date time is only concatenated unless there is no time.
"""
if time is None:
return date
else:
return "%s %s" % (date, time) | 6196c224137f2be158d8580777e9651714613433 | 17,748 |
def _checkinst(inst, disp, fpu, insttable):
"""
Check observation instrument requirements against tonight's instrument configuration.
Parameters
----------
inst : str
Observation instrument
disp : str
Observation instrument disperser (or 'null')
fpu : str
Observat... | 225064720de710933894c951be25c18be89f0181 | 17,749 |
def merge_list(lst, *to_merged_list):
"""
Merge multiple lists into the first list
:param lst:
:param to_merged_list:
:return:
"""
for item in to_merged_list:
lst.extend(item)
return lst | 29b17583c73854363277a65862efc130ae19346a | 17,750 |
def isstr(obj):
"""Return whether an object is instance of `str`."""
return isinstance(obj, str) | 33e1cea9b8a60d224dc395f4446f175c0b967dd0 | 17,751 |
def convert_clip_ids_to_windows(clip_ids):
""" Inverse function of convert_windows_to_clip_ids
Args:
clip_ids: list(int), each is a index of a clip, starting from 0
Returns:
list(list(int)), each sublist contains two integers which are clip indices.
[10, 19] meaning a 9 clip win... | 05600f2eb248ce61359a02cbcd4bd75035c6a55f | 17,752 |
import torch
def kron(*matrices):
"""
Kroneker product between matrices
"""
for m in matrices:
assert m.dim() == 2
if len(matrices) == 0:
return torch.ones(1, 1)
if len(matrices) == 1:
return matrices[0]
x, y, *matrices = matrices
z = torch.einsum("ij,kl->ikjl... | 5d2e732a1b4fe3581522ae16a91833428f928db3 | 17,753 |
def M2_string(params, errors):
"""
Return string describing a single set of beam measurements.
Args:
z: array of axial position of beam measurements [m]
d: array of beam diameters [m]
lambda0: wavelength of the laser [m]
Returns:
Formatted string suitable for printing.
... | 19f97d54e4d12957f79b8c4207660f73c648b2f6 | 17,755 |
def check_approved(userName, userArn):
"""Summary
Args:
userName (TYPE): Description
userArn (TYPE): Description
Returns:
TYPE: Description
"""
# Default
approved = False
# Connect change record DDB
# Check if approved for adding users
# Check how many us... | d827e1f05e69aa22088d3545e82da38fb0398748 | 17,756 |
import string
import random
def seed(length=32):
""" 生成指定长度的随机字符串
:param length: 期望生成的字符串长度
"""
base_str = string.digits + string.ascii_letters
return ''.join([random.choice(base_str) for _ in range(length)]) | 32563ef10dd76a2e44bf0d0a90ba60e21ffb03f5 | 17,758 |
def _is_compiled(url):
"""
Returns True if wheel with provided url is precompiled.
The logic in this method is a less efficient version of
-cp[0-9]{2}- regex matching.
"""
prefix = "-cp"
start = 0
for _ in range(len(url)):
start = url.find(prefix, start)
if start == -1 o... | fada4e14da5c92f7189737a3c50041f9a93acfe1 | 17,760 |
def first_and_last_n_chars(s, n1=30, n2=30):
"""
Utility function to display first n1 characters and last n2 characters of a long string
(Adjusts display if string is less than n1+n2 char long)
:param s: string
:return: string for display
"""
first_len = min(len(s), n1)
first = s[:first_... | f23b02a65f1c8c03a71498b0bcb9cc2941fd8060 | 17,761 |
from pathlib import Path
def create_folder(folder_name, folder_path=""):
"""
Create a folder with a given name in a given path.
Also creates all non-existing parent folders.
Parameters
----------
folder_name : str
Name of the folder to be created.
folder_path : str
Optiona... | ed6f239c210cc9697fe6b4bb45189cc54abda970 | 17,764 |
def log_json(request_id, message, context={}):
"""Create JSON object for logging data."""
stmt = {"message": message, "request_id": request_id}
stmt.update(context)
return stmt | b04c7101fcbc8bd800bd888e726ff131da198854 | 17,766 |
def claim_account_legacy(request):
"""Render a page explaining that claim links are no longer valid."""
return {} | d48db70e437fad3d8048902e640226780d3f4fb4 | 17,767 |
def comma_conjoin(inlist, conjunction):
"""Parses the elements of a list into a string joined by commas,
with an 'and' before the final element. Oxford comma!
"""
if len(inlist) == 0:
return ""
elif len(inlist) == 1:
return str(inlist.pop())
elif len(inlist) == 2:
return... | 1a60d7e8752436796fc518832bfece1a97914ff0 | 17,768 |
def fillna(df, column, value):
"""
Can fill NaN values from a column
Args:
df
column
value
"""
if column in df.columns:
df[column] = df[column].fillna(value)
else:
df[column] = value
return df | 8f14bf01017b62817736c3ae137798fbc63a01d7 | 17,769 |
def min_user():
"""Represent a valid user with minimal data. """
return {
'email': 'minimal@example.com',
'name': 'Primus Minimus',
'age': 18,
} | 9ffe9567a86242830ce3f162ca6effda341a8ae0 | 17,770 |
import warnings
def naive_dump_json(x, indent=None):
"""dumb not safe!
Works for the purposes of this specific script as quotes never
appear in data set.
Parameter indent ignored"""
warnings.warn('about to dump rough read_json')
assert isinstance(x, dict)
# could use pprint for the pu... | 46854a807ffb83ce4c83090ae6f13208fac3d158 | 17,771 |
def same_container(cont1, cont2):
"""
Return True if cont1 and cont2 are the same containers.We assume that processes
that share the same PID are the same container even if their name differ. We
assume that files that are located in the same directory and share the same
inode are the same container... | 88a5abc5547b7ee28ca9136425b7a52f532a23a1 | 17,772 |
def compare_data(plt_type, correct, given):
"""
Determines whether the given data matches any of the data found in the
correct data. This handles plots of different types: if a histogram
was plotted with the expected data for a line plot, it will return True.
Args:
plt_type (str): The expec... | 0bbd217906d86c2117c8c1b7a66a768386ca116b | 17,773 |
def UINT(value): # noqa: N802
"""Converts a value that matches \d+ into an integer."""
if value is None:
raise ValueError('None is not a valid integer')
if not value.isdigit():
raise ValueError('Only positive numbers are allowed')
return int(value) | 3d58dadf97fe26d7bfa00acb3451a39a5e5845bb | 17,777 |
import math
def get_distance(loc1, loc2):
""" Computes the Euclidian distance between two 2D points."""
x_diff = loc1.x - loc2.x
y_diff = loc1.y - loc2.y
return math.sqrt(x_diff**2 + y_diff**2) | 3a603ace039ea887cabd8b16d2b04d84d939c112 | 17,778 |
def get_rank(target, ranks):
"""
Get rank of a target entity within all ranked entities.
Args:
target (str): Target entity which rank should be determined.
ranks (list): List of tuples of an entity and its rank.
Returns:
int: Rank of entity or -1 if entity is not present in ranks.
"""
for i in range(len(r... | 0e247669af757a5ffa5fff016262eb677f7c3cb8 | 17,781 |
from unittest.mock import call
def convert_video_audio(title, video_filename):
"""
Convert given video to the mp3
"""
audio_filename = 'audios/{title}.mp3'.format(title=title)
call([
'ffmpeg',
'-i',
video_filename,
'-b:a',
'192k',
'-vn',
audi... | 3a52e957eb07be7b932db5667a693117f125aadf | 17,784 |
import torch
def _as_tensor(x):
"""
An equivalent of `torch.as_tensor`, but works under tracing.
"""
if isinstance(x, (list, tuple)) and all([isinstance(t, torch.Tensor) for t in x]):
return torch.stack(x)
return torch.as_tensor(x) | 601795d4fb1b7cb31b91d103075db57aedcfa874 | 17,786 |
import sys
def file_opener() -> str:
"""The shell program to use to open a file with the default program."""
return {'linux': 'xdg-open', 'win32': 'start'}[sys.platform] | 93317f4a55999b3e5a8f0cc28dba24e1dccc4946 | 17,787 |
import os
import torch
def load_model(name, dir_path, device='cuda'):
"""
Load pytorch model from given path.
:param device: device to load models.
:param model: model object
:param name: model file name
:param dir_path: model directory
:return: loaded model
"""
model_path = os.pat... | 4bdf9863fe23358e3737db343ace7c29aca109ad | 17,789 |
def get_attributes(obj):
"""
Fetches the attributes from an object.
:param obj: The object.
:type obj: object
:returns: A dictionary of attributes and their values from the object.
:rtype: dict
"""
return {k: getattr(obj, k) for k in dir(obj) if not k.startswith("__")} | 6e1cea3ed8ad2fa1c00f7c2eb86efb4a629e9f06 | 17,790 |
def evaluate_func2(x):
"""a - b + 2a^2 + 2ab + b^2
:param x: numpy ndarray,with shape (2,)
:return:
"""
a = x[0]
b = x[1]
return a - b + 2 * a ** 2 + 2 * a * b + b ** 2 | 0f100254b05137a30f5423b95756f3df03a87cef | 17,791 |
def define_args(parser, *args_builders):
""" Set program args"""
for args_builder in args_builders:
parser = args_builder(parser)
return parser | 36febf6c80d2e66b34d26ea9b522c09144cd2876 | 17,794 |
def bernoulli_lh(ho, ha, s, n):
"""
Returns the likelihood ratio for independently distributed bernoulli random variables.
Parameters
----------
ho : float
null hypothesis
ha : float
alternative hypothesis
s : float or int
number of successes in sample
n : float or int
total number of elements i... | 95b52f3f48a173a6a40fab8ae7c776a7082ebb02 | 17,796 |
def extend_hit_reference(seq1, start1, end1, seq2, start2, end2):
""" Extend the hit on seq1, assuming missing content is identical to seq2
If the hit covers all of seq1, but seq1 is shorter than seq2, assume
the missing sequences from seq1 are identical, and add those sequences.
"""
# If ... | d58dcea4117d1826a434c87092b229a271d4b775 | 17,799 |
def get_predicted_gender(spanish_sent):
"""
Return the gender of the first entity in the spanish
translation.
"""
first_word = spanish_sent.split()[0].lower()
if first_word == "el":
return "male"
elif first_word == "la":
return "female"
else:
return "neutral" | 94f43d37f29af4e3f1314a5e177d2e8036036a0a | 17,800 |
import torch
def make_onehot_kernel(kernel_size, index):
"""
Make 2D one hot square kernel, i.e. h=w
k[kernel_size, kernel_size] = 0 except k.view(-1)[index] = 1
"""
kernel = torch.zeros(kernel_size, kernel_size)
kernel.view(-1)[index] = 1
return kernel.view(1, 1, kernel_size, kernel_size) | be324887a77f454e9f2c306e1bc9eddd8c001bb8 | 17,801 |
def manual_expo_mode(state):
""" Bool to express if mode is manual. """
return state["expo_mode"] == "manual" | b9797a0e85ef9474b8819555afc33cf020031fc1 | 17,802 |
from datetime import datetime
import logging
def get_current():
"""
Grabs the current month in integer / string formats and year.
"""
# format month year for datetime comparison
month = datetime.now().strftime('%m')
month_word = datetime.now().strftime('%B')
year = datetime.now().year
... | 28666b9f643e8d4b9879aeb84dd653adafb4f6e4 | 17,803 |
def whitelist(squat_candidates, whitelist_filename="whitelist.txt"):
"""Remove whitelisted packages from typosquat candidate list.
Args:
squat_candidates (dict): dict of packages and potential typosquatters
whitelist_filename (str): file location for whitelist
Returns:
dict: packag... | 5d8305d7ee721988420a6035d2df9e0b52404b7b | 17,804 |
import sys
import textwrap
import itertools
def format_record_restructuredtext(
record,
out=sys.stdout,
structured_sort=lambda k: k.name,
unstructured_sort=lambda k: k.group_by if k.group_by is not None else "",
):
"""Convert a record to a reStructuedText document.
:param record: Record to fo... | a5aa4572dba17040f809a8e957a580ff4aa6a762 | 17,806 |
def str_to_list(text):
"""
input: "['clouds', 'sky']" (str)
output: ['clouds', 'sky'] (list)
"""
# res = []
res = [i.strip('[]\'\"\n ') for i in text.split(',')]
return res | 2f5bea8885177f89d0d745fdddf0ecd589d1d9bf | 17,807 |
def legacy_collision_handler(slug, node1, node2):
"""Ignores all collisions, like :class:`SystemDispatcher` does.
"""
if node1.type == 'directory' and node2.type != 'directory':
if not node1.children:
# Ignore empty directory
return 'replace_first_node'
if '' not in n... | 1dd7671eaae8b5889c3bd8f9461917376d73a3d6 | 17,808 |
def generate_family_characteristics(df, family_id, group_ids):
"""
Given either an HMIS or a Connecting Point dataframe, add columns regarding family structure.
:param df: HMIS or Connecting point dataframe.
:type hmis: Pandas.Dataframe.
:param family_id: column name of family identifier.
:typ... | f4d37d396352f6e9236e6710d8115bc6a8d3e632 | 17,809 |
import functools
def int_ip_from_string(ip_string):
"""
Convert ip4 address from string representation into int (4 bytes).
Parameters
----------
ip_string : string
ip4 address as string (dot-separated)
Returns
-------
int
4-byte integer ip4 address representation
... | d6a2cd4d93c54887697396533203d1b716e53cfe | 17,811 |
import numpy
def weighted_median(data, weights):
"""
Args:
data (list or numpy.array): data
weights (list or numpy.array): weights
"""
data, weights = numpy.array(data).squeeze(), numpy.array(weights).squeeze()
s_data, s_weights = map(numpy.array, zip(*sorted(zip(data, weights))))
midpoint = 0.5 * sum(s_w... | dff154dd195cef523eb386888c4beddaee68542a | 17,813 |
import re
def find_pattern(text_to_search):
"""
Find pattern .dylib within a text
"""
pattern = re.compile(r'[a-zA-Z0-9_.+-]+\.dylib')
matches = pattern.findall(text_to_search)
pattern_path = re.compile(r'[a-zA-Z0-9_.+-/@]+\.dylib')
matches_path = pattern_path.findall(text_to_searc... | 4f4ec47de86f48782291cc4b7522f88a248d9405 | 17,814 |
def get_values_as_str(history, key):
"""Retrieve values from sequence of dictionaries."""
return [i[key] for i in history] | 46687f63ce519d532f44f4aa6eb836eb079cadba | 17,815 |
def lambda_tuple_converter(func):
"""
Converts a Python 2 function as
lambda (x,y): x + y
In the Python 3 format:
lambda x,y : x + y
"""
if func is not None and func.__code__.co_argcount == 1:
return lambda *args: func(args[0] if len(args) == 1 else args)
else:
return... | e513ed89d3cfc075031a6ecb45d6b839b4b9fdf7 | 17,817 |
def merge_compute(left, right):
"""
Merge two dictionnaries but computing integer values instead of overriding.
Left override every right values except when both left and right value are
integers then right value will be incremented by left value.
Arguments:
left (dict): The dict to merge ... | 37823d5c3bd94c94685aed1f965c77d787900633 | 17,818 |
import torch
def find_good_mu(noise_mag):
"""computes the regularization parameter in adversarial regularizer according to their heuristic"""
return 2*torch.mean(noise_mag) | d7c3ff16ea2f7ce64c81afa20aad3267eacb863f | 17,819 |
def verify_params(post_dict):
"""
Verify that a post dict contains the expected parameters.
"""
if ('target' not in post_dict) or ('source' not in post_dict):
return False
if not post_dict['target'] or not post_dict['source']:
return False
return True | b0dc66873e1771a898eb0b12c778bc2c4341e69f | 17,820 |
def isClimateMap():
"""
Uses the Climate options
"""
return 1 | af5801b3d7b0c7dba8995ce2446a8c31918ee440 | 17,821 |
def build_metadata_from_setuptools_dict(metadata):
"""Build and return metadata from a setuptools dict.
This is typically from package metadata.
"""
# based on warehouse and virtualenv examples
# https://github.com/pypa/warehouse/blob/master/warehouse/templates/packaging/detail.html
# https://g... | 954ec12c2b557f4a5dbad6ed5cdf3f0b05123e21 | 17,822 |
def checkConfig(config):
"""Checks that all necessary configuration fields has been set.
Returns the names of any invalid configuration fields.
:param config: The Configuration object to check.
:type confing: configuration.Configuration
:return: Names of fields that have yet to be set.
:return ... | e5635be1534e587b0c3612caf79147b2d67ecb30 | 17,823 |
import pickle
def load_tokenizer(path):
"""[load tokenizer stored in path]
Args:
path ([string]): [where the tokenizer is stored]
"""
with open(path, 'rb') as handle:
tokenizer = pickle.load(handle)
return tokenizer | 32958c9294d4e93ac66640a150bdaee7e72fcfe1 | 17,825 |
def _get_special_ids(tokenizer):
"""Gets the ids of special [T] and [P] tokens."""
trigger_token_id = tokenizer.convert_tokens_to_ids('[T]')
if trigger_token_id == tokenizer.unk_token_id:
raise ValueError('Tokenizer does not have special [T] token.')
predict_token_id = tokenizer.convert_tokens_t... | ad3458150df641a3ae3ae3ce5d4481b438345757 | 17,828 |
import shutil
def mpi_executable(preferred_executable=None):
"""
Return an mpi executable found on the current system.
Depending on your MPI implementation, the executable name
to run an MPI application may differ. This function will
check which one is available and return the first valid one
... | ab197a7591da0609a4af3eee57e8b8947ab19d9d | 17,830 |
def extract_pattern(fmt):
"""Extracts used strings from a %(foo)s pattern."""
class FakeDict(object):
def __init__(self):
self.seen_keys = set()
def __getitem__(self, key):
self.seen_keys.add(key)
return ''
def keys(self):
return self.see... | 81116122db6167322a4c7d05f6d45dc257fa5a74 | 17,831 |
def yaml_variables_subst(yaml_raw, variables=None):
"""
Performs variables substitute on a provided raw YAML content
:type yaml_raw str
:type variables dict
:rtype:str
"""
if variables is None:
return yaml_raw
# replace "${VAR_NAME}"
for key, value in variables.items():
... | de1c858712c73b6d81ed4f9db10b136a77ebea78 | 17,832 |
def illuminanceToPhotonPixelRate(illuminance,
numerical_aperture=1.0,
pixel_size=6.5e-6,
magnification=1,
sample_quantum_yield=1.,
**kwargs):
"""
... | 9bb90c07c3b58c8b82424147018d697f095303f7 | 17,836 |
def Main():
"""
:return:
"""
a = [1, 2, 3, 4]
b = len(a)
c = -424
d = abs(c)
m1 = 32
m2 = 21
m3 = min(m1, m2)
m4 = max(b, c)
a2 = a[2:]
return m4 + m3 | 9c8c8d9836b05a3393c774a22d833eb6c5a0bc09 | 17,837 |
def abs2(numero):
"""
(num) -> num
Calcula el valor absoluto de un número
>>> abs2(10)
10
>>> abs2(-8)
8
>>> abs2(0)
0
:param numero: el numero a evaluar
:return: el valor absoluto del número
"""
if numero < 0:
# La palabra clave return se utiliza para reto... | 826ab80cc1af250e9e332e72c81ffcc5a5383d83 | 17,838 |
import requests
def fetch_output(input_prefix, input_value, output_prefix, enable_semantic_search=False):
"""Find APIs which can produce the output_prefix
:arg str input_prefix: The prefix of the input, e.g. ncbigene, hgnc.symbol.
:arg str output_prefix: The prefix of the output, e.g. ncbigene, hgnc.symb... | 1ed8f27923695ab7587f49083070aecb040987f6 | 17,839 |
import torch
def InlierPortion(predict_weight,gt_weight,threshold=0.3):
"""
Input: predict_weight ([Batch_size,N]), gt_weight ([Batch_size,N]) , threshold for deciding inliers
OutpuT: portion of the ground truth inlier detected, ground truth inliers among the dtected inliers
"""
predict_weight... | 0b728a59bb880eecb1d9636a838cc4cc6040bdb8 | 17,840 |
from datetime import datetime
def timestamp_string_parse(value):
"""Converte timestamp string no formato %d/%m/%Y"""
return datetime.fromtimestamp(int(value)).strftime('%d/%m/%Y') | 1c561fe6cebac5fba05cc2ce56bf14a2311c51ae | 17,841 |
import sys
def exclude_selection(data, selection):
"""Makes a new dataset excluding points whose id is in selection."""
new_data = [
a_data_point for a_data_point in data
if a_data_point.par.get('resonance_id', None) not in selection
]
if new_data == data:
sys.stdout.write("\... | 7488d44d23b2f9bec42a138cfdd2e32d34b7d473 | 17,842 |
def collinear(p1, p2, p3):
"""
Check if the points are colinear
:param shapely Point p1: point to chek if is colinear
:param shapely Point p2: point to chek if is colinear
:param shapely Point p3: point to chek if is colinear
:return bool: True if are colinear
"""
return (p1[1]-p2[1]... | 5738649db59980742dd7fd089d8f27302eead0ac | 17,843 |
import glob
def parse_lmat_output(lmat_dirname, allow_missing=True):
"""
Returns dict (field_name) -> (parsed_value), see code for list of field_names.
No longer used (LMAT isn't part of pipeline any more), but kept around in case
it's useful to resurrect it some day.
"""
# Represent each ta... | 33ba466c57d972652537a807fd9ad9a15398f762 | 17,844 |
def plugin_final_label():
"""A plug-in function with a different label"""
return "final" | eab1ec3e35099afa92ced379552db06ce5ee3576 | 17,845 |
import requests
def validate_status_via_raw(recommendation, config_data):
"""
Runs validation checks against the recommendation status and associated reputation override.
Args:
recommendation (Recommendation): The recommendation object to be tested.
config_data (dict): Contains configurat... | 3156b67eec9c67bcc1a3b1f8d46057e527d45de3 | 17,846 |
def ListToBullets(files):
"""!
Convert a list of file names into a bulleted list (as a string).
@param files: (list) names of files to be compiled into a bullet list in a string.
@return a string with a well formatted bullet list of file names.
## Profile
* line count: 7
* characters: 149
* returns: return ... | 8ba84c7fc467c8927e690e7762f4412209d5499d | 17,849 |
def _remove_duplicate_transactions(transactions, reference_transactions):
"""Returns a list of transactions that are not present in reference_transactions."""
return [t for t in transactions if t not in reference_transactions] | 8e2ff00dd845acd9ab63f93b8d998fe897a7d21e | 17,850 |
from typing import Dict
from typing import Any
import os
import json
def read_json(path: str) -> Dict[str, Any]:
"""
Read a JSON file (assumed to be a dictionary).
"""
if os.path.exists(path):
with open(path, "r", encoding="utf-8") as file:
return json.load(file)
else:
... | 668d5b9adc3350cb9d5825fe45eefb9403c518e2 | 17,851 |
import argparse
from pathlib import Path
def parse_arguments() -> argparse.Namespace:
"""Parse arguments from CLI."""
parser = argparse.ArgumentParser(
description="Enduro Learner",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
"--store_path",
... | b1c89265222174fa65fcd020fbc2e752235435ce | 17,853 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.