content
stringlengths
39
14.9k
sha1
stringlengths
40
40
id
int64
0
710k
def is_subsequence(short_list, long_list): """Return true if short_list is a subsequence of long_list.""" if len(short_list) > len(long_list): return False for i, _ in enumerate(long_list): looks_good = True for j, item_from_short_list in enumerate(short_list): if len(l...
67a3b2dd9ae326e2710821f074033582f33d6d7d
90,448
def _model_with_preprocess_fn(model, model_preprocess_fn): """Combines the model with its preprocessing function. Args: model: Callable taking (preprocessed_images, is_training, test_local_stats) and returning logits. model_preprocess_fn: Image pre-processing to be combined with `model`. Returns: ...
4563865ae1656fe5317955dca8f3affa3753a5b1
90,449
def isacn(obj): """isacn(string or int) -> True|False Validate an ACN (Australian Company Number). http://www.asic.gov.au/asic/asic.nsf/byheadline/Australian+Company+Number+(ACN)+Check+Digit Accepts an int, or a string of digits including any leading zeroes. Digits may be optionally separated with...
cbabe4a84113cdc02f85922b0012e97c22b99e9e
90,464
def get_err_prob(Q): """ Returns the probability of a given base call being incorrect, based on quality score """ return(10**(-Q/10))
1c34a3c4d15e683c64d68f81b6f5aa306377c6c4
90,474
def _uniquify_fetches(fetch_mappers): """Uniquifies fetches from a list of fetch_mappers. This is a utility function used by _ListFetchMapper and _DictFetchMapper. It gathers all the unique fetches from a list of mappers and builds a list containing all of them but without duplicates (unique_fetches). It a...
e5cf26c2856d04e51cf9c5c87e0d0047a887290d
90,475
import csv def get_vendor_ids(tools_csv): """ Get vendor and tool info from tools.csv Parameters: tools_csv path to the _data/tools.csv in the fmi-standard.org repository Returns: a dictionary {vendor_id: (tool_id, tool_name)} """ vendors = {} with open(tools_csv, 'r') as...
140401b65b03d0605ad484946f3224c94d18ce4e
90,476
def file2uri(path): """Returns the web file URI for the given file path""" return 'file:///' + path.replace('\\', '/')
69dee786fd76be669087aeb457de62c4b555f8ee
90,478
import torch def get_batch(data_iterator, args): """ Generate a batch func. input schema: data_iterator: data iterator that implements the torch.utils.data.DataLoader interface args: user defined arguments dictionary output schema: dictionary (python dict()): a dictionary that ...
7483d3f4b39d205fbd05cf11310aa2f5d9ae979c
90,479
def install_variables(installer): """ Returns a dictionary of variables for use later in the process (e.g., filling a configuration file). These are combined from all sysconfig files. """ return {}
bd7c926578fea6512929be6f9663dc9a36358f6f
90,482
import math def point_az(x1, x2, y1, y2): """ Determines azimuth between two points (in cartesian coordinates). Parameters ---------- x1 : float point 1 x x2 : float point 2 x y1 : float point 1 y y2 : float point 2 y Returns ------- float ...
6c59def409e8b680ff885201950f596c55e1c31d
90,483
import re def _validifyName_(name): """ Inner method used to clean anime search query :param name: Anime search query :return: Replaces special characters with '-' to comply with Gogoanime's URL specifications """ # Replace all special characters and get a normalized name where only - is be...
1243bc44515f1548d61a031c41384a26a374ae8c
90,485
def _genauth(sinfo): """ Return authentication parameters for stream, if present. """ user = sinfo['aaf_username'] if 'aaf_username' in sinfo else None password = sinfo['aaf_password'] if 'aaf_password' in sinfo else None if user and password: return { 'auth': (user, password) } else: return {}
d71258e15d57333feab1e6d8b597dfcb49735ab8
90,487
import itertools def _get_common_blocks(dp_block_sizes, dp_ids): """Return all pairs of non-empty blocks across dataproviders. :returns dict mapping block identifier to a list of all combinations of data provider pairs containing this block. block_id -> List(pairs of dp ids) ...
027ac3625e21ab70de8bd656ed2e625236c12fbb
90,488
def candidate_board_uncertain_cells_heuristic(node): """ Taking in a GameTreeNode, return the number of uncertain cells. """ return len(node.board.getUncertainCells())
05635af6f904796900ff5a915bab101bb9268fd5
90,489
def overrides(interface_class): """Decorator that ensures overriden methods are valid. Args: interface_class: the respective super class Example:: class ConcreteImplementer(MySuperInterface): @overrides(MySuperInterface) def my_method(self): ...
a7f53b50ce8b1741ff5ce1cc3dd021c9c5fb3a0a
90,490
import importlib def import_or_none(library): """Attempts to import the requested library. Args: library (str): the name of the library Returns: the library if it is installed, else None """ try: return importlib.import_module(library) except ImportError: return None
454d8fd71888c98d80f898ff426d86392446b499
90,492
def multivalued_cell_join(params): """Join lists into single strings with a separator. Expects a ``dict`` as loaded from OpenRefine JSON script. Args: parameters['description'] (str): Human-readable description parameters['columnName'] (str): Column to edit parameters['separator'] ...
89408a3edd521a3ad73565184ebd90b07653d956
90,494
def speaker_twitters(talk): """ Return a list of the speakers' twitter handles of the talk.""" return [u'@{}'.format(speaker.user.attendeeprofile.p3_profile.twitter) for speaker in talk.get_all_speakers()]
51af75caa5c82953ac8d5a7a9e1f723f646efa52
90,499
def parse_time(time): """Given the time string, parse and turn into normalised minute count""" if type(time) in [int,float]: return time if time.endswith('m'): time = time[0:-1] if time.find('h') != -1: time = time.replace('h', ':') if time.find(':') != -1: hours,...
b4effe0eb9b93a761e9f6f83f7d7d9b60bb8d978
90,502
import json def load_json(filepath: str): """ Load JSON file Parameters --- filepath (str) File path for JSON """ try: with open(filepath) as file: return json.load(file) except FileNotFoundError: print("Warning: File %s was not found..." % filepath...
5c8d75c68bf9da747f01231d68fa4541a9c353ab
90,511
import torch def get_device(gpu = -1): """Get a device, among those available, on which to compute. Args: $gpu$ (`int`): The gpu to use. Set to -1 to use the last GPU found when GPUs are present; set this to -2 to override using a found GPU and instead use the (first) CPU. Defa- ult: ...
02a583b8e8a7d4795e8855e8322370e992389a0e
90,518
from functools import reduce from math import sqrt def factors(n): """ Finds all factors for a given number. Copied from https://stackoverflow.com/a/19578818 :param n: some integer :return: set with all factors of n """ step = 2 if n % 2 else 1 return set( reduce( ...
2107f9e51ed20edcd7051fe99dd802a783aef4cf
90,519
import types def namespace_wrapper(map): """ Convert a dict to a SimpleNamespace. If you feed in {'key':'val'}, you'll get out an object such that o.key is 'val'. (It's legal to feed in dict keys like 'x.y-z', but the result will have to be read using getattr().) """ return types.SimpleNam...
cc5c5c2df3000b00cda416da788071b7c4579a3d
90,520
def compute_readout(params): """ Computes readout time from epi params (see `eddy documentation <http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/EDDY/Faq#How_do_I_know_what_to_put_into_my_--acqp_file.3F>`_). .. warning:: ``params['echospacing']`` should be in *sec* units. """ epi_factor = 1.0 acc_f...
d293ae09803386c34033e7f4d19d6c306f8eb068
90,521
from typing import Callable def _apply_to_inputs(func_to_apply: Callable, *dec_args, **dec_kwargs) -> Callable: """ Decorator function to apply a function to all inputs of a function. Args: func_to_apply: the function to apply to the inputs *dec_args: positional arguments for the function...
3b696ab41d67d2371581b4a1a6ebdddbff5d5eaa
90,528
def get_col_names(name): """ We store results for each simulation in indexed files. Every simulation will indicate its results with a path and an idx property. Returns the pair of column names for the given type of results. Eg: "spikes" -> ("spikes_path", "spikes_idx") """ return f'{name}_pa...
8ed302987f4ff686d61fc19f408a35a7aeff7547
90,531
def add_previous_traffic(index, incidents): """Adds traffic level for the preceeding hour to the incident""" incidents[index]['previous_traffic'] = [incident['traffic_level'] for incident in reversed(incidents[index-6:index])] return incidents[index]
772da2b2c76f7162ab365e0f0298d1204e1170e3
90,532
import math def distance(v1, v2): """ Distance between two vectors """ # print("vectors are: ", v1, v2) return math.sqrt(math.pow(v1['x']-v2['x'], 2) + math.pow(v1['y']-v2['y'], 2))
5460c5dabe734ed122d531d8bf7d6d843c46aeb2
90,533
import math def deg2rad(degree): """ :param degree: angle in degree :return: angle in radians """ return degree * math.pi / 180.0
2a9214255d3bd9c773a60695a99efc4163f0b252
90,536
def normalized_distribution(distribution): """Returns a normalized distribution with the individual values adding up to 1. Can also be used to convert counts to a distribution.""" if distribution is None: return None distribution_sum = sum(distribution) if distribution_sum == 0: ret...
af28b1072b7a0dcd160a684f9440af65b2179cfe
90,537
import torch def Log(x): """ Log trick for numerical stability """ lt = torch.log(1+torch.exp(-torch.abs(x))) + torch.max(x, torch.tensor([0.]).cuda()) return lt
4529f8904574ad216390fd6a2765f2f1557457ce
90,539
def get_queue_function_name(queue_name): """ Returns the function name of a queue which is not the queue name for namespacing and collision reasons. Args: queue_name: The name of a queue. Returns: The string representing the function name. """ # Remove '-' because that character is not valid for a ...
2eeda155eed194a54739f9a7c5de8f3e71a6e28e
90,541
def getIndexDict(idx, labels, shape): """ Get the index tuple of an index in given shape, with the labels. Parameters ---------- idx : int The index that will be decomposed. labels : list of str The labels corresponding to each dimension. shape : tuple of int The sha...
90333ca668d43774375f3359e6b8628af05b93b0
90,542
def samps2time(samps,delta): """ convert a number of samples to time given the sampling interval. """ return samps * delta
4b5dba79c9c5b61c26e27fb59d8fde3c8ce6cae7
90,544
def read_config_file(path, comment='#'): """Read the lines from a file, skipping empty and commented lines. Don't process comments if 'comment' is falsy. """ with open(path) as file: return [ line for line in (line.rstrip() for line in file) if line and not (comment and ...
424794ec95f63a484836ffcbeec03d2183c702cf
90,547
def _mobius_to_interval(M): """Convert a Mobius transform to an open interval.""" a, b, c, d = M s, t = a/c, b/d return (s, t) if s <= t else (t, s)
60933f5e301077f2307f2a2a00284d078e31d802
90,552
def clan_url(clan_tag): """Return clan URL on CR-API.""" return 'http://cr-api.com/clan/{}'.format(clan_tag)
f2c05b8ecf71771e259874bd78d862356dc2b902
90,554
import re def format_pars_listing(pars): """Returns a formated list of pars. Args: pars (list): A list of PAR objects. Returns: The formated list as string """ out = "" i = 1 for p in pars: # Shorten to 30 chars max, remove linebreaks name = re.sub(r'[\n\...
bce22fbe677389a68d13234e99401fa167fb73cc
90,557
def _is_in_group(user, group_names): """ Returns True if a given user is a member of one or more groups. :param user: The User object :type user: django.User :param group_names: A list of group names :type group_names: list[str] :return: Returns True if the user is in at least one of the na...
1cfd7be46b04b9692785227e9893a3e1ce95e33f
90,565
import random def mutate_guess_i(old_guess, i): """randomly mutate single element in string""" ls_old_guess = list(old_guess) rand_value = str(random.randint(0, 9)) ls_old_guess[i] = rand_value return ''.join(ls_old_guess)
9116f87d9f9a85017fafffe55a5ae640cce13eb7
90,567
def _endpoint_from_image_ref(image_href): """Return the image_ref and guessed endpoint from an image url. :param image_href: href of an image :returns: a tuple of the form (image_id, endpoint_url) """ parts = image_href.split('/') image_id = parts[-1] # the endpoint is everything in the url...
626484976a35b89ecaf5b363503ac993ee231613
90,570
def _t(s): """A dummy translator that can be used for message extraction without actually doing the translation.""" return s
a2161e2e296e121f663d4588ad5bbdbd1adb6df4
90,571
import math def downsample(data, factor, reduce): """This function is used to downsample data in blocks of size `factor`. This function downsamples blocks of size `factor` using the function specified in reduce. If there are insufficient points to fill a final block, this last block is discarded. Pa...
91df0c778e5296b334e5e66f816d42276a3a983d
90,573
def merge_unique_lists(a, b): """ Merges two lists which are actually sets, returning a sorted result list. """ return sorted(list(set(a) | set(b)))
7249b237198e88534a56a00a79dabd8bbe849afd
90,575
def _literal_distance(fuzzy_clause, fuzzy_value, cf_value): """Distance between two fuzzy sets of a fuzzy variable""" skip = abs(list(fuzzy_clause).index(fuzzy_value) - list(fuzzy_clause).index(cf_value)) distance = skip / (len(fuzzy_clause) - 1) return distance
35d0fe84fa029c11013b082eca9331ab192c5cb0
90,577
def collision_rect_point(rect, p): """True if point p is inside rectangle rect.""" x, y = p if x <= rect.x_min: return False if x >= rect.x_max: return False if y <= rect.y_min: return False if y >= rect.y_max: return False return True
498bc68583bf304201998a35cd2cc6628664b89d
90,579
def in_namespace(uri, base_uri): """ Check if given URI is in the "namespace" of the given base URI """ if any(( base_uri.endswith("#"), base_uri.endswith("/") )): # We chop off last character of base uri as that typically can include a # backslash (/) or a fragment ...
6f6250ac0c7b8b7ffdb22601ed166ea5d12cf175
90,582
from datetime import datetime from dateutil import tz def utc_to_local(utc_dt: datetime) -> datetime: """Convert input UTC timestamp to local timezone. Args: utc_dt: Input UTC timestamp. Returns: A ``datetime`` with the local timezone. """ local_dt = utc_dt.astimezone(tz.tzlocal(...
f4bcf9c77cbca63ec1bc7b7f096456ba6d588777
90,583
import inspect def _is_command(obj, cli): """Is this a valid command function? Args: obj (object): candidate cli (module): module to which function should belong Returns: bool: True if obj is a valid command """ if not inspect.isfunction(obj) or obj.__name__.startswith('_...
202d417eec794ad2b9cc3f04f54187e4e7ff0f75
90,584
def get_all_vertices_of_edges_connected_to_vertex(mesh, vertex_u): """ Get all the vertices of edges which are connected to vertex u, exclude u itself. Another output is the edges themselves. """ v_e_u = [] e_u = mesh.ve[vertex_u].copy() # edges connected to vertex u for e in e_u: ...
3ebe5ab2e9fbd7b28f2747c7d32ceffcca38d48c
90,590
def split_course_key(key): """Split an OpenEdX course key by organization, course and course run codes. We first try splitting the key as a version 1 key (course-v1:org+course+run) and fallback the old version (org/course/run). """ if key.startswith("course-v1:"): organization, course, run ...
e22135600d332f3bf183fe234e3383abf82ac466
90,594
def valid_tile_size(value, arg_name, min_power=4, logger=None): """ Verifies that the tile size is defined as an integer in [16, 32, 64, 128, 256, 512, 1024, 2048, 4096]. :param value: int, tile size :param arg_name: str, parameter name :param min_power: int, 2^min_power as minimum tile size (...
b3d00946d6ff21df370e42c58e0405a9fd55dd10
90,596
def default_value(feature): """Decides a default value for the given feature, to replace missing or null values. Parameters ---------- feature (str): Name of feature. Returns ---------- (int or bool): Default value for given feature. """ if feature == 'rqst_timespan': ...
acdd3b15d01507fb592da8e6dd4d9ae942f7b91e
90,597
def decorator_without_argument(func_to_decorate): """ Function decorator without argument :param func_to_decorate: function to decorate :return: function decorated """ def inner_function(*original_args, **original_kwargs): print("Enter decorator") # Something before respo...
b785347878d4771d7c9581e5e8d8a5fabbdb9c5b
90,608
def size_of_ins(statement): """Returns the size (in words) of the instruction.""" # Note: the LC-3 is word-addressable, not byte-addressable, so a two-byte # instruction has a size of 1, not 2. # There is a variant called the LC-3b which is byte-addressable. if statement.statement_type == 'INSTRUCTI...
eefb0a95a76ff4c48b85f799696a497d03362020
90,609
def get_oncall_email(client, service: dict) -> str: """Fetches the oncall's email for a given service.""" escalation_policy_id = service["escalation_policy"]["id"] escalation_policy = client.rget(f"/escalation_policies/{escalation_policy_id}") schedule_id = escalation_policy["escalation_rules"][0]["targ...
7c7d0f8ff6a86662394cd176e816ba2a28facfcf
90,611
def statement_text_padded(statement): """ Return the statement text padded with leading whitespace so that coordinates in the ast match up with coordinates in the text. """ return ( ("\n" * statement._start_row) + (" " * statement._start_col) + statement._text )
a8a1f2fa1c3a96e5e10be0a571534d2b4647eaa2
90,613
import torch def autoencoder_loss(x_output, y_target): """ autoencoder_loss This implementation is equivalent to the following: torch.nn.BCELoss(reduction='sum') / batch_size As our matrix is too sparse, first we will take a sum over the features and then do the mean over the batch. WARNING: T...
0c3306fc8f83d42a1f541ec689aad5e41fa2d27f
90,614
import hashlib def to_hash(string): """ Hash a string, in this case a url. :param str: a str containing an url :return str: a sha256 hashed string """ hash_object = hashlib.sha256(bytes(string.encode("utf-8"))) return hash_object.hexdigest()
a4ac2929aa7ab218f85a7d0c62204570d2ff2253
90,615
def _flatten(lst): """ Flatten a nested list. """ if not isinstance(lst, (list, tuple)): return [lst] result = [] for item in lst: result.extend(_flatten(item)) return result
2f5b2c95b9f6d23cb58de2d8a91b325983963d6b
90,620
def build_bbox_str_list(bbox): """Build bounding box string representation from ``bbox`` :param bbox: dictionary with keys: ``left``, ``top``, ``right``, ``bottom`` :type bbox: dict :return: bounding box string list [left, top, width, height] :rtype: string """ width = bbox['right'] - bbox['left'] heig...
91dc4b97ab20de73b01371eb3ddacd3971948289
90,621
def nop(token): """Create a dummy function for tests.""" return token
a4f7e14d37ba14b1e0a316fe61abad9b1894cb2b
90,624
def parse_partition(partition): """Parses one parttiion tuple consisting of size and mount point. """ partition_data = partition.split(":") if len(partition_data) != 2: raise ValueError("Partitions line parts format is 'size:mount'") return partition_data
09ef01c56d3002552e29d1812cab1ff798beeb0f
90,626
from datetime import datetime def get_assignments_due(canvas_obj, course_id, date, include_no_date=False): """ Returns a list of assignments due past the specified date. """ # Create course object with given id course = canvas_obj.get_course(course_id) # Create list of assignments within the course ...
90571bc4784a8580cad64d1065a1bcfe123bba66
90,628
def restrict(d, languages=['en', 'de']): """Restrict a dictionary with the labels or aliases to the specified languages only""" # lang = ['en', 'de', 'zh', 'hi', 'es', 'fr', 'ar', 'bn', 'ru', 'pt', 'id'] return dict((k, v) for (k, v) in d.items() if k in languages)
04338004f062d1eaa9e26eb73c5b959a83cf2dda
90,629
import requests def get_file_size(url, params, timeout=10): """Get file size from a given URL in bytes. Args: url: str. URL string. timeout: int, optional. Timeout in seconds. Returns: int. File size in bytes. #### Examples ```python get_file_size(url) ## 178904 ``` """ ...
642e733a1385423f0f8a894e8e3bfb96ea15dda4
90,630
def none_provider(_request, _feature_flag_name): """Return None for any given feature flag name.""" return None
4446453832073a6be5fad4dea361fb1ef2c47b92
90,637
def get_max_subarray_sum(nums_array: list) -> int: """ Algorithm for getting the maximum sum of a subarray (Kadane's Algorithm) Complexity --> O(N) :param nums_array: list :return sum: int """ global_sum = local_sum = nums_array[0] for i in range(1, len(nums_array)): if local_s...
5ff5e26836c3014c8916057cb4890a70bafb986a
90,638
def to_solution(parameters, columns): """Convert a solution given as a list pairs of column indices and values to a solution given as a list of pairs of columns and values.""" return [(parameters.columns[column_id], value) for column_id, value in columns]
e8565a1e956b3dac0e8d2e555253fa9f744e10db
90,640
def primes2booleannet(primes, header=""): """Convert a pyboolnet primes dictionary to a BooleanNet string reperesentation. Parameters ---------- primes : pyboolnet primes dictionary Update rules to convert. header : str Text to include at the beginning of the file, e.g., comment lin...
f2d10599d8386e9ed330129cad753e0ee0f52409
90,644
def boost_npa(group, npa): """ Return a fraction of boost based on total number of peptides per IAR. :param pandas.core.frame.DataFrame group: The IAR under review. :param float npa: The total boost amount allotted to this criterion. :returns: The percent of boost provided by this criterion. :r...
3843b027219f810a99a3ce2f8117eddae3f25400
90,645
def train_test_validation(closed_data, train_frac=0.8): """ 8:1:1 train, text ,validation split """ train = closed_data.sample(frac=train_frac) remain = closed_data.drop(train.index) test = remain.sample(frac=0.5) validation = remain.drop(test.index) return train, test, validation
6aadd302f5f77b6b9c78e22f9f9b9b42061b145b
90,649
def get_starttime(event): """Delegate for sorting Calendar entries by event_start time""" return event["DTSTART"].dt
f4bf84311ea272eaf4697b07cb4f25e7b6e30921
90,654
def screen(row, col, maxwell, **kwargs): """ Create a screen with global parameters Parameters ---------- row : string Parameter encoded by the row letter col : string Parameter encoded by the column number maxwell : string Name of the well in the bottom-right corner...
4b6c3ff505c76740fe236ec48913695fd220371d
90,655
from pathlib import Path def true_stem(path: Path) -> str: """True stem of a path, without all suffixes, not just last.""" return path.name[: -(len("".join(path.suffixes)))]
efc6916c81e41b82bdc1da82941f04ba7747f2a2
90,657
def power_solar(solar_irradiation, conductor): """Section 3.3, Eq 8, page 18.""" return conductor.absortivity * solar_irradiation * conductor.diameter
66f2c86a865b2221a20ef21d551004230fff40f9
90,658
def add_source_names(source_ids, names): """Add names of sources to list of source IDs turning the list into a list of tuples. """ return sorted([(s_id, names.get(int(s_id))) for s_id in set(source_ids)])
edea016623676f498f5cca8ccf7df9ee321590bc
90,662
import pathlib import json def load_json_config(json_config_file: pathlib.Path): """ Loads configuration info from a JSON file. :param json_config_file The JSON configuration file path. :return The configuration info values. """ with open(json_config_file, mode="r") as config: return ...
49c5c90bbbf75098d27154a511aa0cd7fe8c1958
90,664
import torch def compute_edge_feats_dict(edge_ixs, det_df, fps, use_cuda): """ Computes a dictionary of edge features among pairs of detections Args: edge_ixs: Edges tensor with shape (2, num_edges) det_df: processed detections datafrmae fps: fps for the given sequence use_...
37d7b4c1ba144260747de0aa677314649bb2906a
90,668
from typing import Dict def group_production(production: Dict[str, int]) -> Dict[str, int]: """Group various types of coal (e.g. lignite, hard coal) and hydro (river, reservoir). Args: production (Dict[str, int]): Dictionary with production for each resource type. Returns: Dict[str, int]...
8605b7bee8d3be1cd2644df447b215a533cfa458
90,671
def color_spot(htmlcolorcode, text=None): """ HTML snippet: span with class 'colorspot' and `htmlcolorcode` as background color """ if text is None: text = htmlcolorcode return u'<span class="colorspot" style="background-color:%s;">&nbsp;&nbsp;&nbsp;</span>&nbsp;%s' % (htmlcolorcode, tex...
be0368fe5a0fad42a84cdbfa46615e71405af785
90,672
def _normalize_deviation_args(lower, upper, msg): """Normalize deviation acceptance arguments to support both "tolerance" and "lower, upper" signatures. This helper function is intended for internal use. """ if isinstance(upper, str) and msg is None: upper, msg = None, msg # Shift values if...
3bd35a9bb12ac30745da165cf085502d021a6083
90,678
def quizzable(obj): """Return if obj is quizzable.""" attrs = ('__question__', '__options__', '__check__', '__score__', '__passing__', '__total__') return [hasattr(obj, attr) for attr in attrs]
1e5b70f650aaaba17cc04add3cb850e7fdd87aeb
90,680
def is_pixel_inside(dim, coord): """ Check if the pixel coordinate is inside the image """ if (len(dim)<2) or (len(coord)<2): raise Exception("Dimensions should be >= 2! Check!") if (0<=coord[0]<=dim[0]) and (0<=coord[1]<=dim[1]): return True else: return False
337de0143a35f06a0e86019901cb9a670b4b074d
90,682
def calc_gamma_ref_via_menq_2003(c_u, p_eff, p_atm=101.0e3): """ Calculate the reference strain for a modulus reduction curve from Menq :param c_u: float Uniformity coefficient (Grain size ratio d_60 / d_10) :param p_eff: :return: """ big_a_gamma = 0.12 * c_u ** -0.6 n_gamma = 0...
5ed98e372cf8ebc81721ea4edbb6323f8512efe2
90,687
def _flag_awakenings(hypno, thresh): """ Mark awakenings as Long or Short depending on threshold in minutes Parameters ---------- hypno : pd.DataFrame Hypnogram dataframe obtained through _read_hypno(). thresh : int or float, positive non-zero Minimum duration in minutes for awa...
a270665b50140117c0651b3bf3d8bbbb18725c00
90,691
def validate_lag(Tplot, chrono): """Return T_lag: - equal to Tplot with fallback: HMM.t.Tplot. - no longer than HMM.t.T. Also return corresponding K_lag, a_lag.""" # Defaults if Tplot is None: Tplot = chrono.Tplot # Rename T_lag = Tplot assert T_lag >= 0 # Validate t2 = chrono.tt[-1] ...
f82ddd0015955ea05d769ab304fd9c8ba54efddc
90,696
def to_bool(val): """Take a string representation of true or false and convert it to a boolean value. Returns a boolean value or None, if no corresponding boolean value exists. """ bool_states = {'true': True, 'false': False, '0': False, '1': True} if not val: return None if isinstanc...
5610248e459ad7f736028fa6093d1639c6dd6c23
90,712
def drop_internal_nodes(network): """ Given a network from `build_monodirectional_network`, drop nodes that are "internal" to a segment. Nodes are internal if their edges only connect it with a single segment. Doesn't drop nodes that are dead_ends. Drops the nodes in place and returns a list of the...
1ccaecb1b90f7a3e412490233320736306d4d290
90,716
def prime_factors(number): """ Finds the prime factors of a number :param number: Integer number to find prime factors for :return: list of primes factors for the given number :rtype: list An example >>> prime_factors(13195) [5, 7, 13, 29] """ c, res = 2, [] while c * c <= n...
100c1efa28e1a64777ad0e6abd98501896b54433
90,724
def divide(value, arg): """ Divides the value by the arg :param value: :param arg: :return: """ if value: return value / arg else: return None
fc65871afd03facf949a260782bbf4b376ea77ff
90,729
from typing import List from typing import Tuple def _calculate_gamma_and_epsilon(zero_counts: List[int], one_counts: List[int]) -> Tuple[int, int]: """Calculates the gamma and epsilon rate based on the one and zero counts the returns them. Args: zero_counts (List[int]): the number of 0 digits across...
a4a1086aac97b1ad59b4e945553a4d5b66426b30
90,730
import re def clean(filepath: str) -> str: """Clean up the content of a subtitle file (vtt) to a string Args: filepath (str): path to vtt file Returns: str: clean content """ # read file content with open(filepath, "r", encoding="utf-8") as fp: content = fp.read() ...
614ec11ff35d4dcc3249bf87273fb363a4d79b32
90,731
import requests def image_exists_on_dockerhub(image_name: str, image_tag: str) -> bool: """ Given an image name and image_tag, check if it is publicly-accessible on DockerHub. Based on the code from this blog post: * htttps://ops.tips/blog/inspecting-docker-image-without-pull/ :param image_n...
989214d56a2a4635759c1bc6fc821e63a2e28718
90,734
def cut_suffix(name, suffix): """Cuts off the *suffix* from *name* string, if it ends with it :param name: original name from which suffix will be cut off :type name: string :param suffix: string to be removed :return: string without suffix """ if isinstance(name, str) and name.endswith(suf...
6c55b265a7b31fc97598ecaa6d7aa6e51d13440b
90,736
import re def valid_org(s): """Is this a valid GitHub org?""" return isinstance(s, str) and re.match(r"^[^/]+$", s)
fe61ba0eb07df0bf2a19556ac1e4ed8e88121e1c
90,738
def frequency_to_probability(frequency_map, decorator=lambda f: f): """Transform a ``frequency_map`` into a map of probability using the sum of all frequencies as the total. Example: >>> frequency_to_probability({'a': 2, 'b': 2}) {'a': 0.5, 'b': 0.5} Args: frequency_map (dict): The...
dcc07f4e6aebd08c6ff84ff0bec95141eb1aa0a5
90,744
def square_meter2ha(value): """Convert m2 to ha.""" return value / 10000
c84e6971b8be7e086ebbb5327f5d962646bc2ae4
90,745
def develop_filename(args, today): """ Figues out whether to use a supplied filename or a date stamped entry """ if args.outfile is not None: return args.outfile return 'utlization-summary-{}.csv'.format(today.strftime("%Y-%m-%d"))
5469a51b369c4c8151b46057fa1c8ae15a251009
90,748
def load_split_indices(file_path, fold_index=0): """ Args: file_path: path to split indices file fold_index: index of the fold whose train and test indices you want Returns: train_index: list of integer indices for train data test_index: list of integer indices for test data...
ab2b850ab385ef1b4c2c9e4636a5d4c2d8910521
90,755