content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def check_module( mymodule, indent='' ):
"""
Returns a string describing the version number, import path and
other administrative information contained in a given module.
:Parameters:
mymodule: Python module
The module to be checked. It must already have been imported.
... | d86b87d1b031bed13610605c1b82920b28f31c23 | 49,397 |
from jinja2 import Environment, FileSystemLoader
import os
def load_template(template_dir: str, filename: str, message_dict: dict, lang: str) -> str:
"""
This function loads a template file by provided language.
"""
if isinstance(template_dir, str) and os.path.isdir(template_dir):
try:
... | b540fc77f77e7a93f7171d8ccca900f8c75d3e3e | 49,398 |
def mul(a,b):
"""cumulative product reduction"""
return a*b | 8fce05af9e0059f4a0aca90325a5dc7cd58b1125 | 49,399 |
def get_bytes_used(current_time, process_durations):
"""
Return bytes used at given time.
>>> get_bytes_used(12, [2, 3, 4])
13
>>> get_bytes_used(14, [2, 3, 4])
14
:type current_time: int
:param current_time: Array index
:type process_durations: list
:param process_durations: ... | b87e4bc1f7050904a58ef6124beded518fda3094 | 49,400 |
def to_pascal_case(value: str, ignore_pattern =None) -> str:
"""
Convert camel case string to pascal case
:param value: string
:return: string
"""
content = value.split('_')
if len(content) == 1:
if ignore_pattern and ignore_pattern.match(content[0]):
return content[0]
... | f92dee394540fb305fb1a6943e26056539487011 | 49,401 |
def call_api(func, n):
"""
A wrapper to call api function. If response is null retry n times.
"""
if n == 0:
return func
else:
n -= 1
return func or call_api(func, n) | 8d61134ed7573eb3df99763a20f81bf081417bd1 | 49,402 |
from typing import List
import heapq
def maxEvents(self, events: List[List[int]]) -> int:
"""
>>> Greedy
Add the events to the min heap and always attend the event that ends
earliest if possible.
"""
events.sort(reverse=True)
heap = []
ans, cur... | f6c53abaedbc3fca50d27f9c449c246bb30c7ec9 | 49,403 |
def produto_vetorial(mat_A: list, mat_B: list) -> list:
"""Aplica uma multiplicação matricial entre A e B."""
assert len(mat_A[0]) == len(mat_B)
matriz = []
for linha in range(len(mat_A)):
matriz.append([])
for coluna in range(len(mat_B[0])):
matriz[linha].append(0)
... | 130d58bc1ee96a01feaff9b9c5e1798e4a2f8654 | 49,404 |
def solutionClosed(n: int, p: float) -> float:
"""
A closed-form solution to solutionRecursive's recurrence relation.
Derivation:
Let q = (-2p + 1).
h[0] = 1,
h[n] = q h[n-1] + p.
By iterating,
h[1] = q + p,
h[2] = q (q + p) + p = q^2 + pq + p,
h[3] = q (q^2 + pq + p) + p = q^3 + pq^2 + pq + p,
h[n] = ... | 2f3bac0cd6981989dac4570180a215e20966dc11 | 49,407 |
def has_lower_letters(password):
"""Return True if password has at least one lower letter."""
return any(char.islower() for char in password) | d55a37e994e289886efdce6e815a430777572b97 | 49,410 |
import yaml
def load(file: str = "lang/en_US.yaml") -> dict:
"""Loads the language file and returns it"""
global lang
with open(file, encoding="utf-8") as f:
lang = yaml.safe_load(f)
return lang | a34cb9d9561b2edf1597f542a07d50b683a8fbff | 49,411 |
async def watches(ctx, msg):
""" * desc: list your stattrak watches
"""
uid, _ = await ctx.db.get_user_id(msg.guild.id, msg.author.id)
watches = await ctx.db.get_user_watches(uid)
msg = ""
for _, _, name, _, _, _, count, _, _ in watches:
msg += "\n * `{}`: {:d}".format(name, count)
r... | 5dbf78287d0f5b759714307c0f3ddcb4b2cd2edb | 49,413 |
import re
def GetRegexPattern(reobj):
"""
* Get the regex pattern string from
the regular expression.
Inputs:
* reobj: Regular expression object.
"""
if not isinstance(reobj, type(re.compile(''))):
raise Exception('reobj must be a regular expression object.')
objstr = str(reobj... | 36b81d20c2dd8f32404c4aee21bd4583f095003f | 49,415 |
def extract_property_from_uri(uri: str) -> str:
"""
从property uri中提取出property name
:param uri: 如 <http://www.kg.com/kg/ontoligies/ifa#createTime>
:return: 如 'createTime'
"""
separator_idx = uri.rfind('#')
if separator_idx == -1:
raise ValueError
return uri[separator_idx + 1:] | 6c0902a954a247c7c843f15be6e3d98bf3a3721f | 49,416 |
def truncated_mean(data):
"""Compute the mean and excluding outliers.
Args:
data (DataFrame): Pandas dataframe.
Returns:
int: Mean of the column.
"""
top_val = data.quantile(0.9)
bot_val = data.quantile(0.1)
trunc_val = data[(data <= top_val) & (data >= bot_val)]
mean =... | c8fa4f57f22c5255467ce1022abdf8c0f2614e2f | 49,418 |
def is_supported_value_type(value):
"""
checks if the given value type is supported.
Supported Types:
- strings
- bytes
- numbers
- tuples
- lists
- dicts
- sets
- booleans
- None
"""
if (
isinstance(value, (str, bytes... | fa9d8ae96dcde739e73d8108cfeefef8bd88451b | 49,419 |
import six
def _is_possible_token(token, token_length=6):
"""Determines if given value is acceptable as a token. Used when validating
tokens.
Currently allows only numeric tokens no longer than 6 chars.
:param token: token value to be checked
:type token: int or str
:param token_length: allo... | 186447c08cb64178e1f99fabc5523f2a92762ca5 | 49,420 |
def add_releaseyear(dataframe):
"""extract release year from release date"""
dataframe['release_year'] = dataframe['release_date'].apply(lambda x: str(x)[:4])
return dataframe | b679361ec35d99611ca64207afd24b542868f179 | 49,422 |
def interpolate_grids(data2, interpolation_scheme):
""" Interpolate all variables in data to a different grid.
Possible interpolations are:
T -> U; T -> V; U -> V; V -> U.
Parameter
---------
data : xarray.Dataset
Dataset containing 4D ('time_counter','x','y','z') and
3D... | 11d340e701a74fcd74d898501a57a192aca3ccb4 | 49,423 |
import unicodedata
def maketrans_remove(accents=("COMBINING ACUTE ACCENT", "COMBINING GRAVE ACCENT")):
""" Makes a translation for removing accents from a string. """
return str.maketrans("", "", "".join([unicodedata.lookup(a) for a in accents])) | 516114526f6d7d36b2b454cd07e40302bd7a83f7 | 49,424 |
def config(request):
"""
fixture to add configurations on setup by received parameters.
The parameters expected in request are the avaiable additional configurations.
e.g. : test_techsupport[acl]
"""
return request.getfixturevalue(request.param) | 30cbfc54ef80739d97b5856f6dfe8f700dc5ca0e | 49,425 |
import struct
def unpackbyte(b):
"""
Given a one-byte long byte string, returns an integer. Equivalent
to struct.unpack("B", b)
"""
(ret,) = struct.unpack("B", b)
return ret | 8d4a79bda22554604637e1ca934a85b3a6f71cdb | 49,426 |
import math
def slurm_format_memory(n):
"""Format memory in bytes for use with slurm."""
if n >= 10 * (1024 ** 3):
return "%dG" % math.ceil(n / (1024 ** 3))
if n >= 10 * (1024 ** 2):
return "%dM" % math.ceil(n / (1024 ** 2))
if n >= 10 * 1024:
return "%dK" % math.ceil(n / 1024)... | 7a454fee5754503ad30d3b0cb8e8261adac7d19f | 49,427 |
def clean(phrase, valid):
"""Remove all characters from `phrase` that are not in `valid`.
:param phrase: the phrase to clean
:param valid: the set of valid characters. A sensible default is
`sounds.ALL_TOKENS`.
"""
return ''.join([L for L in phrase if L in valid]) | 09f01b02b68cb6f63a54102b493e876d9dc1008f | 49,429 |
import time
from datetime import datetime
def base_record() -> dict:
"""
Return a basic record with the audit flags we use in all records.
Args:
None
Returns:
(dict): dict with audit fields populated.
"""
return {"time": time.time(), "time_str": datetime.utcnow().strftime("%Y... | 49a16ac37947ccff482a1400c054f87abfb2553b | 49,431 |
from typing import List
def reverse(data: List[int]) -> List[int]:
"""Given a list of integers, returns the same list in reverse
order.
Initialize empty List Reversed
While there are Numbers in Data:
Remove last Number in Data
Append Number to Reversed
Return Reversed
"""
... | 595a6815c1823141875d7cac7e5cdb5a2bb8b934 | 49,432 |
def _get_cbend_msg(is_stress, is_mag_phase, is_sort1):
"""get the header for the CBEND result"""
if is_stress:
stress_strain = ' S T R E S S E S I N B E N D E L E M E N T S ( C B E N D )'
else:
stress_strain = ' ... | e0778a09369091cc6c8f0d408f34d097d84ee3ec | 49,433 |
def lowercase_first(value: str) -> str:
"""
Lower cases the first character of the value.
Parameters
----------
value: :class:`str`
The value to lower case.
Returns
-------
:class:`str`
The lower cased string.
"""
return value[0:1].lower() + value[1:] | df1ed3d9b3adf9f410cc708fc8505d2791c60187 | 49,434 |
def get_non_hidden_fields(form):
"""
Returns all the visible fields of the form.
"""
return form.visible_fields() | a7003b12f1ca89414db299114a06bd819b3f4932 | 49,435 |
import itertools
def correct_answer_combinations(correct_answer):
"""
Determine all possible orderings for the "correct answers" to a multi choice question.
Args:
correct_answer: An array who elements comprised the correct answer to the question.
"""
combos = itertools.permutations(corre... | b597c149f142aa69c8c89285e187e64457793db5 | 49,436 |
def is_namedtuple_cls(cls):
"""Test if an object is a namedtuple or a torch.return_types.* quasi-namedtuple"""
try:
if issubclass(cls, tuple):
bases = getattr(cls, "__bases__", []) or [None]
module = getattr(cls, "__module__", None)
return module == "torch.return_type... | 73698f8836b902405241df045aa01800173414c8 | 49,437 |
def sort_rat(name_list: list, ratings: list, reverse: bool = True):
"""
Sort ratings associated with names. The sort is stable.
:param name_list: The list of names to be associated with the ratings respectively
:param ratings: The list of ratings to sort
:param reverse: Descending by default. False... | cfb944d067c41f45c4e558fdeb55905de0ec01b4 | 49,438 |
def sigmoid(x):
"""
Sigmoid(x) = 1 / (1+e^-x)
"""
return 1 / (1 + (-x).exp()) | 1d60e8061e239b4de471ae4a38eb337365f498b5 | 49,441 |
import subprocess
import os
def GSL_library_dir():
"""return directory for location of GSL binaries, useful when combining GSL and cython"""
try:
lib_gsl_dir = subprocess.check_output('gsl-config --libs', shell=True).decode('utf-8').split()[0][2:]
except subprocess.CalledProcessError:
lib_... | 461fd615bea5bfc09547d9281da03be3ae9161e6 | 49,442 |
def to_the_power(number, power):
"""
Raises the
:param number:
:param power:
:return: result
"""
return number ** power | 71b9a84d613372c346e4447c5d98dcd6ff3d1a34 | 49,444 |
def duplicate_free_list_polynomials(list_of_polys):
"""
Takes a list of boolean functions and generates a duplicate free list of polynomials.
# Arguments
list_of_polys (BooleanFunction): A list of polynomials.
# Returns
list: A duplicate free list of functions
"""
o... | b5099bf832ff5f23d1f0a4ea7cd74fbba51fbc75 | 49,446 |
def copy_df(df):
"""
DESCRIPTION
-----------
Deep copy a pandas dataframe.
PARAMETERS
----------
df : pd.DataFrame
A pandas dataframe instance
RETURNS
-------
A deep copy of a given pandas dataframe
MODIFICATIONS
-------------
Created : 4/26/19
"""
... | a130830820a9aef0c2419580a2493bb1f14111df | 49,447 |
def strip_locals(data):
"""Returns a dictionary with all keys that begin with local_ removed.
If data is a dictionary, recurses through cleaning the keys of that as well.
If data is a list, any dictionaries it contains are cleaned. Any lists it
contains are recursively handled in the same way.
"""... | 92fb36a2f3bb618b7b706dd33a3347666d0fa07e | 49,448 |
import re
def get_error_log_compiled_pattern():
"""Creates the compiled pattern for error log file
:return: compiled pattern
:rtype: compiled pattern in re library
Example of valid pattern:
'the request e90f9480d500cad488650afb3a73c854 blocked '
'rule ID 1567'
"""
return ... | f2f53d9f8c540f72bb3fd8747e858cb0a7ef2774 | 49,449 |
def budget_equalities(sequence:str, price_vars:list, budget_vars:list)->list:
"""
Given a picking-sequence, create symbolic equalities determining that the
total price of each agent's bundle equals the agent's budget.
Currently works only for 2 agents.
:param sequence: a string determining the pic... | ead48548766afc53e7583b65d88bfc8a10906382 | 49,450 |
def get_rAB_2(new_solution,rAB_p1,rAB_c1):
"""
Gets the rAB_p2 (and rAB_c2) values of all species in a given solution.
Parameters
----------
new_solution: The object representing the cantera model
rAB_p1: A dictionary containing the rAB_p1 values for the reduction
rAB_c1: A dictionary containing the rAB_c1... | 0c2e9f9bd20c7f3c62e6e4b997771ab339c79c3d | 49,451 |
def newtonMethod(f, df, x0, tol=0.001):
"""Calculate the root of f within tolerance tol"""
xi = x0
while abs(f(xi)) > tol:
xi = xi - (float(f(xi))/df(xi))
return xi | 3abc05427a91bcf703eecf071d4a248d387f9a9f | 49,452 |
def get_recipes_in_node(node):
"""Gets the name of all recipes present in the run_list of a node"""
recipes = []
for elem in node.get('run_list'):
if elem.startswith("recipe"):
recipe = elem.split('[')[1].split(']')[0]
recipes.append(recipe)
return recipes | 9d2cc0aac4b819428a5984e3852035650afeedf4 | 49,453 |
import math
def fwhm_to_gamma(fwhm, beta):
""" in arcsec """
return fwhm / 2. / math.sqrt(2**(1./beta)-1) | 4e3deb88c6f21b04e0fd16ed352cce825c10c9a3 | 49,455 |
from pathlib import Path
from typing import Tuple
from datetime import datetime
def parse_dates_from_filename(file: Path) -> Tuple[datetime, datetime]:
"""
Extracts the start and end time from an existing file.
:param file:
:return: tuple of start and end time
"""
split_names = file.stem.spl... | a03212ed2df9826cc631cda9e63157d6675f82a8 | 49,456 |
def weekend_init(M, i, t):
"""
Determines days to treat as weekend using midnight threshold parameters
:param M: Model
:param i: period
:param t: tour type
:return: list of ints; either [1, 7] or [6, 7]
"""
result = []
lens = [M.lengths[k] for k in M.tt_length_x[t]]
max_len = ma... | 59e049e4d22f03e042aafa1799fe9f4e199babb4 | 49,457 |
import json
def canonical_json(o):
"""
Dumps an object as canonical JSON string.
Canonical JSON does not contain an space (except in strings) and
have all the keys sorted.
Args:
o: The object to dump.
Return:
The canonical JSON string.
"""
return json.dumps(o, sort_k... | 74a6e880987cc1aaccd19a3d68f63ecf0d9835d3 | 49,458 |
def grep(pattern, flags, files):
"""
Search file(s) for lines matching a regular expression pattern
and return the line number and contents of each matching line.
:param pattern string - pattern used to match lines in a file.
:param flags string - Zero or more flags to customize the matching be... | 45abd78939f2fe6bd68e8dbe2f59c4b3b93986d0 | 49,459 |
from bs4 import BeautifulSoup
def _parse_winrates(html):
"""
<td><strong>TvZ</strong>:</td>
<td>148-139</td>
<td>(51.6%)</td>
<td>[ <a href="/tlpd/korean/maps/237_Fighting_Spirit/games/TvZ">Games</a> ]</td>
<td><strong>ZvP</strong>:</td>
<td>134-117</td>
<td>(53.4%)</td>
<td>[ <a h... | 148142d5da9cbedf3eeb7282f7972f21f10b926f | 49,460 |
def function_with_docstring(a: int, b: int) -> int:
"""This function has a docstring.
Because of that, it shouldn't be generated.
"""
return a ** b | 9e6e1a6ebf4ea85b368d8ec53efb1747bdaa48c3 | 49,462 |
def _set_new_pose(pose_np, sign, axis):
"""set new pose with axis convention."""
target_sign = [-1, 1, -1]
target_axis = ['x', 'z', 'y']
pose_rearrange_axis_result = pose_np.copy()
for axis_index, axis_name in enumerate(target_axis):
src_axis_index = axis.index(axis_name)
pose_rearr... | 5dfeac95bf97a88397e86e5ebee2ba7cae518961 | 49,463 |
def read_summary_file(summary_file):
"""
Read in partial summary and add gene info to dictionary
:param summary_file: (string) name of partial summary file
"""
genes = {}
case_qual = []
ctrl_qual = []
with open(summary_file, 'r') as infile:
header = infile.readline().strip().spli... | 06d5dfacbef00b4ec3feed6b8ce6559aa7046604 | 49,464 |
def _count_trailing_zeros(mask: int) -> int:
"""count the trailing zeros of a bit mask. Used for shifting.
Args:
mask (int): bit mask, eg 0b00111000
Returns:
int: number of trailing zeros
"""
if mask == 0:
raise ValueError("mask is all zeros")
count = 0
for i in ran... | 3f8ce2c9a5a5143715e2fe52aabdeed3ae692f17 | 49,465 |
import os
def get_dirs_for_features(root, features, dirs):
"""
Find which directories to include in the list of build dirs based upon the
enabled port(s) and features.
"""
outdirs = dirs
for adir in dirs:
for feature in features:
relpath = os.path.join(adir, feature)
... | 849bacca3822bd67889e199ff4cbbcebd61b958f | 49,466 |
def subsetData(data):
"""
function to subset data based on inputs
"""
### processes
return data | 4c2440d7b68cbc5ed9496caf366d5e329a6803f2 | 49,467 |
import os
def ensure_file(file):
"""Ensure a single file exists, returns the absolute path of the file if True or raises FileNotFoundError if not"""
# tilde expansion
file_path = os.path.normpath(os.path.expanduser(file))
if not os.path.isfile(file_path):
raise FileNotFoundError(f"The file {fi... | 9ebc6910dfba0d9c5232781afa1bcd3cfe54d2f2 | 49,469 |
import logging
def prepare_data(df):
""" it is used to prepare dependent and independent features seprately from dataframe
Args:
df (pd.DataFrame): This method takes dataframe as input
Returns:
[tuple]: This method returns tuples
"""
logging.info("preparing the data for training")
X = df.dro... | 067c81d837018e2bb9c9b4e271611ace9dede1e7 | 49,470 |
def imm_to_bin(immediate):
"""
"""
return'{:#018b}'.format(int(immediate)) | 139323403d17551ef12fddc3943475b60d61ca70 | 49,472 |
def relative_x(xarr, yarr, *args):
"""First value in xarr is subtracted from each x
"""
return (xarr - xarr[0], yarr) + args | 8c8310b41b6de8a3d9a1846bda2e23a3d67474c8 | 49,473 |
def update_output_div(input_value):
"""Returning user input.
Args:
input_value: the input of dash.
Returns:
string of the output in html.
"""
return f"{input_value}" | 8c1cd2effd421c419c31b31f589d2d71ecb935ed | 49,474 |
def adjust_site_parameters(site):
"""Add the PV modeling parameters"""
out = site.copy()
modeling_params = {
'ac_capacity': 0.00324, # no clipping
'dc_capacity': 0.00324,
'temperature_coefficient': -0.420,
'dc_loss_factor': 0,
'ac_loss_factor': 0,
'surface_ti... | aa5713f201138a03371b21c63594ad72d47c008c | 49,475 |
import random
def purchase():
"""Return a random amount in cents """
return random.randrange(1000, 90000) | f09b626bc7c73e7281f762258bc795d25acd7b45 | 49,477 |
def get_state(person):
"""Feed a person dict return the state only"""
return person['state'] | b670382b80ccd5f14d6ff2b6cd98ef28330f3c76 | 49,478 |
def kwargsGet(kwargs, key, replacement):
"""As kwargs.get but uses replacement if the value is None."""
if key not in kwargs:
return replacement
elif key in kwargs and kwargs[key] is None:
return replacement
else:
return kwargs[key] | bcb5da19757f685d6ba5b7669c474e5cbc9a13f0 | 49,479 |
def countDigits(number: int):
"""this function is used for counting digits.
Args:
number (int): any number!
Returns:
int: number of digits of your inputted number.
"""
return len(str(number)) | 46d8772ea74694a011fb7651b0e1e7d82b7b96fa | 49,480 |
def calc_nbases(DNA):
"""This command takes a seq and calculates its nbases."""
DNA = DNA.upper()
for i in DNA:
if i not in 'AGCTN':
return 'Invalid Seq'
return DNA.count('N') | a0ca9c05048734fe1735ff9e6ad5f04e2e68ff49 | 49,481 |
def set_creo_version(client, version):
"""Set the version of Creo you are running.
This function only needs to be called once per creoson session.
This function must be called if you are doing certain functions
in Creo 7 due to deprecated config options.
Needed for functions:
familytable_r... | ddedcbb614f9fd545538804ba306b375f26bb1c8 | 49,483 |
def get_define_item(define_module, name):
"""根据字段名取得定义项"""
for define_item in define_module.define:
if define_item[0] == name:
return define_item
return None | 9d17e139e7a79cb62c4d358d8e4cd5800916a8d6 | 49,484 |
def rank_items(items):
""" Get a rank for each item that is computed by price/weight """
for item in items:
item['rank'] = (item['price'] * 1.0) / (item['weight'] * 1.0) # I use 1.0 to get floats
return items | 2237664c7822afc76ddb6b32923e5fd98630b885 | 49,485 |
from typing import List
from typing import Dict
def get_entities_fields(entity_title: str, entities: List[str]) -> List[Dict]:
"""
Builds an entity from given entity title and entities list
Args:
entity_title (str): Title of the entity.
entities (List[str]): List of the entities.
Retu... | 201702971b3bb58285f3adf10e492a6b83f62d27 | 49,486 |
def ZhangJohnson(tokens, index, history):
"""
These features were taken from Zhang and Johnson (2003). They correspond
to the combination B+D+E+F in their paper.
Feature 'C' was not included, since
CRFsuite cannot handle 2nd order CRFS (which can use the i-1 and (i-2)th
labels) or features of t... | f63f22692a8198bba05091b8fdd62cd22f714159 | 49,488 |
import random
def get_random_colour():
"""
Returns a random colour from the entire colour spectrum
:return
colour: a tuple that represents an RGB value
"""
colour = [0, 0, 0]
for i in range(0, 2):
colour[i] = random.randint(0, 255)
return tuple(colour) | e1c8c6f4e721e141dc2bfd1a854fb8d6f9799091 | 49,489 |
import json
import requests
def download_rail_route(rr_file, verbose=False):
"""
Downloads rail route data from railrouter.sg repo.
Source: https://github.com/cheeaun/railrouter-sg
params
------
rr_file (str): filename in the data directory in the repo
verbose (bool): print downloaded rou... | 93d5d16a5b7ba1afb11fc26c3d8a9df4a301dafa | 49,490 |
import os
import sys
def load_ref(obj_reference, paths=None, base_path=None):
"""Loads an object from a python module.
Parameters
----------
obj_reference: str
Reference to a python symbol, for instance 'pkg.mdl' to
load the python module ``pkg.mdl``, or 'pkg.mdl:symbol... | ef599904af0568b590471d01ba47c207d1cbfdb3 | 49,491 |
def insert_pattern(target_node_names, new_nodes, graph):
"""Replace the specific pattern matched from the new constructed graph with new pattern.
Args:
target_node_names: A string list ccontains the names of nodes that will be replaced
new_nodes: a list contains nodes with Operator class
... | 6ca1e6f92b7ddd2ac837a4112c1c4a8f99bd1c1e | 49,493 |
def same_ratio(img_ratio, monitor_ratio, file):
"""
:param img_ratio: Float
:param monitor_ratio: Float
:param file: Str
:return: Bool
"""
percent = img_ratio / monitor_ratio
diff = int(abs(percent - 1) * 100)
if percent > 1:
print("Image is " + str(diff) + "% too wide for sc... | 7631bac3533ff6a223b82e5fa1c1bfffafddce7f | 49,494 |
def add_to_qs(context, *pairs):
""" Adds item(s) to query string.
Usage:
{% add_to_qs key_1 value_1 key_2 value2 key_n value_n %}
"""
query = context['request']['GET'].copy()
keys = pairs[0:][::2] # 0,2,4, etc. are keys
values = pairs[1:][::2] # 1,3,5, etc. are values
for key, v... | f9d15488c57e435ab552e378479dbd84a3798050 | 49,495 |
import codecs
def data_load(data_file):
"""
:param data_file:
:return: [[sent, label,seq_fea,...,single_fea,...],...]
"""
with codecs.open(data_file, "r", encoding="utf-8") as f:
all_data = []
sent = []
label = []
en_ph=[]
tr_ph=[]
i=0
for li... | 2f82c401e6e8f9b7c941c4b54cfc411da893c4ed | 49,496 |
from typing import OrderedDict
def f_state_dict_wrapper(state_dict, data_parallel=False):
""" a wrapper to take care of state_dict when using DataParallism
f_model_load_wrapper(state_dict, data_parallel):
state_dict: pytorch state_dict
data_parallel: whether DataParallel is used
https://disc... | 45f2a39a6dc4bc92464b8f3d193ddd611e64d05a | 49,497 |
import argparse
def get_input_args():
"""
Retrieves and parses 8 command line arguments provided by the user when
they run the class from a terminal window.
"""
parser = argparse.ArgumentParser ()
#
parser.add_argument ( '--dt_path', type=str, default='ts.csv', help="path to your t... | 9b5f83277f82176128b2144a72be93883e975f48 | 49,498 |
def _unsupported_config(ctx):
"""Checks whether we're building with an unsupported configuration.
See b/128308184 for context.
Args:
ctx: The current rule context
Returns:
An empty string if the current build is supported;
otherwise, a string with the name of the unsupported configu... | 465b42070b3d97d6420f6a1da3c42fa56cc2bfa7 | 49,499 |
import os
def _default_pptx_path():
"""
Return the path to the built-in default .pptx package.
"""
_thisdir = os.path.split(__file__)[0]
return os.path.join(_thisdir, "templates", "default.pptx") | ede3fa6ceb9cf610cea579bcb036e20edeb2299a | 49,500 |
import yaml
def calculator_swagger():
"""
Swagger API documentation for calculator API service
"""
f = open('./static/swagger.yaml', 'r')
response = f.read()
f.close()
return yaml.safe_load(response) | eca9f78ff03776b3aef8add49c619177a2b1bbae | 49,501 |
import re
def valid_uniprot_ac_pattern(uniprot_ac):
"""
Checks whether Uniprot AC is formally correct according to
https://www.uniprot.org/help/accession_numbers
This is no check whether it actually exists.
:param uniprot_ac: Accession code to be checked
"""
ac_pat = "[OPQ][0-9][A-Z0-9... | 8478f998d1b8ff2b7f8343317056a9c2c0b36021 | 49,504 |
import subprocess
def grep_terms(term1, term2, filename):
"""
Get lines from the current file that contain both term1 and term2
"""
return subprocess.Popen(f'grep -E "{term1} ((.*\s)*){term2}" {filename}',
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
... | 854c0db275a4f976705a710787f5fb399acef8e1 | 49,505 |
def compute_mse(theta_0, theta_1, data):
"""
Calcula o erro quadratico medio
:param theta_0: float - intercepto da reta
:param theta_1: float -inclinacao da reta
:param data: np.array - matriz com o conjunto de dados, x na coluna 0 e y na coluna 1
:return: float - o erro quadratico medio
"""... | 3adfdc11394a51674ae0d3956ee092684933ef89 | 49,506 |
def AIC(params, log_likelihood_fun, data):
"""Calculates the AIC (akaike criterion)
Parameters
_________
params : tuple
MLE parameters for distribution
log_likelihood_fun : function
calculates the log likelihood for the desired distribution
data : array
empirical dataset to calcula... | 48f812b68fa44320f83032ec927c4d900ae44620 | 49,507 |
def depthwise_conv2d(attrs, args):
"""Check if the external ACL codegen for depthwise convolution should be used.
Note
----
Relay does not have a depthwise conv2d operator whilst ACL does. We simply
separate the checks for depthwise for clarity.
"""
kernel_typ = args[1].checked_type
# O... | 4bb1424a14deaa29e585bdb6cefdda07d307a54f | 49,508 |
import json
def get_database_access(path=None):
"""
Put a json file at your home directory:
"~/access_information.json"
{
"database_name": {
"host": "database-db.host.net",
"user": "user",
"password": "1234",
"database": "database_name",
... | 2e8171ecdacc01d24c5da953dd8c1d448f68442a | 49,509 |
import threading
def _start_background_task(target, *args, **kwargs):
"""We are monkey patching here to start threads in ``daemon`` mode.
Original docs below:
The patch allows for clean exits out of python.
Start a background task.
This is a utility function that applications can u... | 8f79cdfab5590c87d709ea321cbf09bf1bba7aa8 | 49,514 |
def five_options_around(page):
""" Create five page numbers around current page for discovery pagination. """
if page.number <= 3:
return list(range(1, min(5, page.paginator.num_pages) + 1))
elif page.number >= (page.paginator.num_pages - 2):
return list(range(max((page.paginator.num_pages -... | b65b635df3fe0abd4c5674b5b8c41b47a5630f79 | 49,515 |
import base64
def parse_authorization_header(auth_header):
""" Parse auth header and return (login, password) """
auth_str = auth_header.split(' ')[1] # Remove 'Basic ' part
auth_str = base64.b64decode(auth_str).decode() # Decode from base64
auth_str = auth_str.split(':')
return auth_str[0], aut... | cc2db762ddf7b4ce0669a81f24bce9517785350a | 49,516 |
import math
def calculateATan(diff_x, diff_y):
""" Given the difference of the coordinate, calculate the angle """
diff_x += 0.0
diff_y += 0.0
if diff_x == 0:
if diff_y > 0:
return math.pi / 2
else:
return math.pi * 3 / 2
if diff_y == 0:
if diff_x > 0:
return 0
else:
return math.pi
angle = m... | 95c019a7bc42081ff3e05084b797892fee4c9cd2 | 49,517 |
def calc_kcorrected_properties(frequency, redshift, time):
"""
Perform k-correction
:param frequency: observer frame frequency
:param redshift: source redshift
:param time: observer frame time
:return: k-corrected frequency and source frame time
"""
time = time / (1 + redshift)
frequ... | 3a7c151a6777a0e11022e38e73ded45fc7a6706c | 49,518 |
def shift(coord, offset):
"""
(tuple, tuple) -> tuple
Function shifts coord on defined offset
"""
return (chr(ord(coord[0]) + offset[0]), coord[1] + offset[1]) | b33d379ee5ffb1463046fb7ade3355656adebf30 | 49,519 |
def tokenize_options(options_from_db, option_name, option_value):
"""
This function will tokenize the string stored in database
e.g. database store the value as below
key1=value1, key2=value2, key3=value3, ....
This function will extract key and value from above string
Args:
options_fro... | 88127c5e693064ef0c3c087b18bbf213c8a6184f | 49,521 |
def check_int(num):
"""Check if arguement is integer.
Arg:
num (int): The only arguement.
Returns:
bool: The return value. True if num is indeed an integer, False otherwise.
"""
if num is not None:
try:
int(num)
return True
except ValueError:... | 556bc91dbdece439bd66f7f8fa2182d2f9683c67 | 49,522 |
def find_min_max(shape):
"""Finds min/max coordinates for a given shape and returns a tuple
of the form (minx, maxx, miny, maxy)
shape: list with points"""
minx = miny = 1000
maxx = maxy = -1000
for x, y in shape:
if x < minx:
minx = x
if x > maxx:
maxx = ... | 133bc42b9193a950869a784a5cf74b960e79eda1 | 49,523 |
def all_worddict(wordset, flairs):
"""A list of all the words seperately for all the flairs
Returns:
dict: with key as flair
"""
worddicts = {}
for flair in flairs:
worddicts[flair] = dict.fromkeys(wordset, 0)
return worddicts | f0e9ca6546153d657f6207b08a744431a111d5c8 | 49,524 |
def create_dict(breadcrumbs, value=None):
"""
Created a dict out of the breadcrumbs in a recursive manner.
each entry in the breadcrumb should be a valid dictionary key.
If value is None, the last string within' the breadcrumbs becomes the
final value.
:param breadcrumbs:
:param value:
:... | f2f4d2be32aa96b31703cc548edff3999bd42bd3 | 49,525 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.