content
stringlengths
39
14.9k
sha1
stringlengths
40
40
id
int64
0
710k
def uninterleave(data): """Given a stereo array, return separate left and right streams This function converts one array representing interleaved left and right audio streams into separate left and right arrays. The return value is a list of length two. Input array and output arrays are all Numpy...
713e753898236c172b552b1fa245bd0e1feff0fd
691,533
import math def wien_deriv(x): """ The first derivative of the nonlinear equation in wien(). """ return 1 - 5 * math.exp(-x)
cd3836648921b932641c4d6b9d28729c8d6ef7a8
691,542
def find_production_volume_by_id(dataset, uuid): """Find production volume in ``dataset`` with id ``uuid``. Raises ``ValueError`` if ``uuid`` not found in dataset, or if the found exchange does not have a production volume.""" for exc in dataset['exchanges']: if exc['id'] == uuid: if 'p...
96bf9a84d360df7e6173a02ef09b9fbcf223af5c
691,546
def factorial(x): """This is a recursive function to find the factorial of an integer""" if x == 1: return 1 else: return (x * factorial(x-1))
58bbb5794e6110a28653560654e7dd689def3bd8
691,548
def construct_lvol_store(client, bdev_name, lvs_name, cluster_sz=None): """Construct a logical volume store. Args: bdev_name: bdev on which to construct logical volume store lvs_name: name of the logical volume store to create cluster_sz: cluster size of the logical volume store in byte...
33463a7efd59a92ba68eecfca98277f6e273520c
691,549
def dxdt(y, z): """Computes the equation for x prime""" dx = -y - z return dx
5307deada35d965dafa6e32576d67335c522d775
691,551
def split_1_grams_from_n_grams(topics_weightings): """ Pair every words with their weightings for topics into dicts, for each topic. :param topics_weightings: it is a 3D list of shape [topics, number_of_top_words, 2] where the 2 is two entries such as (top_word, top_words_weighting). :return: T...
cdb058d4ad718d578e2e11ec3d4ae9eb008224b4
691,555
def temporal_iou(span_A, span_B): """ Calculates the intersection over union of two temporal "bounding boxes" span_A: (start, end) span_B: (start, end) """ union = min(span_A[0], span_B[0]), max(span_A[1], span_B[1]) inter = max(span_A[0], span_B[0]), min(span_A[1], span_B[1]) if inter...
184b83bf110e1831f4829500d8405e1898c52968
691,556
def _max(arr): """Maximum of an array, return 1 on empty arrays.""" return arr.max() if arr is not None and len(arr) > 0 else 1
72e2a6b5c3a6d09cd38e858211280704be58c838
691,558
def extract_average_token_length(**args): """ Example query feature that gets the average length of normalized tokens in the query„ Returns: (function) A feature extraction function that takes a query and returns the average normalized token length """ # pylint: disable=locally-...
ac1d98ede91b1a8d8b99e63093bb3f5a79747d59
691,560
def parse_bm_alleles_col(_str): """ Parse 'alleles' column of biomart response """ if _str == '': return [] else: return _str.split('/')
31e562608781e14decca447073b45bae1f20c8f4
691,562
def geometry_column_name(df): """Get geometry column name, fall back to 'geometry' Args: df (pandas.DataFrame): [description] Returns: geom_col (string): [description] """ try: geom_col = df.geometry.name except AttributeError: geom_col = 'geometry' retu...
46141489406ad9a542848bbe337e22af5e4e92fb
691,563
def initials(name): """ Converts a name to initials form. :param name: a string of words. :return: the string in initials form. """ return ".".join([x[0].upper() for x in name.split()[:-1]] + [name.split()[-1].title()])
893656321c24b5cc54054a753e388f9f0cda2e63
691,565
def should_update(iteration, epoch, settings): """ Tells whether it is time to update the plateaus or not :param iteration: iteration number :param epoch: epoch number :param settings: settings dictionary :return: True if it is time for an update, and False otherwise """ no_update = Fal...
bc14ddf7cf2c3a23245038a7870794ec8473b69f
691,566
def is_ref_name(name): """Check if a given name is a reference directory """ ext_name = name.split('/')[-1].split('.')[1] if ext_name == 'ref': return True else: return False
3dfdbb6222a61f6bb8fe57be87f670e066101248
691,567
import re def trimUnicode(s): """ Trims string s of unicode text """ return re.sub(r'[^\x00-\x7F]+',' ', s)
e3dfdcce51e3a7e808383ddd8f69803d69b4010b
691,568
def centroid(img): """ finds the centroid of the given image img input:: img (np.ndarray): input img to find the centroid of return:: centroid (tuple): centroid of the input image (height,width) """ centroid = img.shape[0]//2, img.shape[1]//2 return ce...
ec50349c7514f4b104ee598e864f8ecdd78cba09
691,569
import math def haversineDegreesToMeters(lat_1, lon_1, lat_2, lon_2): """ Haversine equation for finding the distance between two lat-lon points in meters. :param lat_1: first latitude point :param lon_1: first longitude point :param lat_2: second latitude point :param lon_2: second longitude ...
5c3a60e0b92d62dbe21169f40ffa99f067648fb6
691,571
def swap_1d(perm, i, j): """ Swap two elements of a 1-D numpy array in-place. Examples -------- >>> perm = np.array([2, 1, 2, 3, 4, 5, 6]) >>> swap_1d(perm, 2, 6) array([2, 1, 6, 3, 4, 5, 2]) """ perm[i], perm[j] = perm[j], perm[i] return perm
d120e9d2aa9f5d7268658698be5b31ec20a31a9d
691,576
def missing_branch(children): """Checks if the missing values are assigned to a special branch """ return any([child.predicate.missing for child in children])
75dd5f4cd503ae614023bc73c0119bebc9bb561e
691,577
def _replace_signature(raw_header: bytes, signature: bytes) -> bytes: """Replace the 'signature' field in a raw header.""" return signature + raw_header[8:]
4e1d37f445488f091a62133f733d67f7707a6229
691,579
def dummy_selector_a(node): """ Dummy node selector. """ return node['name'] in ('A', 'B', 'G')
02311dfa0c2f2a7ae37420b5b2fe61fb29d9aea6
691,583
import logging def check_batch(batch, max_length=None): """print data shapes and check max_length""" def _print(k, d): if k in d: print(f'\t{k}: {d[k].shape}') logging.info(f'Get protein_name: {batch["name"]}') for k in ['aatype', 'msa_feat', 'extra_msa', 'masked_msa_only']: ...
d06862bc2bccab8f88998718e7c3351899a6d49d
691,589
def totaler(products): """Totals the total value of each product.""" totalDict = {'base': 0, 'VAT': 0, 'total': 0}; for h in products: totalDict['base'] += h['base']; totalDict['VAT'] += h['VAT']; totalDict['total'] += h['total']; return totalDict;
1c27cc2a69f44eb60d71cdd12ef887c8d1c7daf1
691,594
def snp_resultsHandover(variantId): """Create the resultsHanover dict by inserting the variantId into the template.""" resultsHandover = [ { "handoverType" : { "id" : "data:1106", "label" : "dbSNP ID" }, ...
177d7437d759696538de70c26b326083d3cd22fc
691,596
def instance_supports_efa(instance_type: str) -> bool: """Checks if instance supports Amazon Elastic Fabric Adapter""" # https://docs.aws.amazon.com/en_us/AWSEC2/latest/UserGuide/efa-start.html return instance_type in ['c5n.18xlarge', 'i3en.24xlarge', 'p3dn.24xlarge']
7e05b87555e2de65b92df0dd6d84f31889493a08
691,598
def first_name(name): """ Return the first name of a name.""" if not isinstance(name, str): return name return name.split(' ')[0].title()
cd1ebfc43351ef05cadf23155bc25b37289c410a
691,600
import sqlite3 def get_user_review(user_id, prof_id, course_name): """ Fetches the user review from DB if exists. Otherwise returns None. """ cursor = sqlite3.connect('./db.sqlite3').cursor() cursor.execute("SELECT * FROM review NATURAL JOIN rating WHERE user_id = ? AND prof_id = ? AND course_...
59514104b1382157627325115bd5f041b961b3b9
691,601
def get_html_xml_path(path, build_name): """Parse and replace $BUILD_NAME variable in the path. Args: path(str): path to html report build_name(str): software build number Returns: str: modified path to html report """ try: return path.replace("__BUILD_NAME__", b...
204722413aea85221756eb53e677d265c20200b5
691,606
def capacity_cost_rule(mod, g, p): """ The capacity cost of projects of the *gen_spec* capacity type is a pre-specified number equal to the capacity times the per-mw fixed cost for each of the project's operational periods. """ return mod.gen_spec_capacity_mw[g, p] * mod.gen_spec_fixed_cost_per_...
521348dc171961e0687661a20a6898a1eca3daf6
691,609
def get_locations(data: dict) -> list: """ Get users' locations from the dictionary. Return list of lists, every one of which contains user's nickname and location. >>> get_locations({'users': [{'screen_name': 'Alina', 'location':\ 'Lviv, Ukraine'}]}) [['Alina', 'Lviv, Ukraine']] """ result...
21c2cbc984e085d8b7b6da418e8184aa2d037cd2
691,612
def _label(label: str) -> str: """ Returns a query term matching a label. Args: label: The label the message must have applied. Returns: The query string. """ return f'label:{label}'
10472e6850923d2f35bdff1fb3603f82293a3d15
691,613
import torch def collate_fn(data): """Sorts the input(the mini-batch) by length and truncates all the data points to the max length of the input""" sorted_data = sorted(data, key=lambda x: x[2], reverse=True) max_len = sorted_data[0][2] x = torch.stack([x_i[:max_len] for x_i, y_i, l_i in sorted_data])...
4a04f4cf82b0db57ef9675d68887eced23662d0a
691,617
def seasonal_naive(data, n=7, **kwargs): """The seasonal naive forecast for the next point is the value observed ``n`` points prior in the series. The seasonal parameter (``n``) does not have units of time, but rather units of one observation. For example, to account for weekly cycles within daily ob...
a72ecc75a2c79f3e0add9659bf576a355deacfe3
691,618
import random def pick(obj): """randomly pick an element from object""" return random.sample(obj, 1)[0]
eded3083c775370dc5e2d23046934b98bfe1ef38
691,622
import re def probability_cube_name_regex(cube_name): """ Regular expression matching IMPROVER probability cube name. Returns None if the cube_name does not match the regular expression (ie does not start with 'probability_of'). Args: cube_name (str): Probability cube name ...
6fafd524405def4490729846f2d4b705b14225a0
691,624
import re def adjust_name_for_printing(name): """ Make sure a name can be printed, alongside used as a variable name. """ if name is not None: name2 = name name = name.replace(" ", "_").replace(".", "_").replace("-", "_m_") name = name.replace("+", "_p_").replace("!", "_I_") ...
931df7fd3f6f456ead9b62692dea6bae31cf736f
691,625
import pickle def from_pickle(input_path): """Read network from pickle.""" with open(input_path, 'rb') as f: unpickler = pickle.Unpickler(f) background_mat = unpickler.load() return background_mat
9fd24fc422b9b15d831d9411ef9ba5537cf2c90d
691,626
def pres(gamma, dens, eint): """ Given the density and the specific internal energy, return the pressure Parameters ---------- gamma : float The ratio of specific heats dens : float The density eint : float The specific internal energy Returns ------- ...
3bdcdfd1dd280d9cfd397ba0c21bffce0d68bcb6
691,629
def compressed(x, selectors): """ compress('ABCDEF', [1,0,1,0,1,1]) --> A C E F """ return [d for d, s in zip(x, selectors) if s]
349ea3ffe35b135b5393650b5aff3d9a981c35d8
691,633
from typing import Any def flatten_dict(data: dict[str, Any], keys: list[str] = []) -> dict: """ Takes a dictionary containing key-value pairs where all values are of type other than `list` and flattens it such that all key-value pairs in nested dictionaries are now at depth 1. Args: data (dict): Diction...
1552225dd436e882685b90e237c761f2526b9244
691,634
import fnmatch def _table_matches_any_pattern(schema, table, patterns): """Test if the table `<schema>.<table>` matches any of the provided patterns. Will attempt to match both `schema.table` and just `table` against each pattern. Params: - schema. Name of the schema the table belongs to. ...
d59e654b52f61e3b5335c2bee5dfdb960c0d8060
691,636
import typing import enum def _enum_labels( value: typing.Union[int, str, enum.Enum], enum_type: typing.Optional[typing.Type] = None, ) -> typing.Dict[int, str]: """ Gets the human friendly labels of a known enum and what value they map to. """ def get_labels(v): return getattr(v, 'native_labe...
c48dece92922044050ad35f066bf303d2b7b9ac1
691,642
def logPlusOne(x): """ compute log(x + 1) for small x Args: x: Tensor Returns: Tensor log(x+1) """ eps=1e-4 mask = x.abs().le(eps).type_as(x) return x.mul(x.mul(-0.5) + 1.0) * mask + (x + 1.0).log() * (1.0 - mask)
5c5e621418490904323d7ca40213df66a23b6076
691,644
def calculate_directions(directions): """ Input: An iterable of (direction, unit) Output: A summarized collection of directions (x, y) """ x = 0 y = 0 for direction, unit in directions: assert direction in ['forward', 'down', 'up'] if direction == 'forward': x += ...
f3b076f8cbf9e0559c418909132b37ee79f908c2
691,645
def inc(x): """ Increments number by one """ return x + 1
5720c02c0d8c2f10249a13951d420d8a958466a6
691,646
def calc_a(dert__): """ Compute vector representation of angle of gradient by normalizing (dy, dx). Numpy-broadcasted, first dimension of dert__ is a list of parameters: g, dy, dx Example ------- >>> dert1 = np.array([0, 5, 3, 4]) >>> a1 = calc_a(dert1) >>> print(a1) array([0.6, 0.8]...
d1be9a8eb2985776af45380248910d70ae09c840
691,647
def slide_window(img, x_start_stop=[None, None], y_start_stop=[None, None], xy_window=(64, 64), xy_overlap=(0.5, 0.5)): """ Generate a list of windows for an image. Args: img: Input image x_start_stop: Start / stop position on the x axis (default to image width) y_s...
39856ae488cbfb74f1865992e7ab7f5ffd971c62
691,651
def util_key_new ( schema, keys ): """Returns list of keys not in schema""" new_keys = [] for i in keys: if i not in schema: new_keys.append(i) return new_keys
3c856516bb6d20da865ac749e35de5f05c9dff66
691,653
import re def remove_redundant_path_slashes(path): """ If a relative filename contains multiple consecutive / characters (except at the beginning, in case of //server/host paths), remove them. >>> remove_redundant_path_slashes('/test//test2') '/test/test2' >>> remove_redundant_path_slashes('//...
5cad7b7bf7d15b2d99894e3ef365c2b18d776c9b
691,654
import math def pose_dist(pose1, pose2): """Return Euclidean distance between two ROS poses.""" x1 = pose1.position.x y1 = pose1.position.y x2 = pose2.position.x y2 = pose2.position.y return math.sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2))
59a884f078debee6a266612b3a5c480950df19eb
691,655
def _user_can_manage(user, partner): """ Whether this user can manage the given partner org """ if user.can_administer(partner.org): return True return user.get_partner() == partner and partner.org.editors.filter(pk=user.pk).exists()
33160eff14687921c127fb2ab199d8b1a406d90d
691,657
def average(sequence): """Calculate the mean across an array of e.g. read depths. Defaults to the mean calculated using numpy and falls back to the naive Python solution. Args: sequence (list): ``numpy.array`` or list of values Returns: float: calculated average value """ try: # first assum...
eb66b74166040b9556f2af3f4ef8c60d0fa91a97
691,658
def cver_t(verstr): """Converts a version string into a tuple""" if verstr.startswith("b"): return tuple([0,0,0,0]+list(cver_t(verstr[1:]))) return tuple([int(x) for x in verstr.split(".")])
73b4abd456551e678f44c0f940ad8d055993a345
691,660
def remove_markdown(body): """Remove the simple markdown used by Google Groups.""" return body.replace('*', '')
0510a76c1ce1ac68a684f954400ea3e162e2e529
691,661
def get_decades(year): """ Return 4 digit and 2 digit decades given 'year' """ if year: try: decade = year[2:3] + "0" decade2 = year[:3] + "0" except: decade = "" decade2 = "" else: decade = "" decade2 = "" return decade, de...
fa5d84466e0b61e4dc88d157dbc22f1a61f231ad
691,673
def apply_weighting(object_to_be_weighted, weights): """ Replicate the components of object_to_be_weighted using the corresponding weights to define the number of replicates. Args: object_to_be_weighted: could be a list or an array weights: a list of integers Returns: the transformed obj...
51161b4ed6e6540390487c40613838083f00fd3b
691,675
def parse_timeout(arg): """Parse timeout argument""" if not arg: return None return int(arg)
e39af5bc323bb0ea32f1438a2459274627fd2f12
691,676
def doubleStuff(a_list): """ Return a new list in which contains doubles of the elements in a_list. """ new_list = [] for value in a_list: new_elem = 2 * value new_list.append(new_elem) return new_list
f34d76eb05fc8a07fb0bee41c701e18542d6554a
691,677
import statistics def median_of_counter_obj(counter): """ Calculate the weighted median of a counter obj :param counter: A counter obj """ items = [] for item in counter.items(): items += [item[0]] * int(item[1]) return statistics.median(items)
35327a66182e4482511b5dc511dd00bf45a9350a
691,678
def vowels_loop(value): """Count the number of vowels in a string, using a loop.""" count = 0 for char in value.lower(): if char in "aeiou": count += 1 return count
6f55e30283e9873933265568b5434cd014f3c825
691,681
def fixup(line): """Account for misformatted data from FFIEC with one-off fixups""" if line[0] == "2016" and line[1] == "0000021122" and len(line) == 23: return line[:6] + line[7:] return line
eccb0cb2afb34ec613efdf1272a6d884ddea2581
691,688
def make_region(chromosome, begin, end): """ Create region string from coordinates. takes 2 (1 for human 1-9) digit chromosome, begin and end positions (1 indexed)""" region = "chr" + str(chromosome) + ":" + str(begin) + "-" + str(end) return region
5108f01bd1ab49770073036e2ad1106e7da354dd
691,689
def _xml_tag_filter(s: str, strip_namespaces: bool) -> str: """ Returns tag name and optionally strips namespaces. :param s: Tag name :param strip_namespaces: Strip namespace prefix :return: str """ if strip_namespaces: ns_end = s.find("}") if ns_end != -1: s = s[...
647ee8e2b1aca898b625b00e0e366e1292ddbed6
691,691
def format_actions(action_list): """ Returns the action list, initially a list with elements "[op][val]" like /2.0, -3.0, +1.0, formatted as a dictionary. The dictionary keys are the unique indices (to retrieve the action) and the values are lists ['op', val], such as ['+', '2.0']. """ return {...
e2c0c15f19184d021fd09b9c93ae89e1aef4efae
691,693
def interpolate_temperature(temperature): """Transform temperature from degree celsius to 0.0 - 1.0 range 0.0 is -10 degrees (very cold) 1.0 is 35 degrees (very hot) Parameters: temperature - float in degrees celsius Returns: float normalized temperature """ return min(1.0,...
b4807e24b6119d70bfbdf31bd19c5777f512773d
691,694
def lead(x, n = 1, default = None): """Return an array with each value replaced by the next (or further forward) value in the array. Arguments: x: a pandas Series object n: number of next values forward to replace each value with default: what to replace the n final values of the array ...
c7c41355008c6691a01bcae31130ab0469543480
691,695
def get_and_check_size(iterator, n): """Check if the iterator is length n and return consumed elements. Consumes the next n+1 elements if possible (up to the end of the iterator). Returns (is_length_n, elems) """ elements = [] try: for _ in range(n): elements.append(next(ite...
e8a7f61f5346cdeccf0e3b67debabf6b9d20eae8
691,696
def square(x): """Return the square of x. >>> square(2) 4 >>> square(-2) 4 """ return x * x
a0cf408826163a0e3a123ff0b71330e09dd59286
691,697
def is_right_bracket(token): """ returns true if token is right bracket """ return token == ")"
0ce454bf48b1473e50f69ab3a6b44a8ceef5a081
691,700
def _make_CSV_line(username, language): """Return a WikiMetrics compatible CSV line.""" return "%s, %swiki" % (username, language)
6dc01ea0e225f19ca88e33ff77757e8cd047408e
691,701
import torch def pixelshuffle(x: torch.Tensor, dimensions: int, scale_factor: int) -> torch.Tensor: """ Apply pixel shuffle to the tensor `x` with spatial dimensions `dimensions` and scaling factor `scale_factor`. See: Shi et al., 2016, "Real-Time Single Image and Video Super-Resolution Using a nEffi...
be1617e01eb43e958fcc5c38c4378ac9dede98ac
691,705
from pathlib import Path def ensure_parent(*args) -> Path: """ Ensure that the parent directory of a file exists. """ path = Path(*args) path.parent.mkdir(parents=True, exist_ok=True) return path
83ba38618ed7e3ddc790904824842a167d8e28d3
691,706
import math def get_utm_zone(lon: float, lat: float) -> str: """ Return the EPSG code of the corresponding wGS84 UTM zone given (lon, lat) coordinates. Args: lon (float): Longitude (in WGS84) lat (float): Latitude (in WGS84) Returns: str: The EPSG code of the correspondi...
45de051564738674d834273b9498e88f5500c7fe
691,711
import json def combine_api_shard_files(input_files, output_file=None): """ Merges the list of .json-formatted API shard files *input_files* into a single list of dictionaries, optionally writing the result to *output_file*. """ input_lists = [] print('Loading input files') for fn in inpu...
ffc8f694ca38b077835b8c80071ce402ceaf6002
691,712
def _GetHeuristicSuspectedCLs(analysis): """Gets revisions of suspected cls found by heuristic approach.""" if analysis and analysis.suspected_cls: return [(cl['repo_name'], cl['revision']) for cl in analysis.suspected_cls] return []
bf678079f10e8fa14874b451cfb5a8e7f76e1878
691,716
def sliding_window_regions(start, end, window_size, step_size): """ sliding_window_regions ====================== This method will split a gene into different regions based on a sliding window and step size. Each region is based on the window size. The window is slid down the gene using the step si...
775e7a8cfe79239465608133d4ad62d147502fab
691,717
from typing import Optional def dict_diff(d1: dict, d2: dict, no_key: Optional[str] = '<KEYNOTFOUND>') -> dict: """Compares two dictionaries Args: d1 (dict): First dictionary to compare d2 (dict): Second dictionary to compare no_key (Optional[str]): What value to use if key is not fou...
2213b4f0a2b6da52220005aa1b9ed9f42cfa4075
691,718
def resolution_from_fsc(bins, fsc, value=0.5): """ Compute the resolution from the FSC curve Args: bins (array): The resolution bins (ordered from low resolution to high) fsc (array): The fsc in that resolution bin Returns: (bin index, bin value, fsc value) """ assert ...
33ebfcb3d03703d6a5ceb5fe8d0220a28eafdb46
691,719
from pathlib import Path import json def Load_User_File(github_user): """ Load the contents of a JSON file Keyword arguments: github_user -- name of the file in the form <username>.json """ GITHUB_USER_PATH= "scripts/files/users/%s" % github_user my_file = Path(GITHUB_USER_PATH) # Are ...
a67a9993b4e512c46a1183c6f2b9e5a81ea162ed
691,720
from typing import Tuple def split_array(array_length: int, num_splits: int, split_id: int) -> Tuple[int, int]: """Split array into parts. Args: array_length: num_splits: split_id: Returns: start and end indices of the """ if not 0 <= split_id < num_splits: raise...
988460b6bf8f16143da3f2f4f01acb336cd0490b
691,722
def process_tags(tags): """Process the provided tag information to correct format. Converts the list of information to a dictionary to be able to pass to the geometry creation step. Input: ----- tags: list of lists, [[tagname1, tagval1], [tagname2, tagval2], ...] Return: ------- ...
95f78cdfb3632f705e6403fe04a78746c6cfa7d0
691,726
def onsegment(p, q, r): """ Returns true if point q lies on segment pq, given three collinear points p, q, r. """ if q[0] <= max(p[0], r[0]) and q[0] >= min(p[0], r[0]) and q[1] <= max(p[1], r[1]) and q[1] >= min(p[1], r[1]): return True else: return False
1c48c9cfeddf00b155ddc63ae81c386ec1105d36
691,728
def _format_rotator_mode(value): """Format rotator mode, and rais appropriate error if it can't be formatted.""" modes = set(['pa', 'vertical', 'stationary']) if value.lower() not in modes: raise ValueError("Rotator mode must be in {!r}".format(modes)) return value.lower()
f56bcccaccfa4d6e68783c68b8cd32676b6b6584
691,729
def _find_gaps_split(datagap_times: list, existing_gap_times: list): """ helper for compare_and_find_gaps. A function to use in a loop to continue splitting gaps until they no longer include any existing gaps datagap_times = [[0,5], [30,40], [70, 82], [90,100]] existing_gap_times = [[10,15], [35,...
af1aaafa27725a033f9d34ff6f10c4288c9f96d9
691,734
def MRR(predictions, target): """ Compute mean reciprocal rank. :param predictions: 2d list [batch_size x num_candidate_paragraphs] :param target: 2d list [batch_size x num_candidate_paragraphs] :return: mean reciprocal rank [a float value] """ assert predictions.shape == target.shape as...
34b156fc3a38f23b6ad3ffae589c9afc773ec1ab
691,736
def isIn(obj, objs): """ Checks if the object is in the list of objects safely. """ for o in objs: if o is obj: return True try: if o == obj: return True except Exception: pass return False
0b19e6ac4d2ac2b290b0fe62bfd862c870708eac
691,737
def sem_of_rule(rule): """ Given a grammatical rule, this function returns the semantic part of it. """ return rule[1][1]
9746ad4c83e681f55c1497ea514637c293074b27
691,740
def htk_to_ms(htk_time): """ Convert time in HTK (100 ns) units to 5 ms """ if type(htk_time)==type("string"): htk_time = float(htk_time) return htk_time / 50000.0
5e177e8e5644e4171296826bc62b71f9803889a3
691,741
def find_diff_of_numbers(stat1, stat2): """ Finds the difference between two stats. If there is no difference, returns "unchanged". For ints/floats, returns stat1 - stat2. :param stat1: the first statistical input :type stat1: Union[int, float] :param stat2: the second statistical input :ty...
b316c702e2a5d63a6dad4beac1dd59939a544aca
691,742
def pylong_join(count, digits_ptr='digits', join_type='unsigned long'): """ Generate an unrolled shift-then-or loop over the first 'count' digits. Assumes that they fit into 'join_type'. (((d[2] << n) | d[1]) << n) | d[0] """ return ('(' * (count * 2) + "(%s)" % join_type + ' | '.join( ...
b3cda375fc2fbc922fcb7ecb7a4faa7bc581f7d8
691,745
import hashlib def hexdigest(s): """ Returns the sha256 hexdigest of a string after encoding. """ return hashlib.sha256(s.encode("utf-8")).hexdigest()
b4ded415c5e7bdf970d51c5973ea9b658ef70fe0
691,750
def factor_first_event(match_info, event_list, team_key): """ Creates factor for an event in event_list Arguments: event_list: list of 'Event' objects team_key: string of the event type in the 'Team' object, e.g. 'firstTower' Returns: -1 if no event did not happen yet 0 if red ...
0691915ddc4fd81775068fa6a1fcda341cbedc3d
691,753
import re def str2num(s, tfunc=None): """Extracts numbers in a string. Parameters ---------- s : str The string. tfunc : None, optional formating function. Returns ------- list The number list. """ numstr = re.findall(r'-?\d+\.?\d*e*E?-?\d*', s) if...
aa735e99251ee681fd4eb94d160a5eaac13648e1
691,756
def escape_like(string, escape_char="\\"): """ Escape the string paremeter used in SQL LIKE expressions. :: from sqlalchemy_utils import escape_like query = session.query(User).filter( User.name.ilike(escape_like('John')) ) :param string: a string to escape ...
df8f805e50c5569910ad32b909db9a7db4b25b53
691,757
def create_bus(net, level, name, zone=None): """ Create a bus on a given network :param net: the given network :param level: nominal pressure level of the bus :param name: name of the bus :param zone: zone of the bus (default: None) :return: name of the bus """ try: assert l...
920aab5009c387b53c92dbd8af64a8122abe18b3
691,758
def u2q(u1, u2, warnings=True): """ Convert the linear and quadratic terms of the quadratic limb-darkening parameterization -- called `u_1` and `u_2` in Kipping 2013 or `a` and `b` in Claret et al. 2013 -- and convert them to `q_1` and `q_2` as described in Kipping 2013: http://adsabs.harvard.e...
baa934c792be8e0b72a9ede9a1431f356f9496fa
691,759
def divide(x, y): """Divide 2 numbers""" return (x / y)
a46d9906da6f9c028ea3f3cb1db67c64775d0d07
691,765
def get_indexed_attestation_participants(spec, indexed_att): """ Wrapper around index-attestation to return the list of participant indices, regardless of spec phase. """ return list(indexed_att.attesting_indices)
5b37fe2628ec906879905da2ff9e433ac4bc16d3
691,768
def nths(x, n): """ Given a list of sequences, returns a list of all the Nth elements of all the contained sequences """ return [l[n] for l in x]
d37cf578d9fa7d1bdbabe951574b30ea2bb608eb
691,769