content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def eligible_parties(zweitstimmen_bundesgebiet, direktmandate):
"""Determine which parties reach the Bundestag in a federal state.
Input:
zweitstimmen_bundesgebiet (DataFrame): votes by party bundesgebiet
direktmandate (DataFrame): By party the number of Direktmandate
Output:
eligible_parties ... | 0ec0c16f0e5fc5d149ff12dbf4baa4d13699986d | 45,452 |
def get_slope(x, y):
"""Calculate slope by taking first and last values."""
return (y[-1]-y[0])/(x[-1]-x[0]) | 92f00bd246e27dae51552dbe546ae108abc17e40 | 45,453 |
def s3_get_bucket_versioning(s3_obj, bucketname, s3_client=None):
"""
Boto3 client based Get Bucket Versioning function
Args:
s3_obj (obj): MCG or OBC object
bucketname (str): Name of the bucket
s3_client: Any s3 client resource
Returns:
dict : GetBucketVersioning respo... | 58017d4a414929d06e4da4c8cac83e6a02ef9975 | 45,454 |
import pathlib
import os
def get_next_name(file_path: str) -> str:
"""
Get next available name to download file.
Parameters
----------
file_path: str
Absolute path of the file for which next available name to
be generated.
Returns
-------
str
Absolute path of ... | d662b86469bbef9c8af3eda8cc14404b98041589 | 45,455 |
def req_file(filename):
"""
We're using a requirements.txt file so that pyup.io can use this for security checks
:param filename:
:return str:
"""
with open(filename) as f:
content = f.readlines()
content = filter(lambda x: not x.startswith("#"), content)
return [x.strip() fo... | ea4b9574b129ebd7aa6e87f3089f9be5da0e0d9c | 45,456 |
def do_full_save(experiment_result):
"""This is a simple check to see if the final OOF ROC-AUC score is above 0.75. If it is, we return True; otherwise, we return
False. As input, your do_full_save functions should expect an Experiment's result dictionary. This is actually the dictionary
that gets saved as ... | a81c0225c910eb88a75b949dc7f1146b3ec4d768 | 45,458 |
from typing import Union
from typing import List
def append_forward_slash_path(
paths: Union[List[str], str]
) -> Union[List[str], str, None]:
"""
Returns the input string(s), in the same format as they were passed in, with a minimum of one forward slash
at the end, given that no forward slash exists ... | e5726067818674457bd5da1b39ba7e47dc91c4d5 | 45,459 |
def MK_BM_calc(item1, item2):
"""
Calculate Informedness (BM), Markedness (MK), and Individual classification success index (ICSI).
:param item1: item1 in expression
:type item1:float
:param item2: item2 in expression
:type item2:float
:return: MK and BM as float
"""
try:
re... | 0a24268c905a03ce904794ae72fbed057ad67c61 | 45,462 |
import copy
def merge_config(base_config, new_config, in_place=False):
"""Recursively merges configurations. """
if base_config is None:
return new_config
if not in_place:
base_config = copy.deepcopy(base_config)
if new_config is None:
return base_config
# Merge a configura... | 9c26679c72559a82c46e99b61b1b5f8395258e9d | 45,463 |
def div_growth_rateGm(curr_earn, cap_emp, dt):
"""
Calculates the growth rate of a dividend using the dividend growth rate
valuation model where dividend is paid yearly.
parameters:
-----------
curr_earn = current earnings
cap_emp = capital employed
dt = current dividend
"""
roi = curr_earn/cap_emp
b = ... | f81bb60fe4c0f903ad308d444c578e1447bbb598 | 45,464 |
import re
def cigarToLen(cigar):
"""
Calculate sequence length from CIGAR string
"""
# Split "cigar" on capital letters
span = re.split('[A-Z]', cigar)
ops = re.split('[0-9]+', cigar)
len = 0
del(span[-1])
del(ops[0])
for i, span in enumerate(span):
if ops[i] in ["M", "... | fa7c2b0633a349cc3295519bffcff9965c6ae704 | 45,466 |
import torch
def mask_out(tensor, start_ind, end_ind, value, dim=1):
""" Set the elements before start_ind and after end_ind (both inclusive) to the value. """
if dim != 1:
raise NotImplementedError
batch_size, time = list(tensor.shape)[:2]
# (oleg) This creates the indices every time, bu... | 1326220320679c32d728ce727d174e00065eaa0a | 45,467 |
import os
import json
def _read_to_json(file: str) -> dict:
"""
read json file to json data
"""
file_path = os.path.join(os.getcwd(), file)
print(file_path)
if not os.path.exists(file_path):
raise FileNotFoundError(f'file <{file}> not found')
with open(file_path, 'r+', encoding='ut... | 538d1d6a4eecf3bc9cf3ba6fbf28c16584a600d4 | 45,469 |
def getFileType(fileName):
"""
Helper fucntion to get the file type of the given file name
"""
# +1 for the index to ignore the dot "."
fileExtension = fileName[fileName.rindex(".")+1:].lower()
if fileExtension in ["mp4", "mov", "avi"]:
return "video"
elif fileExtension in ["jpg", "p... | 87976cfeca7d5b70ab44b59830dabe37abc4ba52 | 45,470 |
def interaction_strength(idx: int, mol_map: dict, acceptor_exp: float) -> float:
"""Calculate interaction strength for atom with index `idx`."""
acceptor_strength = mol_map[idx]["sa"]
num_lp = mol_map[idx]["num_lp"]
if num_lp != 0:
return acceptor_strength * (num_lp ** acceptor_exp)
return 0... | 382b69e56002a24691fdc9e8b6943eeeeee7293a | 45,471 |
import math
def project_z(r, x, y):
"""Project an x,y pair onto a sphere of radius r OR a hyperbolic sheet
if we are away from the center of the sphere.
"""
d = math.sqrt(x*x + y*y)
if (d < r * 0.70710678118654752440): # Inside sphere
z = math.sqrt(r*r - d*d)
else: ... | 07c284fe3f26655a940b0f4438cd1f328eb3db57 | 45,474 |
import re
def parse_auth_header(data: str):
""" Parse an auth header (without a prefix scheme)
"""
val = {}
while True:
m = re.match(r'([^\s,"=]*)\s*=\s*([^\s,"]+|"[^"\\]*(?:\\.[^"\\]*)*")\s*', data)
if not m:
break
val[m.group(1)] = m.group(2).replace('"', '')
... | 27e6590554ee1321146d81d9da0ee55cf8329f1c | 45,475 |
import torch
def rmv(A, b):
"""Tensorized matrix vector multiplication of rightmost dimensions."""
return torch.matmul(A, b.unsqueeze(-1)).squeeze(-1) | 965a29255afd1cf9b102b49ab1b24cd4b3cbfd98 | 45,476 |
from json import JSONDecodeError, loads
from typing import Any
def decode_attrs(attrs: Any) -> Any:
"""Try to decode attributes as json if possible,
otherwise return the attrs as they are
Parameters
----------
attrs: Any
an object containing attributes
Returns
----------
Any
... | e49f344769b75f3d37a0ce86d84ac55f681f8156 | 45,477 |
def calculate_score(hazard_list, dictionary):
"""This function will take the hazard codes from a list and grab the respectvie hazard scores from a dictionary """
score_list = []
for code in hazard_list:
# some of the codes end with a colon from extarcting from jsons. Remove them here if present.
... | e0fe7d995ca263f47624929c84f1a87a506257ed | 45,478 |
def get_all_ips(instance, network_client):
""" Returns the private and public ip addresses of an Azure instances
"""
output = []
for interface in instance.network_profile.network_interfaces:
if_name=" ".join(interface.id.split('/')[-1:])
rg="".join(interface.id.split('/')[4])
tr... | 80b5880586bae4d4238d5b194a74e235cd07a14e | 45,479 |
def verify(self, case='', level='', **kwargs):
"""Enter the verification run mode.
.. note::
This command is only valid at the ``/BEGIN`` level, obtained
with ``mapdl.finish()``.
Parameters
----------
case : str, optional
Optional title of the verification manual file. Also ... | 0b25f240a6bc3bb551613727c32524ebc663f5ee | 45,480 |
def checksum(input):
"""
Consider each pair: 11, 00, 10, 11, 01, 00.
These are same, same, different, same, different, same, producing 110101.
The resulting string has length 6, which is even, so we repeat the process.
The pairs are 11 (same), 01 (different), 01 (different).
This produces the ch... | 4b22e3cac0434cd399d4f1bcfec82fff1c059b43 | 45,481 |
def get_expected_first_bin(begin, freq):
"""Get the first bin of a given frequency based on the begin ts
of a timeseries query."""
# Determine the first bin in the series based on the begin
# timestamp in the timeseries request.
#
# Bin count math will round down to last bin but timerange querie... | 2bdf681bcb83fb90036748a86fbd1cc2e84b9941 | 45,482 |
import os
def get_test_category(test_file):
"""Get a category for the specified test using its path and name.
Args:
test_file (str): the test python file
Returns:
str: concatenation of the test path and base filename joined by dashes
"""
file_parts = os.path.split(test_file)
... | efe9bde27faf791fcb658cc8b58724ecf4addb53 | 45,485 |
import argparse
import re
def contains_any_copyright(comments: list, args: argparse.Namespace) -> bool:
"""
Return True if any comment contain the word "copyright"
"""
return any(
comment.line_number() <= args.max_lines
and re.search(r'copyright', comment.text(), re.IGNORECASE)
... | 954235764556414587cc544d481d022931f00e69 | 45,486 |
import unicodedata
import re
def _key_from_url(url: str) -> str:
"""
Convert a URL str to one valid for use as a file name or dict key. URL Protocols are
removed entirely. The returned string will have characters in the set [a-zA-Z.-_].
Parameters
----------
url : str
A URL string
... | 3e9f85fe38e68966f00f8d2a1fb0b3752d9efb75 | 45,487 |
def mix_wave(src, dst):
"""Mix two wave body into one."""
if len(src) > len(dst):
# output should be longer
dst, src = src, dst
for i, sv in enumerate(src):
dv = dst[i]
if sv < 128 and dv < 128:
dst[i] = int(sv * dv / 128)
else:
dst[i] = int(2... | 174dabee1122e6a207fa5e72c5634c85b03a6378 | 45,488 |
def calculate_slasher_snapshot_difference(client, snapshot_old, snapshot_new):
"""
Calculates the difference between two slasher snapshots
Parameters
----------
client : ``Client``
The respective client.
snapshot_old : `None` or `tuple` of (`dict` of (`int`, `list` of `tuple` \
... | 8e16f3943bcf7651496a7e6e6a2c2e7f59c6fb37 | 45,490 |
import argparse
def parse_args() -> str:
"""Returns Memwatch log filename."""
# LOCAL VARIABLES
parser = argparse.ArgumentParser() # Parser
args = None # Arguments
log_name = '' # Memwatch log filename
# DO IT
parser.add_argument('-l', '--log... | 7c5c6d695626fa5c1607b3c38f6626b12754afe9 | 45,491 |
def render_item(type_, obj, autogen_context):
"""Apply custom rendering for selected items."""
autogen_context.imports.add("import sqlalchemy_utils")
return False | 757448cfda4cee9d144d071686ef47b95b6fdc32 | 45,492 |
def generate_link(resources):
"""
Generates a link in the CoRE Link Format (RFC6690).
:param resources: Array of resources that should translated into links.
Resources are dict, containing a path property and a parameters property.
Path is a string and parameters ... | add8c2a96e1a575b0f51a145761f4bae639f7dae | 45,493 |
def _is_paired(fastq, fastq2, single_end):
"""Determines the workflow based on file inputs.
Args:
"""
if fastq and fastq2:
paired_end = True
interleaved = False
elif single_end:
paired_end = False
interleaved = False
else:
paired_end = True
inter... | 44526810e9c41294f4529baa846eced362b1a2f8 | 45,494 |
import re
def multi_delimiter_split(string, delimiters='', split_whitespace=True,
remove_whitespace=True):
"""
多个分隔符分割字符串,
delimiters = ';,'
split_whitespace 是否加上按照空白分割 默认是按照空白分割
remove_whitespace 是否移除分隔符两边多余的空白字符 默认移除
"""
expr_one = '\s' if split_whitespace ... | 6178b25b03e3200af70efff5da74c8f45bb58b87 | 45,495 |
import numpy
from operator import add
def getMSE(dtModel, data):
"""
Return mean squared error (MSE) of DecisionTreeModel on the given
RDD[LabeledPoint].
"""
seqOp = (lambda acc, x: acc + numpy.square(x[0] - x[1]))
predictions = dtModel.predict(data.map(lambda x: x.features))
truth = data.... | 3f10c24f640cbf4321edfba3ee6b351e74775874 | 45,496 |
def my_range (start, stop, step, include_start = True, include_end = True):
"""
Generate a range of number but allows to force the inclusion of the start and the end
the Cowells but it takes more time to be calculated.
Even if the step is too big, the start and end can be forced
Args:
start... | f99107c488d58bb1d3c964bef496be9edf784bc0 | 45,498 |
import re
import sys
def check_system_build(config, download_os):
"""Check system build and return release data."""
if 'system_build' not in config.keys():
release = download_os['releases'][0]
print(f"Using first available {download_os['name']} build: {release['label']}")
return releas... | 92396f8117478f22d6682552d33d7129ce68abeb | 45,500 |
from typing import Tuple
def summarize_location(location: Tuple[str, str, str, str, str, str]) -> Tuple[str, str, str]:
""" Get manuscript location and summarize for usage in citavi
Args:
location (tuple): metadata of manuscript's location
Returns:
tuple: summary of metadata of manuscrip... | fa6ed40a4ddc4510ea919773d9b68458c5edc738 | 45,501 |
def sumIntegerSeries(start = 1, stop = 100, difference = 1):
"""
This formula is taken from pg 78/79 of "The Art of the Infinite" by Robert and
Ellen Kaplan. It's based on an ancient trick for summing a series of numbers
without having to go through all the middle-work
For example if start = 1, stop... | 635c6e1a9a327d8e4a84482e23d6f48cbe52c872 | 45,502 |
def ldd_to_ddl(ldd):
"""Args:
list of dicts of dicts
Returns:
dict of dicts of lists
"""
return {
placer_name: {
metric_name: [mval[placer_name][metric_name] for mval in ldd]
for metric_name in ldd[0][placer_name]
}
... | 44dae6ade09b50e057c20ccfcc4e4136253f91fc | 45,503 |
def join_audio(audio1, audio2):
"""
>>> join_audio([1, 4], [2, 5, 3, 6])
[1, 4, 2, 5, 3, 6]
"""
return audio1 + audio2 | 86146ac415bba96b57dbea7a1fb69f1ecbc12253 | 45,504 |
def route_format(t_route_dest):
"""Shorten destinations to save space."""
# add more route name formatting to your choice to save dsiplay space
# If there's a substitution in the dictionary, use it, otherwise return the original
return {"TO GRANVILLE": "GRANVILLE", "COMM'L-BDWAY STN": "COM-BW STN"}.get... | 17af8f25dc17c82292a23255676d4584bf44b89e | 45,506 |
def reduce_commutators(element, commutators):
"""
>>> reduce_commutators((0, 1), {(0, 1): [(2, 1)], (0, 2): [], (1, 2): [] })
((2, 1, 0), True)
>>> reduce_commutators((1, 0, 1), {(0, 1): [(2, 1)], (0, 2): [], (1, 2): [] })
((2, 1, 1, 0), True)
>>> reduce_commutators((1, 2, 1,... | b60ddf0bfa8ce2fb8de165d423b839f880f7ec71 | 45,508 |
import pickle
def load_pkl(file):
"""Loads data from pickle
Parameters
----------
file : str
Returns
-------
data
"""
f = open(file, 'rb')
data = pickle.load(f)
f.close()
return data | ff7a9cefa4231c9dee6030b8fd14b72e55a11548 | 45,510 |
def get_rce_bpd(rce):
"""
Gets the BPD pointed-to by the given RemoteCustomEvent
"""
string_build = []
# This is actually a bit weird 'cause the output of these vars uses
# bracket-based indexes, as if they were top-level vars, but they're
# not. So we're doing some special processing on 'e... | 924290ffedd98bbaea2926a23b04124fad8027e8 | 45,511 |
def encode_pos(i, j):
"""Encodes a pair (i, j) as a scalar position on the board."""
return 3 * i + j | 583d2e8370edc5801760f1c59c0c3aadad61876f | 45,512 |
def division(a, b):
"""Функция деления"""
try:
return a / b
except ZeroDivisionError as err:
message = f'Получили ошибку деления на ноль: {err}'
raise ZeroDivisionError(message) | cf8e3e9b18a02e2524772f261abafc18040a046f | 45,513 |
import random
def key_gen(key_size, max_flips_per_node, num_high_and_med):
"""
num_high_and_med: the total number of high- and medium-degree vertices
returns a lexicographically sorted list of 2-tuples,
with the indices in the tuples in increasing order
"""
assert (max_flips_per_node == 1 and ... | d81ac36b2658d2cfdd9e0da3ab39e97d60a3503f | 45,514 |
import jinja2
import os
def generate_content(input_dict):
"""
Use jinja2 template to generate connector content
"""
env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
trim_blocks=True)
config_template = env.get_template('connector.templ... | 8f37880b583785183de7be05c6019a1b7e346c0f | 45,515 |
import json
def save(model, prefix):
"""save model for future inspection and continuous training
"""
model_file = prefix + ".json"
weight_file = prefix + ".h5"
json.dump(model.to_json(), open(model_file, "w"))
model.save_weights(weight_file)
print("Model saved.")
return model | fd7d3be1f6b8760ae943bead50697ce3e3a330f7 | 45,516 |
def peek(env):
"""Peak at the env's board"""
x, y, board, moves = env.reset()
env.close()
m, n = board.shape
return m, n, board, moves | 90507357bf05bd5c0ed8c4eeb99033937b0de460 | 45,517 |
def switch(*pairs):
"""Helper function for cond-logic in a Python lambda expression.
Part of a poor-man's functional programming suite used to define several pfainspector commands as one-liners.
:type pairs: callables
:param pairs: sequence of predicate1, consequent1, predicate2, consequent2, ..., alt... | 1ff3c23e22e316a0959a46da8dda6bfdbe274e86 | 45,518 |
import os
from pathlib import Path
def create_numbered_dirs(parent_dir: str, start: int, end: int):
"""
Creates folders from start to end (both inclusive) at the specified parent directory (absolute path).
If a directory to add already exists, it skips adding it and moves on to the next directory to add
... | 7f50201f8bad89f50e19b4ff349fb314739cda39 | 45,520 |
import os
import tempfile
def build_path(selected,selected_dir,default_dir,outdir):
"""
selected should be True or False
If selected==False (or None), return False
If selected is True:
if selected_dir is set:
return it directly if it is an absolute path, or append it to outdir if i... | 1f16d17ee6808c19a68a007b78ed9851d9fb6539 | 45,522 |
def pct_to_value(data, d_pct):
"""
Function takes dictionary with base value, and dictionary with percentage and converts percentage to value.
"""
if not data or not d_pct:
return data
out_map = {}
for _k in data:
if _k not in d_pct:
continue
out_map[_k] = ... | 3c5b1f75f484b1f767bc3acf6cce5bac4b136608 | 45,523 |
def arr_to_d(dic,arr,K):
"""
Append values to a dictionary.
"""
ln=len(K)
for j in range(ln):
key=K[j]
dic[key]=arr[j]
return dic | 720d4a77aa73358309b24e989c911391dc058093 | 45,526 |
def concat_string(target, msg=[], delimiter="", last=""):
"""
Concatenate a series of strings to the end of the target
Delimiter is optional filler between items
:param target:
:param msg:
:return: target
"""
result = target
for m in msg[:-1]:
result = result + m + delimite... | 00a175d167a82427244ab805269b32677676d292 | 45,527 |
def parse_commenttree(commentlist, comment):
"""获得当前评论子评论的列表
用法: {% parse_commenttree article_comments comment as childcomments %}
"""
datas = []
def parse(c):
childs = commentlist.filter(parent_comment=c, is_enable=True)
for child in childs:
datas.append(child)
... | b935f6ac3643637d314e566192a91fcdcf7e3d8a | 45,528 |
def search_trie(trie, token, token_i=0):
"""
Search the given character-trie for paths that match the `token` string.
"""
if "*" in trie:
return trie["*"]
if "$" in trie and token_i == len(token):
return trie["$"]
if token_i < len(token):
char = token[token_i]
if ... | 46da1627299c2318f8adad59515c8d5fad4e821d | 45,530 |
def is_image_file(s):
"""Checks to see if the string starts with 'img:'"""
return s.startswith('img:') | 68081021527dbff9d2da7235c9bf454d54a7fd68 | 45,531 |
def regexGetGroups(matches, groupsMapping: dict):
"""
:param matches:
:param groupsMapping: {groupNumber: groupName}
:return:
"""
"""
Match 2
Full match | | @var2 .hword 0xABCD:10
Group 1. | | @var2
Group 2. | label | @var2
Group 3. | | .hwor... | 83416c5a14fb75623ac35032a6266ac688091c06 | 45,532 |
def _node_matches(parse_tag, ppdb_tag):
"""
Match tags between Stanford parse and PPDB
"""
# print "Match? \t", parse_tag, ppdb_tag
if parse_tag=="ST" and ppdb_tag.startswith('S'): return True # don't worry about final full stop
if parse_tag.startswith(ppdb_tag): return True # mainly verbs: igno... | 770e1bd5c1ed899016055e6b15d68d6960d8a803 | 45,533 |
def pureDependency(dependency:str) -> str:
"""
Get the name of package
Parameters
----------
dependency : str
package
Returns
-------
str
a name of package without the version
>>> pureDependency('package==1.2.3')
'package'
"""
dependency = dependency.... | 1891c0291b84e10ff35369c0cc740eaa6ab9d4ff | 45,534 |
def multiply_numbers(num1, numb2):
""" Multiplies the numbers"""
return num1 * numb2 | 041afaa677d6cc827abff9440101a13e2e987304 | 45,536 |
from pathlib import Path
import sys
def GetScriptDir():
"""
Get the directory where the PinPlay Python scripts are located.
@return script directory
"""
return f'{Path(sys.argv[0]).parent.resolve(strict=True)}' | a35ef1b656daf5d753f3ce75b5ed01b4f4bd2610 | 45,538 |
import torch
def get_random_tensor(size, dtype, use_cuda):
"""Returns a random tensor of given type and size
Args:
size (int): Tensor size (number of elements)
dtype (:obj:`torch.dtype`): One of `torch.float16` and `torch.flaot32`
use_cuda (bool): Return CUDA tensor
Returns:
... | da17a8e33b9ccf9a5bf9bcc86104a1577a8f38a9 | 45,540 |
import os
import re
def get_special_paths(dirname):
"""Given a dirname, returns a list of all its special files."""
dirs_list = os.listdir(dirname)
special_list = []
for item in dirs_list:
is_special = re.search(r'_{2}\w+_{2}', item)
if is_special:
special_item_path = os.pa... | 9f5fb35da24ed895662b235249b2df36c7d68b80 | 45,541 |
import torch
def sub2ind(shape, rows, cols):
"""
A PyTorch implementation of MATLAB's "sub2ind" function
Parameters
----------
shape : torch.Size | list | tuple
shape of the 2D matrix
rows : torch.Tensor
(n,) row subscripts
cols : torch.Tensor
(n,) column subscript... | 8b89b58824b1c80327082afb74b4486816345d62 | 45,542 |
def get_variable_config(var_config, var):
"""
Retrieve configuration info for variable var as defined in main
configuration file,
"""
vdict = {
'var names': var_config['var names'],
'input resolution': var_config['freq'],
'units': var_config['units'],
'scale factor': ... | c7a2a7136584402460fc97f34f3c37f21475ab98 | 45,543 |
def parsiraj_strelice_BKG(strelice):
"""Čitanje gramatike zapisane u standardnom obliku pomoću strelica.
Svaki red je oblika varijabla -> ds1 | ds2 | ... (moguće desne strane).
ε se može i ne mora pisati. Prvi red s lijeve strane ima početnu varijablu.
Znakovi u svakoj desnoj strani moraju biti razdvoje... | 593462a0d55419465a05f1cc98f4bb4f5005e043 | 45,545 |
import numpy
def update_hull(hull,newx,newhx,newhpx,domain,isDomainFinite):
"""update_hull: update the hull with a new function evaluation
Input:
hull - the current hull (see setup_hull for a definition)
newx - a new abcissa
newhx - h(newx)
newhpx ... | 5c40150731ead1abe0e551cc4c924ec61bcb689b | 45,546 |
def check_overlap(bbox1, bbox2):
"""
Checks if 2 boxes are overlapping. Also works for 2D tuples.
Args:
bbox1: [x1, y1, x2, y2] or [z1, z2]
bbox2: [x1, y1, x2, y2] or [z1, z2]
Returns:
bool
"""
if bbox1[0] > bbox2[2] or bbox2[0] > bbox1[2]:
return False
if l... | 2f39989661d421327b4a82da6e9b2fa4ae550575 | 45,547 |
def _parse_force_block(lines):
"""
Parse the block of total forces from the OUTCAR file
:param lines: A list of lines containing lines including the TOTAL-FORCE block
:returns: A tuple of position and forces
"""
forces = []
positions = []
istart = len(lines)
for idx, line in enumer... | 37d9e488097749d4617364e23b296acee1d9bca5 | 45,548 |
def use_atomics(loopy_opts):
"""
Convenience method to detect whether atomic should be for double precision
floating point operations.
Useful in that we need to apply atomic modifiers to some instructions,
but _not_ the sequential specializer
Parameters
----------
loopy_opts: :class:`l... | 6121904e2b5c4d5fb227b1102e0434e73105b64a | 45,550 |
import ast
def filter_block(node_list):
"""
Remove no-op code (``pass``), or any code after
an unconditional jump (``return``, ``break``, ``continue``, ``raise``).
"""
if len(node_list) == 1:
return node_list
new_list = []
for node in node_list:
if type(node) == ast.Pass:
... | b88d3e4966e162d3e23e56e622ff47c63165b7e6 | 45,551 |
def getownattr(cls, attrib_name):
"""
Return the value of `cls.<attrib_name>` if it is defined in the class (and not inherited).
If the attribute is not present or is inherited, an `AttributeError` is raised.
>>> class A(object):
... a = 1
>>>
>>> class B(A):
... pass
>>>
... | b59acbba4f75492fe52562443b7ca679691e7e10 | 45,552 |
def _raw_to_int(raw_data):
"""Converting list of raw hex values as strings to integers."""
return [int(x, 16) for x in raw_data] | e8ae4784e142bcfa3ba8d7b013871986a1b5173a | 45,553 |
from pathlib import Path
import json
def load_json(filepath: Path) -> dict:
"""load json file and return dict.
Args:
filepath (Path): filepath to json file.
Returns:
dict: dict loaded from json file.
"""
with open(filepath, "r") as f:
obj = json.load(f)
return obj | 5cc66b27a6335e29a540b98b3f29ed79cbbb7777 | 45,555 |
def bdev_rbd_register_cluster(client, name, user=None, config_param=None, config_file=None, key_file=None):
"""Create a Rados Cluster object of the Ceph RBD backend.
Args:
name: name of Rados Cluster
user: Ceph user name (optional)
config_param: map of config keys to values (optional)
... | 82c43cb070298bd983c9bf74cccfff6ddfeddd31 | 45,557 |
import torch
def str_dtype_to_torch_dtype(dtype: str) -> torch.dtype:
"""Converts a string representation of a dtype to the corresponding
PyTorch dtype."""
if dtype == "int32":
return torch.int32
elif dtype == "int64":
return torch.int64
elif dtype == "float32":
return torc... | ddf64bb7fba63ff0395e08a199fa431cd8750972 | 45,558 |
def SAMflags(x):
"""
Explains a SAM flag.
:param x: flag
:returns: complete SAM flag explanaition
"""
flags=[]
if x & 1:
l="1: Read paired"
else:
l="0: Read unpaired"
flags.append(l)
if x & 2 :
l="1: Read mapped in proper pair"
else:
l="0: ... | e3d2c1942eac66acd4735cd4590a1905351cbc24 | 45,559 |
def bytes_xor(byte_seq1, byte_seq2):
"""
(bytes, bytes) -> (bytes)
Do bit level XOR or two byte arrays.
:param byte_seq1: byte sequence (bytes).
:param byte_seq2: byte sequence (bytes).
:return: XOR of the byte bytes sequences (bytes).
"""
assert len(byte_seq1) == len(byte_seq2), "Bytes... | 539ca3707c6c07fbd64691a4b317d0d6eb8acef4 | 45,561 |
import csv
def get_dataset(inputfile):
"""return """
handle = csv.DictReader(open(inputfile, "r"), delimiter=";")
return handle | 64fc0a706e4576fb67ed3c070478ec30fdfe59b8 | 45,562 |
import os
def normpath(d):
"""Normalize absolute path."""
return os.path.abspath(os.path.normpath(d)) | ed8abb4f14ac6974dcf68f7ec4de8f26f2e74ea4 | 45,563 |
def abbreviation(lng):
"""lng (str): Language name."""
if lng == 'Türkçe':
return 'tr'
else:
return lng[:2].lower() | 106b5deb6db691a2cb8c5cb63046e3b5acde3dfb | 45,565 |
def dBm2W(W):
"""Converts an arbitrary power `W` in dBm to W."""
return 10 ** ((W - 3) / 10) | 278f43aac26f5e38ef9ab4e73acb6496dedcb0f7 | 45,566 |
import torch
def distortion_to_3d_conversion(x, y, distortion_func, params):
"""
Models image distortion as a warps image manifold
"""
dx, dy = distortion_func(x, y, params)
return x + dx, y + dy, torch.zeros_like(x) | 68a6fb7c9f849b44a280521e0f83f4f54eb8cfa1 | 45,567 |
import os
import re
import platform
def normalize(exception):
"""Normalize exception output for reproducible test cases"""
if os.name:
exception = re.sub(
r'File[^"]+"[^"]+\.py[^"]*"', lambda m: m.group().replace("\\", "/"), exception
)
exception = re.sub(r"(\r\n|\r|\n)", "... | 78244ebd2dd29d50df00f0dbc7449d47cef57771 | 45,568 |
def buildTADkey(gwas_snp):
"""
gwas_snp - a single row subset of the TAD-GWAS input file
output - The lookup info in the TAD gene dictionary
i.e. [(Chromosome, TAD_ID:TAD_Start-TAD_End)
"""
chrom = gwas_snp['chrom'].replace('chr', '')
start = int(gwas_snp['TADStart'])
end = int(gwas_... | 9226406335dcbf5e54fef8de57c6ec1c6b150528 | 45,569 |
import json
def json_of_response(res):
"""Decode json from response"""
return json.loads(res.data.decode('utf8')) | 8c53a8a283994cf8b16e9d759d6fcdaa35731b04 | 45,570 |
def get_frame(epoch, step_size, frame_number):
"""
Crop an epoch based on a frame number
Args:
epoch: mne.epochs.Epochs
Epoch to crop
steps_size: int
Number of time frames per step
frame_number: int
Current frame number
Returns:
mne.e... | 23c3b730eaf4ac369ff91e2a16f92fc18f4209a5 | 45,571 |
def get_tokens(text_element):
"""Get the tokens annotated by NewsReader pipeline
@param naf_tagged_doc: NAF annotated document generated by NewsReader pipeline
"""
tokens = []
tokens_to_offset = {}
naf_tokens = []
for e in text_element:
naf_tokens.append(e)
for naf_token in... | b54f8b633ba150dd90803c8a66a1c15ecd628872 | 45,572 |
def full_request_url(base, text, wildcards={}):
"""
Build a full request URL from the API URL and endpoint.
Any URL parameters will be replaced with the value set in the environment variables.
"""
for key in wildcards.keys():
text = text.replace(key, str(wildcards[key]))
return str(base)... | 217d921666a0cfa9ddd3fad09469085425398182 | 45,573 |
def collides_with_existing_words(word, line, column, direction, grid):
""" Returns whether the given word collides with an existing one.
"""
for k, letter in enumerate(list(word)):
if direction == "E":
# Collisions
if grid[line][column+k] != 0 and grid[line][column+k] != lett... | 0e8863f725e29b81d9123f29be343cc55f339840 | 45,574 |
import requests
def getGitHub(user: str, repo: str, request="content", path="", branch="master"):
"""
Obtain metadata from GitHub.
Parameters
----------
user : str
repo : str
request : str, optional
Choose from "content", "date", "version". Default is "content".
path : str, op... | 1c278bd86bd30d9188ba95174ae3961fd8cd1aac | 45,575 |
def process_data(batch_size, max_seq_len, tokenizer):
"""process input cloze sentences"""
input_text = ["What a _ day !", "Effective transformer is _ fast !"]
# tokenize
raw_tokens = [['[CLS]'] + tokenizer.tokenize(text) + ['[SEP]'] for text in input_text]
# mask blanks to fill
to_predict = [[... | 064817163f2c4d764d5aa3f8fd093082e68409f3 | 45,578 |
import hmac
import hashlib
def HMAC_MD5(key, data):
"""
@summary: classic HMAC algorithm with MD5 sum
@param key: {str} key
@param data: {str} data
"""
return hmac.new(key, data, hashlib.md5).digest() | 601595073554175e21caac49dc160357ac976e8e | 45,579 |
def _verify_classifiers(classifiers, valid_classifiers):
"""Check classifiers against a set of known classifiers"""
invalid = classifiers - valid_classifiers
return ["Unrecognised classifier: {!r}".format(c)
for c in sorted(invalid)] | 64259f25b769361ddafcb83e63845de0d052c88c | 45,580 |
def extract_csv_row(filename: str, row: int) -> str:
"""Extracts a selected line from the csv file.
Args:
filename:
A path to the file.
row:
The row number to extract.
Returns:
The row from the csv file as a string.
"""
with open(filename, 'r') as fi... | 19f72a462e676675c192f3611d3bb46a8aecc887 | 45,582 |
def remove_empty_buckets(json_data):
"""Removes empty buckets in place"""
if 'bucket' not in json_data:
return json_data
idxs_to_remove = []
for i, bucket in enumerate(json_data.get('bucket')):
dataset = bucket['dataset']
if len(dataset) == 1 and dataset[0]['point'] == []:
... | 2f1ac471a616da2ba0376ff0cffc2196228d084b | 45,583 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.