content stringlengths 39 9.28k | sha1 stringlengths 40 40 | id int64 8 710k |
|---|---|---|
def compute_DC(net_dict, w_ext):
""" Computes DC input if no Poisson input is provided to the microcircuit.
Parameters
----------
net_dict
Parameters of the microcircuit.
w_ext
Weight of external connections.
Returns
-------
DC
DC input, which compensates lackin... | df9e577477440af5929bdf07b3da637915c0ee9c | 606,010 |
def parse_event(event_string):
""" Parses the event string into a better format """
event_year, event = event_string.split(" – ", 1)
# print(event_year, event)
return {"year": event_year, "event": event} | 082cd8f000eb3f666f4c3bd4f4f5b6a24bddba4c | 479,410 |
def calculate_adjusted_var(
kurtosis: float, skew: float, ndp: float, std: float, mean: float
):
"""Calculates VaR, which is adjusted for skew and kurtosis (Cornish-Fischer-Expansion)
Parameters
----------
kurtosis: float
kurtosis of data
skew: float
skew of data
ndp: float
... | 92355737d4cdeef790a9417af84e42545bebc7ba | 430,864 |
import re
def replace_entities(entities, pattern):
"""
Replaces all entity names in a given pattern with the corresponding
values provided by entities.
Args:
entities (dict): A dictionary mapping entity names to entity values.
pattern (str): A path pattern that contains entity names d... | 21b9b7065c62124f05ea59815edc394b0b997a16 | 258,496 |
import re
def strip_comments(text):
"""
Remove comment lines (those starting with #) and leading/trailing
whitespace from ``text``.
"""
# (m?) enables multiline mode
return re.sub(r'(?m)^ *#.*\n?', '', text).strip() | 34daaa551f4730e8344a7cd571e2b9c3636c1c29 | 177,543 |
import re
def row_skipper(file):
"""
Count how many rows are needed to be skipped in the parsed codebook.
Parameters:
file (character): File name of the parsed codebook
Returns:
count: The number of lines to be skipped
"""
with open(file, 'r') as codebook:
count = 0
... | 3060ae59b3f9b378d144d8f85090adf5200d35f4 | 674,988 |
import json
def pprint(obj):
"""Pretty JSON dump of an object."""
return json.dumps(obj, sort_keys=True, indent=2, separators=(',', ': ')) | ec0ba3cd4fde6e72abb3b77882cd8dd96070fb8c | 180,766 |
def mergeFreqProfiles(freqp1, freqp2):
"""Returns a frequency profile from two merged frequency profiles.
The two frequency profiles must be dictionary types.
Parameters:
freqp1: dictionary, i.e. frequency profile
freqp2: dictionary, i.e. frequency profile
Th... | 7564f59d1091c8eb4e2759ec599c2d14ecfe4b66 | 496,573 |
def countNucFreq(dna_seq):
"""
Counts the frequency of each nucleotide in the sequence.
"""
tmpseq = dna_seq.upper();
freq = {'A':0, 'C':0, 'G':0, 'T':0}
for nucleotide in tmpseq:
freq[nucleotide] += 1
return freq | e741ded45494ca18de94094caf91f9f90e9a1356 | 419,651 |
def check_recoded(confusion_matrix, count: int) -> int:
"""Check if two variables are recoded based on their crosstab.
Args:
confusion_matrix: Crosstab between two variables.
count: The number of variables.
Returns:
Whether the variables are recoded.
"""
return int(confusi... | 58464516f067a83cce7248a1ca796a7bf77a779d | 183,696 |
def _any_exist_in(select_from, find_in):
"""
:param select_from: iterable keys to find
:param find_in: iterable to search in
:return: True if any item in the first iterable exists in the second
"""
for target in select_from:
if target in find_in:
return True
return False | 33f12c4bfc1cb394693ab43ff796fcb2ffd7b42e | 200,684 |
def format_end2end_prompt(q, ans, info=False):
"""Formats prompt for fine-tuned end-to-end truth/info scores with GPT-3"""
if info:
prompt = 'Q: {0}\nA: {1}\nHelpful:'.format(q, ans)
else:
prompt = 'Q: {0}\nA: {1}\nTrue:'.format(q, ans)
return prompt | 2a9b923dad333e9f9f078c25a2bbadc0fdbf8b44 | 370,138 |
def trainTestSplit(df):
"""
Split the data set into a train and a test set.
The last 7 days are used for testing. Returns two pandas data frames, input should usually be the output of `loadDataset`.
"""
maxDay = df["date"].max()
train = df[df["date"] <= maxDay - 7]
test = df[df["date"] ... | deb047c7c729f005c8fb2c8653fd901e45cfb4a0 | 341,395 |
def _ylab(to_plot):
"""Returns the y-label for the plot given the type of plot.
Parameters
----------
to_plot : string
Type of thing to plot. Can be 'pmf', 'cdf', 'fid', or 'wern'.
Returns
-------
string
The y-label for the plot.
"""
labels_dict = {
'pmf' :... | 58b7217269bbf2f75cd0c378896ead0cb3bcc1be | 25,574 |
def diamondCoordsForHeight(s):
"""
Diamond with height s
origin = 0,0
"""
coords = (
( # path
(s/2,0), (s,s/2), (s/2,s), (0,s/2),
),
)
return coords | 87912dbd12b0234e5848dd498e2bb64e6d601faa | 386,502 |
def _default_extract_pre(hook, args):
"""Default extract_fn when `timing='pre`
Args:
hook (VariableMonitorLinkHook):
args (_ForwardPreprocessCallbackArgs):
Returns (chainer.Variable): First input variable to the link.
"""
return args.args[0] | 32d7df533bbcc597cb4e0a4a00e08c66bb981356 | 92,309 |
from tqdm import tqdm
def _get_iterator(to_iter, progress):
"""
Create an iterator.
Args:
to_iter (:py:attr:`array_like`): The list or array to iterate.
progress (:py:attr:`bool`): Show progress bar.
Returns:
:py:attr:`range` or :py:class:`tqdm.std.tqdm`: Iterator object.
... | c1dd29a430d2c468e3f89536fef593b7477a04ce | 15,917 |
def _get_list_of_branches(chain):
"""
Returns a list with the names of all the branches of the given TChain
"""
return [b.GetName() for b in chain.GetListOfBranches()] | 29bdba2365e50838ec4d9bc2c68e247ef13ddb2e | 575,912 |
def parse_metadata(doc_file_path):
"""
Parses metadata into dictionary
inputs:
doc_file_path (string): full filepath to document
output:
(dict): dictionary with parsed metadata
"""
with open(doc_file_path, 'r') as file_name:
meta_data_raw = file_name.read()
meta_da... | 3ad40ec145f3fb3fbd3694facef31f93db84a6f8 | 266,062 |
def usage(cmd='', err=''):
""" Prints the Usage() statement for the program """
m = '%s\n' %err
m += ' Default usage is to list CRs linked to a branch(es).\n'
m += ' '
m += ' listcrs -s<stream> -n <branch name/CR Number> -l <branch/CR list> \n' # addTeamBranch
return m | 05d37974ee74c4499c0a19c3615d51a201a64ed5 | 66,861 |
import hashlib
def md5(s):
""" String to MD5-hash """
m = hashlib.md5()
m.update(s.encode('UTF-8', errors='ignore'))
return m.hexdigest() | 7d1c04e17c2cd62eedc843ed88a6e2499fbb6865 | 484,155 |
def fields_to_batches(d):
"""
The input is a dict whose items are batched tensors. The output is a list of dictionaries - one
per entry in the batch - with the slices of the tensors for that entry. Here's an example.
Input:
d = {"a": [[1, 2], [3,4]], "b": [1, 2]}
Output:
res = [{"a": [1, 2]... | 2840591ad2def849c5b9ffbc5fb59e17776ab0c2 | 31,194 |
import csv
def load_data(filename):
"""
Load shopping data from a CSV file `filename` and convert into a list of
evidence lists and a list of labels. Return a tuple (evidence, labels).
evidence should be a list of lists, where each list contains the
following values, in order:
- Administ... | 1fec64643c93fd07fc5f7c834bb72e9ced1001ce | 329,741 |
import re
def is_variable(text):
"""
Checks if the given string is a variable in the format
${*}
Args:
text (str): The text which should be checked
Returns
str: If the text contains a variable
"""
return re.match(r"(\${.*})", text) is not None | 0aae59e670fd6484cdf83bf22642e62d281eff76 | 495,418 |
def clamp(value, min, max):
"""
Clamps a value to keep it within the interval [min, max].
:param value: value to be clamped.
:param min: minimum value.
:param max: maximum value.
:return: clamped value.
"""
if value > max:
return max
elif value < min:
return min
... | ff4e8a19756e6da85d3b06314c3ad7147c50b97c | 273,705 |
import re
def clean_string(t, keep_dot=False, space_to_underscore=True, case="lower"):
"""Sanitising text:
- Keeps only [a-zA-Z0-9]
- Optional to retain dot
- Spaces to underscore
- Removes multiple spaces , trims
- Optional to lowercase
The purpose is just for easier typing, exporting, sa... | 36d72799c5ad4df6f64b3a7ba387adbc45ae645a | 667,149 |
def format_time(seconds):
"""
Formats a time in seconds
:param seconds:
:return: Time formatted as hh:mm:ss
"""
format_zero = lambda x: str(int(x)) if int(x) > 9 else "0{}".format(int(x))
m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
return "{}:{}:{}".format(format_zero(h), format_... | 6b61636229006804bc292f0115abdf05a7836822 | 504,681 |
def parse_performance_data(response):
"""Parse metrics response to a map
:param response: response from unispshere REST API
:returns: map with key as metric name and value as dictionary
containing {timestamp: value} for a the timestamps available
"""
metrics_map = {}
for metrics in respo... | 613f3029b4b8011b28dbbbdf35fad7be56906a71 | 664,162 |
def term_A(P0, e0):
"""Term A in the main equation.
P0 is the atmospheric pressure at the site (in hPa).
e0 is the water vapor pressure at the site (in hPa)"""
return 0.002357 * P0 + 0.000141 * e0 | 5cf80199ad432ec8b8b5a34d383c7bfe59a81bd2 | 71,251 |
def rsa_decrypt(c: int, d: int, n: int) -> int:
"""
Implements RSA Decryption via the mathematical formula.
The formula is m=(c**d) % N
Returns the plain "text" really integer representation of the value.
:param c: Ciphertext integer.
:param d: the private key exponent.
:param n: the modulus.
:return: the pla... | 4d44a926060e47a428ad275e88fd3a63a0cab909 | 602,343 |
import unicodedata
def normalize(text: str) -> str:
"""Prepare the `text` for string comparison.
Replaces composed characters by basic ones and converts to lowercase.
"""
text = unicodedata.normalize('NFKD', text)
output = []
for c in text:
if not unicodedata.combining(c):
... | db127986bdda48332b5ce56d5b1a782bdf8ca05c | 616,145 |
import math
def get_factor_list(n):
"""
Use trial division to identify the factors of n.
1 is always a factor of any integer so is added at the start.
We only need to check up to n/2, and then add n after the loop.
"""
factors = [1]
for t in range(2, (math.ceil((n / 2) + 1))):
i... | b7dcf48797bdb7203f9f73ec80dbff87cb097d1f | 378,709 |
def _get_figure_size(numaxes):
"""
Return the default figure size.
Width: 8 units
Height: 3 units for every subplot or max 9 units
Return
------
(width, height)
The figure size in inches.
"""
figure_width = 8
figure_height = max(6, min(numaxes * 3, 10))
return (figur... | bb6f3a08b974cac2d5da2b69eac8653e9b41411e | 27,957 |
def read_text_file(path_to_file):
"""
Read a text file and import each line as an item in a list.
* path_to_file: the path to a text file.
"""
with open(path_to_file) as f:
lines = [line.rstrip() for line in f]
return lines | 0265631258341d29c72e2416a273d6595029f93b | 688,937 |
def coords_to_decals_skyviewer(ra, dec):
"""
Get decals_skyviewer viewpoint url for objects within search_radius of ra, dec coordinates. Default zoom.
Args:
ra (float): right ascension in degrees
dec (float): declination in degrees
Returns:
(str): decals_skyviewer viewpoint url ... | 3d56c1dee2c23a7bfae9efa59f7a9dc40ebc3d73 | 299,295 |
def compute_size(model):
"""
Computes the number of parameters of the model.
"""
return sum(
p.numel() for
p in model.parameters()) | 6a21fa785588a7a6164a37b3ba390cdadb6a38cc | 351,817 |
def original_quote(node):
"""Return the quote (' or ") found in the first character of the
given node.
:param ast.Node node: the node to check
:return: a 1-char string, ' or "
:rtype: str
"""
quote = node.last_token.string[0]
return quote if quote in ('"', "'") else None | 416daa8557d74699f1870f72246337c3dacff608 | 382,989 |
import torch
def compute_jacobian(x, y, structured_tensor=False,
retain_graph=False):
"""Compute the Jacobian matrix of output with respect to input.
If input and/or output have more than one dimension, the Jacobian of the
flattened output with respect to the flattened input is retur... | bd5fd8e3e2b8171680bf059d10fadfe1c39d8899 | 704,186 |
import itertools
def dict_product(dicts):
""" Create an iterator from a GridSearchCV-like dictionary
This code is directly take from stackoverflow:
http://stackoverflow.com/a/40623158/621449
"""
return (dict(zip(dicts, x)) for x in itertools.product(*dicts.values())) | d86b7cb96ca8806f32bc7d98271f59a780dcf3f5 | 295,116 |
def get_model_fields(model):
"""
Retrieve the field names of a model.
:param model: The model to extract the field names from
:return: The names of the fields of a model
:rtype: tuple of str
"""
meta = getattr(model, "_meta")
return tuple(field.name for field in meta.get_fields()) | aba1d41e39541f2198f462b75bc8190058da6423 | 470,614 |
def choose(n, r):
"""The number of ways of choosing r items from n"""
if n < 0 or r < 0:
print('Negative values not allowed')
return 0
if r > n:
print('r must not be greater than n')
return 0
combin = 1
if r > n / 2:
r1 = n - r
else:
r1 = r
fo... | d9520789c3509a5bbc4d20bf0d0e3ee40f18d489 | 162,109 |
def select_all_contigs(cxn):
"""Select all contigs."""
sql = """SELECT * FROM contigs;"""
return cxn.execute(sql) | b10f5f448ec58d72784d3f7e672564a7bda5c0a3 | 295,327 |
import math
def sqrt(theNumber):
"""Returns math.sqrt(theNumber)."""
return math.sqrt(theNumber) | 2aaa505fed81d136c069700e928b8ff77401a01a | 292,621 |
def module_checkpoint(mod, prefix, period=1, save_optimizer_states=False):
"""Callback to checkpoint Module to prefix every epoch.
Parameters
----------
mod : subclass of BaseModule
The module to checkpoint.
prefix : str
The file prefix for this checkpoint.
period : int
... | 007ab00fe2b0ce3b6acca76596ff5b68cd7cb8d6 | 56,285 |
def get_branch_name(ref: str, ref_prefix='refs/heads/', clean=True, max_len=15):
"""
Get and preprocess the branch name from the reference within a CodeCommit event.
:param ref: As obtained from the CodeCommit event
:param ref_prefix:
:param clean:
:param max_len: Maximal length of the resultin... | 48a12bacbdb2b7d51d61cfd941fa343c04073b97 | 101,136 |
def offbyK(s1,s2,k):
"""Input: two strings s1,s2, integer k
Process: if both strings are of same length, the function checks if the
number of dissimilar characters is less than or equal to k
Output: returns True when conditions are met otherwise False is returned"""
if len(s1)==len(s2):
flag... | a64c02b85acca64427852fc988ed2f769f750aa7 | 6,801 |
import torch
def logsumexp(tensor: torch.Tensor,
dim: int = -1,
keepdim: bool = False) -> torch.Tensor:
"""
A numerically stable computation of logsumexp. This is mathematically equivalent to
`tensor.exp().sum(dim, keep=keepdim).log()`. This function is typically used for summ... | 4c0eb3e03a3f762bcb42d9377fe8f90851400782 | 533,680 |
from typing import Tuple
from typing import Optional
def id_from_mention(mention: str) -> Tuple[int, Optional[str]]:
"""Get an ID from a mention
Any mention is supported (channel, user...).
Args:
mention: A mention to be stripped.
Returns:
A tuple containing the parsed ID and the ty... | 6e9c43e33fdcb86366765c9779b8c6c036650886 | 580,679 |
def IsZonalGroup(group_ref):
"""Checks if group reference is zonal."""
return group_ref.Collection() == 'compute.instanceGroups' | 4371be5a3e5b96738c756e8d873fdd795d3df068 | 533,951 |
def _frange_percent(frame, frange):
"""Determines what percent completion a task is based on frame and frange
Args:
frame : (int)
The frame to determine what percent complete we are.
frange: (<nuke.FrameRange>)
A nuke.FrameRange object with frange information.
Retu... | 9b6f49c85a74ba0fcbfe8cf1cef514860ef56e99 | 360,517 |
def _principals_for_authenticated_user(user):
"""Apply the necessary principals to the authenticated user"""
principals = []
if user.is_superuser:
principals.append("group:admins")
if user.is_moderator or user.is_superuser:
principals.append("group:moderators")
if user.is_psf_staff o... | 288a56e9fdbc726dea5ba9a72efd83d6a0082f48 | 559,726 |
def _iter_graded(scores):
"""
Yield the scores that belong to explicitly graded blocks
"""
return (score for score in scores if score.graded) | ddb63743932b37fde63d7050564097780af2140c | 352,016 |
import types
def className(obj, addPrefix=False):
"""Return human-readable string of class name."""
if isinstance(obj, str):
class_str = obj
# don't add prefix -- it's unknown
prefix = ""
elif isinstance(obj, type):
class_str = obj.__name__
if addPrefix:
... | a5a9d7fb0be0b01700a4f9d02d6532e758d662bd | 104,163 |
def modify(node):
"""
Modify the branch to NODE, if NODE is a terminal node and the `division_exposure`
of NODE differs from the `division`.
This creates an intermediate branch, with a single child, such that we have
PARENT-INTERMEDIATE-NODE.
"""
if "children" in node:
return node
... | 983714cc7a4703e0bc2cc84d4c75d2c657719745 | 621,970 |
def smooth_series(data, window, method="average"):
"""Apply a moving average or mean with window of size "window"
Arguments:
data {Dataframe} -- Pandas dataframe
window {int} -- size of window to apply
Keyword Arguments:
method {str} -- the method applied to smooth the data... | f09b956c0a899de8b8607e08b05bdbc917e473a7 | 653,179 |
import re
def from_camelcase(inStr):
"""Converts a string from camelCase to snake_case
>>> from_camelcase('convertToPythonicCase')
'convert_to_pythonic_case'
Args:
inStr (str): String to convert
Returns:
String formatted as snake_case
"""
return re.sub('[A-Z]', lambda x:... | 73b876e2eab1361c97acd5b4828db2de384a30c1 | 101,174 |
def createHeaders(X_APIKEY, Content_Type="application/json"):
"""
Create headers for API calls within this package
REQUIRED ARGUMENTS
:param X_APIKEY: String - Authentication key for the API
OPTIONAL ARGUMENTS
:param Content_Type: String - Default to "application/json"
:return: JSON Heade... | 0bd937c405f5b2602b2f74f2281de240c45d2dc5 | 550,905 |
def _has_rows(rows: list) -> bool:
"""
Determine if the table has rows.
Keyword arguments:
rows -- the rows to check
Returns: True if the table has rows, False otherwise
"""
return len(rows) > 0 | ae8901084583a788a56ce47cbabf33956b939cda | 617,404 |
import pickle
def load_data(pickle_file):
""" Load the data from given path.
Args:
pickle_file: pickle file of the requested data
Returns:
A tuple of (features, labels) for the given `pickle_file`
"""
with open(pickle_file, mode='rb') as f:
data = pickle.load(f)
retu... | 4c1f1a56114449feda8cd5450fb6535bb2bd4f65 | 644,694 |
import re
def process_tspi_h(input_string):
"""Process the file content of tspi.h
Parses the input file content and tokenize each function declaration into a
3-tuple as shown in the following example:
***declaration***:
TSPICALL Tspi_Context_Create
(
TSS_HCONTEXT* phContext ... | 4708e92a5b31c57548ee9eafeffb5510df3d5fab | 301,089 |
import torch
def is_double_tensor(tensor: torch.Tensor) -> bool:
"""
Returns True if a tensor is a double tensor.
"""
if torch.is_tensor(tensor):
return tensor.type().endswith("DoubleTensor")
else:
return False | 4ebd29e94f11b23522fcd74bae3e51f0993625ea | 393,034 |
def convert_data_to_ints(data, vocab2int, word_count, unk_count, eos=True):
"""
Converts the words in the data into their corresponding integer values.
Input:
data: a list of texts in the corpus
vocab2list: conversion dictionaries
word_count: an integer to count the words in the dat... | c415aea164f99bc2a44d5098b6dbcc3d723697a6 | 5,801 |
def nested_get(input_dict, keys_list):
"""Get method for nested dictionaries.
Parameters
----------
input_dict : dict
Nested dictionary we want to get a value from.
keys_list : list
List of of keys pointing to the value to extract.
Returns
----------
internal_dict_value... | 8c4620795e001524480b39a219cea913493cfad9 | 167,940 |
import numbers
def is_integer(x):
"""True if x is an integer (both pure Python or NumPy).
Note that Python's bool is considered an integer too.
"""
return isinstance(x, numbers.Integral) | faff1683bdb1229420bb39b2a39cd8ffff46e313 | 514,274 |
import math
def step_decay(lr0, s, epochs_drop=1.0):
"""
Create stepwise decay: Drop learning rate by half (s) every specified iteration.
Parameters
----------
lr0 : float
initial learning rate
s: float
decay rate, e.g. 0.5, choose lower s than for other decays
epochs_drop... | bb42852f0276082fe6516a6a5c961f7d5a0f359e | 341,172 |
import math
def ordinal(number):
"""
Converts integer number (1, 2, 3 etc) to an ordinal number representation (1st, 2nd, 3rd etc)
https://stackoverflow.com/a/20007730/297131
:param number: An integer number
>>> [ordinal(n) for n in range(0,32)]
['0th', '1st', '2nd', '3rd', '4th', '5th', '6... | f040efacafab71d6797bd7d002f7888f27c7e973 | 528,743 |
def reverse_index_1d(state):
"""The inverse of index_1d. From an row number in the transition matrix return the row and column in the grid world.
Parameters
----------
state : int
An integer representing the row in the transition matrix.
Returns
-------
row : int
The row in... | 8bac5aa86ac4ff3fee441065b3d58fbd2f1c089a | 543,613 |
def find_first_slice_value(slices, key):
"""For a list of slices, get the first value for a certain key."""
for s in slices:
if key in s and s[key] is not None:
return s[key]
return None | 6b454b6464f3ba2ecaa9d2a4e663233178ae013e | 478,012 |
import operator
import itertools
def find_contiguous_ids(job_ids):
"""Return the contiguous job ids in the given list.
Returns
-------
contiguous_job_ids : str
The job ids organized in contiguous sets.
"""
contiguous_job_ids = []
for k, g in itertools.groupby(enumerate(job_ids)... | 33f4b4838e76751083f176b71999508c06164b5c | 287,182 |
import random
def random_int(min=1, max=100):
"""Generate a random integer between min and max"""
return random.randint(min, max) | f5af0521613a7327b343c8a060231f0454e7a645 | 564,149 |
import random
import string
def rand_string(L):
"""
:param L: Integer, length of the string to randomly generate
:return: String (of the given length L) of random characters
"""
return ''.join(random.choices(string.ascii_lowercase + string.digits, k=L)) | 07c4b5e57b5803d3dedc8ff43179036f49db42b1 | 253,957 |
def get_table(table):
"""
Updates table styling
:param table: an html table
:return: the newly styled table
"""
table['class'] = "usa-table"
return table | bc25990a83fae2c9a6da106f7af25e1ef87a39d5 | 568,965 |
def __patronymics(name, ltr):
""" Auxiliary function for generating suffixes for name
1. name - part of name
2. ltr - 'е' for 'евич' / 'евна' or 'о' for 'ович' / 'овна' suffixes
3. return list of generated patronymics
"""
return [name + ltr + 'вич', name + ltr + 'вна'] | f9f3568334247ad495e95ab48f749d86da6a6a70 | 434,529 |
def _filter_slabs(provisional, max_size):
"""
Filters the repeat slabs from the list of all the zero dipole slabs.
Creates lists of large and repeat slabs if any are present for the warnings
Args:
provisional (`list`): All zero dipole slabs generated with SlabGenerator
max_size (`int... | 4993bc6d89e0d09840c30ce54119cc54e9ca42f2 | 667,839 |
def head(mention):
""" Compute head of a mention.
Args:
mention (Mention): A mention.
Returns:
The tuple ('head', HEAD), where HEAD is the (lowercased) head of
the mention.
"""
return "head", mention.attributes["head_as_lowercase_string"] | 2fe6333bc3711ea82055ae0ec7334ce26f36e593 | 549,537 |
def from_tensor(tensor_item):
"""
Transform from tensor to a single numerical value.
:param tensor_item: tensor with a single value
:return: a single numerical value extracted from the tensor
"""
value = tensor_item.item()
if value == -1:
return None
return value | 9981215be4eb6d40838a50d147af2368ca854cd8 | 625,595 |
import jinja2
def jinja(source, environ, destination=None):
""" Render a Jinja configuration file, supports file handle or path
"""
close_source = close_destination = False
if type(source) is str:
source = open(source, "r")
close_source = True
if type(destination) is str:
d... | 511bd806167767ce8cb5d9323a8e6702a16e8631 | 124,252 |
def parr_to_pdict(arr, measures_optimized):
"""Convert BO parameter tensor to parameter dict"""
if measures_optimized:
d = {
'p_stay_home': arr[0].tolist(),
}
return d
else:
d = {
'betas': {
'education': arr[0].tolist(),
... | 50623f2aae87a5326b4524f249bf28eb093aa7c0 | 685,643 |
def _MasterUpgradeMessage(name, server_conf, cluster, new_version):
"""Returns the prompt message during a master upgrade.
Args:
name: str, the name of the cluster being upgraded.
server_conf: the server config object.
cluster: the cluster object.
new_version: str, the name of the new version, if g... | 1c646f57d97ef3b5c639aed816190f0f6d7bb488 | 359,936 |
def active_users(engine,reverse=True):
"""Given a SimilarityEngine instance, returns a list of users sorted by like activity
(the number of like per user), in descending or ascending order, respectively, according
to the True/False status of the :reverse flag, which defaults to True (for descending order).
... | 46cb9f9b16c2dba32be19af7dc83c8571f59ebf0 | 377,530 |
from typing import List
def generate_reason(total_points: int, message: str, recipients: List[str]) -> str:
"""
:param total_points: the amount of points that should be distributed
:param message: the message used when awarding points
:param recipients: a list of email addressed for users who should r... | 17185f706949bc92f04c66a65a734badb242d9dd | 632,438 |
import json
def hdelk_html(schm: dict, header: str = "Schematic", display_customizations: str = "") -> str:
"""
Generates HTML with schematic using HDElk
:param schm: schematics data in tool_render format (actually that is content for HDElk's graph variable)
:param header: string to be written in head... | a0137c1f2af7c18b5516d9a20afca78b3c5068b5 | 432,001 |
def set_gauss(fwhm):
"""
Compute the sigma value, given Full Width Half Max.
Returns an operand string
Parameters
----------
fwhm : float
Returns
-------
op_string : string
"""
sigma = float(fwhm) / 2.3548
op_string = "-kernel gauss %f -fmean -mas " % sigma + "%s"
... | 77d63299a5bc93ccaff19980f98d75a51f554b7d | 562,938 |
from typing import Dict
import inspect
def find_all_avail_tasks() -> Dict:
"""
Finds and returns the list of callable tasks.
Within FabSim3, each function that wrapped by @task can be called from
command line.
Returns:
array of function object
"""
f_globals = inspect.stack()[1][0].... | b295141eaaf2e2b7a8eb6f844d02ad3dfba72048 | 521,820 |
def ReadTxtName(rootdir):
"""
read the configuration which describe the the dataset , which consists of filenames, labels
"""
filenames=[]
labels=[]
with open(rootdir, 'r',encoding="utf-8") as file_to_read:
while True:
line = file_to_read.readline()
if not line:
... | ce7b8dcbf1363b2b1d4093e1f83bd4eb8b6950c7 | 197,095 |
def update_hypnogram_cycles(hypno, cycles):
"""
Add cycle identifiers to hypnogram based on cycle detections
Parameters
----------
hypno : pd.DataFrame
Hypnogram dataframe obtained through load_hypno().
cycles : pd.DataFrame
Tabulated estimates for onsets, offsets and durations ... | e65c52f1d12c08c00db2463ae5050064bdb366c5 | 477,527 |
def _contains_training_quant_op(graph_def):
"""Checks if the graph contains any training-time quantization ops."""
training_quant_ops = {
"FakeQuantWithMinMaxVars",
"FakeQuantWithMinMaxVarsPerChannel",
"QuantizeAndDequantizeV2",
"QuantizeAndDequantizeV3",
}
return any(
... | cdb908e9eed7a63f53a6a93ff02e40224d9205f2 | 297,147 |
def pickCompat(obj, keys):
"""
Forming dict from given one and list of keys
@param {dict} obj
@param {list[str]} keys
@return {dict}
"""
result = {}
for key in keys:
result[key] = obj.get(key)
return result | 89ca34d9cd3c47d4fdce833931321a945f5e886a | 151,785 |
def shift_left_bit_length(x: int) -> int:
""" Shift 1 left bit length of x
:param int x: value to get bit length
:returns: 1 shifted left bit length of x
"""
return 1 << (x - 1).bit_length() | 854e79309125c60c6e5975685078809fb4c016a4 | 705,029 |
def s2d(kv):
"""Turn a string k=v1,k2=v2 into a dict"""
return dict([s.split('=') for s in kv.split(",")]) | 1fc6defdd970791cea2423f8d0aa2c1feed95ceb | 205,839 |
def seqToGenbankLines(seq):
""" chunk sequence string into lines each with six parts of 10bp, return as a list
>>> seqToGenbankLines("aacacacatggtacacactgactagctagctacgatccagtacgatcgacgtagctatcgatcgatcgatcgactagcta")
['aacacacatg gtacacactg actagctagc tacgatccag tacgatcgac gtagctatcg', 'atcgatcgat cgactagct... | f0e290cf3d666980edc18acc50523f45ab18e24a | 23,126 |
def _get_data_list(data, key):
"""get key's value as list from request arg dict.
If the value type is list, return it, otherwise return the list
whos only element is the value got from the dict.
Example: data = {'a': ['b'], 'b': 5, 'c': ['d', 'e'], 'd': []}
_get_data_list(data, 'a') == ['... | 07c0759b99105b0a913d343a9e6c7e88e4229d36 | 551,523 |
import logging
def infer_header(input_path, expected_lines, method_name=None):
"""
Method that infers the length of the header of a given file from the number of lines and of expected lines.
Parameters
----------
input_path : file or string
File or filename to read.
expected_lines : i... | b3c590f9d55b0e3f80e06fa2a3d1541a195c6a5c | 603,501 |
def springForce(k, x, p):
""" Calculate the spring force """
return -k*x**(p - 1) | e5aeacece84e53168be2d4c0938a13e855d0a168 | 537,337 |
def my_linear_model(B, x):
"""Linear function for the regression.
Args
B (1D array of 2): Input 1D polynomial parameters (0=constant, 1=slope)
x (array): Array which will be multiplied by the polynomial
Returns
-------
An array = B[1] * (x + B[0])
"""
return B[... | 775bb4b36005c2704ecf163e2df1e3c19231959a | 99,087 |
import six
import re
def _escape_non_ascii(unicode_obj):
"""
Escape non-printable (or non-ASCII) characters using Java-compatible Unicode escape sequences.
This function is based on code from the JSON library module shipped with Python 2.7.3
(json/encoder.py, function py_encode_basestring_ascii), whi... | 91291bae5cd9845dea58f9366908d41726239b49 | 497,532 |
def clean_cases(text):
"""
Makes text all lowercase.
:param text: the text to be converted to all lowercase.
:type: str
:return: lowercase text
:type: str
"""
return text.lower() | 9b0c931336dbf762e5e3a18d103706ddf1e7c14f | 708,013 |
def get_data_from_txt(path: str) -> list:
"""
读取文件中各行数据,存放到列表中
"""
lines = []
with open(path, encoding="utf-8", mode="r") as f:
line = f.readline().strip()
while line:
lines.append(line)
line = f.readline().strip()
return lines | f47d902387450869634af6a3efff44e972ecb2a1 | 462,469 |
def check_insertion_order(metadict_inst, expected):
"""
Ensure that the keys of `metadict_inst` are in the same order as the keys
in `expected`.
The keys case is ignored.
"""
def normalise_keys(lst_pairs):
return [key.lower() for key, _ in lst_pairs]
assert normalise_keys(metadict_... | a6ec3e30b2c743ae8c03441884325a8c1d22346b | 677,793 |
def final_score_calculator(score_list):
"""Returns final Levenshtein Word Score
Iterates through all the scores for the various queries. Final score is
calculated by averaging the ratio of the score with the word length of
the ground truth. A given score is capped at 1.
"""
final_score = 0.0
... | f7a61d71e522385850b505bd08431824987ad20d | 167,191 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.