content
stringlengths
35
416k
sha1
stringlengths
40
40
id
int64
0
710k
import math def H(r2, H_s, H_d, a_s, a_d, gamma_s, gamma_d, G, v): """ """ pi = math.pi sqrt = math.sqrt r = sqrt(r2) H2_s = H_s**2 H2_d = H_d**2 R2_s = r2 + H2_s R2_d = r2 + H2_d alpha_s = 1.0 if gamma_s == 1.0 else 4 * H2_s / (pi*R2_s) alpha_d = 1.0 if gamma_d == 1.0 ...
0fa1606212278def22075692a56468d41a8c7a3c
1,098
def addBenchmark(df): """Add benchmark to df.""" # Compute the inverse of the distance distance_inv = (1. / df.filter(regex='^distance*', axis=1)).values # Extract the value at the nearest station values = df.filter(regex='value_*', axis=1) # Compute the benchmark numer = (distance_inv * ...
62c63215d622c46bed8200f97ad55b985e2beb20
1,100
def is_file_like(f): """Check to see if ```f``` has a ```read()``` method.""" return hasattr(f, 'read') and callable(f.read)
9eee8c8f4a6966d1db67fb4aa9149e2fbd390fb9
1,101
def check_protocol(protocol): """ Check if a given protocol works by computing the qubit excitation probabilities """ qubit_weight = {} qubit_weight[protocol[0][0][0]] = 1.0 for pair_set in protocol: for i, j, p in pair_set: qubit_weight[j] = qubit_weight[i] * (1.0 - p) ...
8b9d0a8e329a340718d37bc79066be4a05cf2d20
1,102
def choose_first_not_none(*args): """ Choose first non None alternative in args. :param args: alternative list :return: the first non None alternative. """ for a in args: if a is not None: return a return None
fe3efba85251161cd0a6ecb50583cc443cd04dc0
1,103
def matrix(mat,nrow=1,ncol=1,byrow=False): """Given a two dimensional array, write the array in a matrix form""" nr=len(mat) rscript='m<-matrix(data=c(' try: nc=len(mat[0]) for m in mat: rscript+=str(m)[1:-1]+ ', ' rscript=rscript[:-2]+'), nrow=%d, ncol=%d, by...
a28d91d797238857dd2ff58f24655504a936d4a7
1,104
def add_dict(dct1, dct2): """Returns a new dictionaries where the content of the dictionaries `dct1` and `dct2` are merged together.""" result = dct1.copy() result.update(dct2) return result
eba785e4d00534e94c1bdde413603d64e18aac05
1,105
def template14(): """Simple ML workflow""" script = """ ## (Enter,datasets) << host = chemml << function = load_cep_homo >> smiles 0 >> homo 4 ## (Store,file) << host = chemml ...
d321d2016f0894d0a0538a09f6bc17f3f690317b
1,108
def mapdict(itemfunc, dictionary): """ Much like the builtin function 'map', but works on dictionaries. *itemfunc* should be a function which takes one parameter, a (key, value) pair, and returns a new (or same) (key, value) pair to go in the dictionary. """ return dict(map(itemfunc, diction...
1f0573410f82acb1f3c06029cf4bfaccd295e1ac
1,110
def _map_tensor_names(original_tensor_name): """ Tensor name mapping """ global_tensor_map = { "model/wte": "word_embedder/w", "model/wpe": "position_embedder/w", "model/ln_f/b": "transformer_decoder/beta", "model/ln_f/g": "transformer_decoder/gamma", } if origina...
3331d13e667ee3ef363cdeca5122e8a256202c39
1,111
def get_classpath(obj): """ Return the full module and class path of the obj. For instance, kgof.density.IsotropicNormal Return a string. """ return obj.__class__.__module__ + "." + obj.__class__.__name__
bf986e2b27dd8a216a2cc2cdb2fb2b8a83b361cc
1,112
import numpy as np def label_generator(df_well, df_tops, column_depth, label_name): """ Generate Formation (or other) Labels to Well Dataframe (useful for machine learning and EDA purpose) Input: df_well is your well dataframe (that originally doesn't have the intended label) df_tops is your label dataf...
16336d8faf675940f3eafa4e7ec853751fd0f5d0
1,115
import os def cleanFiles(direct, CWD=os.getcwd()): """ removes the year and trailing white space, if there is a year direct holds the file name for the file of the contents of the directory @return list of the cleaned data """ SUBDIR = CWD + "output/" # change directory to ouput folder co...
2a16037ef15d547af8c1b947d96747b2b2d62fd1
1,116
def wrap_compute_softmax(topi_compute): """Wrap softmax topi compute""" def _compute_softmax(attrs, inputs, out_type): axis = attrs.get_int("axis") return [topi_compute(inputs[0], axis)] return _compute_softmax
3a5e3843f77d8bdfefc0f77b878f135aac4896f6
1,117
def Align4(i): """Round up to the nearest multiple of 4. See unit tests.""" return ((i-1) | 3) + 1
16ff27823c30fcc7d03fb50fe0d7dbfab9557194
1,118
import torch def initialize(X, num_clusters): """ initialize cluster centers :param X: (torch.tensor) matrix :param num_clusters: (int) number of clusters :return: (np.array) initial state """ num_samples = X.shape[1] bs = X.shape[0] indices = torch.empty(X.shape[:-1], device=X.de...
a704daf3997202f4358bb9f3fbd51524fee4afe5
1,119
def parse_structure(node): """Turn a collapsed node in an OverlayGraph into a heirchaical grpah structure.""" if node is None: return None structure = node.sub_structure if structure is None: return node.name elif structure.structure_type == "Sequence": return {"Sequence" : [parse_structure(n) f...
f9374ff9548789d5bf9b49db11083ed7a15debab
1,121
def column_ids_to_names(convert_table, sharepoint_row): """ Replace the column ID used by SharePoint by their column names for use in DSS""" return {convert_table[key]: value for key, value in sharepoint_row.items() if key in convert_table}
6ae1474823b0459f4cf3b10917286f709ddea520
1,122
import uuid def make_unique_id(): """Make a new UniqueId.""" return uuid.uuid4() # return UniqueId(uuid.uuid4())
c7ab0e5242a954db75638b3193609d49f0097287
1,123
import math def calculatePredictions(ReviewsD, userIDTest, scoreTest, simmilarities): """ Function finds userIDTest in all simmilar items and uses all the scores for prediction calculation Returns actualScore and predictedScore for further calculations of finding rmse and mse value...
6b74b9d6ed4855030f2f7405190788db7e0dad52
1,124
def func_2(x: float, c: float, d: float) -> float: """ Test function 2. """ return x + c + d
b95400c6779c0e64e7bb6cda493c0ee5e6f05f7c
1,125
import math def isInner(x1, y1, x2, y2, scale): """ Currently, it's a rectangular kernal Other options: rectangular f(x) = 1 if a <= scale <= b else 0 I don't get the rest of them http://saravananthirumuruganathan.wordpress.com/2010/04/01/introduction-to-mean-shift-algorithm/ ...
b2c715b33ae8b38fdfd19c71b54ee3980b336eeb
1,126
def wklobjective_converged(qsum, f0, plansum, epsilon, gamma): """Compute finale wkl value after convergence.""" obj = gamma * (plansum + qsum) obj += epsilon * f0 obj += - (epsilon + 2 * gamma) * plansum return obj
079841a8ee6d845cdac25a48306c023a1f38b5f7
1,127
def _get_should_cache_fn(conf, group): """Build a function that returns a config group's caching status. For any given object that has caching capabilities, a boolean config option for that object's group should exist and default to ``True``. This function will use that value to tell the caching decora...
7a11124c640bfb3ced28e2d9395593b70dc85a0a
1,128
import json def obter_novo_username() -> str: """ -> Pede um novo nome de usuário. :return: Retorna o novo nome de usuário. """ username = input('Qual é o seu nome? ') arquivo = 'arquivos_json/nome_de_usuario.json' with open(arquivo, 'w') as obj_arq: json.dump(username, obj_arq) ...
b4d4922d68b1fb80e5a9270638d134b5806969fd
1,131
import logging def _parse_block_postheader(line): """ (209)**************!*****************!!*************... """ parts = line[1:].split(')', 1) qlen = int(parts[0]) if not len(parts[1]) == qlen: logging.warn("postheader expected %d-long query, found %d", qlen, len...
5eee6c11160c0f91cb37c025d6d265188488cad9
1,132
import os def _is_toplevel_repository_dir(directory): """Returns if a directory is a git or mercurial directory. This works by searching for a file or directory named `.git` or `.hg` in the directory. This works for both submodules and normal repositories. """ return (os.path.exists(os.path.join(...
25db538b6ef4f7febbdb282561885ff807f03bbe
1,133
def horizontal_move(t, h_speed=-2/320): """Probe moves horizontally at h_speed [cm/s]""" return 0.*t, h_speed*t, 2/16 + 0*t
d9cf0e5b968e7d8319b7f63f7d1d7a4666484ad3
1,134
def categories_report(x): """Returns value counts report. Parameters ---------- x: pd.Series The series with the values Returns ------- string The value counts report. str1 = False 22 | True 20 | nan 34 str2 = False (22) | True (20) | nan (34) ...
695ccd73ee73a13e92edbdf0eb242121d136ddbb
1,135
def detect_ol(table): """Detect ordered list""" if not len(table): return False for tr in table: if len(tr)!=2: return False td1 = tr[0] # Only keep plausible ordered lists if td1.text is None: return False text = td1.text.strip() ...
b7082932fba6ba7f9634e70ea424561c084a2dc1
1,136
import six import base64 def _decode(value): """ Base64 解码,补齐"=" 记得去错多余的“=”,垃圾Docker,签发的时候会去掉 :param value: :return: """ length = len(value) % 4 if length in (2, 3,): value += (4 - length) * "=" elif length != 0: raise ValueError("Invalid base64 string") if not...
c4a28605fb7f8a0d5110fb06738c31b030cae170
1,137
def line2dict(st): """Convert a line of key=value pairs to a dictionary. :param st: :returns: a dictionary :rtype: """ elems = st.split(',') dd = {} for elem in elems: elem = elem.split('=') key, val = elem try: int_val = int(val) dd[k...
86bb6c2e72c8a6b2a027d797de88089067ff7475
1,138
def check_structure(struct): """ Return True if the monophyly structure represented by struct is considered "meaningful", i.e. encodes something other than an unstructured polytomy. """ # First, transform e.g. [['foo'], [['bar']], [[[['baz']]]]], into simply # ['foo','bar','baz']. def d...
e07a2f39c7d3b8f2454b5171119b8698f4f58a99
1,139
import subprocess def generate_keypair(passphrase): """ Create a pair of keys with the passphrase as part of the key names """ keypath = '/tmp/test_{}_key'.format(passphrase) command = 'ssh-keygen -t rsa -b 4096 -C "{p}" -P "{p}" -f {k} -q' command = command.format(p=passphrase, ...
d4c8155173273feda778f5f54a4b0513353a293b
1,140
def euler(step, y0): """ Implements Euler's method for the differential equation dy/dx = 1/(2(y-1)) on the interval [0,4] """ x = [0] index_x = 0 while x[index_x] < 4: x.append(x[index_x] + step) index_x += 1 index_y = 0 y = [y0] def yprime(y): yprime = 1 / (2...
89c6e6409a1c43ce4766507fba2f401bb01cfbb8
1,142
import logging def update_softwaretitle_packages(api, jssid, pkgs): """ Update packages of software title :param jssid: Patch Software Title ID :param pkgs: dict of {version: package, ...} :returns: None """ logger = logging.getLogger(__name__) data = api.get(f"patchs...
0acb3dfbff0e85a2e8a876d5e5d484c4d1e52068
1,143
def progress(self): """Check if foo can send to corge""" return True
89a0c9671645f9fa855db35bf5e383145d6b7616
1,144
def write_sample_sdf(input_file_name, valid_list): """ Function for writing a temporary file with a subset of pre-selected structures :param input_file_name: name of input file :param valid_list: list of indexes of pre-selected structures :return: name of subsampled file """ sample_fil...
0b22c14452f6de978e7ea811d761195d92bfe6c4
1,145
from typing import Sequence def _table(*rows: Sequence) -> str: """ >>> _table(['a', 1, 'c', 1.23]) '|a|1|c|1.23|' >>> _table(['foo', 0, None]) '|foo|||' >>> print(_table(['multiple', 'rows', 0], ['each', 'a', 'list'])) |multiple|rows|| |each|a|list| """ return '\n'.join([ ...
d566da2ad9240e73b60af00d3e4b4e25607234b4
1,146
def make_range(value): """ Given an integer 'value', return the value converted into a range. """ return range(value)
385d23eaebd04249f9384e0d592b7fb3a9bbb457
1,148
def _get_security_group_id(connection, security_group_name): """ Takes a security group name and returns the ID. If the name cannot be found, the name will be attempted as an ID. The first group found by this name or ID will be used.) :param connection: :param security_group_name: :...
70c9b8357a9634043f07ad0019ff3cc621ba859c
1,149
import difflib def lines_diff(lines1, lines2): """Show difference between lines.""" is_diff = False diffs = list() for line in difflib.ndiff(lines1, lines2): if not is_diff and line[0] in ('+', '-'): is_diff = True diffs.append(line) return is_diff, diffs
50916d46871980fadfd854dc698481a4b0f35834
1,150
import re def parse_ipmi_hpm(output): """Parse the output of the hpm info retrieved with ipmitool""" hrdw = [] line_pattern = re.compile(r'^\|[^0-9]*([0-9]+)\|[^a-zA-Z ]* ?([^\|]*)\|([^\|]*)\|([^\|]*)\|([^\|]*)\|') for line in output: match = line_pattern.match(line) if match: ...
001731ce46fa6bbdb5103727265a0bdd353773be
1,151
def get_genes_and_pathways(reactions, r_numbers, species): """Returns a CSV-formatted string with the list of genes and pathways where the reaction(s) of 'species' appear. :param reactions: list of reactions for species :param r_numbers: RNumbers object :param species: KEGG organism code :retur...
0ecddcaf50650b04125be73bcf6b304a77df011d
1,152
import os def datasetFiles(request): """ Return a list all dataset files in the datasets directory, by looking for files ending with .h5 suffix. eg. ['/Users/jarnyc/BioPyramid/data/datasets/lanner.1.0.h5'] """ # This is the dataset directory, set by the config file datadir = request.registry.settings['biopyrami...
0c4e2ffff720ec24b6f673f059baa023458f72e9
1,153
def convertHunit(conc, from_unit='H/10^6 Si', to_unit='ppm H2O', phase='Fo90', printout=True): """ Convert hydrogen concentrations to/from H/10^6 Si and ppm H2O. Based on Table 3 of Denis et al. 2013 """ if phase == 'Fo90': H_to_1_ppm = 16.35 elif phase == 'opx': H_t...
fdd0646a09f3a2c3a8cbbc02410103caa9e023dd
1,155
import re def countBasesInFasta(fastaFile): """ Given a fasta file, return a dict where the number of records and the total number of bases are given by 'records' and 'bases' respectively. """ recordRE = re.compile(r'^>') whiteSpaceRE = re.compile(r'\s+') total_bases = 0 total_seqs = 0...
45eaa5b8d36b4bae6b97bb29fdead1efc0aed8c2
1,156
def test_train_val_split(patient_id, sub_dataset_ids, cv_fold_number): """ if cv_fold_number == 1: if patient_id in sub_dataset_ids[-5:]: return 'test' elif patient_id in sub_dataset_ids[-7:-5]: return 'validation' else: return 'train' ...
129f3856875033505555241408577f8885c9c393
1,157
def linear_search(iterable, item): """Returns the index of the item in the unsorted iterable. Iterates through a collection, comparing each item to the target item, and returns the index of the first item that is equal to the target item. * O(n) time complexity * O(1) space complexity Args: iterable:...
bdbd7e70cea79deef1375648bde61067df1d2221
1,158
def create_MD_tag(reference_seq, query_seq): """Create MD tag Args: reference_seq (str) : reference sequence of alignment query_seq (str) : query bases of alignment Returns: md_tag(str) : md description of the alignment """ no_change = 0 md = [] for ref_base, query_ba...
4b711521d00af132e8e29fe4fc44785b985c2607
1,159
import re def calc_word_frequency(my_string, my_word): """Calculate the number of occurrences of a given word in a given string. Args: my_string (str): String to search my_word (str): The word to search for Returns: int: The number of occurrences of the given word in the given st...
15ff723dd2ff089fb12cccb38283f1f75e37079d
1,160
import hashlib def intmd5(source: str, nbytes=4) -> int: """ Generate a predictive random integer of nbytes*8 bits based on a source string. :param source: seed string to generate random integer. :param nbytes: size of the integer. """ hashobj = hashlib.md5(source.encode()) retu...
c03eb99a67af00a4a081423ecca3a724111514e1
1,161
async def async_setup(hass, config_entry): """ Disallow configuration via YAML """ return True
759cc705a82a0f9ff9d4d43cb14d641d7e552aaa
1,163
import socket def _is_rpc_timeout(e): """ check whether an exception individual rpc timeout. """ # connection caused socket timeout is being re-raised as # ThriftConnectionTimeoutError now return isinstance(e, socket.timeout)
ec832bec086b59698eed12b18b7a37e5eb541329
1,164
def html_anchor_navigation(base_dir, experiment_dir, modules): """Build header of an experiment with links to all modules used for rendering. :param base_dir: parent folder in which to look for an experiment folders :param experiment_dir: experiment folder :param modules: list of all loaded modules ...
1fea16c0aae2f73be713271de5f003e608cee7e9
1,165
def genBoard(): """ Generates an empty board. >>> genBoard() ["A", "B", "C", "D", "E", "F", "G", "H", "I"] """ # Empty board empty = ["A", "B", "C", "D", "E", "F", "G", "H", "I"] # Return it return empty
c47e766a0c897d3a1c589a560288fb52969c04a3
1,166
def _partition_at_level(dendrogram, level) : """Return the partition of the nodes at the given level A dendrogram is a tree and each level is a partition of the graph nodes. Level 0 is the first partition, which contains the smallest snapshot_affiliations, and the best is len(dendrogram) - 1. The higher the level ...
b179127076c386480c31a18a0956eb30d5f4ef2a
1,167
import time def make_filename(): """"This functions creates a unique filename.""" unique_filename = time.strftime("%Y%m%d-%H%M%S") #unique_filename = str(uuid.uuid1()) #unique_filename = str(uuid.uuid1().hex[0:7]) save_name = 'capture_ferhat_{}.png'.format(unique_filename) return(save_name)
bf16b642884381d795148e045de2387d0acaf23d
1,168
import re def is_live_site(url): """Ensure that the tool is not used on the production Isaac website. Use of this tool or any part of it on Isaac Physics and related websites is a violation of our terms of use: https://isaacphysics.org/terms """ if re.search("http(s)?://isaac(physics|chemis...
407624a049e92740eb82753d941780a446b1facf
1,169
def score_false(e, sel): """Return scores for internal-terminal nodes""" return e*(~sel).sum()
077cd38c6d1186e2d70fd8a93f44249b0cef2885
1,170
import logging import numpy def retrieveXS(filePath, evMin=None, evMax=None): """Open an ENDF file and return the scattering XS""" logging.info('Retrieving scattering cross sections from file {}' .format(filePath)) energies = [] crossSections = [] with open(filePath) as fp: ...
388986facd75540983870f1f7e0a6f51b6034271
1,171
import string def _parse_java_simple_date_format(fmt): """ Split a SimpleDateFormat into literal strings and format codes with counts. Examples -------- >>> _parse_java_simple_date_format("'Date:' EEEEE, MMM dd, ''yy") ['Date: ', ('E', 5), ', ', ('M', 3), ' ', ('d', 2), ", '", ('y', 2)] ...
3fe42e4fc96ee96c665c3c240cb00756c8534c84
1,172
import logging def rekey_by_sample(ht): """Re-key table by sample id to make subsequent ht.filter(ht.S == sample_id) steps 100x faster""" ht = ht.key_by(ht.locus) ht = ht.transmute( ref=ht.alleles[0], alt=ht.alleles[1], het_or_hom_or_hemi=ht.samples.het_or_hom_or_hemi, #GQ=ht.samples.GQ, HL=ht.samples.H...
3e879e6268017de31d432706dab9e672e85673aa
1,173
def _format_stages_summary(stage_results): """ stage_results (list of (tuples of (success:boolean, stage_name:string, status_msg:string))) returns a string of a report, one line per stage. Something like: Stage: <stage x> :: SUCCESS Stage: <stage y> :: FAILED Stage: <s...
2f5c757342e98ab258bdeaf7ffdc0c5d6d4668ca
1,174
def read_hdr(name, order='C'): """Read hdr file.""" # get dims from .hdr h = open(name + ".hdr", "r") h.readline() # skip line l = h.readline() h.close() dims = [int(i) for i in l.split()] if order == 'C': dims.reverse() return dims
57daadfdf2342e1e7ef221cc94f2e8f70c504944
1,176
import socket def canonical_ipv4_address(ip_addr): """Return the IPv4 address in a canonical format""" return socket.inet_ntoa(socket.inet_aton(ip_addr))
edacc70ccc3eef12030c4c597c257775d3ed5fa4
1,177
def make_chained_transformation(tran_fns, *args, **kwargs): """Returns a dataset transformation function that applies a list of transformations sequentially. Args: tran_fns (list): A list of dataset transformation. *args: Extra arguments for each of the transformation function. **kw...
5f24e030df74a0617e633ca8f8d4a3954674b001
1,179
def increment(i,k): """ this is a helper function for a summation of the type :math:`\sum_{0 \leq k \leq i}`, where i and k are multi-indices. Parameters ---------- i: numpy.ndarray integer array, i.size = N k: numpy.ndarray integer array, k.size = N...
1ac8ef592376fbfa0d04cdd4b1c6b29ad3ed9fbd
1,180
def generate_outlier_bounds_iqr(df, column, multiplier=1.5): """ Takes in a dataframe, the column name, and can specify a multiplier (default=1.5). Returns the upper and lower bounds for the values in that column that signify outliers. """ q1 = df[column].quantile(.25) q3 = df[column].quantile(....
7f096d5f5cf2417cbc161713715a39560efd140a
1,182
import random def generate_data(Type): """ 随机生成CAN帧中所包含的数据 :param Type: 需要生成数据的类型 :return: 生成的随机数据序列,长度为8,如['88', '77', '55', '44', '22', '11', '33'', '44'] """ data = [] if Type == 1: # 生成反馈帧单体电池Cell1-24电压信息 standard_vol = 35 offset = random.randint(0, 15) ...
3a920be4b7ef5c5c3e258b3e3c79bc028004179a
1,183
def counting_sort(array): """ SORTING FUNCTION USING COUNTING SORT ALGORITHM ARG array = LIST(ARRAY) OF NUMBERS """ ## counter lists has elements for every maximum = max(array) counter = [0]*(maximum+1) for i in range(len(array)): counter[array[i]] += 1 for i in range(1, ma...
986e2f9277fa71dcd9897ac409653009c651c49f
1,184
import math from PIL import ImageColor def indexedcolor(i, num, npersat=15, lightness=60): """Returns an rgb color triplet for a given index, with a finite max 'num'. Thus if you need 10 colors and want to get color #5, you would call this with (5, 10). The colors are "repeatable". """ nsats = int...
418a875bc8ae50ce21f9667f46718863ba0f55e3
1,185
def dot_to_dict(values): """Convert dot notation to a dict. For example: ["token.pos", "token._.xyz"] become {"token": {"pos": True, "_": {"xyz": True }}}. values (iterable): The values to convert. RETURNS (dict): The converted values. """ result = {} for value in values: path = res...
a2c56a01b179d27eabc728d6ff2ec979885d5feb
1,186
def hexagonal_numbers(length: int) -> list[int]: """ :param len: max number of elements :type len: int :return: Hexagonal numbers as a list Tests: >>> hexagonal_numbers(10) [0, 1, 6, 15, 28, 45, 66, 91, 120, 153] >>> hexagonal_numbers(5) [0, 1, 6, 15, 28] >>> hexagonal_numbers(0...
632e60505cb17536a17b20305a51656261e469f5
1,187
def check_add_role(store, id, name): """ Checks if role exist and then adds record if it doesn't """ role = store.find_role(name) if role == None: return store.create_role(id=id, name=name) else: return role
c8680158cc005bf7a278951774b9fe0a733fc8c6
1,188
from pathlib import Path def delta_path(base_path: Path, item_path: Path, new_base_path: Path) -> Path: """ Removes a base path from an item, and appends result to a new path :param base_path: The :py:class:`pathlib.Path` to be removed from `item_path` :param item_path: The :py:class:`pathlib.Path` t...
ec531a011e36f053a8092525faae2047f5f66ccc
1,189
def sum_to_scalar(*args): """Adding losses/nmsks together that were evaluated in parallel""" new_args = list() for arg in args: new_args.append({k: v.sum() for (k, v) in arg.items()}) return new_args
a4264911962c7bf3432735f8872522e193ceec8f
1,191
def plural_suffix(count: int) -> str: """"s" when count is not one""" suffix = '' if count != 1: suffix = 's' return suffix
950002d57560d06e93e08647ff17d885688bca87
1,193
import argparse import sys def parse_args() -> argparse.Namespace: """ Parse program arguments :return: Parser values """ parser = argparse.ArgumentParser(description="") parser.add_argument("-a", action="store_true") parser.add_argument("-c", action="store_true") parser.add_argument("...
9d86d37d94af5c8ff128c4da8226f15728b0da70
1,194
import networkx def compute_participants(matches, challonge_data): """Compute series participants. Iterate all matches and players to create a graph. Apply connected components algorithm to resolve distinct participant groups over all matches. Sort participant groups by number of wins to correla...
a715773d5edd3b4d6852096c665070e64bef1165
1,195
import random def describe_current_subtask(subtask, prefix=True): """ Make a 'natural' language description of subtask name """ to_verb = {"AnswerQuestion": "answering a question", "ArmGoal": "moving my arm", "DemoPresentation": "giving a demo", "Find": "fi...
628c699201c26242bd72c6066cba07cce54b14ca
1,197
def addprint(x: int, y: int): """Print and "added" representation of `x` and `y`.""" expr = x + y return "base addprint(x=%r, y=%r): %r" % (x, y, expr)
e3f735afc1d4826a1af7210c3cec88c8b8c87dfe
1,198
import re def parse_date(deadline_date): """ Given a date in the form MM/DD/YY or MM/DD/YYYY, returns the integers MM, DD, and YYYY (or YY) in this order. """ deadline_split = re.split('\\/|\\-', deadline_date) return int(deadline_split[0]), int(deadline_split[1]), int(deadline_split[2])
0ded6bccce8437aad61cfa5ff121c5ed0595849b
1,199
import re def get_file_name(part): """get file name using regex from fragment ID""" return re.findall(r"='(.*\-[a-z]+).*", part)[0]
30c8867d8e14b04c593359f1c16d9bf324711ba0
1,201
import math def generate_sphere_points(n): """ Returns list of 3d coordinates of points on a sphere using the Golden Section Spiral algorithm. """ points = [] inc = math.pi * (3 - math.sqrt(5)) offset = 2 / float(n) for k in range(int(n)): y = k * offset - 1 + (offset / 2) ...
bd6c7624220f7928a44f6dcb24b7112e8d803eb4
1,202
def expand_locations(ctx, input, targets = []): """Expand location templates. Expands all `$(execpath ...)`, `$(rootpath ...)` and deprecated `$(location ...)` templates in the given string by replacing with the expanded path. Expansion only works for labels that point to direct dependencies of this ru...
efa482d928484b7d6f9c8acbf81e0a3d5b4cd50f
1,203
def black_color_func(word, font_size, position, orientation, random_state=None, **kwargs): """Make word cloud black and white.""" return("hsl(0,100%, 1%)")
d5e874a4f62d30abcba29476d0ba7fc3a31b0ca6
1,210
def detect_label_column(column_names): """ Detect the label column - which we display as the label for a joined column. If a table has two columns, one of which is ID, then label_column is the other one. """ if (column_names and len(column_names) == 2 and "id" in column_names): return [c fo...
40524e7ed0878316564ad8fd66a2c09fc892e979
1,211
def table(custom_headings, col_headings_formatted, rows, spec): """ Create a LaTeX table Parameters ---------- custom_headings : None, dict optional dictionary of custom table headings col_headings_formatted : list formatted column headings rows : list of lists of cell-str...
0ca28fce26fc7476aa5b88a621c5476ae8d381ce
1,213
def conflict(next_x: int, s: tuple) -> bool: """Return a boolean that defines the conflict condition of the next queen's position""" next_i = len(s) for i in range(next_i): if abs(s[i] - next_x) in (0, next_i - i): return True else: return False
cc29b142e1cc799c0a305523b713c5085af25fd0
1,214
from typing import List def split_to_sublists(initial_list:list, n:int, strict:bool=True) -> List[list]: """Takes a list and splits it into sublists of size n Parameters ---------- initial_list : list The initial list to split into sublists n : int The size of each sublist s...
fcca74f9814020c99aaf8b31f092ca3ca9533216
1,215
import os import re def get_matched_files(dirPath=".", regex=None): """Get the abspath of the files whose name matches a regex Only files will be returned, and directories are excluded. Args: dirPath (str): the directory to search regex (regex): the regular expression to match the filena...
118cf628b54f50b2c41c1885bcf000a741966086
1,216
def sectionize(parts, first_is_heading=False): """Join parts of the text after splitting into sections with headings. This function assumes that a text was splitted at section headings, so every two list elements after the first one is a heading-section pair. This assumption is used to join sections wi...
402832d55268dc808888f94b95e3a1c991394041
1,217
def byte_compare(stream_a, stream_b): """Byte compare two files (early out on first difference). Returns: (bool, int): offset of first mismatch or 0 if equal """ bufsize = 16 * 1024 equal = True ofs = 0 while True: b1 = stream_a.read(bufsize) b2 = stream_b.read(bufsi...
59adfe50fefdb79edd082a35437018d4b954ec75
1,218
import re def is_regex(param): """ 判断参数是否是合法正则表达式字符串 :param param: {String} 参数 :return: {Boolean} 是否是合法正则表达式 """ try: re.compile(param) return True except re.error: return False
6a3ee33e68e33d3557db546beadc005235360080
1,219
def min_count1(lst): """ Get minimal value of list, version 1 :param lst: Numbers list :return: Minimal value and its count on the list """ if len(lst) == 0: return [] count = 0 min_value = lst[0] for num in lst: if num == min_value: count += 1 el...
b441d0a37534909e9a990b91a953d4022698c04b
1,220
def exactly_one_topping(ketchup, mustard, onion): """Return whether the customer wants exactly one of the three available toppings on their hot dog. """ return True if int(ketchup) + int(mustard) + int(onion) == 1 else False
214c95d35c116993dc78740d5d16b874122960ed
1,221
def strip_line_endings(data: list) -> list: """Removes line endings(\n). Removes item if only contains \n.""" return [i.rstrip("\n") for i in data if i != "\n"]
5383b1bc3884395459ca63b6f15c0a1091eaaaf0
1,222
def weighting_system_z(): """Z-weighting filter represented as polynomial transfer function. :returns: Tuple of `num` and `den`. Z-weighting is 0.0 dB for all frequencies and therefore corresponds to a multiplication of 1. """ numerator = [1] denomenator = [1] return nume...
8d84c572631c23f50f8a57e388e21fa62e316930
1,223
def denormalize(series, last_value): """Denormalize the values for a given series. This uses the last value available (i.e. the last closing price of the week before our prediction) as a reference for scaling the predicted results. """ result = last_value * (series + 1) return result
f4c32aa4248378482f1294c54e706e6ee8d5332d
1,224