content
stringlengths
35
416k
sha1
stringlengths
40
40
id
int64
0
710k
def lenzi(df): """Check if a pandas series is empty""" return len(df.index) == 0
561705e6ff0da3bfb03407a721f2aff71a4d42a1
4,905
def num_to_int(num): """ Checks that a numerical value (e.g. returned by robot) is an integer and not a float. Parameters ---------- num : number to check Returns ------- integer : num cast to an integer Raises ------ ValueError : if n is not an integer """ if ...
af470940eb035fe8dd0160dfe9614c2b6d060194
4,906
def format_timedelta(tdelta): """Return the timedelta as a 'HH:mm:ss' string.""" total_seconds = int(tdelta.total_seconds()) hours, remainder = divmod(total_seconds, 60*60) minutes, seconds = divmod(remainder, 60) return "{0:02d}:{1:02d}:{2:02d}".format(hours, minutes, seconds)
852902e7972bcd13df8b60864ebcb2d75b2b259d
4,907
from typing import Tuple import torch def permute_adjacency_twin(t1,t2) -> Tuple[torch.Tensor,torch.Tensor]: """ Makes a permutation of two adjacency matrices together. Equivalent to a renaming of the nodes. Supposes shape (n,n) """ n,_ = t1.shape perm = torch.randperm(n) return t1[perm,:]...
df3dc6507b8eae9d148ec9b2e664a427813d93a7
4,908
def make_element_weight_parser(weight_column): """ Parameterize with the column - this allows us to generate data from different analysis result types. """ def parse_element_weight(csv_row): name = csv_row[0] weight = float(csv_row[weight_column]) # Assert not zero? return name, weight return parse_element...
ddc3a4f82ecd0fe4833683759b1a1c4296839a54
4,909
def five_fold(data_set): """[summary] Args: data_set (List of Sample objects): The Samples to be partitioned Returns: fold: where fold is list of len n in n-fold of (train,test) where train and test are lists of Samples """ partition_index = int( len(data_set) / 5 ) s = 0 fol...
d4179c238da3e9ebe05ab3513b80bcce982c8728
4,911
from typing import List import os import requests def _query_trembl(accessions: List[str], format: str) -> str: """Searches TrEMBL server for UniProt entries based on accession. The server to use is set as an environment variable 'TREMBL_SERVER'. Normally this would be the internal TrEMBL server which co...
625f2fdc2054a1ed864e6a3258d00fe33f43787e
4,912
def cache(f): """A decorator to cache results for a given function call. Note: The caching is only done on the first argument, usually "self". """ ret = {} def _Wrapper(*args, **kwargs): self = args[0] if self not in ret: ret[self] = f(*args, **kwargs) return ret...
786218b8c248bcb7c9d519a843dd4542a9b612b0
4,913
def trim_filters(response): """Trim the leading and trailing zeros from a 1-D array or sequence, leaving one zero on each side. This is a modified version of numpy.trim_zeros. Parameters ---------- response : 1-D array or sequence Input array. Returns ------- first : int ...
2582c5821bd5c8487c0f9d2f55d2d982767d2669
4,914
from pathlib import Path from typing import List import os def relative_paths(root: Path, paths: list) -> List[str]: """ Normalises paths from incoming configuration and ensures they are all strings relative to root """ result = [] for path in paths: # more hacks for exclusions I'm not...
8193669491bc33b3014f1b44ca7ef4157e760af0
4,916
import bs4 def is_comment(obj): """Is comment.""" return isinstance(obj, bs4.Comment)
e56749b3d5f95754a031cc7286229d942333a22e
4,919
import itertools def CollapseDictionary(mapping): """ Takes a dictionary mapping prefixes to URIs and removes prefix mappings that begin with _ and there is already a map to their value >>> from rdflib import URIRef >>> a = {'ex': URIRef('http://example.com/')} >>> a['_1'] = a['ex'] ...
9f2befbd52b75b75aa15cadf9e68d5f9eebcae71
4,920
import logging def _VerifyOptions(options): """Verify the passed-in options. Args: options: The parsed options to verify. Returns: Boolean, True if verification passes, False otherwise. """ if options.endpoints_service and not options.openapi_template: logging.error('Please specify openAPI tem...
872feb5ac314ed2ef28ddbfaeff1b5dafc5e9ed8
4,921
def parse_line(line): """ Parse a queue trace line into a dict """ line = line.split() result = {} if len(line) < 12: return result result["event"] = line[0] result["time"] = float(line[1]) result["from"] = int(line[2]) result["to"] = int(line[3]) result["type"] = line[4]...
432e6a624626e89d27fe6d3d9ed7c4230d97c0a6
4,922
def get_census_params(variable_ids, county_level=False): """Gets census url params to make an API call. variable_ids: The ids of the variables to request. Automatically includes NAME. county_level: Whether to request at the county level, or the state level.""" keys = variable_ids.copy() key...
b24204c8e9ef82575b54151bdc0ac98de0fb7fc0
4,923
def lookupName(n, names): """Check if name is in list of names Parameters ---------- n : str Name to check names : list List of names to check in Returns ------- bool Flag denoting if name has been found in list (True) or not (False) """ if n in names:...
0fbb97e252f5daf9de52a946c206fa74395b01c6
4,924
def calculate_appointments(new_set, old_set): """ Calculate different appointment types. Used for making useful distinctions in the email message. new_set will be the fresh set of all available appointments at a given interval old_set will the previous appointments variable getting passed in. ...
b54735293ba910e2b310e55e263e2611863d088a
4,925
def add(left: int, right: int): """ add up two numbers. """ print(left + right) return 0
75d7bd10cfdfb38211f6faf838b5e200e8593693
4,926
import random def rand_x_digit_num(x): """Return an X digit number, leading_zeroes returns a string, otherwise int.""" return '{0:0{x}d}'.format(random.randint(0, 10**x-1), x=x)
b46864143ca6186ebeede6c687a85d1b585e70db
4,927
def subtractNums(x, y): """ subtract two numbers and return result """ return y - x
2b16636e74a2d1a15e79e4669699c96adcd3833b
4,928
import os import shutil def _copy_and_rename_file(file_path: str, dest_dir: str, new_file_name): """ Copies the specified file to the dest_dir (creating the directory if necessary) and renames it to the new_file_name :param file_path: file path of the file to copy :param dest_dir: directory to copy th...
b53ce9d5e968e257919c8f2eb7749a171eddb59d
4,929
def filter_X_dilutions(df, concentration): """Select only one dilution ('high', 'low', or some number).""" assert concentration in ['high','low'] or type(concentration) is int df = df.sort_index(level=['CID','Dilution']) df = df.fillna(999) # Pandas doesn't select correctly on NaNs if concentration...
b886c87c1c5b96e6efc951ef197d3a0fb13707c1
4,930
def update_params(base_param: dict, additional: dict): """overwrite base parameter dictionary Parameters ---------- base_param : dict base param dictionary additional : dict additional param dictionary Returns ------- dict updated parameter dictionary """ ...
e73581cb0b8d264343ead56da52c6dc12fe49dd7
4,931
def briconToScaleOffset(brightness, contrast, drange): """Used by the :func:`briconToDisplayRange` and the :func:`applyBricon` functions. Calculates a scale and offset which can be used to transform a display range of the given size so that the given brightness/contrast settings are applied. :...
b75ce49f4e79f7fef34a855f2897cfa6b4bd7cc7
4,932
import pathlib def check_path(path: pathlib.Path) -> bool: """Check path.""" return path.exists() and path.is_file()
2279dde6912ae6f6eb51d90ed5e71e0b3892fea9
4,933
def count(A,target): """invoke recursive function to return number of times target appears in A.""" def rcount(lo, hi, target): """Use recursion to find maximum value in A[lo:hi+1].""" if lo == hi: return 1 if A[lo] == target else 0 mid = (lo+hi)//2 left = rcount(lo...
79d9be64d332a11993f65f3c0deba8b4de39ebda
4,935
def is_bool_type(typ): """ Check if the given type is a bool. """ if hasattr(typ, '__supertype__'): typ = typ.__supertype__ return isinstance(typ, type) and issubclass(typ, bool)
3d8dfae184be330c8cbd7c0e7382311fef31ede5
4,936
import os def get_file_paths(directory, file=None): """ Collects the file paths from the given directory if the file is not given, otherwise creates a path joining the given directory and file. :param directory: The directory where the file(s) can be found :param file: A file in the directory ...
62e79a52682e046b83f9ad89df18d4dece7bf37a
4,937
import numpy def interpolate_missing(sparse_list): """Use linear interpolation to estimate values for missing samples.""" dense_list = list(sparse_list) x_vals, y_vals, x_blanks = [], [], [] for x, y in enumerate(sparse_list): if y is not None: x_vals.append(x) y_vals.a...
a2983a08f00b4de2921c93cc14d3518bc8bd393d
4,938
def get_jmp_addr(bb): """ @param bb List of PseudoInstructions of one basic block @return Address of jump instruction in this basic block """ for inst in bb: if inst.inst_type == 'jmp_T': return inst.addr return None
13e69032bc7d6ed5413b5efbb42729e11661eab1
4,939
def totals_per_time_frame(data_points, time_frame): """For a set of data points from a single CSV file, calculate the average percent restransmissions per time frame Args: data_points (List[List[int,int,float]]): A list of data points. Each data...
9e71ac2fe7deabd36d7df8ae099575b191260c5d
4,941
import torch def predict_batch(model, x_batch, dynamics, fast_init): """ Compute the softmax prediction probabilities for a given data batch. Args: model: EnergyBasedModel x_batch: Batch of input tensors dynamics: Dictionary containing the keyword arguments for the rel...
61102cfa3bcb3e7d52e9f3eca8c97db4d726c1a7
4,944
import math def get_test_paths(paths, snaps): """ Return $snaps paths to be tested on GLUE """ if snaps == -1: return paths interval = len(paths) * 1. / snaps test_paths = [] for i in range(1, snaps+1): idx = int(math.ceil(interval * i)) - 1 test_paths.append(paths[...
a2ac1f89740e85b6322e553559850c0e686a28c8
4,945
def is_success(code): """Return that the client's request was successfully received, understood, and accepted.""" return 200 <= code <= 299
8a6e64c0f218ca5a866a444c730e1ebf7628727e
4,946
def transform(x,y): """ This function takes an input vector of x values and y values, transforms them to return the y in a linearized format (assuming nlogn function was used to create y from x) """ final = [] for i in range(0, len(y)): new = y[i]#/x[i] final.append(2 ** new)...
119db625f5ebf469794bf3bdacd20a1c70ccd133
4,948
import argparse def get_args(arg_input): """Takes args input and returns them as a argparse parser Parameters ------------- arg_input : list, shape (n_nargs,) contains list of arguments passed to function Returns ------------- args : namespace contains namespace with k...
25b01282deef981197b2c7b62d33211a3200e787
4,950
def cleanup_databases(): """ Returns: bool: admin_client fixture should ignore any existing databases at start of test and clean them up. """ return False
63fa94389609b8e28779d1e9e55e9b1ecde502b6
4,951
def spot_centroid(regions): """Returns centroids for a list of regionprops. Args: regions (regionprops): List of region proposals (skimage.measure). Returns: list: Centroids of regionprops. """ return [r.centroid for r in regions]
f53f403dddf0af123afd207e33cc06254a0f2538
4,952
def overrides(conf, var): """This api overrides the dictionary which contains same keys""" if isinstance(var, list): for item in var: if item in conf: for key, value in conf[item].items(): conf[key] = value elif var in conf: for key, value in c...
18375dc43a0d684feaf9089756ecb45eb5a366f3
4,953
def make_hashable(data): """Make the given object hashable. It makes it ready to use in a `hash()` call, making sure that it's always the same for lists and dictionaries if they have the same items. :param object data: the object to hash :return: a hashable object :rtype: object """ if...
e4b88978ddee6d4dfc354845184a0e80b1f434bf
4,954
import os import glob def check_file(file): """ 检查本地有没有这个文件,相关文件路径能否找到文件 并返回文件名 """ # 如果传进来的是文件或者是’‘, 直接返回文件名str if os.path.isfile(file) or file == '': return file # 如果传进来的就是当前项目下的一个全局路径 查找匹配的文件名返回第一个 else: files = glob.glob('./**/' + file, recursive=True) # 验证文件名是否...
9a1d3283a26a1fcdca67622413dc4fc8e887fbee
4,955
import torch def regular_channels(audio ,new_channels): """ torchaudio-file([tensor,sample_rate])+target_channel -> new_tensor """ sig ,sr =audio if sig.shape[0 ]==new_channels: return audio if new_channels==1: new_sig =sig[:1 ,:] # 直接取得第一个channel的frame进行操作即可 else: ...
5b055d965f35fc4cf0f434b34e8f579f321fee89
4,957
def a_function(my_arg, another): """ This is the brief description of my function. This is a more complete example of my function. It can include doctest, code blocks or any other reST structure. >>> a_function(10, [MyClass('a'), MyClass('b')]) 20 :param int my_arg: The first argument of ...
8624edfe3ec06b53e065a6672c3b21682cdefe06
4,958
import pandas import logging def _shape(df): """ Return DataFrame shape even if is not a Pandas dataframe.""" if type(df) == pandas.DataFrame or type(df) == pandas.Series: return df.shape try: shape = (len(df), len(df.columns)) except Exception as e: logging.error(e) ra...
d5af0e3f92ee649091d9fc8b904e60931fb0f2f7
4,959
import subprocess def get_cmd_output(cmd): """Run a command in shell, and return the Unicode output.""" try: data = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as ex: data = ex.output try: data = data.decode("utf-8") ...
f1ac61b45b2adb404b50c5001e8737db2c0a9c95
4,960
import os def get_window_size(): """Return the window width and height""" width = os.popen( "xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f1").read().strip( "\n") height = os.popen( "xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f2").rea...
7d28746f6c1805e31d93b4c934b9442a19d4cfa1
4,961
def homology(long_sequence, short_sequence): """ Cross-compare to find the strand of long sequence with the highest similarity with the short sequence. :param long_sequence: str :param short_sequence: str :return ans: str, the strand of long sequence with the highest similarity with the short sequen...
1865e7b60cfce3b1ca4e7884377a5a218ecba96a
4,963
import logging def create_sql_delete_stmt(del_list, name): """ :param del_list: list of records that need to be formatted in SQL delete statement. :param name: the name of the table :return: SQL statement for deleting the specific records """ sql_list = ", ".join(del_list) sql_stmt = f"DEL...
aec744198f1b0dd30836f431ac51a4080911f8ae
4,964
def sanitize_email(email): """ Returns an e-mail address in lower-case and strip leading and trailing whitespaces. >>> sanitize_email(' MyEmailAddress@example.com ') 'myemailaddress@example.com' """ return email.lower().strip()
b99e9c38db4fe889e1d0a9175d6535c4790f2f43
4,967
def greet(name): """Greet message, formatted differently for johnny.""" if name == "Johnny": return "Hello, my love!" return "Hello, {name}!".format(name=name)
86efdaccd65a870fd80e402491e9468669cdcd40
4,968
def _toIPv4AddrString(intIPv4AddrInteger): """Convert the IPv4 address integer to the IPv4 address string. :param int intIPv4AddrInteger: IPv4 address integer. :return: IPv4 address string. :rtype: str Example:: intIPv4AddrInteger Return --------------------------------- ...
ac5f55146eedaf0b7caca19327ae0a88c9d5282a
4,970
import re def look_behind(s: str, end_idx: int) -> str: """ Given a string containing semi-colons, find the span of text after the last semi-colon. """ span = s[: (end_idx - 1)] semicolon_matches = [ (m.group(), m.start(), m.end()) for m in re.finditer(r"(?<=(;))", span) ] if l...
0cc478e73edd713fa72743f36e29001bb214e26c
4,971
import six import pytz def make_aware(dt, tz=None): """ Convert naive datetime object to tz-aware """ if tz: if isinstance(tz, six.string_types): tz = pytz.timezone(tz) else: tz = pytz.utc if dt.tzinfo: return dt.astimezone(dt.tzinfo) else: retur...
b5003de5055c5d283f47e33dfdd6fbe57d6fce96
4,972
from itertools import product def listCombination(lists) -> list: """ 输入多个列表组成的列表,返回多列表中元素的所有可能组合 :param lists: 多个列表组成的列表 :return: 所有元素可能的组合 """ result = [] resultAppend = result.append for i in product(*lists): resultAppend(i) return result
6023cdc205b2780c5cd2cf56113d48a0675b98bf
4,973
from typing import List def sequence_to_ngram(sequence: str, N: int) -> List[str]: """ Chops a sequence into overlapping N-grams (substrings of length N) :param sequence: str Sequence to convert to N-garm :type sequence: str :param N: Length ofN-grams (int) :type N: int :return: List of n...
8cbe97ee34c75ca3aad038236bd875ea0c3450cd
4,974
def _format_path(path): """Format path to data for which an error was found. :param path: Path as a list of keys/indexes used to get to a piece of data :type path: collections.deque[str|int] :returns: String representation of a given path :rtype: str """ path_with_brackets = ( ''.j...
1809080453af154824e867cd8104cedbd616b937
4,975
import numpy def generateStructuredGridPoints(nx, ny, v0, v1, v2, v3): """ Generate structured grid points :param nx: number of x cells :param ny: number of y cells :param v0: south west corner :param v1: south east corner :param v2: north east corner :param v3: north west corner :...
0de9a3a3a47b26c3c3d56088c7ec55d241edeff3
4,977
def clear(keyword): """``clear`` property validation.""" return keyword in ('left', 'right', 'both', 'none')
c16cc980b9af82b4210e3c8c430cd65934596aa1
4,978
def _get_embl_key(line): """Return first part of a string as a embl key (ie 'AC M14399;' -> 'AC')""" # embl keys have a fixed size of 2 chars return line[:2]
b54f1a94f120f7ac63a0dd2a22bd47d5a5d5eeb9
4,979
import os def size_too_big(path): """Returns true is file is too large (5MB) """ five_mb = 5242880 return os.path.getsize(path) > five_mb
62e926247ab5439732ce61c8e59fe4a50366cba0
4,980
import os def local_tmp_dir(): """tmp directory for tests""" tmp_dir_path = "./tmp" if not os.path.isdir(tmp_dir_path): os.mkdir(tmp_dir_path) return tmp_dir_path
3f1f710ba18ec336982c69225c999a75fed9c481
4,981
def get_query_string_from_process_type_string(process_type_string: str) -> str: # pylint: disable=invalid-name """ Take the process type string of a Node and create the queryable type string. :param process_type_string: the process type string :type process_type_string: str :return: string that c...
1380ad90a98da26237176890c52a75684e92964e
4,982
def label_vertices(ast, vi, vertices, var_v): """Label each node in the AST with a unique vertex id vi : vertex id counter vertices : list of all vertices (modified in place) """ def inner(ast): nonlocal vi if type(ast) != dict: if type(ast) == list: # pr...
1216c3ff1f5995e24f0f3a245fad5db820335f4d
4,983
def object_gatekeeper(obj, is_auth, ignore_standalone=False): """ It's OK to use available_to_public here because the underlying logic is identical. """ if not obj: return False if is_auth: return True else: try: return obj.available_to_public except: ...
66f0749788f462ba9a0dfee6edf890245aca15ba
4,984
def adaptsim(f, a, b, eps=1e-8, max_iter=10000): """自适应 Simpson 求积 P.S. 这个函数名来自 Gander, W. and W. Gautschi, “Adaptive Quadrature – Revisited,” BIT, Vol. 40, 2000, pp. 84-101. 该文档可以在 https://people.inf.ethz.ch/gander/ 找到。 但该函数的实现并没有使用此文中的递归方法。 Args: f: 要求积的函数 ...
b24ed3c2493b8ece19a69cf781a75e7a9e0f9cd0
4,985
import numpy as np def smoothedEnsembles(data,lat_bounds,lon_bounds): """ Smoothes all ensembles by taking subsamples """ ### Import modules print('\n------- Beginning of smoothing the ensembles per model -------') ### Save MM newmodels = data.copy() mmean = newmodels[-1,:,:,:...
ed8fe2bc3d4e77384179d6a1a1406ca9446dc973
4,986
import socket def ip2host(ls_input): """ Parameters : list of a ip addreses ---------- Returns : list of tuples, n=2, consisting of the ip and hostname """ ls_output = [] for ip in ls_input: try: x = socket.gethostbyaddr(ip) ls_output.append((ip, x[0]))...
234b42bf0406ae5fb67d2c1caba9f7f3a1e92a0c
4,987
import itertools def merge(cluster_sentences): """ Merge multiple lists. """ cluster_sentences = list(itertools.chain(*cluster_sentences)) return cluster_sentences
ec5c9bf7a89bf0d047050d3684876ed481617706
4,988
import re def filter_output(output, regex): """Filter output by defined regex. Output can be either string, list or tuple. Every string is split into list line by line. After that regex is applied to filter only matching lines, which are returned back. :returns: list of matching records ...
d9760a644bb83aee513391966522946a6514ab72
4,990
def increment_with_offset(c: str, increment: int, offset: int) -> str: """ Caesar shift cipher. """ return chr(((ord(c) - offset + increment) % 26) + offset)
50b10b6d3aff3dff157dfc46c368ae251ed060bb
4,991
import numpy def phi_analytic(dist, t, t_0, k, phi_1, phi_2): """ the analytic solution to the Gaussian diffusion problem """ phi = (phi_2 - phi_1)*(t_0/(t + t_0)) * \ numpy.exp(-0.25*dist**2/(k*(t + t_0))) + phi_1 return phi
49fac597afa876f81ba5774bf82fedcfb88f6c7f
4,993
import subprocess def get_changed_files(base_commit: str, head_commit: str, subdir: str = '.'): """ Get the files changed by the given range of commits. """ cmd = ['git', 'diff', '--name-only', base_commit, head_commit, '--', subdir] files = subprocess.check_output(cmd) ...
ebc0a117f2f11d585475f4781e67331e3ca9a06a
4,994
def denormalize_ged(g1, g2, nged): """ Converts normalized ged into ged. """ return round(nged * (g1.num_nodes + g2.num_nodes) / 2)
214813120d552ef5ece10349978238117fe26cf3
4,995
import copy def ImproveData_v2 (Lidar_DataOld,Lidar_Data,Data_Safe,Speed,orientation,orientationm1): """ The function calculates new positions for obstacles now taking into account the car's relative speed in relation to each point. We need the accelerometer for that. Return: ...
2bd6c0f167e65ad4a461d75a95539b68dc0b1a70
4,996
def convert_to_signed_int_32_bit(hex_str): """ Utility function to convert a hex string into a 32 bit signed hex integer value :param hex_str: hex String :return: signed 32 bit integer """ val = int(hex_str, 16) if val > 0x7FFFFFFF: val = ((val+0x80000000) & 0xFFFFFFFF) - 0x80000000 ...
f8d39b20475c30f162948167f8534e367d9c58e8
4,998
def parent_node(max_child_node, max_parent_node): """ Parents child node into parent node hierarchy :param max_child_node: MaxPlus.INode :param max_parent_node: MaxPlus.INode """ max_child_node.SetParent(max_parent_node) return max_child_node
1a54d4c485e61361633165da0f05c8f871296ae6
4,999
import getpass import re import logging import sys def get_user(): """从终端获取用户输入的QQ号及密码""" username = input('please input QQ number: ').strip() if not re.match(r'^[1-9][0-9]{4,9}$', username): logging.error('\033[31mQQ number is wrong!\033[0m') sys.exit(1) password = getpass.getpass('p...
766e8332ea0bed1b793ba80cbf42a43bd54fb800
5,000
def check_if_bst(root, min, max): """Given a binary tree, check if it follows binary search tree property To start off, run `check_if_bst(BT.root, -math.inf, math.inf)`""" if root == None: return True if root.key < min or root.key >= max: return False return check_if_bst(root.left,...
1bb4b601ef548aec9a4ab2cf5242bc5875c587a2
5,001
def aggregate(collection, pipeline): """Executes an aggregation on a collection. Args: collection: a `pymongo.collection.Collection` or `motor.motor_tornado.MotorCollection` pipeline: a MongoDB aggregation pipeline Returns: a `pymongo.command_cursor.CommandCursor` or ...
03ea889ea23fb81c6a329ee270df2ac253e90d69
5,002
def _format_port(port): """ compute the right port type str Arguments ------- port: input/output port object Returns ------- list a list of ports with name and type """ all_ports = [] for key in port: one_port = {} one_port['name'] = key port...
2fa65686b6b764afc97a200a02baec65645c9879
5,004
import time def pretty_date(d): """ returns a html formatted pretty date """ special_suffixs = {1 : "st", 2 : "nd" , 3 : "rd", 21 : "st", 22 : "nd", 23 : "rd", 31 : "st"} suffix = "th" if d.tm_mday in special_suffixs: suffix = special_suffixs[d.tm_mday] suffix = "<sup>" + suffix + "</sup>" day = ti...
7d6675f115021ddd46b2a614e831c9fae8faf7ad
5,005
def _floor(n, base=1): """Floor `n` to a multiple of `base`""" return n // base * base
49019e4aa925b4f77a7f13f9919d36948bd132cc
5,007
import torch def n_step_returns(q_values, rewards, kls, discount=0.99): """ Calculates all n-step returns. Args: q_values (torch.Tensor): the Q-value estimates at each time step [time_steps+1, batch_size, 1] rewards (torch.Tensor): the rewards at each time step [time_steps, batch_size, 1]...
3bbd6026046328dc8ef63ab3e871f6c47636cb80
5,010
def function_3(): """This is a Function prototype in Python""" print("Printing Docs String") return 0
4268904e75772b9fef804931e3a3564fda333bc7
5,011
def get_character_bullet(index: int) -> str: """Takes an index and converts it to a string containing a-z, ie. 0 -> 'a' 1 -> 'b' . . . 27 -> 'aa' 28 -> 'ab' """ result = chr(ord('a') + index % 26) # Should be 0-25 if index > 25: current = index // 26 whi...
357f68feb302f11a996b5446c642ad9ca1f0f8d3
5,012
import sys def _system_path_separator(): """ System dependent character for element separation in PATH variable :rtype: str """ if sys.platform == 'win32': return ';' else: return ':'
b89a77d5b444a1b806a75e9f024f2084e3cfc93f
5,014
import argparse def init_argparse(): """Parses the required arguments file name and source database type and returns a parser object""" parser = argparse.ArgumentParser( usage="%(prog)s --filename 'test.dtsx' --source 'postgres'", description="Creates a configuration file in the output directo...
1c57c6712819d147ef7917d1100c20353339f7b4
5,015
import os import subprocess import logging def join(kmerfile, codonfile, minhashfile, dtemp): """Externally join with built-in GNU Coreutils in the order label, kmers, codons ,minhash Args: kmerfile (str): Kmer csv file codonfile (str): Codon csv file minhashfile (str): Minhas...
d3a373573d87a0312ecb8291bb0c81479f6402b6
5,017
def getNamespace(modelName): """Get the name space from rig root Args: modelName (str): Rig top node name Returns: str: Namespace """ if not modelName: return "" if len(modelName.split(":")) >= 2: nameSpace = ":".join(modelName.split(":")[:-1]) else: ...
abfb4c54f2dd1b54563f6c7c84e902ed4ee77b01
5,018
import os def get_output(db, output_id): """ :param db: a :class:`openquake.server.dbapi.Db` instance :param output_id: ID of an Output object :returns: (ds_key, calc_id, dirname) """ out = db('SELECT output.*, ds_calc_dir FROM output, job ' 'WHERE oq_job_id=job.id AND output.id=?...
8ad5cd6b5ca0808038ee29345b8d3e53e80fb9de
5,019
def normalize(output): """将null或者empty转换为暂无输出""" if not output: return '暂无' else: return output
18af58c74325522a64dcfd98a75f55e677c01ca3
5,020
def make_matrix(num_rows, num_cols, entry_fn): """retorna a matriz num_rows X num_cols cuja entrada (i,j)th é entry_fn(i, j)""" return [[entry_fn(i, j) # dado i, cria uma lista for j in range(num_cols)] # [entry_fn(i, 0), ... ] for i in range(num_rows)]
f706773245730eab3ce6cf41b0f6e81fbe3d52ab
5,021
def proj(A, B): """Returns the projection of A onto the hyper-plane defined by B""" return A - (A * B).sum() * B / (B ** 2).sum()
982cdfb1564166dce14432bf24404f066e2acee3
5,023
def v6_multimax(iterable): """Return a list of all maximum values. Bonus 2: Make the function works with lazy iterables. Our current solutions fail this requirement because they loop through our iterable twice and generators can only be looped over one time only. We could keep track of the maximu...
5539adb0dcb6c9db4f8f2f68487fc13c6aa8d067
5,024
import traceback def format_traceback_string(exception): """Format exception traceback as a single string. Args: exception: Exception object. Returns: Full exception traceback as a string. """ return '\n'.join( traceback.TracebackException.from_exception(exception).format...
debdf53966b26b6562671bf48d283a3bf10d85d5
5,025
def is_batch_norm(layer): """ Return True if `layer` is a batch normalisation layer """ classname = layer.__class__.__name__ return classname.find('BatchNorm') != -1
6494b75a3fbfbfd55ff43b05536a1094290ea915
5,026
import torch def predictive_entropy(y_input, y_target): """ Computes the entropy of predictions by the model :param y_input: Tensor [N, samples, class] :param y_target: Tensor [N] Not used here. :return: mean entropy over all examples """ y_input = torch.exp(y_input) # model output is log...
6c3c4c3cfc93d0c19e2662b54a9b6d41146264d5
5,027
async def find_user_by_cards(app, cards, fields=["username"]): """Find a user by a list of cards assigned to them. Parameters ---------- app : aiohttp.web.Application The aiohttp application instance cards : list The list of cards to search for fields : list, default=["username"...
ef5b20ea668b39eda51c859a3b33f1af30a644f5
5,030
def make_keyword_html(keywords): """This function makes a section of HTML code for a list of keywords. Args: keywords: A list of strings where each string is a keyword. Returns: A string containing HTML code for displaying keywords, for example: '<strong>Ausgangsw&ouml;rter:</stro...
71e35245ad7b2fe2c67f6a4c27d53374945089bd
5,031
def __hit(secret_number, choice): """Check if the choice is equal to secret number""" return secret_number == choice
55bee8370a2480b5ca84cd5f478fd8eb367276bd
5,035