content
stringlengths
35
416k
sha1
stringlengths
40
40
id
int64
0
710k
def alignedLoadFromStoredValue(load_size_bytes, stored_value, stored_size_bytes, load_endness, store_endness): """ Return the correct data when loading from the given stored_value, when sizes may be different. Assumes the load and store were to the _same address_. Also assumes load_size <= stored_size (...
2178c292428245af933f7c83e681c331a1fa68d3
23,333
import functools def stateguard(action_guard): """ Decorator guard refines the criteria for picking an action to run by stating a function with THE SAME signature as the guarded action returning a boolean (True if action allowed). If the speciified function is unbound or a lambda expression, you must ...
988c165fd4496f7c4f4d16a3d213fa98718a1d96
23,334
import copy def get_true_abstract_mask_spriteworld(sprites, config, action=(0.5, 0.5)): """Returns a mask with iteractions for next transition given true sprites. E.g., returns [[1,0,0],[0,1,0],[0,0,1]] for 3 sprites""" sprites1 = copy.deepcopy(sprites) config['action_space'].step(action, sprites1) return c...
4dbb0f6c65d52684077d2a97ee668e02ec4eb31f
23,335
import glob import os def subdirectory_basenames(parent_directory): """ Return list of immediate subdirectories of provided parent_directory. """ return [os.path.basename(sd.rstrip('/')) for sd in glob.glob(parent_directory + '*/')]
f0df3c304ec7146d30ee75b759a65bbf678c96be
23,336
def VLT_distortion(measured_wave, cutoff=10000., slope1=0.06, intercept1 = -100.0, slope2 =0.160, intercept2=-1500.0, ): """Telescope dependent distortion function for the VLT sample.""" if measur...
b2fd724e217e0a0ee11ce0df9d872a7bdbba069d
23,337
def lift(a): """ Lift an element a of Q[y] / (y ** (n // 2) + 1) up to Q[x] / (x ** n + 1). The lift of a(y) is simply a(x ** 2). Input: a A polynomial of Q[y] / (y ** (n // 2) + 1) Output: res The lift of a in Q[x] / (x ** n + 1) Format: Coefficient """ ...
eff5fd7ac4e63ac1887d99ee0c45e2820262bf59
23,338
def get_jaccard_similarity(s, t): """Computes the Jaccard Similarity of two sets""" return len(s.intersection(t)) / len(s.union(t))
12c17780e3ca51b9948b7b89b8b22f89aed6690d
23,343
def strip_list_items(items): """Apply str.strip to all items in a list""" return list(map(str.strip, items))
f34e5d483eb15b4936bff6df57afd0574b05397b
23,345
import random def best_index(seq): """best_index(seq) Given a sequence, find the postion of the largest value. Ties are broken randomly. """ largest = max(seq) indices = [] for idx, val in enumerate(seq): if val == largest: indices.append(idx) # Randomize if necess...
7d9506220d9b216c4016102f48853783d049f33d
23,349
def inask(question: str) -> str: """ this fnc made for test because we need user input but intest it cant typing itself os it need to call patch module but it need to create a sperate function and call it in function that we want to use Args: question (str): any string Returns: str: ...
e0ad0b9fb4ff518b103b35a1855b780e6d323172
23,350
def borough(): """ Ensures the borough entered is a string Parameters ---------- none """ bvalue = "Brooklyn" if isinstance(bvalue, str): return bvalue else: print("Please enter a word")
742c04ced6a6c2d69a2d2c1c2c768f659f6f4963
23,351
import ast def _node_filter_for_globals(globals): """Filters ast nodes in support of setting globals for exec. Removes initial assigns of any variables occuring in `globals`. This is to allow globals to provide the initial value. Subsequent assigns are not removed under the assumption that are re...
5ffc5fb128ab297d0cbc2efef6684fb455dfaa2e
23,353
def nvmf_subsystem_add_ns(client, nqn, bdev_name, tgt_name=None, ptpl_file=None, nsid=None, nguid=None, eui64=None, uuid=None): """Add a namespace to a subsystem. Args: nqn: Subsystem NQN. bdev_name: Name of bdev to expose as a namespace. tgt_name: name of the parent NVMe-oF target (opt...
7cced4de1411e5b082be8a7f19730d56134a85be
23,354
from typing import List from typing import Dict def get_initial_state(procs: int, tasks: List[int]) -> Dict[int, List[int]]: """generate the initial state of the system the initial stage is easy to generate: all processors have an empty tasklist except the first one which has it all example: ...
04ac8b0d99d7b248772894ea5356065e555c5250
23,357
from typing import List def list2str(l: List[int]) -> str: """ Converts list to a string""" return ' '.join([str(x) for x in l])
fde657c2143ab73fbf0e9a28f3cf47fa377de7dc
23,358
def a_function(): """A pretty useless function""" return "1+1"
692f03d4f6a600137c97d0e6af475cc167475146
23,359
import math def _pos_sqrt(value: float) -> float: """Returns sqrt of value or raises ValueError if negative.""" if value < 0: raise ValueError('Attempt to take sqrt of negative value: {}'.format(value)) return math.sqrt(value)
7b4e76f67b2f3f3dfab3e3c441f084685464a994
23,360
def three_sum(number_list, required_sum): """Three sum question using hashing method. Parameters ---------- number_list: list[float] required_sum: int Returns ------- tuple(float) """ for first_number_index in range(len(number_list)): first_number = number_list[fir...
2aa7fa178b16da3d5b7150b1bcfaab27b6947884
23,362
def get_type(): """Collects the graph type the user desires. This function prompts the user as to whether they want to draw an Epitrochoid or a Hypotrochoid. The function will loop until valid input is achieved. Again, the 'loop and a half' method was used. """ types = ['Epitrochoid', 'Hypotroc...
4d1ece158138b141f5ac5a303dcd41a751097041
23,365
import re def filter(phrase, isSpecCharsFiltered=True): """Processes key and value strings for dictionary storage, including condensation of whitespace, removal of bracketed references, and (if not specified otherwise) removal of non-word/space/digit characters. """ # phrase = phrase.encode(...
f97a421539f07fa28dc695055108c9de9eedd5b7
23,366
def find_nth_prime(n: int) -> int: """modified sieve checks every natural number against all previous primes to find the nth prime""" assert n >= 2 current = 3 primes = [current] if n == 1: return current # add 1 continuously in a loop checking if the number divides any of the previously...
1b131ea3f0a00174220f5ed7969bba9a828aa4bf
23,367
from typing import List from typing import Dict def generate_create_sqls(tbl_name: str, columns: List[tuple], keys: Dict) -> str: """ tbl_name: string a table name after pyjj_{tbl_name} columns: list of tuples (column_name, data_type, options) keys: dict of keys key: (columns, options) """ ass...
2bcf1e568ce093426666b8e10f9fa28128b7e995
23,368
import random import os def _set_ants_seed(): """Fix random seed for antsRegistration, antsAI, antsMotionCorr""" val = random.randint(1, 65536) os.environ["ANTS_RANDOM_SEED"] = str(val) return val
2edc4bf148f581950f96287bb990398c2be9a8f4
23,369
import csv def csv2dict(csv_filename, deli=',', encoding=None, key_is_header=False): """ 将指定的 csv 文件转换为 list 返回; :param: * csv_filename: (string) csv 文件的长文件名 * deli: (string) csv 文件分隔符,默认为逗号 * del_blank_row: (string) 是否要删除空行,默认为删除 * encode: (string) 文件编码 :return: ...
71ebf02d85bf9fceaf3374c4233940e5794cc8cc
23,370
import json def put_content(request): """Body should be { 'type': 'page', 'title': 'title', 'body': {'storage': {'value': 'value', 'representation': 'storage'}}, 'version' : {'number': number}, 'ancestors': [{'id': parent_id}] (optional) } """ body = requ...
ded8c5f78e93ba4e3ae7c96d4b2ddfd64a4cb10b
23,372
def tokenize_text(text): """ Fake tokenizer; Return a list of words """ return text.split()
c96764e5d504dcdf0285b0c2117f6a355d0358c5
23,373
def build(lineage): """build(lineage) takes as input the lineage of a stream and constructs the stream. """ plan = lineage if len(plan) == 0: raise ValueError("Plan is empty") elif len(plan) == 1: return plan[0] else: v = plan[0] for op in plan[1:]: v = v[op] return v
7b34c1147515497e8858ea92d57d50709f5f839d
23,374
def validate_and_build_instance_fleets(parsed_instance_fleets): """ Helper method that converts --instance-fleets option value in create-cluster to Amazon Elastic MapReduce InstanceFleetConfig data type. """ instance_fleets = [] for instance_fleet in parsed_instance_fleets: instance_...
4afede0fbee45f5eb4cfeb29aa0eaf759ce31bd9
23,375
def sort(pinyin_d): """ :rtype: list """ return sorted(pinyin_d.items(), key=lambda x: x[0])
19763f57d70b088b869da4d01cd9de8ef3f6d247
23,377
from collections.abc import Iterable def split_iterable(ls: list, n: int): """将可迭代的数据分割成多个列表 :param ls: 可迭代的带下标的数据 (list, str) :param n: 每个列表数据的数量 (n>=1) :return list """ if isinstance(ls, Iterable) and isinstance(n, int) and n >= 1: result = [ls[i:i + n] for i in range(0, len(ls), n...
a9c79078bc89095b942343d866f64fff0800a15c
23,379
def get_node_datatext(node): """Returns a string with data node text if it exists on the node, otherwise returns an empty string""" datatext = "" if node.attributes["id"].value: for data_node in node.getElementsByTagName('data'): if data_node.attributes["key"].value == "d5": ...
b686cc52e0194440f0c86b9e6dfb12e4b7f2a1b4
23,380
import math import numpy import random def partition(array_to_partition, start_index, end_index, partition_style): """ There are various ways to choose a partition. The function returns the index of the passed array that is to be used as the pivot point. The following options are available for sortin...
30ebe40ace8796d4e06ff50956cd27a3b87481e1
23,381
def clean_up_string(string: str) -> str: """ Cleaning up string from invalid chars :param string: :return: """ return ''.join(s for s in string if s == '(' or s == ')')
719feee7d955ad7a788bccfe19998bbdcccf7464
23,382
def make_constructed_utts(utt_tokens): """ Converts utterances into correct form for composition Args: utt_tokens: List of utterances (utterance = list of tokens) Returns: utts: List of utterances for individual tokens and compositions compose_idx: List ...
57eaa008883b2cfde95b438251dc305478dac3f9
23,383
import functools def once(callable_): """ Call the given function at most once per set of parameters """ return functools.lru_cache(maxsize=None, typed=True)(callable_)
b95c38a1ae6120bbd9296457bd201503cd639b5d
23,384
import re def isbase64(value): """ Return whether or not given value is base64 encoded. If the value is base64 encoded, this function returns ``True``, otherwise ``False``. Examples:: >>> isbase64('U3VzcGVuZGlzc2UgbGVjdHVzIGxlbw==') True >>> isbase64('Vml2YW11cyBmZXJtZtestin...
02da2cfe0b32288aa599534dea08f4bc85a41123
23,386
def find_next_biggest_with_same_1s(n): """Finds the next biggest number with the same number of 1 bits. - Flips the rightmost 0 that has ones on its right (increases the value) - Rearrange 1s on its right to lowest positions and flips highest of them (decreases the value and creates same number of 1s...
d323a3d828929f9f6ae0c0ad6f2849e067a2eb8d
23,388
import argparse def parse_args(): """Argument Parser""" parser = argparse.ArgumentParser(description="Car Lane Joint Detection") parser.add_argument("-m", "--mode", choices=["image", "video"], default="image") parser.add_argument("--fps", type=int, default=20, help='registered frames-per-second for vi...
52dde0e6bd7aed1f285c9fc171175291d6670a71
23,390
import math def board_valid(board, current, i): """ Check if matrix is valid :param board: matrix :param current: tuple(matrix index) :param i: number :return: boolean """ if all([i != board[current[0]][x] for x in range(len(board))]): valid_col = all([i != board[x][current[0]]...
186601934dfa97bf3c4b7a14b0e1cfb64e52a44e
23,392
from typing import List from typing import Dict def get_single_color_dicts(self) -> List[List[Dict]]: """ Converts the text in the editor based on the line_string_list into a list of lists of dicts. Every line is one sublist. Since only one color is being applied, we create a list with one dict per li...
9ebcb28e59f6b05591c0c5465513aa9408952a62
23,393
def is_last_ts_in_thousands(timestamps): """Detect if the last timestamp in a sequence is a multiple of 1000. Args: timestamps (list): An list of timestamps (in picoseconds). Returns: True if the last timestamp is a multiple of 1000, False otherwise. """ if timestamps is None: ...
cb26d134eada9407415fefb4761ec265fa3c8f28
23,394
def fixture_srvr_jenny(): """Define example server data: Jenny.""" return { 'name': 'jenny', 'fullName': 'minecraft-main-server-jenny', 'environment': 'main', 'instanceId': '8675309', 'state': 'stopped', 'publicIpAddress': '10.11.12.13' }
b56d6606dae6b0e4df8ca537707eb24564bf7d37
23,395
def is_pos_int(num_str): """ Args: num_str (str): The string that is checked to see if it represents a positive integer (not 0) Returns: bool """ assert isinstance(num_str, str) if num_str.isdigit(): return int(num_str) != 0 return False
52b5dc71f9253518ee07e91cdf5e21e9d5e5588f
23,396
def create_group(key, name): """create a group of keys: node of our tree""" res = {} res['name'] = name res['key'] = key res['keys'] = [] res['groups'] = [] res['children'] = [] return res
f49e2c481b0f41a8e1cf15cb746f605b16abd52a
23,397
from typing import Callable from typing import List def _excluded_save_params( self, super_: Callable[[], List[str]], additionals: List[str], ) -> List[str]: """Method, exclude additional attributes. """ return super_() + additionals
38f39befc2974adf43e5591a5d5aca03f41d0c18
23,398
from typing import List def argv_pars(arguments: List[str]) -> int: """Returns second argv or 30. Args: argv (List[str]): sys.argv Returns: int: i >= 1, or 30 """ try: return max(int(arguments[1]), 1) except Exception: return 30
b96340f9d547e3fabd959f2fe9feb8cd0d3f4c47
23,399
def get_pentagonal_number(n: int) -> int: """Get Pentagonal number `P_n=n*(3n−1)/2` for a given number `n`.""" return (n * (3*n - 1)) // 2
4ec89c0428ea83ede1084877790edadb7b61b6d5
23,400
import secrets def _generate_token_value(): """Return a cryptographic, URL-safe token.""" return secrets.token_urlsafe()
4c5f4247260f2decb83c3f7a0e2049f169f78e3d
23,402
import os def get_duplicate_notebooks(repo): """ The function takes a repository and checks whether two or more notebooks with the same filename are present. Args: repo(Repository): python object representing the repository Returns: paths: list containing paths to note...
d08f1d3e643079cbec951e90f9e9329df0980adb
23,404
import numpy def _detector_camera( positions, intensities, shape=(256, 256), position=(0, 0), exposure=1, binning=(1, 1), axes=(-2, -1), ): """ """ yax, xax = axes ymin = position[0] - shape[0] // 2 ymax = position[0] + shape[0] // 2 + shape[0] % 2 xmin = position[1] - ...
3ad2e3ea6dc31785b5fa89afed3f47b8d65604bb
23,405
def cpf_checksum(cpf): """ CPF Checksum algorithm. """ if cpf in map(lambda x: str(x) * 11, range(0, 10)): return False def dv(partial): s = sum(b * int(v) for b, v in zip(range(len(partial) + 1, 1, -1), partial)) return s % 11 dv1 = 11 - dv(cpf[:9]) ...
cbe634578d50687d2b2aec5aa996123f25a03327
23,407
import argparse def get_arguments(): """Parse command line arguments""" parser = argparse.ArgumentParser( description = "Subset an alignment") parser.add_argument('-a', '--alignment', help = 'fasta alignment', required = True) parser.add_argument('-m', '--missing', help = 'miss...
2ba1deb591844e845262c6125f889794a0a26ced
23,408
def _findBeginning(file_name, loc): """Scan given TRY dat file and find end of header (start of data) Arguments: file_name {str} -- Name of TRY data file loc {str} -- Location of TRY data file Returns: (int, string) -- (lines before data starts, column hea...
20be3ccefafc61bfa3f769b993e5f53c667b37ba
23,409
def mhz_to_freq_khz(mhz): """ Convert MHz to exact frequency in kHz """ return { 14: 14100, 18: 18110, 21: 21150, 24: 24930, 28: 28200 }[mhz]
d7ec477c88b7e212e852aef407f2a31064d806a0
23,410
import base64 def encode_b16(msg: str) -> bytes: """ >>> encode_b16('ini contoh') b'696E6920636F6E746F68' """ encoded = msg.encode("utf-8") b16_encode = base64.b16encode(encoded) return b16_encode
7c0bb90c591d83d01e3bbbe84edd5f10c4a35bf3
23,411
def price_table_to_price_mapping(table): """Convert price table to a dict mapping from region to instance type to instance info """ region_price_mapping = {} for region_table in table['config']['regions']: types = {} for type_category in region_table['instanceTypes']: fo...
d39887b82be8ae37a20d73c830e7ef724553600e
23,413
import hashlib def hash16(data): """ Return a hex string of the data's hash. Currently uses md5. """ hash_object = hashlib.md5(bytes(data, 'utf-8')) return hash_object.hexdigest()
bed6d51832f1354990c08c0c27f883e99f00ddd7
23,414
def tranche99(filt, cutoff=99.6): """ return True if the tranche is below 99.6 VQSRTrancheINDEL90.00to99.00 """ if filt is None: return True if filt[:4] != "VQSR": return False try: return float(filt.split("to")[1]) < cutoff except: return False
039090762623500b804ac222fbb7bf2f8a55402f
23,415
def get_empty_string(submission_json): #pylint: disable=unused-argument """ Empty String - For consistency in defining the map """ return ""
23550c53f7b6e8d22e0a553c1642b1ef480faaab
23,418
def dict_to_css(css_dict, pretty=False): """Takes a dictionary and creates CSS from it :param css_dict: python dictionary containing css rules :param pretty: if css should be generated as pretty :return: css as string """ seperator = '\n' tab = '\t' if not pretty: seperator = '' ...
03c489e2cb3f855fad2e2476c33fc2806be9043f
23,419
def list_insert(collection, position, value): """:yaql:insert Returns collection with inserted value at the given position. :signature: collection.insert(position, value) :receiverArg collection: input collection :argType collection: sequence :arg position: index for insertion. value is insert...
d4a6bf1af3845112b688a867221f6e070a5eac95
23,420
import pandas as pd def load_exercise_threshold_app_data(data_dict={}): """Loads data from data dict with format provided by https://www.exercisethresholds.com/ Parameters: data_dict (dict) : Dictionary with format like test/exercise_threshold_app_test.json Returns: df (pandas df) : Pand...
e872a00d6cb32e2976c393e175fd5580e663c4df
23,421
def avg(iterable): """Simple arithmetic average function. Returns `None` if the length of `iterable` is 0 or no items except None exist.""" items = [item for item in iterable if item is not None] if len(items) == 0: return None return float(sum(items)) / len(items)
1489cf0a828e8c1613453d04abb8773658d60e8e
23,422
def _validate_alphabet(seq): """Validates the encoding alphabet *seq*. Returns :const:`None` if input is invalid, otherwise returns a string copy of the valid alphabet. >>> a = [chr(x) for x in xrange(35, 35 + 85)] >>> print _validate_alphabet(a) # doctest: +ELLIPSIS #$%&...tuvw >>> print...
c3d9e5a243c13a1de5802f8a48faaa29f9f24bd8
23,423
def remove_negative_sum(arr): """ recursive funtion to find and remove starting sequence that yeilds negative value """ _sum = 0 for idx, num in enumerate(arr): _sum += num if _sum < 0: return remove_negative_sum(arr[idx + 1:]) return arr
e1324c0d4ecb8e7382e33f70c0aaf76fa5f87718
23,424
import os def _envvar_to_bool(envvar: str) -> bool: """Convert environmental variable values to bool.""" envvar_value = os.environ.get(envvar, False) envvar_bool = bool(envvar_value) and (envvar != "0") and (envvar.lower() != "false") return envvar_bool
1eb0acd5437fe6a564f26b584cd7b865053cbd65
23,426
def dict_from_tokens(tokens, value): """Build a dict-tree from a list of tokens defining a unique branch within the tree. Args: tokens (list): A list of tokens defining a branch within the nested dict value (any): An object set as the leaf of a branch Returns: dict: A nested di...
dd3b9e72208ba404354f9bd98c8a4a8d80609611
23,427
def mk_falls_description(data_id, data): # measurement group 8 """ transforms a h-falls-description.json form into the triples used by insertMeasurementGroup to store each measurement that is in the form :param data_id: unique id from the json form :param data: data array from the json form ...
1e0c304538159b9bb01d677bdacdfa9a0b3b4e4d
23,428
import inspect import sys def get_all_psf_models(): """Used to display choices in generate.py""" classes = [obj for name, obj in inspect.getmembers(sys.modules[__name__]) if inspect.isclass(obj)] psf_models = [] for cls in classes: if 'Psf' in cls.__name__ and cls.__name__ != 'PsfModel': ...
fbec1f06fdc971fdcdaf38d803869d9b27cc1e29
23,429
def sequence_producer(templates_num,sequence_storage): """ This function aims to convert the a dictonary to a set of sequences, then we can think of it as a time series problem @input parameters : templates_num -> the total numbers of distint template. sequence_storage -> A dicti...
3dd4130d38951c46863f662bf83bf2c0d0f4d14a
23,431
def addMessage(row_num, valid, new_msg, messages): """ Add error message to the list of errors and set the validity""" if new_msg: if "Error" in new_msg: valid = False match = False for msg in messages: if new_msg == msg[1]: match = True ...
899f2c4168ccfbc1fe66ffd35f6b4ad008d6f032
23,432
def get_lines_from(hand, track_num, fps, ticks_per_ms): """ goes through a hand array and converts its information into the form required for the csv file :param hand: a matrix that has the information of what is being played by a hand :param track_num: what track number to give this hand :param fps...
85fab955961704250c00314fafadd013dfed97fa
23,433
from typing import Dict def word_count_helper(results: Dict) -> int: """ Helper Function that computes word count for ocr results on a single image Parameters ---------- results: Dict (OCR results from a clapperboard instance) Returns ------- Int Number of words ...
aaf4b9b6e430c13b804ed96374eecddb134a31ae
23,434
def _findString(text, s, i): """Helper function of findString, which is called recursively until a match is found, or it is clear there is no match.""" # Find occurrence i2 = text.find(s, i) if i2 < 0: return -1 # Find newline (if none, we're done) i1 = text.rfind("\n", 0, i2) ...
a5a87b6c023d09b10d9473c852350a2b56d999da
23,435
import argparse def cli_mode(): """ Configurations fo CLI to run program with. Will be set to default values if run in other environments. :return: Parsed arguments from CLI """ parser = argparse.ArgumentParser(description="Manual to use this script:", usage="python main.py mode model") pars...
cdedd9f98a78c9eba09543b293c48e8c8b386a24
23,436
def get_main_logon_do_form(): """ Assemble form for get_main_logon_do :return: form in dict """ post_data_dict = dict() post_data_dict['continueUrl'] = 'http://www.sd.10086.cn/eMobile/jsp/common/prior.jsp?menuid=index' return post_data_dict
6ff17e1729c5d54a2ed8f68f04f0cf0a2462000b
23,437
import sys def getFormByName(qualifiedName): """ converts 'module_name.forms.FormName' to a class object """ appName, forms, className = qualifiedName.split('.', 2) formsName = '%s.%s' % (appName, forms) __import__(formsName) mod = sys.modules[formsName] return getattr(mod, className)
54a1bbb671f2bce077298bde9770300fbe70399a
23,438
def get_num_train_images(hparams): """Returns the number of training images according to the dataset.""" num_images_map = { 'imagenet': 1281167, 'cifar10': 50000, } if hparams.input_data.input_fn not in num_images_map: raise ValueError( f'Unknown dataset size for input_fn {hparams.input_...
e75e827026b247158ca76890990b04d51cd99a6a
23,439
def all_constant_input(node): """Find the inputs of the given node. If the inputs of this node are all\\ constant nodes, return True. Otherwise, return False. :param node: the input node which has a Node structure\\ :return: whether the node of this node are all constant """ if node.proto is No...
2fd23ad7dec2bb8c77da2d18b875e7030e1c122a
23,440
import os def getfilenames(): """Gets the filenames of the dynamic trial, static trial, vsk file, and output file and returns their file paths. The example filenames below are found in the SampleData folder in the git repository. Returns ------- tuple A tuple of four strings that incl...
637d11a01397b53ee82bb45b0876357fc2f1995f
23,441
def _same_file_up_to_epsilon(filen1, filen2, eps=1e-9): """_same_file_up_to_epsilon Return True if filen1 and filen2 contains the same float data up to epsilon Args: filen1 (str): The path and name of the first filename filen2 (str): The path and name of the second filename eps (flo...
5aea46a44ce5d5df0e8c32ea4c59f34b4751d492
23,442
import sys def convert_to_unicode(value): """ Python 2.x: converts value to unicode :param value: value to be converted to unicode :type value: str :return: unicode string :rtype: str (unicode) """ try: return value.decode(sys.getfilesystemencoding()) except AttributeError...
06f75c9c3b4b6ea4664c71dd389d4fd0de9739ad
23,444
import mimetypes def get_extension(value): """Take in mimetype and return extension.""" mimetypes.add_type("audio/wav", '.wav') extension = None preferred = [".txt", ".jpg", ".mp3"] all_extensions = mimetypes.guess_all_extensions(value) if all_extensions: for ext in all_extensions: ...
b559f3762cf7ad2bf5ad20c59f2bbea21ee6a932
23,445
import argparse def _comma_separated_pyramiding_policies(string): """Parses an input consisting of comma-separated pyramiding policies.""" error_msg = ('Argument should be a comma-separated list of: ' '{{"mean", "sample", "min", "max", "mode"}}: {}') values = string.split(',') if not values: ...
513449b4b2cad4ac3831bb16975aa5c2266889a0
23,447
def unite_statuses(statuses, update): """ Takes two dictionaries <hostname, hoststatus> and returns dictionary with united entries (returncode is set to the max value per host, logs per host are concatenated)""" result = {} for key, value in statuses.iteritems(): if key in update: upd_status = update[...
c0454e3fdc0ccda0c6cabf3ac2ee479aacbfee27
23,448
def stringify(value): """ Escapes a string to be usable as cell content of a CSV formatted data. """ stringified = '' if value is None else str(value) if ',' in stringified: stringified = stringified.replace('"', '""') stringified = f'"{stringified}"' return stringified
74d5683a79e7efab48ec24767d1c912b66c0e65b
23,450
import math def get_bpd(log_p, dimentions=28*28): """ bpd = (nll_val / num_pixels) / numpy.log(2). log_p: log probability dimentions: dimentions (resolution) of image """ return ((-log_p / dimentions) / math.log(2)).mean().item()
a1ba8c8e688988ef0b02ec555e5b31ffc5408d2a
23,452
def nb_coverage_distance(epitope, peptide, mmTolerance = 0): """Determines whether pepitide covers epitope and can handle epitopes and peptides of different lengths. To be a consistent distance matrix: covered = 0 not-covered = 1 If epitope is longer than peptide it is not covered. ...
46b88f83934465e8bb4b30f144b5acc2791c809a
23,455
def get_timespan(): """ function to ask the user for the two timespans which he wants to compare returns a list of the 4 border years author: Leo Raises ------ ValueError if they aren't in ascending order or outside the datarange Returns ------- timespan: list of the...
fa27f08e54d1432e4b9a153a4ee159cc374ee798
23,457
def construct_unsent_berichten_query(naar_uri, max_sending_attempts): """ Construct a SPARQL query for retrieving all messages for a given recipient that haven't been received yet by the other party. :param naar_uri: URI of the recipient for which we want to retrieve messages that have yet to be sent. ...
ff380f1dd2edc77f6ee41376f6c1d8ee50448d43
23,458
def _roman_to_int(r): """ Convert a Roman numeral to an integer. """ if not isinstance(r, str): raise TypeError(f'Expected string, got type(input)') r = r.upper() nums = {'M': 1000, 'D': 500, 'C': 100, 'L': 50, 'X': 10, 'V': 5, 'I': 1} integer = 0 for i in range(len(r)): try: ...
f91c88cbdd6ca31ae811a2300b45fb5a6df3ea91
23,459
def find_min_cost(M, start_node, memo): """Returns minimum length of tour. Connects tour back to starting node and minimizes the cost. """ n_nodes = len(M) # the end state is a bit mask with all bits set to 1 END_STATE = (1 << n_nodes) - 1 min_cost = float('inf') # the end node is th...
e291572734669c9aefd3557de0e9e69280012e35
23,461
import numpy as np def weighted_avg_and_std(values, weights, axis=None): """ Computes weight average and standard deviation Parameters ---------- values : :obj:`array` Input array weights : :obj:`array` Must be same shape as ``values`` axis : int , optio...
4b2cbd2b412174e0035414de23d36f66e29470b6
23,462
import re def match_absolute_path(path: str) -> bool: """ Return true if the path starts with ``http(s)://``, false otherwise. Args: path (str): URL Returns: bool: True for absolute URL, false for relative URL. """ return re.match(r"http(s)*://*", path, re.IGNORECASE) is not ...
8b508b76fc0f5102c687a202a0ffab26631eaf8b
23,463
def fps(branch): """ extracts function #, process #, and scan # from the idstring of a spectrum branch returns function, process, scan as integers """ idstring = branch.getAttribute('id').split() # pull id string from scan attribute return [int(x.split('=')[1]) for x in idstring]
a470d609d2c8c15c88bbaba539c587410c03394a
23,464
import timeit def stages_of_timing(): """ Show when stages are invoked. Demonstrates that 'setup' is invoked once before each repetition. Shows that the statement is repeated 'number' of times. Also observe that the state is shared from one number to another (but not across repetitions. ...
bfcaa41ae745e39144899ecaf7a4ff4e60ef8e2d
23,465
def partition(alist, indices): """A function to split a list based on item indices Parameters: ----------------------------- : alist (list): a list to be split : indices (list): list of indices on which to divide the input list Returns: ----------------------------- ...
b14040058d96d66acf81e0bff8eedfe23df20738
23,466
from typing import Counter def count_elements(data_lst): """Count how often each element occurs in a list. Parameters ---------- data_lst : list List of items to count. Returns ------- counts : collections.Counter Counts for how often each item occurs in the input list. ...
a12f0a35a228e8a8627a8fcfc703d3231984e3f4
23,467
def i_love_python(): """ Let's explain why do we love Python. """ return "I love Python!"
0ce72c35822f52b6cf9153b79555418c1b739f09
23,468
import re def clean_text_from_private_unicode(line): """Cleans the line from private unicode characters and replaces these with space.""" line = re.sub(r"([\uE000-\uF8FF]|\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDDFF])", " ", line) return line
0ad7f47446dfb91069003c3fce0d1129dcb71113
23,469