content
stringlengths
35
416k
sha1
stringlengths
40
40
id
int64
0
710k
def filter_fires(im): """ Earth engine QA filter for fires """ burn_dates = im.select("BurnDate") valid_dates = burn_dates.gt(0).And(burn_dates.lt(367)) valid_qa = im.select("QA").lte(4) # keep QA values 1-4 (5 is detection over agricultural areas) mask = valid_dates.And(valid_qa) r...
8e5d71058d39e8b5cf4c78f0e50db80d36d343cc
38,131
def attack(encrypt_oracle, decrypt_oracle, iv, c, t): """ Uses a chosen-ciphertext attack to decrypt the ciphertext. :param encrypt_oracle: the encryption oracle :param decrypt_oracle: the decryption oracle :param iv: the initialization vector :param c: the ciphertext :param t: the tag corre...
a7ad7b0b3a73c3af9711a51e45a4f2659527f65a
38,132
def word_overlap(left_words, right_words): """Returns the Jaccard similarity between two sets. Note ---- The topics are considered sets of words, and not distributions. Parameters ---------- left_words : set The set of words for first topic right_words : set The set of...
3baa3ec5605bef4658815ac4d546539c480ae4b5
38,133
def shorten(name): """ Shortens a name and adds some ellipses """ if len(name) > 10: name = name[:10] + '...' return name
3b2a0bcdff21d41ff28b99dfbd833cc3e6d7d497
38,134
import os import sys def getPythonCommand(): """ Method to get the prefered python command. @ In, None @ Out, pythonCommand, str, the name of the command to use. """ if os.name == "nt": pythonCommand = "python" else: pythonCommand = sys.executable ## Alternative method. However, if call...
be40fe72fd0c3ade3c3e8f4691a433c9d0191c2a
38,135
import argparse def parse_args(): """Parse command line arguments""" parser = argparse.ArgumentParser(description='Process input files') parser.add_argument('-w', '--watson', type=str, default=None, help='watson (top strand) .vcf file input.') parser.add_argument('-c', '--crick...
fbe7583ab1f4d9302209d546730254644da24d61
38,137
def convert_weight(val, old_scale="kg", new_scale="pound"): """ Convert from a weight scale to another one among kg, gram, and pound. Parameters ---------- val: float or int Value of the weight to be converted expressed in the original scale. old_scale: str Original scale from ...
d38fed48ac998b8c21b8dd25fb497479d04e899a
38,138
def list_filter(data, sequence): """过滤试题库列表,保留特定的信息""" new_data = list() for i in range(data.__len__()): if i in sequence: new_data.append(data[i]) return new_data
9381fcdbdc6c21c5a9a062fe02576ef0c43ee5a3
38,139
import itertools def NumOfNonTrivialPairs(n): """Example: (a,b)(c,d) or (a,c)(b,d) are trivial, but (a,d)(b,c) is not.""" assert n == n/2*2 num = 0 for seta in itertools.combinations(range(n), n/2): setb = [i for i in range(n) if i not in seta] altb = [True]*(n/2) for i in range(n/2): if set...
27e1f5caa13431a68e1211f695ae9c6cb1f43564
38,140
def is_chinese(target_str): """ determine whether the word is Chinese Args: target_str (str): target string """ for ch in target_str: if '\u4e00' <= ch <= '\u9fff': return True return False
ee75d9ea6d6e396964f511c10eaeeaf96a836aaa
38,141
from pathlib import Path def find_in_nbs(fullname, path=None): """ lookup a notebook file to import """ nb_path = '/nbs/' + fullname + '.ipynb' if Path(nb_path).is_file(): return nb_path # allow import Notebook_Name for Notebook Name.ipynb nb_path = nb_path.replace("_", " ") if Path(nb...
9e2009311e53c964972ae23eb47c2382e1e0cb57
38,142
import sys def _environment(): """Collect some useful system information""" data = {} data['os'] = sys.platform data['pyversion'] = '{0:x}'.format(sys.hexversion) data['encoding'] = sys.stdout.encoding or sys.getfilesystemencoding() return data
71caf742e766b9f9937243977c0f2093a129b9a4
38,143
def format_record(record): """Format float values to high precision, not in exponential form.""" return [f'{r:.15f}' if isinstance(r, float) else r for r in record]
a4b6b25ac429129d843ef59b25d9ae9fc7531969
38,144
import math def inverseJukesCantor(d): """Takes a substitution distance and calculates the number of expected changes per site (inverse jukes cantor) d = -3/4 * log(1 - 4/3 * p) exp(-4/3 * d) = 1 - 4/3 * p 4/3 * p = 1 - exp(-4/3 * d) p = 3/4 * (1 - exp(-4/3 * d)) """ assert d >= 0.0 re...
648f091d2a8daf0b41cf939c007e50f6c0eef52a
38,145
def cnvtol(self, lab="", value="", toler="", norm="", minref="", **kwargs): """Sets convergence values for nonlinear analyses. APDL Command: CNVTOL Parameters ---------- lab Valid convergence labels. If STAT, list the status of the currently specified criteria. value T...
632a895db755cdf23c88b1df88700cb9c0529f69
38,147
import os def setup_dirs(config): """Set dirs from config, because now we doesn't use hydra. Only for demo notebook""" # model_save_dir model_save_dir = os.path.join(os.path.abspath(config.model_dir), config.model.model_name_or_path, conf...
b2af330b9bf8fdcf7e1db3dbf3a7c3f22f7beaed
38,148
from typing import Any def find_key(d: dict, key: str) -> Any: """Finds a key nested arbitrarily deeply inside a dictself. Principally useful since the structure of NRPE relation data is not completely reliable. """ if key in d: return d[key] for child in d.values(): if not is...
e6b176450d25ea1e194019c7d4bdb85d500488ae
38,149
def gather_results(detectors): """ Execute the d.compute method for each given detector. After that the result (d.getDetectorOutput()) method is called and added as value under the key d.getName() to the result which is returned in the end. :param detectors: :return: """ results = {} ...
10366cc7880474f54d093c5f4bd8c11b4b454aab
38,150
def _find_label_rows(sheet): """Search excel file column A for cells containing 'Label'. Return a list of zero-indexed rows. """ label_rows = [] for i in range(sheet.nrows): if "Label" in sheet.cell_value(i, 0): label_rows.append(i) return label_rows
5515874500c5ef514df02019e745d609b0474b2f
38,151
def get_request_data(request, keys): """For HTTP functions""" data = {key: None for key in keys} json_data = request.get_json() param_data = request.args for key in keys: if key in json_data: data[key] = json_data[key] elif key in param_data: data[key] = param...
1904bd3083a764b7fa85199d11176423f2143775
38,153
import argparse def _parse_argument(): """Return arguments for Model Freezer for NeuroPilot Model Hub.""" parser = argparse.ArgumentParser( description='Model Freezer for NeuroPilot Model Hub.', formatter_class=argparse.ArgumentDefaultsHelpFormatter ) parser.add_argument( '--in...
a1d1505223522e7dfb15a92e8975e1d5f71df044
38,155
import hashlib def hash_all(strs, digest=None): """Returns a hash of the concatenation of all the strings in strs. If a hashlib message digest is not supplied a new sha1 message digest is used. """ digest = digest or hashlib.sha1() for s in strs: digest.update(s) return digest.hexdigest()
585496aaae534d24cba512482765aeb9250ef6b8
38,156
import socket import struct def parse_ipv6(addr): """ Return a numeric representation of the given IPv6 address. """ binary_ip = socket.inet_pton(socket.AF_INET6, addr) high, low = struct.unpack('!QQ', binary_ip) return high << 64 | low
6456d02ae7b4b5eadd2666fad7308ef5547b98dc
38,157
import os import shutil def delete_folder(path): """ Deletes the folder from the given path :param path: path to folder to delete :return: True if the directory was successfully deleted, False otherwise """ if not os.path.isdir(path): return False shutil.rmtree(path) return os....
aa40026fe7c36e8eba6a5dddd40744ad9380056d
38,158
def get_protein(chain): """ Get protein (residues without hetero-residues). """ return [residue for residue in chain.get_residues() if residue.full_id[3][0] == ' ']
f5d20e0a7edf15f3a90a4b2c3f889211cb44d87d
38,159
import zlib def text_decompress(text) -> str: """对文本进行解压 Args: text (str or bytes): 待解压文本 Returns: str: 解压后的文本 """ return zlib.decompress(text).decode() if type(text).__name__ == "bytes" else text
933d8fe5ac4f615b60831551deee80fc429171ac
38,160
def is_rect_intersection(minlat, maxlat, minlon, maxlon, latitude, longitude): """ Checks if there is a radial intersection between a point radius boundary and a latitude/longitude point. :param: minlat : the minimum rectangular latitude :type: float :param: maxlat : the maximum rectangular latitude...
39f872e74a9cf6d77521a5a5666bf8701662ba0c
38,161
import numpy def vectorspaced(document, all_terms): """ :param document: document object :type document: TrainingDocument :returns: distance vector """ return numpy.array([ document.termsWithWeights.get(word, 0) for word in all_terms ])
e95c4b90818e77df874377b1f9853e5b85d78805
38,162
from datetime import datetime import time def rddToFileName(prefix, suffix, timestamp): """ Return string prefix-time(.suffix) >>> rddToFileName("spark", None, 12345678910) 'spark-12345678910' >>> rddToFileName("spark", "tmp", 12345678910) 'spark-12345678910.tmp' """ if isinstance(tim...
ecf09d0fc16b23b892635197c87495ad8aa42bdf
38,163
def get_word_by_id(word_id): # noqa: E501 """Find word by ID Returns a single word # noqa: E501 :param word_id: ID of word to return :type word_id: str :rtype: Word """ return 'do some magic!'
fbbb62d8f89637c304df0175c2846f098ae08c12
38,164
def group_com(mat_A, mat_B): """Compute the group commutator A B A^dagger B^dagger for two matrices A, B.""" return mat_A @ mat_B @ mat_A.T.conj() @ mat_B.T.conj()
b84170a21fc85f7a3dc68014483137804661f3c0
38,165
import subprocess def run_command(cmd): """ Run a shell command The stdout is shown. Returns the error code """ rv = subprocess.call(cmd, shell=True) return rv
e761609a5338a0d5e5273d5cfcfbe7f923f5d4f6
38,167
def parse_json(j): """ Awful hack to parse a restricted subset of JSON strings into Python dicts. """ return eval(j, {'true':True,'false':False,'null':None})
27036ce0fd6adaedacf9cf81fadf12a14305939f
38,168
from pathlib import Path import os def obtain_base_dir(): """Obtains the base directory to use Returns: A Path object """ path = Path(os.path.expanduser("~")+"/tfbasemodels") path.mkdir(exist_ok=True) return path
d6dbf240fceb09d7a5a70aed242df8e91a959d64
38,169
def compare_dict_keys(dict_a, dict_b, compare_keys): """Compare two dictionaries with the specified keys""" return all(dict_a[k] == dict_b[k] for k in dict_a if k in compare_keys)
00de8cc97f8b56608575570150a97038ed61b997
38,170
def OverrideToImplementCustomLogic(obj): """Users should override this in their sub-classes to implement custom logic. Used in Trainer and Policy to tag methods that need overriding, e.g. `Policy.loss()`. """ return obj
3d3993be19e3f6315bfb7a77f1d9ef1946722eca
38,171
def get_index(sheet, *names): """ Returns the column index for the first matching name, assuming first row is header Matching is done with leading and trailing whitespace stripped, and case insensitive """ header = [(c.value or "").strip().lower() for c in sheet[1]] for name in names: na...
45af5638cc66fb51a4addbf8ecec27ffadd2cf09
38,174
import sys import os def mainopt_mac_uk(i): """<from-format> [<text>] Speak text in Mac OS 10.7+ British voices while using a lexicon converted in from <from-format>. As these voices do not have user-modifiable lexicons, lexconvert must binary-patch your system's master lexicon; this is at your own risk! (Superuse...
04199be2cae16010323cadcf2ce2bab96d1bd20f
38,175
def get_min_move_unit(stock_code): """获取股票最小移动单位 股票为0.01,ETF及分基金等0.001""" stock_code_int = int(stock_code) if stock_code_int < 100000: return 0.01 elif 600000 <= stock_code_int <= 699999: return 0.01 elif 300000 <= stock_code_int <= 399999: return 0.01 else: retur...
2d1173bde9935bddd907fd2c2254674508f30104
38,179
def _hex_to_triplet(h): """Convert an hexadecimal color to a triplet of int8 integers.""" if h.startswith('#'): h = h[1:] return tuple(int(h[i:i + 2], 16) for i in (0, 2, 4))
e84b3de0d94eda11a63390cfd0448708bd69cc66
38,180
def create_routes(name: str) -> str: """ Mutations Routes :param name: :return: """ routes = ''' class Create%s(graphene.Mutation): """ Create %s Record """ class Arguments: createRecord = %sRecord(required=True) message = graphene.String() id = graphene.Int...
d228cc9839e27a9ce72fa3152e86f6797d07319d
38,181
def get_json(self, request): """ Retrieves the loaded JSON information from the request this method assumes that the request is properly formed and that the header information is set in accordance with JSON. :type request: Request :param request: The request to be used. :rtype: Object :...
a170154e0a166a495f60246158b15267dc768772
38,185
def unique_color_from_identifier(identifier): """Return unique color as RGB tuple. Useful for creating PNG images where each color is used as an identifier. Raises TypeError if the identifier is not an integer. Raises ValueError if the identifier is not in the range 0 to 16777215 inclusive. ...
dcf3555c95e6799c1d9042c2342d9181e44d56cd
38,186
def calc_tstop(num_bins, binsize, t_start): """ Calculates the stop point from given parameter. Calculates the stop point :attr:`t_stop` from the three parameter :attr:`t_start`, :attr:`num_bins` and :attr`binsize`. Parameters ---------- num_bins: int Number of bins binsize: qu...
b8e6e7fc3cb92b8f505f757d2e75259d9a208fa8
38,187
from re import search from dateutil.parser import parse def detect_date(token: str): """ Attempts to convert string to date if found mask_test = r'(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s+(\d{1,2})...
ddc72ba38b6a2c757d6ce366a45e2a5a689e6b9c
38,188
def get_recall(rec, tru): """Recommendation recall: |{R & P}|/|P| (R - recommended products, P - relevant products)""" return len(rec & tru)/len(tru) if len(tru) != 0 else 0
83ec9f53a43a8d4f0b2d6174457cd8a7937a1bed
38,189
import json def load_config(config_files): """ loads json configuration files the latter configs overwrite the previous configs """ config = dict() for f in config_files: with open(f, 'rt') as cfg: config.update(json.load(cfg)) return config
4a61ca063bf8147a0f2576cddc8bf438b33f8792
38,192
def lex_next_bits(i): """Return next number with same number of set bits as i.""" # i = xxx0 1111 0000 smallest = i & -i; # 0000 0001 0000 ripple = i + smallest; # xxx1 0000 0000 ones = i ^ ripple; # 0001 1111 0000 ones = (o...
72cf874bdf4045bf9c9d0d03a0016c48df469df6
38,193
import os def read_tracks(filename): """Read the text file and load it into a dictionary with frame number as the keys and the objects and its positions as values. Parameters ---------- filename : str The directory of the video whose tracking data should be shown. The text file wi...
53935da33cfe5fed488a68ea5e0a38b66a3df517
38,194
from typing import Optional def askyn(question: str, default: Optional[bool] = None) -> bool: """ Asks a yes or no question and returns a bool. REF: https://gist.github.com/garrettdreyfus/8153571 """ # Modify the question with the default value capitalized if default is not None: if de...
f038ffce000e5c39d707dd61d3f1967195df4e6d
38,195
import torch def box_center_to_corners(b): """ Converts a set of oriented bounding boxes from centered representation (x_c, y_c, w, h, theta) to corner representation (x0, y0, ..., x3, y3). Arguments: b (Tensor[N, 6]): boxes to be converted. They are expected to be in (x_c, y_c, w,...
0ab937e31fc8c2e67748b5d791a7061fa0fb70fe
38,196
from typing import List def get_requirements(fname: str) -> List[str]: """このパッケージが依存しているパッケージのリストをrequirements.txtから取得して返す。 Args: fname (str): requirements.txt Returns: 依存しているパッケージのリスト """ with open(fname) as fp: lines = fp.readlines() requires = [line.strip() for line ...
b2e22394f16eeda41ac34f31cdad6e3a3732da31
38,197
def make_iterator(it): """ Create iterator from iterable. """ return iter(it)
ec683c4d109fd9afedc57b1a9476080400930122
38,199
from pathlib import Path def get_datapath_base(data_type: str, filename: str) -> Path: """Return the path to the footprints test data file""" return Path(__file__).resolve(strict=True).parent.joinpath(f"../data/{data_type}/{filename}")
9bccb92b1c4a5dbaa625b2fa52b3c77163104c11
38,200
from typing import Collection def find_valid_words(dictionary: Collection[str], candidates: Collection[str]) -> Collection[str]: """Finds valid words from 'candidates' as found in the given words list. dictionary: the list to be used as a dictionary. Only strings in the dictionary are considered valid wor...
14706ca99787869d0eee1c77a929bc1f34cf2238
38,201
def matchingTest(vector): """ input: a list of corr coeff scores from moments output: match or not criteria: all > 0.9 - yes all > 0.8, all but one > 0.9, four>.99 - yes else - no """ point99 = len([v for v in vector if v>0.99]) point9 = len([v for v in vector if v>0.90]) po...
bfc0bd830948cb0c5f4f6342c699ef280d0c4480
38,202
def drop_column(df, columns_to_drop): """ Removes columns from a DataFrame del df[name] Args: df (`pandas.DataFrame`): The dataframe to drop columns on columns_to_drop (:type:`list` of :type:`str`): A list of the columns to remove Returns: `pandas.DataFrame`: `df` ...
1eadbf301aff80752c93ca4393910dfa19a76b3a
38,203
def match_children(node, node_function_dict): """Returns. a list of node, function pairs. Matches the children of the passed in node to parse functions in the passed in dictionary. The node tags are used as keys. Ignores nodes which get no match. """ return [(ch, node_function_dict[ch.tag]) ...
1de01787a452b7784f6cefe7c37327fe6ce043d4
38,207
def makeScalarProduct(vector1, vector2): """ calculating the scalar product vector1 x vector2 """ return vector1[0]*vector2[0] + vector1[1]*vector2[1] + vector1[2]*vector2[2]
1b8d4f3478dd16630336c02917fc60e3479f689d
38,208
def mini_mock(): """ Allows the tests to assert more accurately about the state of the object's properties than a full-blown mock allows. """ class MiniMock(object): def __init__(self, **kwargs): pass return MiniMock
64d2c6a2377d495c53056421d93f11fe86de5e39
38,209
def add_commas(num: int) -> str: """Adds commas to an integer in the international number format - 1000 -> 1,000 - 100000 -> 100,000 - 1000000 -> 1,000,000 Args: num (int): The number Returns: str: The number with commas """ return "{:,}".format(num)
9f63a6389df5b46ebbe0dc7489d4967919da18d7
38,210
import subprocess import os def upscale_ngx(inpath, outpath, workingImage, settings): """Runs a denoising process on the texture specified""" ISRExe = settings["NGX_ISR_Exe"] ISRScalingFactor = settings["NGX_ISR_ScalingFactor"] cmd = [ISRExe, "--input", inpath, "--output", outpath, "--factor", s...
acc3cb535b53ed76783803267c0590dba98cc55e
38,211
from typing import Iterable from typing import List import locale def sorted_locale(iterable: Iterable[str], *, reverse: bool = False) -> List[str]: """Sort a list of strings according to locale. Parameters ---------- iterable : iterable of str A list of strings. reverse : bool, default=F...
e5092e7343989757ffe5fad9bfaf26637b6b5834
38,212
def gram_matrix(y): """ for each channel in C of the feature map: element-wise multiply and sum together return a C*C matrix """ (b, ch, h, w) = y.size() features = y.view(b, ch, w*h) features_t = features.transpose(1,2) gram = features.bmm(features_t) /(ch*h*w) return gram
7026a6b6f42f10e1c6c1625a32c75c823c1bb57a
38,214
from math import sin, cos, sqrt, atan, radians def calc_distance(position_start: tuple, position_end: tuple) -> float: """Calculates the distance between two positions in format (lat, lon) """ f = 1 / 298.257223563 a = 6378173 F = radians((position_start[0] + position_end[0]) / 2.0) G = radian...
c330e7e0e45f7643c7c14c6b066a854a97bd196a
38,215
import pandas as pds def same_missing_modality_tsv(file1, file2): """ Function that is used to compare 2 TSV files generated by the iotool ComputeMissingModalities. Only fields participant_id, pet, t1w, func_task - rest are compared. Line order does not matter. Args: (string) file1: path to...
3d15797f9070af31c65bc9278cd95a1058e4061b
38,216
def find_common_parent(a, b): """Find a common parent for 2 elements.""" a_parents = list(a.iterancestors()) b_parents = list(b.iterancestors()) a_parents_set = set(a_parents) b_parents_set = set(b_parents) if a == b: return a if b in a_parents_set: return b if a in b_par...
b99a865cde17f79b159d26528f5db97137d6c162
38,217
def parse_style(style_string: str) -> dict: """[summary] Args: style_string (str): [description] Returns: dict: [description] """ return {kv.split(':')[0]:int(kv.split(':')[1]) if kv.split(':')[1].isdigit() else kv.split(':')[1] for kv in style_string.split(';')}
4aef99cdb82628ee03f183bf9d876032f80d226c
38,218
def simple_features(): """ Create a list of features representing a network There are 3 features in a flat line running from 0,0 to 300,0 Each feature is 100 units in length """ return [ { "properties": {"EDGE_ID": 1}, "geometry": {"type": "LineString", "coordinat...
d9692e15ae9e4bb1828cc3035c38616847852a3b
38,219
def strip_schema_version(json_dict): """Returns the given JSON dict after stripping its schema version out :param json_dict: The JSON dict :type json_dict: dict :returns: The JSON dict with its schema version stripped out :rtype: dict """ if 'version' in json_dict: del json_dict['v...
2c5e7b5bfb401e1adef5479f0d787c2788d1d735
38,220
def get_machine_from_parent(self): """Get machine object from parent Parameters ---------- self : EEC an EEC object Returns ---------- machine : Machine a Machine object """ parent = self.parent # Try to find simulation parent (output.simu.elec.eec) while p...
82ccddac9f58727f36a9a78be741d2b5dba3369c
38,224
def sum_square_difference(ceiling): """Compute the difference between the sum of squares and the square of the sum of the natural numbers up to and including the provided ceiling. """ numbers = range(ceiling + 1) sum_squares = sum(map(lambda number: number**2, numbers)) square_sum = sum(numbers...
5898969697c2c8500dda0d0ef9ca5f3e7125ff77
38,225
def sine(r, periods): """Sine-wave primitive""" def _record(pen): dp = type(pen)() pw = r.w / periods p1 = r.point("SW") end = r.point("SE") dp.moveTo(p1) done = False up = True while not done: h = r.h if up else -r.h c1 = p...
b1fdee05797e9e7d3e398f639fd8ed2b7a10668c
38,226
import fnmatch def fnmatch_all(names, patterns): """Determine whether all strings in `names` match at least one of the `patterns`, which should be shell glob expressions. """ for name in names: matches = False for pattern in patterns: matches = fnmatch.fnmatch(name, pattern...
52be9c216d222fed331a836d529bc1399ba8e9b4
38,227
import sys def ask_user(dapr_name, query_type, results): """Ask the user to choose from a list of results.""" print("%-8s %-6s got %2d results. Which is it?" % (dapr_name, query_type, len(results))) for i, result in enumerate(results, start=1): info = result['info'].encode(sys.stdout....
bac1fae96505d3745c40717937e3523182be84f5
38,228
def read_seq(handle): """ Read sequence from plain text file (no format). Used for importing reference sequence. :param handle: :return: str, sequence """ seq = '' for line in handle: seq += line.strip() return seq
063f9e5300093537d81ed6ee8eb96579ae0dfcf5
38,230
def split(n): """ Split string or Array >>> split("hello") ['he', 'llo'] >>> split([1,2,3,1,2,4]) [[1, 2, 3], [1, 2, 4]] """ return [ n[:len(n)//2:], n[len(n)//2::] ]
ab132de4077bbc390a8b4f2f38c5154ecd75d579
38,231
from datetime import datetime import argparse def valid_date(date): """Validate the user-supplied date is a valid format to parse.""" try: datetime.strptime(date, '%Y-%m-%d') return date except ValueError: raise argparse.ArgumentTypeError('Provide the format: YYYY-MM-DD')
8068aef68c2a7d667e570790b834bfee75b89b3f
38,232
from typing import Union from typing import Tuple from typing import Optional import os def get_job_server_fd( job_server_fd: Union[int, Tuple[()], None]) -> Optional[int]: """Get the job server file descriptor from env var if input is a tuple. Args: job_server_fd: If this is not a tuple, return it direc...
f1a1d0e7a982d0ec3efceeb6399b523d0c1c8f5a
38,235
def parse_tile(tile_string): """ >>> parse_tile("esew") (1, -1) >>> parse_tile("esewnw") (0, 0) >>> parse_tile("nwwswee") (0, 0) """ data = list(tile_string) cur_pos_ew = 0 cur_pos_ns = 0 while len(data) != 0: c1 = data.pop(0) if c1 == 'w': cur...
7b6ee9725a65e88f3110c288000fb8d9626826b7
38,236
import os def is_newer(src: str, dest: str) -> bool: """ Returns whether the source file is newer than the destination file """ if not os.path.isfile(dest): return True return os.stat(src).st_mtime > os.stat(dest).st_mtime
ddb66cbacfe81d81707784b0dfea74ed3373432a
38,237
def parse_storage_mappings(storage_mappings): """ Given the 'storage_mappings' API field, returns a tuple with the 'default' option, the 'backend_mappings' and 'disk_mappings'. """ # NOTE: the 'storage_mappings' property is Nullable: if storage_mappings is None: return None, {}, {} back...
ea182c91ff5e2fe1e9a7a7066071a618eb039a5f
38,239
def bbox3d2result(bboxes, scores, labels, attrs=None): """Convert detection results to a list of numpy arrays. Args: bboxes (torch.Tensor): Bounding boxes with shape (N, 5). labels (torch.Tensor): Labels with shape (N, ). scores (torch.Tensor): Scores with shape (N, ). attrs (to...
d31481229e17bc25d4f1d6fe5b9ac757b194357e
38,242
import pathlib def _load_file_contents(path: pathlib.Path) -> str: """Return the contents of a file.""" with path.open("r") as fp: return fp.read()
ca90bcc6f346e69f10323388b8bc2faf49e2553d
38,244
import random def mutate_all_even(even_numbers): """ Mutates a string of even numbers in an other string of even numbers :param even_numbers: string of even numbers :return: string of other even numbers """ new_numbers = "" for i in range(len(even_numbers)): new_numbers += str(random.c...
57f2348c3e6a8a8926ebb3ebd130e872c68254f0
38,246
import configparser def __read_option(file_path, section, option): """ Method to parse the config file and read out its values. """ c = configparser.RawConfigParser() c.read(file_path) value = "" try: value = c.get(section, option) except configparser.NoSectionError: ...
d414c37247b8008ece9ce7c337799c6ddbe0451d
38,247
def filter_rr(rr): """filtered version of data""" return rr
ba903e89c73d75f741325439bc6cba7f54a8b327
38,248
def recordCounter(x): """ Simple record sizer that just returns 1 for each record """ return 1
a9b735c34b7978a866de6ffcf268875940664160
38,249
def q_mult(q1, q2): """ quarternion-quarternion multiplication """ w1, x1, y1, z1 = q1 w2, x2, y2, z2 = q2 w = w1 * w2 - x1 * x2 - y1 * y2 - z1 * z2 x = w1 * x2 + x1 * w2 + y1 * z2 - z1 * y2 y = w1 * y2 + y1 * w2 + z1 * x2 - x1 * z2 z = w1 * z2 + z1 * w2 + x1 * y2 - y1 * x2 retur...
fdf917dafd2a28d4d9105cd5d88d4da2794d71a2
38,250
import hashlib def sha256(byte_array) -> bytes: """ Perform a SHA256 operation on the input. :param byte_array: data to hash. :type byte_array: bytearray or bytes :return: hashed data :rtype: bytes """ return hashlib.sha256(byte_array).digest()
9017ccfa9f548502fcebdc61aedec85924907225
38,251
def get_first_and_last_line(fname): """ Get the first and last line of the file. Since the common_crawl files are alphabetical, we can use this information to determine the alphabetic range of entries covered by the file. This information will later be used to limit the zone comparison to only those...
6c69957698cf9357c0c223ec55ba01ecf1aff6ea
38,252
def AAPIUnLoad(): """Execute commands while Aimsun is closing.""" return 0
72814f6b67712ca51f384273f86546558dd637bf
38,253
def get_deltah_multipliers(accuracy_order): #Test Function Written """Get the deltah multipliers""" deltah_multipliers = [[-1.,0.,1.],[-2.,-1.,0.,1.,2.],\ [-3.,-2.,-1.,0.,1.,2.,3.],[-4.,-3.,-2.,-1.,0.,1.,2.,3.,4.]] return deltah_multipliers[accuracy_order/2-1]
e0f026784a78e7670b698147e3a16ed7c679061d
38,255
def obtain_points(func, theta_0, theta_1, min_x, max_x, step=0.1): """ Return a tuple of x and the corresponding points for the given x """ x_values = [] y_values = [] x = min_x while x <= max_x: y_values.append(func(x, theta_0, theta_1)) x_values.append(x) x += ...
a603660d60a8fdc8c99b5fb05c756afe972dd1ab
38,256
def create_aln_expr(id, start=None, stop=None): """ Create an alignment expression, such as ``n2[5:8]`` or ``tw1`` given an id, and start/stop range. :param id: ID with which to align :type id: str :param start: Range at which to start :type start: int :param stop: Range at which to stop ...
e06c4e65beffc1ec14bd4b16e34e6f14b22f2576
38,257
def normalize_by_mean(nodes, edges, feature_list, sequence_info): """ Normalize over all existing edges in the batch """ normalizing_feature_names = [feature for feature in feature_list if feature+"_MNORM_" in feature_list] for feature in normalizing_feature_names: data = edges[feature].clone() ...
ebbf23de962d9e566c3832e96e18206a6593ce40
38,259
def compressFeatureMap(featureMap, ignoreGaps=0, terse=0): """Given a feature map as returned by ClientDirectory.getFeatureMap, compress the data from each server's server descriptors. The default behavior is: if a server has two server descriptors such that one becomes valid immediately afte...
6ec3413b7a8de44eb3e0d872576f4cb02e571075
38,260
import sys def read_input(): """assumes input is provided in dictionary format coverts to dict format""" data = "" for line in sys.stdin: data += line #remove the new lines and convert to dictionary data = data.replace("\n","") return eval(...
06a5d1d84b856682f851a6bacc646dcb194b1695
38,261
import torch def ellip_gaussian2D(radius, sigma_x, sigma_y, dtype=torch.float32, device='cpu'): """Generate 2D ellipse gaussian kernel. Args: radius (tuple(int)): Ellipse radius (radius_x, radius_y) of gaussian ...
97caa00f535321b4c7831c251d3f0d6aaf3d2e32
38,262
import heapq def _simple_chooser(queue, remaining): """Default contraction chooser that simply takes the minimum cost option. """ cost, k1, k2, k12 = heapq.heappop(queue) if k1 not in remaining or k2 not in remaining: return None # candidate is obsolete return cost, k1, k2, k12
5bb92184767ba68247b124d4a935ea9dab327f96
38,263