content
stringlengths
35
416k
sha1
stringlengths
40
40
id
int64
0
710k
def _checker(word: dict): """checks if the 'word' dictionary is fine :param word: the node in the list of the text :type word: dict :return: if "f", "ref" and "sig" in word, returns true, else, returns false :rtype: bool """ if "f" in word and "ref" in word and "sig" in word: return...
ee6ec5a7ee393ddcbc97b13f6c09cdd9019fb1a6
709,680
def classified_unread_counts(): """ Unread counts return by helper.classify_unread_counts function. """ return { 'all_msg': 12, 'all_pms': 8, 'unread_topics': { (1000, 'Some general unread topic'): 3, (99, 'Some private unread topic'): 1 }, ...
4d5e984641de88fd497b6c78891b7e6478bb8385
709,681
def to_n_class(digit_lst, data, labels): """to make a subset of MNIST dataset, which has particular digits Parameters ---------- digit_lst : list for example, [0,1,2] or [1, 5, 8] data : numpy.array, shape (n_samples, n_features) labels : numpy.array or list of str Returns ------...
79652687ec0670ec00d67681711903ae01f4cc87
709,682
def format_value_with_percentage(original_value): """ Return a value in percentage format from an input argument, the original value """ percentage_value = "{0:.2%}".format(original_value) return percentage_value
78bfb753b974bc7cbe3ac96f58ee49251063d2e7
709,684
import numpy def get_Z_and_extent(topofile): """Get data from an ESRI ASCII file.""" f = open(topofile, "r") ncols = int(f.readline().split()[1]) nrows = int(f.readline().split()[1]) xllcorner = float(f.readline().split()[1]) yllcorner = float(f.readline().split()[1]) cellsize = float(f....
e96db5c2ae4a0d6c94654d7ad29598c3231ec186
709,685
import torch def train_discrim(discrim, state_features, actions, optim, demostrations, settings): """demostractions: [state_features|actions] """ criterion = torch.nn.BCELoss() for _ in range(settings.VDB_UPDATE_NUM): learner = discrim(torch.cat([state_features, actions], di...
7e6c16fc396b371e92d3a04179eacb9cae63659c
709,686
def max_tb(collection): # pragma: no cover """Returns the maximum number of TB recorded in the collection""" max_TB = 0 for doc in collection.find({}).sort([('total_TB',-1)]).limit(1): max_TB = doc['total_TB'] return max_TB
bde417de0b38de7a7b5e4e3db8c05e87fa6c55ca
709,687
import time def datetime_to_timestamp(d): """convert a datetime object to seconds since Epoch. Args: d: a naive datetime object in default timezone Return: int, timestamp in seconds """ return int(time.mktime(d.timetuple()))
356ac090b0827d49e9929a7ef26041b26c6cc690
709,688
def decomposePath(path): """ :example: >>> decomposePath(None) >>> decomposePath("") >>> decomposePath(1) >>> decomposePath("truc") ('', 'truc', '', 'truc') >>> decomposePath("truc.txt") ('', 'truc', 'txt', 'truc.txt') >>> decomposePath("/home/...
7b45cfe64f631912fc56246f404ddbea51b9f1ec
709,689
def update_coverage(coverage, path, func, line, status): """Add to coverage the coverage status of a single line""" coverage[path] = coverage.get(path, {}) coverage[path][func] = coverage[path].get(func, {}) coverage[path][func][line] = coverage[path][func].get(line, status) coverage[path][func][li...
46e5a1e5c4ebba3a9483f90ada96a0f7f94d8c1d
709,690
def cross_product(v1, v2): """Calculate the cross product of 2 vectors as (x1 * y2 - x2 * y1).""" return v1.x * v2.y - v2.x * v1.y
871d803ef687bf80facf036549b4b2062f713994
709,691
def divisors(num): """ Takes a number and returns all divisors of the number, ordered least to greatest :param num: int :return: list (int) """ # Fill in the function and change the return statment. return 0
f15169b2672847294a219207f6022ad3e49338d2
709,692
def compare_distance(tree,target): """ Checks tree edit distance. Since every node has a unique position, we know that the node is the same when the positions are the same. Hence, a simple method of counting the number of edits one needs to do to create the target tree out of a given tree is equal to the number of...
96b57e88b8e70dbb43231b56cbe7e9b7ebcfd10f
709,693
def header(name='peptide'): """ Parameters ---------- name Returns ------- """ with open('{}.pdb'.format(name), 'r') as f: file = f.read() model = file.find('\nMODEL') atom = file.find('\nATOM') if atom < 0: raise ValueError('no ATOM entries found in...
84e75e34771b7c395ee36611c8d055ca1fdf67dc
709,694
def str2bytes(seq): """ Converts an string to a list of integers """ return map(ord,str(seq))
7afe8e40cd4133c59be673b537f2717591b093cf
709,695
import os def getsize(filename): """Return the size of a file, reported by os.stat().""" return os.stat(filename).st_size
f21bd048bf1fdbc80cdcbd4f14dba8f390439f74
709,697
def drop_path(input, drop_prob=0.0, training=False, scale_by_keep=True): """ Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks). """ if drop_prob == 0.0 or not training: return input keep_prob = 1 - drop_prob shape = (input.shape[0],) + (1,) * (input....
289ae545fa184bb459275685d3a2894e5219db2e
709,698
import os def envi_header(inputpath): """ Convert a envi binary/header path to a header, handling extensions Args: inputpath: path to envi binary file Returns: str: the header file associated with the input reference. """ if os.path.splitext(inputpath)[-1] == '.img' or os.path...
45df7507017676648cd4fae955da26916bbf4738
709,700
import socket def basic_checks(server,port): """Perform basics checks on given host""" sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) # 2 seconds timeout sock.settimeout(2) return sock.connect_ex((server,int(port))) == 0
4a31521089feb2c178bb5202fa818804dfe87142
709,703
def ordToString(ordList): """Use this function to convert ord values to strings.""" newStrList = [] cstr = "" for cint in ordList: cstr += chr(cint) if cint == 44: newStrList.append(cstr[:-1]) cstr = "" return newStrList
5a836f7fe34803744de90aa2608e3d99a081c7ff
709,704
import re def _xfsdump_output(data): """ Parse CLI output of the xfsdump utility. """ out = {} summary = [] summary_block = False for line in [l.strip() for l in data.split("\n") if l.strip()]: line = re.sub("^xfsdump: ", "", line) if line.startswith("session id:"): ...
dbc7fbf9dced99b83a7dc5917c473a1dee16d749
709,705
def csstext(text: str, cls: str, span: bool=False, header: bool=False) -> str: """ Custom build HTML text element. """ if span: tag = 'span' elif header: tag = 'h1' else: tag = 'p' return f'<{tag} class="{cls}">{str(text)}</{tag}>'
0833fd9d83143e09b5c234e193a8e53ef653112b
709,706
def trans_exam_list_to_colum(example_list, headers=None): """ 将example列表转换成以列表示的形式,用于适配输出附加信息 :param example_list: example 列表 :param headers: 需要的属性,默认为("question", "answer", "yes_or_no") :return: {header1:[...],header2:[...],...} """ if headers is None: headers = ("question", "answer...
ff5a2e5f6e27ce0a32717e55ba35dbd864a11dbb
709,707
def parseParams(opt): """Parse a set of name=value parameters in the input value. Return list of (name,value) pairs. Raise ValueError if a parameter is badly formatted. """ params = [] for nameval in opt: try: name, val = nameval.split("=") except ValueError: ...
b932f74c8e5502ebdd7a8749c2de4b30921d518b
709,708
def _get_name(dist): """Attempts to get a distribution's short name, excluding the name scope.""" return getattr(dist, 'parameters', {}).get('name', dist.name)
fd57e523c1a84a36f9ed56236e4b8db1e887575c
709,709
def GenerateConfig(context): """Generates configuration.""" key_ring = { 'name': 'keyRing', 'type': 'gcp-types/cloudkms-v1:projects.locations.keyRings', 'properties': { 'parent': 'projects/' + context.env['project'] + '/locations/' + context.properties['region'], 'keyRingId': context.env['d...
257b7217c1a08bba46866aff0b7faa1a03fe7fdc
709,710
def _remove_none_from_post_data_additional_rules_list(json): """ removes hidden field value from json field "additional_rules" list, which is there to ensure field exists for editing purposes :param json: this is data that is going to be posted """ data = json additional_rules = json.get...
c82aa568f82ba4abcb8f4e6f9c770969277d078f
709,711
def NO_MERGE(writer, segments): """This policy does not merge any existing segments. """ return segments
0742365f30d59cb219ac60483b867180bd910ba8
709,712
import os def package_files(directory): """package_files recursive method which will lets you set the package_data parameter in the setup call. """ paths = [] for (path, _, filenames) in os.walk(directory): for filename in filenames: paths.append(os.path.join('..', path, f...
e043de9a9e8ed9092f933df00b167b092ba6abaa
709,713
def transplant(root, u, v): """ 注意, 这里要返回root, 不然修改不了 """ if u.parent == None: root = v elif u.parent.left == u: u.parent.left = v else: u.parent.right = v if v: v.parent = u.parent return root
cadf0433399e428596d1d0d4ab200e4d79285d21
709,714
import subprocess def pr_branches() -> list[str]: """List of branches that start with 'pr-'""" out = subprocess.run( [ "git", "for-each-ref", "--shell", '--format="%(refname:strip=3)"', "refs/remotes/origin/pr-*", ], capture_o...
f144d2546ef59cb392f4ad1226c2246384bdfd99
709,715
from typing import Union def parse_boolean(val: str) -> Union[str, bool]: """Try to parse a string into boolean. The string is returned as-is if it does not look like a boolean value. """ val = val.lower() if val in ('y', 'yes', 't', 'true', 'on', '1'): return True if val in ('n', 'no...
e2cbda5a849e1166e0f2a3953220c93d1f3ba119
709,716
def supports_color(stream) -> bool: # type: ignore """Determine whether an output stream (e.g. stdout/stderr) supports displaying colored text. A stream that is redirected to a file does not support color. """ return stream.isatty() and hasattr(stream, "isatty")
4a427d6725206ef33b3f4da0ace6f2d6c3db78a9
709,717
import os def get_current_version_name(): """Returns the version of the current instance. If this is version "v1" of module "module5" for app "my-app", this function will return "v1". """ return os.environ['CURRENT_VERSION_ID'].split('.')[0]
cbd7fdbb9af4990e32130f2aa3af0cfe8bf59816
709,718
import re def safe_htcondor_attribute(attribute: str) -> str: """Convert input attribute name into a valid HTCondor attribute name HTCondor ClassAd attribute names consist only of alphanumeric characters or underscores. It is not clearly documented, but the alphanumeric characters are probably restr...
7a4dda539b2379120e68737d72a80226c45f5602
709,720
def make_csv(headers, data): """ Creates a CSV given a set of headers and a list of database query results :param headers: A list containg the first row of the CSV :param data: The list of query results from the Database :returns: A str containing a csv of the query results """ # Create a list where each entr...
5101d53de8dd09d8ebe743d77d71bff9aeb26334
709,721
from typing import Tuple def extract_value_from_config( config: dict, keys: Tuple[str, ...], ): """ Traverse a config dictionary to get some hyper-parameter's value. Parameters ---------- config A config dictionary. keys The possible names of a hyper-parameter....
d545d4c9298c74776ec52fb6b2c8d54d0e653489
709,722
import numpy def boundaryStats(a): """ Returns the minimum and maximum values of a only on the boundaries of the array. """ amin = numpy.amin(a[0,:]) amin = min(amin, numpy.amin(a[1:,-1])) amin = min(amin, numpy.amin(a[-1,:-1])) amin = min(amin, numpy.amin(a[1:-1,0])) amax = numpy.amax(a[0,:]) amax ...
6c007c6cf2c7c5774ca74365be8f63094864d962
709,723
def vision_matched_template_get_pose(template_match): """ Get the pose of a previously detected template match. Use list operations to get specific entries, otherwise returns value of first entry. Parameters: template_match (List[MatchedTemplate3D] or MatchedTemplate3D): The template match(s) ...
b854da7a085934f4f3aba510e76852fb8c0a440a
709,724
def no_zero(t): """ This function replaces all zeros in a tensor with ones. This allows us to take the logarithm and then sum over all values in the matrix. Args: t: tensor to be replaced returns: t: tensor with ones instead of zeros. """ t[t==0] = 1. return t
8119d1859dc8b248f5bb09b7cc0fc3b492d9b7bd
709,726
def get_vocabulary(query_tree): """Extracts the normalized search terms from the leaf nodes of a parsed query to construct the vocabulary for the text vectorization. Arguments --------- query_tree: pythonds.trees.BinaryTree The binary tree object representing a parsed search query. Each lea...
bd03f4894cd3f9a7964196bfb163335f84a048d7
709,728
def find_point_in_section_list(point, section_list): """Returns the start of the section the given point belongs to. The given list is assumed to contain start points of consecutive sections, except for the final point, assumed to be the end point of the last section. For example, the list [5, 8, 30, 3...
47d5cda15b140ba8505ee658fd46ab090b2fda8a
709,729
import os import types def generate_module(file_allocator, name): """ Generate an in-memory module from a generated Python implementation. """ assert name in file_allocator.allocated_files f = file_allocator.allocated_files[name] f.seek(0) data = f.read() modname, _ = os.path.splitex...
beab4cdf12fcdfeacef9f8a8607e995b771d6012
709,730
def choose(population, sample): """ Returns ``population`` choose ``sample``, given by: n! / k!(n-k)!, where n == ``population`` and k == ``sample``. """ if sample > population: return 0 s = max(sample, population - sample) assert s <= population assert population > -1 i...
659eac683cae737888df74c0db21aa3ece746b33
709,731
def eea(m, n): """ Compute numbers a, b such that a*m + b*n = gcd(m, n) using the Extended Euclidean algorithm. """ p, q, r, s = 1, 0, 0, 1 while n != 0: k = m // n m, n, p, q, r, s = n, m - k*n, q, p - k*q, s, r - k*s return (p, r)
56e1c59ac3a51e26d416fe5c65cf6612dbe56b8c
709,733
import csv def parse_kinetics_splits(level): """Parse Kinetics-400 dataset into "train", "val", "test" splits. Args: level (int): Directory level of data. 1 for the single-level directory, 2 for the two-level directory. Returns: list: "train", "val", "test" splits of Kinetics...
ee2521919f9f9c3f499cd28bc6003528eb402d2b
709,736
import uuid def ticket() -> str: """生成请求饿百接口所需的ticket参数""" return str(uuid.uuid1()).upper()
aaf1135d6ef5e61aa65960c5c38007848cbd0b17
709,737
def get_clients( wlc, *vargs, **kvargs ): """ create a single dictionary containing information about all associated stations. """ rsp = wlc.rpc.get_stat_user_session_status() ret_data = {} for session in rsp.findall('.//USER-SESSION-STATUS'): locs...
c4ab5941033632d7f2b95bc23878f0464d12adb7
709,738
def maximum_value(tab): """ brief: return maximum value of the list args: tab: a list of numeric value expects at leas one positive value return: the max value of the list the index of the max value raises: ValueError if expected a list as input ValueError if no positive value found """ if not(isinstan...
1c31daf3a953a9d781bc48378ef53323313dc22a
709,739
import math def dsh( incidence1: float, solar_az1: float, incidence2: float, solar_az2: float ): """Returns the Shadow-Tip Distance (dsh) as detailed in Becker et al.(2015). The input angles are assumed to be in radians. This is defined as the distance between the tips of the shadows in the ...
5aef1c9d7ffeb3e8534568a53cf537d26d97324a
709,740
def instantiate(class_name, *args, **kwargs): """Helper to dynamically instantiate a class from a name.""" split_name = class_name.split(".") module_name = split_name[0] class_name = ".".join(split_name[1:]) module = __import__(module_name) class_ = getattr(module, class_name) return class_...
d5906c835de9c2e86fbe3c15a9236662d6c7815d
709,741
import six def _stringcoll(coll): """ Predicate function to determine whether COLL is a non-empty collection (list/tuple) containing only strings. Arguments: - `coll`:* Return: bool Exceptions: None """ if isinstance(coll, (list, tuple)) and coll: return len([s for s in c...
9490a973900e230f70fea112f250cfe29be3a8bc
709,742
def __check_complete_list(list_, nb_max, def_value): """ make sure the list is long enough complete with default value if not :param list_: list to check :param nb_max: maximum length of the list :param def_value: if list too small, completes it with this value :return: boolean,...
9d439cd3eeea04e7a3e0e59aa4fe0bbb875bdfe4
709,743
def verify_parentheses(parentheses_string: str) -> bool: """Takes input string of only '{},[],()' and evaluates to True if valid.""" open_parentheses = [] valid_parentheses_set = {'(', ')', '[', ']', '{', '}'} parentheses_pairs = { ')' : '(', ']' : '[', '}' : '{' } if le...
2e2c07314d474b582f12af8cf53a311c0fa323c1
709,745
import re def compute_dict(file_path): """Computes the dict for a file whose path is file_path""" file_dict = {} with open(file_path, encoding = 'utf8') as fin: for line in fin: line = line.strip() txt = re.sub('([^a-zA-Z0-9\s]+)',' \\1 ',line) txt = re.sub('([\...
821e29181aad781279b27174be0fd7458b60481f
709,747
def isMatch(s, p): """ Perform regular simple expression matching Given an input string s and a pattern p, run regular expression matching with support for '.' and '*'. Parameters ---------- s : str The string to match. p : str The pattern to match. Returns -------...
92cd3171afeb73c6a58bbcd3d3ea6d707401cb09
709,748
from typing import Optional def convert_postgres_array_as_string_to_list(array_as_string: str) -> Optional[list]: """ Postgres arrays are stored in CSVs as strings. Elasticsearch is able to handle lists of items, but needs to be passed a list instead of a string. In the case of an empty array, ret...
cc64fe8e0cc765624f80abc3900985a443f76792
709,749
def add_prefix(key): """Dummy key_function for testing index code.""" return "id_" + key
96dda0bd57b4eb89f17c8bb69ad48e3e1675a470
709,750
def binaryToString(binary): """ 从二进制字符串转为 UTF-8 字符串 """ index = 0 string = [] rec = lambda x, i: x[2:8] + (rec(x[8:], i - 1) if i > 1 else '') if x else '' fun = lambda x, i: x[i + 1:8] + rec(x[8:], i - 1) while index + 1 < len(binary): chartype = binary[index:].index('0') # 存放字...
2044109d573abe7c9428b64b289b5aa82ec4d624
709,751
import functools import logging def disable_log_warning(fun): """Temporarily set FTP server's logging level to ERROR.""" @functools.wraps(fun) def wrapper(self, *args, **kwargs): logger = logging.getLogger('pyftpdlib') level = logger.getEffectiveLevel() logger.setLevel(logging.ERRO...
6990a2a1a60ea5a24e4d3ac5c5e7fbf443825e48
709,752
import json import operator def my_subs_helper(s): """Helper function to handle badly formed JSON stored in the database""" try: return {'time_created':s.time_created, 'json_obj':sorted(json.loads(s.json_data).iteritems(), key=operator.itemgetter(0)), 'plain_json_obj':json.dumps(json.loads(s.json_data...
4b649d865c3a99f89111baa694df4902e65243e6
709,753
def add_to_codetree(tword,codetree,freq=1): """ Adds one tuple-word to tree structure - one node per symbol word end in the tree characterized by node[0]>0 """ unique=0 for pos in range(len(tword)): s = tword[pos] if s not in codetree: codetree[s] = [0,{}] ...
e92a48f112e7a774bed3b125509f7f64dce0a7ec
709,754
def remove_from_dict(obj, keys=list(), keep_keys=True): """ Prune a class or dictionary of all but keys (keep_keys=True). Prune a class or dictionary of specified keys.(keep_keys=False). """ if type(obj) == dict: items = list(obj.items()) elif isinstance(obj, dict): items = list(...
b1d9a2bd17269e079ce136cc464060fc47fe5906
709,755
def stringToTupleOfFloats(s): """ Converts s to a tuple @param s: string @return: tuple represented by s """ ans = [] for i in s.strip("()").split(","): if i.strip() != "": if i == "null": ans.append(None) else: ans.append(float...
7eec23232f884035b12c6498f1e68616e4580878
709,756
import sys def factorial(x): """factorial(x) -> Integral "Find x!. Raise a ValueError if x is negative or non-integral.""" if isinstance(x, float): fl = int(x) if fl != x: raise ValueError("float arguments must be integral") x = fl if x > sys.maxsize: raise...
664cc8e0e215f089bbc57fec68553d788305e4c0
709,757
import json def read_json(file_name): """Read json from file.""" with open(file_name) as f: return json.load(f)
2eccab7dddb1c1038de737879c465f293a00e5de
709,758
def _decode_end(_fp): """Decode the end tag, which has no data in the file, returning 0. :type _fp: A binary `file object` :rtype: int """ return 0
5e8da3585dda0b9c3c7cd428b7e1606e585e15c6
709,759
def get_camelcase_name_chunks(name): """ Given a name, get its parts. E.g: maxCount -> ["max", "count"] """ out = [] out_str = "" for c in name: if c.isupper(): if out_str: out.append(out_str) out_str = c.lower() else: out_s...
134a8b1d98af35f185b37c999fbf499d18bf76c5
709,760
def orb_scf_input(sdmc): """ find the scf inputs used to generate sdmc """ myinputs = None # this is the goal sdep = 'dependencies' # string representation of the dependencies entry # step 1: find the p2q simulation id p2q_id = None for key in sdmc[sdep].keys(): if sdmc[sdep][key].result_names[0] == 'o...
c319693e9673edf540615025baf5b5199c5e27a3
709,762
def is_success(code): """ Returns the expected response codes for HTTP GET requests :param code: HTTP response codes :type code: int """ if (200 <= code < 300) or code in [404, 500]: return True return False
fa502b4989d80edc6e1c6c717b6fe1347f99990d
709,763
import json def get_node_to_srn_mapping(match_config_filename): """ Returns the node-to-srn map from match_conf.json """ with open(match_config_filename) as config_file: config_json = json.loads(config_file.read()) if "node_to_srn_mapping" in config_json: return config_j...
37bf2f266f4e5163cc4d6e9290a8eaf17e220cd3
709,765
def nest_dictionary(flat_dict, separator): """ Nests a given flat dictionary. Nested keys are created by splitting given keys around the `separator`. """ nested_dict = {} for key, val in flat_dict.items(): split_key = key.split(separator) act_dict = nested_dict final_key = ...
f5b8649d916055fa5911fd1f80a8532e5dbee274
709,766
def list_a_minus_b(list1, list2): """Given two lists, A and B, returns A-B.""" return filter(lambda x: x not in list2, list1)
8fbac6452077ef7cf73e0625303822a35d0869c3
709,767
def gt_dosage(gt): """Convert unphased genotype to dosage""" x = gt.split(b'/') return int(x[0])+int(x[1])
819fc9beb834f57e44bcb0ac3e1d3c664c7efd42
709,768
import csv import re import sys def read_mapping_file(map_file): """ Mappings are simply a CSV file with three columns. The first is a string to be matched against an entry description. The second is the payee against which such entries should be posted. The third is the account against which such...
e72ceb08daac0a12a426062f95cfa06776cfdedd
709,769
import os def GetEnvironFallback(var_list, default): """Look up a key in the environment, with fallback to secondary keys and finally falling back to a default value.""" for var in var_list: if var in os.environ: return os.environ[var] return default
1b9cad3c46264c089f250ccb19119cff8cacd0d1
709,770
def task_migrate(): """Create django databases""" return { 'actions': ['''cd CCwebsite && python3 manage.py migrate'''] }
d0d146c2e628abbe33714ae0ff6a546aab9842cc
709,771
import os def print_header(args, argv, preamble='CIFAR10', printfn=print, log=open(os.devnull, 'w'), first=('model','dataset','epoch','batchsize','resume','out')): """ Prints the arguments and header, and returns a logging print function """ def logprint(*args, file...
c1213f441696dbabedafe9888a681cf64bab4249
709,772
def tempo_para_percorrer_uma_distancia(distancia, velocidade): """ Recebe uma distância e a velocidade de movimentação, e retorna as horas que seriam gastas para percorrer em linha reta""" horas = distancia / velocidade return round(horas,2)
e7754e87e010988284a6f89497bb1c5582ea0e85
709,773
def find_last_index(l, x): """Returns the last index of element x within the list l""" for idx in reversed(range(len(l))): if l[idx] == x: return idx raise ValueError("'{}' is not in list".format(x))
f787b26dd6c06507380bf2e336a58887d1f1f7ea
709,774
def _CheckUploadStatus(status_code): """Validates that HTTP status for upload is 2xx.""" return status_code / 100 == 2
d799797af012e46945cf413ff54d2ee946d364ba
709,776
def identifyEntity(tweet, entities): """ Identify the target entity of the tweet from the list of entities :param tweet: :param entities: :return: """ best_score = 0 # best score over all entities targetEntity = "" # the entity corresponding to the best score for word in tweet: ...
d6825dfddf01706ee266e0f1c82128a42bcb8554
709,777
def _apply_D_loss(scores_fake, scores_real, loss_func): """Compute Discriminator losses and normalize loss values Arguments --------- scores_fake : list discriminator scores of generated waveforms scores_real : list discriminator scores of groundtruth waveforms loss_func : objec...
9432962af57193c07a268d00a3f1f01d372cb6a0
709,778
import random def pick_op(r, maxr, w, maxw): """Choose a read or a write operation""" if r == maxr or random.random() >= float(w) / maxw: return "write" else: return "read"
a45f53bf12538412b46f78e2c076966c26cf61ac
709,779
import os def isvalid(save_path, file): """ Returns true if the file described by the parameters is a file with the appropriate file extension. """ return os.path.isfile(os.path.join(save_path, file)) and \ str(file).endswith('.meta')
55f76212eaaae3be6706a01f3f28d24005d28f75
709,781
def min_index(array, i, j): """Pomocna funkce pro razeni vyberem. Vrati index nejmensiho prvku v poli 'array' mezi 'i' a 'j'-1. """ index = i for k in range(i, j): if array[k] < array[index]: index = k return index
4c59362fac2e918ba5a0dfe9f6f1670b3e95d68c
709,782
def average_precision(gt, pred): """ Computes the average precision. This function computes the average prescision at k between two lists of items. Parameters ---------- gt: set A set of ground-truth elements (order doesn't matter) pred: list A list of predicted elements (order does mat...
ca265471d073b6a0c7543e24ef0ba4f872737997
709,784
import math def rotate_coo(x, y, phi): """Rotate the coordinates in the *.coo files for data sets containing images at different PAs. """ # Rotate around center of image, and keep origin at center xin = 512. yin = 512. xout = 512. yout = 512. cos = math.cos(math.radians(phi)) ...
a57a4c36119e96d757bd23f28a0790f6d68661fc
709,785
def ip_block_array(): """ Return an ipBlock array instance fixture """ return ['10.0.0.1', '10.0.0.2', '10.0.0.3']
c74756f34b97d2550cb238bd63e0c9505f3935d3
709,786
import os def _find_modules_and_directories(top_level_directory): """ Recursive helper function to find all python files included in top level package. This will recurse down the directory paths of any package to find all modules and subpackages in order to create an exhaustive list of all python ...
2aecb5974f83ce01b2a8e4a6fb8313399756c1d4
709,787
import math import torch def log_density_gaussian(x, mu, logvar): """Calculates log density of a gaussian. Parameters ---------- mu: torch.Tensor or np.ndarray or float Mean. logvar: torch.Tensor or np.ndarray or float Log variance. """ normalization = - 0.5 * (math.log(2...
3fdc751aa58b3ec82e1aa454f593879d5da4c310
709,788
def split_page(array, limit, index): """ 按限制要求分割数组,返回下标所指向的页面 :param array: 需要分割的数组 :param limit: 每个数组的大小 :param index: 需要返回的分割后的数组 :return: 数组 """ end = index * limit start = end - limit return array[start:end]
ecce83d6e2e09d47e124536f294ece1e1631e6b6
709,789
def Flatten(matrix): """Flattens a 2d array 'matrix' to an array.""" array = [] for a in matrix: array += a return array
00389b4dd295274d8081331d6ae78f233f0b5b59
709,790
def get_ws_param(args, attr): """get the corresponding warm start parameter, if it is not exists, use the value of the general parameter""" assert hasattr(args, attr), 'Invalid warm start parameter!' val = getattr(args, attr) if hasattr(args, 'ws_' + attr): ws_val = getattr(args, 'ws_' + attr) ...
ea1d762654153602f8ad54048e54995c26304e40
709,791
def escape_name(name): """Escape sensor and request names to be valid Python identifiers.""" return name.replace('.', '_').replace('-', '_')
856b8fe709e216e027f5ab085dcab91604c93c2e
709,792
def multiset_counter(mset): """ Return the sum of occurences of elements present in a token ids multiset, aka. the multiset cardinality. """ return sum(mset.values())
36885abd5bf666aa6c77a262a647c227e46d2e88
709,793
def lengthenFEN(fen): """Lengthen FEN to 71-character form (ex. '3p2Q' becomes '111p11Q')""" return fen.replace('8','11111111').replace('7','1111111') \ .replace('6','111111').replace('5','11111') \ .replace('4','1111').replace('3','111').replace('2','11')
f49cdf8ad6919fbaaad1abc83e24b1a33a3ed3f8
709,794
import os import pickle def load_flags(save_dir, save_file="flags.obj"): """ This function inflate the pickled object to flags object for reuse, typically during evaluation (after training) :param save_dir: The place where the obj is located :param save_file: The file name of the file, usually flags.o...
44cc70f185645799fdfd81c8806f3d3f8585fef4
709,795
def pancakeSort(self, A): # ! 这个方法实际上是在每轮循环中寻找最大的那个数,使其在正确的位置 """ :type A: List[int] :rtype: List[int] """ bucket = sorted(A) ans = [] for k in range(len(A),0,-1): i = A.index(bucket.pop())+1 ans += [i, k] A = A[i:k][::-1] + A[:i] + A[k:] print(A) ret...
35d358c6631f5cc708232f67a3e55d685116dff8
709,797
def includeme(config): """ Get build Git repository directory and make it accessible to all requests generated via Cornice """ # Make DB connection accessible as a request property def _get_repos(request): _settings = request.registry.settings repo_dir = _settings['repo_basedir'...
f2d73eb01b616f79059f4001c7b3faad67f48cd2
709,798