content
stringlengths
39
14.9k
sha1
stringlengths
40
40
id
int64
0
710k
def deserialize_utf8(value, partition_key): """A deserializer accepting bytes arguments and returning utf-8 strings Can be used as `pykafka.simpleconsumer.SimpleConsumer(deserializer=deserialize_utf8)`, or similarly in other consumer classes """ # allow UnicodeError to be raised here if the decodin...
21cc61d6048b5f7d9333ceadb86d03666719f05f
25,860
from typing import Iterable from typing import Union from typing import List from typing import Generator def make_single_arguments(iterable_of_args: Iterable, generator: bool = True) -> Union[List, Generator]: """ Converts an iterable of single arguments to an iterable of single argument tuples :param i...
4469b7bb1a18e72948380ebea90c52459f528be1
25,861
def FindPosCol( iDotData ): """Find the column representing the SNP position, based on our conventions.""" return 'Pos' if 'Pos' in iDotData.headings else 'pos'
7048a0fd3d662f392e5a8b36acd94d1b92b674ba
25,863
def get_media_info(player): """ Function to fetch the current playing track and artist information""" media = player.get_media() info = str(media.get_meta(12)) info = info.split("-") artist = info[0] track = info[1] return artist, track
32463946e98d453ae399b25dc7d6b8555812f319
25,867
def get_step_time_shift(step): """Calculates the time shift generated in each filtering step Parameters ---------- step: dict Dictionary object holding information about a given filter step Returns ------- shift: float Time shift value """ input_sample_period = step[...
b6c2d299337e37a13e0fe6472577da3e3663aae1
25,876
def query_row_args_2_dict(args): """ change query_row_args to dict :param args: query row args :type args: QueryRowArgs :return: :rtype dict """ return { 'rowkey': args.rowkey, 'maxVersions': args.max_versions, 'cells': args.cells }
50f7131052cf17fba960759a5d6a27b3203e4008
25,881
def basin_ensemble_mean(dict_by_basin, basin_name, case): """Compute the multi-GCM ensemble mean SPEI for a given basin and case Parameters ---------- dict_by_basin : DICT Stores SPEI per basin basin_name : STR Which basin to study case : STR 'WRunoff', 'NRunoff', 'd...
b7c9c2bebca2639f260c65abddea0e30c3ecef7f
25,883
def timedelta_to_seconds(td): """Convert a timedelta to seconds. The returned seconds will be rounded to the nearest whole number. """ return round(td.total_seconds())
66cbe5409ac378825590ba96fc5affc469267f3d
25,884
import copy def remove_whitespace(dictionary): """ Remove values that empty whitespace in the dictionary """ nd = copy.deepcopy(dictionary) bad_keys = [] for k,v in nd.iteritems(): if hasattr(v,'strip'): stripped = v.strip() # ghetto and maybe unnecessary if...
7f06794cafff4754430a45ee39b38735263fc357
25,886
import hashlib def sha256(filepath,blocksize=2**20): """ Return the sha256 hash of a file. `blocksize` adjusts how much of the file is read into memory at a time. This is useful for large files. 2**20: 1 mb 2**12: 4 kb """ hasher = hashlib.sha256() with open(filepath,...
086d6284953709a87b1a14c5c5b8c56b28b1d9d5
25,887
def sum_risk(method): """ Sum risk of all nodes in the method graph. """ risk = 0 for node_name in method.graph.nodes_iter(): node = method.graph.node[node_name] if "entry_point" in node: continue if "risk" in node: risk += node["risk"] return risk
5ae3bc3138a7f4b9d905c5f2122c7a1ecd9bbc09
25,889
def split_labels(data, label_idx=-1): """ Split labels from numerical data :param data: array of inputs data :type data: nd.array :param label_idx: index where label is located in the array. It can be only at start of at the end of the array :type label_idx: int :return: data without labels...
d3b59dca790255ae14269836ace58df151f84684
25,890
import ast def init_quantizer(name: str) -> ast.Assign: """ Generate quantization node initialization to add to the end of __init__() :param name: generated name of the node :return: quantization init ast node """ quant_linear = ast.Attribute(value=ast.Name(id="quant_nn", ctx=ast.Load()), attr...
b6159998556dba27bbb46049d7aeb8cbd390d2c7
25,891
def str2link(s, directory, title=''): """ Used by the --html options, this takes a string and makes it into an html <a href...> link without a closing </a>. """ if directory == '': return '' else: if title: return '<a href="%s/%s" title="%s">' % (directory, s, title) ...
512af2dd4308ac65b24f84e24aec95cb8144f8a1
25,893
import re def extract_only_numbers(text): """ Little function to extract only numbers from a string. Usuful in OCR if we want to detect only digits. Also, in converts 'o's and 'O's to 0 since it appears to be hard for tesseract even if I fucking tell it to parse only digits. GG google. :para...
a51520376c492a0629c564e8b8d54a19c1d5041e
25,894
import fnmatch def does_pattern_exists(patterns_list, value): """ Checks a list of patterns against a value. :param: patterns_list : A list of regular glob expression strings :type: str :returns: Returns True if any of the patterns match the value, False otherwise. :type: boolean "...
cb1d6c8ea079aa25f980b42c2755db9253f68284
25,896
def top_n_countries(world_confirmed, feature='Confirmed', n=10): """Return list of top n countries with highest feature (Confirmed, Deaths, Recovered, Daily ...)""" top_n = (world_confirmed .groupby('Country/Region') .agg('max') .sort_values(feature, ascending=False) ...
dd50882f8378e2405c8d6b2eadbe878d11b43351
25,900
def selectors_escape(s): """ Escapes all selectors used in html, css, js & jquery :param s: string The string to escape :return: string The escaped string """ selectors_reserved = '\!"#$%&\'()*+,./:;<=>?@[]^``{|}~' for char in selectors_reserved: s = s.replace(char, f...
fd95d9ebd5de2461bcf836f4e0792b17433451ce
25,901
def d(series, n=1): """Difference over n periods""" return series-series.shift(n)
b585f13851a9cff9655cad29564b909ecffbd238
25,903
def isnumber(num): """ Checks whether argument is number""" try: float(num) return True except ValueError: return False
4ea3b253ff1ffdd8f5adf532ffa194525c8dfaf0
25,911
def update(day, day_to_implement, new_social_distance, new_stay_at_home): """ updates current policies, panic, quarantine policiy and stay at home order Parameters ---------- day : int current day of the simulation. day_to_implement : int day from which measures are implemented. ...
fd0e3232f8ef7b7e7c4ed6fb0716ba851635b2e4
25,912
def get_options_at_path(user_selected_path: str, file_list: list): """ Returns all the alternative items (folders and files) on the provided path """ # Get the number of folders at the current level n_folders = len(user_selected_path.split("/")) # Get all the files at level subfolder_options...
31fc39005fdd3b9151cdcea75738c4ed06b30504
25,914
def format_title(host: str) -> str: """Format the title for config entries.""" return "Controller ({})".format(host)
99ca5c97007a8f0373184d8d9c5c55bb5d7d64b9
25,916
def parse_bool(data): """Parse a string value to bool""" if data.lower() in ('yes', 'true',): return True elif data.lower() in ('no', 'false',): return False else: err = f'"{data}" could not be interpreted as a boolean' raise TypeError(err)
60f35d69178fa6322f3ff29b64b96deb7bd43f94
25,919
def read_last_seen(FILE_NAME: str) -> int: """ gets the id of last seen tweet Args: FILE_NAME: static file name which stores the last seen id Returns: last_seen_id: id of the tweet """ file_read = open(FILE_NAME, 'r') readed = file_read.read() if readed != "": las...
d7d919deabc133d8500ab0a6f6ea786e9a291edd
25,921
def reverse_chain(joints): """ Reverses the hierarchy of the joint chain. :param joints: List of joints in the chain to reverse :return: the same list of joints in reverse order """ # -- Store the base parent so we can reparent the chain # -- back under it base_parent = joints[0].getPa...
8961c0031c7fd230935ffd212eca63f9f2ff6112
25,923
def _node_like(test_dict: dict): """ Evaluates whether a dict can be converted to a node safely. test_dict : dict | Dict to check """ if not isinstance(test_dict, dict): return False keys = list(test_dict.keys()) try: keys.remove("ParameterName") keys.remove("ParameterValue") keys.remove("ParameterInfo"...
c03d2f6d5824068646ef011b8b3d9dd2fca58767
25,924
from typing import Set from typing import Tuple def get_line_between_points(x_0: int, y_0: int, x_1: int, y_1: int) -> Set[Tuple[int, int]]: """ Gets a line between two coordinate pairs represented by a list of tuple[x, y]. The line is found using Bresenham's line algorithm. See: https://en.wikipedia....
98324b303268a6e8b48aa7e7dba2e1fa85f7b463
25,931
import json def parse_json_data(filename) -> dict: """Returns the contents of a JSON file as a dict""" with open(filename, "r") as f: return json.loads("".join(f.readlines()))
d061043cf29d1ed8d790a51d135c251e2226de77
25,940
def get_marble(value=0, prev=None, next=None): """Get new marble, with value, prev and next.""" return {'value': value, 'prev': prev, 'next': next}
2cf13f5a46111b56c154a1bba0eec33bfb3ad8bc
25,944
from typing import List def add_to_leftmost_int(stack: List, x: int) -> List: """ Add x to leftmost int in l if no int in l, do nothing return modified l """ int_locations = [isinstance(i, int) for i in stack] if not any(int_locations): return stack index = int_locations.index(...
c110df6643b98ddf7a3c18933fc1911bc247a138
25,965
def squareT(A): """ Returns (A Aᵀ) """ return A.dot(A.T)
ea214c8cccfff2146b66013fc00f06d6cbfc0337
25,966
def GetVectorValue(item): """Given an smtk.attribute.Item, return a list containing its values.""" N = item.numberOfValues() return [item.value(i) for i in range(N)]
573468b6416126553774a97de70b99c069390754
25,971
import platform import inspect def _get_mro(cls): """ Returns the bases classes for cls sorted by the MRO. Works around an issue on Jython where inspect.getmro will not return all base classes if multiple classes share the same name. Instead, this function will return a tuple containing the class...
d6e402e774078788020553c41a2a693591dac88a
25,972
def format_metrics(d: dict) -> dict: """ Format the floats in a dict with nested dicts, for display. :param d: dict containing floats to format :return: new dict matching the original, except with formatted floats """ new = {} for key in d: if isinstance(d[key], dict): ...
1be92878ce97db21b7775345a9a830c42265a5c8
25,973
def titlecomment(line): """Condition for a line to be a title comment""" return line.startswith('//') and len(line.lstrip('//').strip()) > 0
a1a1f44e01399c4a3511670146d1e2587d9ead26
25,974
def session(context_name="session", request=None, **kwargs): """Returns the session associated with the current request""" return request and request.context.get(context_name, None)
e379e2fbf313557aa8c5087c8c0d75a5738243fe
25,975
def extract_tags(cgx_dict): """ This function looks at a CloudGenix config object, and gets tags. :param cgx_dict: CloudGenix config dict, expects "tags" keys supported in root. :return: list of tags present. """ # tags exist, return them. tags = cgx_dict.get("tags", []) if tags is None...
b2b78f46c65d4ca7c9c3ae0ed54a9d2a4da80724
25,980
def split_outfile(line): """ Split the output file from a command. """ redirect = line.find('>') if redirect == -1: return line, None else: return line[:redirect].rstrip(), line[redirect+1:].lstrip()
0ba0f76132256d87c61c6e98d9e5e6d310b04d6c
25,987
def calculate_turnaroundtime( burst_time: list[int], no_of_processes: int, waiting_time: list[int] ) -> list[int]: """ Calculate the turnaround time of each process. Return: The turnaround time for each process. >>> calculate_turnaroundtime([0,1,2], 3, [0, 10, 15]) [0, 11, 17] >>> calculate...
cac09f266599293abfd2f90d22523444556c3204
25,992
def append_gw_teams(df, df_match): """ Count the number of teams playing in a single gameweek :param df: Input DataFrame (must contain 'player_id', 'gw' columns) :param df: Match DataFrame :returns: Input DataFrame with 'gw_teams_ft' column appended """ df = df.copy() df_teams = (df_matc...
1ff1798d51268d1aa111ebf6763725abd674bc44
25,998
def convert_weight_pounds(weight) -> int: """ Converts Kilograms into Pounds """ pounds = round((weight * 2.20462), 5) return pounds
edc50cbc4bc8f6a40b354376b3d42fedc8097698
26,000
from typing import Any from typing import TypeGuard from typing import Callable from typing import Coroutine import asyncio def acallable(arg: Any) -> TypeGuard[Callable[..., Coroutine[Any, Any, Any]]]: """Type guard for coroutine (async) functions""" return callable(arg) and asyncio.iscoroutinefunction(arg)
c81ed04cc07f20148356be60eddb89fad9bf061e
26,001
def fraction_edge(r): """Calculate fraction of coins that landed on edge""" total = r['Edge'] + r['Tails'] + r['Heads'] fraction_edge = r['Edge'] / total return fraction_edge
0153fc983bc9c2ae3f3d7b3cd1940c11671c71ca
26,004
def convert_to_minutes(num_hours): """ (int) -> int Return the number of minutes there are in num_hours hours. >>> convert_to_minutes(2) 120 """ result = num_hours * 60 return result
a959182939cd3a2e6bd4076a706c4993086daa4a
26,006
def _is_cast(**kwargs) -> bool: """ Does this spec require casting """ return 'cast' in kwargs
97a12699408a23a9f2021532ae36071c2254cc99
26,007
from datetime import datetime def generate_upload_file_path(form_fields): """ Use validated form fields to create the key for S3 """ now = datetime.now().strftime("%Y%m%d-%H%M%S") file_path_to_upload = "{}/{}_{}.{}".format( form_fields["file_location"], now, form_fields["fi...
b981bd059130c953b93fca61fa43b2608f84b07c
26,010
def make_doublebang_pulse_fun(parameters, tf): """Return double-bang pulse function. y0, t1, y1 = parameters For 0 <= t <= t1, constant height y0. For t >= t1, constant height y1. """ y0, t1, y1 = parameters def fun(t, *args): if 0 <= t <= t1: return y0 elif t1 ...
619cdef2117237f683b8d8eea996867cf82c473f
26,011
def df2node_attr(df): """Convert dataframe to dict keyed by index which can be used to set node attributes with networkx""" # NOTE: df.index has to be the nodes return df.T.to_dict()
718506480f5da95c9c1ab90798d06d9696cacd5b
26,020
def sigmoid_across_unit_interval(p, k=1.2): """ Sigmoid transformation for a unit interval. Returns: a value [0,1] associated with a proportion [0,1] Parameters: p -- proportion across the unit interval [0,1] k -- shape of the simoid transformation ...
e8f1fb1472b3341ee32833bf7c91ebcdaf27fa11
26,027
from typing import Any def delete_none_keys(dict_: dict[Any, Any]) -> dict[Any, Any]: """Remove any keys from `dict_` that are None.""" new_dict = {} for key, value in dict_.items(): if value is not None: new_dict[key] = value return new_dict
6a3ab5457203457044207a985c1588ef0fddcccf
26,030
def is_not_set(check, bits): """Return True if all bits are not set.""" return check & bits == 0
7b60d6ed9d12402240b2a7f7048ab9fd11a4b777
26,036
import random def generate_random_dict(keys_count=10, depth=1): """ Generate a dictionary with fixed random values. """ result = {} keys = list(range(0, keys_count)) random.shuffle(keys) current = {} result = current for index in range(0, depth): current["depth_%s" % (in...
f85fef810ee32705a0c1687ed1740c3f59bc04c5
26,038
def get_local_node_mapping(tree, last_tree, spr): """ Determine the mapping between nodes in local trees across ARG. A maps across local trees until it is broken (parent of recomb node). This method assumes tree and last_tree share the same node naming and do not contain intermediary nodes (i.e. si...
b30a95bb0c23fc00005de9474da19e781bc0485e
26,043
def int2ap(num): """Convert integer to A-P string representation.""" val = '' ap = 'ABCDEFGHIJKLMNOP' num = int(abs(num)) while num: num, mod = divmod(num, 16) val += ap[mod:mod + 1] return val
6f9b0f84485461c5b73525c48838e157bf6136c3
26,044
def heatCapacity_f1(T, hCP): """ heatCapacity_form1(T, hCP) slop vapor & solid phases: T in K, heat capaity in J/mol/K; heat capacity correlation heat capacity = A + B*T + C/T^2 Parameters T, temperature hCP, A=hCP[0], B=hCP[1], C=hCP[2] A, B, and C are regression coe...
5f90c998bb913bd617b959396bc7e5d67a0cd24f
26,045
import torch def generate_spatial_noise(size, device, *args, **kwargs): """ Generates a noise tensor. Currently uses torch.randn. """ # noise = generate_noise([size[0], *size[2:]], *args, **kwargs) # return noise.expand(size) return torch.randn(size, device=device)
5c9116fdc132d59e4a0ccc6c5674042f70533efe
26,046
def get_file_contents(filename: str) -> str: """ Receive a filename and return its contents """ with open(filename, "rt", encoding="utf-8") as infile: text = infile.read().rstrip() return text
b16f14a65120ba79799ca97186fd119f4bb1b040
26,050
def my_sqrt(x: int) -> int: """Implement int sqrt(int x) https://leetcode.com/problems/sqrtx/ Compute and return the square root of x, where x is guaranteed to be a non-negative integer. Since the return type is an integer, the decimal digits are truncated and only the integer part of the resu...
c7193b646223b8b89bdd20fd1beaf8c8e0acc003
26,057
import logging def extract_clsy(the_sidd): """ Extract the ownerProducer string from a SIDD as appropriate for NITF Security tags CLSY attribute. Parameters ---------- the_sidd : SIDDType|SIDDType1 Returns ------- str """ owner = the_sidd.ProductCreation.Classification.o...
8f5a3f0cd59dfcc9822341fc0effd0a515f23681
26,059
def scale_serpent_to_origen(serpent_volume): """ Function for performing the volume conversion to make Serpent results comparable to ORIGEN ones. ORIGEN scales the results to 1 ton of U, so the serpent volume must be scaled to match. """ fuel_density = 10.41 #10.41 g/cm^3 as default fuel_ur...
efd5b9847386e3f512a8a096ba8d12682e028334
26,062
import glob def generate_files(original_pattern: str, mask_pattern: str): """generator for original and mask img path Args: original_pattern (str): original path pattern mask_pattern (str): mask path pattern """ def real_generator(): original_img_paths = sorted(glob.glob(orig...
bc95ea5cd3ec40c43b875e56c782e1324133826d
26,063
def eval(predict, groundtruth): """计算预测结果的准确率、召回率、F1 Args: predict (list): 预测结果 groundtruth (list): 真实结果 Returns: tuple(precision, recall, f1): 精确率, 召回率, f1 """ assert len(predict) == len(groundtruth) tp, fp, tn, fn = 0, 0, 0, 0 for i in range(len(predict)): ...
e75a35156f9bb72b4ec2fd5099bc6b399c923533
26,071
def expect( obj, attr, value, nullable=False, types=None, not_types=None, convert_to=None ): """ Check, whether the value satisfies expectations :param obj: an object, which will set the value to its attribute. It is used to make error messages more specific. :param str att...
7d1559dac92ebe8b5ba646a98a6b1a5021751c4a
26,076
def get_channels(color: str) -> tuple[int, int, int]: """Convert a 24-bit hex color string into an RGB color. :param color: A 24-bit hexadecimal color string, like is commonly used in HTML and CSS. :return: A :class:tuple object. :rtype: tuple """ r = int(color[:2], 16) g = int(colo...
6f3bc0e366957f3426d7c909ae9a72080bd5def0
26,077
def get_order_by_parts(order_by): """ Extract the order by clause information. In future this could be used to update multiple column ordering. :param order_by: the order by clause, for example: ' ORDER BY column_name ASC/DESC' :return: order by field name, order by order. For example: column_name, ASC/...
db400dd1aa4f47ffda58b8ccc6e101b7f395537a
26,081
def db_get_idents(conn): """ Returns the idents table as dict of dicts (the ids in the first dimension are always smaller than those of the second. Args: conn: Sqlite3 connection object. Returns: Idents table as dictionary. """ cur = conn.cursor() result = {} for id_...
11d5888ca979425417b4e70808477925c436cf0e
26,082
def toslice(text=None, length=None): """Parses a string into a slice. Input strings can be eg. '5:10', ':10', '1:'. Negative limits are allowed only if the data length is given. In such case, input strings can be e.g. '1:-10'. Last, an integer can be given alone such as '1' to select only the 1st ...
b81345e678e681931c6a3dae287566cd0578bebb
26,084
def address_to_vec(addr): """ Convert an address into a list of numbers. """ # Strip of first and last char, then create list of nums. # -2 to also ignore trailing dash. numbers = addr[1:-2].split('-') v = [] for e in numbers: v.append(int(e)) return v
0ee27bb945ba1c736500cef1772a12890a9cee03
26,085
def z_to_y(mdrrt, z): """convert z into y according to target mdrrt. This method achieve the conversion of y into z. This is (7) in the paper. Args: mdrrt (MDRRT): target MDRRT z (pyqubo.array.Array): decision variable z Returns: list<list<pyqubo.Binary>>: decision variabl...
8eb456c7972d5005b74cd07a67fd23032082cc2a
26,090
def normalize(name): """ Normalizes text from a Wikipedia title/segment by capitalizing the first letter, replacing underscores with spaces, and collapsing all spaces to one space. :Parameters: name : string Namespace or title portion of a Wikipedia page name. :Return: string Normalized text """ r...
daa0349fbaa21c5edeb5ea8ca65f6b6c7fa8da91
26,093
import re def contentfilter(fsname, pattern): """ Filter files which contain the given expression :arg fsname: Filename to scan for lines matching a pattern :arg pattern: Pattern to look for inside of line :rtype: bool :returns: True if one of the lines in fsname matches the pattern. Otherwise...
ea30d6af9df3adc0986d9eaed9913f1160bd24d3
26,094
def con_per_dec(e): """convert p(a percentage) into a decimal""" return e / 100
62febf24b2ca8b38bc2b1f33d12d2b083a32fa5a
26,097
def is_defined_string(value): # pylint: disable=unused-variable """ Returns true if the specified value is a non-zero length String """ if isinstance(value, str) and value: return True return False
e5796f95dc46df17e874db04e0b79f94e35fb539
26,099
import csv def read_csv(file): """ Read a CSV file and return it as a list """ with open(file, 'r') as csvfile: reader = csv.reader(csvfile, delimiter=',') return list(reader)
31fc6f489cbebdb5e83a05bbb8ea3e09c41df6f1
26,104
def isurl(value): """ Determine if the parsed string is a url """ url = False if isinstance(value, str): if value[:4] == 'http' or value[:3] == 'www': url = True return url
58ef164aca40c3b6dd379ea20b798759dfd5e0e0
26,110
def ueGas(ub, umf, emf, delta, fw): """ This function calculates the velocity of the gas in the emulsion phase with K/L eqs. 6.39-6.40. Parameters ---------- ub : float Bubble rise velocity [m/s] umf : float Minimum fluidization velocity [m/s] emf : float Void fr...
c3756c353a7f317cf249db74f8e8f32503b00ea6
26,113
def track_objs(frame,frame_id,objects): """Perfrom tracking on every object in the frame Parameters ---------- frame : numpy array The input image to track the objects within frame_id : int The order of the frame in the video objects : list list of the current traffic ob...
1b65e8b50efbcd6d31b81208cf7da0f84b588bba
26,115
def delete_invalid_values(dct): """ Deletes entries that are dictionaries or sets """ for k, v in list(dct.items()): if isinstance(v, dict) or isinstance(v, set): del dct[k] return dct
eeadaeea809e7e38fcac7837981c3710b26817ae
26,116
def get_unique(list_): """Returnerar en lista där varje värde bara förekommer en gång. """ return list(set(list_))
b1380522fa407157d03b4d5b87daed73eed70b8d
26,117
def make_function_listener(events): """ Return a simple non-method extension point listener. The listener appends events to the ``events`` list. """ def listener(registry, event): events.append(event) return listener
b385d25eb98ee50f90d428b59cacb356144b2bb1
26,126
def generate_allocation_piechart(risk_prof): """ Queries for the ticker names and weights based on the user's risk profile and the profile's allocation. Returns a dictionary of dictionaries with "Stocks" and "Bonds" as the key with a value of ticker name as key and weight as value. """ ...
bbbb5b9dff82683fee508e5ac46fbd7e8971f426
26,131
import requests def get_target_chemblid(target_upid): """Get ChEMBL ID from UniProt upid Parameters ---------- target_upid : str Returns ------- target_chembl_id : str """ url = 'https://www.ebi.ac.uk/chembl/api/data/target.json' params = {'target_components__accession': targ...
5f1283ea1814e9c4be5c57af98e10c6cf238414e
26,132
def lcore_core_ids(lcore_mask_host): """ Convert CPU ID mask from argument 'lcore_mask' to a list of CPU IDs """ lcore_cores = [] binary_mask = bin(int(lcore_mask_host, 16))[2:] for i, val in enumerate(binary_mask[::-1]): if val == "1": lcore_cores.append(i) return lcore_cores
fe16d49b04a4a08fe6c9a0aacca91f5191738aca
26,135
def nd_normalize(x, mu, sigma): """Re-center and scale `x` given the mean (mu) and standard deviation (sigma) of the distribution of `x`. :param x: :param mu: :param sigma: """ return (x - mu) / sigma
8e664b1bbd976a353bb10cddd22d040bb7c03672
26,136
def get_item_by_id(test_item, item_id): """Return the requested test item by its identifier. Goes over the test item's sub tests recursively and returns the one that matches the requested identifier. The search algorithm assumes that the identifiers assignment was the default one (use of default in...
6c27b735cae3ae2f70650a14e9a8483fef7bd05d
26,137
import base64 def _encode(data): """Safely encode data for consumption of the gateway.""" return base64.b64encode(data).decode("ascii")
1b0403a46f65ac90e536c5fd700dfa26fb54865e
26,139
def __make_threephase_node_name(node_name_prefix, phase): """ Returns a node name with "phase" sufix and trailing whitespaces (6 characters). """ new_name = node_name_prefix + phase whitespaces = 6 - len(new_name) new_name = new_name + (" " * whitespaces) return new_name
580c838dace828c4fe2d35d148ddf2da6aa57a0a
26,143
def _compare_trigrams(trig1: set, trig2: set) -> float: """ Checks how many trigrams from the first set are present in the second and returns that value divided by the length of the second set. """ count = 0 for i in trig1: if i in trig2: count += 1 return count / len(tri...
f6887c1288abb22ca3caac444f20bbc4e51d4541
26,146
def get_epoch_from_header(sig_header: str)-> str: """Extracts epoch timestamp from the X-Telnyx-Signature header value""" sig_key_value = dict(param.split("=", 1) for param in sig_header.split(",")) epoch = sig_key_value["t"] return epoch
1829807121802d149547ad90c4427a8550e46d85
26,147
def test_agent(env, agent, num_rollouts=20): """ This function runs `num_rollouts` using the current agent's policy. :param env: environment to test the agent in (gym.Env) :param agent: Agent to predict actions (DQNAgent) :param num_rollouts: number of episodes to play (int) :return: average_rew...
ba2f65d6220ac225df5189c1d10d55dbe9d608b6
26,148
import yaml def get_dependency_graph(path="configs/dependency-graph.yaml"): """Load dependency_graph file Parameters ---------- path : str, optional dependency-graph.yaml path, by default 'configs/dependency-graph.yaml' Returns ------- dict variables from dependen...
e1bac88e50e0d7bdf24e2a64d7ae8d2e9d2bd830
26,151
def stats_to_list(stats_dict): """ Parse the output of ``SESConnection.get_send_statistics()`` in to an ordered list of 15-minute summaries. """ result = stats_dict['GetSendStatisticsResponse']['GetSendStatisticsResult'] datapoints = [dp for dp in result['SendDataPoints']] datapoints.sort(k...
9a0b1709eedec66edca722d60578a2ba2385cc9d
26,153
def indexToSymbol(index): """ returns the nucleotide symbol for an index in the alphabetic order """ if index == 0: return 'A' elif index == 1: return 'C' elif index == 2: return 'G' elif index == 3: return 'T' else: print('number should be 0 to 3, it is ' + str(index)) ...
80f693372919abf3090d54c99d394b05afc5351e
26,156
def to_byte_string(value, count=2, signed=False, byteorder='little'): """Take bytes and return string of integers. Example: to_byte_string(123456, count=4) = '64 226 1 0' """ byte_value = value.to_bytes(count, byteorder=byteorder, signed=signed) return ' '.join([str(x) for x in byte_value])
d1b2cc12000958a3858f73271b300ebe15480a43
26,157
def search_error_for_adams(adams_results: list, adams_results_less: list, m: int) -> list: """ Function for calculating errors for Adams method :param adams_results: results from this method :param adams_results_less: results from this method with divided step :param m: value for the fault :retu...
d63cffa19c840ca8bf3fe3d7b236e999b214317c
26,158
def count_increases(depths: list): """ Count the number of times a value is greater than the previous value. :param depths: list of depths :return: number of times depth increased :rtype: int """ increases = 0 previous = None for depth in depths: depth = int(depth) ...
43dc82d403747aaa36f2e0bd794e1d3f840bc5da
26,159
def get_ha1_file_htdigest(filename): """Returns a get_ha1 function which obtains a HA1 password hash from a flat file with lines of the same format as that produced by the Apache htdigest utility. For example, for realm 'wonderland', username 'alice', and password '4x5istwelve', the htdigest line would ...
bd79458b89556b570338f3365d0a4ee6582f8aa0
26,160
import six def ExtractSnapshotTtlDuration(args): """Extract the Duration string for the Snapshot ttl. Args: args: The command line arguments. Returns: A duration string for the snapshot ttl. """ return six.text_type(args.snapshot_ttl) + 's'
0816e2e24ccdeceeeb3154c55288dc6733c042ff
26,163
def shuffle(n_cards, actions): """ Return (a, b) such that for any card, shuffled_position = (a * initial_position + b) % n_cards """ a, b = 1, 0 for action in actions: if action.startswith("deal with increment"): n = int(action.split()[-1]) a *= n b *= n ...
2e3e159ac44b32742015914360d0d6774fc4fddb
26,164