content
stringlengths
39
9.28k
sha1
stringlengths
40
40
id
int64
8
710k
def sum_of_squares(x, y, fn): """ Calculates error between training set and our approximation Residential sum of squares: sum(|f(x) - y|^2) for all (x,y) in out training set :return: float which represents error """ return sum([(i - j) ** 2 for i, j in zip(map(fn, x), y)])
99be28ba69a5abb99617221279b561c6a6d5df35
310,555
def _convert_None_to_str(value): """ returns input value or 'None' string value if input is None The DictParser representation of a pygeometa MCF can't handle an actual value of: None. All dict keys must be strings. >>> _convert_None_to_str('foo') 'foo' >>> _convert_None_to_str('None') ...
52408d30d9e2ba4de184289647b5991dc7032c21
463,066
def swap_element(sequence, idx, replacement): """ Returns a copy of the sequence with the ith value swapped with the replacement value. Useful for immutable values such as strings. :param sequence: the original immutable sequence. :param idx: the index of the sequence element to swap (use negative ...
63b89eddb23ad748e820a0e314aeea29395b967c
408,547
def correlation_matrix(data): """Calculates the correlation matrix of a dataframe and orders by degree of correlation. Args: data (pandas dataframe): The data object. Returns: pandas series: The correlation matrix sorted with highest\ correlation on the top.""" data = data....
8d19cf7de1e7cb028e47dc6563b99a10fe7e7586
537,734
def squared_loss(x1: float, x2: float): """Returns the squared difference between two numbers""" return (x1 - x2) ** 2
dcec9a0632e9b3c70aec0d6e1610286b8b6923cc
230,696
def _estimate_fgbio_defaults(avg_coverage): """Provide fgbio defaults based on input sequence depth and coverage. For higher depth/duplication we want to use `--min-reads` to allow consensus calling in the duplicates: https://fulcrumgenomics.github.io/fgbio/tools/latest/CallMolecularConsensusReads.htm...
c5d4e93c41e00f66d35935035a157054e66d69c9
54,400
def check_for_ticket_quantity_error(quantity): """ Returns any error message if the ticket's quantity is not between 1 and 100 else if there is no errors it returns false. :param quantity: the ticket's quantity as a string :return: false if no error, else returns the error as a string message "...
80001bbcaffe8193eaa158219f1747b18c4110a5
84,670
def get_year_month_day(node): """ Retorna os valores respectivos dos elementos "year", "month", "day". Parameters ---------- node : lxml.etree.Element Elemento do tipo _date_, que tem os elementos "year", "month", "day". Returns ------- tuple of strings ("YYYY", "MM", "...
f16fcc8b54984c7f26b2ce3f37da0353d2e7542e
563,180
from typing import Sequence from typing import Tuple def get_default_powerup_distribution() -> Sequence[Tuple[str, int]]: """Standard set of powerups.""" return (('triple_bombs', 3), ('ice_bombs', 3), ('punch', 3), ('impact_bombs', 3), ('land_mines', 2), ('sticky_bombs', 3), ('shield',...
1e125dfe64627b25e56e9f905d4fc8cc1a878684
35,863
def addHtmlBreaks(s, isXhtml=True): """Replace all returns by <br/> or <br>.""" tag = {True:'<br/>\n', False:'<br>\n'}[isXhtml] return s.replace('\n',tag)
dc4fb9d39fc7a2fba8d8c795c3c8394630358425
656,849
def is_empty(module, container_name, facts): """ Check if container can be removed safely. To be removed, a container shall not have any container or device attached to it. Current function parses facts to see if a device or a container is attached. If not, we can remove container Parameters ...
e91eb5dfa36c14d701082d0831d6be5147d88179
629,239
import copy import itertools def merge_cropobject_lists(*cropobject_lists): """Combines the CropObject lists into one. This just means shifting the `objid`s (and thus inlinks and outlinks). It is assumed the lists pertain to the same image. Uses deepcopy to avoid exposing the original lists to mo...
7c92fd345d932746460034dcbf8fad4325933a0d
335,188
import re def get_rna_filtered_reads(wildcards, config): """ get the clean reads for a sample then insert requested sequence type name into fastsq file name eg: turn sample.clean.fastq -> sample.clean.SSU.fastq """ cleaned_reads = config["sample_data"][wildcards.sample]["clean"] rrna_subs...
f70fe6282f1cc47ec90708fe5cd665dd41413305
236,532
def insertion_sort(array): """ Insertion Sort Complexity: O(N^2) """ array_len = len(array) for k in range(array_len): temp = array[k] i = k while i > 0 and temp < array[i-1]: array[i] = array[i-1] i -= 1 array[i] = temp return array
09a9e5be73e23f42ee04129f979516e9e556a908
664,724
def sqrt(number): """ Calculate the floored square root of a number Args: number(int): Number to find the floored squared root Returns: int: Floored Square Root """ if number < 0 or number is None: return None elif number == 0: return 0 elif number == 1: ...
d4235023cfbc56aa59d3709a3039914b1e808fb7
69,533
def format_duration(dur_ms): """Return a time string representing the duration in human readable format.""" if not dur_ms: return "0ms" ms = dur_ms % 1000 dur_ms = (dur_ms - ms) / 1000 secs = dur_ms % 60 dur_ms = (dur_ms - secs) / 60 mins = dur_ms % 60 hrs = (dur_ms - mins) / 60 out = "" if hr...
f552b52058ba104517d3082fe19839afb137ebe2
136,242
def parse_count(cell_value): """ Parse Halias data cell value to integer. """ if cell_value.startswith('"') and cell_value.endswith('"'): cell_value = cell_value[1:-1] if len(cell_value) > 0: cell_value = int(cell_value) else: cell_value = None return cell_value
ad4a3062d06c8c81141ba28a5a9db497b2e65a0e
313,611
def bokeh_barbs(mpl_barb): """Convert matplotlib.quiver.Barbs to bokeh multiline/patches data""" xo, yo = mpl_barb.get_offsets().T paths = mpl_barb.get_paths() xs, ys = [], [] for path in paths: x, y = path.vertices.T xs.append(x) ys.append(y) return xo, yo, xs, ys
d5599adc187a8e47ae270c6d7e8afed0af7676b2
411,490
def decrypt(sk, c): """Decrypt a cyphertext based on the provided key.""" return (c % sk) % 2
d3a96f66e1b449ffbd5b6ca1ba0827455b83f9e2
701,346
def interval_to_col_name(interval): """ Queries the proper name of the column for timespans given an interval. """ interval = interval.lower() if interval == "yearly": return "year" elif interval == "monthly": return "month" elif interval == "weekly": return "week" ...
8fefc26f256b19a45317e608803c2fc1e8fcb06f
197,390
def create_empty_vapp(client, vdc, name, description): """Helper method to create an empty vApp. :param pyvcloud.vcd.client.Client client: a client that would be used to make ReST calls to vCD. :param pyvcloud.vcd.vdc.VDC vdc: the vdc in which the vApp will be created. :param str name: ...
7dcd5641ba00056b2045c57bbca3cc8529cf9f95
496,956
import textwrap def indent(multiline_str: str, indented=4): """ Converts a multiline string to an indented string Args: multiline_str: string to be converted indented: number of space used for indentation Returns: Indented string """ return textwrap.indent(multiline_str, " " ...
9fd5f2310ade00071a57731040435428cff88557
698,815
def guard(f, *args, **kwargs): """ Run a function. Return (is_error, result), where ``is_error`` is a boolean indicating whether it raised an exception. In that case, ``result`` will be an exception. """ try: return (False, f(*args, **kwargs)) except Exception as e: return (...
7b612dbc88a098c50a5f3b9cc2d2e8eeb617b160
34,919
import random def random_models(ctx, model_class_name, min_count=0, max_count=3): """ Get a random model identifier by class name. Example usage:: # db/fixtures/Tag.yml {% for i in range(0, 10) %} tag{{ i }}: name: {{ faker.name() }} {% endfor %} # db/fixt...
d213733551c81bc71c9199fbb9c0045c55dcea5d
145,411
import math def eq_A4_phi_parallel_corner(W_m, H_m, S_m, multiplier=1): """Equation A4 in BR 187 second edition (2014) calculates view factor from a rectangle corner parallel. :param W_m: in m, width of emitter panel :param H_m: in m, height of emitter panel :param S_m: in m, separation distance from...
d7bb8ef276cf76e553da88fe9b0dbc777577d559
545,061
def get_experiments_from_server_by_run_id(uploader, run_id, schema_namespace): """ Query the server for all Experiments (run and project) with a matching run_id Parameter. Returns a list of integer object IDs. :param uploader: An uploader object instance :t...
18974960abac11dcde6ea7293db6c1dd8e775226
391,595
def _pkg_curated_namespace(package): """ Strips out the package name and returns its curated namespace. """ return f"curated-{package.split('/', 1)[0]}"
d7e8bd4a0e28f0aa46bdcf8eb4bddd02a7928450
342,940
def get_mean(iterable): """ Returns the mean of a given iterable which is defined as the sum divided by the number of items. """ return sum(iterable) / len(iterable)
c1a5a81a7ac9c04991145a8b8245f8cd05af5fcb
573,414
import re def remove_pattern(input_text, pattern): """ Finds patterns in posts and substitutes them with blank space. Args: input_text: String representing of a twitter post pattern: Regex pattern to search for in twitter post Returns: String with pattern stripped. """ ...
7681566e64a136a3adb7fe02338dff2698cb9623
317,182
def load_file_lines(filepath): """ Load lines of the file passed. :param filepath: path to the file :type filepath: str """ with open(filepath, 'r') as f: contents = f.readlines() return contents
b7be92214098fb5ec323e20092c03cb1886e5575
437,651
def compose_line(title, file_stem): """ Composes the line to be written to the index in md format """ index_line = f'* [{title}]({file_stem}.html)' + '\n' return index_line
a015bea14f365641ea89baa8fab8fed72fbfb4f9
101,022
def generateContentRange(tup): """tup is (rtype, start, end, rlen) rlen can be None. """ rtype, start, end, rlen = tup if rlen == None: rlen = '*' else: rlen = int(rlen) if start == None and end == None: startend = '*' else: startend = '%d-%d' % (start, en...
2e5bd5240a2ffe89a789a554f09a6b07ffc737b0
292,209
def idx2long(index): """Convert a possible index into a long int.""" try: return int(index) except Exception: raise TypeError("not an integer type.")
7b2064abd6210230c0e726191f7498e2e8ca0816
161,917
from typing import Tuple def rgb_from_native(native_color: int) -> Tuple[int, int, int]: """ Extract RGB values from a native (OS-dependent) color. Parameters ---------- native_color : int Native color. Returns ------- r, g, b : (int, int, int) RGB values between 0 an...
9fc34dc84bbef13b498262158c27ed024b4bde81
166,879
def gcf(a, b, epsilon=1e-16): """Return the greatest common factor of a and b, using Euclidean algorithm. Arguments: a, b -- two numbers If both numbers are integers return an integer result, otherwise return a float result. epsilon -- floats less than this magnitude are consid...
91bc03277495c8968486d5f8b059057f72f5d715
243,336
def get_input_tool_name(step_id, steps): """Get the string with the name of the tool that generated an input.""" inp_provenance = '' inp_prov_id = str(step_id) if inp_prov_id in steps: name = steps[inp_prov_id]['name'] if 'Input dataset' in name: inp_provenance = "(%s)" % nam...
336926d59b4409d095feac36b4ffe374fcf56755
608,476
def knots_to_mps(vals): """Knot to meters/second.""" return vals * 1852.0 / 3600.0
2ea67e9b33e32537d8f1db7197e3123801c2ce97
387,604
def meanRelativeSquaredError(xs,ys,func): """Return the mean relative squared error.""" return sum([((func(x)-y)/y)**2 for x, y in zip(xs,ys)])/len(xs)
28ca788f51c9482cc7fb29532a967fb0f4123d9d
121,996
def cm_q(cm_i, l_t, mac): """ This calculates the damping in pitch coefficient Assumptions: None Source: J.H. Blakelock, "Automatic Control of Aircraft and Missiles" Wiley & Sons, Inc. New York, 1991, (pg 23) Inputs: cm_i [dimensionless] l_t ...
e41ea49ce3727397ad9c7a48cecbb4391366209d
259,274
def make_xor(f, g): """ Compose functions in a short-circuit version of xor using the following table: +--------+--------+-------+ | A | B | A^B | +--------+--------+-------+ | truthy | truthy | not B | +--------+--------+-------+ | truthy | falsy | A | +-------...
6cb0164594e7cd51c4e3aaa7d3c2988fbec93b45
448,419
from typing import OrderedDict def filter_words(word_to_idx, vectors, vocabulary): """Filter word vector data to vocabulary.""" filtered_to_idx, filtered_indices = OrderedDict(), [] for word, idx in word_to_idx.items(): if word in vocabulary: filtered_to_idx[word] = len(filtered_to_idx...
dc545455d9a60b17191602d55866acabd8006d20
94,967
def read_txt_file(fname): """ read a txt file, each line is read as a separate element in the returned list""" return open(fname).read().splitlines()
af0be81903c6ffa8a574b8e33b842e62ae4a5bc8
661,074
def _should_process_segment(seg, segname): """Check if we should process the specified segment.""" return segname.endswith('__DATA_CONST.__mod_init_func') or \ segname == '__DATA.__kmod_init'
c0fc59f25dc523f669a63c2bf026aff26bc42877
617,262
def format_time(seconds): """Formats seconds to readable time string. Args: seconds: Number of seconds to format. Returns: The formatted time string. Raises: ValueError: If the input `seconds` is less than 0. """ if seconds < 0: raise ValueError(f'Input `second...
2d58918fa22cd7cd40eea531f6bc86116bee1748
238,773
def get_data(users, exclude=None): """ users: set of Django users exclude [optional]: set of Django users to exclude returns: {'EMAIL': u.email} for all users in users less those in `exclude` """ exclude = exclude if exclude else set() emails = (u.email for u in users) return ({'EMAIL':...
f92ed5aef2873a09abd7612dfc767019909a9083
476,631
def generate_registers_riscv_plic0_threshold(hart, addr): """Generate xml string for riscv_plic0 threshold register for hart""" return """\ <register> <name>threshold_""" + hart + """</name> <description>PRIORITY THRESHOLD Register for hart """ + hart + """</d...
822c17560e055a5652621176630d9437ca90f631
437,535
def aix_path_join(path_one, path_two): """Ensures file path is built correctly for remote UNIX system :param path_one: string of the first file path :param path_two: string of the second file path :returns: a uniform path constructed from both strings """ if path_one.endswith('/'): path...
073115ad92683dd6d22da6dc2d5dea6562e51e74
569,095
def noll_to_wss(zern): """ Transform a Noll Zernike index into a JWST WSS framework Zernike index. :param zern: int; Noll Zernike index :return: WSS Zernike index """ noll = {1: 'piston', 2: 'tip', 3: 'tilt', 4: 'defocus', 5: 'astig45', 6: 'astig0', 7: 'ycoma', 8: 'xcoma', 9: 'ytrefo...
dede2e9057fe5418488532d0a763c64886372932
232,667
def filter_post_edits(dict_elem): """ Filter post history events that modified the body of the posts. :param dict_elem: dict with parsed XML attributes :return: boolean indicating whether element modified the body of the corresponding post """ return int(dict_elem['PostHistoryTypeId']) in [2, 5,...
b8f567d6dceb0dd1deb6cffac631bfc44f0fb282
21,023
async def get_authenticated_user(*, app, logger): """Get information about the authenticated GitHub user. This function wraps the `GET /user <https://developer.github.com/v3/users/#get-the-authenticated-user>`_ method. Parameters ---------- app : `aiohttp.web.Application` The app i...
b7577fbe203b08080dd2c2e9c9f3af132095e4d7
79,140
from typing import List def get_available_signatures() -> List[str]: """Return a list of available signatures. Returns ------- List[str] List of all available signatures. """ signatures = [ "high_q_freq", "high_q_dur", "low_q_freq", "low_q_dur", "zero_q_freq", "q95", "q5", "q_...
69c93c5d10cbf669a9959a7f8fb555c656da5a98
320,914
def get_missing_vars(aws): """ return a list of missing required env vars if any """ required = ["AWS_SECRETS_NAME", "AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY"] return [f'Missing env variable "{v}"' for v in required if aws.get(v, None) is None]
8fd121c74a8771893627ce75ee4636ce612ca1d4
377,240
import time def verify_token(timestamp): """判断token是否过期 :param timestamp: token过期时间戳 :type timestamp: int """ # 过期时间2小时 if timestamp - int(time.time()) <= 7200: return True return False
2dd0fd629028e8d399f36dc95bf0f050af627301
516,088
def endswith(x, lst): """ Select longest suffix that matches x from provided list(lst) :param x: input string :param lst: suffixes to compare with :return: longest suffix that matches input string if available otherwise None """ longest_suffix = None for suffix in lst: if x.endswith...
875f213d3478a6c49956b195db9bd4fd5fbdfc7b
190,649
def parse_row(row): """ Take in a tr tag and get the data out of it in the form of a list of strings. """ return [str(x.string) for x in row.find_all('td')]
44b8eadcd11d79ede2ae3d0a0866bfa80ff5e36d
666,796
import re def clean_output(output: str) -> str: """Removes ansi color codes from string""" return re.sub(r"\x1B[@-_][0-?]*[ -/]*[@-~]", "", str(output).strip())
ba4aa3e90f53fa1f61a9c8b4264fd737c89d2553
343,428
def _resample_daily(data): """ Resample data using linear interpolation. :param data: Pandas DataFrame or Series. :return: Resampled daily data. """ return data.resample('D').interpolate(method='linear')
974eda3a0a0e842f478128ddfa87a765899c9d14
438,185
def _html_param_builder(params): """ Build a HTML params string out of a dictionary of the option names and their values. If a list is the value (it is intended in a select case) the original list is returned instead of a string :param dict params: :return str | list: the composed parameters string...
e483c1f43cd5dde78982bdf8026a3a5c1b9a73b2
428,956
def myRound(x, y=4): """Rounds floating point number to specified number of decimal places.""" return round(x*y)/y
692ee4ee73f94acd025edc4464ce267c9cf9ae71
158,683
def is_a_number(x): """ Returns True if x is an int or a float. """ return (type(x) is int) or (type(x) is float)
bacb75da546e551f0e4e2f7fcd3345ffd49e8b6e
354,715
def collectKwargs(label, inKwargs): """ Collect kwargs of the type label_* and return them as a dict. Parameters ---------- label: str inKwargs: dict Returns ------- Dict with the collected kwargs. """ outKwargs = dict() for key, value in inKwargs.items(): if la...
0e92c451dd2c3f9463da263f3b09a95a23c11543
304,665
def compute_prior_pseudocounts(vs, rv, pseudocount_base, pseudocount_match): """ Make pseudocounts dict. Input: vs a list of votes (domain of prior) rv a particular vote (e.g. the reported vote) pseudocount_base a prior pseudocount (e.g. 0.5) ...
f190e8cdf9462f5d13d4846c6561810a35f0011c
596,587
def contains(element): """ Check to see if an argument contains a specified element. :param element: The element to check against. :return: A predicate to check if the argument is equal to the element. """ def predicate(argument): try: return element in argument exce...
901785df69b8ee3f07c01cc1d3a1ce1c31d204b2
682,523
import math def py37_isqrt(n): """Return largest integer r such that r^2 <= n""" if n < 10000000000000000000000: # trial and error return math.floor(math.sqrt(n)) else: # https://stackoverflow.com/a/53983683 if n > 0: x = 1 << (n.bit_length() + 1 >> 1) whil...
7f5a93f8b8db5ecfc49c239343fb679063ea0534
593,596
def check_output_options(input,): """ Checks the inputs of the mcmc_options dictionary and ensures that all keywords have valid values. output_options={ 'write_chain' : False,# Write MCMC chains for all paramters, fluxes, and # luminosities to a FITS table We set this to false ...
0bf69c7bc2d24cca315c1956ffb6cdfd34a4b5bd
173,506
import random def init_neurons(count): """ Initialize the weights of the neurons :param count: number of neurons to initialize :return: list of neurons as weight vectors (x,y) """ return [[random.uniform(0.0, 1.0), random.uniform(0.0, 1.0)] for i in range(count)]
98be8fc1f621e2c768af3c93d1a0254ac42a4ffc
667,504
def _GetPercentageChange(value1, value2): """Returns the percentage change between the specified values.""" difference = value2 - value1 return 0 if value1 == 0 else difference/value1 * 100
987d2cd20456ad5fad72145adecdda96256b9162
584,109
def get_categories_of_column(data: list, column: str, delimiter=',') -> list: """Get list of unique categories of non-atomic column which contains multiple categorical values splitted by delimiter Parameters ---------- data : list Data stored in list of dicts column : str Column...
2890918e0f5a69546c23cecbe04ef452e3b39f7b
129,592
def _build_selector(selectors, separator): """ Build a selector defined by the selector and separator :param selectors: a list of strings that are selector :param separator: the char that separates the different selectors :return: the resulting selector """ selector = "" for i, sel in en...
fb61d36f2d552e655e9f071cabacc8792217421f
566,374
import copy def merge_vocabulary(vocab1, vocab2): """ Merges two vocabularies :param vocab1: :param vocab2: :return: merged vocab """ merged = copy.deepcopy(vocab1) for key2 in vocab2.keys(): if key2 not in merged: merged[key2] = len(merged) return merged
c8d08c3d2ae722f59f95d4e8b7f5e97d31ad6a0b
219,398
def get_audit_ccs(assessment): """Returns audit CCs regarding assessment. Args: assessment: An instance of Assessment model. Returns: List of audit ccs """ audit_issuetracker_issue = assessment.audit.issuetracker_issue if audit_issuetracker_issue is not None and audit_issuetracker_issue.cc_list: ...
0630f9c69acf0b2f61c362b2bed1dc35eb2bd8f2
59,374
import re def filter_cmd_list(cmd_list, regex_to_include=".*", regex_to_exclude=None, dict_key='label'): """Filter a list of Benchpress commands Parameters ---------- cmd_list : list of dict The commands to filter. regex_to_include : str RegEx that match for inclusion. regex_t...
77eafc02cb530f0f84a80d24e517c0104e524dcc
262,311
def determine_if_pb_should_be_filtered(row, min_junc_after_stop_codon): """PB should be filtered if NMD, a truncation, or protein classification is not likely protein coding (intergenic, antisense, fusion,...) Args: row (pandas Series): protein classification row min_junc_after_stop_codon (...
29ab7ce53ac7569c4d8a29e8e8564eab33b3f545
2,631
import hashlib import re def _build_schedule_name( job_body_data: bytes, schedule: str, pipeline_name: str, display_name: str, ) -> str: """Generates the name for the schedule. Args: job_body_data: The serialized pipeline job. schedule: Schedule in cron format. pipeline_name: Full res...
740f22c4c78b588806e14df61ad10dcaf116e7e9
534,138
def Bin_minutes(val): """ Map minutes to a time bin. """ if val/60. >= 0.5: return 0.5 else: return 0.0
67175df068e0b51e56ac7b4b99c734dfba5c44e9
129,441
import re def custom_regex_removal(regex, text): """ Find and substitue given regex in given text :param regex: regex that removed :param text: arbitrary string :return: clean string """ text = re.sub(r'{}'.format(regex), '', text) return text
9c2ca934b5f0d3121d75a73b3f95d6bb242bb5bb
504,797
def checkNextString(StringList, index, storageString, rawlength): """ checkNextString takes a parsed ICS string list, along with the current index being read, the string the user is writing to along with the rawlength of the string list. returns a tuple containing the indexes we combined in...
e061833b39d772f87bdfca1d8737f1787669bf1e
476,024
def doubleChar(words): """ Function to repeat the chars. Given a string, return a string where for every char in the original, there are two chars. Args: words (String): String provided by user Return: result (String): String with characters dupplicated """ result = ""...
2acff6db3a258cb7c90b7e5c92192a8aafce31a5
333,293
def get_providers(targets, provider, map_fn = None): """Returns the given provider (or a field) from each target in the list. The returned list may not be the same size as `targets` if some of the targets do not contain the requested provider. This is not an error. The main purpose of this function is...
81bda635566479d02ca9d21a096bc4caeaabda01
274,351
import itertools def take(n, gen): """Take the first n items from the generator gen. Return a list of that many items and the resulting state of the generator.""" lst = list(itertools.islice(gen, n)) return lst, gen
6254817eb20c14e8eed75d5051aedf865b28223e
448,005
def get_aF(r1_norm, r2_norm): """ Computes the semi-major axis of the fundamental ellipse. This value is kept constant for all the problem as long as the boundary conditions are not changed. Parameters ---------- r1_norm: float Norm of the initial vector position. r2_norm: float...
739a5c8d61ccde8db0eb7df10335940c338353c7
589,966
def preprocessed_test_metrics(expected_metrics): """function that creates a single file with metrics that need to be tested in different files In: expected_metrics: List[ Tuple[FileName, Dict[Metric1: Value1, Metric2: Value2, ...], ...] ] Out: res: List[ Tuple[FileName, Metric1...
ce70cf7fe342fd761d3669af512752ab0ba96231
216,313
def get_det_prefix(pv_info): """ Determines which prefix will be passed into the detector init. Parameters ---------- pv_info: ``str`` The second element in a camview cfg line. Returns ------- detector_prefix: ``str`` The prefix to use in the detector init. """ ...
0b973808092f14b0eeeb6d20f5e3c207a83a7068
136,620
from typing import OrderedDict def get_partial_state_dict(model_state_dict, modules, init_from_decoder_asr=False, init_from_decoder_mt=False): """Create state_dict with specified modules matching input model modules. Note that get_partial_lm_state_dict...
4d83f22124dca13852451e4016f5a52a727fa031
610,750
def filter_by_type(lst, type_of): """Returns a list of elements with given type.""" return [e for e in lst if isinstance(e, type_of)]
8aa0c910ee7b098b2715cd612b434b37ea75e51a
329,285
def createExpressionList(string): """Creates a list of expression strings Keyword arguments: string -- String of semicolon-separated expressions Takes the expression string and splits it with semicolon as delimiter Returns list of single expression strings """ exprList = li...
eb7424827a0508a169f2caa069331dd4ab0947b1
514,303
def redis_serialize_data(datum): """Serialize a data object for redis. The format is 'data:<pk>' """ return "data:" + str(datum.pk)
5a9892264647f2cd1ab042a6a62640cd4f0f5397
508,434
import time def parse_recurrence(time_string): """Parse recurrence data found in event entry. Keyword arguments: time_string: Value of entry's recurrence.text field. Returns: Tuple of (start_time, end_time, frequency). All values are in the user's current timezone (I hope). start_time and end_time...
f2a991c2f2846c46228f0aa67cb883310abfe267
410,913
import six def to_unicodestr(string): """If input string is a byte string convert to Unicode string.""" if isinstance(string, six.binary_type): return string.decode('utf8') return string
c07a885a2d1ae4ee291a547b1e6d27de874c25bf
164,377
def checkBuildingType(line): """Checks if the building type is a house, or if the item is being bought or sold""" if " is buying " in line: return "buy" elif " is selling " in line: return "sell" else: return "house"
b18c2db78aba84820e4b489f5b8bad128e7c1860
399,030
def pass_min_coverage(dp, i, min_coverage, cov_metric): """ if the DP flag does not meet minimum coverage, toss it. if the DP4 flag does not meet minimum coverage, toss it. :param dp: DP coverage allele depth :param i: string DP4 coverage allele depth :param min_coverage: int ...
929852dd7635bfa6917ba5a1e8c1456b69db2bbf
427,149
def _get_smartcard_keychain(xml): """Get keychain items from the output of 'system_profiler SPSmartCardsDataType -xml'""" keychain = [x for x in xml if x.get("_name", None) == "AVAIL_SMARTCARDS_KEYCHAIN"] if len(keychain) == 0: return [] keychain = keychain[0].get("_items", None) return keychain
bf5c3414a0b333ad805458c9e6a36a4cfa918be8
543,067
def format_duration(duration: float): """Formats the duration (milliseconds) to a human readable way. :param duration: Duration in milliseconds :return: Duration in HOURS:MINUTES:SECONDS format. Example: 01:05:10 """ m, s = divmod(duration / 1000, 60) h, m = divmod(m, 60) if h: retu...
20314e05294504a1b8d0979b48397d8b0563eb0d
464,620
def prime_sieve(n): """ Return a list of all primes smaller than or equal to n. This algorithm uses a straightforward implementation of the Sieve of Eratosthenes. For more information, see https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes Algorithmic details ------------------- ...
180dc6a2ff1d3096630a6279ace841e4c5efdd83
661,389
def get_item(dictionary, key): """ Given a dictionary and a key, return the key's value """ return dictionary.get(key)
97bf041cb8afe160a5c1610e088dadb91d023e8f
97,582
def s2b(u, enc='UTF-8'): """ Convert a string into a bytes object. """ return u.encode(enc)
e19c795722380bed50aa1f011b65dacfe92c13cc
557,091
def find_smallest(num_vars): """Find the smallest exponent of two that is greater than the number of variables Parameters ---------- num_vars : int Number of variables Returns ------- x : int Smallest exponent of two greater than `num_vars` """ for x in range(10...
ab773fbbad29c75df6350a426acc2db9c30d8137
190,100
def parse_task(line): """ Receives a line and parses it to match the format `[subject] name`, where `subject` is a two-letter code for the subject and `name` is the name of the task. If `subject` is invalid, the user is re-prompted until a valid entry is given. Capitalisation is automatic. Args: ...
e378c028089b44a8d6eca1123a15f71ce210f7cc
293,751
def get_blacklist_scans(subject_id, blacklist_path, new_id=None): """ Finds all entries in <blacklist_path> that belong to the participant with ID <subject_id>. If <new_id> is given, it modifies the found lines to contain the new subject's ID. """ try: with open(blacklist_path, 'r') as b...
ab7e1aca57cbc944da48d7e6fe36c5888429eeda
168,422
def remove_repeated_coords(sequence): """ Removes coordinates repeated on a sequence Args: sequence (list): list of tuples Returns: List of unique tuples """ seen = set() return [x for x in sequence if not (x in seen or seen.add(x))]
361e2fb256a9b8299d3982569af10ac503d56ad6
335,129