content
stringlengths
39
9.28k
sha1
stringlengths
40
40
id
int64
8
710k
def extract_model_parameters(state_dict): """ Extracts model parameters from saved PyTorch state_dict :param state_dict: Result from torch.load() :return: Scale factor of pretrained model """ if state_dict['module.tail.0.0.weight'].shape[0] == 2304: scale = 3 elif 'module.tail.0.2.we...
360bb6578cc85c3c2af6bf5415226ee2ec70733d
452,589
def is_empty(value: object) -> bool: """ Check if value is None or not empty in case if not None. """ return (value is None) or (not value)
88b848e6a25da134a3408def4db83d258a031919
677,108
def listify(obj) -> list: """Converts obj to a list intelligently. Examples -------- Normal usage:: listify('str') # ['str'] listify((1, 2)) # [1, 2] listify(len) # [<built-in function len>] """ if isinstance(obj, str): return [obj] try: retur...
82e3110f29da0eb85c176c4ea8783ce22ff93e93
324,895
def split_train_test(X, y, test_percentage): """ Randomly split given dataset into training- and testing sets :param X: Design matrix to split :param y: Response vector to split :param test_percentage: Percentage of samples to use as test :return: Two tuples of: (train set X, train set y), (test...
7f98f9bb5ef9376308da9e10518c94ee1680f71e
688,417
from textwrap import dedent def dedent_docstring(docstring): """This removes initial spaces from the lines of the docstring. After the first line of the docstring, all other lines will include some spaces. This removes them. Examples -------- >>> from _pyodide.docstring import dedent_docstri...
8e727f56561d715ea9de1a6e93d4f5cbc6abe764
471,503
def move_to_next_pixel(fdr, row, col): """ Given fdr (flow direction array), row (current row index), col (current col index). return the next downstream neighbor as row, col pair See How Flow Direction works http://desktop.arcgis.com/en/arcmap/latest/tools/spatial-analyst-toolbox/how-flow-direction-w...
d134bb35ed4962945c86c0ac2c6af1aff5acd06b
707,105
def roundplus(number): """ given an number, this fuction rounds the number as the following examples: 87 -> 87, 100 -> 100+, 188 -> 100+, 999 -> 900+, 1001 -> 1000+, ...etc """ num = str(number) if not num.isdigit(): return num num = str(number) digits = len(num) rounded...
895704e849694927ac391a06a95e40f52f6fec21
157,424
def _find_config(pav_cfg, conf_type, conf_name): """Search all of the known configuration directories for a config of the given type and name. :param pav_cfg: The pavilion config data. :param str conf_type: 'host', 'mode', or 'test' :param str conf_name: The name of the config (without a file extens...
0f2dcbbdb3ac77717bd89a7f1b5ac3e3d17464f2
301,069
import copy def get_category_obj(data, category_name): """Extract obj with `name` == `category_name` from `data`.""" cats = copy.copy(data) while(cats): cat = cats.pop() if cat['name'] == category_name: return cat if 'children' in cat: cats.extend(cat['child...
82782dba9ae9374abc5e3f510ba53f9e03e14a62
666,937
import torch def DH(theta, d, r, alpha, device): """ Calculates the Denavit-Hartenberg Matrix where d: offset along previous z to the common normal theta: angle about previous z, from old x to new x r: length of the common normal (aka a, but if using this notation, do not confuse with al...
9b40c28bbe93e2b3b08be4e171ec0d0aebe14810
329,142
import json def to_json(raw_data): """ Pretty-prints JSON data :param str raw_data: raw JSON data """ return json.dumps(raw_data, sort_keys=True, indent=4, separators=(',', ': '))
9faf1a31e2f906e8170226d81160a5523c201566
673,725
def get_max(list_of_string): """Return maximum value from a list of string or integer """ return max(map(int, list_of_string))
cd4a3cbf67b3d2c663ff45ac294b1ac6f2678062
125,006
def replace_conditional(record: dict, field: str, value: str, replacement: str): """ Function to conditionally replace a value in a field. Parameters ---------- record : dict Input record. field : str Key of field to be conditionally altered. value : str Value to ide...
4f3e25c5ca174289de3154332bfeac988391979e
135,365
def retrive_bgp_neighbor(bgp_data, neighbor): """ Parse the output from NAPALM's get_bgp_neighbors() Retrieve the specified neighbor's BGP dictionary. """ return bgp_data['global']['peers'][neighbor]
c733c6518849f0e342173df6feb58b0708f7a514
189,045
from operator import and_ def e(*operands): """ Alias for and_(). """ return and_(*operands)
360ba57648006e090dca94c83a70d46f2eaa1e79
492,847
def madd(a,b,c): """Return a+c*b where a and b are vectors.""" if len(a)!=len(b): raise RuntimeError('Vector dimensions not equal') return [ai+c*bi for ai,bi in zip(a,b)]
3a7c6345b8699a72bbc8ea5d2a3dd2c8523391f2
289,786
import jinja2 def generate_template(templatename, **kwargs): """This renders a JINJA template as a generator. The templates exist in our lib/python/treadmill/templates directory. :param ``str`` templatename: The name of the template file. :param ``dict`` kwargs: key/value passed into...
cc8789e25fef2daaba783446294bb07dc68797f3
520,896
def temporal_affine_forward(x, w, b): """ Inputs: - x: Input data of shape (N, T, D) - w: Weights of shape (D, M) - b: Biases of shape (M,) Returns a tuple of: - out: Output data of shape (N, T, M) - cache: Values needed for the backward pass """ N, T, D = x.shape M = b.shap...
eae8f0dbbea596a4bcc1a7739cfd249e8898df90
662,301
import json def check_file_contents_for_email_alerts( app ): """ See if any admin users have chosen to receive email alerts when a repository is updated. If so, the file contents of the update must be checked for inappropriate content. """ sa_session = app.model.context.current admin_users = a...
5f4f7b02178bd129a695bd3330a28f974d66ea52
289,227
def load_data(path_to_dir): """ Loads the train and test set into four different lists. """ train_pos = [] train_neg = [] test_pos = [] test_neg = [] with open(path_to_dir+"train-pos.txt", "r") as f: for i,line in enumerate(f): words = [w.lower() for w in line.strip()...
d5e0bbf8e1033c7256b44c2f61624c07dedcfff3
548,747
from operator import add def check_ts(number): """ Verifica la validità del codice di identificazione della tessera sanitaria :param number: codice di identificazione da verificare :return: True/False """ if not number.isdigit(): return False if len(number) != 20: return ...
dc8e19cfa79ab806f2810a2cab7809e98edec642
298,545
def format_metric(metric: float) -> str: """ Returns a readable string from the given Dice or loss function value, rounded to 3 digits. """ return "{:0.3f}".format(metric)
e117d483fd7f4398296cf370cd0427593c694100
381,185
def quote_literal(value): """Quote provided literal.""" return "'{}'".format(value .replace("\\", "\\\\") .replace("'", "\\'"))
561309d4b473d9daf0f46e55cfc6be830c805a5f
406,754
def bestAlgorithm_(sequencingChemistries): """ Identify the (de novo) consensus algorithm we expect to deliver the best results, given the sequencing chemistries represented in an alignment file. We key off the sequencing chemistries as follows: - Just RS chemistry data? Then use quiver (at l...
25b73bbba48d1a58b6c31645f04f810dc025178c
588,599
import copy def _DeepCopySomeKeys(in_dict, keys): """Performs a partial deep-copy on |in_dict|, only copying the keys in |keys|. Arguments: in_dict: The dictionary to copy. keys: The keys to be copied. If a key is in this list and doesn't exist in |in_dict| this is not an error. Returns: Th...
2d759603ad7cf1ada5741333be138f57957677f6
690,606
def check_hypervisor_availability(available_images, fname, hyp_type): """ This routine checks if a given hypervisor is present in given list of images in FVM. Args: available_images(str): JSON of response of enumerating hypervisors in FVM. fname(str): Name of file to be searched in response. hyp_ty...
7cb928cb86cab0c5e39eace543b67e0ca18bd66f
479,463
def get_colour_key_hitmask(image, rect, key=None): """ Returns a hit-mask using an image's colour_key. image -> pygame Surface, rect -> pygame Rect that fits image, key -> an over-ride colour, if not None will be used instead of the image's colour_key """ if not key: colour_k...
8de9a6f9f14fcc19e0816cac8fd922b95293aed4
130,497
def compute_sma(df, column_source, column_target_sma, time_periods): """ Compute Simple Moving Average (SMA). :param df: dataframe (sorted in ascending time order) :param column_source: name of source column in dataframe with values to compute SMA (e.g. close price) :param column_target_sma: prefix...
861f0e8cc5a8c5321eae74166b34f2851ed1ed53
460,812
import csv def load_categories_from_csv_file(args): """Loads categories from a csv file. The CSV file should have one comma delimited numeric category id and string category name pair per line. For example: 0,"cat" 1,"dog" 2,"bird" ... Args: csv_path: Path to the csv file to be parsed into categor...
d2352159d86ccaceaba605c844a8a6951159760e
574,034
def get_enrichment_analysis_name_from_file_name(fn): """ Output from ChromHMM Overlap Enrichment usually denotes the enrichment analysis name as the file names existing in the coordinate directory: For example: mutation_occ1.bed.gz We want the enrichment_analysis_name to be mutation_occ1 """ return (fn.split(".")...
2c13b5af94210ee68fb34f877c610542e34f2f56
525,335
from datetime import datetime from dateutil import tz def add_tz(dt: datetime, zone: str) -> datetime: """add_tz datetime doesnt assign a time zone. This function shows how to do it. Args: dt (datetime): original datetime zone (str): desired zone Returns: datetime: a new dateti...
bb10df403031e4d3f175539c35ffaa0f250958f6
133,879
def get_bin_values(base_dataset, bin_value): """Gets the values to be used when sorting into bins for the given dataset, from the configured options.""" values = None if bin_value == "results": values = base_dataset.get_output() elif bin_value == "all": # We set all values to 0, assuming...
cf2419066d6e642e65d9a8747081ebfee417ed64
706,934
def most_expensive_menu_item(restaurant): """ Loops through a list of menu items and determines the most expensive item Parameters: restaurant (dict): A dictionary with three lists items, prices, and cals Returns: str: A string with the name of the most expensive item """ highe...
a06e0ec925dc573a2dd6523497870dda663d051d
104,529
def checkOutfileOption(outfileOption): """ function to set the default value for outfileOptions Args: outfileOption: relative path to output location or None Returns: relative path to output location """ if outfileOption is None: return './index.rst' else: return o...
788b56889304f06400bb11b27c40243a577ac106
249,039
def _get_number_of_warmup_and_kept_draws_from_fit(fit): """Get number of warmup draws and kept draws.""" if 'warmup2' not in fit: n_warmup = 0 n_draws = fit['n_save'][0] else: n_warmup = fit['warmup2'][0] n_draws = fit['n_save'][0] - fit['warmup2'][0] return n_warmup, n...
e1928cd5eb6eb47d1d1347ebf05f65434fb1336c
661,531
def crop_pcm(value, sample_rate=16000, time=5): """Returns a cropped part of PCM.""" start = sample_rate end = time * sample_rate + start contain_time = int(value.shape[0] / sample_rate) if time > contain_time or end > value.shape[0]: return value return value[start:end]
30b6307dc5a6ca782e46264a71f73dd1635e93bc
548,610
import torch def get_state_dict(model): """ Gets state dict for a given tacotron2 model. Handles parallel & non-parallel model types. Parameters ---------- model : Tacotron2 tacotron2 model Returns ------- dict Model state dict """ if isinstance(model, tor...
ea07d2bb1d025909c479242b37aebf7941dc9775
267,237
def flag_match(obj, flags): """ Given a component or attribute, return true if it matches all of the given flags and False otherwise. If there are no flags, always return True. """ if "flags" in obj: return all(obj['flags'][key] == value for key, value in flags.items()) return True
449ffa243879550e7870adbf6d02c1965053a467
392,455
def exec_string(string, language="python", decorators=None): """Execute a string as python code. The languages available are ``python`` and ``mel``. During the process, creates a new function and calls it using the :func:`exec` builtin function. With this process, it is possible to apply decorato...
850e595523453b4d28abf745290886b4587e3a8b
571,689
def decoder(obj): """Decodes 'bytes' object to UTF-8.""" if isinstance(obj, bytes): return obj.decode("utf-8") return obj
09ba08af32bd145470ec2a3c6c8ebb875330e22b
433,951
import typing from typing import Counter def alignment_conservation(alignment: typing.Dict[str, str]) -> typing.List[float]: """ Obtain residue conservations of each position in a sequence alignment Parameters ---------- alignment dict of key: aligned sequence Returns ------- ...
d82c5313538b9c7f87184a98fffc9f6c56d86182
443,223
import inspect def is_functional_member(member): """ Check whether a class member from the __dict__ attribute is a method. This can be true in two ways: - It is literally a Python function - It is a method descriptor (wrapping a function) Args: member (object): An object in t...
268068600689a7935c9a8b26aa14ca09f9679228
12,690
def parse_pots(initial): """Parse initial pots.""" return [[pot, index] for index, pot in enumerate(initial.split(': ')[1])]
bacc10b5a1e737cbd58662b360a7bf058c9abf5d
248,132
from typing import Optional def get_fullname(namespace: Optional[str], name: str) -> str: """ Constructs a fullname from a namespace and a name. """ if namespace: return namespace + "." + name else: return name
5bc82836186089368eeeea66c206d8f09b006ba6
666,198
def ListFeatures(font): """List features for specified font. Table assumed structured like GPS/GSUB. Args: font: a TTFont. Returns: List of 3-tuples of ('GPOS', tag, name) of the features in the font. """ results = [] for tbl in ["GPOS", "GSUB"]: if tbl in font.keys(): results += [ ...
0fb2a1ac5b367d7d711cab7b303d2ba1fd487514
678,446
def percentage(value, total_sum): """calculate a percentage""" if total_sum == 0: return 0 else: return round(100 * float(value) / float(total_sum))
b6aa712b58f93fd1aa18587d7816e500a1585971
419,030
import yaml def read_yaml_file(filename): """Read a YAML file.""" with open(filename, 'r') as f: return yaml.safe_load(f.read())
4f13467fcf675d26f5b1118ad48dc7b03f769d47
97,774
import pickle def read_encoded_ctx_file(encoded_ctx_file: str): """ Returns dictionary containing the encoded passages and their vector embeddings :param encoded_ctx_file: :return: """ with open(encoded_ctx_file, mode="rb") as f: p_emb = pickle.load(f) # create dictionary, so that...
23bbf7e76d53c3b3ea8228b9e8b2d53d932bae33
66,149
def split_lhs_rhs(expr): """Split the equation into left and right hand side. >>> split_lhs_rhs(" 12 + a ") (None, '12 + a') >>> split_lhs_rhs(" c = 12 + a ") ('c', '12 + a') """ expr = [x.strip() for x in expr.split("=")] if len(expr) == 1: rhs = expr[0] output = None ...
ac7fd4861ad3289365030d6eac656e021ee39e6f
42,664
def reformat_ssh_key_to_pem_bytes(ssh_key_str: str) -> bytes: """ reformat the ssh key string to pem format bytes for github client. :param ssh_key_str: utf-8 string without header and footer for the github app rsa private key :return: pem formatted private key in bytes with header and footer """ ...
404e7198e2d5c07b8badd7bfaa4ece344303be98
245,407
def has_children(obj_json, client): """Checks whether an archival object has children using the tree/node endpoint.""" resource_uri = obj_json['resource']['ref'] tree_node = client.get('{}/tree/node?node_uri={}'.format(resource_uri, obj_json['uri'])).json() return True if tree_node['child_count'] > 0 el...
0933dbdda99b1577ecc78d4b9dc73f50dcc72b4e
57,676
def ensure_existence(f): """ Ensures that method is not marked as non_existent Parameters ---------- f Method Raises ------ NotImplementedError if the method is marked as non existent Returns ------- Method f """ if getattr(f, 'not_existing', False): raise Not...
18410fe298fcb5dab3114dea1632010d4778417c
639,802
def place_word(grid, coords, word): """ Return the grid with the new word placed """ for i, l in enumerate(word): x, y = coords[0] + i, coords[1] grid[y][x] = l return grid
6921f13c378aa69ec87bb097db6ce38df13340a3
315,151
def validToken(token): """ Return True if token is in hex and is 64 characters long, False otherwise """ if len(token) != 64: return False try: token.decode("hex") except TypeError: return False return True
1fa264acc43dd67ba400ddb50ccf3aaa04f33300
660,938
import string def extract_words(text): """Return the words in a tweet, not including punctuation. >>> extract_words('anything else.....not my job') ['anything', 'else', 'not', 'my', 'job'] >>> extract_words('i love my job. #winning') ['i', 'love', 'my', 'job', 'winning'] >>> extract_words('mak...
cc0b7dbc548696ed74b48dec57b386fe38adfa41
699,019
from typing import OrderedDict def get_stepped_value(value, step, step_type='Down'): """Returns the rounded value, given an initial input value. Args: value(int): The input value step(int | OrderedDict): The step value step_type(str): Whether the value is incremented to the next ste...
a622d42e1a875a311a10e36ea129fd926cdd10d8
311,958
import torch def categorical_kl(p1, p2): """ calculates KL between two Categorical distributions :param p1: (B, D) :param p2: (B, D) """ p1 = torch.clamp_min(p1, 0.0001) # actually no need to clamp p2 = torch.clamp_min(p2, 0.0001) # avoid zero division return torch.mean((p1 * torch.l...
64b10348322743228e1877ac2164d2725788972e
482,839
def get_atom_indices(labels, atom): """ labels - a list of coordinate labels ("Elements") atom - the atom whose indices in labels are sought Returns a list of all location of [atom] in [labels] """ indices = [] for i in range(len(labels)): if labels[i] == atom: indices.ap...
a5b36423becc9935e64225a6a029999e24471a65
690,825
import re def _is_tab_line(line: str) -> bool: """ Check if this line is a tab line :param line: Line for which we want to check if it is a tab line :return: Boolean indicating if line is a tablature line """ if re.match(r'\s*[eBGDAE]? {0,5}(\|\))? {0,5}[-0-9|b/hp ]{10,}.*', line) \ ...
aaaf018451b30a921d756cf1fa5161ff3af478dd
494,870
def traverse_pip(conn, wire_in_tile_pkey): """ Given a generic wire, find (if any) the wire on the other side of a pip. Returns None if no wire or pip connects to this wire. """ cur = conn.cursor() cur.execute( """ SELECT src_wire_in_tile_pkey FROM pip_in_tile WHERE is_pseudo = 0 AND ...
b74f702647e45a151eb08177e2c90148b44dc161
524,577
def _get_function_name(addr, p): """ Return a function name :param addr: function address :param p: angr project :return: function name """ return p.loader.find_plt_stub_name(addr)
0e55ebb28200ac2670d1079c5bf9ea6aec2b9ed3
246,396
from typing import Tuple def bbox(polygon) -> Tuple[float, float, float, float]: """Compute the Bounding Box of a polygon. :param polygon: List of coordinate pairs (x,y) """ x,y = 0,1 vtx = polygon[0] minx, miny, maxx, maxy = vtx[x], vtx[y], vtx[x], vtx[y] for vtx in polygon[1:]: ...
c0e07607a94ee6b7f6945622c39e06a11e2bf4d0
610,338
def _findCookie(filenames, cookie_re): """ Look through a group of files for a cookie that satisfies a given compiled RE, returning first such cookie found, or None. """ for file in filenames: data = open(file, 'r').read() m = cookie_re.search(data) if m: return m.group(1)
894e5d3426c15857c3ef140cb72efbfcb2891bba
452,469
def date2epoch(dt): """ Convert list of datetime objects to epoch time Parameters ---------- dt : datetime.datetime Single or list of datetime object(s) Returns ------- time : float Datetime converted to epoch time (seconds since 1/1/1970 00:00:00) """ if not i...
1d13af15d856ca9d8f45fcda5f37d7a7eaff284a
104,210
from unicodedata import normalize def unicodify(s, encoding='utf-8', norm=None): """Ensure string is Unicode. .. versionadded:: 1.31 Decode encoded strings using ``encoding`` and normalise Unicode to form ``norm`` if specified. Args: s (str): String to decode. May also be Unicode. ...
ee4882dd7450ba0b146e3fb9ddabf9deaf0e7903
29,888
def sec_to_exposure_decimation(sec): """ Convert seconds to exposure and decimation. The algorithm is limited since it multiplies decimation by 10 until the resulting exposure is less than 65_535. This is not perfect because it limits decimation to 10_000 (the next step would be 100_000 which is ...
c880a371bc3aa9420de094df4815a876bb504b33
20,176
import requests import json def post(url, params, proxies, headers): """Send a request with the POST method.""" response = requests.post(url, data=json.dumps(params),proxies=proxies, headers=headers) return response
a6d57ee82021154540ea7b8c68329d2f85eaa157
653,074
import torch from typing import Optional def create_src_lengths_mask(batch_size: int, src_lengths: torch.Tensor, max_src_len: Optional[int] = None): """ Generate boolean mask to prevent attention beyond the end of source Inputs: batch_size : int src_lengths : [batch_size] of sentence lengths ...
b26c42a5fdc0ec25c1320d4db668e457ada30af2
630,996
import json import hashlib def _generate_etag(etag_data, etag_schema=None, extra_data=None): """Generate an ETag from data etag_data: Data to use to compute ETag etag_schema: Schema to dump data with before hashing extra_data: Extra data to add before hashing Typically, extra_data is used to add...
6fa4828787f4d38a0503f14867350aa35f4109ad
518,833
from typing import Tuple def split_url(url: str) -> Tuple[str, str, str]: """ Splits a url into its components: filename, basename, extension Example: ('v.png', 'v', 'png') :param url: :return: Tuple[str, str, str] """ filename = url.split("/")[-1] x, _ = filename.split("?") basena...
0672fac3b96e4c6175c81f0d4e9fe0915b1d9eaa
519,953
def __ngrams(s, n=3): """ Raw n-grams from a sequence If the sequence is a string, it will return char-level n-grams. If the sequence is a list of words, it will return word-level n-grams. Note: it treats space (' ') and punctuation like any other character. >>> ngrams('This i...
e0cdbf7a231adcec2ab2c48742c2c8f5b285530d
327,269
def _is_comment(cells): """Returns True if it is a comment row, False otherwise.""" for cell in cells: if cell.strip() == '': continue return cell.lstrip().startswith('#') return False
db9e6125cdd3c4ae3ea2613682e0cb942277f386
140,886
def shorten(txt: str, length: int = 10, ellipsis: str = "…") -> str: """Truncate ``txt``, adding ``ellipsis`` to end, with total ``length``.""" if len(txt) > length: return txt[: length - len(ellipsis)] + ellipsis else: return txt
ed53866d76d50cae216ced01b6527d3e87180b06
507,795
def dict_diff(first, second): """ Return a dict of keys that differ with another config object. If a value is not found in one fo the configs, it will be represented by KEYNOTFOUND. @param first: Fist dictionary to diff. @param second: Second dicationary to diff. @return diff: ...
163e2c7de61ad6758bcb6307c427441624c28266
630,802
def map_value_or(f, value, default): """Return Value or Default if Value is None.""" return f(value) if value is not None else default
e450e021a567fd57935dcebd120cbf3a74fc4098
150,915
import torch from typing import Optional def dkl_diag_gaussian( mu_1: torch.Tensor, var_1: torch.Tensor, mu_2: Optional[torch.Tensor] = None, var_2: Optional[torch.Tensor] = None, log_flag: bool = False, avg: bool = True, ) -> torch.Tensor: """Computes the analytical KL divergence between ...
ee9fa71a94142ab7fbbdc3a021b5d1edaa515f27
243,166
def specNameToCName(specName): """ Given an string containing an ASN.1 name, returns a string that is a valid C++ identifier that is as similar to that name as possible. Since most ASN.1 identifiers used in PKIX specifications are legal C++ names except for containing hyphens, this function just con...
42c9bba5c9bf76720cd4747588ddc291ec27d316
224,238
import re def PHONOTACTIC(pattern): """Takes a string representing the regex pattern of a particular phonotactic restriction, and returns a function that will count the number of times that pattern occurs in an unparsed output string.""" def F(output): return len(re.findall(pattern, output...
44bb47602df700f4400d8abad4cc45424d42a35e
604,373
def bestScheduleChannel(sched, node_id): """Choose the best single channel for the given node to use from the schedule. If the schedule allows the given node to transmit on multiple channels, pick the channel with the most air time. Args: sched: A schedule node_id: A node Retu...
0ede5bbf290572bd1b20f1948b1e7f29c075b417
470,972
def binary_tail(n: int) -> int: """ The last 1 digit and the following 0s of a binary representation, as a number """ return ((n ^ (n - 1)) + 1) >> 1
63460cef7b39b7e7ee2ec880810ff71d82be01e9
5,459
def cel2kel(t): """Converts from Celsius to Kelvin""" return t + 274.2
04d6d474e9de56a8200a0fc147611906d4e58a16
650,776
def solve_1d_quadratic(p, q, r=0): """ Finds the minimizer of an 1-D quadratic system, raises an error if there is no minimizer (p<0) Inputs: - p, q, r: the coefficients of the 1D quadratic system Output: - xstar: the minimizer """ assert ... return ...
1495a5933e183b3ad6ea5e6be41e6aeac372771b
451,136
def prop(x, s): """Returns the proportion of `x` in `s`. """ return list(s).count(x)/len(s)
e35acf9e1ab49507822f2d316a1c8e79eb70cc50
556,020
import itertools def styleguide_lint_with_options(request, styleguide_lint, config_write, tmp_path): """Fixture which will run the styleguide with the "lint" subcommand, given the provided options. The options will be tested on the command line as well as in the config. `base_args` and `lint_args` are si...
ca745bc90c760d89cdf842aac903f0d9728ac2df
158,403
def count_type_changes(pattern: str): """Count the number of type changes in the given pattern. The pattern is expected to describe Bloch points with single characters where each character type represents one type of Bloch point. Example: `iooi` -> two type changes. """ count = 0 for left, ...
91959d61d1c76833aeeff6e91d97f83e5bf0bd46
472,659
import requests def check_csv(url: str) -> bool: """Checks if the CSV from URL file is available. Args: url: str - an URL link or a filepath to a CSV file Returns: bool: True if the CSV file is available """ status_code = requests.get(url).ok if status_code: print("C...
1e696bba28b49b527aad24db9d176562b534dee3
574,403
def class_labels(column): """ Takes in target column and creates list of binary values. 1 (>=0.5) being in the positive class (toxic), 0 (<0.5) being in the negative class (Not toxic) """ class_label = [] for row in column: if row < 0.5: class_label.append(0) else...
3b94e6fbc918abb50a932550544408acca42843a
668,867
def parse_requirements(fpath): """ Parse a requirements file and return a dict of deps and versions. """ with open(fpath, 'r') as fh: data = fh.read() lines = data.split('\n') lines = [line.strip() for line in lines if line and line[0] != '#'] deps = {} for line in lines: ...
ae9f4ee13d9e3d3d193c6114145da92995364c44
454,782
def create_agg_log(db, sessionID): """ Instantiate the Aggregate Data Collection. :param db: The database object. :param sessionID: Current user's session ID. :return: The Aggregate Data Collection object. """ collection_name = 'agg_collection_' + sessionID agg_collection = db[collection...
23d8ea94adfe98aad28376184f173e3c772a8546
558,195
def get_dependencies(doc, n): """Get dependencies in the format of a list of (token, deprel, dependent_token) pairs- for all 'n' sentences in doc""" def getdeps(i): deps = [] for head, rel, dep in doc.sentences[i].dependencies: deps.append((head.text, rel, dep.text)) ...
cf60c17d64e8d45ce1cc9449db7fed4763bafbae
85,455
def get_hours_minutes_by_seconds(seconds): """ Gets hours and minutes by input seconds :param seconds: seconds :type seconds: int :return: hours and minutes :rtype: tuple """ m, s = divmod(seconds, 60) h, m = divmod(m, 60) return h, m
83526c2bb40dc19cf797e3f8b6369b8da9e2aea5
552,551
def indent(str, dent): """Simple function to uniformly add whitespace to the front of lines.""" return '\n'.join(map(lambda x: ' ' * dent + x, str.split('\n')))
72369e6dbab5413eed1f845833c96f5bef199950
516,044
def _CheckForDangerousTestFunctions(input_api, output_api): """Tests should not be using serveAsynchronousMockedRequests, since it does not guarantee that the threaded HTML parser will have completed.""" serve_async_requests_re = input_api.re.compile( r'serveAsynchronousMockedRequests') errors =...
3daa6c5760abcbe82f718ae9129afdb5b582c1a8
365,182
def strip_nones(row): """ Remove all items with None for a value, because why include it if there's no value? """ return dict([(k,v) for k, v in row.items() if v is not None])
31c7a9d269b84bb7a4a375b766d1dad19e2c58a4
143,421
def calculate_bps(current_sample_octets, current_sample_time, historical_sample_octets, historical_sample_time): """Calculate the bits-per-second based on the octets and timeticks (hundreths of a second).""" # When the SNMP counter reaches 18446744073709551615, it will rollover and reset to ZERO. # If this...
af26b62cb0dba703c8f41514b0afae835e387158
210,616
import torch def get_device(logger): """ Get device model will be run on (GPU or CPU) :param logger: Logger object to note the device :return: device type, num_of_gpus """ device = torch.device("cuda" if torch.cuda.is_available() else "cpu") n_gpu = torch.cuda.device_count() logger.inf...
9b6ed3ecbd54741b4feb200f1a67f0d10cb4518b
246,186
def replace_tags(string, from_tag="i", to_tag="italic"): """ Replace tags such as <i> to <italic> <sup> and <sub> are allowed and do not need to be replaced This does not validate markup """ string = string.replace("<" + from_tag + ">", "<" + to_tag + ">") string = string.replace("</" + from...
dccb4f34d0c26575a9a0c74fdb02c9a3dc4b2cd2
672,406
def formatNumber(number): """Ensures that number is at least length 4 by adding extra 0s to the front. """ temp = str(number) while len(temp) < 4: temp = '0' + temp return temp
33caf6a3304f8c0e39f937fc11f2daee463a6286
620,573
import random def generate_random_data(nb_objs, nb_attrs): """ Generates a matrix of random data. :param nb_attrs: the dimension of the data :type nb_attrs: int :return: a matrix with nb_objs rows and nb_attrs+1 columns. The 1st column is filled with line numbers (integers, from 1 to nb_objs)....
4e7205746b5aa8e31fab1a91c9e8bcd67cb91776
157,073
def test_name(msg_name): """Generate the name of a serialization unit test given a message name""" return "test_{}_serialization".format(msg_name)
261c4c4e215b84c0358ca51cbbd4723208dedb12
664,000