content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def strip_server(path):
""" Removes the server part from xrdfs output.
Example input:
root://polgrid4.in2p3.fr:1094//dpm/in2p3.fr/home/cms/trivcat/store/user/rembserj
Output:
/dpm/in2p3.fr/home/cms/trivcat/store/user/rembserj
Note:
Returns None if the input does not match the ... | 91a9bbe327e0c0b165137ed3ff49be490f6373be | 61,268 |
def rewrite_kwargs(conn_type, kwargs, module_name=None):
"""
Manipulate connection keywords.
Modifieds keywords based on connection type.
There is an assumption here that the client has
already been created and that these keywords are being
passed into methods for interacting with various ... | b5fc487a50f82e28dc00282f08951c759f19780d | 61,269 |
def normalize_path(path):
"""Put a URL path into the format used by the data structure."""
if path in ('', '/'):
return '/'
path = path.rstrip('/')
if not path.startswith('/'):
path = '/{path}'.format(path=path)
return path | 53435e41f240a5f4f8d33f4a9a670eaa0d2c2cab | 61,272 |
import requests
def get_last_tag(github_config, owner, repo):
""" Get the last tag for the given repo """
tags_url = '/'.join([github_config.api_url, 'repos', owner, repo, 'tags'])
tags_response = requests.get(tags_url, headers=github_config.headers)
tags_response.raise_for_status()
tags_json = ta... | 706758b43e7fe1d0405241ca7c8e4cff71207591 | 61,273 |
def _cubic_spline_point(b_coeff, t):
"""
Internal convenience function for calculating
a k-dimensional point defined by the supplied
Bezier coefficients. Finds the point that
describes the current position along the bezier
segment for k dimensions.
params:
b_coeff => b0...b3: Four k... | 1471743893fbb6874b39ca1fa7634a246b1f2aee | 61,274 |
from typing import List
def _is_torso_visible_or_labeled(kp: List) -> bool:
"""
True if torso (left hip, right hip, left shoulder,
right shoulder) is visible else False
"""
if len(kp) != 51:
raise ValueError(
"keypoint list doesn't fit the format of "
"COCO human ke... | 06bad20526b74db08daa22ddb6bf63b5394fb26d | 61,284 |
def StringRotation(s1: str, s2: str) -> bool:
"""Returns whether s2 is a rotation of s1.
>>> StringRotation("", "")
True
>>> StringRotation("a", "")
False
>>> StringRotation("", "b")
False
>>> StringRotation("a", "a")
True
>>> StringRotation("a", "b")
False
>>> Stri... | 4d6c8bec9e72b92545cfa34804910466771ac158 | 61,291 |
import six
def quote(s, *args):
"""Return quoted string even if it is unicode one.
:param s: string that should be quoted
:param args: any symbol we want to stay unquoted
"""
s_en = s.encode('utf8')
return six.moves.urllib.parse.quote(s_en, *args) | 14b72b9231a2d53f242136cb002dc2d189eca1aa | 61,297 |
def DescribeStory(story):
"""Get the docstring title out of a given story."""
description = story.__doc__
if description:
return description.strip().splitlines()[0]
else:
return '' | 1b8dc5f7c2d108c035e7b6838b1608a511c5ba56 | 61,303 |
def margins_to_dict(margins):
"""Convert the margin's informations into a dictionary.
Parameters
----------
margins : the list of OpenTurns distributions
The marginal distributions of the input variables.
Returns
-------
margin_dict : dict
The dictionary with the informatio... | 0efa7862d7c47744d016b923056b74c265c2316d | 61,305 |
import math
def repeatedString(s, n):
"""
Returns the number of 'a's in the first n letters of a string consisting of
infinitely repeating strings, s.
"""
count = 0
s_count_a = s.count('a')
count += math.floor(n / len(s)) * s_count_a
for _ in range(n % len(s)):
if s[_] == 'a'... | b35bf491ed532e5d70cf273ea3d30af0bb184ff4 | 61,310 |
from typing import Union
def _create_table_row(key: str, value: Union[str, int], highlight: bool = False) -> str:
"""
Create table row for stats panel
"""
template_stats_data = """
<tr style="border-bottom: 1px solid;">
<th style="text-align: left">{key}</th>
<td style="text-align:... | 362154b67151f9f6c1d996c1e9ee67cbcf8b7ea3 | 61,313 |
import random
def number(minimum=0, maximum=9999):
"""Generate a random number"""
return random.randint(minimum, maximum) | b3f06823431cfaca549e3dc9544e68fd13171571 | 61,314 |
import torch
def topk_pool(x, k=32):
"""
Args:
x: (B, F, M, P)
k: top k
Returns:
(B, F, M, topk)
"""
_, idx = torch.topk(x, k=k, dim=3) # (B, F, M, k)
pooled = torch.gather(x, dim=3, index=idx)
return pooled | d3dcce9c94c9c8dbdf839b713718c8ac803bddec | 61,321 |
import re
def uid_from_context(context):
"""
Parse post.uid from a link
"""
# id pattern found in link
pattern = r"[0-9]+"
uid = re.search(pattern, context)
uid = uid.group(0) if uid else ""
return uid | 471918ef387112094fc450a4bd4b924614e59171 | 61,325 |
from typing import List
from typing import Dict
import json
def get_movie_data(files: List[str]) -> List[Dict]:
"""Parse movie json files into a list of dicts."""
movie_data = []
for file in files:
with open(file, encoding="utf-8") as f_in:
movie_data.append(json.load(f_in))
return... | 14e27498b4153595d37e87140caba6a455ad6f99 | 61,328 |
def get_lines(row):
"""Get lines from start and end coordinates.
Output format: [((x1, y1), (x2, y2)), ...]
:param row: measurement segments grouped by instance and index
:return: line coordinates
"""
x1s, y1s, x2s, y2s = (
row["x1coordinate"],
row["y1coordinate"],
... | 082f2b595cc7c6835c9ebf6f06f2c23cb7cb8a3e | 61,329 |
from typing import Dict
def _add_sub_path(arg: Dict, sub_paths: Dict) -> Dict:
"""Add the sub_path field to an argument."""
name = arg['name'].replace('-', '_')
if name in sub_paths:
arg['sub_path'] = sub_paths[name]
return arg | 3d0125ba8a64ea0b9bdb1a445fe2f3a297d226a4 | 61,330 |
import re
def camel_case_to_snake_case(camel_case):
""" Convert string from camel (e.g. SnakeCase) to snake case (e.g. snake_case)
Args:
camel_case (:obj:`str`): string in camel case
Returns:
:obj:`str`: string in snake case
"""
_underscorer1 = re.compile(r'(.)([A-Z][a-z]+)')
... | 2d58755d6c3ad97a109a284ff90cd9a8be909a50 | 61,335 |
import torch
def reduce_loss(loss: torch.Tensor, reduction: str = "mean") -> torch.Tensor:
"""
:param loss: loss tensor
:param reduction: mean, sum, or none
"""
if reduction == "mean":
loss = loss.mean()
elif reduction == "sum":
loss = loss.sum()
elif reduction == "none":
... | 4cfd19ecefeadd1a8208de6e5f848b7164e6c3d1 | 61,343 |
import re
def StripSingleLineComments(
string: str, start_comment_re: str = "(#|//)",
) -> str:
"""Strip line comments from a string.
Args:
string: The string to strip the comments of.
start_comment_re: The regular expression to match the start of a line
comment. By default, this matches Bash-sty... | 73670417a90d383051f93e5181c52e1d352751a9 | 61,347 |
def deduce_environment_variable(option_strings: list) -> str:
"""Deduce the environment name from the long option name of the parameter.
Every parameter has a long named option and is last in the list. The last
in the list will be assumed to resemble the environment variable.
E.g. "-q", "--query_ip", ... | 6a41f97fce32aedfe712683c106e47fc3973f295 | 61,350 |
import requests
def send_request(body, url, token):
"""
Sends a request to a SOS using POST method
:param body: body of the request formatted as JSON
:param token: Authorization Token for an existing SOS.
:param url: URL to the endpoint where the SOS can be accessed
:return: Server response to... | ec092d7ebf7f8f2002795465f04804f19f094c90 | 61,351 |
import json
def convert_to_json(data):
"""Convert data into json format"""
data = json.loads(data)
return data | d5993ea405ec8a59999706e52c887eb05b1336fe | 61,355 |
import string
import random
def random_string(min_length: int = 1, max_length: int = 150):
"""
Generate a random string.
Args:
min_length(int): minimum length of the generated string
max_length(int): maximum length of the generated string
Returns:
str: a string of random char... | 0d52690322da2342e8288f1ca371a9f552314aaf | 61,356 |
def is_using_reverse_process(input_shape):
"""Check if output of attention meachanism is a single
Attention matrix or 2 attention matrices - one for A_in
one for A_out
[description]
Arguments:
input_shape {[tuple]} -- input_shape
"""
# dimension of attention layer output
dim =... | 885559ec584cb2e0a7dec8bcd0392a510187bc62 | 61,358 |
def nodelabel2line(label: str):
"""Given a node label, return the line number.
Example:
s = "METHOD_1.0: static long main()..."
nodelabel2line(s)
>>> '1.0'
"""
try:
return str(int(label))
except:
return label.split(":")[0].split("_")[-1] | 41b87f3a9e7f4a628f818be96fe3767960837f29 | 61,360 |
import time
def getTimeLeft(to, start, position, end):
"""Return the time left in the loop."""
return (end - position) * (time.time() - to) / (position - start) | acb285a4c6e691a620673754249963d806be3d61 | 61,363 |
def my_subreddits(client, status, limit):
"""
return a list of subreddits an account is subscribed to.
client requires running accounts.user_login() first to start a user session
status: 'subscriber', 'moderator', 'contributor'
limit: max of 100
> my_subs = my_subreddits(client, 'contributor... | a6369110d8e84e644697f6536c896318eed1a4ad | 61,364 |
def merge_parameter_lists(*parameter_definitions):
"""
Merge multiple lists of parameters into a single list. If there are any
duplicate definitions, the last write wins.
"""
merged_parameters = {}
for parameter_list in parameter_definitions:
for parameter in parameter_list:
... | c5dd6521dcd0e3a3961a9d1438b34c6159149c1d | 61,367 |
def parse_platform(platform):
"""Split platform into OS name and architecture."""
assert '-' in platform
# platforms can have multiple hyphens e.g. linux-cos5-64 Our
# goal here is to separate the general name from the
# bit-width.
pieces = platform.rsplit("-", 1)
return (pieces[0], pieces[1... | 7236a13edc29d4c5025461216e957a9d5f1ed451 | 61,369 |
def active_mode_french(raw_table, base_index):
""" Convert mode to french """
value = raw_table[base_index]
if value == 0:
return "Antigel"
if value == 2:
return "Nuit"
if value == 4:
return "Jour"
return "Inconnu" | 9c3f491b6137ae817b137913002c3f4ae327bc9b | 61,373 |
def name_is_special(method_name):
"""Returns true if the method name starts and ends with two underscores."""
return method_name.startswith('__') and method_name.endswith('__') | fecb067fa2564167af515522e57031735cdbae83 | 61,374 |
import re
def get_list_or_none(pattern, text):
"""
Similar function to get_value_or_none except in this case we want our match
to be a list of strings instead of a single string.
For example if our match is 'Slovenia, Croatia, Serbia' we would rather have this information split
into a list of cou... | 2442f8d2b22a897d5b9cc467f1f6745242410e97 | 61,381 |
def commit_to_the_database(p_my_connection):
"""Called to commit (agree to) the changes proposed to the database. Returns None."""
p_my_connection.commit()
return None | 547bc92c237fcecaa663e301eb784b63d1284efb | 61,384 |
def _op_is_ok_to_apply(i, n_local_discretes):
"""Returns whether applying a 7-discrete building_block with the ith discrete of the system
being the left-most of the 7, is okay, if there are n_local_discretes local
discretes in total. "Being okay" refers to being able to do the matrix product
without causing pad... | d0fe99ba5df1bb3c0aaaf8f5d5c9baf4b00063c6 | 61,385 |
def _get_discussion_styles(_helper_cfg):
"""This function defines (when present in the configuration) the enabled discussion styles in the environment.
:param _helper_cfg: The configuration parsed from the helper configuration file
:type _helper_cfg: dict
:returns: List of enabled discussion styles in ... | 131eb14e15f09ca84ac0b737448e5f0463cf52cd | 61,387 |
def read_file(filename):
"""
Read input file and save dots and folds.
:param filename: input file
:return: list of dots, list of folds
"""
dots = []
folds = []
max_x = 0
max_y = 0
with open(filename, 'r', encoding='UTF-8') as file:
for line in file:
if ',' in ... | 0670f3bdcd34a166d24a0742b1f9e13f22a5e005 | 61,388 |
def reverse_remap_to_dict(data: list):
"""
From a list of dictionnaries of values, remap the
different items to create a dict where the keys
are a list of values
Parameters
----------
data (list): [{'a': 1}, {'a': 2}]
Returns
-------
list: list of dictionnaries
"... | 33eb999fbe2ba3a350b53d5394b82cd311738e2f | 61,389 |
def listify(items):
"""Puts each list element in its own list.
Example:
Input: [a, b, c]
Output: [[a], [b], [c]]
This is needed for tabulate to print rows [a], [b], and [c].
Args:
* items: A list to listify.
Returns:
A list that contains elements that are listifie... | 07fd8597d9fe2524b74810fcc85d60b4f05017f3 | 61,393 |
def abbrev_prompt(msg: str, *options: str) -> str:
"""
Prompt the user to input one of several options, which can be entered as
either a whole word or the first letter of a word. All input is handled
case-insensitively. Returns the complete word corresponding to the input,
lowercased.
For exa... | bf3702f9254a8fe1f5879ecff987a9fb3d9ce81c | 61,394 |
def validate(data, required_fields):
"""Validate if all required_fields are in the given data dictionary"""
if all(field in data for field in required_fields):
return True
return False | bd53351007bd1de3934b0a5245437c3889091573 | 61,397 |
def next_pos_from_state(state):
""" Function that computes the next puck position
From the current state, the next position of the puck is computed
but not set.
Returns:
dict: coordinates
"""
xn = state['puck_pos']['x'] + state['puck_speed']['x'] * state['delta_t']
yn = state['puck... | 61eb3fef17706be5f15a41757580d12fada1f810 | 61,400 |
from pathlib import Path
def _private_key_verified(key_path):
"""
Verify private key exists
Arguments:
key_path (str):
Path to private key
Return:
boolean
"""
private_key = Path(key_path).expanduser()
return private_key.exists() | 373bd69257b0612f26dc9f96c5c6355dbb9c9dca | 61,404 |
def split_3d_array_into_channels(arr):
"""Split 3D array into a list of 2D arrays.
e.g. given a numpy array of shape (100, 200, 6), return a list of 6 channels,
each with shape (100, 200).
Args:
arr: a 3D numpy array.
Returns:
list of 2D numpy arrays.
"""
return [arr[:, :, i] for i in range(arr... | 9c41ec61c41f386cbfecdeea355a2ddede083e55 | 61,409 |
def negative_grad(orig, grad):
"""Returns -grad"""
return [-grad] | 6ba15b92ae8f78d020a1df44c572b631efe9e6db | 61,411 |
def _ParseAppServers(app_servers):
"""Parse the app servers for name and project id.
Args:
app_servers: list|str|, a list of strings defining the Google Cloud Project
IDs by friendly name.
Returns:
A dictionary with the friendly name as the key and the Google Cloud Project
ID as the valu... | 7bd3bf9c62e7dd7737995a04d968ea1cec8c4005 | 61,413 |
def caseless_uniq(un_uniqed_files):
"""
Given a list, return a list of unique strings, and a list of duplicates.
This is a caseless comparison, so 'Test' and 'test' are considered duplicates.
"""
lower_files = [] # Use this to allow for easy use of the 'in' keyword
unique_files = [] # Guarante... | 6bbf93c5993ffd6c600847ecbcd0998820224c0a | 61,414 |
def _string_to_float(string_list):
"""
Converts a list of string values to float values.
:param string_list:
:return:
"""
return map(float, string_list) | ffc2dcdb6319712e9b576e7ec9dbfa3a0eaaef53 | 61,417 |
def apply_scale_offset(scale, offset, value):
"""Apply scale and offset to the given value"""
return (value + offset) / scale | 50850cb1a95dddfdcf127cc3993c9ac3ff9e748a | 61,421 |
def force_zero_resource_area_constraint_rule(backend_model, node, tech):
"""
Set resource_area to zero if energy_cap_max is zero
(i.e. there can be no energy_cap, so similarly there can be no resource_area)
"""
return backend_model.resource_area[node, tech] == 0 | b7f97931f9eb21d7bc81248c109c95a21640b7a6 | 61,422 |
def float_to_str(source: float) -> str:
"""Converts an float to a str."""
return str(source) | 25044a627765c9a1742c5bc176e3811f4eef14ed | 61,423 |
import math
def round_repeats(repeats: int, depth_multiplier: int) -> int:
"""
Round off the number of repeats. This determine how many times to repeat a block.
"""
return int(math.ceil(depth_multiplier * repeats)) | 160145c60d71de99905721d85ce85bbfb390cb59 | 61,424 |
import string
import click
def validate_bigip_name(ctx, param, value):
"""
Big-IP is kinda picky about names. Names with special characters
will (mostly) get rejected, and some (slashes) will lead to unexpected
results (path traversal). Best not to accept names like that.
"""
if not value:
... | 46bffbb79d24ccd3b26bbf2a888bfedf7ac60264 | 61,427 |
def getJob(config, args):
"""Identify the job in the Config that matches the command that was sent to Skelebot"""
job = None
for configJob in config.jobs:
if args.job == configJob.name:
job = configJob
return job | 08036ea0cc574a41580a7e4418ef2487b6b07f00 | 61,432 |
def edx_rtd_url(slug):
"""Make a RTD URL for a book that doesn't branch for each release."""
return f"https://edx.readthedocs.io/projects/{slug}/en/latest/" | ebac4f30156d8bd2711a9262026d548b7faddbfe | 61,433 |
def report_writer(md):
"""
Reads meta data into function and makes txt message report.
----------
md : dict
Contains meta data from experiment file
Returns
-------
message : string
The text output for the report
"""
s_name = md["sample_meta_data"]["sample_name"]
s... | 16d67de3ca6f858aeea1f1a652ab4946a6c60cc0 | 61,436 |
def flipMultiDict(eDict, fDict):
""" Make a dict keyed off the values of two dicts
Args:
eDict,fDict: Two dictionaries with hashable values
Returns:
A dictionary in this form: (eValueSet,fValueSet):key
"""
inv = {}
allKeys = eDict.viewkeys() | fDict.viewkeys()
for k in allKeys:
eVal = frozenset(eDict.get... | bbe766d64861753cba44fb29737fa59d4eb38fb2 | 61,443 |
def cssname(value):
"""Replaces all spaces with a dash to be a valid id for a cssname"""
return value.replace(' ', '-') | d374d84482d062fde387a967f7d790985e87033c | 61,445 |
import hashlib
def cat2hash(category):
"""
Hash a category string in order to be usable in dict for example.
:arg str category:
A category string.
:returns:
A hash of this category string
"""
return hashlib.md5(category.encode('utf-8')).hexdigest() | 66dd6c34f59e65ad82ae812edc577ec28b430f15 | 61,446 |
def example(a: int, b: int) -> int:
"""
Returns the sum of a and b, except one or both are 0 then it returns 42.
:param a: The first operand
:type a: int
:param b: The second operand
:type b: int
:returns: The conditional sum
:rtype: int
.. testsetup::
from <%= rootPackage... | aac4b49706753f40390277d9c19de08323e96799 | 61,449 |
def _read_csv_lines(path):
"""
Opens CSV file `path` and returns list of rows.
Pass output of this function to `csv.DictReader` for reading data.
"""
csv_file = open(path, "r")
csv_lines_raw = csv_file.readlines()
csv_lines_clean = [line for line in csv_lines_raw if len(line.strip()) > 0]
... | ab147d1e8e9fa7e4c41b96bed4c2a9373fb39c1c | 61,450 |
def fix_dims_for_output(forecast_dataset):
"""Manipulate the dimensions of the dataset of a single forecast so that we
can concatenate them easily."""
return (
forecast_dataset.stack(
{"forecast_label": ["forecast_year", "forecast_monthday"]}
)
.expand_dims("forecast_tim... | 0754937845ef3a31e0d96b5812903e3b10a8656d | 61,453 |
import pwd
def system_user_exists(username):
""" Check if username exists
"""
try:
pwd.getpwnam(username)
except KeyError:
return False
return True | 229c02197a15eece3c6118d73384be4e754372da | 61,455 |
import io
def compact_decode(b:bytes) -> int:
"""Converts bytes with compact int to int"""
stream = io.BytesIO(b)
i = stream.read(1)[0]
if i >= 0xfd:
bytes_to_read = 2**(i-0xfc)
return int.from_bytes(stream.read(bytes_to_read), 'little')
else:
return i | 21cc236e8660077e74feaea7381a6f1798abf986 | 61,456 |
import zipfile
import tempfile
def training_model_archive(filepath):
"""
Create zip archive file for training model.
:param filepath:
:return: temporary archive file
"""
if zipfile.is_zipfile(filepath):
return open(filepath, 'rb')
tmp_file = tempfile.NamedTemporaryFile(suffix='.zip... | 4d8dd1d6166c50d8c368cb34599126ab7d838333 | 61,459 |
def isblank(s):
"""Is this whitespace or an empty string?"""
if isinstance(s, str):
if not s:
return True
else:
return s.isspace()
else:
return False | 1b61202a679fcf89bbbc7f7d1409b4715c824afa | 61,461 |
def durationBucket(durationStr):
"""
Return string category label for call duration
"""
duration = int(float(durationStr))
if duration < 60:
return "0 to 1 min"
elif duration < 120:
return "1 min to 2 min"
elif duration < 180:
return "2 min to 3 min"
elif duration... | cc4d091303333d1f9a634cc47f4a5b508943c783 | 61,467 |
import random
def point1(parent1, parent2):
"""Basic 1 point crossover for lists"""
if len(parent1) < 2:
return []
parent1, parent2 = list(parent1), list(parent2)
point = random.randint(1, len(parent1) - 1)
return [parent1[:point] + parent2[point:],
parent2[:point] + parent1[p... | 455bcaddd42810762b0a805e069a02a55b48f144 | 61,473 |
def det(r1, r2, r3):
"""Calculates the determinant of a 3x3 matrix with rows as args.
Args:
r1: First row
r2: Second row
r3: Third row
Returns:
Determinant of matrix [r1,r2,r3]. Functionally equivalent to
jnp.linalg.det(jnp.array([r1,r2,r3])), but jits 10x faster for large batch.
"""
r... | 9f445bbe9b0d60242096f649ca5868ed40ff2589 | 61,475 |
def _get_lim(q, qlim):
"""Gets the limits for a coordinate q."""
if qlim == 'range':
return min(q), max(q)
else:
return qlim | fe8bc53f110653403b0bd9726973ccde8ccb1e37 | 61,482 |
import tempfile
def create_tmp_f(content=None, mode="w"):
"""Create a temporary file
Parameters
----------
mode : str, optional
Write-mode [default: 'w']
content : str, optional
The content to write to the file
If `None`, leave the file empty
Returns
-------
str... | 128b855840648f8d795a4d1504d2dc12e291b336 | 61,484 |
def find_node(nodes, attribute, value):
"""Search among nodes by attribute.
Args:
nodes: list of nodes
attribute: attribute name
value: attribute value
Returns:
First matched node
Raises:
IndexError if unable to find the node
"""
return [
node f... | 88b0d9e938112a9130af2952e664d05e92577382 | 61,487 |
def get_mixins_attrs(mixins):
"""
Merges attributes from all mixins
"""
attrs = {}
if mixins:
# just make all those mixin classes inherit in to one
Mixin = type('Mixin', tuple(mixins), {})
for k in dir(Mixin):
if not k.startswith('__') or k in ['__unicode__', '__s... | a207d4b65bf3f9a1399eccc0b3af32c336c9b0aa | 61,488 |
def auth_headers(auth_token):
"""Return HTTP authentication headers for API requests.
Kwargs:
auth_token: valid API token.
Returns a dict that can be passed into requests.post as the
'headers' dict.
"""
assert auth_token is not None, (
u"No valid HipChat authentication tok... | 3f4598bd0b4d1d6021a53de5088e0dc854c16fe2 | 61,490 |
def fix_metadata(ds):
"""
Fix known issues (from errata) with the metadata.
"""
# https://errata.es-doc.org/static/view.html?uid=2f6b5963-f87e-b2df-a5b0-2f12b6b68d32
if ds.attrs["source_id"] == "GFDL-CM4" and ds.attrs["experiment_id"] in [
"1pctCO2",
"abrupt-4xCO2",
"histori... | 9723436e90bf4b3a9c4955869a6751e74d97968d | 61,492 |
def classname(obj):
"""
Returns object class name
"""
return obj.__class__.__name__ | 636dbaf5d40fca66c3e0b5dbba6188e9b4830f4d | 61,496 |
def get_database(conn, name):
"""Gets an arangodb database safely
Returns an instance of an Arango database. If the database does not exist
a new one will be created.
:type conn: Connection
:type name: str
:rtype: Database
"""
if conn.hasDatabase(name) is False:
return conn.cr... | a0910d5ef15162a273cd217d48e9289fb04e0228 | 61,500 |
def is_between(a, b, c):
"""
Determine if point b is between point a and c
:param a: One end of our line
:param b: Point we are checking
:param c: Other end of our line
:return: Boolean: True if on the line formed from a -> c, else False
"""
dotproduct = (c[0] - a[0]) * (b[0] - a[0]) + (... | b2a70ecaada50b664d5c830a4adca6d033244a80 | 61,505 |
import time
def datetime_to_ms(dt):
"""
Convert an unaware datetime object to milliseconds.
This datetime should be the time you would expect to see
on the client side. The SMC will do the timestamp conversion
based on the query timezone.
:return: value representing the datetime in millisecon... | af66e06b94f7e94414edc33a203f3c71b335a4b3 | 61,506 |
def relativeSize(bbox1, bbox2):
"""
Calculate the relative size of bbox1 to bbox2.
:return: (sx, sy) where bbox1_width = sx * bbox2_width, etc.
"""
sx = (bbox1[2]-bbox1[0]) / (bbox2[2]-bbox2[0])
sy = (bbox1[3]-bbox1[1]) / (bbox2[3]-bbox2[1])
return (sx, sy) | e5477ad9921628470a78161ec46ed6f48531e144 | 61,509 |
def backend_name(setup_backend_pars):
"""The name of the currently tested backend."""
return setup_backend_pars[0] | c892c4719bc7c9ac94f7e52579829d5cd1003329 | 61,514 |
def number_of_words(input):
"""Return number of words in a string.
"""
return len(input.split()) | 8b6ee07c7ab81fe68cbc79efbfdd519a3fa9ffbe | 61,515 |
def MinimalBpseqParser(lines):
"""Separate header and content (residue lines).
lines -- a list of lines or anything that behaves like that.
The standard bpseq header (from the CRW website) is recognized. Also,
lines that contain a colon are accepted as header lines.
Header lines that aren't ac... | e877150348e43341e764f16b2e2774c29df9afc5 | 61,516 |
import torch
def im2col(img, win_len, stride=1):
"""
INPUTS:
- img: a b*c*h*w feature tensor.
- win_len: each pixel compares with its neighbors within a
(win_len*2+1) * (win_len*2+1) window.
OUTPUT:
- result: a b*c*(h*w)*(win_len*2+1)^2 tensor, unfolded neighbors for each pixel
"""
b,c,_,_ = img.size()... | 302798cc735439c18c1cbd92d09a38962f123753 | 61,518 |
def compute_loss(target, output, criterion, weights, args, model, data):
"""
Compute the loss.
:param target: target labels
:param output: predicted labels
:param criterion: loss criterion
:param weights: the weight per task / label
:return: the computed loss
"""
loss = criterion(ou... | 51e2d662c456901514cb82bad2a14d8f146279e1 | 61,523 |
def isSameNode(node1, node2):
"""Compare two nodes, returning true if they are the same.
Use the DOM lvl 3 Node.isSameNode method if available, otherwise use a
simple 'is' test.
"""
if hasattr(node1, 'isSameNode'):
return node1.isSameNode(node2)
else:
return node1 is node2 | a3c1021811580e259c9005bc40a843f272b5036d | 61,525 |
def count(dependencies):
"""
Count the number of dependencies in a list.
Ignores any comments (entries starting with #).
"""
return len([i for i in dependencies if not i.strip().startswith("#")]) | 614913f63842eacd6bd858501d68d3862ac13cb1 | 61,526 |
from google.cloud.ndb import context as context_module
def get_batch(batch_cls, options=None):
"""Gets a data structure for storing batched calls to Datastore Lookup.
The batch data structure is stored in the current context. If there is
not already a batch started, a new structure is created and an idle... | e54893bbe62149c1e918027365c6d2e9660d806c | 61,528 |
import sympy
def rref (A):
"""Compute the reduced row echelon for the matrix A. Returns
returns a tuple of two elements. The first is the reduced row
echelon form, and the second is a list of indices of the pivot columns.
"""
m = sympy.Matrix (A)
return m.rref() | 2d796f8c48e2a88d87358b03158623ff04c64a48 | 61,530 |
def format_obj_keys(obj, formatter):
"""
Take a dictionary with string keys and recursively convert
all keys from one form to another using the formatting function.
The dictionary may contain lists as values, and any nested
dictionaries within those lists will also be converted.
:param object ... | 9d4e5ea2692e3e65e2b12c2134c775ef16e0a6d7 | 61,532 |
def gsetting_to_R(G, oldmezz=False):
"""This function converts an analog gain setting into the corresponding effective
resistance set in the switchable resistor.
Parameters
----------
G : Integer [0, 15]
Mezzanine gain setting
oldmezz : Boolean, default=False
For use with the R... | c8ab1083cc69404d1140ac7ac26ff8746728b7a1 | 61,534 |
def list_startswith(l, prefix):
"""Like str.startswith, but for lists."""
return l[:len(prefix)] == prefix | aef517c04a0eb12886a029ad8ea8247c3767cfbf | 61,535 |
def create_category(session, displayname, file_extensions,
return_type=None, **kwargs):
"""
Create a new file lifecycle category with its file extensions.
:type session: zadarapy.session.Session
:param session: A valid zadarapy.session.Session object. Required.
:type displayna... | b6626ac4d7b8c611d564f5cd5773bfff6b3cd7f9 | 61,537 |
def init_similar_images(paths_files_source):
"""Return empty dictionary of lists, where keys are names of source images"""
similar_images = {}
for source_path_file in paths_files_source:
similar_images[source_path_file] = []
return similar_images | 117d22436b83915b38661b63df63aa1998057aa4 | 61,539 |
def get_dependencies(requirements_file_path):
"""read dependencies from requirements.txt"""
with open(requirements_file_path, 'r', encoding='utf-8') as fstream:
dependencies = fstream.read()
return dependencies | 3abb2447c86948e68038ce9735c25b1742bbcb55 | 61,545 |
def convert_value(var):
"""Convert the metric value from string into python type."""
if var["type"] == "number":
return float(var["value"])
if var["type"] == "boolean":
return var["value"] == "true"
if var["type"] == "string":
return var["value"]
print("can't convert unknown... | 52dc9ebe2f66de7638dc8f5ab8261c1e2f76e199 | 61,546 |
import functools
def wraps_py2(wrapped, *args):
"""Wrap a function and add the __wrapped__ attribute.
In Python 2, functools.wraps does not add the __wrapped__ attribute, and it
becomes impossible to retrieve the signature of the wrapped method.
"""
def decorator(wrapper):
functools.upda... | e382827fc21bf7f839a8a18fc91a2c8064ac3b35 | 61,547 |
def text_questmark(text_content):
"""
处理文本中的问号
:param text_content:处理对象文本
:return: 是否含有问号(1:有,0:无),问号数量
"""
en_questmark_nums = text_content.count("?")
cn_questmark_nums = text_content.count("?")
if(en_questmark_nums + cn_questmark_nums > 0):
return 1,en_questmark_nums + cn_quest... | 9145595672317e7d5cdaadc8c1d94e686dfa94ba | 61,550 |
from typing import Dict
from datetime import datetime
def transform_metadata(record) -> Dict:
"""Format the metadata record we got from the database to adhere to the response schema."""
response = dict(record)
response["info"] = {"accessType": response.pop("accessType")}
if "createDateTime" in respons... | 4555946b9202a2d174eea96379c22d09e19846a1 | 61,552 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.