content stringlengths 39 9.28k | sha1 stringlengths 40 40 | id int64 8 710k |
|---|---|---|
def del_constant_start_stop(x):
"""
>>> l = [1,2,3,4]
>>> del_constant_start_stop(l)
[1, 2]
>>> l = [1,2,3,4,5,6,7]
>>> del_constant_start_stop(l)
[1, 2, 7]
"""
del x[2:6]
return x | f6b98c3d1e082588db962f6887a4035307756a0d | 109,584 |
import re
def gather_fn_handles(mc_lines, warn):
"""Gets all footnote references (handles) occuring in main content
excluding any occuring in XML comments."""
fn_handles = set()
in_comment = False
for mcl in mc_lines:
if re.match("^\s*<!---?\s*$", mcl):
in_comment = True
... | da5cd8bef220e01968005700d336e54a3dde0ee2 | 265,968 |
def get_wv1(conds):
"""
[ [wc, wo, wv],
[wc, wo, wv], ...
]
"""
wv1 = []
for cond in conds:
wv1.append(cond[2])
return wv1 | e88de170aaf091d5fa3bbde9b26690e0942b4b49 | 259,391 |
def image_zoom(img, new_size, **kwargs):
"""
Resizes an *image* (from :epkg:`PIL`).
@param img :epkg:`PIL.Image`
@param new_size size after zoom
@param kwargs additional arguments
@return new image
"""
return img.resize(new_size, **kwargs) | 24799135c293a40a13a1462d8d5c978ba5170c67 | 232,645 |
def _is_hierachy_searchable(child_id: str) -> bool:
""" If the suffix of a child_id is numeric, the whole hierarchy is searchable to the leaf nodes.
If the suffix of a child_id is alphabetic, the whole hierarchy is not searchable. """
pieces_of_child_id_list = child_id.split('.')
suffix = pieces_of_... | 13146128fc8ab050323a23f07133676caeb83aaf | 28,275 |
def _parse_limits(joint):
"""Parse joint limits."""
limit = joint.find("limit")
lower, upper = float("-inf"), float("inf")
if limit is not None:
if limit.has_attr("lower"):
lower = float(limit["lower"])
if limit.has_attr("upper"):
upper = float(limit["upper"])
... | 6aa1a31183f52b4699081e1a34860f8f7588c67f | 277,768 |
def align_embedding(sequences, padding_word="<PAD/>", max_length=-1):
"""
Pads all sentences to the same length. The length is defined by the longest sentence.
Returns padded sentences.
"""
print("aligning sequences...")
if max_length < 0:
max_length = max(len(x) for x in sequences)
... | c87670ad068f811c44621772e0ace4dbdee9de6b | 461,338 |
def _get_node(root, name):
""" Find xml child node with given name """
for child in root:
if child.get('name') == name:
return child
raise ValueError(f'{name} not found') | 4cb0d450fd1ea6fffda3366ec77ed500e6a47a9a | 406,620 |
from typing import List
from typing import Optional
from typing import Tuple
def _get_file_name(path: List[str]) -> Optional[Tuple[str, str]]:
"""Fetches the file name from the path.
Args:
path: The list of elements in the path
Returns:
None is returned on failure. If the path contains
... | 101069b6403b3da0d6b705d714943f32cd0a4810 | 331,551 |
import pickle
import zlib
def zunpickle(zdata):
"""Given a zlib compressed pickled serialization, returns the deserialized data."""
return pickle.loads(zlib.decompress(zdata), encoding='latin1') | 201ca5f014c7f3b23ddbd418541b233b3a6f1d54 | 152,194 |
def addLists(list1, list2):
"""Add lists together by value. i.e. addLists([1,1], [2,2]) == [3,3]."""
# Find big list and small list
blist, slist = list(list2), list(list1)
if len(list1) > len(list2):
blist, slist = slist, blist
# Overlay small list onto big list
for i, b in enumerate(sl... | f5469dab8fd2c62d2d3ffed253803c1a3d343281 | 702,997 |
def addYears(date, value):
"""Add or subtract an amount of years to a given date and time.
Args:
date (Date): The starting date.
value (int): The number of units to add, or subtract if the
value is negative.
Returns:
Date: A new date object offset by the integer passed ... | 0d218095921e38b92042b80e1fb8b20c62de3b28 | 537,075 |
def is_palindrome(word):
"""
Determines if the specified word is a palindrome.
Args:
word: The word to check.
Returns:
True if the word is a palindrome, otherwise False.
"""
return word.lower() == word[::-1].lower() | 606934276488a1e8e88fa59fb21b41c8da84f1d2 | 433,991 |
import torch
def random_choice(a, size):
"""Generates a random sample of a given size from a 1-D tensor. The sample
is drawn without replacement.
Parameters
----------
a: torch.tensor
The input tensor from which the sample will be drawn.
size: int
The size of the generated sam... | d47202dd08a1a5f0845c6057fbee8a0a41a0a3f9 | 83,636 |
from datetime import datetime
def as_date(x, format='%m/%d/%Y'):
"""
Convert date string to datetime object
"""
return datetime.strptime(x, format) | a4a6e11310894db0c8781a2ae70874b51a41bc5b | 396,240 |
import six
def convert_id36_to_numeric_id(id36):
"""Convert strings representing base36 numbers into an integer."""
if not isinstance(id36, six.string_types) or id36.count("_") > 0:
raise ValueError("must supply base36 string, not fullname (e.g. use "
"xxxxx, not t3_xxxxx)")
... | 5ccd3661f6985c73e38ebcb6bbf9d0e242cddbb6 | 657,389 |
def get_pbs_node_requirements(sys_settings,node_count):
"""Get the cpu and memory requirements for a given number of nodes
Args:
sys_settings (dict): System settings dict, as supplied from config_manager
node_count (int): Number of whole nodes on target system
Returns:
dict... | f4fd12dee6608a87e6c8b0f2f56e245e6be7c0fc | 8,257 |
def max_value_constraint(value, limit):
"""Test maximum value constraint."""
if value <= limit:
return True
return False | 53f9849ae2bd3ee2dd953525c6a0a0bd223c5757 | 449,304 |
def get_objname_from_tuple(obj_name_tuple):
"""Given a O, C, I tuple, return its string full name
(e.g 0&0&DEFINING_ORIGIN).
"""
O, C, I = obj_name_tuple
return str(O) + '&' + str(C) + '&' + I | 23f6bee2f1af9dfbca90eecca16a00fe5641b722 | 370,375 |
from typing import List
from typing import Any
def flatten_list(nested: List[List[Any]]) -> List[Any]:
"""Flatten a nested list."""
flat = []
for x in nested:
flat.extend(x)
return flat | ef71bf3072b74af31ff218ea0e57ba3c08e0436c | 293,176 |
def check_size(indices: list, queries: list) -> int:
""" Check whether size of all indices and queries are the same
:param list indices: list of all indices
:param list queries: list of all queries
:returns: the size when size of all indices and queries are the same or -1
if lists does no... | 7075c42042824439b6d25bffd1a5b8c2291b4012 | 549,550 |
def interpolate(r1, r2, x=None, y=None):
"""Perform simple linear interpolation between two points in 2D
- one of x or y must be defined
Parameters
----------
r1,r2 : float
x,y coordinates from which to interpolate
x : float
x-value from which to interpolate y (default: None)
... | a222293c451b5a0826ddcd5c5223f9b85c2a6510 | 315,999 |
from datetime import datetime
def is_rule_expired(rule_timestamp):
"""Returns True if the rule timestamp is expired."""
return rule_timestamp < datetime.now() | fd9c0c5f693efa53ea721a030544db5b620d2b54 | 402,323 |
def get_average(pixels):
"""
Given a list of pixels, finds the average red, blue, and green values
Input:
pixels (List[Pixel]): list of pixels to be averaged
Returns:
rgb (List[int]): list of average red, green, blue values across pixels respectively
Assumes you are returning in th... | 5e26a0aee4f719ff499f0c5ce73e8794ce40388f | 296,111 |
def doc_urls_to_string(doc_urls, queryset=False):
"""
Args:
doc_urls: [{"name": "wiki", "url": "http://www.wiki.com"}, ...] OR
doc_urls: [models.DocUrl] (if queryset=True)
Returns:
'(wiki, http://www.wiki.com), ...'
"""
if queryset:
new_doc_urls = [(i.name, i.url) for... | c89de44daec117c5e09870e4381993e08ef1b933 | 147,857 |
def check(grad_honests, f_real, defense, factor=-16, negative=False, **kwargs):
""" Check parameter validity for this attack template.
Args:
grad_honests Non-empty list of honest gradients
f_real Number of Byzantine gradients to generate
defense Aggregation rule in use to defeat
... ... | 59b11df0809cf2de7e35e23c6b9416adad3202da | 425,255 |
import torch
def smooth_weights(class_freqs: torch.Tensor,
smoothing: float = 0.15,
clip: float = 10.0,
normalize: bool = True) -> torch.Tensor:
"""Compute smoothed weights starting from class frequencies (pixel counts).
Args:
class_freqs (torc... | 75bdb480c158632dfd418582d77f3c54c3b7af8a | 288,691 |
import torch
def all_comb(X, Y):
"""
Returns all possible combinations of elements in X and Y.
X: (n_x, d_x)
Y: (n_y, d_y)
Output: Z: (n_x*x_y, d_x+d_y)
Example:
X = tensor([[8, 8, 8],
[7, 5, 9]])
Y = tensor([[3, 8, 7, 7],
[3, 7, ... | 525370a163c2c40593e6277f1f27befd1fc3be09 | 558,543 |
def surface_absorption(wave_len, wave_len_min, wave_len_max, abs_surface):
"""Determines probability of absorption as a function of wavelength at a
particular boundary.
Parameters
----------
wave_len : float
Bundle wavelength
wave_len_min : float
Minimum wavelength absorbed ... | 90cc70051f6977bdffa42e026d1a46f6d2575ba3 | 478,333 |
def calc_clf(rs, rso):
"""
Crawford and Duchon (1999) cloud fraction.
Parameters
----------
rs : numpy ndarray
Total incoming shortwave solar radiation, in MegaJoules per square meter per day
rso : numpy ndarray
Clear-sky solar radiation.
"""
clf = 1.0 - (rs / rso)
... | 47b73001f05e06bb7b01a25338c54b8398e6cf3c | 376,013 |
def get_sources(dataframe):
"""
extract sources
:param pandas.core.frame.DataFrame dataframe:
:rtype: set
:return: set of archive.org links
"""
sources = set()
for index, row in dataframe.iterrows():
sources.update(row['incident_sources'].keys())
return sources | 468c0cf6428833c9b05c06415917a516471189a5 | 700,385 |
def load_RIRE_ground_truth(file_name):
"""
Load the point sets defining the ground truth transformations for the RIRE
training dataset.
Args:
file_name (str): RIRE ground truth file name. File format is specific to
the RIRE training data, with the actual data expectd to... | 9c7747b6fad1a10fb8cbb32162a3423e31fa40f3 | 27,368 |
def print_last_word(words):
"""Prints the last word after popping it off."""
word = words.pop(-1)
print(word)
# Poop out
result = None
return result | 35b24f63921c46e8f075a0f85fe0bd6d540b2a37 | 398,375 |
def _calc_padding_for_alignment(align, base):
"""
Returns byte padding required to move the base pointer into proper alignment
"""
rmdr = int(base) % align
if rmdr == 0:
return 0
else:
return align - rmdr | 473876dc24eefadfc174c5c3cb05820085d2e1d5 | 455,332 |
def expand_onPremisesExtensionAttributes(entry):
"""
entry - a dictionary that must have the "onPremisesExtensionAttributes" key defined
This transformer takes a dictionary, and returns the same dictionary, but with the
"onPremisesExtensionAttributes" value expanded into it's own key: value pair.
T... | 3bcf88ff68fe92588f42ad27018a31d4935161d7 | 159,224 |
def splitclass(classofdevice):
"""
Splits the given class of device to return a 3-item tuple with the
major service class, major device class and minor device class values.
These values indicate the device's major services and the type of the
device (e.g. mobile phone, laptop, etc.). If you google ... | 37c19ab17293b4fd0c46cff24c30e349459f7bd0 | 707,830 |
def as_lines(content):
"""This function splits given ``content`` into lines if it's a string or
returns it as is if it's a list.
Args:
content: String or list of strings.
Returns:
List of strings.
"""
if isinstance(content, list):
return content
return content.split... | 129d95a35e3e74837d9c168df5bcd4e6c7271d5e | 598,013 |
import random
def _get_user_agent() -> str:
"""Get a random User-Agent strings from a list of some recent real browsers
Parameters
----------
None
Returns
-------
str
random User-Agent strings
"""
user_agent_strings = [
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 1... | bad887c3c3ee66bdb70f7f4fda4a925df0afb12d | 122,239 |
def is_numeric(lit):
"""
value of numeric: literal, string, int, float, hex, binary
From http://rosettacode.org/wiki/Determine_if_a_string_is_numeric#Python
"""
# Empty String
if len(lit) <= 0:
return lit
# Handle '0'
if lit == '0':
return 0
# Hex/Binary
if len(li... | 75f49677274e800af93fd9f518f05d72e8f85c6c | 313,890 |
def sql_file(tmp_path):
""" Construct a file containing a SQL statement """
directory = tmp_path / "sql"
directory.mkdir()
file = directory / "sql.txt"
file.write_text("SELECT\n 1 as foo;")
return file.absolute() | e5adb73bc24519ab7547aa2ca897bcca70e4aaca | 653,561 |
def gen_file_name(output_path, title):
"""Generates the name of the PDF-file from the "doc title" in the json file.
Args:
output_path (string): relative output path
title (string): title of the file according to content.json
Returns:
string: file_name of the pdf-file
"""
fi... | 031e5fd78e0958c3de711c33e0357f1034a5e02d | 64,598 |
def separate_hourly_vals(hourstring):
"""Separate individual hourly field means from the string containing all
24 values in the WDC file. Called by wdc_parsefile.
Args:
hourstring (str): string containing the hourly magnetic field means
parsed from a WDC file for a single day.
Retu... | 0f9cca7102f583ca747ba4928fcb3cec4d996a99 | 407,572 |
def get_child_object_data(raw_data):
"""
Returns key/value pairs that describe child objects in raw data
Args:
raw_data (dict):
Returns:
dict:
"""
return {k: v for k, v in raw_data.items() if k.startswith("[")} | 1ea57f62592de0ed17d9f45628ecd3d87313d654 | 453,077 |
def _GetMuteConfigIdFromFullResourceName(mute_config):
"""Gets muteConfig id from the full resource name."""
mute_config_components = mute_config.split("/")
return mute_config_components[len(mute_config_components) - 1] | 33b5c5598a156768dc4c87ddf5cc77d08cb6766e | 87,112 |
def list_contains(list1, list2):
"""Return True if any item in `list1` is also in `list2`."""
for m in list1:
for n in list2:
if n == m:
return True
return False | 37668fe6641f3c7c575c4b82dd6c3d1d4dfda974 | 265,023 |
import collections
def count_tokens(samples):
"""Count tokens in the data set."""
token_counter = collections.Counter()
for sample in samples:
for token in sample:
if token not in token_counter:
token_counter[token] = 1
else:
token_counter[to... | 416d3450b25c3e2d1b9ab10914b45f5f848a6608 | 193,162 |
import csv
def get_consensus_sequence(seq_info):
"""
Determine the consensus sequence of an alignment.
Definition of consensus: most common base represented at that position.
"""
def output_position_matrix(position_matrix):
output_file = open('position_matrix.csv', 'w', newline='')
... | d0c0d8ab0ebe5686514d8769bf7e00df5dd92a36 | 551,998 |
def get_repository_from_image(image):
""" Returns the first RepoTag repository
found in image. """
repotags = image.attrs['RepoTags']
for repotag in repotags:
repository, tag = repotag.split(':')
return repository | 1fd10666caea62d2412639b64ac573cefbd77a12 | 316,680 |
def poll_for_valid_message(consumer):
"""
Polls the subscribed topics by the consumer and checks the buffer is not empty or malformed.
:param consumer: The consumer object.
:return: The message object received from polling.
"""
msg = consumer.poll()
assert not msg.error()
return msg | 50e7e48cf24427101e1db52854b540ebb2d60f9f | 570,472 |
def evaluate(pred_joins, gt_joins):
""" Evaluate the performance of fuzzy joins
Parameters
----------
pred_joins: list
A list of tuple pairs (id_l, id_r) that are predicted to be matches
gt_joins:
The ground truth matches
Returns
-------
precision: float
Precis... | c8c43a7d1d0905f10f21395d162b2202186989f4 | 225,030 |
def get_grouped_by_powers(bases, powers):
"""
Groups the powers and bases in the given
`~astropy.units.CompositeUnit` into positive powers and
negative powers for easy display on either side of a solidus.
Parameters
----------
bases : list of `astropy.units.UnitBase` instances
powers :... | add38c3024ef25c04bccdab6093a32370725f654 | 453,522 |
def ad_group_ids_are_unique(df):
"""
This function returns True iff ad_group_ids are unique (only show up once in the rows of df)
"""
return len(df[['ad_group_id']].drop_duplicates()) == len(df) | 468834e05f7bb15282078fa0bb73ed82227fc18d | 599,750 |
import json
def loadSettings(save):
"""load ON, OFF and VOLUME_THRESHOLD settings from a file"""
try:
with open("./settings/" + save+".json", "r") as f:
data = json.load(f)
print("Loaded settings")
return data["off"], data["on"], data["vol"]
except Exception as ... | 6010dc5b1e7e51d5a2da905c0906236090c8a2d1 | 295,198 |
def _function_iterator(graph):
"""Iterate over the functions in a graph.
:rtype: iter[str]
"""
return (
node.function
for node in graph
) | aaff945176f3d5754a4381cb74ad5a660a298556 | 691,013 |
from typing import Iterable
from typing import Any
def join(items: Iterable[Any], s: str) -> str:
"""Join items (probably of an array).
Example usage:
myArray|join:','
"""
return s.join(items) | 30480c3582cd7e602a7d5108b820c573908b4c22 | 561,833 |
def win_ts_to_unix_epoch(high, low):
"""Convert Windows timestamp to POSIX timestamp.
See https://goo.gl/VVX0nk
Args:
high (int): high 32 bits of windows timestamp.
low (int): low 32 bits of windows timestamp.
Returns:
float
"""
return high * ((2 ** 32) / 1e9) + low / ... | 6f309ec4255dd8063814ad329984f0d80afd6b36 | 79,499 |
import torch
def get_minibatch(t, y, nsub=None, tsub=None, dtype=torch.float64):
"""
Extract nsub sequences each of lenth tsub from the original dataset y.
Args:
t (np array [T]): T integration time points from the original dataset.
y (np array [N,T,d]): N observed sequences from the orig... | 7773b86be5966306c3d33827ef49353b9525f8bf | 459,783 |
def build_dependency_list(deps, version_prefix=''):
"""Build a list of dependency specifiers from a dependency map.
This can be used along with :py:data:`package_dependencies`,
:py:data:`npm_dependencies`, or other dependency dictionaries to build a
list of dependency specifiers for use on the command ... | 910a250a45a21025a47ff2695f11b56d1cee910f | 170,646 |
def get_snapping_pos_line_chart_vertical(data_objects, line_pos):
"""
Calculates the nearest pos of and objects from a line chart with an vertical line.
:param data_objects: The nodes of the data objects in the chart.
:type data_objects: dict[str, PolyLineNode]
:param line_pos: The necessary positi... | bb0db8aa9280d21119fd07d85b3046453fa4ffda | 641,467 |
import collections
def read_csv(path):
"""Read data from a CSV file.
Parameters
----------
path : str
Path to the CSV file produced by the `ChessAnalysis` program.
Returns
-------
data : dict
Dictionary mapping player names to a sequence of rating values.
"""
data... | 2fc9dee72997eebbbfdd8e1958b8a7d6ce60b265 | 287,851 |
def transposed(matrix):
"""Returns the transpose of the given matrix."""
return [list(r) for r in zip(*matrix)] | 30835a1583f365b558c39e8fd1b459e79e85448e | 638,027 |
import torch
def get_backward_segment(backward_rnn_output, s, e, device):
"""Gets span representation in backward rnn
Arguments:
forward_rnn_output {tensor} -- backward rnn output
s {int} -- span start
e {int} -- span end
device {int} -- device
Returns:
tensor -- ... | 11189a690b1fb9b0420657882a47093f1099589b | 598,995 |
import math
def degToRadian(angle):
"""Convert angle from degrees to radians"""
return angle*(math.pi/180) | fcac824c69ea56e58702ead320293e760a10fe2c | 215,039 |
def get_responders(players, suggester):
""" get the responders (in the correct order) for the given suggester """
si = players.index(suggester)
return players[si+1:] + players[:si] | b64fb803c3c95ddf9080ca5bbaaf902cd61e45c2 | 430,998 |
from typing import Optional
import logging
def get_existing_handlers(handlertype) -> Optional[logging.Handler]:
"""
Returns Existing handler or None (if the handler has not yet been added to the root handlers).
"""
return next((h for h in logging.root.handlers if isinstance(h, handlertype)), None) | b5cdfbf20133fcc7629c3291f1111fe353b067af | 694,434 |
def constraints_violated(constraints):
"""
:param constraints: constraints to be evaluated
:return [0]: True if there are any constraints that are violated, false otherwise
:return [1]: Maximum violation if one or more constraints exist, else None
:return [2]: Name of the maximum constraint violated... | a9274c2f5de0eada038b8c4068acf3a510dc0146 | 107,653 |
def user_known(env, user):
"""Returns whether the user has ever been authenticated before."""
for row in env.db_query("""
SELECT 1
FROM session
WHERE authenticated=1 AND sid=%s
""", (user,)):
return True
return False | 97238304979f670fba5e3b7f2c09512e40db1f8e | 374,202 |
def xor(bytes1, bytes2):
"""
Xor two input bytes and return
Input: `bytes1`, `bytes2`: bytes need to xor.
Output: xor result
"""
return bytes([a ^ b for a, b in zip(bytes1, bytes2)]) | ac898cf412bb48482d2919a213934262e9d7ecda | 649,416 |
def parse_filename(filename):
"""Parse python and platform according to PEP 427 for wheels."""
stripped_filename = filename.strip(".whl")
try:
proj, vers, build, pyvers, abi, platform = stripped_filename.split("-")
except ValueError: # probably no build version available
proj, vers, py... | 3f301b0939ffbb5886e827d6b7fd15a96e68d0fc | 353,551 |
def get_friendly_name(name: str) -> str:
"""Get a friendly version of a name."""
return name.replace("_", " ").title() | f66c5c8205e973d3d0c0cf0ed3acf3ea0a99e840 | 146,509 |
def crowd_comparison(p, q):
"""Crowded Comparison Operator. Return 1 means p is better than q.
Return -1 means q is better than p.
"""
if p.rank < q.rank or (p.rank == q.rank and p.distance > q.distance):
return 1
elif p.rank > q.rank or (p.rank == q.rank and p.distance < q.distance):
... | ae7f484feb319477b5d90476f9e4440c551041fe | 484,200 |
def standard_rb(x, baseline, amplitude, decay):
"""
Fitting function for randomized benchmarking.
:param numpy.ndarray x: Independent variable
:param float baseline: Offset value
:param float amplitude: Amplitude of exponential decay
:param float decay: Decay parameter
:return: Fit function... | 60d67143e16307ebd2fa8581d269570590ae6774 | 651,705 |
from typing import Callable
def abstract(method: Callable) -> Callable:
"""Marks a method as abstract"""
def wrapper(*args, **kwargs):
raise NotImplementedError(f"Missing required method {repr(method)}")
return wrapper | 70462cb5232b6b3ad2ac56b19d6da65f9eb64e9d | 286,143 |
def split_obs(obs):
"""Split a dict obs into state and images."""
return obs['state'], obs['img'] | ebb043f2b75c2a9e12883ef8fe49595c3a751483 | 38,450 |
import re
def parse_event_fields(lines, idx, event_dict):
"""
Parses lines from a proto file that contain an event definition and stores it in event_dict
"""
fields = []
end_of_event = False
# record all fields in event definition.
# note: we don't check if there's a leading brace.
... | f7c229d4a0315e3e8a7d0adbf5b91a4105f36592 | 614,839 |
def filename_dist(dist):
""" Return the filename of a distribution. """
if hasattr(dist, 'to_filename'):
return dist.to_filename()
else:
return dist | 3791f8b03b254108a2a97bc725fd2802187367bd | 655,482 |
import logging
def create_ssh_key(nova_client, keypair_name, replace=False):
"""Create ssh key.
:param nova_client: Authenticated nova client
:type nova_client: novaclient.v2.client.Client
:param keypair_name: Label to apply to keypair in OpenStack.
:type keypair_name: str
:param replace: Whe... | 8b62e2378145cd9473530a390e97dd45e40a78ab | 255,236 |
def full_email(service_account):
"""Generate the full email from service account"""
return "{0}@{1}.{2}".format(service_account.name, service_account.project,
service_account.suffix) | 8b5305f794fd59b24adfefca1338db594fb799bc | 33,897 |
def str2list(string):
"""Convert a string with comma separated elements to a python list.
Parameters
----------
string: str
A string with comma with comma separated elements
Returns
-------
list
A list.
"""
string_list = [str_.rstrip(" ").lstrip(" ") for str_ in str... | 5563ef02e27f30a3316164c48148db62735a7469 | 372,242 |
def get_thirdparty_plugin(main_window, plugin_title):
"""Get a reference to the thirdparty plugin with the title given."""
for plugin in main_window.thirdparty_plugins:
if plugin.get_plugin_title() == plugin_title:
return plugin | cfa5bf6e0933fa253ed97e0efb5f3c61e466b430 | 131,350 |
def lopen_loc(x):
"""Extracts the line and column number for a node that may have an opening
parenthesis, brace, or bracket.
"""
lineno = x._lopen_lineno if hasattr(x, "_lopen_lineno") else x.lineno
col = x._lopen_col if hasattr(x, "_lopen_col") else x.col_offset
return lineno, col | 75545bb527dac4ab0ceffffbbd2c3f028ac4f898 | 666,509 |
import json
def open_vocab(vocab_path):
"""
Opens the json containing the vocabulary used for the word2vec
Args:
vocab_path : str
the path where the vocab json file is stored
Returns:
vocab_dic : dic
the vocab dictionnary
"""
with open(vocab_path, "r", e... | 4ff7d66bc53df99581c2e06f7f64aa13978c676d | 488,345 |
def CombineMetrics(loss_metric_weight_pairs):
"""Combines metrics from `loss_metric_weight_pairs` according to weights.
Keys must either exist in all metrics, in which it will be processed as a
weighted sum, or exist in only one metrics, in which case it will be copied.
Args:
loss_metric_weight_pairs: a l... | f1859a6a250dcc911cd654cac9ea8aeaa0e73deb | 409,574 |
def transform_point(point, matrix):
"""Transform point by matrix.
:param list point: 2-item list
:param list matrix: 6-item list representing transformation matrix
:returns list: 2-item transformed point
"""
x, y = point
a, b, c, d, e, f = matrix
# This leaves out some unnecessary stuff... | 92c16f1698db3e9b2d754aefb0b44a8bef2cf783 | 59,670 |
from typing import List
def match_shape(tensor, *expected_shape):
"""Compare the given tensor's shape with what you expect it to be.
This function serves two goals: it can be used both to assert that the size
of a tensor (or part of it) is what it should be, and to query for the size
of the unknown d... | 2206343129ce9b1078bcab567f3a49a66b64ecde | 600,243 |
import time
def do_work(task):
""" Sample task evaluation. Returns a result as string and an optional log message."""
time.sleep(2)
return "result", "Another information" | 3e354a7e3547428f8ab73832278838a120a9cd58 | 442,513 |
def flag(state, name, value: bool = True):
"""Set the state variable as a flag (boolean value)"""
state.vars[name] = bool(value)
return state | 7d7f42b51a900f2de647ce36ccd13bc8ae67c0b3 | 80,251 |
import json
def output_generic_from_traj(traj, out_file, name, f):
"""Creates and returns outputter function that dumps some data
about atoms to json.
The resulting file will be in the JSON Lines format, i.e. one JSON-document
on each line.
:param traj: traj object containing atoms objects.
... | 17a07cfcf13e6ef05a7a8895b30bb4432798b6f3 | 301,268 |
def is_in_period(month, period):
"""Return which months fall within a specified group of calendar months.
Parameters
----------
month : int or iterable of ints
One or a series of calendar month numbers [1..12].
period : tuple of ints
Group of calendar month numbers to match against.... | e973f1ec11ea4dc6b87834c75d6374bbbb152635 | 10,105 |
def _append_spc_date_to_storm_ids(primary_id_strings, spc_date_string):
"""Appends SPC date to each storm ID.
N = number of storm objects
:param primary_id_strings: length-N list of primary IDs.
:param spc_date_string: SPC date (format "yyyymmdd").
:return: primary_id_strings: Same as input but wi... | de5d54dfb322bdbf4ab7e261526b6e295ea1900c | 103,427 |
def get_session(monitored_sess):
""" Get Session object from MonitoredTrainingSession.
"""
session = monitored_sess
while type(session).__name__ != 'Session':
session = session._sess
return session | a377a2aeeed1cc7f625f49693adc6b1b6ee203cf | 96,268 |
def _sanitize_ipv4_mapping(ip_str):
"""
Sanitize IPv4 mapping in a expanded IPv6 address.
This converts ::ffff:0a0a:0a0a to ::ffff:10.10.10.10.
If there is nothing to sanitize, returns an unchanged
string.
Args:
ip_str: A string, the expanded IPv6 address.
Returns:
The san... | ece3a84d69eb5eefed1ca4908ea03b095644e89d | 552,015 |
def get_legacy_msg_type(identifier):
"""
Convert an SBP spec identifier to the message type #define identifier according to the legacy API
Only works for real messages, will assert when called for any other type
"""
assert identifier[:4] == "MSG_"
return "SBP_" + identifier | 213f469458298c8e8ec4b9f12156cb60db9561f2 | 322,515 |
def epsi_vapor_top(Fr_top):
"""
Calculates the vapor content of bubble layer at the top of column
Parameters
----------
Fr_top : float
The Frudo criterion at the top of column, [dimensionless]
Returns
-------
epsi_vapor_top : float
The vapor content of bubble layer at the... | 30157399f659514ef2a041fa19e7902773581ed4 | 503,544 |
def _create_sitelink_campaign_extension_setting_mutate_operation(
client, customer_id, campaign_id
):
"""Creates a MutateOperation for the sitelink campaign extension setting
that will be removed.
Args:
client: an initialized GoogleAdsClient instance
customer_id: the client customer ID.... | 28dbaf410935b3e59c655c370aecd30ab0b465a3 | 288,776 |
def mult(value, arg):
"""Multiplies the value by the arg"""
return int(value)*int(arg) | 74afbb99fa473ffbe822ea9e44a54cc0ccb27677 | 453,038 |
def make_weights_for_balanced_classes(images, nclasses):
"""
Generates weights to get balanced classes during training. To be used with weighted random samplers.
:param images: list of training images in training set.
:param nclasses: number of classes on training set.
:return: list of weights for ... | 9d48b07161c403543174548b90ebda7b04ce760f | 603,965 |
def no_op(arg):
"""Dummy do nothing function"""
return arg | 185a29bbfbcf6598d88b6a934a5bbc47017710c2 | 319,459 |
from typing import List
def read_docs(fnames: List[str]) -> List[str]:
"""
Reads in the documents.
param fnames: List of paths to .txt files to read.
returns: List of input documents.
"""
all_docs = []
for docfile in fnames:
doc = open(docfile, 'r').read()
all_docs.append(... | 26c8bd7c31ecfd84144ee5d180ae5d41353945f3 | 69,599 |
def update_trackers(frame,trackers,penalties=0,mark_new=True):
"""Update all the trackers using the new frame
Args:
frame ([type]): new frame
trackers (List[TrackerObj]): List of trackers to update
penalties (int, optional): Amount of penaltie. Defaults to 0.
mark_new (bool, opt... | 275905dbffc57639caf8a99d55a686d2f53ddf5f | 480,724 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.