content
stringlengths
39
9.28k
sha1
stringlengths
40
40
id
int64
8
710k
def wafv2_custom_body_response_content(content): """ Validate wafv2 custom body response content. Any character between 1 to 10240 Property: CustomResponseBody.Content """ if not content: raise ValueError("Content must not be empty") if len(content) > 10240: raise ValueError("Co...
a3d5df6a385422ff783ec4adbfcfb9132a11feba
557,623
def cell_volume(a1,a2,a3): """ returns the volume of the primitive cell: |a1.(a2xa3)| """ a_mid_0 = a2[1]*a3[2] - a2[2]*a3[1] a_mid_1 = a2[2]*a3[0] - a2[0]*a3[2] a_mid_2 = a2[0]*a3[1] - a2[1]*a3[0] return abs(float(a1[0]*a_mid_0 + a1[1]*a_mid_1 + a1[2]*a_mid_2))
b9421ea1ad230cbe876968980fe7f1580ecde1d9
381,656
def preproc(unclean_batch_x): """Convert values to range 0-1""" temp_batch = unclean_batch_x / unclean_batch_x.max() return temp_batch
ef84265c0e6fe244ce2367514d0f4b901d8f958b
562,343
def get_file_contents(file_path): """Return a string containing the file contents of the file located at the specified file path """ with open(file_path, encoding="utf-8") as f: file_contents = f.read() return file_contents
4e00422c05de3b90e3457b8d468514957c28b5f3
625,560
def dot_index(index, data): """Internal method for indexing dicts by dot-notation. Args: index: a string with the dot-index key. data: a dict with the index. Returns: A list with the result. Example: >>> data = {'apa': {'bepa': {'cepa': 'depa'}}} >>> list(dot_index('a...
0891b65d7c15438c0581295d3d7d8e4931da50f9
486,583
def isfloat(value): """ Check input for float conversion. :param value: input value :type value: str :return: result as bool (True: input_value is a number, False: otherwise) """ try: float(value) return True except Exception: return False
59889102a8855338b0149feb9f96e0c0b4fea52c
327,397
import six import ipaddress def address_to_bin(address, split=None): """Converts an dotted-decimal (IPv4) or groups of hexadecimals (IPv6) formatted address to a binary representation :param address: The IP address :type address: ipaddress.IPv4Address or ipaddress.IPv6Address or str :param int sp...
3c668221f407211cc1eaed0f157006248bdf8892
215,371
import re def is_base64(string: str) -> bool: """ Verifies if `string` is encoded in Base 64. Parameters ---------- string: str String object to be verified Returns ---------- bool True, if `string` complies with Base 64 format, False, otherwise """ return re...
9fb176814dade945e40af2c72640fcda865651c9
311,172
def has_preview(song_data): """ Returns True if a song's Spotify metadata contains a valid preview URL Inputs: song_data : json/dict track metadata object from Spotify API (ex: output of call to spotipy.track(track_id)) Outputs: bool """ preview = song_data[...
852ebb6a5e385e3dfc3d3b1eaf82ff9f6a1b6907
454,540
def time_fmt(secs): """ Return a string representing the number of seconds, in a human readable unit. """ if secs < 120: return "{}s".format(int(secs)) if secs < 3600: return "{}m".format(secs // 60) return "{}h".format(secs // 3600)
aef5f7fc548939dd7f285115d2af2a7b166186b3
295,958
def get_spatial_dim(tensor): """ Return spatial dim of the input tensor (without channels and batch dimension). Parameters ---------- tensor : tf.Tensor Returns ------- dim : int """ return len(tensor.get_shape().as_list()) - 2
75dcf6e50a9901ed2f6e6caa465e7455e9b5577b
369,942
def endswith(suffix): """ Create a function that checks if the argument that is passed in ends with string :param str suffix: string to check the end for :return func endswith_function: a function that checks if the argument ends with the specified string """ def string_ends_with(string)...
ad6a28cc5671a8bac323ba2a45faaeae5cc8569e
523,118
def make_swagger_name(group: str, version: str, name: str) -> str: """ This function creates properly formatted swagger names for an object :param group: string; group that the object belongs to :param version: string; version that the object belongs to :param name: string: name of the object (class...
fe2a4331477f7cfc6daae146537edb6884ed535a
54,914
def _to_hass_brightness(brightness): """Convert percentage to Home Assistant brightness units.""" return int(brightness * 255)
df05529683a403b9ff542ec7001bc48975034f32
334,888
def contained_point(point, mask): """Checks to see if a point is contained within the coordinates of a mask""" if point[0] < mask.x2 and point[0] > mask.x1 and point[1] < mask.y2 and point[1] > mask.y1: return True return False
426a1ae8953867e98ad94b07070fbd9992098df7
614,787
def css_check(css_class): """ Function that checks if a CSS class is something that a command can act on. Generally speaking we do not act upon posts with these two classes. :param css_class: The css_class of the post. :return: True if the post is something than can be worked with, False if it's in...
58ffcc05e4636985d54d91c708caa3087690da90
530,818
def endfSENDLineNumber( ) : """Indicates the end of an ENDF data section for one (MF, MT) pair.""" return( 99999 )
bd910343d6800bbb608774cdf6a62585d32dc54f
651,655
def bytes_to_str(value): """Return UTF-8 formatted string from bytes object.""" return bytes(value).decode('UTF-8')
8e43de7f21cbcde55b79f3ea118b7e29b4e78aa1
657,526
def context(context, request_headers): """Return the Context object for passing to SecurityView.__call__().""" context.host = "via.hypothes.is" context.proxied_url = "https://example.com/foo" context.headers = [] context.get_header.side_effect = request_headers.get context.query_params = {} ...
64cc1d5bdc7df06f96e84e3a003a2d5d5d4578de
496,822
def clamp_band(data, min, max): """clamp data in band between min an max Parameters ---------- data: np.array band data min: Number max: Number Min and max values to clam to Returns ------- np.array band_data """ data[data < min] = min data[data ...
82f7514851d7420f0300206b8734b403b2d4b4ce
180,032
import pathlib def about_package(init_posixpath: pathlib.Path) -> dict: """ Return package information defined with dunders in __init__.py as a dictionary, when provided with a PosixPath to the __init__.py file. """ about_text: str = init_posixpath.read_text() return { entry.split(" = ...
4e43c305ecf784e8355d2ab9ac735c18b7346881
627,624
def is_profile_bare_os(profile): """ Check if profile is set up as bare os profile """ # bare_os field is optional return 'bare_os' in profile and profile['bare_os'] is True
e4a92172b9bd4793c7b3c7e2cd16e144dd58bbbb
492,685
def SuppressBlanks(text): """ Replace succesive blanks with a blank :param str text: string :return: string :rtype: str """ outtext='' for s in text.split(): outtext=outtext+s+' ' return outtext.strip()
42bedaf7f7601cffdad2410a119bef1506226c08
567,914
def even_or_odd(x=0): """Find whether a number x is even or odd. >>> even_or_odd(10) '10 is Even!' >>> even_or_odd(5) '5 is Odd!' whenever a float is provided, then the closest integer is used: >>> even_or_odd(3.2) '3 is Odd!' in case of negative numbers, th...
bac5431d26eb4f0512354431bb03b1ba5d815cfb
359,433
import hashlib import hmac def _salted_hmac(key_salt, value, secret): """ Returns the HMAC-SHA1 of 'value', using a key generated from key_salt and a secret. A different key_salt should be passed in for every application of HMAC. Lifted from: http://code.djangoproject.com/svn/django/trunk/django/util...
f91334cdd3c783475ed0f784ec74b2467591ca69
254,294
def extract_tag_indexes(tag_seq, b_tag, i_tag): """ Returns index of B-LOC and I-LOC, I-LOC = -1 if no I-LOC exist """ i_tag_index = -1 # default value b_tag_index = tag_seq.index(b_tag) if b_tag_index == len(tag_seq) - 1: i_tag_index = b_tag_index return b_tag_index, i_tag_inde...
6432d66fff72d43da0783f0dfc909cb001f42929
584,304
def merge(numbs1, numbs2): """ Go through the two sorted arrays simultaneously from left to right. Find the smallest element between the two in the two arrays. Append the smallest element to a third array and increase the index from which the element was taken by one. If the two elements are the...
2595f5bea09004461cf6e3e984455d260adf87bf
87,178
def greaterD( ef, gh): """ Return True if pair ef has greater margin than pair gh. A pair is a pair of the form: (pref[e,f],pref[f,e]) Schulze says (page 154): "(N[e,f],N[f,e]) >_win (N[g,h],N[h,g]) if and only if at least one of the following conditions is satisfied: 1. N[e,f] > N[f,e] ...
a7e63f7aff655aa085389a34f4ad873b5d3e9d9b
318,769
def add_multiples(maximum): """Add all numbers that are multiples of 3 and 5 below the maximum.""" total = 0 for x in range(maximum): if x % 3 == 0 or x % 5 == 0: total += x return total
0724e049e6157f463c7a127dca27856eaddb20f3
608,796
def avg_Q(q_S, q_D): """ Return total transmission capacity of station, assuming transmission evenly distributed over hexagonal cell Parameters ---------- q_S : float channel capacity in Mbps q_D : float data demand rate in Mbps Returns ...
db78680a57319d642e367fe8fbacdbf8f31648ff
615,427
def kansai_gas_nattoku(contract, power): """ 関西電力「なっトクでんき(なっトクパック)」での電気料金計算 https://kepco.jp/ryokin/menu/nattokudenki/ Parameters ---------- contract : None 契約アンペア数 (本プランでは計算に使用しません) power : float 前回検針後の使用電力量(kWh) Returns ------- fee: int 電気料金 """ ...
67e495f0c536de76c2e3b47735add907a982c1fa
301,009
import re def commas(line): """ Return the location of all the commas in an input string or line """ return [m.start() for m in re.finditer(',', line)]
c5327e3c34336db3c64acfa391da179018276b3b
44,462
def make_list(length): """ Creates and initializes a list in a safe manner (avoiding reference issues) """ return [None for x in range(length)]
f87fb65e3e0fcc2961abebe20ac20e9bba4e28cb
589,026
def max_farmers(collection): # pragma: no cover """Returns the maximum number of farmers recorded in the collection""" max_farmers = 0 for doc in collection.find({}).sort([('total_farmers',-1)]).limit(1): max_farmers = doc['total_farmers'] return max_farmers
9f91774d0fe36fc4299db938e11db45d080ed5c1
690,882
def sigmoid(x, a, c, fw): """Sigmoid function with scale parameter a and horizontal shift c, evaluated at point x using the framework fw (numpy or theano.tensor). """ return 1. / (1. + fw.exp(-1. * a * (x - c)))
94ddc51e486e23619dac15870659eb02032b4248
548,248
import re def handle_gutenberg(text: str) -> str: """Removes Project Gutenberg boilerplate from text. :param text: A Project Gutenberg document. :return: The input text document without the Gutenberg boilerplate. """ # find end of front boiler plate, assuming something like: # *** START ...
3a11ade12113b5580b8ade830cd4ade9190f15d1
495,998
from string import printable def unprintable(mystring): """return only the unprintable characters of a string""" return ''.join( character for character in mystring if character not in printable )
bb48580d525d1e829f5b4b33cd4c0e540aa3a21a
34,516
def risk_to_size(capital_size: float, risk_percentage: float, risk_per_qty: float, entry_price: float) -> float: """ calculates the size of the position based on the amount of risk percentage you're willing to take example: round(risk_to_size(10000, 1, 0.7, 8.6)) == 1229 :param capital_size: :param...
502d7ac41afb603b3e1c66ec24ae8735e9b667d8
272,063
def format_rotor_key_defs(rotor_keyword_vals): """ Formats strings that contain the 'Group', 'Axis', and 'Symmetry' keywords and values that are used to define hindered rotors and internal rotors in MESS input files. :param rotor_keyword_vals: values for the for some rotor keyword :...
6c8d8f3e3674b6541a5e02796f633be58ebf5c90
362,909
import re def separate_words(name): """Convenience function for inserting spaces into CamelCase names.""" return re.sub(r"(.)([A-Z])", r"\1 \2", name)
a2c2db19d9eddf94edd846f0752ca237cb99e441
687,685
import inspect def getfile(fn): """ Returns the file where the function is defined. Works even in wrapped functions """ if hasattr(fn, '__wrapped__'): return getfile(fn.__wrapped__) else: return inspect.getfile(fn)
44d9021c4628966f9f314ab90ee36066a9500962
607,553
from typing import Dict from typing import List def _create_key_value_pair_list(input_dict: Dict[str, str]) -> List[str]: """ Helper to create name=value string list from dict Filters "ANY" options. """ res_list: List[str] = [] if not input_dict: return res_list for name, value in ...
52fe113c3486a133cb39480742cfa0386633b4b5
470,109
import re def check_string_capitalised(string): """ Check to see if a string is in all CAPITAL letters. Boolean. """ return bool(re.match('^[A-Z_]+$', string))
f496d79fafae4c89c3686856b42113c4818f7ed8
708,880
def get_event_ends(T_part, n_repeats): """get the end points for a event sequence, with lenth T, and k repeats - event ends need to be removed for prediction accuracy calculation, since there is nothing to predict there - event boundaries are defined by these values Parameters ---------- T_...
1080784ad0b448d326b257f74e9fe9f857eef37c
290,534
def default_init_params(output_min, output_max): """Returns default initialization bounds depending on layer output bounds. Args: output_min: None or minimum layer output. output_max: None or maximum layer output. """ if output_min is None and output_max is None: return 0.5, 1.5 else: return ...
1db53b3b9b887a53165ac17d5f822df1fd8294e9
154,011
def get_standard_file(standard): """ Map the standard to a file """ standard_files = {"C2004": "misra-c2004-guidelines.csv", "C2012": "misra-c2012-guidelines.csv", "CPP2008": "misra-cpp2008-guidelines.csv"} if standard in standard_files.keys(): return st...
6416bd8a995682eeb90b69bc4370bd984771f10f
289,099
import six import json def meta_serialize(metadata): """ Serialize non-string metadata values before sending them to Nova. """ return dict((key, (value if isinstance(value, six.string_types) else json.dumps(value)) ...
a2ef8762c9d1b3d78dc401996392df0985c1c226
699,251
def does_not_contain_arxiv(value: object) -> float: """Value does not contain the word `arxiv`.""" if not isinstance(value, str): return 0.0 return 0. if 'arxiv' in value else 1.
2c0aa71a6d6dc3772e0a4d5d23c18045cfb3f7e8
161,627
def get_initials(pname): """ Splits name on spaces and returns first letter from each part. :param pname: str, player name :return: str, player initials """ return ''.join([part[0] for part in pname.split(' ')])
282ae97ca4033a40f1bc5d2133bb50121bfdbdbd
272,574
def get_file_name(args) -> str: """Creates the base file name for this experiment from the command line arguments.""" if args.override_name is not None and args.override_name != "": if args.name_suffix != "": raise ValueError("Cannot set --override_name and --name_suffix.") return ar...
47dd967c03ea9d9f8fd2d3a75462dc97911b223f
566,434
def differentiate_frames(src): """Subtract every two consecutive frames.""" # Shift data to pre/post frames pre_src = src[:-1] post_src = src[1:] # Differentiate src points src = pre_src - post_src return src
2fd69cb9850529639cfa02bfbd7d0239bcd2c3e8
323,059
def rescaleInput(input): """ scales input's elements down to range 0.1 to 1.0. """ return (0.99 * input / 255.0) + .1
06f097e2f8dafaaffda395ef590a1ac5cb7b78dd
89,025
def _override_license_types_spec_to_json(override_license_types_spec): """ Given an override license types spec, returns the json serialization of the object. """ license_type_strings = [] for license_type in override_license_types_spec: license_type_strings.append("\"" + license_type + "\""...
57ab635a35c44e9deddeb015f197a1b071f8d4ff
74,922
from typing import List from typing import Dict def sort_on_categories(methods: List[dict]) -> Dict[str, Dict[str, dict]]: """ Sorts methods on categories Returns: Dict[category: str, Dict[method_name: str, method: dict]] """ categories: Dict[str, Dict[str, dict]] = {} for method in methods: ...
39989295a80bf3f87d7417774b3b9ce8b9b53d22
554,638
import logging def convert_to_es(scan_result: tuple[dict, str]) -> dict: """ Converts a dictionary with an IP as a key to a dictionary with the IP as a value, which helps elasticsearch queries. Input: - scan_result: a tuple with the scanned dictionary as the first element and the IP address of the...
dacf2eefc02e881478b3ddb9e01b600090fe38d7
264,076
def parse_behave_table(context_table): """Cast behave's table to a dict.""" return next( dict(zip(context_table.headings, row)) for row in context_table.rows )
3499dbdfb19d33fd1790e61e89a6da2c4132165d
116,093
def gas_fvf(z, temp, pressure): """ Gas FVF calculated in oilfield unit, result in res ft3/scf inputs temp in Fahrenheit, pressure in psia or psig """ temp = temp + 459.67 Bg = 0.0282793 * z * temp / pressure return(Bg)
8ca09ad37a2b33ea784ed347c6919ec856c65963
347,015
def convert_bbox_info(f_frame_len, bbox_info): """Convert bbox old information: <bb_left>, <bb_top>, <bb_width>, <bb_height> to new form to fit cv2.rectangle() inputs: <bb_left>, <bb_top>, <bb_right>, <bb_bottom>""" total_length = 0 bbox = list(bbox_info) for key in f_frame_len.keys(): tota...
602455e12ca0c57d3d97c0f08d64d22a3fcc47bd
122,772
def _boolstring(arg): """ Checks api_parser that are not required and have default values on the server. Argument is a string but mus be converted to True, False or ''. Args: arg (str): Parsed argument. Returns: bool or empty string: "True" -> `True` "False...
0f1f2c236690757f4af7279f4a2859bf5b533fd0
498,993
import json import codecs def parse_json(filename): """Parse data from filename and return a list of boats.""" country = filename.split("/")[2][0:3] try: rms = json.load(codecs.open(filename, "r", "utf-8-sig"), strict=False) except json.decoder.JSONDecodeError as e: print(f"Error par...
db05745a9ff37377fe419afae50ec3cf9cc643e9
98,682
def _data_types_from_dsp_mask(words): """ Return a list of the data types from the words in the data_type mask. """ data_types = [] for i, word in enumerate(words): data_types += [j + (i * 32) for j in range(32) if word >> j & 1] return data_types
a0c10a96ce8d6ca0af3156ee147de8571f605447
49,322
def compare_bits(olds, news): """Subtract 2D list to determine changes to bit state.""" rows = len(olds) cols = len(olds[0]) delta = [[0] * cols for i in range(rows)] for i in range(0, rows): for j in range(0, cols): delta[i][j] = news[i][j] - olds[i][j] return delta
cdf1a99b3b3f168f0f2e6715854f06eb640564eb
194,032
def lookup_fits_header(remote_path): """Read the FITS header from storage. FITS Header Units are stored in blocks of 2880 bytes consisting of 36 lines that are 80 bytes long each. The Header Unit always ends with the single word 'END' on a line (not necessarily line 36). Here the header is streame...
c150e2e260060b5b6446170729d51cdfd154c9b0
180,224
def url2db(identifier): """ Converts species name from its representation in url to its database representation. :param identifier: Species name as in url, e.g. "canis_familiaris" :return: Species name as in database "Canis lupus familiaris" """ # special cases if identifier in ('canis_famil...
dc3e0bf33397f57deddcdbdfec5052d9775f12c4
313,737
def PolyMod(f, g): """ return f (mod g) """ return f % g
53b47e993e35c09e59e209b68a8a7656edf6b4ce
708,867
import colorsys def label_color_css(bg_color): """Create CSS for a label color.""" r, g, b = [int(bg_color[i : i + 2], 16) / 255 for i in [0, 2, 4]] h, l, s = colorsys.rgb_to_hls(r, g, b) return "".join( f"--label-{ltr}:{int(val * fac)};" for ltr, val, fac in zip( "rgbhsl",...
f48a45d6fe3ec6f7e5b6f422e59af54cf8813715
127,146
import functools import operator def combine_probability_matrices(matrices): """given a sequence of probability matrices, combine them into a single matrix with sum 1.0 and return it""" distribution = functools.reduce(operator.mul, matrices) # normalize return distribution / distribution.sum()
e27e702226188238d49fd285e5171af06a40bead
60,754
def format_date(date): """ Formats passed date in datetime into a format that the front end can display without the need for filters or directives. """ if date: return date.strftime("%b %d, %Y")
7a839822ea920ac950f093f8eceb84faee0b403f
447,848
def _ascii_decode(ascii: bytes) -> str: """Decode bytes of ASCII charactors to string. Args: ascii (bytes): ASCII charactors Returns: str: Converted string """ return ascii.decode("ascii", "replace").replace("\x00", "")
9f764760e6d1d1ddb43306df7f072706b8ebca10
219,291
def has_rep(chrn, rfrom, rto, rstrand, rep_pos): """ Return the names of the REP elements in the region Arguments: - `chrn`: chromosome name - `rfrom`: region from - `rto`: region to - `rstrand`: region strand - `rep_pos`: REP positions dictionary """ reps = [] for repel, rep...
edb47b8799d89ffc6eaafb9bb1f381de44b17db6
336,966
def check_requirements(requirements, entities): """ This method compares the existing entities and the entities required to complete an intent. :param requirements: The list of the entities needed :param entities: The list of current entities :return: If entities are missing, a list of th...
49c186c404ec32cee04c8daa7da4325f7d7b5b9f
475,225
import torch def ndc_to_camera_space(Xn, P): """Transform point(s) from normalised device coordinates to camera space. Args: Xn (torch.Tensor): homogeneous point(s) in normalised device coordinates. P (torch.Tensor): projection matrix. Returns: Xc (torch.Tensor): homogeneous poin...
40e731bb349ed5248bf22993107c76245e4e0767
631,039
from typing import List def evalRPN(tokens: List[str], verbose=False) -> int: """Evaluate an integer expression in Reversed Polish Notation (aka Postfix Notation) Keyword arguments: tokens -- list of tokens presented as strings, can be integers or operators '+,-,*,/' verbose -- flag to enable stack r...
1769133f1edaad79d4eb58f05d9affe075983d7c
446,223
import typing import re def _get_mypy_errors(stdout) -> typing.Dict[int, typing.Dict[str, str]]: """Parse line number and error message.""" errors: typing.Dict[int, typing.Dict[str, typing.Any]] = {} # last line is summary of errors for error in [x for x in stdout.split("\n") if x != ""][:-1]: ...
7bc5b0c9cdbd9ce81a28c65885c36d5697c4900e
598,770
def get_renumber_starting_ids_from_model(model): """ Get the starting ids dictionary used for renumbering with ids greater than those in model. Parameters ----------- model : BDF BDF object to get maximum ids from. Returns -------- starting_id_dict : dict {str : int, ...} ...
e545e1248a0c2ea5db9a6055851a143270fc2fbc
446,913
from pathlib import Path from click.testing import CliRunner def runner_with_args_and_paths(tmp_path: Path): """ wrap up some things used for click testing """ runner = CliRunner() workdir = tmp_path / "work" output = tmp_path / "output" args = ["--workdir", str(workdir), "--output", str(outpu...
8ca08f08cc2a81ec97dcb12e06e2154317377619
580,276
from functools import reduce import operator def list_geometric(ls): """ Returns the geometric mean of a list.""" return reduce(operator.mul, ls)**(1.0/len(ls))
27b65a50e7d6d1f466835550ce219ab1599f7785
445,701
def errorMessage(err, location = None): """ Generate a standard error message. Parameters ---------- err : str The error message. location : str, optional Where the error happens. E.g. CTL.funcs.funcs.errorMessage Returns ------- str The generated error ...
fbc1c0cee3de8d165cb4f2512e5f830cedaa0c27
82,047
import requests def read_data(url_page, parser): """ Call requests.get for a url and return the extracted data. Parameters: url_page -- url of the Billboard data parser -- Instantiated parser (either ParseWeek() or ParseYear(). """ req = requests.get(url_page) parser.feed(req....
d9d8bedc0a18b64a197e007cf0fdc63d5a1e63cb
37,448
def comma_labels(x_list): """Change list of int to comma format.""" result = [] for x in x_list: result.append(format(int(x), ',')) return(result)
7fa2eb8f8ba20ca10ef23c6882a24fe16be1675c
495,530
def grow_population(initial, days_to_grow): """ Track the fish population growth from an initial population, growing over days_to_grow number of days. To make this efficient two optimizations have been made: 1. Instead of tracking individual fish (which doubles every approx. 8 days which will result O...
88b8283e5c1e6de19acb76278ef16d9d6b94de00
2,974
def file_len(fname): """ Get the number of lines in a text file. This is used to count the number of NE found by gamebit. :param fname: file name. :return: number of lines. """ num_lines = sum(1 for line in open(fname)) return num_lines
e175e166cb60df1a1386f572ec46dcb10f01de07
301,513
def is_compatible_broadcast_shape(src_shape, dst_shape): """ Check if src_shape can be broadcasted to dst_shape dst_shape needs to be numpy compatible with src_shape, and each matching dimension for dst_shape must be equal or larger than src_shape Args: src_shape: tuple or list, shape of th...
70c34c5c743637d9cc1bbc02a1759b7caf158008
123,023
def isClose(float1, float2): """ Helper function - are two floating point values close? """ return abs(float1 - float2) < .01
bc37c5dfb48bc0d9d3c3f933af04fa7a7f1c76c0
305,499
import torch def _reduce_camera_iou_overlap(ious: torch.Tensor, topk: int = 2) -> torch.Tensor: """ Calculate the final camera difficulty by computing the average of the ious of the two most similar cameras. Returns: single-element Tensor """ # pyre-ignore[16] topk not recognized ...
40f532417c6fdfba4fa370996946c3924061c77a
465,422
import math def dbm2mw(v): """ dBm to mW mW = 10^(dBm/10) >>> dbm2mw(0) 1.0 >>> dbm2mw(10) 10.0 """ return math.pow(10, v / 10)
1fe33850a48087378d095d5c235c1b78b7efb1b9
380,086
import re def normalize_file_name(fname): """ Remove/replace characters in the string so that the string is suitable to be used as a file name. """ t = fname t = re.sub('[^0-9A-Za-z_-]', '_', t ) t = re.sub('_+', '_', t) return t
d4d988b2f7b0cd2acf74f113df6c6091481d7b0c
99,351
def total_loss_factor(frequency, reverberation_time): """ The total loss factor can be related to the reverberation time for any subsystem. :param frequency: Frequency :math:`f`. :param reverberation_time: Reverberation time :math:`T`. :returns: Total loss factor. .. math:: \\eta ...
fbe8160fa680e84f5c7cbde49f39e859f2b99adc
366,186
def subset(shape, dims): """Returns the dims-th elements of shape.""" out = [] for dim in dims: out.append(shape[dim]) return out
1eb66727f124f7769bf64b454f0a7d0f8e9a54c4
576,029
def extract_header(msg_or_header): """Given a message or header, return the header.""" if not msg_or_header: return {} try: # See if msg_or_header is the entire message. h = msg_or_header["header"] except KeyError: try: # See if msg_or_header is just the heade...
731b79f9b1336fe0cefd44ed2cebb9f43c894115
207,862
def filter_flash_errors(glm_data, LL_coords, UR_coords): """ There appears to be dense lines of erroneous flashes around 26 N on 10 Sep & 11 Sep from 1500-2100z. This function will remove these, but is unable to distinguish if a flash is genuine or erroneous. Parameters ---------- glm_data ...
5ff8ca4dbb82b633e36105527ac7bf18db7b5c94
23,032
def convert_steering_value_to_rad(steering_value): """Converts the steering value in range -1, +1 to steering angle in radians.""" return steering_value * 0.91
98a67ea392d57da57ff23b47e68bef1dfc848aac
440,692
def start(ctx): """ Start Docker container for this project. """ return ctx.obj['docker'].start(verbose=ctx.obj['verbose'])
43491cf2cf87bf229ed769358f0ca5e8901a4cce
462,357
def strings_from_csv(file): """ Return a list of strings from a .csv fle. Parameters ---------- file : str Path of .csv file. Returns ------- list List of strings. """ with open(file, 'r') as f: strings = f.readlines() return [[i.rstrip('\n') for i i...
1dca6b20de46e755b96fe8bbf5de6da757129db9
212,277
def strip_padding(blocklen, data, padding_class=0x01): """ Strip the padding of decrypted data. Returns data without padding """ if padding_class == 0x01: tail = len(data) - 1 while data[tail] != '\x80': tail = tail - 1 return data[:tail]
651288c08134d90d42050b26328ef59824a08840
457,033
import re def query_and_ref_names_from_path(filepath): """ Return a tuple of the query and product names from a path including bin names separated by "_to". E.g. "potential_relpath/bin_a_to_bin_b" --> bin_a, bin_b :param filepath: string to search :return: dict containing the query_bin, ref...
9f8a9376e24b9ab927fd313f5cabcb58777de7c8
91,660
import logging def float_user_needs_update(float_data, latest_data): """ Return False if all values in latest_data matches all values in float_data. Return Trues otherwise indicating that the data in Float needs to be updated """ # Loop through latest data for key, value in latest_data.items(): # Lo...
2b0e72c07179472ccf410ac4f0f0c0fa00eed23c
564,118
def penn_to_wordnet(tag): """ Convert a Penn Treebank PoS tag to WordNet PoS tag. """ if tag in ['NN', 'NNS', 'NNP', 'NNPS']: return 'n' #wordnet.NOUN elif tag in ['VB', 'VBD', 'VBG', 'VBN', 'VBP', 'VBZ']: return 'v' #wordnet.VERB elif tag in ['RB', 'RBR', 'RBS']: return ...
3935e5bfcda542d819d5cdeee3b02541c968461d
534,800
from typing import Tuple def cnnxfc_params( image_size: Tuple[int, int], n_channels: int, out_features: int, bias: bool = True ): """ Return the number of parameters in a CNN followe by a linear layer. Args: image_size: Size of the output of the CNN. n_channels: Number of the image's c...
9d34a900a821031cb183a26dd5780e3c52a7016e
541,203
import json import re def maybe_replace_staging(page_data, module_config): """Replace host in JSON data if configured.""" if module_config.replace_staging_host: json_data = json.dumps(page_data) json_data = re.sub( re.escape(module_config.stage_host), module_config.prod_host, json...
c4f0e28d33e4a2adf3344c72615ecd64b47870ea
135,707