content
stringlengths
35
416k
sha1
stringlengths
40
40
id
int64
0
710k
import base64 def hex_to_base64(hex_): """ Converts hex string to base64 """ return base64.b64encode(bytes.fromhex(hex_))
26f42b25c9e804bc1b786aadab033db104882f4b
706,891
def clean_tag(tag): """clean up tag.""" if tag is None: return None t = tag if isinstance(t, list): t = t[0] if isinstance(t, tuple): t = t[0] if t.startswith('#'): t = t[1:] t = t.strip() t = t.upper() t = t.replace('O', '0') t = t.replace('B', '8...
1d2709323c4d80f290701d5cdc3a993b4bac25d4
706,893
import math def hard_negative_mining(loss, labels, neg_pos_ratio=3): """ 用于训练过程中正负例比例的限制.默认在训练时,负例数量是正例数量的三倍 Args: loss (N, num_priors): the loss for each example. labels (N, num_priors): the labels. neg_pos_ratio: 正负例比例: 负例数量/正例数量 """ pos_mask = labels > 0 num_pos = p...
3b2e38ab2b0bbd9732fceafdfd023ea220b3c5eb
706,894
def bbox_area(gt_boxes): """ gt_boxes: (K, 4) ndarray of float area: (k) """ K = gt_boxes.size(0) gt_boxes_area = ((gt_boxes[:,2] - gt_boxes[:,0] + 1) * (gt_boxes[:,3] - gt_boxes[:,1] + 1)).view(K) return gt_boxes_area
57ad16b8b339e4515dcd7e7126b9c6b35b6c3d8b
706,895
def compare_dicts(cloud1, cloud2): """ Compare the dicts containing cloud images or flavours """ if len(cloud1) != len(cloud2): return False for item in cloud1: if item in cloud2: if cloud1[item] != cloud2[item]: return False else: ret...
4c13ed92da2cd40b543b75fac119b5da302717e3
706,896
import string def str2int(string_with_int): """ Collect digits from a string """ return int("".join([char for char in string_with_int if char in string.digits]) or 0)
86955812fa3b2e6af0b98a04a1516897ccf95c25
706,897
def find_routes(paths) -> list: """returns routes as tuple from path as list\ like 1,2,3 --> (1,2)(2,3)""" routes = [] for path in paths: for i in range(len(path)): try: route = (path[i], path[i + 1]) if route not in routes: r...
67fb8eb575dd45879f5e5b465a7886f2a2387b26
706,898
def deploy_tester_contract( web3, contracts_manager, deploy_contract, contract_deployer_address, get_random_address, ): """Returns a function that can be used to deploy a named contract, using conract manager to compile the bytecode and get the ABI""" def f(contract_n...
ee925e9632f3bfd66a843d336bd287c92543b2ed
706,899
def make_hashable_params(params): """ Checks to make sure that the parameters submitted is hashable. Args: params(dict): Returns: """ tuple_params = [] for key, value in params.items(): if isinstance(value, dict): dict_tuple = tuple([(key2, value2) for key2, ...
39d5de594b8caf776d2732e0e58b1c11127e5047
706,900
def mil(val): """convert mil to mm""" return float(val) * 0.0254
9071b0116a7062ef93d6bee56a08db2b9bec906a
706,901
def ask_number(question, low, high): """Poproś o podanie liczby z określonego zakresu.""" response = None while type(response) != int: try: response = int(input(question)) while response not in range(low, high): response = int(input(question)) except V...
fdae37e6a0cd34d36b647a23f4a0f58cad46680a
706,902
def laplacian_operator(data): """ apply laplacian operator on data """ lap = [] lap.append(0.0) for index in range(1, len(data) - 1): lap.append((data[index + 1] + data[index - 1]) / 2.0 - data[index]) lap.append(0.0) return lap
3d7755cdc52352cc445d5942e34c09f65f3e11db
706,903
from pathlib import Path def input_file_path(directory: str, file_name: str) -> Path: """Given the string paths to the result directory, and the input file return the path to the file. 1. check if the input_file is an absolute path, and if so, return that. 2. if the input_file is a relative path, co...
dd866a5f8b6f776238269844d64686f7fb28347c
706,904
import os def get_ps_lib_dirs(): """ Add directory to list as required """ polysync_install = os.path.join('/', 'usr', 'local', 'polysync') polysync_lib = os.path.join(polysync_install, 'lib') polysync_vendor = os.path.join(polysync_install, 'vendor', 'lib') return [ polysync_lib,...
ce4745ef5dcdb4c00051eff6fae6082f98c90498
706,906
import math def workout_train_chunk_length(inp_len: int, resampling_factor: int = 1, num_encoders: int = 5, kernel: int = 8, stride: int = 2) -> int: """ Given inp_len, return the chunk ...
a7e7f42aa9670f1bda98c588e50052db0f4eb90f
706,907
def ft32m3(ft3): """ft^3 -> m^3""" return 0.028316847*ft3
74f55f722c7e90be3fa2fc1f79f506c44bc6e9bc
706,908
def _calculate_target_matrix_dimension(m, kernel, paddings, strides): """ Calculate the target matrix dimension. Parameters ---------- m: ndarray 2d Matrix k: ndarray 2d Convolution kernel paddings: tuple Number of padding in (row, height) on one side. If you...
77b5cabd7101b957a27fc422d1ed1715525400a0
706,909
def pretty_duration(seconds): """Return a human-readable string for the specified duration""" if seconds < 2: return '%d second' % seconds elif seconds < 120: return '%d seconds' % seconds elif seconds < 7200: return '%d minutes' % (seconds // 60) elif seconds < 48 * 360...
8e34addedeeb98e1e028fa9374fcc8c4f134a9f7
706,910
from typing import Counter def train(training_data): """Trains the model on a given data set. Parameters ---------- training_data Returns ------- """ counts = Counter(training_data) model = {} # sort counts by lowest occurrences, up to most frequent. # this allows higher...
328901b090392097d22b21a948691787e0128d48
706,911
def get_ref_kmer(ref_seq, ref_name, k_len): """ Load reference kmers. """ ref_mer = [] ref_set = set() for i in range(len(ref_seq) - k_len + 1): kmer = ref_seq[i:(i + k_len)] if kmer in ref_set: raise ValueError( "%s found multiple times in reference %s, at p...
72b75dccfba122a986d50e144dea62bfafe0fb50
706,912
import ipaddress def is_valid_ip(ip: str) -> bool: """ Args: ip: IP address Returns: True if the string represents an IPv4 or an IPv6 address, false otherwise. """ try: ipaddress.IPv4Address(ip) return True except ValueError: try: ipaddress.IPv6Addre...
aa1d3b19828dd8c3dceaaa8d9d1017cc16c1f73b
706,913
import torch def pick_best_batch_size_for_gpu(): """ Tries to pick a batch size that will fit in your GPU. These sizes aren't guaranteed to work, but they should give you a good shot. """ free, available = torch.cuda.mem_get_info() availableGb = available / (1024 ** 3) if availableGb > 14:...
31d970697b417b40f8ef5b41fdeacc0e378543a0
706,914
def tree_to_newick_rec(cur_node): """ This recursive function is a helper function to generate the Newick string of a tree. """ items = [] num_children = len(cur_node.descendants) for child_idx in range(num_children): s = '' sub_tree = tree_to_newick_rec(cur_node.descendants[child_idx])...
751d46dbb4e3a5204900601164410b5bf7f0578b
706,915
def indexData_x(x, ukn_words): """ Map each word in the given data to a unique integer. A special index will be kept for "out-of-vocabulary" words. :param x: The data :return: Two dictionaries: one where words are keys and indexes values, another one "reversed" (keys->index, values->words) ...
3f6ffd97d33400c3418b78ad3b383766cc07bee3
706,917
def shimizu_mirioka(XYZ, t, a=0.75, b=0.45): """ The Shinizu-Mirioka Attractor. x0 = (0.1,0,0) """ x, y, z = XYZ x_dt = y y_dt = (1 - z) * x - a * y z_dt = x**2 - b * z return x_dt, y_dt, z_dt
60e5b52e1755de8bcc966364d828d47b05af3723
706,918
def pack_bidirectional_lstm_state(state, num_layers): """ Pack the hidden state of a BiLSTM s.t. the first dimension equals to the number of layers. """ assert (len(state) == 2 * num_layers) _, batch_size, hidden_dim = state.size() layers = state.view(num_layers, 2, batch_size, hidden_dim).trans...
de102ce55deceb5ca7211def122dc2767c35cdd3
706,920
import time def convert_time(time_string): """ Input a time in HH:MM:SS form and output a time object representing that """ return time.strptime(time_string, "%H:%M")
f34b46fe8cd242ee12a9768102486cba243d94df
706,921
from typing import Dict def _build_request_url( base: str, params_dict: Dict[str, str]) -> str: """Returns an URL combined from base and parameters :param base: base url :type base: str :param params_dict: dictionary of parameter names and values :type params_dict: Dict[str, str]...
30e27cf55692884be408218403c2f94279516ad2
706,922
def get_players(picks): """Return the list of players in the team """ players = [] for rd in picks: play = list(rd.keys()) players = players+play players = list(set(players)) return players
79963bc19af662d44d4eaf29a04995ede331706c
706,923
def sub_vectors(a, b): """Subtracts two vectors. Args: pos1 (tuple[int]): first position pos1:(tuple[int]): second position Returns: tuple[int]: element wise subtraction Examples: >>> sub_vectors((1,4,6), (1,3,7)) (0, 1, -1) """ return tuple(a[i] - b[i]...
02c35bf46311142a3f3e90cd803d908c6ff63896
706,924
import re def text_pre_process(result): """ 이미지에서 인식된 글자를 정제 합니다. 특수문자 제거, 1-2단어 제거, 줄바꿈 및 공백 제거 :param result: 이미지에서 인식된 글자 :return: 문자를 전처리한 결과 """ copy = str(result) copy2 = copy.replace("\n", "") copy3 = re.sub('[^ㄱ-힗]', '', copy2) # re.sub('[^A-Za-z0-9]', '', copy2) result = re.sub('[-=+,#}/\{:^$.@...
c9a25fb19a723d38eb19a8a086a2134369223ea1
706,925
import argparse def ParseCommandYAML(): """Function for parsing command line arguments for input to YAML HDIprep""" # if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("--im", nargs='*') parser.add_argument("--pars") parser.add_argument("--out_dir") args = ...
3a56d16d960f59f0afd888120c19d12b0b6f25b3
706,927
import torch def x_gate(): """ Pauli x """ return torch.tensor([[0, 1], [1, 0]]) + 0j
736d72d832380ea5a1d6c4a840cb6aa0050638e5
706,928
def merge_dictionaries(default_dictionary, user_input_dictionary, path=None): """Merges user_input_dictionary into default dictionary; default values will be overwritten by users input.""" return {**default_dictionary, **user_input_dictionary}
ea600efcd69e920ae536fa2f22a4c883a71d8ad3
706,929
def get_fiber_protein_intake( nutrients_lower_lists, nutrients_middle_lists,nutrients_upper_lists): """Gets financial class-wise fibee and protein intake data.""" lower_fiber_prot = nutrients_lower_lists.map(lambda x: (x[1], x[3])) middle_fiber_prot = nutrients_middle_lists.map(lambda x: (x[1], x[3...
990293236a10ed18960393b39dbfb46652fca51d
706,930
def _format_rest_url(host: str, append: str = "") -> str: """Return URL used for rest commands.""" return f"http://{host}:8001/api/v2/{append}"
1d5ace3919da004e648cb6c7d6d80fe72903c0e1
706,931
def is_correlated(corr_matrix, feature_pairs, rho_threshold=0.8): """ Returns dict where the key are the feature pairs and the items are booleans of whether the pair is linearly correlated above the given threshold. """ results = {} for pair in feature_pairs: f1, f2 = pair.split("__"...
18afa0cc24f5d9205cde3c8ad23f70d73b5c395b
706,932
def find_password(liste, login): """ """ for user in liste: if user[0] == login: return user[1] return None
8f61072a8b1cc34eb27c1665b1cd34aeb6630ce2
706,933
def get_bin_values(base_dataset, bin_value): """Gets the values to be used when sorting into bins for the given dataset, from the configured options.""" values = None if bin_value == "results": values = base_dataset.get_output() elif bin_value == "all": # We set all values to 0, assuming...
cf2419066d6e642e65d9a8747081ebfee417ed64
706,934
async def get_temperatures(obj): """Get temperatures as read by the thermostat.""" return await obj["madoka"].temperatures.query()
b4643d9c40f6aa8953c598dd572d291948ef34a4
706,935
import math def acos(x): """ """ return math.acos(x)
0a8ca8f716f0ea54b558ca27021830480dac662d
706,936
def transaction_update_spents(txs, address): """ Update spent information for list of transactions for a specific address. This method assumes the list of transaction complete and up-to-date. This methods loops through all the transaction and update all transaction outputs for given address, checks ...
6ac33306cafd5c75b37e73c405fff4bcc732226f
706,937
def count_tilings(n: int) -> int: """Returns the number of unique ways to tile a row of length n >= 1.""" if n < 5: # handle recursive base case return 2**(n - 1) else: # place each tile at end of row and recurse on remainder return (count_tilings(n - 1) + cou...
70f9caa9a27c65c73862dd8c415d93f5a7122632
706,938
import math def _meters_per_pixel(zoom, lat=0.0, tilesize=256): """ Return the pixel resolution for a given mercator tile zoom and lattitude. Parameters ---------- zoom: int Mercator zoom level lat: float, optional Latitude in decimal degree (default: 0) tilesize: int, opt...
467d23bd437f153345c67c8c1cab1a086fde4995
706,939
def manhattanDistance( xy1, xy2 ): """Returns the Manhattan distance between points xy1 and xy2""" return abs( xy1[0] - xy2[0] ) + abs( xy1[1] - xy2[1] )
ce0ee21237f253b1af33fbf088292405fd046fe3
706,940
def verifyIP(ip): """Verifies an IP is valid""" try: #Split ip and integer-ize it octets = [int(x) for x in ip.split('.')] except ValueError: return False #First verify length if len(octets) != 4: return False #Then check octet values for octet in octets: if octet < 0 or octet > 255: return ...
72c373099a75adb2a1e776c863b6a2d1cb2698df
706,941
from datetime import datetime def get_datetime_now(t=None, fmt='%Y_%m%d_%H%M_%S'): """Return timestamp as a string; default: current time, format: YYYY_DDMM_hhmm_ss.""" if t is None: t = datetime.now() return t.strftime(fmt)
c4fc830b7ede9d6f52ee81c014c03bb2ef5552dc
706,942
def is_firstline(text, medicine, disease): """Detect if first-line treatment is mentioned with a medicine in a sentence. Use keyword matching to detect if the keywords "first-line treatment" or "first-or second-line treatment", medicine name, and disease name all appear in the sentence. Parameters ---------- ...
c9f8a31c6089c4f7545780028ccb1a033372c284
706,943
def file_reader(file_name): """file_reader""" data = None with open(file_name, "r") as f: for line in f.readlines(): data = eval(line) f.close() return data
6d3d63840cc48ccfdd5beefedf0d3a60c0f44cf9
706,944
import os def dir_is_cachedir(path): """Determines whether the specified path is a cache directory (and therefore should potentially be excluded from the backup) according to the CACHEDIR.TAG protocol (http://www.brynosaurus.com/cachedir/spec.html). """ tag_contents = b'Signature: 8a477f597d2...
b63f46ebafe6ff3c917325e19adfec551497ce68
706,945
def clean_str(string: str) -> str: """ Cleans strings for SQL insertion """ return string.replace('\n', ' ').replace("'", "’")
d3833293163114642b4762ee25ea7c8f850e9d54
706,946
import os def explode(req: str): """Returns the exploded dependency list for a requirements file. As requirements files can include other requirements files with the -r directive, it can be useful to see a flattened version of all the constraints. This method unrolls a requirement file and produces a...
1a4c389537dcc9e5abd34d19ed386c48d3d6ecc6
706,947
def get_output_attribute(out, attribute_name, cuda_device, reduction="sum"): """ This function handles processing/reduction of output for both DataParallel or non-DataParallel situations. For the case of multiple GPUs, This function will sum all values for a certain output attribute in various batch...
c09ff6a3dd4ae2371b1bbec12d4617e9ed6c6e1e
706,948
def get_ref_aidxs(df_fs): """Part of the hotfix for redundant FCGs. I did not record the occurrence id in the graphs, which was stupid. So now I need to use the df_fs to get the information instead. Needs to be used with fid col, which is defined in filter_out_fcgs_ffs_all. """ return {k: v for ...
9b57d7297d96f6b711bb9d3c37f85a17c4ccacd5
706,949
def format_info(info): """ Print info neatly """ sec_width = 64 eq = ' = ' # find key width key_widths = [] for section, properties in info.items(): for prop_key, prop_val in properties.items(): if type(prop_val) is dict: key_widths.append(len(max(list(p...
9dd3a6ef15909230725f2be6eb698e7ca08a2d8b
706,950
import collections def _get_ordered_label_map(label_map): """Gets label_map as an OrderedDict instance with ids sorted.""" if not label_map: return label_map ordered_label_map = collections.OrderedDict() for idx in sorted(label_map.keys()): ordered_label_map[idx] = label_map[idx] return ordered_labe...
4c5e56789f57edda61409f0693c3bccb57ddc7cf
706,951
def eight_interp(x, a0, a1, a2, a3, a4, a5, a6, a7): """``Approximation degree = 8`` """ return ( a0 + a1 * x + a2 * (x ** 2) + a3 * (x ** 3) + a4 * (x ** 4) + a5 * (x ** 5) + a6 * (x ** 6) + a7 * (x ** 7) )
98be2259c9e0fae214234b635a3ff55608f707d1
706,952
def _splitaddr(addr): """ splits address into character and decimal :param addr: :return: """ col='';rown=0 for i in range(len(addr)): if addr[i].isdigit(): col = addr[:i] rown = int(addr[i:]) break elif i==len(addr)-1: col=addr...
6f4ef43ed926a468ae5ae22fc062fe2b2701a18a
706,953
def remoteness(N): """ Compute the remoteness of N. Parameters ---------- N : Nimber The nimber of interest. Returns ------- remote : int The remoteness of N. """ if N.n == 0: return 0 remotes = {remoteness(n) for n in N.left} if all(remote % 2...
6ea40df2a79a2188b3d7c9db69ee9038ec2e6462
706,954
def extendCorrespondingAtomsDictionary(names, str1, str2): """ extends the pairs based on list1 & list2 """ list1 = str1.split() list2 = str2.split() for i in range(1, len(list1)): names[list1[0]][list2[0]].append([list1[i], list2[i]]) names[list2[0]][list1[0]].append([list2[i], list...
cb586be8dcf7a21af556b332cfedbdce0be6882a
706,955
def split_to_sentences(data): """ Split data by linebreak "\n" Args: data: str Returns: A list of sentences """ sentences = data.split('\n') # Additional clearning (This part is already implemented) # - Remove leading and trailing spaces from each sentence...
56540da88e982615e3874ab9f6fd22229a076565
706,956
def read_config_file(fp: str, mode='r', encoding='utf8', prefix='#') -> dict: """ 读取文本文件,忽略空行,忽略prefix开头的行,返回字典 :param fp: 配置文件路径 :param mode: :param encoding: :param prefix: :return: """ with open(fp, mode, encoding=encoding) as f: ll = f.readlines() ll = [i for i in...
94e6130de22b05ca9dd6855206ec748e63dad8ad
706,957
def custom_address_validator(value, context): """ Address not required at all for this example, skip default (required) validation. """ return value
06ec3af3b6103c06be5fc9cf30d1af28bd072193
706,958
def get_trajectory_for_weight(simulation_object, weight): """ :param weight: :return: """ print(simulation_object.name+" - get trajectory for w=", weight) controls, features, _ = simulation_object.find_optimal_path(weight) weight = list(weight) features = list(features) return {"w": ...
e68827fc3631d4467ae1eb82b3c319a4e45d6a9b
706,959
import warnings def get_integer(val=None, name="value", min_value=0, default_value=0): """Returns integer value from input, with basic validation Parameters ---------- val : `float` or None, default None Value to convert to integer. name : `str`, default "value" What the value rep...
9c967a415eaac58a4a4778239859d1f6d0a87820
706,960
import re def _get_variable_name(param_name): """Get the variable name from the tensor name.""" m = re.match("^(.*):\\d+$", param_name) if m is not None: param_name = m.group(1) return param_name
4f6258667383c80b584054af20ac9a61cf25381f
706,961
def get_mwis(input_tree): """Get minimum weight independent set """ num_nodes = input_tree['num_nodes'] nodes = input_tree['nodes'] if num_nodes <= 0: return [] weights = [0, nodes[0][0]] for idx, node_pair in enumerate(nodes[1:], start=1): node_weight, node_idx = node_pair ...
3df82615d1060756b1a4863fe168ea542dfed4f9
706,962
def trim_to_min_length(bits): """Ensures 'bits' have min number of leading zeroes. Assumes 'bits' is big-endian, and that it needs to be encoded in 5 bit blocks. """ bits = bits[:] # copy # make sure we can be split into 5 bit blocks while bits.len % 5 != 0: bits.prepend('0b0') # Ge...
d740ce27e0ebce30f382844a9810f7792c9b4669
706,963
def display(choices, slug): """ Get the display name for a form choice based on its slug. We need this function because we want to be able to store ACS data using the human-readable display name for each field, but in the code we want to reference the fields using their slugs, which are easier to ch...
e177fa4596de8a9921d05216d51344e95dce89ab
706,964
def yes_or_no(question, default="no"): """ Returns True if question is answered with yes else False. default: by default False is returned if there is no input. """ answers = "yes|[no]" if default == "no" else "[yes]|no" prompt = "{} {}: ".format(question, answers) while True: answe...
496137bcd3d99a3f0bcc5bb87ab3dc090f8fc414
706,965
def decode(encoded: list): """Problem 12: Decode a run-length encoded list. Parameters ---------- encoded : list The encoded input list Returns ------- list The decoded list Raises ------ TypeError If the given argument is not of `list` type """ ...
8fb273140509f5a550074c6d85e485d2dc1c79d0
706,966
import random def create_offset(set_point_value): """Docstring here (what does the function do)""" offset_value = random.randint(-128, 128) offset_value_incrementation = float(offset_value / 100) return set_point_value - offset_value_incrementation
8b41ce32d98edd87c2317a971d87f9b74c3f1b6c
706,967
import re def clean_url(str_text_raw): """This function eliminate a string URL in a given text""" str_text = re.sub("url_\S+", "", str_text_raw) str_text = re.sub("email_\S+", "", str_text) str_text = re.sub("phone_\S+", "", str_text) return(re.sub("http[s]?://\S+", "", str_text))
f14d4647bad72ec08aa64f19bbdd2726eb47d63b
706,968
def calculate_prec_at_k(k, prediction, target): """ Calculating precision at k. """ best_k_pred = prediction.argsort()[:k] best_k_target = target.argsort()[:k] return len(set(best_k_pred).intersection(set(best_k_target))) / k
61637938078b938e90f6ada70888512a97435ca1
706,969
def get_ttl(cur): """Get the 'extract' table as lines of Turtle (the lines are returned as a list).""" # Get ttl lines cur.execute( """WITH literal(value, escaped) AS ( SELECT DISTINCT value, replace(replace(replace(value, '\\', '\\\\'), '"', '\\"'), ' ...
454b843bfc47b5a6f11cc06ea881773421499eed
706,970
def geom_cooling(temp, k, alpha = 0.95): """Geometric temperature decreasing.""" return temp * alpha
4263e4cc8a5de21d94bc560e8ff364d8c07f97fd
706,971
import re def bytes_to_escaped_str(data, keep_spacing=False, escape_single_quotes=False): """ Take bytes and return a safe string that can be displayed to the user. Single quotes are always escaped, double quotes are never escaped: "'" + bytes_to_escaped_str(...) + "'" gives a valid Python st...
fe8aa0ed3a8e3f2c7a2cf1aaeebc555b7281bde7
706,972
def is_polindrom(string): """ This function checks whether the given string is a polindrom or not. """ for i,char in enumerate(string): if char != string[-i-1]: return False return True
94e3cdb68c538da7b18e4567dc62fb35a58ebebb
706,973
def int_div_test(equation, val): """ Comparison for the integer division binary search. :equation: Equation to test :val: Input to the division """ r1 = equation(val) if r1 == None: return None r2 = equation(val - 1) if r2 == None: return None if r1 == 1 and r2 ...
16b9106ddb1fc7472339019926a891c6c1942d18
706,975
import re def clean_caption(text): """ Remove brackets with photographer names or locations at the end of some captions :param text: a photo caption :return: text cleaned """ text = str(text) text = re.sub(r'\s*\[.+?\]$', '.', text) text = re.sub(r'\s*\(photo.+?\)', '', text) retur...
f07713de58c8304e437904914c78f89c795d9776
706,976
import math def score_mod(mod, word_count, mod_count, mod_match_unlabel): """计算模式的评分""" p = word_count[mod] u = len(mod_match_unlabel[mod]) t = mod_count[mod] return (p / t) * math.log(u + 1, 2) * math.log(p + 1, 2)
1184800a2b6a2ebfbbbdcbcbf4a0d8f8cb261e98
706,977
import json def read_anno_content(anno_file: str): """Read anno content.""" with open(anno_file) as opened: content = json.load(opened) return content
208d5f92d479ebfc0aa1e93d26ca68d3ce2a1e7e
706,978
def hex_form(hash): """Returns the hash formatted in hexadecimal form""" final_hash = '' for i in range(len(hash)): final_hash += format(hash[i], '02x') return final_hash
67c1d376352517a9f368dfc56f03f1af3d45e128
706,979
def user_tickets(raffle_prize, user): """return the allocate ticket for user""" return raffle_prize.allocated_tickets(user)
a29c578713664018f639088539f2404fc7a63171
706,980
def get_corners(n): """Returns corner numbers of layer n""" end = end = (2*n + 1) * (2*n + 1) return [end-m*n for m in range(0,8,2)]
8d78135f13675d01fc2b6736b7c1fb1e7cf3e5f5
706,981
from datetime import datetime def datetime_to_timestamp(dt, epoch=datetime(1970,1,1)): """takes a python datetime object and converts it to a Unix timestamp. This is a non-timezone-aware function. :param dt: datetime to convert to timestamp :param epoch: datetime, option specification of start of ep...
2fbd5b3d6a56bc04066f7aaa8d4bef7c87a42632
706,982
def connectivity_dict_builder(edge_list, as_edges=False): """Builds connectivity dictionary for each vertex (node) - a list of connected nodes for each node. Args: edge_list (list): a list describing the connectivity e.g. [('E7', 'N3', 'N6'), ('E2', 'N9', 'N4'), ...] as_edges (b...
58f24c6465fa1aaccca92df4d06662b0ce1e1e77
706,983
import socket def init_socket(): """Returns a fresh socket""" return socket.socket()
429d790f3007a357d4a14d57066d890f14f42178
706,984
import os def get_file_size(path: str): """ Return the size of a file, reported by os.stat(). Args: path: File path. """ return os.path.getsize(path)
f6e7dc89c1fc046f1492bad43eae8c8a14e335af
706,985
import torch def predict(model, dataloader): """Returns: numpy arrays of true labels and predicted probabilities.""" device = torch.device("cuda" if torch.cuda.is_available() else "cpu") model.to(device) model.eval() labels = [] probs = [] for batch_idx, batch in enumerate(dataloader): ...
1e4b6e1f72127174a8bdbc693665ace8cbe8e4af
706,986
def get_model_config(model): """Returns hyper-parameters for given mode""" if model == 'maml': return 0.1, 0.5, 5 if model == 'fomaml': return 0.1, 0.5, 100 return 0.1, 0.1, 100
dcdfb3c00026a172b22611ad3203a7c32d8e59d7
706,987
def find_longest_substring(s: str, k: int) -> str: """ Speed: ~O(N) Memory: ~O(1) :param s: :param k: :return: """ # longest substring (found) lss = "" # current longest substring c_lss = "" # current list of characters for the current longest substring c_c = [] ...
78936d140ea1e54945c6b4dd849b38f0c5604a36
706,988
def _fixTool2(scModel,gopLoader): """ :param scModel: :param gopLoader: :return: @type scModel: ImageProjectModel """ def replace_tool(tool): return 'jtui' if 'MaskGenUI' in tool else tool modifier_tools = scModel.getGraph().getDataItem('modifier_tools') if modifier_tools ...
3eb3bf8a47514a28c2e699a2eeefb084f9f7923b
706,989
import re def name_convert_to_camel(name: str) -> str: """下划线转驼峰""" contents = re.findall('_[a-z]+', name) for content in set(contents): name = name.replace(content, content[1:].title()) return name
109a1035a3efa98861b6a419206823b1114268e2
706,990
import decimal def as_decimal(dct): """Decodes the Decimal datatype.""" if '__Decimal__' in dct: return decimal.Decimal(dct['__Decimal__']) return dct
d25b3ff73d7559a9018666d5f2cd189e6503a268
706,991
def calc_recall(TP, FN): """ Calculate recall from TP and FN """ if TP + FN != 0: recall = TP / (TP + FN) else: recall = 0 return recall
8f3513e11f8adad111eee32740c271aad31fbe28
706,992
def make_segment(segment, discontinuity=False): """Create a playlist response for a segment.""" response = [] if discontinuity: response.append("#EXT-X-DISCONTINUITY") response.extend(["#EXTINF:10.0000,", f"./segment/{segment}.m4s"]), return "\n".join(response)
8419b100409934f902c751734c396bc72d8a6917
706,993
from typing import Any def from_dicts(key: str, *dicts, default: Any = None): """ Returns value of key in first matchning dict. If not matching dict, default value is returned. Return: Any """ for d in dicts: if key in d: return d[key] return ...
508febc48fd22d3a23dc0500b0aa3824c99fdbc3
706,994
def time_in_words(h, m): """Hackerrank Problem: https://www.hackerrank.com/challenges/the-time-in-words/problem Given the time in numerals we may convert it into words, as shown below: ---------------------------------------------- | 5:00 | -> | five o' clock | | 5:01 | -> | one m...
85f2247f01df36ef499105a9940be63eee189100
706,995
def majorityElement(nums): """超过三分之一的数,最多不超过两个数""" num1, num2 = -1, -1 count1, count2 = 0, 0 for i in range(len(nums)): curNum = nums[i] if curNum == num1: count1 += 1 elif curNum == num2: count2 += 1 elif count1 == 0: num1 = curNum ...
ef71fa445c3bc16bbaf79a1ab4e9548125e71b7b
706,996