content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def parseRegionSetName(regionSetName):
""" Get region and setName from regionSetName """
if '.' in regionSetName: region,setName = regionSetName.split('.')
else: region,setName = 'Assembly',regionSetName
return region,setName | ebda9b44833e42127c7bec1169b9660137c8daa3 | 697,333 |
def flatten_object(obj, result=None):
"""
Convert a JSON object to a flatten dictionary.
example: { "db": { "user": "bar" }} becomes {"db.user": "bar" }
"""
if not result:
result = {}
def _flatten(key_obj, name=''):
if isinstance(key_obj, dict):
for item in key_obj:... | 3a86a9c3ed1ad4add6027207a074ba0c0ed1b3c8 | 697,334 |
def check_view_filter_and_group_by_criteria(filter_set, group_by_set):
"""Return a bool for whether a view can be used."""
no_view_group_bys = {"project", "node"}
# The dashboard does not show any data grouped by OpenShift cluster, node, or project
# so we do not have views for these group bys
if gr... | 8baeeb827ba092a3b5262f076ba1fa77aaf55b5f | 697,335 |
def ping(event):
"""Responds 'pong' to your 'ping'."""
return 'pong' | 48d07ca1e513b28212c56758c41e1757b5f75468 | 697,340 |
import functools
import operator
def _has_pattern_match(name: str, patterns) -> bool:
"""Check if name matches any of the patterns"""
return functools.reduce(
operator.or_,
map(lambda r: r.search(name) is not None, patterns),
False) | 1dd6ad54ee35db20b6fcec0495e4c4ef61788aa0 | 697,341 |
import torch
def _get_zero_grad_tensor(device):
""" return a zero tensor that requires grad. """
loss = torch.as_tensor(0.0, device=device)
loss = loss.requires_grad_(True)
return loss | 5bf67a7ab0ff50e041fcd07484d6f5468acf6d4e | 697,343 |
def update_borders(bb: list, roi_size: list):
"""
Update bounding box borders according to roi_size. Borders are updated from center of image.
:param bb: original bounding box
:param roi_size: output bounding box size
:return: modified bounding box
"""
mid_x = bb[0] + bb[2] / 2
mid_y = b... | 15574e03cc3bea0b33e5f20014bc83ea60b47bfc | 697,345 |
import random
def random_up(sentence: str) -> str:
"""
Randomly makes some letters lower case and some upper case
Parameters:
sentence(str): the sentence to mix case of the letters in
Returns:
str: modified sentence
Examples:
>>> random_up('abc')
... | 15d7300e258b54462ae51b8f70a1b8e8a59e0120 | 697,347 |
import json
def load_scenario(json_file_path):
""" Load scenario from JSON """
json_file = open(json_file_path, 'r')
parsed_json = json.loads(json_file.read())
json_file.close()
return parsed_json | 005eb73753fcbbd873e5cb73fa54142990ebc97d | 697,349 |
def to_deg(value, loc):
"""convert decimal coordinates into degrees, munutes and seconds tuple
Keyword arguments: value is float gps-value, loc is direction list ["S", "N"] or ["W", "E"]
return: tuple like (25, 13, 48.343 ,'N')
"""
if value < 0:
loc_value = loc[0]
elif value > 0:
... | 5c2eb955bc3e05f5f8378bc0df2ed16ea7f7cf3b | 697,350 |
def max_sub_array(nums):
""" Returns the max subarray of the given list of numbers.
Returns 0 if nums is None or an empty list.
Time Complexity: O(n)
Space Complexity: O(1)
"""
if nums == None:
return 0
if len(nums) == 0:
return 0
max_sum = nums[0]
curr... | 729f277b61b517fe7e434812576347fe6742401c | 697,351 |
def add_camera_args(parser):
"""Add parser augument for camera options."""
parser.add_argument('--video', type=str, default=None,
help='video file name, e.g. traffic.mp4')
parser.add_argument('--video_looping', action='store_true',
help='loop around the video ... | 21f74ccd2a092ba9620f40bb1a0a9c5c6dbf72a5 | 697,356 |
def process_wildcard(fractions):
"""
Processes element with a wildcard ``?`` weight fraction and returns
composition balanced to 1.0.
"""
wildcard_zs = set()
total_fraction = 0.0
for z, fraction in fractions.items():
if fraction == "?":
wildcard_zs.add(z)
else:
... | 6358bfc7ee3b7f187b375b1df2cecd8ce104674a | 697,357 |
def _convert_ketone_unit(raw_value):
"""Convert raw ketone value as read in the device to its value in mmol/L."""
return int((raw_value + 1) / 2.) / 10. | 804d34ecc9d901f3d958ebee34282885248c3499 | 697,361 |
import base64
def secret_to_bytes(secret):
"""Convert base32 encoded secret string to bytes"""
return base64.b32decode(secret) | 81720bc65fa4be6a18cf0ba461adaf7b9227a417 | 697,362 |
def find_constraints(mol, sites):
"""
Find the NwChem constraints for a selection of sites on a molecule.
"""
# Find the corresponding atom numbers in string format
site_numbers = []
for i in range(len(mol.sites)):
if mol.sites[i] in sites:
site_numbers.append(str(i + 1) + ... | 978bef23a58ec670e4bf002b16ebca580acb5663 | 697,370 |
def decomp_proc (values):
"""
Given the row of predictions for the decomposition mode test output, remove the pointless training zeroes from
the time
:param values: A row of the decomposition predictions .csv, split by commas into a list
:return: Same row with pointless zeros after the time removed... | 6898dc6586ffed0b16dbde1159861eccc63206c5 | 697,371 |
def _non_adjacent_filter(self, cmd, qubit_graph, flip=False):
"""A ProjectQ filter to identify when swaps are needed on a graph
This flags any gates that act on two non-adjacent qubits with respect to
the qubit_graph that has been given
Args:
self(Dummy): Dummy parameter to meet function speci... | 9d3a55341c2a1410c5c1864ce5fcd6ea177d4026 | 697,373 |
def str2bool(str):
"""Tells whether a string is a Yes (True) or a No (False)"""
if str.lower() in ["y", "yes"]:
return True
elif str.lower() in ["n", "no"]:
return False
else:
raise Exception("Please enter Yes or No") | ba3f8a2fdca089ae5cdc608a04091009a57a7662 | 697,374 |
def _make_value_divisible(value, factor, min_value=None):
"""
It ensures that all layers have a channel number that is divisible by 8
:param v: value to process
:param factor: divisor
:param min_value: new value always greater than the min_value
:return: new value
"""
if min_value is Non... | 89561ca1551b988030b3d0b4fdd5d17f5664607f | 697,380 |
def contig_count(contig):
"""Return a count of contigs from a fasta file"""
return sum([1 for line in open(contig, 'r').readlines() if line.startswith('>')]) | dde6bbcf5799dbea197c2b0f391bf26e9ac960b6 | 697,381 |
from pathlib import Path
def contour(anchor):
"""contour(anchor) -> Path
Returns a Path object representing the contour starting with the
Dart anchor. (syntactic sugar for 'Path(anchor.phiOrbit())')"""
return Path(anchor.phiOrbit()) | c2fee570e3feb753439c5af941b0658e2aa49bbc | 697,382 |
def HPX_grid_size(Nside):
"""Return the size of the pixel grid (Nx, Ny) for a given Nside"""
Nx = 8 * Nside
Ny = 4 * Nside + 1
return Nx, Ny | 8e267c467ed52ef24b1d540cff9aeac84a1e1bb4 | 697,385 |
def _get_percent(text):
"""If text is formatted like '33.2%', remove the percent and convert
to a float. Otherwise, just convert to a float.
"""
if not text:
return None
if text.endswith('%'):
text = text[:-1]
return float(text.strip()) | 2975f0a603a113bf7991753250a83be4da363070 | 697,388 |
def contig_to_array(bw, chrm, res = None):
"""
Convert single basepair bigwig information to a numpy array
Args:
bw - a pyBigWig object
chrm - name of chromosome you want
res - resolution you want data at in bp.
Returns:
outarray - numpyarray at specified resolut... | f09fb80ef5a073bf87f82b0d86c26153db404f4f | 697,389 |
def clean_empty_keyvalues_from_dict(d):
"""
Cleans all key value pairs from the object that have empty values, like [], {} and ''.
Arguments:
d {object} -- The object to be sent to metax. (might have empty values)
Returns:
object -- Object without the empty values.
"""
if not... | 8769e5ceda55588a136fdf131f19aea4c5f06f95 | 697,391 |
import random
def session_id_generator(size = 8):
"""
Generating session id
"""
s = "0123456789ABCDEF"
return "".join(random.sample(s,size )) | b57ca24f6cc08cb465562f09495c99f25d72d296 | 697,392 |
def _resource_name_package(name):
"""
pkg/typeName -> pkg, typeName -> None
:param name: package resource name, e.g. 'std_msgs/String', ``str``
:returns: package name of resource, ``str``
"""
if not '/' in name:
return None
return name[:name.find('/')] | f434aa1fcfd18797625ca63c7f121dce020f8585 | 697,398 |
def hours2days(period):
"""
uses a tuple to return multiple values. Write an hours2days function that takes one argument, an integer, that is a time period in hours. The function should return a tuple of how long that period is in days and hours, with hours being the remainder that can't be expressed in days. F... | 2198538b30ae9e0b1b1c1ec6f9f7f76ac393cafb | 697,403 |
def top_ranked_final_primers(filter_merged_df):
"""
Drops duplicate sequence ids and keeps first (which also corresponds)
to the highest ranking primer pair for each sample.
Args:
filter_merged_df (DataFrame): input from filter_merged, where primers are only equal
... | 03f682a03d6454c3b142231fe78d82208117cf09 | 697,407 |
def words_sent(message_container, start_date, end_date):
"""
Return number of words sent between start and end date contained by
message container (chat/member).
"""
words_sent = 0
for message in message_container.messages:
if (start_date <= message.timestamp.date() <= end_date
... | c8e466a8d9c1049a6b5066fe0c9efccbbd3ae245 | 697,409 |
import math
def matrix_from_quaternion(quaternion):
"""Calculates a rotation matrix from quaternion coefficients.
Parameters
----------
quaternion : [float, float, float, float]
Four numbers that represents the four coefficient values of a quaternion.
Returns
-------
list[list[fl... | 57a38e4214c94e54e2cfb2fd71e1bfa57d4f714b | 697,413 |
from typing import Iterable
def create_item_name(item_type: str, item_names: Iterable[str]) -> str:
"""
Translates an item with a type into a name. For instance, if there are two items of type 'POST', the first will
be named 'POST0' and the second will be 'POST1'
Args:
item_type: Type of item... | 8ec37473ee0a3dc880dc962b9f1c622c2dfd9af3 | 697,414 |
def get_installed_tool_shed_repository( app, id ):
"""Get a tool shed repository record from the Galaxy database defined by the id."""
return app.install_model.context.query( app.install_model.ToolShedRepository ) \
.get( app.security.decode_id( id ) ) | d76c3af3f159f9a0882a6b27951a2e8060f4bc28 | 697,421 |
def _keytify_test_cases(test_cases):
"""Traverse the test cases list and return a dictionnary
which associate test case name to its duration. This is used for
fast access to tests cases duration.
"""
res = {}
for tc in test_cases:
key = "%s/%s" % (tc.get('classname'), tc.get('name'))
... | 3adb4f94e617bc03722cb860f0bcd2c388d6ec1a | 697,422 |
def vv_vel(vel, dt, force, force_previous, mass):
"""Computes the new velocities using the velocity-verlet integration scheme
Args:
vel -- np.array(N,dim) containing the current particle velocities
DT -- timestep
force -- np.array(N,dim) containing the current net forces on each particl... | df56e09ad191b161d258f1decf2bdcaedf7bded9 | 697,423 |
import requests
import json
def getdetailedinfofromid(url, token, personid):
"""
@param url: url for the webex teams API calls
@param token: WebEx Teams Token to be used for the queries of the WebEx Teams Cloud
@param personid: personID of the end user that we would like to return the email to.
@... | c6bd54182cb8c7cc109ad68505fca5887a6f9fad | 697,425 |
def map_nlist(nlist, fn):
"""
Maps `fn` to elements in nested list that has arbitrary depth.
https://stackoverflow.com/a/26133679
:param nlist: Input list
:param fn: Function to be applied
:return: Modified list
"""
new_list = []
for i in range(len(nlist)):
if isinstance(nlis... | 5f808eff663eae9b38073804241295c6976237a3 | 697,427 |
def s3_upload_part_copy(
s3_obj, bucketname, copy_source, object_key, part_number, upload_id
):
"""
Boto3 client based upload_part_copy operation
Args:
s3_obj (obj): MCG or OBC object
bucketname (str): Name of the bucket
copy_source (str): Name of the source bucket and key name... | e89fdcf85616eeeab6c8da93dbbd290ad992820b | 697,428 |
import math
import torch
def sdeint_euler(f, g, dif_g, t, h, x0, mid_state=None):
"""
SDE integration from t0=0 to t1=t. Assume diagnoal noise.
Args:
f: drift function of (t, X), t is time and X is a d-dimensional vector.
Outputs a d-dimensional vector
g: diffusion function of (... | f9147add232a244cd94d91f95610ff37987c07c3 | 697,430 |
def max_element(l):
"""
Returns the maximum element of a given list of numbers.
"""
max_ = None
for x in l:
if max_ is None or x > max_:
max_ = x
return max_ | 1596f33f0bb91839fbcaf2613892bf90fafd6afd | 697,432 |
def mask_pipe_mw(text: str) -> str:
"""
Mask the pipe magic word ({{!}}).
:param text: Text to mask
:return: Masked text
"""
return text.replace("{{!}}", "|***bot***=***param***|") | 546d7c4b71ce3403da7a33883dac2cd3171224e6 | 697,433 |
def to_scalar(var):
"""
convert a tensor to a scalar number
"""
return var.view(-1).item() | 56170067e38773ce452268827ef87d7b1bab877a | 697,434 |
def check_input(def_list):
"""Check that all defect structures in list are not None.
Args:
def_list (list): List of defect structures
Returns:
True if all defect structures are present.
"""
for defect in def_list:
if not defect:
return False
return True | 0c1372688e4780dd44df575d470e0511366dbbc4 | 697,435 |
from time import strftime, localtime
from typing import Union
def format_time(time_tick: Union[int, float]) -> str:
"""
格式化时间戳为具体日期,例\n
>>> format_time(123456789)\n
>>> '1973-11-30 05:33:09'\n
:param time_tick: 时间戳
:return: 具体日期
"""
return strftime('%Y-%m-%d %H:%M:%S', localtime(time_t... | 8f3da87066013ce267b485d4924617c9615b455e | 697,440 |
def pack(word, pattern):
"""Return a packed word given a spaced seed pattern.
>>> pack('actgac', [True, False, True, True, False, True])
'atgc'
"""
ret = []
for i, char in enumerate(word):
if pattern[i]:
ret.append(char)
return "".join(ret) | 9697a4ee5b9bbc3d7f4d22040196bc8856fd2b6d | 697,441 |
def get_shp_extent(gdf):
"""Fetch extent of input shapefile"""
extent = tuple(gdf.bounds.values[0])
return extent | d9343f94f349c1db5af033d78693d3b55407a3c8 | 697,448 |
def get_grid_data(df):
"""
Prunes dataframe to rows whose longitudes are multiples of 60
degrees and whose years are multiples of 10. This includes only
lat/lon grid locations for which we have USNO data for all eight
types of twilight events.
"""
bools = (df['Longitude'] % 60 == 0... | 4788356a9c0b14759a34c436f2f8267ea07043be | 697,449 |
def factorial(value: int) -> int:
""" Calculates the factorial of the given value.
factorial
=========
The `factorial` function takes an positive integer value and calculates the
factorial (n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1).
Parameters
----------
value: int
an positive inte... | 642700f9ec42c3ab47130d599626c44b2de4165c | 697,450 |
import ast
def _build_table(src):
""" Builds AST tree table from given source.
Args:
src (str): source code
Returns:
dict: table of ast.AST nodes in tree
"""
table = {}
tree = ast.parse(src)
for node in ast.walk(tree):
curr = table.get(node.__class__, [])
... | 955fcec38e57a9657ffad183a7486ddfc5847bfc | 697,451 |
import torch
def make_bow_vector(sentence, word_to_ix):
"""
Turn a sentence (list of words) into a vector using the dictionary (word_to_ix)
return data is a FloatTensor of shape 1 (batch size) by len(word_to_ix)"""
vec = torch.zeros(len(word_to_ix))
for word in sentence:
vec[word_to_ix[word]] += 1... | ae0df26878537ae232e70881d5e8a56fcea0c350 | 697,453 |
def matmul(a, b):
"""
Multipy two matrices
:param a: list of list of floats
:param b: list of list of floats
:return: resulting matrix
"""
res = []
for r_idx, a_r in enumerate(a):
res_row = [
sum([a_v * b_r[b_idx] for a_v, b_r in zip(a_r, b)])
for b_idx in... | 504f53c1de68a28a2c23c479b53acc76f359f347 | 697,454 |
from typing import Dict
from typing import Any
from typing import List
def directory(module_locals: Dict[str, Any]) -> List[str]:
"""
Return the module's public directory for dir function.
Parameters
----------
module_locals
The module's locals as generated by the locals() function.
... | 37dc44ddc18a21c5aa6faba9887cae0aa6bcdd0b | 697,456 |
def SplitDataset_x_y(df, IndependentColumnName):
"""
This function split a dataframe into a dataframe with independent variables and a dataframe with dependent variables.
The IndependentColumnName define what is/are the independent variables based on the related column name.
Arguments:
----------
... | a2e4a6244fc5bcee401981ee54f20d179c09dc89 | 697,459 |
from functools import reduce
import operator
def validate_nmea_checksum(sentence):
"""
Validates NMEA sentence using checksum according to the standard.
:param sentence: NMEA sentence including checksum
:returns:
- Boolean result (checksum correct)
- raw NMEA data string, with prefix $G... | 82f5a63943916e4323178063366a0f8c276ad64a | 697,461 |
def get_sorter_by_args(model, args: list):
"""Get list of SQLAlchemy order_by args from dictionary of arguments.
"""
sorters = []
for key in args:
if key[0] == '-':
sorters.append(getattr(model, key[1:]).desc())
else:
sorters.append(getattr(model, key))
return... | d9572ad576d8980dd453835b80f36673f6ab4f16 | 697,462 |
def get_crash_arg() -> bytes:
"""
This function returns the (pre-encoded) `password` argument to be sent to
the `sudo` program.
This data should cause the program to crash and generate a core dump. Make
sure to return a `bytes` object and not an `str` object.
WARNINGS:
0. Don't delete this... | f25bf1c66c5387076830e77077b97d9844244428 | 697,466 |
def ParseLine(line, new_target):
"""Parse one line of a GCC-generated deps file.
Each line contains an optional target and then a list
of space seperated dependencies. Spaces within filenames
are escaped with a backslash.
"""
filenames = []
if new_target and ':' in line:
line = line.split(':', 1)[1... | ab0df773a9279f30b438ee7c325225a74574a588 | 697,470 |
def has_refseq(db_list):
"""
Return the index of the list where the 'RefSeq' string is located.
Otherwise return None
:param db_list: A list of db names taken as the first element of the tuples in a
Swissprot.record.cross_references list
:return: int: index or None
"""
if 'RefSeq' in db_... | ffa175079e7e14e91fe9b8901c3d8cd60b200eea | 697,472 |
import ipaddress
def prefix_to_network(prefix):
"""Convert an IP prefix to an IP-address and network mask."""
ipaddr = ipaddress.ip_interface(prefix) # turn into ipaddress object
address = ipaddr.ip
mask = ipaddr.netmask
return address, mask | ac521405d5bdd90f082bc4d0e5f434b7a5b7f3f7 | 697,476 |
def deflatten(d, sep='.', maxdepth=-1):
"""Build a nested dict from a flat dict respecting a separator.
>>> d_in = {'a': 1, 'c': {'a': 2, 'b': {'x': 5, 'y' : 10}}, 'd': [1, 2, 3]}
>>> d = flatten(d_in)
>>> for k, v in d.items(): print(k, v)
a 1
c.a 2
c.b.x 5
c.b.y 10
d [1, 2, 3]
... | dc507bd9c167c1b2c9cb89605a424d235c11fb82 | 697,477 |
import click
def config_option(config_function):
"""Helper decorator that turns an option function into a cli option"""
return (lambda function: click.option('--' + config_function.__name__,
help=config_function.__doc__.strip() + '. Example: "' +
... | f6e8dd160bf6b1f38612cbf338140f6f94862644 | 697,479 |
import re
def strip_headers(pem_text):
"""
Strips the headers off a a FinCrypt key or message.
:param pem_text: Text of key or message (string)
:return: Tuple (header (ie. 'BEGIN FINCRYPT MESSAGE'), base64 (string))
"""
match = re.match(
r'(?:-+ (BEGIN FINCRYPT (?:PUBLIC |PRIVATE )?(... | c00f3006f392bde2ed835905cdf0582e25049a9d | 697,480 |
def _CreateAssetsList(path_tuples):
"""Returns a newline-separated list of asset paths for the given paths."""
dests = sorted(t[1] for t in path_tuples)
return '\n'.join(dests) + '\n' | bb57f014e68d398eb89468a7c86c972f03e47b7d | 697,481 |
def discount_with_dones(rewards, dones, gamma):
"""
Calculates discounted rewards. This is still valid if the episode
terminated within the sequence.
From OpenAI basline's A2C.
Parameters
----------
rewards: list
list of rewards with the last value being the state value
dones:... | 2feef30d209795414029cfc79aef2ea8e65220af | 697,484 |
def ema(series, n):
"""
指数加权移动平均线: 求series序列n周期的指数加权移动平均
计算公式:
ema(x, n) = 2 * x / (n + 1) + (n - 1) * ema(x, n).shift(1) / (n + 1)
注意:
1. n 需大于等于1
2. 对距离当前较近的k线赋予了较大的权重
Args:
series (pandas.Series): 数据序列
n (int): 周期
Returns:
... | fcdf4a33821ba20d7026f30f4229ab7f62f32eda | 697,485 |
from typing import Any
from typing import Dict
def _get_feature_row(features: Any, index: int) -> Dict[str, Any]:
"""Returns one row of the features table as a dictionary."""
return {name: values.iloc[index] for name, values in features.items()} | 8729d3f4c8adaa00fd219e2bb74d6ba138776793 | 697,491 |
def get_quarter_from_month(month: int):
"""Returns the quarter for a given month"""
month_quarter_map = {1: 1, 2: 1, 3: 1, 4: 2, 5: 2, 6: 2, 7: 3, 8: 3, 9: 3, 10: 4, 11: 4, 12: 4}
return month_quarter_map[month] | ef7f3a83c3b4b75823e67bca9ce3f62dd1cae5cf | 697,494 |
def _precision(tp, fp):
"""Calculate precision from true positive and false positive counts."""
if fp == 0:
return 1 # by definition.
else:
return tp / (tp + fp) | 9bf80bc0ce2b657b1c8bbc8fb57e64e7df2081c9 | 697,496 |
def inference(model, X):
"""Run model inferences and return the predictions.
Inputs
------
model : ???
Trained machine learning model.
X : np.array
Data used for prediction.
Returns
-------
preds : np.array
Predictions from the model.
"""
return model.pre... | c9edd988933bff12fa4da14c9735f8f482e82ca8 | 697,497 |
from datetime import datetime
def now(frm: str = '%d/%m/%Y %H:%M:%S') -> str:
"""
Функция возвращает текущее время и дату
Args:
frm (str): Формат времени и даты
Returns:
str: Текущее время и дата
"""
return datetime.now().strftime(frm) | e21851f65de1e7640dc7e34f8f3761129052e1c3 | 697,498 |
def get_full_piece_id(piece):
"""
Returns rdb piece id and append movement id if exists.
:param piece: A piece as stored in dataset
:return: A string containing either the piece ID (no movement information) like "123", or the piece ID followed
by dash, followed by the movement ID like "123-46123"... | 7d9c0946d26035cdbf945f6d854913388818e8f9 | 697,501 |
import itertools
def maxgap(data, max_gap):
"""
Arrange data into groups where successive elements
differ by no more than *maxgap*
The input has to be a list of list with the structure:
[['id1', distance between start decay and last expression],['id2',dist2],...,['idn', distn]]
The output wi... | fba36520d40263eafe25556304a8cbbaf8f724fb | 697,502 |
def get_slice(img, ori, slc):
"""
Extract one slice from a 3D numpy.ndarray image.
:param img: np.array. input image to extract slice.
:param ori: int. orientation to extract slice. 1. sagittal. 2. coronal. 3. axial.
:param slc: int. slice number to extract.
:return: extracted 2D slice: np.array... | dcf03eec0d16c68f55f701b2d312dbf4fa946ee7 | 697,503 |
def prune_multiple_copies_of_species(tree, g2s_map, s2g_map):
"""
Removes all but one leaf with the same species label
Parameters
----------
tree : treeswift tree object
g2s_map : dictionary
maps gene copy labels to species labels
s2g_map : dictionary
maps specie... | a7b5b5a0b8af0ea157d5bbf1bbbfb1337dc7ee69 | 697,504 |
def get_link(task_id, tasks_df):
"""Return the task link from the task ID."""
task = tasks_df.loc[int(task_id)]
return task['info']['link'] | a24c467f298526d2176747960430f5e283384043 | 697,507 |
def known_face_sentence(known_face_name):
"""
describe known person
Example:
Anuja is in front of you.
:param known_face_name: name of known person in the frame
:return: sentence descibing person
"""
return "%s in front of you" % (
known_face_name
) | 266da5bf129ba6844dbe0bd3cbcf9b4663100d1c | 697,508 |
from typing import Union
from pathlib import Path
def ensure_path(path: Union[str, Path]) -> Path:
"""
Ensure string is converted to a Path.
This is a more restrictive version of spaCy's [ensure_path](https://github.com/explosion/spaCy/blob/ac05de2c6c708e33ebad6c901e674e1e8bdc0688/spacy/util.py#L358)... | 1f70ab426f6347399da73e854c0c2be9eee7843c | 697,510 |
def tokenize_table_name(full_table_name):
"""Tokenize a BigQuery table_name.
Splits a table name in the format of 'PROJECT_ID.DATASET_NAME.TABLE_NAME' to
a tuple of three strings, in that order. PROJECT_ID may contain periods (for
domain-scoped projects).
Args:
full_table_name: BigQuery table name, as ... | a092f749e18cdec41b50a8f1b7e1e5e99cd8e2e3 | 697,517 |
def linear_annuity_mapping_fprime(underlying, alpha0, alpha1):
"""linear_annuity_mapping_fprime
first derivative of linear annuity mapping function.
See :py:func:`linear_annuity_mapping_func`.
The function calculates following formula:
.. math::
\\alpha^{\prime}(S) := \\alpha_{0.}
wher... | ff57723cad7ade65644744dc30abb6db5c1e6b95 | 697,518 |
def third_bashforth(state, tendencies_list, timestep):
"""Return the new state using third-order Adams-Bashforth. tendencies_list
should be a list of dictionaries whose values are tendencies in
units/second (from oldest to newest), and timestep should be a timedelta
object."""
return_state = {}
... | 6b1a62b94c662a1b14eafa3be6953e73486b6cfd | 697,519 |
from typing import OrderedDict
def getAttrFromList(objList, attr):
"""\
Given a list of objects in objList, each having the attribute attr, return a list comprising the value of attr for each object in objList.
Return: A list of values.
Parameters:
* objList: The list of objects
* attr: The attribute had in... | bef6386afff15a0d6a78d92f02878a47171dd9d7 | 697,521 |
def remove_control_char(pdf_content):
"""
移除控制字符,换行符、制表符、转义符等)python-docx是不支持控制字符写入的
:param pdf_content: PDF 文件内容
:return: 返回去除控制字符的内容
"""
# 使用str的translate方法,将ASCII码在32以下的都移除 http://ascii.911cha.com/
return pdf_content.translate(dict.fromkeys(range(32))) | 84dff48a5654b12f7446f77cbc4d132716d2018c | 697,523 |
def confirm(question: str) -> bool:
"""Ask a confirmation to the user in the console.
Args:
- question: the question to ask the user.
Returns:
True if the user answered 'yes' or 'y', False otherwise.
"""
input_ = input(question + " Enter (y)es or (n)o: ")
return input_ == "yes... | bd6415658d4c7adf73d682fb151dc8aecc7eaf6d | 697,524 |
def make_safe_label(label):
"""Avoid name clashes with GraphViz reserved words such as 'graph'."""
unsafe_words = ("digraph", "graph", "cluster", "subgraph", "node")
out = label
for word in unsafe_words:
out = out.replace(word, "%sX" % word)
return out.replace(".", "__").replace("*", "") | e122575956e492cbb450287a6b91174fdc59233a | 697,526 |
def load_bands(src, bands, masked=False):
"""
Load selected bands of a raster as array
*********
params:
--------
src : rasterio.DatasetReader object
bands : list
list of bands to load, e.g. [1,2,3]
masked : bool (default:False)
if True... | e0c131ca93066387ae12f9bc6206626d4313cdf7 | 697,527 |
def is_in_tol(value, expected_value, tolerance):
"""Is the provided value within expected_value +/- tolerance
Parameters
----------
value : int, float
Value of interest
expected_value : int, float
Expected value
tolerance : int, float
Allowed deviation from expected_valu... | b1cde33b7979995b86e3ecd4cd41330cfa31c447 | 697,529 |
def merge(left, right):
"""
Merge two sorted arrays in a resulting array of size len(left) + len(right)
"""
result = []
while len(left) != 0 and len(right) != 0:
if left[0] < right[0]:
result.append(left.pop(0))
else:
result.append(right.pop(0))
if len(l... | 9a962735cc157a135c4d65b4f18c5e55d8e182d2 | 697,531 |
def loglines(logspath):
"""
Read logging lines generated by a test case.
Parameters
----------
logspath : str
Path to which test case wrote logs.
Returns
-------
Iterable of str
Logs from the test case.
"""
with open(logspath, 'r') as logfile:
retu... | a30680a863fba0b1098536404021b4d32b31abff | 697,534 |
import re
def read_best_values(file_list):
"""Reads the best hypervolume values from files in file_list, where each is formatted as a C source file
(starts to read in the next line from the first encountered 'static').
Returns a dictionary containing problem names and their best known hypervolume va... | 9f9088931f64dbeb463223b62c871c1462561ca6 | 697,537 |
def GetGems(gem_counts):
"""Returns a list of GemTypes given a dict from GemType to counts."""
gems_list = []
for gem_type, count in gem_counts.iteritems():
if count < 0:
raise NotImplementedError("count cannot be negative")
for _ in range(count):
gems_list.append(gem_type)
return gems_list | 08b4f7e669cbf2a0fb621449a2d845500637c4e1 | 697,539 |
def _get_obj_name(obj):
"""Auxiliary function to retrieve the name of an object."""
name = str(obj).replace("class ", "")
return name.translate(str.maketrans({c: "" for c in "(<>),'"})) | 92e3d774036a1f0d2bab9bdc60ae9e6582b8aa40 | 697,540 |
def uniform_heuristic(item):
""" Taking in an item, return 1. """
return 1 | bf1b25c96d25c56852446e36c6653c141a6f6460 | 697,541 |
def can_read_deleted(context):
"""Indicates if the context has access to deleted objects."""
if not context:
return False
return context.read_deleted | 58b3025f133ee6bb8a1cc17c410bc1b0ea43c3b5 | 697,542 |
import requests
def get_google_dot_com(use_ssl=True):
"""Return the contents of Google.com
:param use_ssl: Use SSL? You should! Don't turn this off. You've been warned. Scamp!
"""
protocol = "https" if use_ssl else "http"
return requests.get(f"{protocol}://www.google.com/").text | 246420a67f5706fab2bf3d13bb6bb9e1bb7d00d7 | 697,543 |
import torch
def get_gpu_or_cpu_number(device):
"""Returns the GPU number on which the tensors will be run. Returns -1 if the CPU is used"""
if 'cuda' in device:
if not torch.cuda.is_available():
raise RuntimeError("Torch cuda check failed, your drivers might not be correctly installed")
... | 5a16538e8339747d459ac94467278017b8294f21 | 697,544 |
def map_calculated_scores_to_user(predictions, user):
"""
This function replaces the previous scores (only 0's in production) with the computed scores)
:param predictions: the list of prediction-scores
:param user: the user with its (original) scores
:return: the user with its new scores
"""
... | 23a1dcc077cab2f5f27750c660abbab09bf0ff4c | 697,546 |
from pathlib import Path
def check_db_dir(parent: Path):
"""Checks whether the db directory exists.
If not, create it.
Args:
parent (Path): the parent to both server_settings and db
Returns:
Path: the directory itself
Raises:
Exception: the db dir path exists, but it isn... | 3f7c0197dc7d7b04c0864d479ac834518815aade | 697,547 |
from bs4 import BeautifulSoup
def read_XML_file(filename):
"""Reads file, with specific filename and returns parsed XML-tree
:param filename: path to file with urls
:return: parsed XML-tree, that contains in specefied file
"""
with open(filename) as xml:
soup = BeautifulSoup(xml, "lxml-xml... | 025b45453ef812d6d91d8386dde33f8e59882ce1 | 697,550 |
def iterkeys(obj, **kwargs):
"""Iterate over dict keys in Python 2 & 3."""
return (obj.iterkeys(**kwargs)
if hasattr(obj, 'iterkeys')
else iter(obj.keys(**kwargs))) | 03787c0e8bb493c721871990c4068144782370e2 | 697,552 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.