content
stringlengths
39
14.9k
sha1
stringlengths
40
40
id
int64
0
710k
def _core_dist(point, neighbors, dist, n_features): """ Computes the core distance of a point. Core distance is the inverse density of an object. Args: point (int): number of the point in the dataset neighbors (np.ndarray): array of dimensions (n_neighbors, 1): array of all ...
ec3801709b5fbce4107f94cd19f3ccd59c971887
100,198
def subtree_induced_by_subset(tree, s): """ Returns the subtree of tree induced by the nodes containing the set s. Args: tree (NetworkX graph): A junction tree. s (set): Subset of the node in the underlying graph of T. Example: >>> t = jtlib.sample(5) >>> t.nodes No...
51794d12299c832d69262258a1d4f69896fa6e86
100,200
def _get_filter_settings(relay_config, flt): """ Gets the filter options from the relay config or the default option if not specified in the relay config :param relay_config: the relay config for the request :param flt: the filter :return: the options for the filter """ filter_settings = re...
9a8ce92d2b2c8af35b3817ab410ff8c960e9de49
100,201
def nframes(dur, hop_size=3072, win_len=4096) -> float: """ Compute the numbero of frames given a total duration, the hop size and window length. Output unitiy of measure will be the same as the inputs unity of measure (e.g. samples or seconds). N.B. This returns a float! """ return (dur - ...
c59058259c9e2c98b45789848002fc55bb7b4971
100,204
def kwargs_nonempty(**kwargs): """Returns any keyword arguments with non-empty values as a dict.""" return {x: y for x, y in kwargs.items() if y}
25229dfccdd99fec79f8d2c86fe234182b82f1a7
100,210
def read_int(prompt: str, min_value: int = 1, max_value: int = 5) -> int: """Read an integer between a min and max value.""" while True: line = input(prompt) try: value = int(line) if value < min_value: print(f"The minimum value is {min_value}. Try again....
aebadaa743fccf4ffa6eaf0ae78d121562fb3862
100,211
def create_rules(lines): """ Given the list of line rules, create the rules dictionary. """ rules = dict() for line in lines: sline = line.split() rules[sline[0]] = sline[-1] return rules
3ae3555f08fa4aa2cb147172ad4d584025c35133
100,215
from typing import List def _remove_blank_lines_from_list(*, lines: List[str]) -> List[str]: """ Remove blank lines from a list of lines. Parameters ---------- lines : list of str Target list of lines. Returns ------- result_lines : list of str A lines list which remo...
e1fe11c74594f77c70521b75f5534debc6817efd
100,218
import re def cigar_to_max_operation(cigar): """Get the longest cigar operation from this cigar string.""" return max([int(i) for i in re.split(r"[=IDX]+", cigar) if i])
88ef78293d64e513510ca48e86a6fa450215d912
100,221
def validateMCMCKwargs(ap, samplerKwargs, mcmcKwargs, verbose=False): """ Validates emcee.EnsembleSampler parameters/kwargs. Parameters ---------- ap : approxposterior.ApproxPosterior Initialized ApproxPosterior object samplerKwargs : dict dictionary containing parameters in...
e8b8102433343a523def0603d4e69952acf3a244
100,225
def load_protobuf(file, pb_cls): """ Instantiates protobuf object and loads data from file into object. :param file: file containing serialized protobuf contents :param pb_cls: class from generated client :return: instance of pb_cls """ obj = pb_cls() if hasattr(file, "read"): co...
270f9d2dc18305f1255ff2073528d850283768a8
100,229
def check_tiramisu_layers(tiramisu_model=None): """Checks and returns the tiramisu layers on the tiramisu model string. Parameters ---------- tiramisu_model : str or None, optional (default : None) The tiramisu model to be used. Returns ------- tiramisu_layers : str String ...
d84580b8409d7892158cc43a15116c138d4ecc51
100,233
def stemWords(words_list, stemmer): """ Stemming repetitive/similar words Params: list of words (text), stemmer algorithm """ return [stemmer.stem(word) for word in words_list]
cf9195d5f948c034deba178026859ece14fd3ed8
100,234
import torch def _torch_normalize_vectors(rr): """Normalize surface vertices.""" new_rr = rr.clone() size = torch.linalg.norm(rr, axis=1) mask = (size > 0) new_rr[mask] = rr[mask] / size[mask].unsqueeze(-1) return new_rr
fc3746ac16eca52aba00b749240eae419885ab57
100,236
def cleanup_favorite(favorite): """Given a dictionary of a favorite item, return a str.""" return str(favorite["post"])
e0824b655e3f2ab46d27dccd351313eecc39599b
100,237
import torch def bellman(qf, targ_qf, targ_pol, batch, gamma, continuous=True, deterministic=True, sampling=1, reduction='elementwise_mean'): """ Bellman loss. Mean Squared Error of left hand side and right hand side of Bellman Equation. Parameters ---------- qf : SAVfunction targ_qf : SA...
8f57db995c092c9ec81aa321c347439788ab06f3
100,239
def archive_coupling_dict(coupling_dict): """ Turns an enzyme coupling dict of the form: .. code:: python {'AB6PGH': <Enzyme AB6PGH at 0x7f7d1371add8>, 'ABTA': <Enzyme ABTA at 0x7f7d1371ae48>, 'ACALD': <Enzyme ACALD at 0x7f7d1371aeb8>} to: .. code:: python {'AB...
433a7432653ad21d9f538b34e1f36a611499e9a2
100,240
def get_m3(m1, c, gamma): """ Helper: get M3 value from M1, Cv and skewness. """ std = c * m1 var = std**2 return gamma * var * std + 3 * m1 * var + m1**3
c9b4c067b914594f14dd36a2ba2d920f5da02de5
100,242
def avoids(word, forbidden): """ Checks a word for a string of forbidden characters. Return False if any are present, else return True word = word to check forbidden = characters to avoid """ for char in forbidden: if char in word: return False return True
aae79c01b0ba4d61333104f84b62041651028823
100,244
from datetime import datetime def convert_datetime(value): """Convert a date and time to a :class:`~datetime.datetime` object. Parameters ---------- value : :class:`bytes` The datetime value from an SQLite database. Returns ------- :class:`datetime.datetime` The `value` a...
8e76e26e70f61572a48238bbda6f9417d27a01a7
100,247
def is_native(obj, module): """ Determines if obj was defined in module. Returns True if obj was defined in this module. Returns False if obj was not defined in this module. Returns None if we can't figure it out, e.g. if this is a primitive type. """ try: return module.__name__ in ...
6d3a6c9babe0d02c1eb177b6f312d23d0b826848
100,250
def populate_nested_dictionary(dictionary, key_list, types=[]): """ For each key k_i in key_list, make sure that dictionary[k_0][k_1][k_2]...[k_i] exists, creating objects of the appropriate type in each sub-dictionary as needed. If types is specified, then dictionary[key_list[i]] should point to a...
8b531db42db49809e8cb510e5a121a394dc13f17
100,255
def cov_pow(h, w=1.0, r=1.0, s=1.0): """ 1D-power covariance model (with sill=1 and range=1): :param h: (1-dimensional array or float): lag(s) :param w: (float >0): weight (sill) :param r: (float >0): range :param s: (float btw 0 and 2): power :return: (1-dimensional array or flo...
ecc8ac5a3a9de7dfdeb428b21efdfa36a1377b76
100,260
import re def build_regexp_if_needed(maybe_regexp): """ Creates a regexp if the `maybe_regexp` is a str. """ if not isinstance(maybe_regexp, str): return maybe_regexp return re.compile(maybe_regexp)
32b1d1b7547c5d62314b2fca47f8d5a671f3aff5
100,261
def maybe_create_block_in_items_map(im, block): """ create/return the block in an items_map """ try: return im[block] except: im[block] = l = [None] * len(block.items) return l
d7dccaa17301ae9b3f6dc056143b291231b634fa
100,265
def calc_probability(col_dict): """ This function calculates probability of each item in the dictionary For example, {'item1':10,'item2':30} gives prob = {'item1': 0.25, 'item2': 0.75} """ s = sum(col_dict.values()) for key, val in col_dict.items(): col_dict[key] = val / s return co...
680632c54e795e93289af830c1e9f1fba1983f71
100,266
def _get_exist_branches(branch_names, all_branch_names): """Filter out not existing branches from branch names or return all branches.""" if not branch_names: return all_branch_names return set(branch_names).intersection(all_branch_names)
254b3520f3c3cd9dd86791d0cebdaef3d02024af
100,273
def get_time_diff(old_time, new_time): """Returns the difference in time between two rospy times""" time_diff = new_time.to_sec() - old_time.to_sec() return time_diff
d38d1942cfbaa4262fdd1411cfde05b48ea0f576
100,278
import statistics def get_stats(any_list): """ Return basic stats about a list :param any_list: a list :return: mean, median, stdev, variance """ mean = statistics.mean(any_list) median = statistics.median(any_list) stddev = statistics.stdev(any_list) variance = statistics.variance...
901cf529bc3c4e8897d2e615c6bd12af00ce507d
100,280
def toTokenList(x): """ String to list of characters (tokens) """ return list(x)
145e99aeeea170d08911f620128355bd2ba144c6
100,283
def _get_xyz(df, label): """Get xyz coordinates from a pandas data frame. Parameters ---------- df : pandas.DataFrame Data frame with (at least) columns x, y, z, label. label : str Electrode label for which to get x, y, z from `df`. Returns ------- x, y, z : float ...
d83c45fa38b14691d5dd39b8c74bcbd2ade29988
100,284
def url(base_url: str, region: str) -> str: """Returns a regionalized URL based on the default and the given region.""" if region != "us": base_url = base_url.replace("https://", f"https://{region}-") return base_url
9302316d4c980f9ec22f7b2ca343d95d4fcfd3b8
100,285
def find_seperation(arg): """ Helper Function for decompose @param: arg is a string corresponding to two function statement sepereated by a comma Example: "and(and(a,c),b),or(ab,b)" @return: return the index of the comma seperating the functions or -1 if no such comma exist ...
316aa2a4cf4bc2e06f783d02b1a7d895c6615b71
100,287
def _parse_options(options): """Parse search options string into optiond_dict """ if options is None: return {} search_options = { 'insensitive': 'i' in options, 'word_boundaries': 'b' in options, 'recursive': 'r' in options, } return search_options
c0e1083f3b58ac9bad04809c5db4738d1d305f41
100,293
import random import string def generate_rand_name() -> str: """Generate a random name of the form "export_XXXXXX" where XXXXXX are 6 random characters. Returns: str: the generated name """ suf = "".join(random.choices(string.ascii_uppercase + string.digits, k=6)) return f"exporters_{...
3bc205a34a08acb3a520b96d52611f45797df230
100,296
def transform_state(input_state: str, transformation: str): """ A function to track the next position on the Bloch sphere based on the current position and the applied clifford :param input_state: Position on the bloch sphere (one of the six poles) :param transformation: A clifford operation :return...
aecd577a8eb039b0a7baf755f22c3d85148165a7
100,299
def _check_center_ok(centerpos, centersize, pos): """Checks whether pos is far away enough from centerpos""" x, y = False, False if pos[0]-centersize > centerpos[0] or pos[0]+centersize < centerpos[0]: x = True if pos[1]-centersize > centerpos[1] or pos[0]+centersize < centerpos[1]: y = True return ...
f3a966ad4824c921e1a721c328acdb9833d49524
100,300
def get_symmetric_pos_th_nb(neg_th): """Compute the positive return that is symmetric to a negative one. For example, 50% down requires 100% to go up to the initial level.""" return neg_th / (1 - neg_th)
3b9af948d6f405147aa7c156bd81556e7e44b8d9
100,303
import json def create_opaque_data(nonce: str, token: str) -> str: """ :param nonce: Nonce :param token: Token :return: Opaque data for the user """ # The "1" below denotes the version of the data exchanged, right now only version 1 is supported. return '1' + json.dumps({'nonce': nonce, '...
8e239ad31f4776c86f6a14b3760ee8aa83eb23ae
100,304
def norm_aplha(alpha): """ normalise alpha in range (0, 1) :param float alpha: :return float: >>> norm_aplha(0.5) 0.5 >>> norm_aplha(255) 1.0 >>> norm_aplha(-1) 0 """ alpha = alpha / 255. if alpha > 1. else alpha alpha = 0 if alpha < 0. else alpha alpha = 1. if alph...
df3a6bd4133c03f8da2825d9cd5c32cb666b9d4a
100,305
def NoOpDecorator(func): """Mock decorator that passes through any function for testing.""" return func
12efae5b016f296f683e6e7f303568085f930357
100,307
def reconstruct_path(came_from, start, end): """ Reconstructs the came_from dictionary to be a list of tiles we can traverse and draw later. :param came_from: dictionary :param start: Tile :param end: Tile :return: List path """ current = end path = [current] while current !=...
9d654ff65dbb0ffc2e5848b9c26ba7dcd652903b
100,311
def to_joules(ujoules): """ Converts from microjoules to joules """ return ujoules*10**(-6)
44d42c37384ec177d97084eaaf87ac6680eb3c58
100,312
def clamp_image(image, bounds=(0, 1)): """ Clamps the values of an image to be within bounds. """ a, b = bounds return image.clamp(a, b)
28607fb5acac4b0655cd99ab6ea129ed5e27a69f
100,316
def line_intersection(line1, line2): """ finds the intersection point of two straight lines from: https://stackoverflow.com/questions/20677795/how-do-i-compute-the-intersection-point-of-two-lines-in-python by: @paul-draper :param line1: 2 point defining a line :type line1: tuple :param line2...
79936aff9f5884115e2912069da5e653f14fc753
100,319
import math def minutes_to_hours(minutes): """ Converts Minutes into Hours and Minutes """ hours = math.trunc(minutes / 60) mins = minutes % 60 return f"{hours} Hours and {mins} Mins"
c3b79d3efc0d7cdefc6be850b8d41a51169a986d
100,323
def transliterate(trans, item): """Transliterates string, list of strings and list of list of strings""" if isinstance(item, str): return trans.get(item, item) if isinstance(item, list) and len(item) > 0: if isinstance(item[0], str): return [trans.get(i, i) for i in item] ...
0774c95528b984b9be2972221077e21836537a32
100,324
import json def read_input_json(jsonfile): """Read the JSON supplied from the data manager tool Returns a tuple (param_dict,extra_files_path) 'param_dict' is an arbitrary dictionary of parameters input into the tool; 'extra_files_path' is the path to a directory where output files must be put fo...
a4dfb0bba2d2c21ea5de440458d8fbcddd3c15da
100,329
import torch def seq_mask(seq_len, max_len): """Create a mask for the sequences. :param seq_len: list or torch.LongTensor :param max_len: int :return mask: torch.LongTensor """ if isinstance(seq_len, list): seq_len = torch.LongTensor(seq_len) mask = [torch.ge(seq_len, i + 1) for i...
6582cea6dfb9c967ac1430dc676bbec55452411e
100,332
def _is_vcs_file_status_unstaged(file_status): """Returns True if file status is unstage. Staged status is determined by the second position of `file_status.stats` code. See `guild.vcs_util.FileStatus` for details. """ return file_status.status[1] != "_"
95d9cec2d2587fc8c37046598114cdac363df15f
100,333
def toWidthHeight(anchor): """Transforms an anchor in [x0,y0,x1,y1] format to [w,h,x,y] Where [w,h,x,y] stands for width, height, center x coord, center y coordinate """ # Since in an anchor [x0,y0,x1,y1] we are represesnting not corner coordinates but # coordinates of pixels that compose the corner...
ad4953c45bcb85d119a62f09a3fbe503e4426232
100,334
import json def parse_ironic(ironic_file): """Extracts relevant data from each ironic input file """ with open(ironic_file, 'r') as f: try: ironic = json.load(f) except Exception: raise RuntimeError( 'Invalid JSON file: {ironic_data_file}'.format( ...
531b1ad1bd29171007e876d016e5808f39add4fc
100,336
def product(xs): """Return the product of the elements in an iterable.""" accumulator = 1 for x in xs: accumulator *= x return accumulator
22e06452da356797ce5934a28bae5dbe4d249317
100,339
def temp_ftoc(temp_f): """Convert fahrenheit degrees to celsius. Prometheus expects SI units, but some sensors return F. """ return (temp_f - 32.0) * (5.0 / 9.0)
9c2ec79602295f97fb6dc96dd29073dd7cbaa26d
100,342
def text(element): """Get the text of an element as a string.""" text = element.text return text if text is not None else ""
57838244d1f8fd9e389a2cebc7ffc9fb62eda664
100,345
def net_income(financials_df): """Checks if the latest reported Net Income is positive. Explanation of Net Income: https://www.investopedia.com/terms/n/netincome.asp financials_df = Financial Statement of the specified company """ net_income = financials_df.iloc[financials_df.index.get_loc("Net...
bb6563b09339fb485e2db62aec741264e9ff935a
100,351
def min_max(input): """ Returns a tuple of min and max of the input list. Assume input is a non empty numeric list Use only builtin functions from: https://docs.python.org/2/library/functions.html """ return min(input),max(input)
5aaf4dee929e5746b10ce6464dd50f318d6479b7
100,353
import requests def get_rss(url): """ get rss feed from a given url :param url: url to resource containing rss feed :return: text of the response, otherwise None """ try: response = requests.get(url, timeout=1.0).text except (requests.RequestException, ValueError): response...
b14ba03b4959fe5b0e9c9a9ea3cd8097427a48a8
100,358
import re def parse_write_collections(script): """Extract collections intended for writing from migration script""" collections_regex = r'//\s*write\s*([\w-]+)' return re.findall(collections_regex, script)
1ba9c5c74b607428a78c630045611302ab5297fd
100,365
import hashlib def sha1_hash(string): """Return 20-byte sha1 hash of string.""" return hashlib.sha1(string).digest()
8819b8bc68b105a01799a10d0e5cf6fcd0556fcb
100,369
from typing import Iterable def aslist(item): """ Wraps a single value in a list, or just returns the list """ if isinstance(item, list): value = item elif isinstance(item, str): value = [item] elif isinstance(item, Iterable): value = list(item) else: value ...
08c97d20fb9c5644f694c570ef89b63751402e46
100,371
from typing import Optional from typing import Tuple def check_interval_included(element1: dict, element2: dict) -> Optional[Tuple[dict, dict]]: """ Comparison of two entities on start and end positions to find if they are nested Parameters ---------- element1 : dict element2 : dict b...
bc01eefa8969261844956bd73502b061599a2326
100,373
def create_compose(ctx): """ Creates a docker-compose file for this project. """ return ctx.obj['docker'].create_compose( project=ctx.obj['project_name'] )
9678e552a018d3aa54da156808fd8323f551a91d
100,376
def flat_scale_parameters(band): """ Return the flat scaling parameters for a given band. :param band: The band to use, either 'FUV' or 'NUV'. :type band: str :returns: tuple -- A three-element tuple containing the flat scaling parameters. """ if band == 'NUV': flat_corre...
58196a67842b11906d3bd370101d0772ce5d90b7
100,377
import ast def valid_check(code): """Performs a check to ensure that the code provided by the user is syntactically correct. :param code: Source code string block. :type code: str :returns: True is successfully compiled, False otherwise. """ try: node = ast.parse(code) # prin...
b4dad88c1be86eda28cbbc0a7eb60fcaed502f29
100,378
import hashlib import hmac def check_signature(token: str, hash: str, **kwargs) -> bool: """ Generate hexadecimal representation of the HMAC-SHA-256 signature of the data-check-string with the SHA256 hash of the bot's token used as a secret key :param token: :param hash: :param kwargs: al...
cd7e15f916c79623198b75fb44e2d895331d8c16
100,381
def get_response_names(response_count): """Returns a list of response variable names up to the count. Example: >>> get_response_names(3) ["R1", "R2", "R3"] """ return ['R' + str(i+1) for i in range(response_count)]
afbf749caf86ac3e89b9f4f34a1ea0379347d2b7
100,382
def validate_bandskpoints(value, _): """ Validate bandskpoints input port. Checks the kpoints list is set. """ if value: try: value.get_kpoints() except AttributeError: return "bandskpoints requires a list of kpoints, use `set_kpoints`."
1756dad18ea2f98801de05950c34d580c1f22dce
100,391
def checkml(ctx): """A check for the user circles.png. Args: ctx (commands.Context): The context of the command. Returns: bool: True if the user is circles.png. """ return ctx.author.id == 262120465525506049
37df602712902dbdc9bbab906fc949b6c78e49f3
100,392
import torch def normalize_last_dim(tensor, eps=1e-6): """ Normalizes to a mean of 0 and a norm of 1. :param tensor: a ND tensor :param eps: epsilon to add not to divide by 0 :return: the tensor with normalization along last dimension axis. """ tensor = tensor - tensor.mean(-1, keepdim=Tr...
7210e472f864eb5964d19f408922dc95c8918e0e
100,393
def parse_dns_record(record: dict) -> dict: """ Parse the DNS record. Replace the ttl and prio string values with the int values. :param record: the unparsed DNS record dict :return: the parsed dns record dict """ if record.get("ttl", None) is not None: record["ttl"] = int(record["...
f1aa9c66ffe5ddd8b17e4e9a4928a6167a7b386b
100,397
def calc_cigar_bit(cigar_op): """Given a cigar operation integer, return the cigar bit.""" # taken from htslib bam_cigar_type function return 0x3c1a7 >> (cigar_op << 1) & 3
ae42fe88f53cdfd160a0124f228b1bfe2bb82513
100,407
def determine_non_fit_area(shape, basic_shape, max_error=None): """ Determines the area of the part of the basic shape that does not fit the given shape (i.e. what is left after differencing the two shapes, and optionally negative buffering with the max error). Parameters ---------- shape :...
a26e155c890decfa78857814c2822fbba75416e2
100,409
import calendar import time def parse_timestamp(timestamp): """Parse a timestamp of the form "yyyy-mm-ddThh:mm:ssZ". Args: timestamp: the timestamp, as a string Returns: the number of seconds since the UNIX Epoch, as described by the timestamp """ return calendar.timegm(time.strpt...
e26ba6ff2eb119464347c4fadf47525635945efe
100,416
def calc_qv_delta_p_ref(n_delta_p_ref, vol_building): """ Calculate airflow at reference pressure according to 6.3.2 in [2] :param n_delta_p_ref: air changes at reference pressure [1/h] :param vol_building: building_volume [m3] :returns: qv_delta_p_ref : air volume flow rate at reference pressure ...
9f1f06a20c92012ac1ba442fa2511b4752e54d14
100,418
import copy def weak_execute(t, pn, m): """ Execute a transition even if it is not fully enabled Parameters ---------- :param t: transition to execute :param pn: Petri net :param m: marking to use Returns ------- :return: newly reached marking if :param t: is enabled, None ot...
3178d09c139a3cb009712a81bf4de720caac6cdd
100,419
def drop_empty_props(item): """Remove properties with empty strings from nested dicts. """ if isinstance(item, list): return [drop_empty_props(i) for i in item] if isinstance(item, dict): return { k: drop_empty_props(v) for k, v in item.items() if v != '' ...
c427c01dc282b2cf42fa2fa701cdc707142c3088
100,420
def rank(tensor): """get rank attribute or None""" try: result = tensor.__class__.rank except AttributeError: result = None pass return result
be01b1013e325fff45d6db1476af35ddb0ebd9d9
100,422
def get_result(response, ctxlen): """Process results from OpenAI API response. :param response: dict OpenAI API Response :param ctxlen: int Length of context (so we can slice them away and only keep the predictions) :return: continuation_logprobs: np.array Log probab...
2014c3f5d3c92220a56419372d47039ab472967f
100,424
def get_list(data): """ This function generates a list of strings from the date time index in data Parameters ------------------- data = a pandas dataframe This contains a Date Time as index and tidal data OUTPUT ------------------- This function returns a list of strings "...
1ab6d9cdeaa116856a9dcb4b600e3502f52bf903
100,431
def get_dag_args(dags, args): """Given a list of Airflow dags and a list of argument names, return a dictionary dag_ids and their corresponding args dictionaries. If a particular dag argument is not defined directly or via default args, 'None' is returned.""" dags_args = {} for dag in dags: dag_args...
de2d6669c6e60aec13eb4f823848918b3aa8d488
100,432
def in_custom_unit(td, seconds_per_unit, unit_name): """Return a string describing the number of whole 'unit_name' in 'td'. 'seconds_per_unit' is used as the divisor to determine how many whole units are present in 'td'. If the number of units is other than 1, an 's' is appended to the name of the...
090bdb4ac968d5d0a67394b2f843838b62266a48
100,433
def MMD2u_estimator(K, m, n): """ Compute the MMD^2_u unbiased statistic. This is an implementation of an unbiased MMD^2_u estimator: Equation (3) in Gretton et al. Journal of Machine Learning Research 13 (2012) 723-773 :param K: numpy-array the pair-wise kernel matrix :param m: int ...
64f63f3daee1e4aeeba28c1a76ee4d2442a08a81
100,434
def _attrgetter(attr): """ Return a callable object that fetches attr from its operand. Unlike operator.attrgetter, the returned callable supports an extra two arg form for a default. """ def fn(obj, *args): return getattr(obj, attr, *args) return fn
82cb7e663875a9900f73fa8fecd38a41085b163e
100,436
def overwrite(_old, new): """Overwrites the old value with the new value Args: _old: old value to be overwritten new: new value to overwrite Returns: new value """ return new
9968366f8be6039c814455eaa76e4f2fd25ad92a
100,437
from typing import List from typing import Tuple def column_labels_level(column_labels: List[Tuple]) -> int: """Return the level of the column index.""" if len(column_labels) == 0: return 1 else: levels = set(1 if label is None else len(label) for label in column_labels) assert len...
5de26a67d8bfaeb14045acc1183b79dec73aabdb
100,446
def calculate_value(mask, value): """ Calculates value with mask applied. :param mask: mask string :param value: int value :return: int value """ # get binary value as string bin_value = '{0:036b}'.format(value) # replace all values except X for i in range(len(mask)): if ma...
525fc29fc58d97b6687ff598a2e0589600140f01
100,450
def check_arg(name, value, exp_type, exp_range=()): """ Checks a value against an expected type and range. Used for data preprocessign and projections. Keyword Arguments: - name: name of the argument, for error messages - value: value - exp_type: the type that the value should have - ex...
ac4b3c6809fb7bceba6a581c0e1986b0aa6dcfe6
100,451
import pkg_resources def matches_version_range(version, version_range, name=None): """Return whether a version matches a given range. This will compare the version to a range specification, checking if it matches. The range must be in the form of ``name[>=]specifier``. If ``name`` is specified, then...
ae46707e6aaf1ba16fc00208fcaee6d019e81702
100,453
def coord_Array2Im(x_arr, y_arr, origin=1): """ Convert image coordniate to numpy array coordinate """ X_IMAGE, Y_IMAGE = y_arr+origin, x_arr+origin return X_IMAGE, Y_IMAGE
04dc036035b5a5d871653eec9fcf2b4f498a3ebf
100,454
def enum_choices(cls): """ Return a list of the names of the given Enum class members. """ return [choice.name for choice in cls]
2d2d5662b65b8409dc5103f137d5958b0dd20cfb
100,455
def cat_imputer(trfm, col_names): """ Parameters ---------- trfm : Contains the Sklearn's Imputer preprocessing instance col_names : list Contains list of feature/column names. The column names may represent the names of preprocessed attributes. Returns ------- ...
8573c51c93376eb527d80661a902675816ea1e17
100,457
def _func_parallelfraction(f, p, n): """ Model function to calculate the parallel fraction. :param f: Actual parallel fraction parameters values :param p: Numbers of cores used on model data :param n: Problems size used on model data :return: calculated parallel fraction value """ fp =...
3c54174c14f919f9671551a77886fa886ef66e6e
100,461
def get_tensor_children(tensor): """ Get all calculation and data parent tensors (Not read). """ children_list = [] children_list.append(tensor) if tensor.op: for t in tensor.op.outputs: if not 'read:0' in t.name: children_list += get_tensor_children(t) return lis...
5d7bd97e9f1836e0df31a46013727d657d048185
100,464
import hashlib def hash_file(path, hash_type): """create hash string for a file Arguments: path (str) : the path for the file hash_type (str) : the type of the hash Returns: list of byte : the hash bytes """ with open(path, "rb") as f: h = hashlib.new(hash_type) ...
84c6089ccbfb3808121b6822c9a71cdca100f311
100,467
def set_document_cookie_disabled(disabled: bool) -> dict: """ Parameters ---------- disabled: bool Whether document.coookie API should be disabled. **Experimental** """ return { "method": "Emulation.setDocumentCookieDisabled", "params": {"disabled": disabled}, ...
e04f053ac8ea8e7153b0a4f936a8a78100324772
100,468
def decode_to_unicode(data): """Recursively decodes byte strings to unicode""" if isinstance(data, bytes): return data.decode('utf-8') elif isinstance(data, dict): return dict((decode_to_unicode(k), decode_to_unicode(v)) for k, v in data.items()) elif isinstance(data, list): ...
5ba4138248d7ee948bc8a7d5ab371ec42b1bf5e9
100,469
def get_player_material(board): """Counts the number of materials on the current board for each player (A and B). Args: board (pgn board): Current board Returns: [int]: materialPlayerA [int]: materialPlayerB """ # clear board to read out information information = str(bo...
61fe7ffa5856d0a70481a831496cb7e10d215eb2
100,479
def num_leading_line_spaces(istr,start,pound=0): """count the number of leading non-whitespace chars (newline chars are not be counted, as they end a line) if pound, skip any leading '#'""" length = len(istr) if start < 0: start = 0 if length < 1 or length <= start: return 0 posn = st...
92ec78f331d49f6b08f2cdf109dbd8164319d8e5
100,491
def make_node_barrier(node): """Turns a node into a hard barrier.""" node.make_barrier() node.is_hard_barrier = True return node
49a958485091a783e9ca5f898019bfd1c665bcdf
100,495