content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
import sympy
def antal_h_coefficient(index, game_matrix):
"""
Returns the H_index coefficient, according to Antal et al. (2009), as given by equation 2.
H_k = \frac{1}{n^2} \sum_{i=1}^{n} \sum_{j=1}^{n} (a_{kj}-a_{jj})
Parameters
----------
index: int
game_matrix: sympy.Matrix
Ret... | 0e05a6a622ef24ff63b18b9c8b80348b860a16c3 | 702,877 |
from typing import List
from typing import Dict
def _cx_to_dict(list_of_dicts: List[Dict], key_tag: str = "k", value_tag: str = "v") -> Dict:
"""Convert a CX list of dictionaries to a flat dictionary."""
return {d[key_tag]: d[value_tag] for d in list_of_dicts} | ea80e9a50ea04536c2ed068d19220b56a9bdf3ed | 702,879 |
import typing
import pathlib
import itertools
def find_pyfiles() -> typing.Iterator[pathlib.Path]:
"""Return an iterator of the files to format."""
return itertools.chain(
pathlib.Path("../gdbmongo").rglob("*.py"),
pathlib.Path("../gdbmongo").rglob("*.pyi"),
pathlib.Path("../stubs").rg... | 74b0c11771799fba6090569595d24e70ec68899d | 702,880 |
def visibility_define(config):
"""Return the define value to use for NPY_VISIBILITY_HIDDEN (may be empty
string)."""
hide = '__attribute__((visibility("hidden")))'
if config.check_gcc_function_attribute(hide, 'hideme'):
return hide
else:
return '' | b08e8515440c4bf1ebec51c4100e55fe9f14b17d | 702,882 |
def calculate_num_points_in_solution(solution):
"""Calculates the number of data points in the given solution."""
return sum(len(points) for points in solution.values()) | c75f7cb7d9c8c2731e4698040954c559b6b5d4ec | 702,883 |
import re
def get_polygon_speed(polygon_name):
"""Returns speed unit within a polygon."""
result = re.search(r"\(([0-9.]+)\)", polygon_name)
return float(result.group(1)) if result else None | 2d2cc99f30153c4fbc9ac358ad3debc15fc3227e | 702,884 |
import copy
def random_reset_mutation(random, candidate, args):
"""Return the mutants produced by randomly choosing new values.
This function performs random-reset mutation. It assumes that
candidate solutions are composed of discrete values. This function
makes use of the bounder function as specif... | c357237e22e34b7496f8cc17f4ad0efa2bd4621d | 702,891 |
import re
def normalise_name(raw_name):
"""
Normalise the name to be used in python package allowable names.
conforms to PEP-423 package naming conventions
:param raw_name: raw string
:return: normalised string
"""
return re.sub(r"[-_. ]+", "_", raw_name).lower() | 2c9aea4a3e83fdb52f952d2308de29d8948f6917 | 702,893 |
def timestr_mod24(timestr):
"""
Given a GTFS HH:MM:SS time string, return a timestring in the same
format but with the hours taken modulo 24.
"""
try:
hours, mins, seconds = [int(x) for x in timestr.split(":")]
hours %= 24
result = "{:02d}:{:02d}:{:02d}".format(hours, mins, s... | ea049f4b31861de56b04dba6f4356ed46930af44 | 702,894 |
from functools import reduce
def constant_time_compare(x, y):
"""
Compares two byte strings in a way such that execution time is constant
regardless of how much alike the input values are, provided that they
are of the same length.
Comparisons between user input and secret data such as calculated... | fe7fc348d367907eee2c9df3b7d0fbe232072714 | 702,900 |
def _str2bool(string):
"""Converts either 'true' or 'false' (not case-sensitively) into a boolean."""
if string is None:
return False
else:
string = string.lower()
if string == 'true':
return True
elif string == 'false':
return False
else:
raise ValueError(
'String should either... | 97755d1901a836bb1e3ce062afdbffc8b5b92de1 | 702,901 |
import math
def _get_alpha_bar_from_time(t):
"""
Noise scheduling method proposed by Nichol et. al to avoid too noisy image especially for smaller resolution.
This strategy creates beta as follows:
alpha_bar(t) = f(t) / f(0)
f(t) = cos((t / T + s) / (1 + s) * PI / 2) ** 2
beta(t) ... | ecb79239e2181d6e17db0b30885ec68d48b0a2d3 | 702,902 |
def ExtractModuleIdIfValidBreakpad(file_path):
"""Extracts breakpad file's module id if the file is valid.
A breakpad file is valid for extracting its module id if it
has a valid MODULE record, formatted like so:
MODULE operatingsystem architecture id name
For example:
MODULE mac x86_64 1240DF90E9AC39038E... | e846cf05976c2c1622160d1a2a639d605e072417 | 702,904 |
from datetime import datetime
import pytz
def _timestamp_to_iso_str(timestamp):
"""
Converts the timestamp value into a iso str
Args:
timestamp(float): the timestamp to convert
Returns:
str: converted timestamp
"""
return datetime.fromtimestamp(timestamp).replace(tzinfo=pytz.... | 89257c74a96c5335bc25ef617e41c0eeeb31021e | 702,905 |
def subtract_mean_vector(frame):
"""
Re-center the vectors in a DataFrame by subtracting the mean vector from
each row.
"""
return frame.sub(frame.mean(axis='rows'), axis='columns') | 4a6207889b958aebd608c349ad889e109ab3f4a9 | 702,906 |
def to_location(maiden: str, center: bool = False) -> tuple[float, float]:
"""
convert Maidenhead grid to latitude, longitude
Parameters
----------
maiden : str
Maidenhead grid locator of length 2 to 8
center : bool
If true, return the center of provided maidenhead grid square... | fddcbdab4f3e0f812dd7fac3509e66bc63f8fb84 | 702,908 |
def flipDP(directionPointer: int) -> int:
"""
Cycles the directionpointer 0 -> 1, 1 -> 2, 2 -> 3, 3 -> 0
:param directionPointer: unflipped directionPointer
:return: new DirectionPointer
"""
if directionPointer != 3:
return directionPointer + 1
return 0 | 928347a5c1934c822c77434ca9a91d913ef7f3b5 | 702,909 |
def process_link(link):
"""
Get text and link from an anchor
"""
return link.text_content(), link.get('href') | 34429289076c8518b076fdf0f228eb6948109c6c | 702,913 |
def merge_unique(list1, list2):
"""
Merge two list and keep unique values
"""
for item in list2:
if item not in list1:
list1.append(item)
return list1 | ecfd32178541dcb5956d4c1c74dc9cea2ab1fa45 | 702,916 |
def increment(number: int) -> int:
"""Increment a number.
Args:
number (int): The number to increment.
Returns:
int: The incremented number.
"""
return number + 1 | 27f4becd9afb747b22de991ab4cf030b14d3dac5 | 702,917 |
import re
def normalize_name(name: str) -> str:
"""Replace hyphen (-) and slash (/) with underscore (_) to generate valid
C++ and Python symbols.
"""
name = name.replace('+', '_PLUS_')
return re.sub('[^a-zA-Z0-9_]', '_', name) | 46624c7180b1303e715d73aefe75cdd8e49b4a22 | 702,919 |
import torch
def project_to_2d(X, camera_params):
"""
Project 3D points to 2D using the Human3.6M camera projection function.
This is a differentiable and batched reimplementation of the original MATLAB script.
Arguments:
X -- 3D points in *camera space* to transform (N, *, 3)
camera_para... | 0727efaeecfa48540590461f7d9222c8e6071f6d | 702,924 |
import hashlib
def checksum_md5(filename, blocksize=8192):
"""Calculate md5sum.
Parameters
----------
filename : str or pathlib.Path
input filename.
blocksize : int
MD5 has 128-byte digest blocks (default: 8192 is 128x64).
Returns
-------
md5 : str
calculated ... | 759c0c5cbc37ebe0cc85eb8156127308eff354bc | 702,927 |
def normalize_volume_and_number(volume, number):
"""
Padroniza os valores de `volume` e `number`
Args:
volume (None or str): volume se aplicável
number (None or str): número se aplicável
Notas:
- se `number` é igual a `ahead`, equivale a `None`
- se `00`, equivale a ... | 1ec42912b942f6c1b7e22d2e64c4d842af100877 | 702,928 |
from typing import List
from typing import Tuple
def style_close(style: List[Tuple[str, str]]) -> str:
"""
HTML tags to close a style.
>>> style = [
... ("font", 'color="red" size="32"'),
... ("b", ""),
... ("i", ""),
... ("u", ""),
... ]
>>> style_close(style)
... | 2043803e50230f139a6a60599b40c53461ed6ed8 | 702,929 |
def process_categories(cat_path):
""" Returns the mapping between the identifier of a category in
Places365 and its corresponding name
Args:
cat_path: Path containing the information about the Places365
categories
"""
result = {}
with open(cat_path) as f:
lines = f.re... | f87741b990ee9ab9c8216112df73c7aa5bab8d49 | 702,940 |
import struct
def fread(f,byteLocation,structFormat=None,nBytes=1):
"""
Given an already-open (rb mode) file object, return a certain number of bytes at a specific location.
If a struct format is given, calculate the number of bytes required and return the object it represents.
"""
f.seek(byteLoca... | ae86bb1f3bc839053ca34c8bf2b4beb0af04aaee | 702,942 |
def _get_year(obj):
"""
Get the year of the entry.
:param obj: year string object
:return: entry year or none if not valid value
"""
year = obj[0:4]
try:
year = int(year)
except ValueError:
year = None
return year | 6d3cbcc8759096ec3e798e90dc3a307b4a34b6ae | 702,945 |
import math
def lat_meters(lat: float) -> float:
"""
Transform latitude degree to meters.
Parameters
----------
lat : float
This represent latitude value.
Returns
-------
float
Represents the corresponding latitude value in meters.
Examples
--------
Latit... | c31025552778b0039079d33e134e0b19077b83d4 | 702,949 |
def getFilteredLexicon(lexicondict, allwords):
""" Returns a lexicon with just the necessary words.
Assumes all wanted keys exist in the given lexicon """
return { word: lexicondict[word] for word in allwords } | db3c58b71df848ef5b1d49ebdd4670a552481c64 | 702,951 |
import unittest
def filter_suite(condition, suite):
"""Return tests for which ``condition`` is True in ``suite``.
:param condition: A callable receiving a test and returning True if the
test should be kept.
:param suite: A test suite that can be iterated. It contains either tests
or suit... | 9131d49d3f87a117d2b9625d521e932db2666860 | 702,952 |
import re
def read_cpr(path):
"""Read and parse a CPR file. Return masks, which are (id, RLE data).
Note: Python 3.6.4 docs say its XML module is not secure, se we use regexp.
"""
# Example: <Mask id="123">[12 34 56]</Mask>
mask_pattern = r'<Mask\s.*?id="(.*?)".*?>.*?\[(.*?)\].*?</Mask>'
text... | b5781607c150d0521d816c9027660e2b5e4b0fe0 | 702,965 |
import math
def schaffer6(phenome):
"""The bare-bones Schaffer function 6."""
sum_of_squares = phenome[0] ** 2 + phenome[1] ** 2
result = math.sin(math.sqrt(sum_of_squares)) ** 2 - 0.5
result /= (1.0 + 0.001 * sum_of_squares) ** 2
result += 0.5
return result | 80f19b28ebf4511a0670dfa622ffd3c55e8ec670 | 702,966 |
import re
import socket
def get_host_name() -> str:
"""Get the host name.
:return: A string value.
"""
return re.sub(r"\.(?:local|lan)", "", socket.gethostname()) | 225889a0bf40943ef962903551bde85fd2729ac8 | 702,970 |
def fix_hyphen_commands(raw_cli_arguments):
"""Update options to match their module names with underscores."""
for i in ['gen-sample', 'run-python', 'run-stacker']:
raw_cli_arguments[i.replace('-', '_')] = raw_cli_arguments[i]
raw_cli_arguments.pop(i)
return raw_cli_arguments | cbc420547f1d3a04787d059aa09eb0199df82dba | 702,971 |
def read_line_offset(file, offset):
""" Seek to offset in file, read a line and return the line and new offset """
fp = open(file, "r")
fp.seek(offset, 0)
line = fp.readline()
offset = fp.tell()
fp.close()
return (line, offset) | 429d592cf44e1f287eea5a67302a78473eb2362f | 702,973 |
def calculate_bmi(weight, height):
"""
Calculates BMI given the weight and height as float
"""
bmi = (weight / (height * height)) * 703.0
return bmi | 8495b11598e50516dca80965d5063df92aa78f40 | 702,974 |
def argstr(arg): # pragma: no cover
"""
Return string representation of a function argument.
:param object arg: Argument object. Differs between Python versions.
:return: String name of argument.
"""
if isinstance(arg, str):
return arg
if 'id' in arg._fields:
return arg.id
... | 565349fc4a1fb9b28e8333a44893925cea9e72d9 | 702,976 |
def getDistance(sensor):
"""Return the distance of an obstacle for a sensor."""
# Special case, when the sensor doesn't detect anything, we use an
# infinite distance.
if sensor.getValue() == 0:
return float("inf")
return 5.0 * (1.0 - sensor.getValue() / 1024.0) | 68ff9e0c8c4dd7687e328d3b9c4634677cfe25cd | 702,978 |
import math
def circles_intersection(x_a, y_a, r_a, x_b, y_b, r_b):
"""
Returns the point of intersection of two circkes
:param x_a: x coordinate of the center of first circle
:param y_a: y coordinate of the center of first circle
:param r_a: radius of first circle
:param x_b: x coordinate of ... | dc504bbe970c83bf1caf7727613ecaa44c1c818e | 702,985 |
def bubble_sort(vals):
"""Sort the given array using bubble sort."""
for i in range(len(vals) - 1):
for j in range(len(vals) - i - 1):
if vals[j] > vals[j + 1]:
vals[j], vals[j + 1] = vals[j + 1], vals[j]
return vals | ee0286dd53da0fbfc508fa1c26dbf913ba8f92ce | 702,993 |
def public_byte_prefix(is_test):
"""Address prefix. Returns b'\0' for main network and b'\x6f' for testnet"""
return b'\x6f' if is_test else b'\0' | 3ecc4fe0cbbd8dee1a91f90e0112d9be3184fc73 | 702,994 |
import json
def _json_read(filename):
"""Read a json into a dict."""
with open(filename) as file:
return json.load(file) | 84187d2a2281d2725adb8dae903253bdcd41e2b9 | 702,996 |
def addLists(list1, list2):
"""Add lists together by value. i.e. addLists([1,1], [2,2]) == [3,3]."""
# Find big list and small list
blist, slist = list(list2), list(list1)
if len(list1) > len(list2):
blist, slist = slist, blist
# Overlay small list onto big list
for i, b in enumerate(sl... | f5469dab8fd2c62d2d3ffed253803c1a3d343281 | 702,997 |
import tarfile
def files_from_archive(tar_archive: tarfile.TarFile):
"""
Extracts only the actual files from the given tarfile
:param tar_archive: the tar archive from which to extract the files
:return: List of file object extracted from the tar archive
"""
file_members = []
# Find the ... | 09ead0b2b955afdc5bf96a8e0a8717989c155406 | 702,998 |
def split_nth(string, count):
"""
Splits string to equally-sized chunks
"""
return [string[i:i+count] for i in range(0, len(string), count)] | 38833ef711ce04f5563b343f477e7792035ec669 | 703,003 |
import requests
def check_all_links(links):
""" Check that the provided links are valid.
Links are considered valid if a HEAD request to the server
returns a 200 status code.
"""
broken_links = []
for link in links:
head = requests.head(link)
if head.status_code != 200:
... | b6e784da72b4f81af3e393804ef3f776c2f3fc85 | 703,006 |
def compute_seen_words(inscription_list):
"""Computes the set of all words seen in phrases in the game"""
return {word
for inscription in inscription_list
for phrase in inscription['phrases']
for word in phrase.split()} | 496fc64ee37a6a6b0b3df0c3e9230d7b7ef46d0f | 703,008 |
from typing import List
def _get_create_repo(request) -> List[str]:
"""
Retrieves the list of all GIT repositories to be created.
Args:
request: The pytest requests object from which to retrieve the marks.
Returns: The list of GIT repositories to be created.
"""
names = request.confi... | 4ac8cefefb75af3bb86fcc16f5c8b79953b136bf | 703,012 |
def _check_electrification_scenarios_for_download(es):
"""Checks the electrification scenarios input to :py:func:`download_demand_data`
and :py:func:`download_flexibility_data`.
:param set/list es: The input electrification scenarios that will be checked. Can
be any of: *'Reference'*, *'Medium'*, *... | ccd1ec8f0b1349267ba1334f7744056bc43e32ec | 703,014 |
def header_is_sorted_by_coordinate(header):
"""Return True if bam header indicates that this file is sorted by coordinate.
"""
return 'HD' in header and 'SO' in header['HD'] and header['HD']['SO'].lower() == 'coordinate' | b656770806818abe742be32bc14c31a8a8e3e535 | 703,016 |
import types
def is_variable(tup):
""" Takes (name, object) tuple, returns True if it is a variable.
"""
name, item = tup
# callable()
# 函数用于检查一个对象是否是可调用的。如果返回True,object仍然可能调用失败;
# 但如果返回False,调用对象ojbect绝对不会成功。
# 对于函数, 方法, lambda 函式, 类, 以及实现了 __call__
# 方法的类实例, 它都返回 True。
if callab... | 81055d1ed252160c417b386c875e818b87780f14 | 703,020 |
def mps_to_kmph(mps):
"""
Transform a value from meters-per-second to kilometers-per-hour
"""
return mps * 3.6 | fee133def1727801e5e473d3ffb2df6c7e733a04 | 703,022 |
def create_list_id_title(sheets: list) -> list:
"""
Args:
this function gets a list of all the sheets of a spreadsheet
a sheet is represented as a dict format with the following fields
"sheets" : [
{
"properties": {
... | a32d2cbfce6f06d326f49e69983e05e67bfc1697 | 703,025 |
def parse_glyphs_groups(names, groups):
"""
Parse a ``gstring`` and a groups dict into a list of glyph names.
"""
glyph_names = []
for name in names:
# group names
if name[0] == '@':
group_name = name[1:]
if group_name in groups:
glyph_names +... | 50e79acffdc6d26576e8524b52219afad3e40a4e | 703,027 |
def perc_range(n, min_val, max_val, rounding=2):
"""
Return percentage of `n` within `min_val` to `max_val` range. The
``rounding`` argument is used to specify the number of decimal places to
include after the floating point.
Example::
>>> perc_range(40, 20, 60)
50
"""
ret... | 379515f6c0483b4bfed93d0c1012bb2ca111e410 | 703,032 |
def sort_sequence_by_key(sequence, key_name, reverse=False):
"""
often when setting up initial serializations (especially during testing),
I pass a list of dictionaries representing a QS to some fn.
That list may or may not be sorted according to the underlying model's "order" attribute
This fn sort... | fbe46c942ac35d5399450c6bba430a096e6b7503 | 703,033 |
def width_from_bitdefs(bitdefs):
"""
Determine how wide an binary value needs to be based on bitdefs used
to define it.
Args:
bitdefs (list(BitDef)): List of bitdefs to find max width of
Returns:
(int): Maximum width
"""
max_index = max([bitdef.end for bitdef in bitdefs])
... | 59503f335d6d427579be730806c738108091e9ed | 703,034 |
from typing import Sequence
import difflib
def _validate_magics_with_black(before: Sequence[str], after: Sequence[str]) -> bool:
"""
Validate the state of the notebook before and after running nbqa with black.
Parameters
----------
before
Notebook contents before running nbqa with black
... | e6e655f2e6ea5e8d055f27e8da14cf0233c0c202 | 703,037 |
def get_var_names(var_name):
"""Defines replacement dictionary for the bare variable name and
the names derived from it - the optimization flag and the identifier name.
"""
repl = dict()
repl['opt_var_name'] = "Opt_%s"%var_name
repl['id_var_name'] = "ID_%s"%var_name
repl['var_name'] = var_name
return... | 37999ffed0a0df1dbf736ada0cc355080dd9997f | 703,046 |
from typing import List
from typing import Dict
import re
def parse_header_links(value: str) -> List[Dict[str, str]]:
"""
Returns a list of parsed link headers, for more info see:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link
The generic syntax of those is:
::
Link: < u... | 536d3f2b477666c076ac29312f3acfe63f40e324 | 703,049 |
def parseFloat(value, ret=0.0):
"""
Parses a value as float.
This function works similar to its JavaScript-pendant, and performs
checks to parse most of a string value as float.
:param value: The value that should be parsed as float.
:param ret: The default return value if no integer could be pa... | 6828cc19882dcbfcf7b83781b1e79a6014034cad | 703,050 |
def discard_inserted_documents(error_documents, original_documents):
"""Discard any documents that have already been inserted which are violating index constraints
such documents will have an error code of 11000 for a DuplicateKey error
from https://github.com/mongodb/mongo/blob/master/src/mongo/base/... | 9d7d47a0ade2300449a7f1a4a20c3a70f6dce583 | 703,051 |
def list_folder(drive, folder_id):
"""
Lists contents of a GoogleDriveFile that is a folder
:param drive: Drive object to use for getting folders
:param folder_id: The id of the GoogleDriveFile
:return: The GoogleDriveList of folders
"""
_q = {'q': "'{}' in parents and trashed=false".format(... | 1ea5837d6096f2f9c1f0485d5a02bd43a8b8c55e | 703,052 |
import struct
def htons(cpu_context, func_name, func_args):
"""
Convert the provided 16-bit number in host byte order (little-endian) to network byte order (big-endian)
"""
le_port = func_args[0]
port_data = struct.pack("<H", le_port)
return struct.unpack(">H", port_data)[0] | 095be37630fbe0dc86ea5e731180249c29ccac85 | 703,054 |
def ordinal_number(n: int):
"""
Returns a string representation of the ordinal number for `n`
e.g.,
>>> ordinal_number(1)
'1st'
>>> ordinal_number(4)
'4th'
>>> ordinal_number(21)
'21st'
"""
# from https://codegolf.stackexchange.com/questions/4707/outputting-ordinal-numbers-1... | 9cb2b333cfe7d4e7b115d21d9d3c1bbaec02cdd9 | 703,057 |
def mode_batch_size(mode, hparams):
"""Returns the batch size for a given mode (train or eval).
Args:
mode: Either 'train' or 'eval'.
hparams: Hyperparameters.
Returns:
Integer batch size.
Raises:
ValueError: If mode is not 'train' or 'eval'.
"""
if mode == 'train':
return hparams.bat... | 42f45e54698a539b27ad764b0c6584fb3620990d | 703,059 |
from typing import Optional
import ast
def _parse_type_comment(
type_comment: Optional[str],
) -> Optional[ast.expr]:
"""
Attempt to parse a type comment. If it is None or if it fails to parse,
return None.
"""
if type_comment is None:
return None
try:
# pyre-ignore[16]: th... | 49aafd9df3d590ccebf1c4b20b0c2a04640a9797 | 703,061 |
def identity(obj):
"""
Identity function computing no operation
Parameters
----------
obj : object
any object
Returns
-------
obj
the input object itself
"""
return obj | 252a44ce3251b74ad25e28bf6bff462f6227f04b | 703,067 |
def extract(key, items):
"""Return the sorted values from dicts using the given key.
:param key: Dictionary key
:type key: str | unicode
:param items: Items to filter.
:type items: [dict]
:return: Set of values.
:rtype: [str | unicode]
"""
return sorted(item[key] for item in items) | d39b6d42a08ea8e2e7d7488fb00a28243c9a6718 | 703,070 |
def format_kvps(mapping, prefix=""):
"""Formats a mapping as key=value pairs.
Values may be strings, numbers, or nested mappings.
Nested mappings, e.g. host:{ip:'0.0.0.1',name:'the.dude.abides'},
will be handled by prefixing keys in the sub-mapping with the key,
e.g.: host.ip=0.0.0.1 host.name=the.... | 4780d5c705a8805331a1d981e87fa3d3dca263a8 | 703,072 |
import torch
def project(meta_weights, P, Q):
""" project meta_weights to sub_weights
Args:
meta_weights: a 4-D tensor [cout, cin, k, k], the meta weights for one-shot model;
P: a 2-D tensor [cout, cout_p], projection matrix along cout;
Q: a 2-D tensor [cin, cin_p], projection matrix along cin;
Retu... | a693d51a4a74358bd831954c46bb8cb993dabf66 | 703,074 |
def _is_not_blank(line):
"""Return true if `line` is not blank."""
return len(line.split())>0 | 835d991d71dcb59075b6ae2b317c8fb8c51abee9 | 703,076 |
def overlaps(box1, box2):
"""
Checks whether two boxes have any overlap.
Args:
box1: (float, float, float, float)
Box coordinates as (x0, y0, x1, y1).
box2: (float, float, float, float)
Box coordinates as (x0, y0, x1, y1).
Returns:
bool
... | b8bf96e87f45f24d337b503184670d0f56d209e0 | 703,077 |
def to_sendeable_block_original_bus(array_of_msgs):
"""Given an array of msgs return it in the format
panda.can_send_many expects.
Input looks like: [(512, bytearray(b'>\x80\x1c'), 0), ...]
Output looks like: [(512, '>\x80\x1c', 0), ...]
"""
new_arr = []
for msg in array_of_msgs:
ne... | 24fd1cdf8c1bfed095d1685a8eaa246c89425958 | 703,080 |
import yaml
def _GetErrorDetailsSummary(error_info):
"""Returns a string summarizing `error_info`.
Attempts to interpret error_info as an error JSON returned by the Apigee
management API. If successful, the returned string will be an error message
from that data structure - either its top-level error message... | 276e8520bc5ca790fc61c71e0f43ebee0d78b597 | 703,084 |
def format_duration_hhmm(d):
"""
Utility function to format durations in the widget as hh:mm
"""
if d is None:
return ''
elif isinstance(d, str):
return d
hours = d.days * 24 + d.seconds // 3600
minutes = int(round((d.seconds % 3600) / 60))
return '{}:{:02}'.format(hours... | 941670b1a16c87816589cfb05ff80b651857d337 | 703,086 |
def try_int(obj):
"""return int(obj), or original obj if failed"""
try:
return int(obj)
except ValueError: # invalid literal for int()
return obj | 21613ce19e86f5c5545e9dc4b161f6ddc95fd0ce | 703,088 |
def _anonymous_model_data(ops_data):
"""Returns a dict representing an anonymous model.
ops_data must be a dict representing the model operations. It will
be used unmodified for the model `operations` attribute.
"""
return {"model": "", "operations": ops_data} | 6b64f9098b30cf3e079311b75ca136cfc2f7038f | 703,090 |
def encode_to_dict(encoded_str):
""" 将encode后的数据拆成dict
>>> encode_to_dict('name=foo')
{'name': foo'}
>>> encode_to_dict('name=foo&val=bar')
{'name': 'foo', 'val': 'var'}
"""
pair_list = encoded_str.split('&')
d = {}
for pair in pair_list:
if pair:
key = pair.spli... | a3af4d93d13404f01511483621e166c50d9e489e | 703,091 |
def taxonomy_levels_below(taxa_level):
"""
E.g. 'Order' --> ['Family', 'Genus']
"""
p_levels = ['Kingdom', 'Phylum', 'Class', 'Order', 'Family', 'Genus']
position_of_taxa_level = p_levels.index(taxa_level)
return p_levels[position_of_taxa_level + 1:] | 57e41b0042daa14b8ed09469006c6c3bdac320ec | 703,092 |
def sort(nodes, total_order, dedup=False):
"""Sorts nodes according to order provided.
Args:
nodes: nodes to sort
total_order: list of nodes in correct order
dedup: if True, also discards duplicates in nodes
Returns:
Iterable of nodes in sorted order.
"""
total_order_idx = {}
for i, nod... | 4cfb53593b3c862ab918507ea3d4fe94ab4899df | 703,093 |
def _test_against_patterns(patterns, entity_id):
"""Test entity against list of patterns, true if any match."""
for pattern in patterns:
if pattern.match(entity_id):
return True
return False | 16881be06e86ae3fe1afc9dc8fb642573cf6fdcf | 703,097 |
def find_root_visual(conn):
"""Find the xcffib.xproto.VISUALTYPE corresponding to the root visual"""
default_screen = conn.setup.roots[conn.pref_screen]
for i in default_screen.allowed_depths:
for v in i.visuals:
if v.visual_id == default_screen.root_visual:
return v | 930bb700bdcb141aba9fc4370d244b588357f8f1 | 703,099 |
import re
def creole_slugify(value):
"""Convert the given string to a slug consistent with heading IDs used
by our creole parser.
>>> creole_slugify("Only 20%!")
"only-20"
"""
if not value:
return value
# Only keep alphanumeric and space characters.
value = re.sub(r"[^a-zA-Z... | fe621981715372c4a9c03179d862b745551d87f2 | 703,100 |
def async_wraps(cls, wrapped_cls, attr_name):
"""Similar to wraps, but for async wrappers of non-async functions."""
def decorator(func):
func.__name__ = attr_name
func.__qualname__ = ".".join((cls.__qualname__, attr_name))
func.__doc__ = """Like :meth:`~{}.{}.{}`, but async.
... | c93fb2a52bfcb3edc9cbf0442138daa1ecf84dda | 703,103 |
def qgrams_to_char(s: list) -> str:
"""Converts a list of q-grams to a string.
Parameters
----------
s : list
List of q-grams.
Returns
-------
A string from q-grams.
"""
if len(s) == 1:
return s[0]
return "".join([s[0]] + [s[i][-1] for i in range(1, len(s))]) | cc7dc5eb4d5c9e3e5f751cf7c2190e68c3ba11bd | 703,109 |
import re
def arguments_from_docstring(doc):
"""Parse first line of docstring for argument name.
Docstring should be of the form ``min(iterable[, key=func])``.
It can also parse cython docstring of the form
``Minuit.migrad(self[, int ncall_me =10000, resume=True, int nsplit=1])``
"""
if doc... | 4b08f36678247df6119e594ff9859f697f2e8d23 | 703,114 |
def _check_mod_11_2(numeric_string: str) -> bool:
"""
Validate numeric_string for its MOD-11-2 checksum.
Any "-" in the numeric_string are ignored.
The last digit of numeric_string is assumed to be the checksum, 0-9 or X.
See ISO/IEC 7064:2003 and
https://support.orcid.org/knowledgebase/artic... | 685a9e8085000248290c9e482a115c99942c51d1 | 703,115 |
def dictize(aniter, mode, initial=None):
"""iter must contain (key,value) pairs. mode is a string, one of: replace, keep,
tally, sum, append, or a custom function that takes two arguments.
replace: default dict behavior. New value overwrites old if key exists. This
is essentially a pass-thru.
... | c56a2ad83ec9a45e87caa7def33c6b51f63655cb | 703,125 |
def read_txt_file(file_path, n_num=-1, code_type='utf-8'):
"""
read .txt files, get all text or the previous n_num lines
:param file_path: string, the path of this file
:param n_num: int, denote the row number decided by \n, but -1 means all text
:param code_type: string, the code of this file
... | 9c55d370d8e8610965e0f8c4b1bed85e6adcdc5b | 703,128 |
import torch
def l1_loss(pred_traj, pred_traj_gt):
"""
Input:
:param pred_traj: Tensor of shape (batch, seq_len)/(batch, seq_len). Predicted trajectory along one dimension.
:param pred_traj_gt: Tensor of shape (batch, seq_len)/(batch, seq_len).
Groud truth predictions along on... | 3fb4dd2b7fc85e8f32610065078aa3dc98d728d5 | 703,131 |
def _is_subexpansion_optional(query_metadata, parent_location, child_location):
"""Return True if child_location is the root of an optional subexpansion."""
child_optional_depth = query_metadata.get_location_info(child_location).optional_scopes_depth
parent_optional_depth = query_metadata.get_location_info(... | 29391226258e75d434e07c291fe9590c1810d85b | 703,134 |
def _filter_labels(text, labels, allowed_labels):
"""Keep examples with approved labels.
:param text: list of text inputs.
:param labels: list of corresponding labels.
:param allowed_labels: list of approved label values.
:return: (final_text, final_labels). Filtered version of text and labels
... | e17ed7659acbdadc71a6b3f5b522af1e34d40370 | 703,135 |
def array_check(lst):
"""
Function to check whether 1,2,3 exists in given array
"""
for i in range(len(lst)-2):
if lst[i] == 1 and lst[i+1] == 2 and lst[i+2] == 3:
return True
return False | ef60b52a9d7300fa458b503f49996aec0f0831ad | 703,139 |
from typing import List
from typing import Any
def list_difference(list_1: List[Any], list_2: List[Any]) -> List[Any]:
""" This Function that takes two lists as parameters
and returns a new list with the values that are in l1, but NOT in l2"""
differ_list = [values for values in list_1 if values no... | 3831d799bb40080b828ee90e2929f77ff8aeb7ba | 703,140 |
def correlation(self, column_a, column_b):
"""
Calculate correlation for two columns of current frame.
Parameters
----------
:param column_a: (str) The name of the column from which to compute the correlation.
:param column_b: (str) The name of the column from which to compute the correlation.... | b8f1600e0b2968ca4013418b2fbfda0b13f5911a | 703,143 |
def good_fft_number(goal):
"""pick a number >= goal that has only factors of 2,3,5. FFT will be much
faster if I use such a number"""
assert goal < 1e5
choices = [2**a * 3**b * 5**c for a in range(17) for b in range(11)
for c in range(8)]
return min(x for x in choic... | e469a37f28869dca520aea3520fa0d763e9bb8ae | 703,149 |
def connect_to_ecs(env):
"""
Return boto connection to the ecs in the specified environment's region.
"""
rh = env.resource_handler.cast()
wrapper = rh.get_api_wrapper()
client = wrapper.get_boto3_client(
'ecs',
rh.serviceaccount,
rh.servicepasswd,
env.aws_region
... | e4c0b7ad80c18fd6d2a90df6670ca9bfa6f1cbe3 | 703,150 |
def rotated_array_search(input_list, number):
"""
Find the index by searching in a rotated sorted array
"""
high = len(input_list) - 1
low = 0
while low <= high:
mid = (low + high) // 2
if input_list[mid] == number:
return mid
elif input_list[mid] < number <= ... | c3deb50e608c58e5e11665d949a602cc661305ae | 703,152 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.