content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def ringfilter(motif, bond, pivot1, pivot2):
"""
For a given linear sequence of atoms it tests whether they for a ring, i.e., whether atoms pivot1 and pivot 2 are connected.
"""
if bond[motif[pivot1]][motif[pivot2]] > 0:
return 1
else:
return 0 | 2fea90a0965d8a1504f5b82610a90ab8611287b9 | 18,246 |
import os
def read_data():
"""
Function: read_data\n
Parameters: None\n
Functionality: Read the data and convert it to a meaning ful form\n
"""
parent_dir = os.getcwd()
dir_name = 'analysis_output_files'
file_name = 'scenario_analysis.log'
file_path = os.path.join(parent_dir, dir_n... | b462f0345b0bb0f1f13defaa72772c84c29c2cbf | 18,248 |
def FindNonTrivialOrbit(generators):
"""
Given a generating set <generators> (a Python list containing permutations),
this function returns an element <el> with a nontrivial orbit in the group
generated by <generators>, or <None> if no such element exists.
(Useful for order computation / membership ... | ddd3f92523a0b0f8a7cb08146d4d1014a5adedf1 | 18,249 |
def city_functions(city, country, population=''):
"""Generate a neatly formatted city."""
if population:
return (city.title() + ', ' + country.title() + ' - population ' +
str(population) + '.')
return city.title() + ', ' + country.title() + '.' | 1fde2b9bd910e02c67cf7a5c46c13b88d381ce03 | 18,253 |
def create_pivot_df(df_snp):
"""constructs pivot DataFrame
grouping data by the duplex variant
"""
context_data = df_snp.groupby('ref_duplex').sum()
context_data.drop(['start_pos', 'stop_pos'], inplace=True, axis=1)
return context_data | 691f067155c12a58522d48f83789db2fa4b5d584 | 18,254 |
def key_(arg):
""" get an argument's destiation key """
_, kwargs = arg
return kwargs['dest'] | 51b310edda31a1973b62e4ae3b6a24b1fcd5f35b | 18,255 |
import torch
def smooth_dice_loss(pred: torch.Tensor, target: torch.Tensor,
smooth: float=1., eps: float=1e-6) -> torch.Tensor:
"""
Smoothed dice loss.
:param pred: (torch.Tensor) predictions, logits
:param target: (torch.Tensor) target, logits or binrary
:param smooth: (floa... | 30cda9c2789661d997254e43febb4412ecc76b15 | 18,256 |
import argparse
def parse_args():
"""Use argparse to get command line arguments."""
'''
task: segmentation
gt: path to ground truth
result: path to results to be evaluated
num_classes: dataset classes. #e.g. 19 for cityscapes
ignore_label: label to be ignored when to do evalution. #e.g. 25... | d94a12b76251415a42c7262e2163ce6eaf347aa0 | 18,257 |
def climbing_stairs_three_recur(steps: int) -> int:
"""Staircase by top-down recursion.
Time complexity: O(3^n).
Space complexity: O(n).
"""
if steps < 0:
return 0
if steps == 0:
return 1
return (climbing_stairs_three_recur(steps - 1) +
climbing_stairs_three_r... | 5ecf0ee4a627b22d4aac65e488d62c86ca958ac3 | 18,258 |
def get_seat_id(ticket: str) -> int:
"""Get seat id based on boarding ticket (ie. 'BBFFBBFRLL')"""
rows = range(128)
cols = range(8)
for letter in ticket:
if letter in "FB":
midpoint = len(rows) // 2
rows = rows[:midpoint] if letter == "F" else rows[midpoint:]
e... | 5f901755192c93dc275afa5392c2472db7e60108 | 18,262 |
def _create_object_from_type_and_dict(cls, obj_dict):
"""Creates an object, bypassing the constructor.
Creates an object of type `cls`, whose `__dict__` is updated to contain
`obj_dict`.
Args:
cls: The type of the new object.
obj_dict: A `Mapping` that should be used to initialize the new object's
... | 540c11639f724aeacc745cc7b334abb556783eee | 18,263 |
import copy
def populate_target_env_cfg(target_cfg, target_env):
"""
Read out context from target config then merge it with global magic context
All keys in target config that starts with `_` is considered magic context
and will be merged into each target_env config.
"""
# we need to do deepc... | b252b87faa50a949b3c1a51ed8da5dac8256a2ac | 18,264 |
import re
def valid_email(email):
"""Verifica la validità sintattia di una mail
Args:
email (str): email da validare
Returns:
bool: restituisce True se la mail è valida
"""
EMAIL_REGEX = r"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a... | 8335f4fe0fcdfaaf5d053104c838a039c2555041 | 18,265 |
from typing import Union
from typing import Callable
import importlib
def validate_task(task: Union[str, Callable]) -> str:
"""
Helper function for dealing with task inputs which may either be a callable, or a path to a callable as a string
In case of a string being provided, this function checks whether... | f5938029aea67c711ed3c5363c6682fa4d6389bb | 18,266 |
def SetSingleTrack(center_row, height):
""" This function will set the single track parameters. The parameters are
validated in the following order: centre row and then track height.
Parameters:
int center_row: centre row of track
int height: height of trac... | 9e086cbffa046763200d0ddb4eb21261a9cfe0ee | 18,267 |
def check_msg_size(msg):
"""Check if the commit message is too long.
Parameters
----------
msg : str
Returns
-------
bool
"""
if len(msg) > 72:
print(
"ERROR: Commit message is too long. It should be 72 characters or"
" less."
)
retur... | 4e3a985bcaccf0546d51a1fb67990c100ae9ab6e | 18,268 |
import os
def config(key):
""" reads key-value pairs from a .env file.
"""
return os.environ.get(key) | 3a2e09c656c7caf2ba265023ec08c19e7e2c02e4 | 18,269 |
def get_option_value(option):
"""
An option in a Checkboxes or CheckboxTree question is a dict, but we need to treat their
contents in consistent ways, e.g. when getting the value to be persisted in the API.
:param option: dict from a Question's list of options
:return: string value to be persisted
... | 98e9119c77a1fbc05f8e988bc7cf9a0e3ef9385e | 18,270 |
def bytes2str(data):
"""
Convert bytes to string
>>> bytes2str(b'Pwning')
'Pwning'
>>>
"""
data = "".join(map(chr, data))
return data | cd2e7fd59628c7b4eb8fdc918148f960f1226d6f | 18,271 |
from io import StringIO
def svg(plot, close=True):
"""
Creates SVG code and closes plot.
Args:
plot: matplotlib.pyplot
Plot from which the SVG should be made.
Returns:
str
SVG code.
"""
# make SVG
svg_file = StringIO()
plot.savefig... | 4acdd6f346af2de672e538415795e0e1181ee4e4 | 18,272 |
def docselect(posts, category):
"""
Receives the category of devices and returns the relevant documents
"""
search_filter = {'Ancestors': {"$in": [category]}, "$where": 'this.Toolbox.length>0'}
postsample = posts.find(search_filter, no_cursor_timeout=True)
print('{} document are selected'.format... | dcee4a1fe6223307a16114ca7fe9b3cae58fbe44 | 18,273 |
def mocked_events_ics(source: str = "uqcs") -> bytes:
"""
Returns a locally stored .ics file that
imitates the UQCS Calendar on Google Calendar.
"""
with open("test/test_events_events.ics", "rb") as events_file:
return events_file.read() | 8388d826648c9b274c991453eaf9e3885794e980 | 18,275 |
def extract_elements_from_nested_list(nested_list):
"""Extract elements from nested list."""
new_list = []
# For item in nested list
for item in nested_list:
# Detangle
if type(item) != str:
new_item = extract_elements_from_nested_list(item)
... | 4aa3ea7c6d07b73383f54a26ce073d85db383047 | 18,276 |
import re
def split_psalm(reference):
"""splits pslams when multiple are included together"""
# Example input: 'Ps. 33,108:1-6,7-13'
# Example input: 'Ps. 63:1-8,9-11,Ps. 98'
if len(re.findall(r'Ps\.', reference)) > 1:
psalms = reference.split(',Ps. ')
psalms[0] = re.sub(r'Ps\. ', '', ... | d104e6a4ab718a544ef8d5970959ccb549e72704 | 18,277 |
def remove_upper_channel(lo, hi):
"""
take difference between two channels:
# rule:
lo ) 0 0 1 1
up ) 0 1 0 1
-> 0 0 1 0
"""
lo = lo.astype(bool)
hi = hi.astype(bool)
return (lo ^ (lo & hi).astype(bool)).astype(bool) | b3b6a86af53a6529b873a0aefb642589c58f27bd | 18,278 |
def _dictify(value):
"""
Converts non-dictionary value to a dictionary with a single
empty-string key mapping to the given value. Or returns the value
itself if it's already a dictionary. This is useful to map values to
row's columns.
"""
return value if isinstance(value, dict) else {'': value} | 241ead832384a1459666f70829634aa8f3fdc2ae | 18,279 |
def find_opposite_neighbor(node, element, elements):
"""
This function returns the neighbor of 'element' that doesn't contain the
node 'node'.
NOTE: Valid only for triangular elements.
"""
neighbors = elements[element.neighbors - 1]
for neighbor in neighbors:
if node not in neigh... | 1a38deabf1e9e89ba0e3bab3b88398c0c0d71357 | 18,280 |
import random
def random_row(categories=None):
"""
Make a random row
Returns rows like (category, a, b):
- category is a categorical variable,
- a is a randomly selected cluster value (with two clusters)
- b is a uniform integer on 0, 1
Returns:
(category, a, b) - the r... | dc4db2db758454898a92a7953cb0f186e03a5ba8 | 18,281 |
import re
def _generate_remote_name(remote_url: str) -> str:
"""Generate a kind-of human readable name based on a url."""
filtered = (
re.sub(r"[./\\@:\^]", "-", remote_url).replace("https", "").replace("http", "")
)
return re.sub(r"[-]{2,}", "-", filtered).strip("-") | d3ed64cfbe9ad222b12620254f709cccfe101352 | 18,283 |
def connect_device_success(self, *args, **kwargs):
"""Return `self`, which will result in the ADB connection being interpreted as available."""
return self | 55b8238f4406804609f08318b00ebfe2b4997690 | 18,284 |
import logging
def prepare_data(df):
"""it is used to separate the dependent variables and independent features
Args:
df (pd.DataFrame): its the pandas DataFrame to
Returns:
tuple: it returns the tuples of dependent variables and independent variables
"""
logging.info("Preparing th... | 4891e6d858c1f56a1d9b1dd634668bf92f56015e | 18,286 |
def count_vowels(sentence:str) -> dict:
"""
find vowel count in a sentence
We are not initializing a vowels_count with each vowel set to 0
"""
vowels = ['a', 'e', 'i', 'o', 'u']
vowel_cnt = {}
for char in sentence:
if char in vowels:
vowel_cnt.setdefault(char, 0)
... | 9730910d359564bc2be5721a69b41cb57ca59b27 | 18,287 |
def parseExitStatus(exitStatus):
"""Parse exit status of command line commands"""
# 0 means executed correctly
return not bool(exitStatus) | 460e93275e519848837a9251adf21f8a57ab90de | 18,290 |
import re
def delete_links(string):
"""Delete links from input string
Args:
string (str): string to delete links
Returns:
str: string without links
"""
return re.sub(r'http\S+', '', string) | c452e25f245b7b791800cff8ca31ce75598e06c9 | 18,291 |
def validate_entrypoints(entrypoints):
"""Check that the loaded entrypoints are valid.
Expects a dict of dicts, e.g.::
{'console_scripts': {'flit': 'flit:main'}}
"""
def _is_identifier_attr(s):
return all(n.isidentifier() for n in s.split('.'))
problems = []
for groupname, gr... | 3785b9739a0d6aa281f9d6b448dd0581f3c44e04 | 18,293 |
import six
def prepare_call(parameters):
"""Dispatches messages to a different pipeline.
Sends the message through another pipeline. Any changes to the
message will be visible in the remainder of this pipeline. Note that there
is a hardcoded limit of 10 pipeline changes per message (includes jumps
... | e98620474c39deae79289a85154d1a1d127faf7f | 18,294 |
import random
def random_pick(i_list: list,n)-> list:
"""
Select n numbers from the source list
:param i_list: The source list
:param n: The number of element to pick
:return: The output list
"""
_list_copy = i_list.copy()
_shallow_list = []
assert(n <= len(i_list))
iter_idx = ... | a2d1c7fd986e9d46ce1cdf7831c3bf91ae806295 | 18,296 |
def parse_ffmpeg(input_dir, input_file_name, video_scale_bitrates, video_keyint):
"""parse ffmpeg command"""
ffmpeg_cmd = []
ffmpeg_files = []
# 音频处理
audio_file = input_dir + '\\' + 'video_audio.mp4'
# audio_cmd = 'ffmpeg' + ' ' + '-i ' + input_file_name + ' ' + '-c:a copy -vn' + ' ' + audio_f... | 26158819802a48c608a4b26cb97f88c96507eb04 | 18,297 |
def strip_uri(repo):
"""
Remove the trailing slash from the URI in a repo definition
"""
splits = repo.split()
for idx, val in enumerate(splits):
if any(val.startswith(x) for x in ("http://", "https://", "ftp://")):
splits[idx] = val.rstrip("/")
return " ".join(splits) | 284d100f96c5d6912f75c4b7ae45310a69a6dc6c | 18,298 |
def aoi_status(objects,status):
"""
Returns the status of the aoi
"""
return objects.filter(status=status) | 0fc8542ec8e92e65f58e10e86c8ae5566008245d | 18,301 |
import logging
import sys
def parser_cvs(filename, fields_jsons):
"""esta funcion lista con un diccionario con la configuracion"""
try:
with open(filename, "r") as conf_file:
readfilecsv = conf_file.readlines()
info_load_config = "Cargado archivo: {}"
logging.info(info_loa... | e3c24c04bf731b3351bad5484a85ab2777e3186c | 18,302 |
def one_text_header(response, header_name):
"""
Retrieve one text header from the given HTTP response.
"""
return response.headers.getRawHeaders(header_name)[0].decode("utf-8") | afc4b3bba143a092173a935ede77ff8ecec6d7e3 | 18,303 |
import numpy as np
def vectorised_exceed_ns_icpm(cln_min, cln_max, cls_min, cls_max, dep_n, dep_s):
"""Vectorised version of exceed_ns_icpm(). Calculates exceedances based on
the methodology outlined by Max Posch in the ICP Mapping manual (section
VII.4):
https://www.umweltbundesamt.de/si... | 2c79709ca15e6ade5a66a8135a4446d31afd3ed4 | 18,305 |
from typing import Optional
from typing import Dict
from typing import List
from typing import Tuple
import base64
def as_metadata(
credentials: Optional[Dict[str, str]] = None, requires_leader: Optional[bool] = None
) -> Optional[List[Optional[Tuple[str, str]]]]:
"""Returns a valid grpc "metadata" object."""... | 3377aed0298de597edfb5edb6141024a65c39fc5 | 18,306 |
def node_tuple():
"""
:returns: The tuple that defines a node
:rtype: :class:`tuple_(dict, dict)`
"""
return {}, {} | fe3793124eb4d56fdf7537f403d1c9d11ec5e343 | 18,307 |
def split_string(string: str, indices: list) -> list:
"""Splits string between indices.
Notes:
It is possible to skip characters from the beginning and end of the
string but not from the middle.
Examples:
>>> s = 'abcde'
>>> indices = [1, 2, 4]
>>> split_string(s, i... | 0850c4d0f18b70cbd75790e34580ea0567ddea05 | 18,308 |
import subprocess
def check_vault_connection():
"""docstring for check_vault_connection"""
try:
out = subprocess.check_output(['vault', 'read', '--format', 'json', '/auth/token/lookup-self']) == 0
except subprocess.CalledProcessError as e:
return False
else:
return True | f6f5bf1a2b26bfbb2891693d56ea0d416081db70 | 18,310 |
def preproc(line):
"""
一行の命令を命令名と引数の列に分解する。
引数はカンマ区切りで分割され、前から順番にargsに入る。
d(Rb)の形式のものは、d,Rbの順でargsに入る。
"""
head, tail = "", ""
for i in range(len(line)):
if line[i] == " ":
tail = line[i + 1 :]
break
head += line[i]
cmd = head.upper()
tmp... | bf884ea59599c0c1026310ac364317687349151c | 18,311 |
def attributes(attrs):
"""Returns an attribute list, constructed from the
dictionary attrs.
"""
attrs = attrs or {}
ident = attrs.get("id","")
classes = attrs.get("classes",[])
keyvals = [[x,attrs[x]] for x in attrs if (x != "classes" and x != "id")]
return [ident, classes, keyvals] | 92d48f897bd0a825819dc1b3a8f1ffd18686bd05 | 18,312 |
def fact_iter(n):
"""
1. number of times around loop is n
2. number of operations inside loop is a constant
3. overall just O(n)
>>> fact_iter(5)
120
>>> fact_iter(12)
479001600
>>> fact_iter(10)
3628800
>>> fact_iter(16)
20922789888000
>>> fact_iter(4)
24
""... | 063abee825c8407b276f839543eb6985a90ac653 | 18,316 |
def char_sum(word: str) -> int:
"""Sum letter indices of uppercase word."""
total = 0
for letter in word:
total += ord(letter) - 65
return total | 58ac7b372a8dcbee3beed6b8132295cdc677095c | 18,319 |
def _new_base(dests: str) -> str:
"""
Create New Base State
:param dests: Dests
:return: New Base
"""
bat, run1, run2, run3 = int(dests[:1]), int(dests[1:2]), int(dests[2:3]), int(dests[3:4])
nrunner1, nrunner2, nrunner3 = '0', '0', '0'
if run1 == 1 or bat == 1:
nrunner1 = '1'
... | 047b648b24d3aa20a3e964583d39eea151b99f42 | 18,320 |
def execute(command, document):
"""Call obj as an command recursively while callable."""
while callable(command):
command = command(document)
return command | 46f34e8eb04a21aee303f3b13088d7bc4be1c16e | 18,322 |
def r(a, b, C):
"""
Defines the compatibility coefficients
"""
return C[a, b] | f1f8f109742feabb4119e20b137d7ae30a635db3 | 18,323 |
def _model_field_values(model_instance) -> dict:
"""Return model fields values (with the proper type) as a dictionary."""
return model_instance.schema().dump(model_instance) | aeffb9cfc9304dec5672be6169c0909f2afbb3cb | 18,324 |
import re
def is_in_file(path, search_string):
"""
Determine whether a string is contained in a file.
Like ``grep``.
Parameters
----------
path : str
The path to a file.
search_string : str
The string to be located in the file.
"""
with open(path, 'r') as filep:
... | 9912db6a81551e6b930bbf9b3c11168a34b91fe5 | 18,325 |
def rc_one_hot_encoding(encoded_seq):
"""Reverse complements one hot encoding for one sequence."""
return(encoded_seq[::-1, ::-1]) | 7dbd65c384cdd89dbb76698fe792fa85b0ff4206 | 18,327 |
def safe_get(obj, key, def_val=None):
""" try to return the key'd value from either a class or a dict
(or return the raw value if we were handed a native type)
"""
ret_val = def_val
try:
ret_val = getattr(obj, key)
except:
try:
ret_val = obj[key]
except:
... | 8fd58128801f5338d7ddbc8fbb1b78830b644b4b | 18,329 |
def _genotypes_str(sample_genotypes, genotypes_str_cache):
"""
Returns
- string representations of sample genotypes,
- string representations of various marginal probabilities in form (0??, 1??, ..., ?0?, ...).
"""
n_copies = len(sample_genotypes[0])
sample_cn = sum(sample_genotypes[... | 195ec10ed2690ad114e80f7156fed172095dc6cc | 18,330 |
import uuid
def format_jsonrpc_msg(method, params=None, *, notification=False):
"""
Returns dictionary that contains JSON RPC message.
Parameters
----------
method: str
Method name
params: dict or list, optional
List of args or dictionary of kwargs.
notification: boolean
... | 23797940fb64efd7cc39da6871a377268ace57a7 | 18,331 |
def day2yr(day):
"""day -> yr"""
return day/365 | 4b7cd48f432df6ddf27096624a89f5380982a5f2 | 18,332 |
import os
def generate_indexed_filename(name_format, idx_start=0, folder=""):
"""
Generate an unused indexed filename in `folder`.
The name has `name_format` (using standard Python :func:`format()` rules), with index starting with `idx_start`.
"""
while True:
name=name_format.format(i... | 031a9b889b5cb6cd2c1b8e67a9d70cb65cd39225 | 18,333 |
import gzip
import base64
def decompress(data):
"""
Decodes a Base64 bytes (or string) input and decompresses it using Gzip
:param data: Base64 (bytes) data to be decoded
:return: Decompressed and decoded bytes
"""
if isinstance(data, bytes):
source = data
elif isinstance(data, st... | 30dff2aad4facbece190a2b2719fb96b840fd6ee | 18,334 |
from typing import Dict
def largest_valued_key(dic: Dict[str, set]) -> str:
"""Find the key with the largest value."""
biggest_size = -1
biggest_key = None
for key, value in dic.items():
length = len(value)
if length > biggest_size:
biggest_size = length
biggest... | 2d4312217b93560514fb717251028baaeee7a6fe | 18,335 |
def validate_entangler_map(entangler_map, num_qubits, allow_double_entanglement=False):
"""Validate a user supplied entangler map and converts entries to ints.
Args:
entangler_map (list[list]) : An entangler map, keys are source qubit index (int),
value is array
... | 5c329eadd1aa1775e0df403ad5c0fe728e8b2750 | 18,336 |
def keyName(*args):
"""Sort values in order and separate by hyphen - used as a unique key."""
a = [int(i) for i in [*args]] # make sure all ints
a = [str(i) for i in sorted(a)] # sort ints and then return strings
return '-'.join(a) | 4eea1461cc308e8e4491f9c970ee23473e48c5a7 | 18,339 |
def get_declarative_base(model):
"""
Returns the declarative base for given model class.
:param model: SQLAlchemy declarative model
"""
for parent in model.__bases__:
try:
parent.metadata
return get_declarative_base(parent)
except AttributeError:
... | 35beb1d7a75f30ddf5c4246a0c659c2caac9b10a | 18,340 |
def get_supported_versions():
""" """
return ['RAS500', 'RAS41'] | fe7906fec549f144cb8c9064df91792145a210fb | 18,342 |
def one_quarter_right_rotation_escalators(escalator):
"""
Return the escalator coordinates rotated by 1/4. This assumes the escalator is defined for a 4×4 board.
"""
return ((escalator[0][1], 4 - (escalator[0][0] + 1)), (escalator[1][1], 4 - (escalator[1][0] + 1))) | 22e4dfe3fc63f3cc1e81450b921e5c64c00e841e | 18,343 |
def run_caffe_net_forward(net, names):
"""
:return: The network output is a list of predicted bounding boxes
"""
outs = net.forward(names)
return outs | 4cbe747d2214e1688326b05500558dbb95150d33 | 18,344 |
def _decorate_tree(t, series):
""" Attaches some default values on the tree for plotting.
Parameters
----------
t: skbio.TreeNode
Input tree
series: pd.Series
Input pandas series
"""
for i, n in enumerate(t.postorder()):
n.size = 30
if n.is_root():
... | 2e7a14c19882938a6b6132c8a09764ab641f2be2 | 18,346 |
from functools import reduce
def AddRelativeAndCumulativeDistributions( h ):
"""adds relative and cumulative percents to a histogram.
"""
if len(h) == []: return []
new_histogram = []
total = float(reduce( lambda x,y: x+y, map( lambda x: x[1], h)))
cumul_down = int(total)
cumul_up = 0
... | 81f5868ba7b03fe34d7257850f91065070eaa400 | 18,348 |
import os
def rootname(filename):
"""Return basename root without extensions."""
name = os.path.basename(filename)
root, ext = os.path.splitext(name)
while ext:
root, ext = os.path.splitext(root)
return root | 628908dfe2ff4f64d97c5f87447e599795a2f885 | 18,349 |
def format_response(resp, body):
"""Format an http.client.HTTPResponse for logging."""
s = f'{resp.status} {resp.reason}\n'
s = s + '\n'.join(f'{name}: {value}' for name, value in resp.getheaders())
s = s + '\n\n' + body
return s | 5866723df307a66a710bb105dc31ed9662780d78 | 18,350 |
def public(func):
"""Do not require authentication on given view method."""
msg = "*Does not require authentication*\n"
doc = func.__doc__
prefix = doc[:len(doc) - len(doc.lstrip())]
func.__doc__ = prefix + msg + doc
func.needs_auth = False
return func | bc93d9c250d8a285439904355a7083e62b877b8e | 18,351 |
import struct
def read_entry(f):
""" Read a single entry of trace file f.
"""
kinds={0:'loads', 1:'stores', 2:'atomics'}
mark = f.read(1)
# kernel start mark
if mark == b'\x00':
buf = f.read(2)
size, = struct.unpack('H', buf)
kernelname = f.read(size).decode('utf-8')
... | 195d53ed045fd062dce2c6b4257573731d5acd30 | 18,353 |
def roh_air( dem, tempka):
"""
calculates the Atmospheric Air Density.
This is found in Bastiaanssen (1995).
/* Atmospheric Air Density
* Requires Air Temperature and DEM*/
"""
b = (( tempka - (0.00627 * dem )) / tempka )
result = 349.467 * pow( b , 5.26 ) / tempka
if (result > 1.5):
result = -999.99
elif ... | b837baf3a0123af27a75587aed7552f6d58642ad | 18,354 |
from typing import Tuple
def _should_include(key: str, split_range: Tuple[float, float]) -> bool:
"""
Hashes key to decimal between 0 and 1 and returns whether it falls
within the supplied range.
"""
max_precision_order = 10000
decimal_hash = (hash(key) % max_precision_order) / max_precision_o... | 28cb494f5ca4681d04d3568b0c5e74a1e4d28ee3 | 18,355 |
def extendedEuclideanAlgorimth(a, b):
"""
Compute the coefficients of the bezout's identity.
Bezout's identity: for integer a and b exist integers x and y such that
a * x + b * y = d, where d = gcd(a, b).
Parameters
----------
a: int
One of the numbers used for compute the coef... | 37f5cd45254e358bc0c0c267d2b1d77351d04711 | 18,356 |
import torch
def get_knots(start, end, n_bases=5, spline_order=3):
"""
Arguments:
x; torch.tensor of dim 1
"""
x_range = end - start
start = start - x_range * 0.001
end = end + x_range * 0.001
# mgcv annotation
m = spline_order - 1
nk = n_bases - m # number of interior kno... | 824cac0f71a1790698c14956db074a484417de9a | 18,357 |
def make_vlan_name(parent, vlan_id):
"""
Create a VLAN name.
Parameters
----------
parent : str
The parent interface.
vlan_id :
The vlan id.
Returns
-------
str
The VLAN name.
"""
return '{}.{}'.format(parent, vlan_id) | 52793977737792726066de674d3da854bd3cf129 | 18,358 |
def index_to_coord(index):
"""Returns relative chunk coodinates (x,y,z) given a chunk index.
Args:
index (int): Index of a chunk location.
"""
y = index // 256
z = (index - y * 256) // 16
x = index - y * 256 - z * 16
return x, y, z | 35c3aa7efdd9d820c1e8ca1e269d74a4b7d082ca | 18,359 |
import math
def diagonal(n: int, p: int) -> int:
"""
We want to calculate the sum of the binomial coefficients on a given diagonal.
The sum on diagonal 0 is 8 (we'll write it S(7, 0), 7 is the number of the line
where we start, 0 is the number of the diagonal).
In the same way S(7, 1) is 28, S(7, ... | 2a8545851c407cbee0eb839bc5c8507d52722c33 | 18,360 |
import torch
def orthogonal_random_matrix_(rows, columns, device):
"""Generate a random matrix whose columns are orthogonal to each
other (in groups of size `rows`) and their norms is drawn from the
chi-square distribution with `rows` degrees of freedom
(namely the norm of a `rows`-dimensional vector ... | bfd40861fb78ecebe7cfceeaf5ab32044cf1a8dc | 18,361 |
def parse_pairs(pairs):
"""Parse lines like X=5,Y=56, and returns a dict."""
# ENST00000002501=0.1028238844578573,ENST00000006053=0.16846186988367085,
# the last elem is always ""
data = {x.split("=")[0]: x.split("=")[1] for x in pairs.split(",")[:-1]}
return data | f39c329e74ec0e749754386cbffbea186ba43a3c | 18,363 |
def to_snake_case(camel_str):
"""
From https://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-snake-case
Note that this function doesn't cover all cases in general, but it covers ours.
"""
return ''.join(['_'+c.lower() if c.isupper() else c for c in camel_str]).l... | 43737481fc871051dc816c969d51174f84c29e3d | 18,364 |
def symbol_constructor(loader, node):
"""YAML constructor for Ruby symbols.
This constructor may be registered with '!ruby/sym' tag in order to
support Ruby symbols serialization (you can use
:py:meth:`register_constructors` for that), so it just need return the
string scalar representation of the ... | 5539c9f8043da419eebb35a41744338ccf7c6636 | 18,365 |
def drop_peaks(dataframe,data,cutoff):
"""
Filters out the peaks larger than a cut-off value in a dataseries
Parameters
----------
dataframe : pd.DataFrame
dataframe from which the peaks need to be removed
data : str
the name of the column to use for the removal of peak values
... | d645b8519a7da9d4dff588ccc1bbf50ecc801d34 | 18,366 |
import argparse
def _parser():
"""Take care of all the argparse stuff.
:returns: the args
"""
parser = argparse.ArgumentParser(description='Xml generator for tapas submission')
parser.add_argument("fname", help='Input file name', type=str)
parser.add_argument("-o", "--output_file", help='Outp... | 37c1183fd77235944bd06c5ae5e630d50edccccb | 18,367 |
def decap(df, neck, end_func=None):
"""
Separate the head from the body of a dataframe
"""
if end_func is None:
end_func = lambda h, b: len(b) - 1
head = df.iloc[:neck]
body = df.iloc[neck:]
end = end_func(head, body)
body = body[:end]
return head, body | 06da0736ce37308a2794722ddc502789fd9a0a5e | 18,368 |
import imghdr
def what(pic_filename):
"""
获得图片的真实类型
:param pic_name: 图片文件名
:return:
"""
return imghdr.what(pic_filename) | ab57fb251457abc692c829b7eb34fef7dbeb0ac9 | 18,372 |
import os
def get_branch(default="master"):
"""
Derive the selected branch. We first look to the environment variable
for INPUT_BRANCH, meaning that the user set the branch variable. If
that is unset we parse GITHUB_REF. If both of those are unset,
then we default to default (master).
Returns... | 6f85a83476500ce927b4f580d91d61564606485a | 18,373 |
def get_maximal_alignment(address):
"""
Calculate the maximal alignment of the provided memory location.
"""
alignment = 1
while address % alignment == 0 and alignment < 256:
alignment *= 2
return alignment | efd24a7030b968d9f7630390077b3a0642fd30a2 | 18,374 |
import logging
def create_logger(log_name, log_file):
"""
This function is used to generate logger for the whole program
:param log_name: The name of the logger
:param log_file: The output log file to save logging
:return: logger
"""
logger = logging.getLogger(log_name)
logger.setLevel... | 461cd0f186d129cf011387e0d5dd70689dc1409e | 18,375 |
def intersection(iterableA, iterableB, key=lambda x: x):
"""Return the intersection of two iterables with respect to `key` function.
Used to compare to set of strings case insensitively.
"""
def unify(iterable):
d = {}
for item in iterable:
d.setdefault(key(item), []).append... | 1e38162dc7508e5621618b089d64be8ae4b57669 | 18,378 |
def get_location_from_action_name(action):
"""Return the location from the name of the action"""
if action.startswith('at_'):
location_name = action[len('at_'):]
elif action.startswith('go_to_'):
location_name = action[len('go_to_'):]
elif action.startswith('look_at_'):
location_... | c918630b03c4b233d6b976ebb31fd295a94dee2b | 18,380 |
import torch
def array_to_tensor(array):
""" Converts a numpy.ndarray (N x H x W x C) to a torch.FloatTensor of shape (N x C x H x W)
OR
converts a nump.ndarray (H x W x C) to a torch.FloatTensor of shape (C x H x W)
"""
if array.ndim == 4: # NHWC
tensor = torch.from_numpy(array).... | 8fe8bfcbad60c3b14fa7390af2051ebaf2d44021 | 18,381 |
import itertools
def subsequences(iterable, seq=2):
"""Return subsequences of an iterable
Each element in the generator will be a tuple of `seq` elements that were
ordered in the iterable.
"""
iters = itertools.tee(iterable, seq)
for i, itr in enumerate(iters):
for _ in range(i):
... | da436028d37f74729a2b5c2dfb74716da61efb2d | 18,382 |
def sign(x):
"""
Return 1 if x is positive, -1 if it's negative, and 0 if it's zero.
"""
if x > 0:
return 1
elif x < 0:
return -1
else:
return 0 | 7625903a16419c8914b92c2c1273c34bd646d9d2 | 18,383 |
def copy_metadata(nb_data):
"""Copy metadata of notebook
Args:
nb_data (JSON): a json data load from jupyter notebook
Returns:
dict: metadate copied from nb_data
"""
metadata = dict()
metadata["metadata"] = nb_data["metadata"]
metadata["nbformat"] = nb_data["nbformat"]
... | bfd0c0e53097b4a47150b5a2d7a35fabbcc03098 | 18,387 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.