content stringlengths 39 9.28k | sha1 stringlengths 40 40 | id int64 8 710k |
|---|---|---|
def cpc(total_cost, total_clicks):
"""Return the CPC (Cost per Click).
Args:
total_cost (float): Total cost of marketing.
total_clicks (int): Total number of clicks.
Returns:
cpt (float) as total cost per click
"""
return total_cost / total_clicks | 3d4ec2d15ac5653cefdb40ba51ad06a93e68462f | 249,223 |
def valid_follow_type(follow_type: str):
"""Ensure follow type is valid steemd type."""
# ABW: should be extended with blacklists etc. (and those should be implemented as next 'state' values)
supported_follow_types = dict(blog=1, ignore=2)
assert follow_type in supported_follow_types, "Unsupported follo... | 9d4cc977e91b1e4357c3f4f848b95855e75a1420 | 134,455 |
from typing import List
from typing import Dict
import itertools
def merge_memory_map_lists(
mml1: List[Dict[str, List[float]]], mml2: List[Dict[str, List[float]]]
) -> List[Dict[str, List[float]]]:
"""
Given two lists of memory maps, produce the "cartesian product" of the memory maps:
merge_memo... | e9ea93810bcc13ade3a064816bdb7ad34398f0b2 | 346,810 |
def make_adder_inc(n):
"""
>>> adder1 = make_adder_inc(5)
>>> adder2 = make_adder_inc(6)
>>> adder1(2)
7
>>> adder1(2) # 5 + 2 + 1
8
>>> adder1(10) # 5 + 10 + 2
17
>>> [adder1(x) for x in [1, 2, 3]]
[9, 11, 13]
>>> adder2(5)
11
"""
count = 0
def real_adde... | 58f9bd2e6f947b94454b8673cf73b3007584f583 | 495,093 |
def compute_wiener_filter(speech_psd, noise_psd):
"""
Compute Wiener filter in the frequency domain.
Parameters
----------
speech_psd : numpy array
Speech power spectral density.
noise_psd : float or numpy array
Noise variance if white noise, numpy array otherwise.
Returns
... | 2aa59a0f2b4d93fc22c20c4e29e0e79f35411191 | 609,297 |
def decode_rate_depth(x: int):
"""return rate and depth from encoded representation"""
rate = x >> 8
depth = x & 0xff
return rate, depth | 2c5b59041a2867e2e5c5153696decb328d70bb80 | 209,836 |
def count_inversions(array, blank):
"""Returns the number of inversions in a list ignoring the blank value."""
count = 0
for i, tile1 in enumerate(array[:-1]):
if tile1 is not blank:
for tile2 in array[i + 1 :]:
if tile2 is not blank:
if tile1 > tile2:... | 7f70df885e39f10ad70343c302756e25f1573305 | 84,426 |
def _get_castep_output_file(calculation):
"""Return a list of the lines in the retrieved dot castep file"""
fname = calculation.get_option('output_filename')
fcontent = calculation.outputs.retrieved.get_object_content(fname)
return fcontent.split('\n') | 0dc78bed80dc753192d1317f3373c0a4eb5e09c2 | 538,493 |
def get_pil_mode(value, alpha=False):
"""Get PIL mode from ColorMode."""
name = {
'GRAYSCALE': 'L',
'BITMAP': '1',
'DUOTONE': 'L',
'INDEXED': 'P',
}.get(value, value)
if alpha and name in ('L', 'RGB'):
name += 'A'
return name | 4f66500fe15cb3e4bd865677225b428dfc2ed470 | 497,404 |
import inspect
def classify_class_attrs(object):
"""Wrap inspect.classify_class_attrs, with fixup for data descriptors."""
results = []
for (name, kind, cls, value) in inspect.classify_class_attrs(object):
if inspect.isdatadescriptor(value):
kind = 'data descriptor'
results.app... | 0d13cd5026e770a4a79c3cbf06b403f0db08e8a9 | 392,978 |
from datetime import datetime
def check(str1, str2, format_str):
"""Check if two strings are equal (based on format), or both are redacted."""
try:
str1_conv = datetime.strptime(str1, format_str)
str2_conv = datetime.strptime(str2, format_str)
if str1_conv == str2_conv:
ret... | 0f03443136ebe1d55d360147dcf25aa40dffb167 | 691,935 |
import re
def _clean_expression(expression: str) -> str:
"""Clean the given expression.
:param expression: The expression to clean.
:return: The cleaned expression."""
expression = re.sub(r'[<>@]', '', expression)
expression = re.sub(r'&(\d+)', r'\1', expression)
return expression | 3d0402cb9328ab06ec3473e36efa561614499254 | 492,245 |
from typing import List
def get_starttime_default(features: List[str]) -> int:
"""
Heuristic for selecting a sound attribute as default for start time
:param features: list of available features
:return: index of the suggested feature in the list
"""
for idx, f in enumerate(features):
... | 4089ddfb7265659e64599c2d75ea084fbe34f0eb | 491,970 |
def calculate_position_part2(infile_path: str) -> int:
"""
Read input, determine vertical and horizontal position and return the product of the values
:param infile_path: file path to input file with instructions separated by newlines
:type infile_path: str
:return: product of the vertical and horiz... | 3dfe30a9b4e2971385f610417d2e9cefa34fc1d8 | 656,130 |
def get_comparative_word_freq(freqs):
"""
Returns a dictionary of the frequency of words counted relative to each other.
If frequency passed in is zero, returns zero
:param freqs: dictionary
:return: dictionary
>>> from gender_novels import novel
>>> novel_metadata = {'author': 'Hawthorne,... | 5d59d25a15119a8e5f934804f1b8ee4ab5ecdbc4 | 680,615 |
def xgcd(a, b):
"""
Performs the Extended Euclidean algorithm to return the result of Bézout's
identity.
Arguments:
a (:int) - the first integer
b (:int) - the second integer
Returns:
'r' such that ar + bs = d where d = gcd(a, b)
"""
r, s = 0, 1
while b != 0:
c, d = divmod(a, b)
r, s = s, r - c*s
... | 8a1cdf00e11a7af259476b5e9884a70fc2e4c04c | 480,092 |
import six
def ported_string(raw_data, encoding='utf-8', errors='ignore'):
"""
Give as input raw data and output a str in Python 3
and unicode in Python 2.
Args:
raw_data: Python 2 str, Python 3 bytes or str to porting
encoding: string giving the name of an encoding
errors: hi... | 70afe0d3f0363959ba0b37f339e581403fb63798 | 456,749 |
def generic_struct(name):
"""
Wraps a C struct in an empty ctypes class.
:param name: the struct name
:return: string
"""
text = (
'class {name}(ctypes.Structure):\n'
' """Wrapper for the {name} C struct."""\n'
'\n'
' pass\n\n\n'
)
return text.for... | 26c9cbf4f2ede3d18ae9ac52f95115d2149c1674 | 415,374 |
def render_literal(obj):
"""
Render obj as a literal expression in C.
"""
if isinstance(obj, str):
return '"%s"' % obj
else:
return repr(obj) | f3c3fd0b8325345ae8d421b3b8da9635f58fb876 | 349,735 |
def str2ds(strings):
"""
Convert numbers to strings conforming to dicom rules,
maximum 16 characters.
:param strings:
:return: formatted string representation.
"""
# Decimal string encoding, maximum 16 characters
h = ['{:+16.8e}'.format(x) for x in strings]
return h | 7e7973044ce45f9684a3640f9d2a228d3801d9cc | 516,953 |
import random
def shuffled(li):
"""Return a shuffled version of the list."""
copy = li[:]
random.shuffle(copy)
return copy | af04eaa4acd07b34b99809455aa8ff1ce514178b | 397,057 |
def nbt_path_join(*args):
"""Join two NBT paths into a longer path, similar to os.path.join()."""
if len(args) == 0:
return '{}'
if len(args) == 1:
return args[0]
if args[-1] == '':
return nbt_path_join(*args[:-1])
if args[1].startswith('['):
return nbt_path_join(f'{a... | 9f6e5ea5cfe28949a2f8d8f36dbe79a655caad84 | 402,037 |
def get_binary_indexes(coordinates):
"""Generate binary coordinates."""
bin_coordinates = []
for coord in coordinates:
coord = ("{:08b}".format(coord[0]),
"{:08b}".format(coord[1]),
"{:08b}".format(coord[2]),)
bin_coordinates.append(coord)
return bin_coo... | 2731cfbed13556faba21e47b8567c47569324e31 | 448,990 |
def is_staff_user(request):
"""
Args:
request (HTTPRequest): django request object
Returns:
bool: True if user is staff
"""
return request.user is not None and request.user.is_staff | d1f18ac5ef61b611128d9c7842c61a41004a72c6 | 371,051 |
def normal_percentile_to_label(percentile):
"""
Assigns a descriptive term to the MMSE percentile score.
"""
if percentile >= 98:
return 'Exceptionally High'
elif 91 <= percentile <= 97:
return 'Above Average'
elif 75 <= percentile <= 90:
return 'High Average'
elif 25... | 7c2e92ee51b00308f10f14e89869cb339ee551b1 | 109,871 |
import json
def build_message(status, message=None, state=None):
"""
Build message string to send to connected clients.
:param status: HTTP status code of the message, int
:param message: Optional free-form message to display to the client, can be string or dictionary.
Either this or state sh... | 82998943feefb8ceeadf0c03e80a49ba0a67cc0e | 492,329 |
from typing import Dict
import json
def read_json(path: str) -> Dict[str, object]:
"""
Reads json from file path
:return: Dict[str, object]
"""
with open(path) as json_file:
return json.load(json_file) | 345083155ef9aa42157a36feebf768d8cb52a00b | 613,292 |
def get_dns_classification(self) -> list:
"""Get application definition for DNS from Cloud Portal. This
generates a lot of data and require longer response time.
.. list-table::
:header-rows: 1
* - Swagger Section
- Method
- Endpoint
* - spPortal
- GET... | 7261ab56274e52e35cdb96921d9e6e160f86a1a9 | 598,282 |
def int_to_binary(integer):
"""Convert an integer to a 36-bit binary representation."""
return f'{integer:036b}' | 95b0f77dc3ecb59cd7c2a85d8aacacb80575ae6f | 223,572 |
def _makeBool(value, default=True):
""" Helper to make boolean out of a .ini value """
if default is True:
if (value or '').lower() in ('off', 'false', '0'):
return False
else:
if (value or '').lower() in ('on', 'true', '1'):
return True
return default | c79095a8636ed3c6e36e914ce5131a1389cd91d3 | 588,108 |
def generate_query_string(query_params):
"""Generate a query string given kwargs dictionary."""
query_frags = [
str(key) + "=" + str(value) for key, value in query_params.items()
]
query_str = "&".join(query_frags)
return query_str | ca656c1d3c43a069b1eb9b4f4d98ba94c7c98256 | 164,095 |
def is_upper_bound(y):
"""
Was right bound reached?
:param y: y coordinate.
:return: True - bound was reached, False - otherwise.
"""
return y <= 0 | d784c6da3c9c760158f0c582a9945ea450b06119 | 523,885 |
def es_primo(n: int) -> bool:
"""Determina si un número es primo.
:param n: número a evaluar.
:n type: int
:return: True si es primo, False en caso contrario.
:rtype: bool
"""
if n == 2 or n == 3:
return True
if n % 2 == 0 or n < 2:
return False
for i in range(3, int... | fff4802d6e47c379b6510f13e2ffe9a9d56429d2 | 698,494 |
from pathlib import Path
def count_standard_seeds(seeds_dir):
"""Count the number of seeds for a standard benchmark."""
return len([p for p in Path(seeds_dir).glob('**/*') if p.is_file()]) | 9e704fa63cee25069ad0f880d67151f6bb12761f | 136,709 |
def build_model_identifier(model_id, model_version):
"""Generate the long identifier for a model given its ID and version. Used for
naming conda environments, storage directories, and similar.
Parameters
----------
model_id : int
ID of the model
model_version : str
Version of th... | a73ef44df3c37e9ad51311dc3de040a575e1f304 | 443,962 |
def maxOfArray(A):
"""Durchlaufe die Elemente der Menge und merke das jeweils größte Element.
Args:
A (list): Menge A
Returns:
tuple: max. von A und Index i, sodass 0 <= i <= len(A) und A[i]==max
oder 0,-1 falls A leer ist.
"""
# abbruch, da leeres array.
if len(A) ... | 9121308b63190af7e46f33101e25e8bfcec7ac05 | 341,489 |
def make_filename_from_version(handle, version):
"""Make a filename with the handle and version."""
return f"{handle}-v{version}.toml" | c548e2a7c651dd25ccdf4880033932798ba3df01 | 205,238 |
def mix_targets(preds, targets, target_name1, target_name2, weight1=0.5,
weight2=0.5, skip_missing=False, new_name=None):
"""
Linearly combines two targets into one, optionally with custom weights,
storing it under the name of the first one, unless `new_name` is given.
`weight1` and `wei... | 048341c365cc7166027e3aa46f805c14d233c227 | 665,966 |
def reg_read(spi, cs, reg, nbytes=1):
"""
Read byte(s) from specified register. If nbytes > 1, read from consecutive
registers.
"""
# Determine if multiple byte (MB) bit should be set
if nbytes < 1:
return bytearray()
elif nbytes == 1:
mb = 0
else:
mb = 1
... | 2e84f78f4e0416b0a677d57d1caa8c32fb21a2fa | 453,340 |
def check_individuals(ped_individuals, vcf_individuals):
"""
Check if the individuals from ped file is in vcf file
Arguments:
ped_individuals (iterator): An iterator with strings
vcf_individuals (iterator): An iterator with strings
Returns:
bool: if the individuals exis... | e65b24390c8cebff7870e46790cf1c0e9b2d37c6 | 12,026 |
def lag(array, n=1):
"""
>>> x = [19, 100, 36, 6, 100, 20, 75, 66, 98, 55]
>>> lag(x)
[100, 36, 6, 100, 20, 75, 66, 98, 55]
>>> lag(x, 2)
[36, 6, 100, 20, 75, 66, 98, 55]
"""
return array[n:] | 6fea13e3f0d9b91c35683675c9f42ffea07e9563 | 526,566 |
def token_links_factory(token):
"""Links factory for token views."""
rec = token.get_record()
links = dict(
# token_detail=url_for('oarepo_tokens.token_detail', token_id=token.id, _external=True),
)
if rec is not None:
links['record'] = rec.canonical_url
links['files'] = f"{r... | da85cdc237c3fa3665d304e2df982c5baac70005 | 463,361 |
def type(record):
"""
Put the type into lower case.
:param record: the record.
:type record: dict
:returns: dict -- the modified record.
"""
if "type" in record:
record["type"] = record["type"].lower()
return record | c014281e533752cc2d719166c3df8194bc906be9 | 474,403 |
def wrap_hashlib(hasher, length=None):
"""
Wraps hashlib's functions, returning a function that returns the hex-digest of its input.
>>> from hashlib import sha1
>>> wrap_hashlib(sha1)(b'heyo')
'f8bb1031d6d82b30817a872b8a2ec31d5380cee5'
:param hasher: A function from :mod:`hashlib`
:return... | dbd07d4151a5c5c523fe75c3f29b72abfd15c3b8 | 702,274 |
def backcomp(arglist):
"""Modify arglist for backwards compatibility"""
for i in range(len(arglist)):
if arglist[i] == "attr":
arglist[i] = "write-attr"
elif arglist[i] == "--known-endpoints":
arglist[i] = "--ep-known"
try:
arglist.remove("--echo")
except ... | 9d3f451b1bb5449df8dce672c45d051e378f5050 | 566,278 |
def wants_plain_hotdog(ketchup, mustard, onion):
"""Return whether the customer wants a plain hot dog with no toppings.
"""
return not ketchup and not mustard and not onion | 78f7308cd63f7133e1f96202164246e0d0cd9a8a | 84,758 |
def sort_by_relevance(repo_list):
"""
Build display order.
As of 2020-01-14 it sorts by number of forks and stars combined
:param repo_list: repolist to sort
:return: sorted repolist
"""
repo_list.sort(key=lambda repo: repo['repo_forks'] + repo['repo_stars'], reverse=True)
return repo_l... | e18708489c87c097e5c22f4f5b67a133b915fba5 | 556,003 |
import math
def round_index(index: float) -> int:
"""Округляет значение к ближайшему целому.
Основное применение функции - однозначно определять конечное значение индекса.
Отличие от стандартной функции round() в том, что округление чисел с дробной
частью = 0.5 всегда идет в большую сторону.
Exa... | 97f830dba481774e894f73b3ce0c99a62e2ae843 | 177,008 |
def transpose(x, y, _):
"""Transpose rows and columns."""
return y, x | 46f2b58e6f15c7b337a9b6d714ff4c7cd1ba5ea3 | 98,220 |
def is_yaml_view(view):
""" Returns true if given view contains YAML code. """
return view.score_selector(0, "source.yaml") > 0 | fe3177e95baa341103241e20bea32fb2d90e03f4 | 413,161 |
def gini(dist):
"""Returns the Gini impurity of a counter.
If used by a decision tree learning algorithm, the goal is to minimize the Gini impurity inside
each leaf.
Parameters:
dist (proba.Multinomial)
Example:
>>> from creme import proba
>>> from scipy import stats
... | dd02700ef533c72ec2352f2926857bc39f5f3d48 | 518,310 |
def _add(shape, solution):
"""
Adds all points of the shape to the solution if they are not already
contained.
Returns True if all points could be added or False otherwise
"""
if any([ point in solution for point in shape ]):
return False
for point in shape:
solution.append... | 2795cfb2b8c167294e9dc4c1104fe6887fa472d4 | 116,419 |
def monthly_N_fixation_point(
precip, annual_precip, baseNdep, epnfs_2, prev_minerl_1_1):
"""Add monthly N fixation to surface mineral N pool.
Monthly N fixation is calculated from annual N deposition according to
the ratio of monthly precipitation to annual precipitation.
Parameters:
... | 51d2de4c024fbd0b41a6f75b66090aef18067dbe | 475,171 |
def _make_argo_task(name, dependencies):
"""Generate an Argo Task spec
"""
task = {
'name': name,
'dependencies': dependencies,
'template': 'run-task',
'arguments': {
'parameters': [{
'name': 'task_name',
'value': name,
... | f2dbfdec4d409dddbaab1bb80082a49ee004c40f | 498,968 |
def _detect_format_from_extension(filename):
"""
Attempts to detect file format from the filename extension.
Returns None if no format could be detected.
"""
if filename.endswith('.bz2'):
return "bz2"
elif filename.endswith('.xz'):
return "xz"
elif filename.endswith('.gz'):
... | 45875b4b594f38619cdd4179ad2dd28c278e875f | 301,022 |
def rotr(v, count, bits):
""" Rotate v right count bits """
mask = (1 << bits) - 1
count = count % bits
return ((v >> count) | ((v << (bits - count)) & mask)) | cc3dd1b7ec0060a8d1b8e6b4c162ad0629f12116 | 426,507 |
def _genfmt(size, endian, sign):
"""
Generates a format string that can be used with struct.pack()
and struct.unpack().
"""
if sign not in [True, False]:
raise ValueError('sign must be either True or False')
if endian == 'little':
fmt = '<'
elif endian == 'big':
fmt ... | 4bd61554bb24930fd44e3e8a2f00e5aacdbe8bed | 203,738 |
def label_breakdown(data):
""" Find the label breakdown in data. """
res = {}
for row in data:
# if valid label
if (row[3]):
res[row[1]] = row[7]
neg, neu, pos = 0, 0, 0
for key in res.keys():
r = res[key]
if (r == -1):
neg += 1
... | 07aa33f36da83eb2b21d211ffe1979fb2b5c3491 | 145,940 |
def MergeComponents(components):
"""Given a list of components, merges components with the same hierarchy.
For components with same hierarchy, return the most fine-grained component.
For example, if components are ['Blink', 'Blink>Editing'], we should only
return ['Blink>Editing'].
"""
if not components or... | 189308f4ddda3489234936286da22e4260449a10 | 579,519 |
def parse_byte_ranges(s):
"""Parses strings like "1,3-5" into set(1,3,4,5)."""
result = set()
for term in s.split(","):
parts = [int(p) for p in term.split("-")]
if len(parts) == 1:
hi = parts[0]
lo = parts[0]
elif len(parts) == 2:
lo, hi = min(par... | a3a75c11e52f7c439ed3ca073e8c72dc30a0d58a | 544,161 |
def swap_keys_values(_dict: dict):
"""Swaps the Keys and Values in Dictionary.
Parameters
----------
_dict : dict
The dictionary that needs to be reversed.
Returns
-------
swapped_dict : dict
Returns the Swapped/Reversed Dictionary.
"""
swapped_dict = {value: key fo... | ff92e6eff371aca31ef8549c2293530303c99d75 | 372,777 |
from typing import List
def rindex(lst: List, value: str) -> int:
"""
Return the index of the last occurence of a value in a list.
:param lst: The list to search in.
:param value: The value to search for.
:return: The index of the last occurence of the value.
"""
try:
return len(l... | 0bbe8a1aa2c8786b18a5c1cb97155e25ec36fa07 | 226,888 |
import networkx as nx
def mol_to_nx(mol):
"""Converts RDKit mol to NetworkX graph object.
Parameters
----------
mol : RDKit mol
RDKit molecule.
Returns
-------
G : Networkx Graph.
Graph object.
References
----------
`keras-molecules <https://github.com/dakoner/keras-molecules/blob/dbbb790e74e406faa70... | a1ddb82bdd3cc80ea61a377ec3f86397074d113e | 538,647 |
def tag_kinds(atoms):
"""Tag different atom kinds, depending on oxidation state, magnetization, etc.
E.g. if there are 4 different types of 'Fe', tag them with 1,2,3 and 4.
"""
# Prepare dictionary [symbol][magnetization] => tag (tag is 0, if only single oxidation state)
symbols = set(atoms.get_ch... | fad4304b1789dc63972d6c5e9a6a5ac1ad5c1666 | 377,770 |
import importlib
def get_module(module_name):
"""Attempts to find a bot module by name. This function looks for a
Python module named `module_name` located in `botnet.modules`. If the name
is prefixed with `botnet_` this function will look for an external module
instead.
"""
if not module_name... | 3f277799bedf479ffe89c4a65ccba5b05b23b78c | 449,695 |
def rgba_to_int(r: int, g: int, b: int, a: int) -> int:
"""Use int.from_bytes to convert a color tuple.
>>> print(rgba_to_int(0, 0, 0, 0))
0
>>> print(rgba_to_int(0, 1, 135, 4))
100100
"""
return int.from_bytes([r, g, b, a], byteorder="big", signed=True) | 8ad6eb4aefe06ba5d2c60ee1c32f8a8f390adee9 | 405,805 |
def ipopo_state_to_str(state):
"""
Converts the state of a component instance to its string representation
:param state: The state of an iPOPO component
:return: A string representation of the state
"""
ipopo_states = {
0: "INVALID",
1: "VALID",
2: "KILLED",
3: "... | 9d53fe004176a7d541694a83721293106fc83cd3 | 473,947 |
def separateUnit(string):
"""
Separates the unit and number in given string
e.g. '1 em' will return (float(1), 'em')
"""
# create an array of valid numbers (and '.')
nums = ['.'] + [str(x) for x in range(10)]
num_str = str()
unit_str = str()
# find first char in string that i... | ceab4bfc607c70714a5bc0459747a087eefec344 | 621,509 |
def get_imag(input, input_type="linear", channels_axis=1):
"""Returns the imaginary components of the complex-valued input.
Arguments
---------
input : torch.Tensor
Input tensor.
input_type : str,
(convolution, linear) (default "linear")
channels_axis : int.
Default 1.
... | 168f2a89dd76cd0bfaa41eae1f8b4138832ecffc | 620,322 |
def add_vars(var_seq_1, var_seq_2):
"""
Add two variable sequences.
"""
return [v1 + v2 for v1, v2 in zip(var_seq_1, var_seq_2)] | 31118b9947441ebec8afebcca502992c27a8589f | 295,443 |
def consume_next_text(text_file):
"""Consumes the next text line from `text_file`."""
idx = None
text = text_file.readline()
if text:
tokens = text.strip().split()
idx = tokens[0]
tokens.pop(0)
text = " ".join(tokens)
return idx, text | 9a0595580a9fa8d6b5f480d218e88c508e5cd197 | 681,983 |
def fix_range(a, nmin, nmax):
"""
Given an array of values `a', scale the values within in to the range
specified by `nmin' and `nmax'.
Parameters
----------
a : ndarray
Array of values to scale.
nmin, nmax : float
New minimum and maximum values for the new range.
Retur... | 58e35fba4df24ac1d00614ebb179a2ce3f618602 | 343,015 |
import time
def _learn(ulearn, adaptive_learning_rate, increase_rate, decrease_rate, left_out, printer):
"""
Perform the learning process on ulearn with the given parameters.
Prints the preparation and learning time of the process using the printer.
:param ulearn: The learning object
:type ulearn... | 90ed5c69c3009356cfbb95a7dd1371f66613aefa | 129,957 |
import itertools
def partition(seq, key):
"""Group a sequence based into buckets by key(x)."""
groups = itertools.groupby(sorted(seq, key=key), key=key)
return ((k, list(v)) for k, v in groups) | 89c97578444a2d99f88e1945f6819f84cdc1a7f6 | 203,175 |
import pathlib
import base64
def read_image(filepath: pathlib.Path) -> str:
"""
Read an image from a file.
Args:
filepath: Input image file path
Returns:
Image encoded in Base64
"""
with open(filepath, "rb") as f:
image_base64: str = base64.b64encode(f.read()).decode(... | 4219c092188acd6953e9043bdb083f165af742fe | 613,839 |
def insert_whitespace(seq: str) -> str:
"""
Return the sequence of characters with whitespace after each char
>>> insert_whitespace("RKDES")
'R K D E S'
"""
return " ".join(list(seq)) | f30c62bd3e88821f74a53cbf80b69c729026c21a | 553,786 |
def get_airtime(row):
""" extract the airtime (seconds) """
airtime = float(row['airtime'])
return 0.0 if airtime < 0.0 else airtime | afc01eb20a1305ff7baa72e29bbacb478b0d700a | 193,088 |
def get_description_paragraph(soup):
"""Return the description paragraph from a class soup."""
return soup.find("p", id="VAR3").text | 71d7af1f5932aa3bc936fb39c93eb4ca6258ad6d | 374,474 |
def load_file(file: str) -> list:
"""
Loads a list of frequency changes and returns a list of integers
:param file: Name of file containing list of integers
:return: Python list of integers in the file
"""
with open(file) as f:
frequency_string = f.read().split()
frequency_list = [i... | 79c966e30f7caf801e337c79d2b7b896cf747902 | 297,672 |
def isAscii(b):
"""
Check if a given hex byte is ascii or not
Argument : the byte
Returns : Boolean
"""
return b == 0x0a or b == 0x0d or (b >= 0x20 and b <= 0x7e) | 7b6b84bd0ca36582b98de0dc2c4ebd1c31144f3b | 92,847 |
def select_query(x, read_seq, read_qual):
"""Selects query.
If multiple matches are found, select the one with the smallest levenshtein
distance. If multiple matches having the same smallest levenshtein
distance, select the one with lowest sequencing quality sum at the
mismatched nucleotides. If th... | cbc9eaf92d9cc532cdb13824215aa698bbd6b6fe | 404,530 |
def dimensions_match(matrix1, matrix2):
"""
This function checks if the orders of the given matrices match.
Arguments: matrix1 {Matrix} - The first Matrix object matrix2 {Matrix} - The
second Matrix object
Returns: boolean-- True or False depending on if their orders match or not.
"""
... | a7ce6a7894b4ec8ff6827e8b802c2227909d9c60 | 631,331 |
def matTransposed(mat):
"""Return the transposed of a nxn matrix.
>>> matTransposed(((1, 2), (3, 4)))
((1, 3), (2, 4))"""
dim = len(mat)
return tuple( tuple( mat[i][j]
for i in range(dim) )
for j in range(dim) ) | e74eb18d9bccda06b160bfdd9bd8b67564c56d06 | 174,448 |
def get_user_tables(conn):
"""Retrieve all user tables."""
query_string = "select schemaname, relname from pg_stat_user_tables;"
with conn.cursor() as cursor:
cursor.execute(query_string)
tables = cursor.fetchall()
return tables | 36a8b76d2b0ed2c4f00bbdd9d61f6ac0d2ea2e60 | 579,077 |
def multiline_string_repr(string):
"""Return a representation of the string using multi-line string format
if possible."""
if '"""' not in string:
string = '"""{}\n"""\n'.format(string)
elif "'''" not in string:
string = "'''{}\n'''\n".format(string)
else:
string = repr(strin... | 6a190c49777571bb3cb774b4a065bfec8f63326e | 158,517 |
def df_swap_cols(df, columns):
"""Swaps the column by column name or index
columns: Can be a tuple of column indexes or names
ex. (2, -1) or ('a', 'b')
"""
first, second = columns
cols = list(df.columns)
if type(first) is int:
cols[first], cols[second] = cols[second], cols[first]
... | d6f3c9b38f2046e9d9633374e0165a54eb528508 | 576,663 |
def get_radec_cols(cat):
"""Return names of the RA and Dec columns for this catalog.
Parameters
----------
cat : Astropy Table object
catalog to extract RA and Dec columns from
Returns
-------
racol : Astropy.table.column object
RA column values
deccol : Astropy.table... | 8ebdd7e89d444e91b8d2dacf294200839a72dcc9 | 481,815 |
def make_play(play, board):
"""Put the word down on the board."""
(score, (i, j), (di, dj), word) = play
for letter in word:
board[j][i] = letter
i += di
j += dj
return board | fbc36b89dfebd526e02c3d790d0ac787e6228728 | 87,532 |
import json
def load_json_rcfile(fname):
"""Loads a JSON run control file."""
with open(fname, "r", encoding='utf-8') as f:
rc = json.load(f)
return rc | b698f06ed0cd2b0e0097d010a0199aa607c8e340 | 113,384 |
from pathlib import Path
def cleaning(*, path: Path, extension: str, affix: str) -> None:
"""Deletes all files in a Path with certain extension and name termination.
Parameters:
path: Path - directory where to delete files
extension: str - extension of files to errase
affix: ... | a9f305090fd6a105dc9d2cb08a98b75fdf12f35b | 589,453 |
def get_bit(byteval, index) -> bool:
"""retrieve bit value from byte at provided index"""
return (byteval & (1 << index)) != 0 | 1fe020449ae2ae2513073835db6f75b24e558fdb | 1,692 |
def get_width_height(image):
""" Returns a tuple (width, height) indicating the width and height of the image."""
width = len(image)
height = len(image[0])
return width, height | 4b45ec92d3a4b400d3b106e63d56fcbdef297760 | 692,309 |
def _get_task_file_name(task):
"""Returns the file name of the compile task. Eg: ${issue}-${patchset}.json"""
return '%s-%s-%s.json' % (task['lunch_target'], task['issue'],
task['patchset']) | a7df31c6312da0fec18e76099af1020fdbcbe325 | 667,697 |
def get_base_url(parsed):
"""Convert a parsed URL back to string but only include scheme, netloc, and path, omitting query."""
return parsed.scheme + "://" + parsed.netloc + parsed.path | 21df200efbd72eab7ea844e3d8b5466170eac5c9 | 627,723 |
def get_line_ABC_inter(line1, line2):
"""get line intersection point,
line1: A1*x + B1*y + C1 = 0, [A1, B1, C1]
line2: A2*x + B2*y + C2 = 0, [A2, B2, C2]
inter = B1*A2 - A1*B2
x = (C1*B2-B1*C2)/inter, y=(A1*C2-A2*C1)/inter
"""
inter = line1[1]*line2[0] - line1[0]*line2[1]
if inter != 0:
... | 291753265f253b0dd17fefd7de815b1b55686583 | 396,358 |
import warnings
def get_chromosome_reads(bam):
""" This function returns statistics about mapped/unmapped reads per chromosome as they are stored in the index.
It makes use of the method get_index_statistics() from the pysam module.
Parameters
----------
bam : dict, It is the output of the functi... | a94ac731e995b4a0ca8ecc16363af3428beb0df3 | 408,914 |
def output_name(pre_filename: str):
"""
Args:
pre_filename: test_pre_*****.png
Returns:
test_localization_*****_prediction.png,
test_damage_*****_prediction.png
"""
test_local = pre_filename.replace('pre', 'localization').replace('.png', '_prediction.png')
test_damage =... | f8c5b04bb531f663167395e1068aadc9855448f1 | 288,547 |
from typing import List
def calculate_node_correctness(pairs: List, num_correspondence: int) -> float:
"""
Calculate node correctness given estimated correspondences
Args:
pairs: a list of pairs of nodes
num_correspondence: the real number of correspondences
Returns:
node_corr... | 3fba7c4e7f7c30804a539b3becd61780e1207d7b | 432,904 |
from typing import Generator
def gen(*args: int) -> Generator[int, None, None]:
"""Convert arguments to generator"""
return (_ for _ in args) | 35ec3c24e6a3f7897618c8b4ddb849097f6682b4 | 130,306 |
def trace(X_ref, Y_ref):
"""
Calculates the slope and intercept for the trace, given the position of the direct image in physical pixels.
These coefficients are for the WFC3 G141 grism.
See also: https://ui.adsabs.harvard.edu/abs/2009wfc..rept...18K/abstract
"""
BEAMA_i = 41
BEAMA_f = 248
DYDX_0_0 = -3.5501... | da2f0f040804da451e860392456ecd31718ba1a0 | 217,880 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.