content
stringlengths
39
14.9k
sha1
stringlengths
40
40
id
int64
0
710k
def nearest(last, unvisited, D): """Return the index of the node which is closest to 'last'.""" near = unvisited[0] min_dist = D[last, near] for i in unvisited[1:]: if D[last,i] < min_dist: near = i min_dist = D[last, near] return near
8b9ad31fbcba52ee9b9bfbf7c2b0caa78959e6dc
695,865
import hashlib def md5_file_hash(file_path): """ A method generating MD5 hash of the provided file. :param file_path: file's path with an extension, which will be opened for reading and generating md5 hash :return: hex representation of md5 hash """ hash_md5 = hashlib.md5() with open(file...
be8241fd0c254bbfc4d0e1e4330cf36228e0a040
695,868
def line_coeff_from_endpoints(p1, p2): """Given two points on a line, find the coefficients of the line equation ax + by + c = 0""" a = p1.y - p2.y b = p2.x - p1.x c = -a * p1.x - b * p1.y return a, b, c
fdbed65cbd3dbabd920817367005c8f05c7dadaf
695,869
import math def butterfly(theta: float) -> float: """Butterfly function""" return math.e ** math.sin(theta) - 2 * math.cos(4 * theta)
5d48df3df396fd666770f61e841b3dee2e967ab9
695,870
from typing import List from typing import Optional from typing import Set def create_exp_name(flags_and_values: List[str], flag_skip_set: Optional[Set[str]] = None, skip_paths: bool = False) -> str: """ Creates an experiment name based on the command line arguments (be...
e8c6c114a62146a5a3200e88315b1921c28b258f
695,871
def bisect_left(func, val, low, high): """ Like bisect.bisect_left, but works on functions. Return the index where to insert item x in list a, assuming a is sorted. The return value i is such that all e in a[:i] have e < x, and all e in a[i:] have e >= x. So if x already appears in the list, a.in...
de7b72585657c183176b4cd1c6b5301e0f837a01
695,873
def is_shared(resource): """Checks if a resource is shared """ return resource['object'].get('shared', False)
dd54a631cff0e79b00942ca4b1e43b1fb2a70c04
695,874
def h1(curr_state, goal_dict): """ Heuristic for calculating the distance of goal state using Manhattan distance Parameters: curr_state(np.ndarray): A 3x3 numpy array with each cell containing unique elements goal_dict(dict[int, tuple[int, int]]): A mapping of cell contents to a tuple conti...
e7d353dcfe5dacee5319dc7b8c4fbae43294acd3
695,879
import importlib def plugin_import(plugin): """Import a plugin from string. :param plugin: Python import in dot notation. :type plugin: String :returns: Object """ return importlib.import_module(plugin, package="directord")
147c1c053eda10935c1f597cbde1a2d71451f843
695,880
def Edges_Exist_Via(G, p, q): """Helper for del_gnfa_states --- If G has a direct edge p--edgelab-->q, return edgelab. Else return "NOEDGE". We maintain the invariant of at-most one edge such as edgelab for any p,q in the GNFA. """ edges = [ edge for ((x, edge), St...
53af339eb5317321a8f125a289215bff89a95b5d
695,887
import csv import requests def get_words(min_length=5,max_length=5,capitalization='lower',use_file=''): """Gets a list of english words from instructables of a desired length. Args: min_length (int, optional): Keep words of this length or longer. Defaults to 5. min_length (int, optional): Kee...
ceeacd7772ced20c86d3a66cb966cb25ea286d85
695,888
import hashlib import binascii def multipart_etag(digests): """ Computes etag for multipart uploads :type digests: list of hex-encoded md5 sums (string) :param digests: The list of digests for each individual chunk. :rtype: string :returns: The etag computed from the individual chunks. ""...
1d6d13d3f28cdbae6a56fe903329bd8f91b53000
695,889
def Tsorties_echangeur(Te1,Te2,mf1,mf2,Cp1,Cp2,eff): """ Calcul les températures au niveau des sorties d'un échangeur thermique' Parameters ---------- Te1 : Température d'entrée du fluide chaud Te2 : Température d'entrée du fluide froid mf1 : Débit massique du fluide chaud mf2 : Débi...
ebae4e1f99bc0eea1941e85dbd5087f825bb5105
695,890
import json def load_schema(filename): """Load schema from a JSON file. Parameters ---------- filename : str The path to your file. Returns ------- schema : dict A dictionary containing the schema for your table. """ with open(filename) as f: schema = jso...
55b475a4cc7bfb184c0f2db3e41d6e3408b888e6
695,891
import inspect def get_linenumbers(functions, module, searchstr='def {}(image):\n'): """Returns a dictionary which maps function names to line numbers. Args: functions: a list of function names module: the module to look the functions up searchstr: the string to search for Retu...
b2cc1bc104cdae6bbbfb3680ac940540396db08a
695,893
def get_lrs(optimizer): """Return the learning-rates in optimizer's parameter groups.""" return [pg['lr'] for pg in optimizer.param_groups]
6e32c90e42321d070cc1f444a6f117b72ad59adb
695,895
def highlight_min(s): """ highlight the minimum in a Pandas dataframe series yellow """ is_min = s == s.min() return ["background-color: yellow" if v else "" for v in is_min]
ee74a19721fc7312744847b0c4d6de9255f312b0
695,896
import torch def Rotz(t): """ Rotation about the z-axis. np.array([[c, -s, 0], [s, c, 0], [0, 0, 1]]) -- input t shape B x 1 -- return B x 3 x 3 """ B = t.shape[0] Rz = torch.zeros((B, 9, 1), dtype=torch.float) c = torch.cos(t) s = torch.sin(t) ones = torch.ones(B) Rz[:, 0, 0] = c Rz[:, 1, 0]...
6a078e033f6ad6b497da05999433ef745c76d2ed
695,897
import tokenize import codecs def read_pyfile(filename): """Read and return the contents of a Python source file (as a string), taking into account the file encoding.""" with open(filename, "rb") as pyfile: encoding = tokenize.detect_encoding(pyfile.readline)[0] with codecs.open(filename, "r",...
a6fce0f2acdb5156872ef572ab7e77ba6507873d
695,901
def parse_version_string(version): """ Returns a tuple containing the major, minor, revision integers """ nums = version.split(".") return int(nums[0]), int(nums[1]), int(nums[2])
a8d50804ebe82541e57c83a813843d255b3b6fbb
695,902
def get_building_coords(town): """ Generates a dictionary of all (x,y) co-ordinates that are within buildings in the town, where the keys are the buildings' numbers (or "pub" for the pub) and the values are lists of co-ordinates associated with the building. Data must have 25 houses (numbered as mu...
085c95d40d9d84569180155f5b0b150334dbc526
695,908
def promptConfirm(message: str) -> bool: """ Prompts confirming a message. Defaults to "no" (False). :param message: Message to prompt. :return: Whether the prompt was confirmed. """ result = input(message + " (y/N): ").strip().lower() return result == "y" or result == "yes"
4d0ba40150231939571915676740a1e6b5857f0d
695,912
def _check_state(monomer, site, state): """ Check a monomer site allows the specified state """ if state not in monomer.site_states[site]: args = state, monomer.name, site, monomer.site_states[site] template = "Invalid state choice '{}' in Monomer {}, site {}. Valid " \ "state...
8f61c91ddae5af378503d98377401446f69c37db
695,914
import unicodedata def unicode_to_ascii(s): """ Takes in a unicode string, outputs ASCII equivalent :param s: String of unicode :return: String of ASCII """ return ''.join(c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn')
03781e1286aef5a67ea389dad4fcf59cc9317f23
695,916
def image_layers(state): """Get all image layer names in the state Parameters ---------- state : dict Neuroglancer state as a JSON dict Returns ------- names : list List of layer names """ return [l["name"] for l in state["layers"] if l["type"] == "image"]
6c843855e01957386871f90d54eee69800f08c37
695,923
import requests def coordinate_finder(result: requests.Response) -> tuple: """ One filter function for the send_get_request function. This filter function is used for getting a tuple (lat, long) from the wikipedia geoData api with type props=coordinate. More information found: https://www.mediawiki.or...
3069e7c3782d292fc708f79a7d178a4b4f40ebb7
695,928
def filter_merge_clusters(clusters, max_block_size_multi=5, min_block_pop=50, buffer_amount=150): """ The vectors created by create_clusters() are a single square for each raster pixel. This function does the follows: - Remove overly large clusters, caused by defects in the input raster. - Remove clusters with pop...
8b6091baeb55e0c72c468aa6eb4300c4db40ecbd
695,931
import pickle def load(path): """ Load pickled pandas object (or any other pickled object) from the specified file path Parameters ---------- path : string File path Returns ------- unpickled : type of object stored in file """ f = open(path, 'rb') try: ...
6ed0b0ae944fa8bdaacfd4cbd8cdb3864f1adb47
695,934
def get_y_indicator_variable_index(i, j, m, n): """ Map the i,j indices to the sequential indicator variable index for the y_{ij} variable. This is basically the (2-dimensional) 'array equation' (as per row-major arrays in C for example). Note that for MiniSat+, the variables are juist indexed...
8c6dc999ebe3120084ae741403f15acdd900e783
695,936
def truncate_string(s,length): """ Truncate string to given length. """ return s[0:min(length,len(s))]
9b44cf31c7905109497e485d0ffa707dada9d67b
695,937
import torch def inverse_sigmoid(x, eps=1e-5): """Inverse function of sigmoid. Args: x (Tensor): The tensor to do the inverse. eps (float): EPS avoid numerical overflow. Defaults 1e-5. Returns: Tensor: The x has passed the inverse function of sig...
01d02c9f04d4a9318f0ec0d4bb8cf7301181c8f5
695,939
def get_best_sales_rep(df): """Return a tuple of the name of the sales rep and the total of his/her sales""" best_rep_df = df.groupby(['Rep'])['Total'].sum() return (best_rep_df.idxmax(), best_rep_df.loc[best_rep_df.idxmax()]) pass
e4313cf517ecb513918944fdbb55caea3f20fb0c
695,942
def _solveX(L, U, b): """Use forward and backwards substitution to calculate the x vector to solve the linear system of equations. Parameters ---------- L: numpy.arrays Lower triangular matrix U: numpy.arrays Upper triangular matrix b: numpy.array Column vector of constant terms Returns ------- x: nu...
997b472ea45796268a1d87c5ade3de4ab66115a0
695,944
def nearest_square(num): """ Find the nearest square number to num """ root = 0 while (root + 1) ** 2 <= num: root += 1 return root ** 2
53b899958a053c8bfe6383e240d3b8ddb7d291c1
695,945
import socket def create_rawsock(iface): """Creates a new raw socket object. The socket sends/receives data at the link layer (TCP/IP model)/data-link layer (OSI model). Args: iface: A string specifying the name of the network interface to which the raw socket should be ...
ea56408403ada6b9750265547677028c197ae933
695,946
def vector_mul(k, a): """Multiplication of a vector by a scalar. >>> vector_mul((1, 2), 2) (2, 4) """ return tuple(map(lambda x: k * x, a))
cdc289430ab87ac70e8387d4dd807fb4dfd1e1da
695,949
import math def replace_invalid_values(row): """Replace float values that are not available in BigQuery. Args: row: List of values to insert into BigQuery. Returns: List, `row` with invalid values replaced with `None`. """ invalid_values = [math.inf, -math.inf, math.nan] return [x if x not in in...
c07c16780a52870f9d0954b3f8bba5a91baf6b58
695,954
def interp_from_u(idx, w, y): """ compute Wy W.shape: (n, u) y.shape: (u,) """ return (y[idx] * w).sum(axis=1)
b0312063699a16a75307774dbf54cb758082d678
695,959
def A004767(n: int) -> int: """Integers of a(n) = 4*n + 3.""" return 4 * n + 3
5f97cccc4f540b46029e57c11d1ab718a59e227c
695,961
import random def get_random_string(length=10): """ Generates a random string of fixed length """ string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" return ''.join(random.choice(string) for i in range(length))
043f7ef3b495c199825242ffd55fabf9e7c1cda7
695,971
def assemble_api_url(domain, operators, protocol='https'): """Assemble the requests api url.""" return '{}://{}{}'.format(protocol, domain, operators)
105d541f2e9196583b2fd5eac1af75cf4c62669f
695,979
from datetime import datetime import uuid def generate_ami_name(prefix): """ Generate AMI image name. """ # current date and time now = datetime.now() s2 = now.strftime("%Y%m%d%H%M%S") x = uuid.uuid4().hex postfix = str(x)[:10] ami_name = prefix + "-" + s2 + "-" + postfix return ami_name
50cf4e6f8ab55b252503319429594242cea9a77e
695,980
def _cap_str_to_mln_float(cap: str): """If cap = 'n/a' return 0, else: - strip off leading '$', - if 'M' in cap value, strip it off and return value as float, - if 'B', strip it off and multiple by 1,000 and return value as float""" if cap == "n/a": return 0 capital = ...
a4c984013ba7c1e06b3569f61d65fe69d98ae2da
695,981
def bed_get_region_id_scores(in_bed, no_float=False): """ Read in .bed file, and store scores for each region in dictionary (unique column 4 ID and column 5 score have to be present). Return dictionary with mappings region ID -> region score >>> test_bed = "test_data/test5.bed" >>> bed_get_regi...
cd4305388251ab9ff9d301ff4bf0409783d1bcfd
695,984
import json def put_json(client, url, data, headers={}): """Send PUT request with JSON data to specified URL. :url: URL string :data: Data dict :headers: Optional headers argument (usually will be authorization) :returns: Flask response object """ return client.put(url, data=json.dumps(dat...
e5fff7c1fdc9cf72e8b314854415c9426e5b261b
695,985
def sipi(b3, b4, b8): """ Structure Intensive Pigment Index \ (Peñuelas, Baret and Filella, 1995). .. math:: SIPI = b3/b8 - b4 :param b3: Green. :type b3: numpy.ndarray or float :param b4: Red. :type b4: numpy.ndarray or float :param b8: NIR. :type b8: numpy.ndarray or float ...
b0a7181970e9165d0e75ab7319646fd6bd1c6bbd
695,986
import random def random_nucleotides(sample_size: int, seq_length: int, seed: int = 1789): """ Return a random list of DNA nucleotides sequences. Args: sample_size: generate N random sequences. seq_length: set sequence length. seed: random seed for reproducibility. Returns: ...
ce283d43495fa53be4276cf0ab3c6793e053a723
695,987
def populate_game_starting_lineups(gl, games, player_id): """ Populates all the starting lineups in a game by updating the "teams" dictionary in each Game object, with key = team_id, value = [list of player_ids on that team] Every "teams" dictionary has two keys because two teams play in a game Each ke...
9de9be892765581a4c74d060979d086a0bf6031c
695,989
def clean_venue_name(venue_name: str) -> str: """Clean the venue name, by removing or replacing symbols that are not allowed in a file name. Args: venue_name: Original venue name. Returns: Cleaned venue name. """ return venue_name.replace("*", "").replace("/", "_").replace(" ", "_"...
90b6f8b3787af17750c548bb816383bf8a5b07a4
695,990
def get_border(char, length): """Get a border consisting of a character repeated multiple times. :param char: The character to make up the border. :param length: The length of the border. :return: A string consisting of the character repeated for the given length. """ border = '' for i in r...
9cd73504dc450e1e31c75b398240a27184a130e4
695,996
from typing import Iterable def hash_from_dict(dictionary): """ Creates a hashable string from a dictionary that maps values to their assignments. Ex: dictionary={"A": 1, "B": 5, "C": 1} => "A=1,B=5,C=1" """ hashstring = "" for i, key in enumerate(sorted(list(dictionary.keys()))): hashstring +...
1e906f178a6353e9bdac7bed929be1e0f16ae060
696,002
def almost_equal_floats(value_1: float, value_2: float, *, delta: float = 1e-8) -> bool: """ Return True if two floats are almost equal """ return abs(value_1 - value_2) <= delta
ff1c29c57434a169824fe76e451053f3edc6e519
696,006
def stationObjectsByRiver(stations, rivers): """Returns a list of Monitoring Station objects which are on the rivers input""" stationObjectsByRiverOutput = [] for river in rivers: for station in stations: if station.river==river: stationObjectsByRiverOutput.append(station...
882c42acf4ef1d9af2aec8a1c4090f8bca4322e7
696,007
from typing import Tuple def _yymmdd2ymd(yymmdd: int) -> Tuple[int, int, int]: """yymmdd -> (year, month, day) Examples: >>> _yymmdd2ymd(321123) (32, 11, 23) >>> _yymmdd2ymd(320323) (32, 3, 23) """ year, mmdd = divmod(yymmdd, 10000) month, day = divmod(mmdd, 100) ...
9e9d3fa20b4684b603a203c5cc8c8284a8f45dd7
696,008
def sqliteRowToDict(sqliteRow): """ Unpacks a single sqlite row as returned by fetchone into a simple dict. :param sqliteRow: single row returned from fetchone DB call :return: dictionary corresponding to this row """ return dict(zip(sqliteRow.keys(), sqliteRow))
979bb63142a797749937ee382d9b9eb1c26dd7bd
696,013
def _get_average_score(concept, _keywords): """Get average score of words in `concept`. Parameters ---------- concept : str Input text. _keywords : dict Keywords as keys and its scores as values. Returns ------- float Average score. """ word_list = conc...
ce930ae5871dfc218ae5f057f7dc76d64671a7f6
696,015
from datetime import datetime def get_start_next_month(date): """ Parameters ---------- date: datetime.datetime Returns ------- datetime.datetime date of the start of the next month """ if date.month+1 <= 12: return datetime(date.year,date.month+1,1) return d...
737ace5854593007ff62d169c3b69f3118056be1
696,019
def computePoint(triangle): """ Computes the last point D in an ABC square triangle where a and c are the diagonal - triangle = [a,b,c] D--- C | / | | / | |/ | A----B """ # get coordinates of each point a, b, c a, b, c = triangle xa, ya = a x...
e7b37852440eaf43844d5d6e1cd2c2921bc9e6b3
696,020
def get_metric_scores(ground_truth, simulation, measurement, metric, measurement_kwargs={}, metric_kwargs={}): """ Function to combine measurement and metric computations :param ground_truth: pandas dataframe of ground truth :param simulation: pandas dataframe of simulation :param measurement: meas...
4087e60ce0578d11756f449e776e01ee81b6e4ac
696,025
import json def util_json_get_value ( s_json, key ): """Returns value for supplied key in JSON document""" try: t = json.loads(s_json, strict=False) except ValueError: return '' try: value = t[key] except KeyError: return '' return value
773ae165ac58f4ac20772d5c344aca241c74786c
696,034
import hashlib import json def treehash(var): """ Returns the hash of any dict or list, by using a string conversion via the json library. """ return hashlib.sha256(json.dumps(var, sort_keys=True).encode("utf-8")).hexdigest()
e196a8d601b59a893bf05bc903aa7e3af4927cef
696,038
def is_float(dtype): """Return True if datatype dtype is a float kind""" return ('float' in dtype.name) or dtype.name in ['single', 'double']
3c6301e6d89fb8d825ac4181ca02b5cf95028066
696,041
def _find_method(obj, string): """Find methods in object that starts with `string`. """ out = [] for key in dir(obj): if key.startswith(string): out.append(getattr(obj, key)) return out
1250a6dc39d2ac47ca4a5e561f55f4fb2b456c96
696,042
def split_list(ls, size): """ Split list :param list ls: list :param int size: size :return list: result >>> split_list([1, 2, 3, 4], 3) [[1, 2, 3], [4]] """ if size == 0: return ls return [ls[i:i + size] for i in range(0, len(ls), size)]
de28981d576122f99be34a57c94d73457b63c04b
696,046
def getColumnsEndingAt(columns, zLevel): """Returns columns w/ endPoint at zLevel""" columnGroup = {} for columnID, column in columns.inventory.iteritems(): diff = abs(zLevel - column.endJoint.z) if diff <= 0.001: columnGroup[column.uniqueName] = column return columnGroup
4f6b7aac922bd5985b6faeb509d26bf6aec98629
696,047
def hpo_job_describe(sm_client, tuning_job_name): """API call to describe a hyperparameter tuning job.""" try: response = sm_client.describe_hyper_parameter_tuning_job( HyperParameterTuningJobName=tuning_job_name ) return response except sm_client.exceptions.ResourceNotFound: raise Exception...
98bb1ad03883e862a8730ec4740c3bb92b1a4830
696,050
import traceback def tb_log_str(exception) -> str: """ Format an exception as a full traceback. """ return "".join(traceback.format_exception(None, exception, exception.__traceback__))
6776a7416cb512bf23e6557833e3a95779172bd4
696,051
import requests def get_agol_token(username, password): """ purpose: get a security token from ArcGIS Online arguments: username: string password: string return value: string token, None if error """ try: url = "https://www.arcgis.com/sharing/rest/gener...
9086fbb7e199c7dd9410bfe4f89b65d34a2424be
696,055
def read_grammar(grammar_file): """ Reads in the given grammar file and splits it into separate lists for each rule. :param grammar_file: the grammar file to read in. :return: the list of rules. """ with open(grammar_file) as cfg: lines = cfg.readlines() return [x.replace("->", "").s...
c9320a4126ed6bc05a5df8b05c9997890c7f620a
696,059
from pathlib import Path def list_files(dirpath: str, pattern: str = "*.csv") -> list: """ List files in a directory """ file_names = list(Path(dirpath).glob(pattern)) return file_names
0c291d6818c38f6f9219f92b900e5fd8ed5960d6
696,060
def _plot(ax, coords, pos_columns, **plot_style): """ This function wraps Axes.plot to make its call signature the same for 2D and 3D plotting. The y axis is inverted for 2D plots, but not for 3D plots. Parameters ---------- ax : Axes object The axes object on which the plot will be cal...
80cadfff00f864b9d38e51768e68674dfc981a06
696,062
def get_i_colour(axis_handle) -> int: """ Get index appropriate to colour value to plot on a figure (will be 0 if brand new figure) """ if axis_handle is None: return 0 else: if len(axis_handle.lines) == 0: return 0 else: return len(axis_handle.lines)-1
b5001da3325168e0f359596bfe65487708f59e3b
696,064
def read_all(port, chunk_size=200): """Read all characters on the serial port and return them.""" if not port.timeout: raise TypeError('Port needs to have a timeout set!') read_buffer = b'' while True: # Read in chunks. Each chunk will wait as long as specified by # timeout. In...
cf894c2449fa4eba763dc7bf4da86b0072a78a19
696,065
import base64 import pickle def encode_store_data(store_data): """ Encode store_data dict into a JSON serializable dict This is currently done by pickling store_data and converting to a base64 encoded string. If HoloViews supports JSON serialization in the future, this method could be updated to ...
0a576a8146c0657610b508ebc6338d3ed6790b70
696,066
def find_feature_by_gi(gid, record, ftype): """ Loops over the ftype features in the passed SeqRecord, checking db_xref qualifiers for a match to the passed gid. Returns the first feature identified, or None if no feature found. """ for feature in [f for f in record.features if f.type == fty...
050c5464a8d425f5db53440abd79c64b2938f81b
696,070
def loglik_nats(model, x): """Compute the log-likelihood in nats.""" return - model.log_prob(x).mean()
f929be38cb70fe56b6bb1a0e5cc21cf02fead3b6
696,072
def _get_item(node): """ Returns the item element of the specified node if [the node] is not null. :param node: The node to extract the item from. :return: A node's item. """ return node.item if node is not None else None
42dff5ef2e98a0dd78b822ee29a75c72d737e23f
696,075
def change_action_status(action_type, new_status): """ This function changes the status of an action type. """ # replace the last bit of a dot separate string with the new_status return "%s.%s" % ('.'.join(action_type.split('.')[:-1]) , new_status)
1032486b1f5b32a36806d397a68f42f549b6228c
696,077
def extract_x_positions(parameter, joining_string="X"): """ find the positions within a string which are X and return as list, including length of list :param parameter: str the string for interrogation :param joining_string: str the string of interest whose character positions need to ...
5843d7a86823b960bb1c99379174f60697850378
696,080
def char2cid(char, char2id_dict, OOV="<oov>"): """ Transform single character to character index. :param char: a character :param char2id_dict: a dict map characters to indexes :param OOV: a token that represents Out-of-Vocabulary characters :return: int index of the character """ if cha...
4a872cb12f11ed8ba2f3369749a3a2f356b7b97e
696,081
import re def extractCN(dn): """Given the dn on an object, this extracts the cn.""" return re.findall('CN=(.*?),', dn)[0]
dad91c436b5035664dd6d463e0e626949b6cd838
696,086
def packRangeBits(bitSet): """Given a set of bit numbers, return the corresponding ulUnicodeRange1, ulUnicodeRange2, ulUnicodeRange3 and ulUnicodeRange4 for the OS/2 table. >>> packRangeBits(set([0])) (1, 0, 0, 0) >>> packRangeBits(set([32])) (0, 1, 0, 0) >>> packRangeBi...
a4484da8635efe9c1ddc5259563ff6db5b2b5ed4
696,087
def reward_min_waiting_time(state, *args): """Minimizing the waiting time. Params: ------ * state: ilurl.state.State captures the delay experienced by phases. Returns: -------- * ret: dict<str, float> keys: tls_ids, values: rewards """ try: wait_times = sta...
85e88f15e560d761ac59bdbd31bfb78cdfe6936f
696,088
from pathlib import Path import yaml def get_config(base_path: Path): """ Get the config file from the base path. :param base_path: The base path to the .fsh-validator.yml File. :return: Configuration """ config_file = base_path / ".fsh-validator.yml" if not config_file.exists(): ...
694aad52afda7588d44db9f22cc31f05e64358ac
696,091
def _combine_ind_ranges(ind_ranges_to_merge): """ Utility function for subdivide Function that combines overlapping integer ranges. Example [[1,2,3], [2,3], [3], [4,5], [5]] -> [[1,2,3], [4,5]] """ ind_ranges_to_merge = sorted(ind_ranges_to_merge) stack = [] result = [] for curr...
fcece4c58a0d231863b0bfb22bd3ff20bcd5858e
696,092
import hashlib def get_md5_hash(to_hash): """Calculate the md5 hash of a string Args: to_hash: str The string to hash Returns: md5_hash: str The hex value of the md5 hash """ return hashlib.md5(to_hash.encode('utf-8')).hexdigest()
118b5b87500b22780f541fa46ad54361c7e7440e
696,095
def calc_tile_locations(tile_size, image_size): """ Divide an image into tiles to help us cover classes that are spread out. tile_size: size of tile to distribute image_size: original image size return: locations of the tiles """ image_size_y, image_size_x = image_size locations = [] ...
fa898d2b5da4a6d6482d52238eecd1460bd0d167
696,096
def join(G, u, v, theta, alpha, metric): """Returns ``True`` if and only if the nodes whose attributes are ``du`` and ``dv`` should be joined, according to the threshold condition for geographical threshold graphs. ``G`` is an undirected NetworkX graph, and ``u`` and ``v`` are nodes in that graph. ...
8968ea954be10cf3c3e2ed2c87748b00da0d850a
696,101
def epsg_for_UTM(zone, hemisphere): """ Return EPSG code for given UTM zone and hemisphere using WGS84 datum. :param zone: UTM zone :param hemisphere: hemisphere either 'N' or 'S' :return: corresponding EPSG code """ if hemisphere not in ['N', 'S']: raise Exception('Invalid hemisphere ("N" or "S").') ...
c448ffd7b18e605f938c7e8fa294a29218f74d36
696,102
def estimate_flag(bflag, corr_moments, cr_moments, cr_ldr, bounds_unfiltered_moments): """retrieve the integer flag from the binary flag the available integer flags are: .. code-block:: python {0: 'not influenced', 1: 'hydromet only', 2: 'plankton', 3: 'low snr', 4: '', 5: 'melt...
8e600a4972de64cb0171239359b5609779723eab
696,103
import torch def _safe_check_pinned(tensor: torch.Tensor) -> bool: """Check whether or not a tensor is pinned. If torch cannot initialize cuda, returns False instead of error.""" try: return torch.cuda.is_available() and tensor.is_pinned() except RuntimeError: return False
6d023bf0554ac41834f421d07ea7959952dcc9e8
696,105
def sum_list(list_to_sum): """Function to sum the items in the input list.""" return sum(list_to_sum)
e4a922888d9ed229b0c74b4e9006cae7ba02c976
696,110
import torch def numpy_to_tensor(data): """Transform numpy arrays to torch tensors.""" return torch.from_numpy(data)
06c2aee2081bbb017d9b33065c6925c589378df9
696,111
def asint(x): """Convert x to float without raising an exception, return 0 instead.""" try: return int(x) except: return 0
b8ebcd4efc43c24726d35f7da80a5001b44b6f17
696,116
import typing def sort(array: list) -> list: """Insertion sort implementation. """ for j in range(1, len(array)): key: typing.Any = array[j] i: int = j - 1 while i > -1 and key < array[i]: array[i + 1] = array[i] i = i - 1 array[i + 1] = key retu...
f3d36f95f3b7fc3e64593e23b9a21544fc880383
696,118
def line_width( segs ): """ Return the screen column width of one line of a text layout structure. This function ignores any existing shift applied to the line, represended by an (amount, None) tuple at the start of the line. """ sc = 0 seglist = segs if segs and len(segs[0])==2 and segs[0][1]==None: seglist...
7f6585126a0ecdbab4d1d371e23ddc279dce5b75
696,119
def compute_opt_weight(env, t): """ Computes the optimal weight of the risky asset for a given environment at a time t. Arguments --------- :param env : Environment instance Environment instance specifying the RL environment. :param t : int Period in episode for which...
92a05ea1172871328ab88ac990ed760012634018
696,120
def is_palindrome(string: str) -> bool: """ Test if given string is a palindrome """ return string == string[::-1]
1a94f7f2889d6d13080198729825347b939a0a68
696,124
def _format_s3_error_code(error_code: str): """Formats a message to describe and s3 error code.""" return f"S3 error with code: '{error_code}'"
9498a531392f0f18e99c9b8cb7a8364b0bff1f9a
696,126
import hashlib def hash_ecfp_pair(ecfp_pair, size): """Returns an int < size representing that ECFP pair. Input must be a tuple of strings. This utility is primarily used for spatial contact featurizers. For example, if a protein and ligand have close contact region, the first string could be the protein's ...
b2e4107ee59ce2c801d10b832e258d567875d987
696,128