content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def load_coco_name(path):
"""Load labels from coco.name
"""
coco = {}
with open(path, 'rt') as file:
for index, label in enumerate(file):
coco[index] = label.strip()
return coco | 2da456b7c2879ec5725172280dacbcaaacd86bfc | 704,690 |
import base64
import gzip
import json
def decompress_metadata_string_to_dict(input_string): # pylint: disable=invalid-name
"""
Convert compact string format (dumped, gzipped, base64 encoded) from
IonQ API metadata back into a dict relevant to building the results object
on a returned job.
Parame... | c521da786d2a9f617c560916cc5f058b20cb3e21 | 704,691 |
import struct
import socket
def inet_atoni(ip):
"""Like inet_aton() but returns an integer."""
return struct.unpack('>I', socket.inet_aton(ip))[0] | 3bd18b7aecf9a5a45033c7873163ee1387cb8a13 | 704,692 |
import re
def rep_unicode_in_code(code):
""" Replace unicode to str in the code
like '\u003D' to '='
:param code: type str
:return: type str
"""
pattern = re.compile('(\\\\u[0-9a-zA-Z]{4})')
m = pattern.findall(code)
for item in set(m):
code = code.replace(item, chr(int(item[2... | 70e28ea741f0347190628876b59e27a56a5c0ccf | 704,693 |
import ast
def is_py3(file_path):
"""Check if code is Python3 compatible."""
# https://stackoverflow.com/a/40886697
code_data = open(file_path, "rb").read()
try:
ast.parse(code_data)
except SyntaxError:
return False
return True | 78a48bdcc682108ce4fbe6fffe4a235898beec1c | 704,699 |
def part_1(input_data: list[int]) -> int:
"""Count the number of times a depth measurement increases from the previous measurement.
Args:
input_data (str): depths
Returns:
int: number of depth increases
"""
inc_count = 0
for i, depth in enumerate(input_data):
if i != 0 a... | 3ee506aca019f9393c93ced75e430d53b31a9fc2 | 704,702 |
def single_varint(data, index=0):
"""
The single_varint function processes a Varint and returns the
length of that Varint.
:param data: The data containing the Varint (maximum of 9
bytes in length as that is the maximum size of a Varint).
:param index: The current index within the data.
:ret... | 55b052300cc0cf5ac2fd8f7451ac121b408c1313 | 704,703 |
from typing import Tuple
def _color_int_to_rgb(integer: int) -> Tuple[int, int, int]:
"""Convert an 24 bit integer into a RGB color tuple with the value range (0-255).
Parameters
----------
integer : int
The value that should be converted
Returns
-------
Tuple[int, int, int]:
... | df3eb5ad92d9383b0e6fe5c1603e0caec0df5c45 | 704,705 |
def label2binary(y, label):
"""
Map label val to +1 and the other labels to -1.
Paramters:
----------
y : `numpy.ndarray`
(nData,) The labels of two classes.
val : `int`
The label to map to +1.
Returns:
--------
y : `numpy.ndarray`
(nData,) Maps ... | 5bce8491e9eef3a8c36b784ee0e252c641b24fdf | 704,706 |
def extract_power(eeg, D=3, dt=0.2, start=0):
""" extract power vaules for image
Parameters
----------
seizure : EEG | dict
eeg data
D : int, optional
epoch duration, by default 3
dt : float, optional
time step (seconds), by default 0.2
start : int, optional
... | 04c3fed38fa2a2d46ba7edee4bb3f04011d9d2a7 | 704,708 |
def calc_fm_perp_for_fm_loc(k_loc_i, fm_loc):
"""Calculate perpendicular component of fm to scattering vector."""
k_1, k_2, k_3 = k_loc_i[0], k_loc_i[1], k_loc_i[2]
mag_1, mag_2, mag_3 = fm_loc[0], fm_loc[1], fm_loc[2]
mag_p_1 = (k_3*mag_1 - k_1*mag_3)*k_3 - (k_1*mag_2 - k_2*mag_1)*k_2
mag_p_2 = (k_... | 00ba68c74d781748f39d2a577f227316dc523f0f | 704,710 |
from typing import Optional
def injection_file_name(
science_case: str, num_injs_per_redshift_bin: int, task_id: Optional[int] = None
) -> str:
"""Returns the file name for the raw injection data without path.
Args:
science_case: Science case.
num_injs_per_redshift_bin: Number of injectio... | 57b034b6a60c317f0c071c1313d0d99f2802db30 | 704,717 |
def sd_title(bs4_object, target=None):
"""
:param bs4_object: An object of class BeautifulSoup
:param target: Target HTML tag. Defaults to class:title-text, a dict.
:return: Returns paper title from Science Direct
"""
if target is None:
target = {"class": "title-text"}
return bs4_o... | 8429fe680fafb86c773a0cd2b3280e893b95fc9a | 704,720 |
def split_formula(formula, net_names_list):
"""
Splits the formula into two parts - the structured and unstructured part.
Parameters
----------
formula : string
The formula to be split, e.g. '~ 1 + bs(x1, df=9) + dm1(x2, df=9)'.
net_names_list : list of strings
A... | 1fce8617cbdaf767c1aebb6d0d685ca63975c820 | 704,721 |
import requests
def analyze_comments_page(username, repo, per_page, page, print_comments, print_stage_results):
"""
Analyzes one page of GitHub comments. Helping function.
Parameters
----------
username : str
The GitHub alias of the repository owner
repo : str
The GitHub repo... | e3d153a0319db0bc723df65cb8a92533f9b37b82 | 704,725 |
def get_remotes(y, x):
"""
For a given pair of ``y`` (tech) and ``x`` (location), return
``(y_remote, x_remote)``, a tuple giving the corresponding indices
of the remote location a transmission technology is connected to.
Example: for ``(y, x) = ('hvdc:region_2', 'region_1')``,
returns ``('hvdc... | 3c479d818947362349982c77a9bbd87a97a3d4d5 | 704,726 |
from typing import List
def ingrid(x: float, y: float, subgrid: List[int]) -> bool:
"""Check if position (x, y) is in a subgrid"""
i0, i1, j0, j1 = subgrid
return (i0 <= x) & (x <= i1 - 1) & (j0 <= y) & (y <= j1 - 1) | d296d8a7abe5eeb3da8d57691755a2bd19dd15b6 | 704,727 |
from typing import Union
from pathlib import Path
from typing import Any
import json
def load_jsonl(path: Union[Path, str]) -> list[dict[str, Any]]:
""" Load from jsonl.
Args:
path: path to the jsonl file
"""
path = Path(path)
return [json.loads(line) for line in path.read_text().splitlines()] | a59d2920bfa491b1d4daa693b5e2e1b4846d6fc6 | 704,728 |
def row2string(row, sep=', '):
"""Converts a one-dimensional numpy.ndarray, list or tuple to string
Args:
row: one-dimensional list, tuple, numpy.ndarray or similar
sep: string separator between elements
Returns:
string representation of a row
"""
return sep.join("{0}".form... | f81a2ec54b8c37285715cadca4458918962440b9 | 704,734 |
def build_aggregation(facet_name, facet_options, min_doc_count=0):
"""Specify an elasticsearch aggregation from schema facet configuration.
"""
exclude = []
if facet_name == 'type':
field = 'embedded.@type'
exclude = ['Item']
elif facet_name.startswith('audit'):
field = facet... | b8c3f337143a229401b9a41a8fde8903027cf67e | 704,735 |
def inline(text):
"""
Convert all newline characters to HTML entities:
This can be used to prevent Hypertag from indenting lines of `text` when rendering parent nodes,
and to safely insert `text` inside <pre>, <textarea>, or similar elements.
"""
return text.replace('\n', ' ') | 658f7e5adbf5747ea069fad8a9599e9bd499a381 | 704,737 |
def get_bq_col_type(col_type):
"""
Return correct SQL column type representation.
:param col_type: The type of column as defined in json schema files.
:return: A SQL column type compatible with BigQuery
"""
lower_col_type = col_type.lower()
if lower_col_type == 'integer':
return 'I... | 86cac08a04d804cc6addbeee86014f1aa6d35735 | 704,738 |
import unicodedata
def remove_accents(string):
"""
Removes unicode accents from a string, downgrading to the base character
"""
nfkd = unicodedata.normalize('NFKD', string)
return u"".join([c for c in nfkd if not unicodedata.combining(c)]) | 41c8e05aa8982c85cf5cf2135276cdb5e26fefec | 704,740 |
def parse_range(rng, dictvars={}):
"""Parse a string with an integer range and return a list of numbers, replacing special variables in dictvars."""
parts = rng.split('-')
if len(parts) not in [1, 2]:
raise ValueError("Bad range: '%s'" % (rng,))
parts = [int(i) if i not in dictvars else dictva... | 214109a71c84d06241e29cacaa052d9ce00302c5 | 704,741 |
def is_odd(num: int) -> bool:
"""Is num odd?
:param num: number to check.
:type num: int
:returns: True if num is odd.
:rtype: bool
:raises: ``TypeError`` if num is not an int.
"""
if not isinstance(num, int):
raise TypeError("{} is not an int".format(num))
return num % 2 ==... | 0e5781596a99909e58583859948332c3afb06fb0 | 704,742 |
def interpolation(x0: float, y0: float, x1: float, y1: float, x: float) -> float:
"""
Performs interpolation.
Parameters
----------
x0 : float.
The coordinate of the first point on the x axis.
y0 : float.
The coordinate of the first point on the y axis.
x1 : float.
T... | f8fc96c6dc6c2eeeeceb22f92b32023f3873fe3e | 704,744 |
import collections
def product_counter_v3(products):
"""Get count of products in descending order."""
return collections.Counter(products) | 22c57d50dc36d3235e6b8b642a4add95c9266687 | 704,745 |
def rossler(x, y, z, a, b, c):
""" Rössler System of Ordinary Differential Equations """
dx = - y - z
dy = x + a*y
dz = b + z*(x - c)
return dx, dy, dz | bcf27c7ff8223681d6dc7d0c49497e975b826d80 | 704,747 |
import re
def get_extension(filename):
"""
Extract file extension from filename using regex.
Args:
filename (str): name of file
Returns:
str: the file extension
"""
match = re.search(r"\.(?P<ext>[^.]+)$", filename)
if match:
return match.group("ext")
raise Val... | 8f5195b339a153d5fa144182505dba986992d4df | 704,748 |
def scale_val(val, factor, direction):
"""Scale val by factor either 'up' or 'down'."""
if direction == 'up':
return val+(val*factor)
if direction == 'down':
return val-(val*factor)
raise ValueError('direction must be "up" or "down"') | 16c2efe16fc787fe4461fb0ae640e2cf22d556e0 | 704,749 |
def adjust_update_rules_for_fixed_nodes(predecessor_node_lists, truth_tables, fixed_nodes):
"""
Adjust "update rules" matrix and its free element vector so that the fixed nodes will end up in their fixed
states on each time step automatically, with no manual interventions required.
:param predecessor_n... | f41609ae25c3622100674372de5a364b095650f8 | 704,751 |
def parse_list_from_string(value):
"""
Handle array fields by converting them to a list.
Example:
1,2,3 -> ['1','2','3']
"""
return [x.strip() for x in value.split(",")] | 51e9c654b9d18b8be61c37aab5f5029dfdea2213 | 704,753 |
import itertools
def merge(d1, d2):
"""Merge to dicts into one.
Args:
d1 (dict): dataset 1
d2 (dict): dataset 2
Returns:
dict: merged dict
"""
return dict(itertools.chain(list(d1.items()), list(d2.items()))) | bb1d38f3cb45de6e98855fb04ae1d3d7e73e4a40 | 704,755 |
import re
def is_valid(number):
"""
Check if number is roman
:param number: string to check
:type number: str
:return: True or False
:rtype: bool
"""
return re.match(
r"^(M{0,3})(D?C{0,3}|C[DM])(L?X{0,3}|X[LC])(V?I{0,3}|I[VX])$", number
) | 52e1937418d28701ee3d30da139f16ae64cfe480 | 704,756 |
def row_contains_data(fieldnames, row):
"""Returns True if the value of atleast on of the fields is truthy"""
for field in fieldnames:
if row.get(field):
return True
return False | 7575d1280186c582a652ab37deb4a93e667b51b2 | 704,761 |
from typing import Callable
from typing import Iterable
from typing import List
def lmap(f: Callable, x: Iterable) -> List:
"""list(map(f, x))"""
return list(map(f, x)) | 51b09a3491769aafba653d4198fde94ee733d68f | 704,769 |
def estimate_infectious_rate_constant_vec(event_times,
follower,
t_start,
t_end,
kernel_integral,
count_events... | 207833e1b32885fe39a209bfef227665c8c59ad1 | 704,772 |
def find(word,letter):
"""
find letter in word , return first occurence
"""
index=0
while index < len(word):
if word[index]==letter:
#print word,' ',word[index],' ',letter,' ',index,' waht'
return index
index = index + 1
return -1 | bdeb0f0993fb4f7904b4e9f5244ea9d7817fa15f | 704,773 |
def has_file_ext(view, ext):
"""Returns ``True`` if view has file extension ``ext``.
``ext`` may be specified with or without leading ``.``.
"""
if not view.file_name() or not ext.strip().replace('.', ''):
return False
if not ext.startswith('.'):
ext = '.' + ext
return view.fil... | 043edf03874d1ec20e08fcb5795fd205206f7194 | 704,775 |
def get_genes(exp_file, samples, threshold, max_only):
"""
Reads in and parses the .bed expression file.
File format expected to be:
Whose format is tab seperated columns with header line:
CHR START STOP GENE <sample 1> <sample 2> ... <sample n>
Args:
exp_file (str): Name... | 62b27eef9c863078c98dee0d09bada5e058909e2 | 704,776 |
def conv_name_to_c(name):
"""Convert a device-tree name to a C identifier
This uses multiple replace() calls instead of re.sub() since it is faster
(400ms for 1m calls versus 1000ms for the 're' version).
Args:
name: Name to convert
Return:
String containing the C version of this... | 150af670d8befea7374bbb5b13da9d6e0734863e | 704,777 |
def get_account_id(role_arn):
"""
Returns the account ID for a given role ARN.
"""
# The format of an IAM role ARN is
#
# arn:partition:service:region:account:resource
#
# Where:
#
# - 'arn' is a literal string
# - 'service' is always 'iam' for IAM resources
# - 'regi... | 623eb66eefd59b9416deb478c527062ae4454df7 | 704,778 |
from typing import Any
def list_to_dict(data: list, value: Any = {}) -> dict:
"""Convert list to a dictionary.
Parameters
----------
data: list
Data type to convert
value: typing.Any
Default value for the dict keys
Returns
-------
dictionary : dict
Dictionary ... | 1e73bb6ca98b5e2d9b1e0f8d4cb19fc044a9ce63 | 704,780 |
def get_tag_name(tag):
"""
Extract the name portion of a tag URI.
Parameters
----------
tag : str
Returns
-------
str
"""
return tag[tag.rfind("/") + 1:tag.rfind("-")] | e24f0ae84ed096ec71f860291d1e476c75bf8370 | 704,781 |
def imap_any(conditions):
"""
Generate an IMAP query expression that will match any of the expressions in
`conditions`.
In IMAP, both operands used by the OR operator appear after the OR, and
chaining ORs can create very verbose, hard to parse queries e.g. "OR OR OR
X-GM-THRID 111 X-GM-THRID 22... | de4ef1680cd2c8370d82640ff95186ed3ea81202 | 704,783 |
def format_sources(sources):
"""
Make a comma separated string of news source labels.
"""
formatted_sources = ""
for source in sources:
formatted_sources += source["value"] + ','
return formatted_sources | f9f86f11e4dfe9ecd3fbbd5e14d3ca750a4e1a5a | 704,784 |
def launch_coef_scores(args):
"""
Wrapper to compute the standardized scores of the regression coefficients, used when computing the number of
features in the reduced parameter set.
@param args: Tuple containing the instance of SupervisedPCABase, feature matrix and response array.
@return: The stan... | 02423ef564b55dfcc37bddadcc813edffba05795 | 704,786 |
def create_link(url):
"""Create an html link for the given url"""
return (f'<a href = "{url}" target="_blank">{url}</a>') | 77a5375369be2be140a69a4521c50a92cee2d5ed | 704,787 |
def cummean(x):
"""Return a same-length array, containing the cumulative mean."""
return x.expanding().mean() | b5a35c56cb78e0588dd5be64a75384c4cd81ccb5 | 704,788 |
def get_syntax_errors(graph):
"""List the syntax errors encountered during compilation of a BEL script.
Uses SyntaxError as a stand-in for :exc:`pybel.parser.exc.BelSyntaxError`
:param pybel.BELGraph graph: A BEL graph
:return: A list of 4-tuples of line number, line text, exception, and annotations p... | a0f3493b88b081de3613397c997d71dabdae78be | 704,789 |
def is_valid_combination( row ):
"""
Should return True if combination is valid and False otherwise.
Test row that is passed here can be incomplete.
To prevent search for unnecessary items filtering function
is executed with found subset of data to validate it.
"""
n = len(row)
if ... | c0758c3d30debbd3fc3d5f07d6728c23bfb71145 | 704,790 |
def get_callback(request, spider):
"""Get request.callback of a scrapy.Request, as a callable."""
if request.callback is None:
return getattr(spider, 'parse')
return request.callback | a1f62822d812bebdeabafa14edda4462949657d8 | 704,793 |
def merge_values(list1, list2):
"""Merge two selection value lists and dedup.
All selection values should be simple value types.
"""
tmp = list1[:]
if not tmp:
return list2
else:
tmp.extend(list2)
return list(set(tmp)) | 9412dd28c6110bc6df70ac7d563cb19d1211beb8 | 704,798 |
def format_heading(level, text):
"""Create a heading of <level> [1, 2 or 3 supported]."""
underlining = ['=', '-', '~', ][level-1] * len(text)
return '%s\n%s\n\n' % (text, underlining) | 6b8caaa134ddc32666a4d7ce62a775d6ffda7425 | 704,800 |
def get_new_size_zoom(current_size, target_size):
"""
Returns size (width, height) to scale image so
smallest dimension fits target size.
"""
scale_w = target_size[0] / current_size[0]
scale_h = target_size[1] / current_size[1]
scale_by = max(scale_w, scale_h)
return (int(current_size[0]... | e0b42eab3d35ba5c662282cab1ffa798327ad92a | 704,801 |
def get_name_component(x509_name, component):
"""Gets single name component from X509 name."""
value = ""
for c in x509_name.get_components():
if c[0] == component:
value = c[1]
return value | 6a473a96b99daa6f69fd6aac45f2594af933d4bd | 704,802 |
def song_line(line):
"""Parse one line
Parameters
----------
line: str
One line in the musixmatch dataset
Returns
-------
dict
track_id: Million song dataset track id, track_id_musixmatch:
Musixmatch track id and bag_of_words: Bag of words dict in
{word: cou... | 2108dfa037aa6293a0b3111a97c354e62c0dd2a5 | 704,803 |
def remove_st_less_than(dataframe, column='ST', less_than=0.001):
"""
Remove any entry with an ST less than specified
Args:
dataframe (pandas.Dataframe): dataframe containing sensitivity analysis output
column (str): Column name, default is 'ST'
less_than (float): Remove anything le... | 2ba052004c436f8d527ab9b5bc3e76c90aa5dce9 | 704,804 |
def fact(n):
"""Return the factorial of the given number."""
r = 1
while n > 0:
r = r * n
n = n - 1
return r | 7bdcdc759b49a9cd72f7bf3f12a18fc03ce50668 | 704,806 |
def apply_functions(lst, functions):
"""
:param lst: list of values
:param functions: list of functions to apply to each value.
Each function has 2 inputs: index of value and value
:return: [func(x) for x in lst], i.e apply the respective function to each
of the values
"""
assert len(ls... | 679a2219008e438249e1227d5aab6529019c497c | 704,811 |
def dict_is_test(data):
"""helper function to check whether passed argument is a proper :class:`dict` object describing a test.
:param dict data: value to check
:rtype: bool
"""
return (
isinstance(data, dict)
and "type" in data
and data["type"] == "test"
and "id" in... | 320b47f8f41f42f6a6554741c9b2de38b370605a | 704,813 |
from typing import Set
def GetZonesInRegion(region: str) -> Set[str]:
"""Returns a set of zones in the region."""
# As of 2021 all Azure AZs are numbered 1-3 for eligible regions.
return set([f'{region}-{i}' for i in range(1, 4)]) | e539662604eb5da2583630844dd54d11d266c827 | 704,814 |
def compare_3PC_keys(key1, key2) -> int:
"""
Return >0 if key2 is greater than key1, <0 if lesser, 0 otherwise
"""
if key1[0] == key2[0]:
return key2[1] - key1[1]
else:
return key2[0] - key1[0] | d134eaaa4ef8f218164be4e5bc6fced01c3de7eb | 704,815 |
def _GetMSBuildToolSettings(msbuild_settings, tool):
"""Returns an MSBuild tool dictionary. Creates it if needed."""
return msbuild_settings.setdefault(tool.msbuild_name, {}) | 3a2cb3e9c8910a6901be0937be18aac00d532e2b | 704,816 |
def convert_to_date(col):
"""Convert datetime to date."""
return col.date() | c6ac8febf4751e8f2c2c27fc740de286f2870cbe | 704,820 |
from typing import Any
def isstring(var:Any, raise_error:bool=False) -> bool:
"""Check if var is a string
Args:
var (str): variable to check
raise_error (bool, optional): TypeError raised if set to `True`. Defaults to `False`.
Raises:
TypeError: raised if var is not string
R... | 897c43539099c3d0b9b38abccce88869a90b9d9e | 704,826 |
def get_index_from_filename(
file_name: str
) -> str:
"""
Returns the index of chart from a reproducible JSON filename.
:param file_name: `str`
The name of the file without parent path.
:returns: `str`
The index of the chart (e.g., 1) or an empty string.
"""
assembled_ind... | 2cddcbcd9bf5079d58c75f19b5d2bf5b44ded173 | 704,829 |
def sexastr2deci(sexa_str):
"""Converts as sexagesimal string to decimal
Converts a given sexagesimal string to its decimal value
Args:
A string encoding of a sexagesimal value, with the various
components separated by colons
Returns:
A decimal value corresponding to the sexagesimal... | 46a9d8752b05b1579ecc2b85d94c28613a08ab3c | 704,832 |
def reverb2mix_transcript_parse(path):
"""
Parse the file format of the MLF files that
contains the transcripts in the REVERB challenge
dataset
"""
utterances = {}
with open(path, "r") as f:
everything = f.read()
all_utt = everything.split("\n.\n")
for i, utt in enumerate... | c8a1aa0c8a4d0dec6626cf8e9d2491336ee42d5a | 704,833 |
def architecture_is_32bit(arch):
"""
Check if the architecture specified in *arch* is 32-bit.
:param str arch: The value to check.
:rtype: bool
"""
return bool(arch.lower() in ('i386', 'i686', 'x86')) | a0cfaef4b03bc8cf335f0d19a3e46457db7574a9 | 704,838 |
def mpls_label_group_id(sub_type, label):
"""
MPLS Label Group Id
sub_type:
- 1: L2 VPN Label
- 2: L3 VPN Label
- 3: Tunnel Label 1
- 4: Tunnel Label 2
- 5: Swap Label
"""
return 0x90000000 + ((sub_type << 24) & 0x0f000000) + (label & 0x00ffffff) | f0235d1cd8baaf601baf0db43b81417d3d5823ac | 704,845 |
import torch
def get_spin_interp(zeta: torch.Tensor) -> torch.Tensor:
"""Compute spin interpolation function from fractional polarization `zeta`."""
exponent = 4.0 / 3
scale = 1.0 / (2.0 ** exponent - 2.0)
return ((1.0 + zeta) ** exponent + (1.0 - zeta) ** exponent - 2.0) * scale | b1abced09aead7394be773d93d59a621cda98d14 | 704,847 |
def string2token(t,nl,nt):
"""
This function takes a string and returns a token. A token is a tuple
where the first element specifies the type of the data stored in the
second element.
In this case the data types are limited to numbers, either integer, real
or complex, and strings. The types... | 23fd5da01a49076b1fcf474fbe1047329ad7471a | 704,852 |
def get_div(integer):
"""
Return list of divisors of integer.
:param integer: int
:return: list
"""
divisors = [num for num in range(2, int(integer**0.5)+1) if integer % num == 0]
rem_divisors = [int(integer/num) for num in divisors]
divisors += rem_divisors
divisors.append(integer)
... | 4c40a2b2da1d9681c1d7ca69a53975dd27c7bdb8 | 704,853 |
from typing import get_origin
def is_dict_type(tp):
"""Return True if tp is a Dict"""
return (
get_origin(tp) is dict
and getattr(tp, '_name', None) == 'Dict'
) | 3b9992b7b131e936472d4d0e2994ac476f0d0f76 | 704,855 |
def sum_up_validation_dataset(dataset, batch_size, repeat=True,
number_of_repetitions=0):
"""Define how the validation dataset is suppose to behave during training.
This function is applied to the validation dataset just before the actual
training process. The characteristics... | 9bab85eba802d5198bfd39bc42bd2fae5209d356 | 704,856 |
def cleanup_code(content: str):
"""Automatically removes code blocks from the code."""
# remove ```py\n```
if content.startswith('```') and content.endswith('```'):
return '\n'.join(content.split('\n')[1:-1])
# remove `foo`
return content.strip('` \n') | a026668f01e1641618c5b25b06396516410dbe1e | 704,859 |
import operator
def lcs(l1, l2, eq=operator.eq):
"""Finds the longest common subsequence of l1 and l2.
Returns a list of common parts and a list of differences.
>>> lcs([1, 2, 3], [2])
([2], [1, 3])
>>> lcs([1, 2, 3, 3, 4], [2, 3, 4, 5])
([2, 3, 4], [1, 3, 5])
>>> lcs('banana', 'baraban')... | 4b5d3cb9911a6834c006e78f7b40061695c464e2 | 704,863 |
def calc_sparsity(optimizer, total_params, total_quant_params):
"""
Returns the sparsity of the overall network and the sparsity of quantized layers only.
Parameters:
-----------
optimizer:
An optimizer containing quantized model layers in param_groups[1]['params'] and non-quantized... | 92ee924239ee8d7ac97aebba2958671043aa2d89 | 704,864 |
def dict_get(d, key, default=None):
""":yaql:get
Returns value of a dictionary by given key or default if there is
no such key.
:signature: dict.get(key, default => null)
:receiverArg dict: input dictionary
:argType dict: dictionary
:arg key: key
:argType key: keyword
:arg default:... | 5fb6a71e507f62eb530215385c97c56a75765df7 | 704,872 |
import pytz
def as_utc(time):
"""Convert a time to a UTC time."""
return time.astimezone(pytz.utc) | 716858e88daa43b61f5cedae72e74dafcf67d423 | 704,878 |
def insertion_sort(L):
"""Implementation of insertion sort."""
n = len(L)
if n < 2:
return L
for i in range(1, n):
tmp = L[i]
j = i
while j > 0 and tmp < L[j - 1]:
L[j] = L[j - 1]
j -= 1
L[j] = tmp | ca7cbb5c676173ad10ce98d8b9e579a65afad0fb | 704,882 |
def get_img_space(wsp, img):
"""
Find out what image space an image is in
Note that this only compares the voxel->world transformation matrix to the
reference image for each space. It is quite possible for two images to be in
the same space but not be registered to one another. In this case,
... | b455dd6300cf13cbba5d8e2d44685e06d8fb4cad | 704,887 |
def _not_exhausted(last_fetched):
"""Check if the last fetched tasks were the last available."""
return len(last_fetched) == 100 | 570cf94ba9c723cced8ec3a746f2ce070d780fd5 | 704,891 |
def has_oxidation_states(comp):
"""Check if a composition object has oxidation states for each element
Args:
comp (Composition): Composition to check
Returns:
(boolean) Whether this composition object contains oxidation states
"""
for el in comp.elements:
if not hasattr(el, ... | 702595070b588761142055bc1532ce26acd287fb | 704,895 |
from typing import Optional
def parse_opt_int(s: Optional[str]) -> Optional[int]:
"""
parse_opt_int(s: Optional[str]) -> Optional[int]
If s is a string, parse it for an integer value (raising a ValueError if
it cannot be parsed correctly.)
If s is None, return None.
Otherwise, raise a TypeErro... | 91a102c8c8e6a6ee109e9c88c56d9a6959f1f838 | 704,897 |
def setup(hass, config):
"""Mock a successful setup."""
return True | fd2977534aa8a165b49c4fbddc513c8f77b0588d | 704,898 |
def get_attachment_file_upload_to(instance, filename):
""" Returns a valid upload path for the file of an attachment. """
return instance.get_file_upload_to(filename) | e38c51a2ca947bebe1ed274c4265081c6b9e7c41 | 704,902 |
def read_to_ulens_in_intvls(read, intvls):
"""Extract units within `intvls` from `read.units`."""
return [unit.length for unit in read.units
if unit.length in intvls] | 11159bea8bbf0cb68f0e9a7355c82e93b430065d | 704,909 |
def find_merge_commit_in_prs(needle, prs):
"""Find the merge commit `needle` in the list of `prs`
If found, returns the pr the merge commit comes from. If not found, return
None
"""
for pr in prs[::-1]:
if pr['merge_commit'] is not None:
if pr['merge_commit']['hash'] == needle[1... | 42320473aff84985e35cdf9024a64a18fe6f14f1 | 704,913 |
def update_board(position, board, player):
"""
Update the board with the user input position if position not taken
returns board, True=position taken or False=position not taken and board updated
args: position (int 1-9, user input)
board (np.array 2d)
player ("X" or "O")
"""
... | eb53d24c4976499e6611c97757d0c33b4cb3254f | 704,918 |
def marks(category, mark=None, category_marks=None, public=False):
"""Assign marks to a test or suite of tests, grouped by a category."""
def decorator(test_item):
if mark is None and category_marks is None:
raise ValueError("One of mark or category_marks must be defined")
test_item... | 2d47a8df4f610dbc081dd57fce169e2f89b88ca4 | 704,922 |
def underscore_to_camelcase(value):
"""
Converts underscore notation (something_named_this) to camelcase notation (somethingNamedThis)
>>> underscore_to_camelcase('country_code')
'countryCode'
>>> underscore_to_camelcase('country')
'country'
>>> underscore_to_camelcase('price_GBP')
'pri... | 94bb5c007d3b50112c62ca9b3e97c5bf4f155fff | 704,925 |
def findCenter(S):
"""Find the approximate center atom of a structure.
The center of the structure is the atom closest to (0.5, 0.5, 0.5)
Returns the index of the atom.
"""
best = -1
bestd = len(S)
center = [0.5, 0.5, 0.5] # the cannonical center
for i in range(len(S)):
d = S.... | 634945a5560b3791f3835f3da090decd1b06b933 | 704,926 |
from datetime import datetime
def _make_todays_date() -> str:
""" build today's date as a standard format """
return datetime.now().strftime("%a %d-%b") | fdb9bc420689081586ac19fe91a17ea871576d59 | 704,930 |
def get_keywords(string):
"""Get keywords for a given string.
Args:
string (str): A string to get keywords for.
Returns:
(list): A list of keywords.
"""
keywords = string.lower().split(' ')
keywords = [x.strip() for x in keywords if x]
keywords = list(set(keywords))
retur... | 8d4e0781701dc3574583baf417c573967638e86f | 704,934 |
def distancia(ponto1, ponto2):
"""
Calcula a distância entre dois pontos
"""
xdif = ponto2.getx() - ponto1.getx()
ydif = ponto2.gety() - ponto1.gety()
dif = (xdif**2 + ydif**2)**0.5
return dif | 36a980a1081133fb6496585c25cca5782ceef06d | 704,935 |
def prep_tweet_body(tweet_obj, args, processed_text):
""" Format the incoming tweet
Args:
tweet_obj (dict): Tweet to preprocess.
args (list): Various datafields to append to the object.
0: subj_sent_check (bool): Check for subjectivity and sentiment.
1: subjectivity (num... | 9163d7bb10e3bb31849090d8ebfe4d00c19db2df | 704,939 |
import time
def timedcall(fn, *args):
"""
Run a function and measure execution time.
Arguments:
fn : function to be executed
args : arguments to function fn
Return:
dt : execution time
result : result of function
Usage example:
You want to time the function call "C = foo(A... | 60779c4f4b63796995d722133c304edf519ecd8f | 704,940 |
def tokuda_gap(i):
"""Returns the i^th Tokuda gap for Shellsort (starting with i=0).
The first 20 terms of the sequence are:
[1, 4, 9, 20, 46, 103, 233, 525, 1182, 2660, 5985, 13467, 30301, 68178, 153401, 345152, 776591, 1747331, 3931496, 8845866, ...]
h_i = ceil( (9*(9/4)**i-4)/5 ) for i>=0.
If ... | 710633e924cb6e31a866683b91da6489c781ba4a | 704,941 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.