content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
import json
def load_cat_to_name(path):
"""Load a JSON file containing a mapping of category labels to flower names.
Args:
path: A pathlib.Path object containing the location of the JSON file.
Returns:
Dictionary: Containing the category labels as keys and the flower names
... | 3ca0d36caaf3315c021cea2c4d1b8d691d7b351e | 95,536 |
import re
def naive_error_classifier(error_string):
"""Attempts to guess the cause of an error in R
Parameters
----------
error_string : string
error output
Returns
-------
Likely error type (library, setwd, No such file) or None
"""
if re.search('library\s*\(',... | f70fbcd9cd2d70cf5653a1aa1ca13387655a5b00 | 95,537 |
def test_model(model, test_review_values):
"""
Get predicted values from test set
:param model: classifier model
:param test_review_values: values to test with
:return: predicted values (binary), predicted values (probability)
"""
predicted = model.predict(test_review_values)
predicted_p... | 0f1309b7d79f2120b35ff54f76f40334dde135ba | 95,545 |
from typing import Any
from pathlib import Path
def r(obj: Any, ignoreintkey: bool = True) -> str:
"""Convert a python object into R repr
Examples:
>>> True -> "TRUE"
>>> None -> "NULL"
>>> [1, 2] -> c(1, 2)
>>> {"a": 1, "b": 2} -> list(a = 1, b = 2)
Args:
ignorei... | 5c907ee0725ac49958f01ee0fe59f2b9deb7a4fd | 95,546 |
import typing
import itertools
def islice_limit(iterable,
*, limit: typing.Optional[int] = None,
offset: typing.Optional[int] = 0):
"""Return a slice from iterable applying limit and offset.
>>> list(islice_limit('spam', limit=3))
['s', 'p', 'a']
>>> list(islice_lim... | 1777c470901b98209fad841c0c25859adbdec7d7 | 95,550 |
def compare_version_numbers(version1, version2):
"""
Compare two version numbers.
Return -1 if version1 < version2, 0 if version1 == version2, +1 if version1 > version2
Version :== (k,l,m,n)
k, l, m, n := int
"""
if version1 is None:
if version2 is None:
return 0
... | c07db8c961042beecd1c358fc3734e460251056d | 95,552 |
def MakeUrl(host, port=80, location=''):
"""
Create a Tasmota host url
@param host:
hostname or IP of Tasmota host
@param port:
port number to use for http connection
@param location:
http url location
@return:
Tasmota http url
"""
return "http://{shost}... | 1865a59648ce0cd1ec04426a783eae043b9600d0 | 95,553 |
def hex_to_string(val):
"""Converts hex string to utf-8 string.
Accepts padded or unpadded values.
"""
if val is None:
return ""
s = val.strip('0x').rstrip('0')
if len(s) % 2 == 1:
s += "0"
return bytes.fromhex(s).decode('utf-8') | dfe4445a37d07e146df706607028d58d64df74a0 | 95,555 |
def sign(val):
"""
Mimics MATLAB's sign function
:param val: Input value
:type val: float
:return: The sign of ``val``
:rtype: float
"""
if val > 0.0:
return 1.0
elif val == 0.0:
return 0.0
else:
return -1.0 | dc7404ab357182ea718d1f925e2e12fda0f2c96a | 95,557 |
def get_folded_phase(t,best_period):
"""Fold the observation times with the best period of the variable signal."""
# light curve over period, take the remainder (i.e. the "phase" of one period)
phase = (t / best_period) % 1
return phase | 76788c1ebeaea4ade928a987ebc423f1eba4cdea | 95,558 |
def poisson(t, y, u):
"""Poisson's equation as system of 1st order ODEs."""
y1, y2 = y
y1d = y2
y2d = -u(t) ** 2 / t
return [y1d, y2d] | 8c51650044fe91ae71b80732773d1b4f84766395 | 95,560 |
def compute_overview_levels(band):
"""Return an appropriate list of overview levels."""
max_dim = max(band.XSize, band.YSize)
overviews = []
level = 1
while max_dim > 256:
level *= 2
overviews.append(level)
max_dim /= 2
return overviews | 96c2a73b902ac11dbedfde6e77511519a5f93619 | 95,564 |
def calc_SEFD(A, Tsys, eff=1.0):
""" Calculate SEFD
Tsys = system temperature
A = collecting area
Ae = effective collecting area
eff = aperture efficency (0.0 to 1.0)
"""
kb = 1.3806488e3 # 1.38064852e-23 Boltzmann constant
Ae = A*eff
return 2 * Tsys * kb / Ae | ac53e3925c8665a4e1ee524f84c49eb244f3adf1 | 95,565 |
import time
def convert_millisecond_date(x: int, date_format: str = "%Y-%m-%d") -> str:
"""
Converts a date in milliseconds to a string date.
:param x: time in milliseconds
:param date_format: date format to return
:return: time in date format
"""
return time.strftime(date_format, time.gm... | 317ce900bcbeaa80b265231608ef1cb2ad9fac56 | 95,566 |
import itertools
def peek(iterable):
"""
Get the next value from an iterable, but also return an iterable
that will subsequently return that value and the rest of the
original iterable.
>>> l = iter([1,2,3])
>>> val, l = peek(l)
>>> val
1
>>> list(l)
[1, 2, 3]
"""
peek... | c91cddb1f72b3a081f506022a0cffbf500f90844 | 95,570 |
def div_stand_devs(df, inputs):
"""
Divides each column by its standard deviation.
"""
sd = df.std(axis = 0)
for i in df:
df[i] = df[i] / sd[i]
return df | b52b5f46b86dae5fbbd2e400fc60d6b482dbcf42 | 95,572 |
import torch
def init_model(model_path: str):
"""
Loads PyTorch neural net located at <model_path>, and sets the model to
evaluation mode.
:param model_path: Global path to PyTorch model.
:return: Module
"""
model = torch.load(model_path, map_location=torch.device('cpu'))
model.eval()... | fc3c5d35099dd306c675b323094dc5d5660f045e | 95,573 |
import json
def dump_jsonl(obj):
"""Convert JSON object into 'JSON Lines' format string.
See http://jsonlines.org/ for the detail of the format.
Parameters
----------
obj : list of JSON compatible objects
Objects to be dumped.
Returns
-------
str
Resulting string.
... | c8ce5f6a190c74e4683e47cb674a96b6398d991e | 95,574 |
def jvq_to_list(jvq):
"""Turns a joint value quantity into a list
Parameters:
jvq JointValueQuantity
Return:
list with 7 elements
"""
return [getattr(jvq, 'joint_' + str(num)) for num in range(1, 8)] | b3924d0079092425d43dfa5bb3d8df6f8dbb40ef | 95,577 |
def is_supported_key_type(key):
"""
checks if the given key type is supported
Supported Types:
- int
- float
- str
- tuple
- NoneType
"""
if (
isinstance(key, (int, float, str, tuple, )) or
key is None
):
return True
retur... | 18bc01dc2d909d2c0fff0b4d68256f3b591a70ba | 95,581 |
def fvfm(fm, f0):
"""Calculate Fv/Fm
Fv/Fm = (fm - f0) / fm
:param fm: Fm
:param f0: F0
:returns: Fv/Fm (float)
"""
return (fm - f0) / fm | 9299dc5e77618180989c718b09b77e0217d84550 | 95,586 |
from typing import Dict
def _get_export_config(
multi_value_delimiter: str = "|", limit_records: int = 0, columns_exclude_regex: str = "",
) -> Dict:
"""Packages relevant pieces of JdbcExportInfo object into an exportDataConfig for jdbc export
in form of json dictionary
Args:
multi_value_del... | d9934680b86c87782884608f8ce5a2a1b96187d4 | 95,587 |
def create_cagr(equity, periods=252):
"""
Calcola il tasso di crescita annuale composto (CAGR)
per il portafoglio, determinando il numero di anni e
quindi creando un tasso annualizzato composto basato
sul rendimento totale.
Parametri:
equity - Una serie di pandas che rappresenta la curva eq... | 7a714db066d42a2b4217c34027d9d5877353b022 | 95,588 |
def output_ext(key: int, ext: str):
"""
given a key and file ext, concats them both.
de, 6 --> de6
"""
new_ext = ext + str(key)
return new_ext | 48a3e1ab76f3f764fe6a236aa8ae5fd06f45ab24 | 95,589 |
def bubblesort(numbs: list) -> list:
"""
Go through the array from left to right, for each couple of
numbers, check which one is bigger. If the first element of
the couple is bigger than the second, swap the two numbers.
Repeat the same process until the array is sorted (i.e.
when the number of ... | 1e688a195b9dcfb7d92ee75fdc5cbed12ab2e693 | 95,593 |
from typing import Any
def add_to(collection: Any, elem: Any) -> Any:
"""Add element to collection; return new collection."""
if isinstance(collection, str):
return collection + elem # Strings
try: # Lists and other collections
return collection + type(collection)([elem])
except Typ... | 49afdd40ca3ad296283d3ab54dca24195c0d8cf9 | 95,594 |
def process_ports_list(ports_list: list):
"""
:param ports_list: list of ports
[{'port name': 'RAW_L0', 'port size': 'L0_SIZE_RGB', 'port type': 'B'}]
:return: A list only with the port name
'RAW_L0, '
"""
string_to_return = ''
if ports_list is None:
s... | 142fae3e7187df87f37812b680fce040262c9ca1 | 95,596 |
def checkArrSqr(arr):
"""Check if arr has square shape"""
if arr.shape[0] == arr.shape[1]:
return True
else:
return False | e058293ab2fdac789fdf7211991399eddd617837 | 95,601 |
def append_suffix(name: str, suffix: str):
"""
Append a suffix (e.g. numeric or layer name) to a file-like name; preserve
the original non-numeric file extension (e.g. .fits); return the unmodified
name if it already contains this suffix
:param name: data file name, group name, etc.
:param suff... | 102bd67acb8552963a9ece0dc9e94776732746cb | 95,603 |
def num_months_between(start, end):
"""
Returns number of months between two dates.
Ignores day of month.
"""
m1 = start.year * 12 + (start.month - 1)
m2 = end.year * 12 + (end.month - 1)
return m2 - m1 | cfce358a668874fefacb0fde76face4b9bb2f17b | 95,605 |
import re
def GetBackgroundColorTypeTagForTableValue(Color, ColorType):
"""Setup color type tage for setting background of a table value."""
ColorTypeTag = "class" if re.match("^colorclass", ColorType, re.I) else "bgcolor"
return ColorTypeTag | 6df7cb31b66ff38a228e618ee914281eee2da5b7 | 95,606 |
import hashlib
def _path_safe(text):
"""
Return a filesystem-safe version of a string ``text``
返回文件系统安全版本的字符串``text``
>>> _path_safe('simple.org').startswith('simple.org')
True
>>> _path_safe('dash-underscore_.org').startswith('dash-underscore_.org')
True
>>> _path_safe('some@symbol?'... | 57d5fd527fc5515a84c3aae1b35f91a5da804d0b | 95,607 |
def grange(a,b,step=1.2):
"""
Returns a list between a and b of geometrically progressing series
"""
r = []
while(a < b):
r += [a]
a *= step
return r | a135c9ac7e64b58e6cc60ada49ffd577299f36cf | 95,608 |
def unpackRangeBits(ur1, ur2, ur3, ur4):
"""Given the ulUnicodeRange1, ulUnicodeRange2, ulUnicodeRange3,
ulUnicodeRange4 values from the OS/2 table, return a set of bit numbers.
>>> unpackRangeBits(0x0, 0x0, 0x0, 0x0)
set()
>>> unpackRangeBits(0x1, 0x0, 0x0, 0x0)
{0}
>>>... | 51f050c33246b4bd7b2111564ce6d5a0eb53ea7f | 95,609 |
def round_to_closest(x, y):
"""
A function to round x to divisible by y
"""
return int( y * ( ( x // y) + (x % y > 0) ) ) | ef8f5fff0ecd7314afe3e653e8cc5619c6fe19b6 | 95,611 |
def _casing_permutations(noun_chunk):
"""Generates casing permutations before wiki2vec entity lookup
Case matters during lookup into the pretrained entity embeddings, so
generate some permuatations to avoid misses.
Parameters
----------
noun_chunk : spacy.tokens.Span
Returns
-------
... | 95ba5af822f7e7ddbb6adcf97c0e3e6ff079131f | 95,614 |
def image_to_text(image, threshold):
"""Converts an image to text, lighting pixel greater than a threshold"""
text = ""
for y in range(image.size[1]):
for x in range(image.size[0]):
if image.getpixel((x, y)) > threshold:
text += "^^"
else:
text... | 4719053395592ea60c0fd19bed9eaed8bbe68829 | 95,615 |
def vertex_group_data(mesh, index):
"""
Return vertex group data for each vertex. Vertices not in the group
get a zero value.
:param mesh:
:param index:
"""
group_data = []
for vertex in mesh.vertices:
weight = None
for group in vertex.groups:
if group.group... | 691a6b531add2961012858cffa33f4e7829344a6 | 95,616 |
def _get_tf_batch_norm_parameter_name(bn_counter):
"""Returns the name of the batch_norm layer for the given batch norm index.
Args:
bn_counter: Integer number denoting the batch norm op index.
Returns:
A String denoting the name of the batch norm layer.
"""
if bn_counter != 0:
return 'batch_nor... | 2259cb01188354eaaeab082b6d00071326b9d9fa | 95,618 |
def _pluralize(wordlist):
"""Take a list of words and return a list of their plurals"""
return [i + 's' for i in wordlist] | f3656f4ba4516dd7a8cc3f1a5de2caa0894e9a8e | 95,620 |
def make_edge(u, v):
"""
Create a tuple representing an undirected edge.
@param u, v endpoints of the edge
@return a tuple (u, v) representing the edge. It is guaranteed that u <= v.
"""
if u > v:
u, v = v, u
return (u, v) | 1b2a1c0937be95bd47b0ad516d1012e4c38bce9a | 95,623 |
import json
def prettify_json_message(json_message):
"""
This function is a helper function that is used to prettify a json/dict message obj so that is more readable
for humans when it is logged.
:param json_message (dict): A message that is to be prettified before being logged.
Returns:
... | 42ca0e4e41b323c16c787c5586c580dcd3728949 | 95,627 |
def is_multiline(s):
"""Returns True if the string contains more than one line.
This tends to perform much better than len(s.splitlines()) or s.count('\n')
:param s: string to check
:return: Bool
"""
start = 0
lines = 1
while True:
idx = s.find('\n', start)
if idx == -1... | 1953791a57e257189ad944a363279ed74df593c3 | 95,628 |
def row_split(A, *indices):
"""
returns a list of rows corresponding to the passed indices
"""
if not indices:
indices = list(range(A.shape[0]))
res = [ A[i, :] for i in indices ]
return res | 829b40d2de2bc4e2ae79b14081c765abc4bad08c | 95,629 |
def mol_file_basename(tag):
"""Convert a tag into a molecular data file name.
This could be a tag string, if it is quoted and starts with a 0,
e.g. '032504', or a molecule number (int), e.g. 32504"""
if str(tag)[0] == '0':
return 'c'+tag+'.'
else:
return 'c%06d.' % tag | 7eac5dcf7716eced33bc5b0d3a3c8e35c9773ce5 | 95,631 |
from typing import Dict
import json
def load_params_file(params_file: str) -> Dict:
"""
Load a JSON file of training parameters.
:param params_file: The input file.
:return: A dictionary of training parameters.
"""
with open(params_file, 'r') as fin:
return json.load(fin) | 0538c795c706f6a4edf1c523b643dc349d1e033e | 95,632 |
def mock_object(**params):
"""creates an object using params to set attributes
>>> option = mock_object(verbose=False, index=range(5))
>>> option.verbose
False
>>> option.index
[0, 1, 2, 3, 4]
"""
return type('Mock', (), params)() | 937f41d630300adc3b5ba47aefb9a117261e5583 | 95,637 |
def extract_active_ids(group_status):
"""Extracts all server IDs from a scaling group's status report.
:param dict group_status: The successful result from
``get_scaling_group_state``.
:result: A list of server IDs known to the scaling group.
"""
return [obj['id'] for obj in group_status['g... | 2247e1aec63058e78b32e4d837e14ef5d978db16 | 95,639 |
def calc_check_digit(number):
"""Calculate the check digits for the number."""
return str(sum(int(n) * (7 - i) for i, n in enumerate(number[:6])) % 10) | e88e0f049599b2393ef55693db136ce1e10186fc | 95,649 |
def filter_black(word_list: list[str], black_list: str):
"""filters out words containing one of the given letters"""
for letter in black_list:
word_list = [word for word in word_list if not letter in word]
return word_list | 86254e087ca8dea39944f2544a771b1c6fa53ad9 | 95,650 |
def proxy_url(value, socks_scheme=None):
"""
Parse a single proxy config value from FindProxyForURL() into a more usable element.
:param str value: Value to parse, e.g.: ``DIRECT``, ``PROXY example.local:8080``, or ``SOCKS example.local:8080``.
:param str socks_scheme: Scheme to assume for SOCKS proxie... | 38be927f309374f1d17c383aa7059f735b22e3e4 | 95,651 |
def list_results(query_results):
"""
keys :: [key]
= all possible keys. (Not all results will contain all keys).
results :: [dict]
= list of results
"""
keys = query_results['head']['vars']
results = query_results['results']['bindings']
return keys, results | 6a7f927219411ad1e02b9d9c0c8e39f8547d34a5 | 95,654 |
from typing import Optional
import re
def parse_to_n_digit(url: str) -> Optional[str]:
"""Parses a n-hentai url to its digit."""
n_digit_match = re.search('([1-9][0-9]*)', url)
return n_digit_match.group(1) if n_digit_match is not None else None | 09cdc24eb2acabee3a5a58aa4ba0b3d89ac868cd | 95,663 |
def _embed_initial_state(initial_state, embedding, qubits):
"""Embed the states provided by the initial_state parameter used for reverse annealing.
Args:
initial_state (list of lists): Logical initial state as it would be passed to SAPI for reverse annealing.
embedding (dict): The embedding u... | 0c5b3722421288674efceba743a55c45d90ac7d4 | 95,666 |
def maxL(*it):
"""
Calculate maximum length of provided items.
Parameters
----------
*it : objects
Items of various lengths. Only lengths
of iterables are returned.
Returns
-------
Length of longest object (int).
"""
m = set()
for i in it:
try:
... | da8ef145097f03a02dea113ab0c0164b334cc35a | 95,670 |
def list_flatten(input_list):
"""Flatten an N-dimensional list of lists into a single dimension."""
# Convert atomic elements to single item lists then using a list
# comprehension convert to a flattened equivalent.
formatted_list = []
for element in input_list:
element = element if isinsta... | 6dba6a59c3814d0a30c944662604ced6100f8b1e | 95,673 |
def index_fixer(x_init, y_init):
"""
:param x_init: input X df
:param y_init: input y
:return: X,y with aligned indices
"""
y0 = y_init.dropna(how='any', axis=0)
x0 = x_init.dropna(how='any', axis=0)
common_indices = x0.index.intersection(y0.index)
y_final = y0.loc[common_indices]
... | 96062063e7676fe2c3a75685f493b2315b342745 | 95,675 |
import re
def remove_comments(contents):
"""
Remove the comments from the contents
"""
contents = re.sub(re.compile(r"#.*?\n", re.DOTALL), "",
contents) # remove all occurrences of #COMMENT from line
return contents | 26dce5172c16b68b1ab5a1b64b1dd2f4d49b0aaf | 95,679 |
import yaml
def replace_pcell_params_from_yaml(pcell_script, params_yaml_path):
"""Replace PCell params from YAML file
Parameters
----------
pcell_script : str
Python PCell script.
params_yaml_path : str
Absolute path of design params YAML.
Returns
-------
pcell_s... | 152e2689c9dacdd68aa09bbb141dfbc79de96539 | 95,684 |
def next_marker_by_offset(collection, limit, marker):
"""
Returns the next marker that is just the current marker offset by the
length of the collection or the limit, whichever is smaller
:param collection: an iterable containing the collection to be paginated
:param limit: the limit on the collect... | ae13d1568dc27ab64d8821ba530f2e294ec47082 | 95,690 |
import random
def evolve(pop, mutate_rate, mu, lambda_):
"""
:param pop: populations of the parents
:param mutate_rate: default rate is 0.02 in function mutate
:param mu: select the size of parents who behave better
:param lambda_: size of the mutated children
:return: a new populations
""... | d6c98156b22b6a1c53bc30b2d2a2152e1c6babf2 | 95,695 |
from typing import List
from typing import Dict
def build_url_filter(
excluded_fields: List[str],
included_fields: List[str]
) -> Dict[str, Dict[str, bool]]:
"""Return a URL filter based on included and excluded fields.
If a field appears in both excluded_fields and included_fields, it
is... | 611e15cab2e1bd7927e5ea1b441dbf13f34f48bf | 95,696 |
def count_model_params(model):
"""
Returns number of trainable and non-trainable parameters in a model.
:param model: A PyTorch nn.Module object.
:return: A tuple (train_params_count, non_train_params_count)
"""
train_params_count = 0
non_train_params_count = 0
for p in model.parameters... | cd2d6f41d0e65d2c6ff9dd5ee7ce02a554c5edfa | 95,697 |
def pad_pkcs5(data, block_size):
"""
Returns the data padded using PKCS5.
For a block size B and data with N bytes in the last block, PKCS5
pads the data with B-N bytes of the value B-N.
:param data: Data to be padded.
:type data: :class:`str`
:param block_size: Size of the block.
:typ... | 5b28ef53a2fba394741a040509b5f82b2d947021 | 95,702 |
import string
import random
def _random_string(length, chars=string.ascii_lowercase, prefix='', suffix=''):
"""
Return a random string with given length, prefix and suffix.
The random characters are chosen from the chars iterable (lowercase
letters by default)
"""
r = ''.join(random.choice(cha... | 9d2f349d5ddcacf6f1b367bac0f8dbbbd9b31fa2 | 95,704 |
def split_context(method, args, kwargs):
""" Extract the context from a pair of positional and keyword arguments.
Return a triple ``context, args, kwargs``.
"""
return kwargs.pop('context', None), args, kwargs | d37c0112eed8d54741b0d1b73dda8187b95752a4 | 95,705 |
def clean_text(text: str) -> str:
"""Clean Text of a String and make it URI-Compatible
Args:
text (str): The Text to String
Returns:
str: Cleaned Text
"""
return (
text.replace(",", "%252C")
.replace("?", "%253F")
.replace("/", "%252F")
.replace("\\"... | 3da7bd895c8977aa307048912196b9a8099704e8 | 95,711 |
def tupleized(a, b):
"""Python supports a single return value.
None by default.
Multiple return values can be packed into a tuple.
"""
return b, a | c4ec00760aa86380044ef626bb20595345001e9a | 95,715 |
def lookup(dictionary, key, *keys):
"""
Helper to lookup a key or nested keys within a dictionary
"""
if keys:
return lookup(dictionary.get(key, {}), *keys)
return dictionary.get(key) | be7ff76162f751b6b835855438de165d87ead752 | 95,717 |
def get_target(df):
"""Get the target variable as a numpy array."""
return df['target'].values | 1f840830a54b5f5bd81f3a39b969cdd6903fe3e6 | 95,719 |
def link(href):
"""Create a regex for a <a> tag."""
return '<a ([^>]*?)href="{}"'.format(href) | 751eb26be44a65d9b844657cc434894b8d9cff50 | 95,724 |
from typing import Union
import json
def dump_json(path: str, data: Union[dict, list], indent: int = 4) -> str:
"""
Shortcut for dumping data to a json file.
Parameters
----------
`path` : str
The path to the json file.
`data` : Union[dict, list]
The json serializable object t... | 00f173e2414ac2fb63b4178717af931e1c6b5439 | 95,726 |
def tesla_to_gauss(tesla):
"""Converts tesla to gauss"""
return tesla*1e4 | c43aa035a2cbf1625f1ea3c71b3068d6356ff847 | 95,734 |
def vector_to_probs(vec, counts):
""" Return dict of probabilities.
Parameters:
vec (ndarray): 1d vector of probabilites.
counts (dict): Dict of counts
Returns:
dict: dict of probabilities
"""
out_counts = {}
idx = 0
for key in counts:
out_counts[key] = vec[... | f1ab089c80b5cc4445b6038f02809bd6afcc0146 | 95,738 |
def load_palette(filename):
"""
Loads a 64 value palette from a .pal file (binary, 3 bytes per color).
Palettes can be created from bisqwit's tool here: https://bisqwit.iki.fi/utils/nespalette.php
:return: A list of rgb tuples (elements in range 0-255) corresponding to the palette colors
"""
wit... | dcd450a54d617cf7b5759b6b5d35ec65faccde40 | 95,739 |
def get_engine(self, name):
"""
Retrieves the (template) engine for the requested name,
this value is going to be retrieved from the currently
set map of engines in from the controller.
:type name: String
:param name: The name of the engine that is meant to
be retrieved, this name should be... | 6025e9cfd4d88ad972f176f437ae9747ad2e839d | 95,741 |
def get_year(date):
"""Get year of DATE string"""
return date[0:4] | 547b6cab1610e10772a98ec4170c47e381ef879f | 95,744 |
import tempfile
import json
def convert_txt_to_tmp_json_file(txt_inference: str) -> str:
"""Converts a txt with inference content to a JSON file with schema
expected by read_examples. Returns a filename to the temp JSON file."""
tmp_file = tempfile.NamedTemporaryFile(mode='w', delete=False)
json_data ... | b12b51ebb4b7f0d33e87e0738be1a1b557240fcc | 95,760 |
def _execute(executable_resource):
"""
Invoke a get/list Google Classroom SDK function,
retrying if there are errors.
Parameters
----------
executable_resource: function
is the get/list Google Classroom SDK function to call
Returns
-------
object
a Google Classroom ... | 84398e56f04961977d802a17ffff00cc8f8932fc | 95,764 |
from typing import List
def tokenize(expr: str) -> List[str]:
"""Breaks expression `expr` into a list of tokens"""
return expr.split(" ") | 3ea07a9d99937297bb78d15da509d1c7f96072b0 | 95,766 |
from typing import TextIO
def read_sequence(input_io: TextIO) -> str:
""" Read sequence data. """
return "".join([s.strip() for s in input_io.readlines()]) | 0da8aca479fd59768f8c8a2e953b24797a3db8e6 | 95,773 |
def get_number_of_epochs(opt, loader_train):
"""define the number of training epochs based on the lenght of the dataset and the number of steps"""
epochs = opt['epochs']
iter_per_epoch = -(-len(loader_train.dataset) // opt['bs'])
if epochs < 0:
epochs = 1 + opt['nsteps'] // iter_per_epoch
re... | a73904933e151ad03bb7ef3f9a23f0627d0ca086 | 95,777 |
import re
def parse_dependencies_from_ldd_output(content):
"""Takes the output of `ldd` as a string or list of lines and parses the dependencies."""
if type(content) == str:
content = content.split('\n')
dependencies = []
for line in content:
# This first one is a special case of invo... | c423ba158f1bba5b6100f22428fa6cf513ef2dd2 | 95,778 |
import logging
def run_initializer(initializer, initargs):
"""Runs the Pool initializer dealing with errors."""
try:
initializer(*initargs)
return True
except Exception as error:
logging.exception(error)
return False | f07f99c650f90531c8f0f9976db5a8e40150c8e7 | 95,779 |
def convert_to_oneline(multiline: str) -> str:
"""Converts a multiline Sleep command to a single line.
Args:
multiline (str): The multiline Sleep command.
Returns:
str: A single-lined version of the same Sleep command.
"""
# Format wrapper so it sends as one-line
oneline = ... | edf833ff0920673bbab1cff2122f66b22bac08cc | 95,782 |
def list_from_file(filename, encoding='utf-8'):
"""Load a text file and parse the content as a list of strings. The
trailing "\\r" and "\\n" of each line will be removed.
Note:
This will be replaced by mmcv's version after it supports encoding.
Args:
filename (str): Filename.
e... | 9f61c00107d715e01e0f3f0821e222eb5e641e51 | 95,784 |
def constrain(x, x_max, x_min=None):
"""
Constrans a given number between a min and max value.
Parameters
----------
x : scalar
The number to constrain.
x_max : scalar
The upper bound for the constrain.
x_min : scalar, default=None
The lower bound for the constrain. If None, defaults to -`x_m... | 0876ce02d4a61f717824613c0543d83228ab6902 | 95,787 |
import json
def ensure_serializable(data):
"""
This ensures data is serializable.
Args:
data: Any data to serialize.
Returns:
data: The serializable data.
"""
try:
json.dumps(data)
return data
except:
return str(data) | 83703458fd95154ff12addc0e93d7cf3f031a827 | 95,791 |
import math
def logistic_function(beta, h):
"""logistic function for logistic regression"""
return 1/(1 + math.exp(-(beta[0] + beta[1]*h))) | 0735c4b4eb3a1248bd9b8b28220d2ea68904637c | 95,795 |
def _check_if(cond, fn, value, name):
"""Performs a check if condition is true."""
return fn(value, name) if cond else value | 73adef5ad56934f3bf9c77bd75ac3c3a1dee034b | 95,796 |
import toml
def environment(file, transect):
"""
Read environmental metadata, temperature and salinity, from the file
"transects.toml".
Args:
file (str): path to transects.toml.
transect (str): Name of transect.
Returns:
float: Temperature (degrees Celsius... | 0623b41a7c163e7fe2a10cd3c5b2ca7877263c5e | 95,797 |
def get_points(view):
"""Get the list of cursor positions."""
return [region.b for region in view.sel()] | 9a59f098eb85d574554434df8542473f7459575d | 95,799 |
def determine_elevations(grid_elevation_file, elevations, height):
"""Determine a list of adjusted elevations to use
Args:
grid_elevation_file <file>: File where 0 elevations are to be written
elevations [<float>]: Initial list of elevations
height <float>: Height for the bottom pressur... | 4d4446739ffbeda0724aa995c808ad2f54b44be4 | 95,800 |
def energyNormFunc(v, mean, stddev):
"""Energy normalizes the given value.
For normally distributed data, 95% of it should lie within 2 stddev's of the mean.
So we want to get 95% of the data between -127 and +127, and then we'll shift it
up by 127 to get it from 0 to 255"""
factor = 127.5/max(2*std... | b00de9326b940fec2be9928fcb132d46f4f597a2 | 95,802 |
def all_exist(paths):
"""Return True if all paths in list exist."""
return all([path.exists() for path in paths]) | e27d911e20b78e64320f573ce502453516833b5b | 95,809 |
def get_current_light_reading(response):
"""Get light value from response."""
current_light_reading = response.get('light')
return current_light_reading | b1e1cd9a5acf5adef0beab8785a2dba6050e1f4b | 95,810 |
import csv
from collections import namedtuple
def new_objects_from_csv(csv_file: str):
"""For each row in the .csv, returns a list of custom objects with properties/attributes corresponding to the header names of each column.
Example:
>>> results = new_objects_from_csv('brandnew.csv')\n
>>> p... | 92e55fa34783f38ca787cb19842db4d00cc3f76f | 95,812 |
def find_datafields(obj):
"""Return pairs of (`number`, `title`) for all available data fields in
`obj`.
"""
token = '/data/title'
channels = [int(k[1:-len(token)]) for k, _ in obj.items()
if k.endswith(token)]
titles = [obj['/{}/data/title'.format(ch)] for ch in channels]
... | 164c0b262b78f15a633c13b2c1a625bb54904b86 | 95,814 |
def recurrent_name(recurrent):
"""
Gets a human readable name for the recurrent.
:param recurrent: recurent instance
:return: name
"""
return ' '.join(recurrent.__name__.split('_')) | 1e14635fcb164b374d227dadc4a293defc5b101a | 95,815 |
def reactionStrToInt(reactionStr):
""" Groups GENIE reaction string into following categories
Reactions can be divided into two basic categories:
1) CC, 2) NC
These can then be further divided into subcategories of
interaction modes
1) QES, 2) RES, 3)DIS, 4) COH
And the target nucleon can b... | c64adc712bc996923ad4991e51d64abcb4b2e69a | 95,820 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.