content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def get_height(prms):
"""prms = ObjParams(shape, r, fi, args, color)"""
return prms.shape.get_height(prms.args) | 9fd7a0bb61ffd68d645560787413495a30937806 | 44,761 |
def create_extension_client_fixture(mgmt_client, get_extension_client_class):
""" Test fixture: Create Extension Client (Factory)"""
def _func(**kwargs):
component = kwargs.pop('component', 'as3')
version = kwargs.pop('version', None)
use_latest_metadata = kwargs.pop('use_latest_metadat... | 7920131cd9b998c9cc64c96dc2722f81e58461af | 44,762 |
def find_range(index, window, max):
""" find the left and right endpoints of a window in an array
:param index: index window is to be centered at
:param window: the length of the window
:param max: the size of the array
:return: left and right endpoints of the window
"""
half_window = int(w... | f4bc4cd41b0c3d30c906bbf8f2e7449b0ca118de | 44,763 |
def find_crop_size(crop_array, size = 15):
""" Goes thorugh rotated crop_array and finds values with 255. Marks the first and last position of those values and widens the crop coordinates by "size" in pixels.
"""
nrows = len(crop_array)
ncols = len(crop_array[0])
first_coord = (0, 0)
last_coord ... | 86b4ee37aec9e6a156c3f8d849bf9e04135aa054 | 44,764 |
def validate_comma_separated_list(setting, value, option_parser,
config_parser=None, config_section=None):
"""Check/normalize list arguments (split at "," and strip whitespace).
"""
# `value` is already a ``list`` when given as command line option
# and "action" is "... | acef867cb2c9c49ad44245cecfc6e78dc56824ab | 44,765 |
import os
def GenerateUploadDict(base_local_path, base_remote_path, pkgs):
"""Build a dictionary of local remote file key pairs to upload.
Args:
base_local_path: The base path to the files on the local hard drive.
base_remote_path: The base path to the remote paths.
pkgs: The packages to upload.
R... | a65c57f6b9e3eb4e07e7400ccbb8e75a0ced1d2e | 44,766 |
def MSD(Z, Y):
"""Compute the mean square distortion (MSD) between Z and Y
Parameters
----------
Z: torch.Tensor of shape (n_samples, n_features)
Tensor to be compared
Y: torch.Tensor of shape (n_samples, n_features)
Tensor to be compared
Returns
-------
msd: float
... | 7b13824a4898cbc20609d1a67600298a44cff7c3 | 44,767 |
def get_product_metadata(product_file):
"""
Metadata appended for labels xr.DataArray
"""
return dict({"product_file": product_file}) | 42961dca05a6846c7065879110e0711df2edce4a | 44,768 |
def static_vars(**kwargs):
"""Add static variables to a method.
To add the variable :py:obj:`counter` to :py:meth:`foo` :
.. code-block:: python
@static_vars(counter=0)
def foo():
foo.counter += 1 # foo.counter is incremented on every call to foo
"""
def ... | ec41feaf8252dd8e870582cb9b8b125f498d0d46 | 44,769 |
import torch
def avg_disp(y_pred, y_true):
""" Average displacement error. """
y_true, masks = y_true
seq_lengths = masks.sum(1)
batch_size = len(seq_lengths)
squared_dist = (y_true - y_pred)**2
l2_dist = masks * torch.sqrt(squared_dist.sum(2))
avg_l2_dist = (1./batch_size) * ((1./seq_l... | a97ca860dbc13d857ebfd46a5f831e6f07dc8c5f | 44,770 |
import random
def rollDice(inputArray):
"""Simulate rolling dice. Accepts array size of three. Returns a int value representing the total."""
diceValue = []
for x in range (0,int(inputArray[0])):
diceValue.append(random.randint(1, int(inputArray[1])))
print("Dice rolls: [%s]"%','.join(map(str,... | 897a9329a4464705c57ee4ebf8fe0f764424c29c | 44,771 |
import os
import logging
def generate_summaries(run_folder, output_folder):
"""
Creates text summary output from a MiSeq run using InterOp software
:param run_folder: path to MiSeq run folder
:param output_folder: path to output folder
:return: list of paths to each text file produced
"""
... | 3805ec94bc9ee7eff95ca85af6103b452ec8bf83 | 44,773 |
def count(items: list) -> list:
"""
Generate a list of counts for each item in the input list. Outputs with highest counted item at index 0
Args:
items (list): A list of objects to be sorted
Returns:
list: A list of unique items in the input and the number of occurances for each item
... | a13697f72c67cffb2c59d30565924bab99b746de | 44,774 |
import json
def to_json(dict_):
"""
serialize dict to json
:param dict_: dict_
:returns: JSON string representation
"""
return json.dumps(dict_) | a0ee283fbcb5d56d8032a25259a01a13a0782858 | 44,775 |
def announcement_channel(will):
"""Used for retrieving the current announcement channel"""
if will.load('announcement_channel'):
channel = will.load('announcement_channel')
else:
will.save('announcement_channel', 'announcements')
channel = 'announcements'
return channel | e0b24591c147c196b4605285787d5f1d0e3fcaa1 | 44,776 |
def find_in_reference_list(reference_list, source_name):
"""Check if it is already in reference list"""
if reference_list.get(source_name):
return True
return False | a36ea3a8d33100c1c831dbb352c79008017e4f29 | 44,779 |
def null_count(df):
"""
Returns total amount of null values in the DataFrame.
"""
nulls = df.isnull().sum()
return nulls | 2e923c56b9048781aec39e68758bbdeebb39362e | 44,781 |
import subprocess
def build_ms():
"""Invoke build command on Windows."""
return subprocess.call(['msbuild', 'libMultiMarkdownShared.vcxproj',
'/p:Configuration=Release']) | f1c13fe9bb93ffcf3694b90fe40d8eece35c0415 | 44,782 |
def remove_blank_lines(lines):
"""Get all non-blank lines out of a list of lines"""
return [line_out for line_out in (line_in.strip() for line_in in lines) if len(line_out) > 0] | 6725f3f602da4ca0dc5e4d250cfd0d8b95181c15 | 44,783 |
import re
def parse_game_times(bs_times_table, team):
"""Hard coded TZ info... and oh god fix this blregghhh."""
tds = bs_times_table.find_all('td', text=re.compile(team))
td_family = [list(x.parent.stripped_strings) for x in tds]
result = []
for x in td_family:
if 'bye' not in x and len(x... | d8821dea0330fcb5fc23a273696e678cbc28ab8e | 44,785 |
import textwrap
def test_include_inherit_context(env, render):
"""
The !include tag passes given ``context`` to downstream renderers.
"""
env.write(
"file.sls",
textwrap.dedent(
"""
#!jinja|text
{{ fuubar() }}
"""
).strip(),
... | b0a22e7a15b173a3e81f0d5f6dbc51d5064b9132 | 44,789 |
def removeOutliers(data_dict,listOfOutliers):
"""
Parameters:
data_dict= The data_dict provided by Udacity.
listOfOutliers = Python List of outliers (key names)
to remove from the data_dict.
Output:
Updated data_dict where the outliers have been ... | a6a2ad32decb258b91e2497cbad5ac63b7c8c843 | 44,790 |
def merge_graphs(main_graph, addition_graph):
"""Merges an ''addition_graph'' into the ''main_graph''.
Returns a tuple of dictionaries, mapping old node ids and edge ids to new ids.
"""
node_mapping = {}
edge_mapping = {}
for node in addition_graph.get_all_node_objects():
node_id = nod... | 4518d4738be8e88b8788eaa9d8433ddaf4c46661 | 44,791 |
def perovskite_order_param(Rs_order_param=None):
""" Define an order parameter for peroskite.
"""
if Rs_order_param is None:
Rs_order_param = [(1, 0, 1), (1, 0, -1), (1, 1, 1), (1, 1, -1), (1, 2, 1), (1, 2, -1)]
Rs_in = [(3, 0, 1)] + Rs_order_param
return Rs_in | 0525349d0e0bc3cb6068d38c3e1e71732d3c8a44 | 44,792 |
def RemoveRowsWithHighNans(dataframe):
"""
param1: pandas.DataFrame
return: pandas.DataFrame
Function delete rows containing more than 50% NaN Values
"""
percent = 50.0
min_count = int(((100-percent)/100)*dataframe.shape[1] + 1)
dataframe = dataframe.dropna( axis=0,
... | fda65bfb802e6491141c7212a4c5d5e25217ca99 | 44,793 |
import json
def mock_prom(self, metric):
"""Fake Prometheus query response.
Args:
metric (dict): Input metric query.
Returns:
dict: Fake response.
"""
data = {
'data': {
'result': [{
'values': [x for x in range(5)],
'value': [0,... | b5f7c293c15703f004fa696142947b65455babda | 44,795 |
from typing import List
def smallest(number: int) -> List[int]:
"""Finds smallest number.
Examples:
>>> assert smallest(261235) == [126235, 2, 0]
>>> assert smallest(209917) == [29917, 0, 1]
>>> assert smallest(285365) == [238565, 3, 1]
>>> assert smallest(269045) == [26945, 3... | 6d7ac3bf0259923a1779e1b5e8651cd24aa516b3 | 44,797 |
def format_time(time_units):
""" Returns a formated time value (hh:mm:ss:ms). """
return ":".join(["{0}".format(time_units[inx]) for inx in range(4, len(time_units))]) | 28c622043a9b39ae1fe1e1c61ee441a5884a03a3 | 44,798 |
def first(xs, fn=lambda _: True, default=None):
"""Return the first element from iterable that satisfies predicate `fn`,
or `default` if no such element exists.
Args:
xs (Iterable[Any]): collection
fn (Callable[[Any],bool]): predicate
default (Any): default
Returns:
Any... | f4931e9d6b9044f4cffdb23961c6e33dea627083 | 44,799 |
import subprocess
def gnupg_agent_socket_path() -> str:
"""
:return: the agent socket to mount
"""
try:
result = subprocess.run(
["gpgconf", "--list-dir", "agent-extra-socket"], stdout=subprocess.PIPE
)
return result.stdout.decode("utf-8").strip()
except FileNot... | faf6be530769d83c5094a3b1fa56038dcacd18dd | 44,800 |
def _completeEdits(filteredTokens, fullSentence):
"""Given a set of tokens (along with their edit path), generates
a complete list of edit paths, adding the edit 'p' in case the
token is not in the filtered tokens.
"""
allTokens = fullSentence.split(" ")
edits = []
k = 0
for t in al... | c197742809ca67e717e59b2d16df3c81b4327794 | 44,802 |
from typing import Sequence
from typing import List
def bubble_sort_rec(seq: Sequence) -> List:
"""
Sort a sequence with the recursive bubble sort algorithm.
Parameters
----------
seq : Sequence
Returns
-------
List
"""
def rbubblesort(seq: List, length: int):
"""Re... | e9ba43daa21cf58165efce7a60dc21f0ce455076 | 44,803 |
def PerpProduct2D(a,b):
"""Computes the the 2D perpendicular product of sequences a and b.
The convention is a perp b.
The product is:
positive if b is to the left of a
negative if b is to the right of a
zero if b is colinear with a
left right defined as shortest a... | 94f6184c8c5bfb83f29d4adc40ca030931522e66 | 44,804 |
def no_intervening_genes(feat,b_feat,bed):
"""retunrs true is there are no intervening genes between feat and b_feat
NOTE feat < b_feat... sort before hand"""
if feat[0] == b_feat[0] and feat[4] == b_feat[4]:
if feat[2] >= b_feat[1]: return True
### want to skip non merged feats for now
... | 459c81408bde75f41b33fcaf8eda276d4233c2d5 | 44,805 |
def PreprocessImage(img):
"""
Preprocess for imput image.
:param actionSpaceList: action number for different tasks, which is a list.
:param img: the image.
:return: the normalized image.
"""
imgOut = img / 255.
return imgOut | 51a2b2101932e34e591610ba9ec7c929438af3fa | 44,806 |
import os
def dummy_pubkey():
"""public key fixture."""
return os.getenv("PUBLIC_KEY", "pub") | cbe50c4c516f22dc5f82646ab1e434520d6165e3 | 44,808 |
def try_key(d, key, val):
"""
d: dict
key: str
val: object
the default value if the key does not exist in d
"""
if key in d:
return d[key]
return val | 7a28f1aaf0c989675bab32f9deacc39e1f6ca9d0 | 44,809 |
def index_to_rowref(index):
"""
0ベース数字を1ベース行番号文字に変換する。
Params:
index(int):
Returns:
str:
"""
return str(index+1) | 19aab9fca0c6fadbd18aa0c6a22fc344f5eb3e0b | 44,810 |
def numpy_reflectance(cosines, ref_idxs):
"""
Calculate the reflectance using Schlick's approximation.
I have no idea whats going on in here. Stolen from:
https://raytracing.github.io/books/RayTracingInOneWeekend.html#dielectrics/schlickapproximation
Args:
cosines (numpy.ndarray): Cosine o... | 72498fb6fdcace10dc603ef65913964075586db7 | 44,811 |
def is_subset(l1: list, l2: list) -> bool:
"""
Test if l2 is a subset of l1, i.e. all elements of l2 are contained in l1 and return True if it the case, False
otherwise.
:param l1: main list
:param l2: list whose elements are to be checked (if they're in l1 or not)
:return: True if l2 is a subs... | 09831684f55af2670ac4fd7e930c574f0265483c | 44,813 |
import pprint
def format_display(opt, num=1, symbol=" "):
"""Convert dictionary to format string.
Args:
opt (dict): configuration to be displayed
num (int): number of indent
"""
indent = symbol * num
string = pprint.pformat(opt)
string = indent + string.replace("\n", "\n" + in... | 6621756ef42bd439db37fe4155ff3bf50efc5621 | 44,815 |
def _looks_like_numpy_function(func_name, numpy_module_name, node):
"""
Return True if the current node correspond to the function inside
the numpy module in parameters
:param node: the current node
:type node: FunctionDef
:param func_name: name of the function
:type func_name: str
:par... | e343f39d2388ce31f2d749d50b1c8f4e47475780 | 44,816 |
from typing import Callable
import functools
def to(data_type) -> Callable:
"""
Apply a data type to returned data from a function.
Args:
data_type: The data type to apply. Eg: list, int etc.
Returns:
Decorator that applies the data type on returned data
"""
def decorator(fu... | b0b5c43c96ea6081888ed8e212d43c8206966ddb | 44,817 |
import random
import string
import hashlib
def generate_response(wallet_address, contract_address, tokenId):
"""Unique message generator.
Args:
wallet_address (string): The address of the requesters wallet.
contract_address (string): The address of the raindrops smart contract.
tokenId... | 4b00616f331077efcdf40597a9d2223cf0bde545 | 44,818 |
import random
def create_id():
"""This function shuffles a list of IDs, and returns them to main"""
id_list = list(range(1,21)) # 20 voter_ids have been declared.
random.shuffle(id_list)
return id_list | 8fe2ec7605f9997257fbc8c70c246335c0a808ea | 44,819 |
import sys
def bits2bytes(__n):
"""bits2bytes(n, /) -> int
Return the number of bytes necessary to store n bits.
"""
if not isinstance(__n, (int, long) if sys.version_info[0] == 2 else int):
raise TypeError("integer expected")
if __n < 0:
raise ValueError("non-negative integer expected")
... | 83f6d764cdd321de7e0f6b6e92862b2cf76a2ff3 | 44,820 |
def list_nodes(base):
"""Utility function that lists Senlin nodes."""
res = base.client.list_objs('nodes')
return res['body'] | 09c42f361be4e2abcb5685b63ce202cc71822e16 | 44,822 |
def guess_mime_type(content, deftype):
"""Description: Guess the mime type of a block of text
:param content: content we're finding the type of
:type str:
:param deftype: Default mime type
:type str:
:rtype: <type>:
:return: <description>
"""
#Mappings recognized by cloudinit
s... | d5ad35c9c6acddcd1d9e284822144509eacf0bc6 | 44,823 |
def Extract_Deltas_from_Eigenvalues(l, Q, R):
""" Maps eigenvalues to delta values. """
return 2 - 2.0 / R * l * Q | 727d45f79e1958cb4f415a2ee68189863a61e50c | 44,824 |
def GetCost(term):
"""Calculate the cost of a term.
Quota is charged based on how complex the rules are rather than simply
limiting the number of rules.
A firewall rule tuple is the unique combination of IP range, protocol, and
port defined as a matching condition in a firewall rule. And the cost of a
fir... | b21755d3bb6a32dc7b1b23718b940d3169d050fc | 44,825 |
import os
def get_path(file):
""" Get the path of the input file """
return os.path.realpath(file) | 1f8e6fb4fdbd5594ede23e5ddfbd0fd560bbba40 | 44,826 |
from typing import Tuple
def convert_tuple_to_prayer_dict(tuple_data: Tuple) -> dict:
"""Convert tuple record from DB to prayer dictionary.
:param tuple_data: Prayer data from DB
:return: Dict in thr format -> {Title
Name
Prayer}
... | 172643341e7b94ee91d977706f9e21b1023664ed | 44,827 |
def is_num(val):
"""Return True if val is number, i.e. int of float."""
return isinstance(val, int) or isinstance(val, float) | e2177b70c090701f03d517bece2b3bc3d86edcac | 44,828 |
def ArgumentCountException(function: str, args: int, count: int) -> bool:
"""
Checks if the correct number of arguments were given to a specific command.
:param function: The display name given to the function making the call.
:param args: The number of arguments passed into the command.
:param coun... | a857d3af14da917690e8c33eb78f21e36838ca9d | 44,829 |
def getTier0Regex():
"""
_getTier0Regex_
Define the Tier0 states and matching regex out of the object
so it can be fetched without instancing the plugin.
This are the uncompiled regular expressions in the correct
order of the states
"""
regexDict = {'Repack': [('Merge', [r'^/Repack_Run[... | 4805b8b5afa1823aa6f9bc2bc3e6baf5b0f03579 | 44,830 |
import torch
def _softplus(x):
"""Implements the softplus function."""
return torch.nn.functional.softplus(x, beta=1, threshold=10000) | 65f83d32b949eccbf8ba5e4b2471852ffa5b9c6b | 44,832 |
def _filter_distance(barcodes, candidate, min_dist, distance):
"""Test whether {candidate} can be added to {barcodes} based on the minimum
distance between {candidate} and all barcodes in {barcodes}.
:arg list barcodes: List of barcodes.
:arg str candidate: Candidate barcode.
:arg int min_dist: Min... | d61643d1bffe21a713466b2e7bd44891b2149a33 | 44,833 |
import numbers
def combine_slices(slice1, slice2):
"""
Given two slices that can be applied to a 1-d array, find the resulting
slice that corresponds to the combination of both slices. We assume that
slice2 can be an integer, but slice1 cannot.
"""
if isinstance(slice1, slice) and slice1.step... | 15b7453dada8f33122e5e901714e5519a634f99a | 44,836 |
def add_more(*args):
"""
Arbitrary Arguments
>>> add_more(1, 2, 3)
6
"""
return sum(args) | 875ee128d4fee537cd0c2f5cdaff57ff7bec81dd | 44,837 |
def record_read_in_group(read_calls, my_call, my_phred, my_umi, read_name):
"""
Add call data from read to read_calls dictionary of name -> call.
"""
my_call_data = [my_call, my_phred, my_umi] #, my_start
# do we already have a call from this read pair?
if read_name in read_calls:
asser... | 3b3472e4d7e030ba3576e08093ced4cb80a5f423 | 44,838 |
def read_list(filename):
""" read a list of strings from file, one per line """
fd = open(filename,'r')
lines = []
for line in fd:
lines.append(line.strip())
return lines | f717a5bcc0015ff39adfb131cd3e611f77e0924c | 44,839 |
def create_fan_string(fan_id):
"""
Function which accepts a fan_id arg and returns sql string
param:
fan_id = '1234'
returns:
" AND youtube_fan_id = 1234"
"""
video_string = f" AND youtube_fan_id = {fan_id}"
return video_string | 7f444e6e60445a4347850f58f32030e06df67621 | 44,840 |
import random
def unif_minus_one(N, m):
"""Sample uniformly from 0, ..., N-1, minus m.
"""
return random.randint(m + 1, m + N) % N | ae1374cefb2b4310ca0b7b3cf1e2279b9a7adc5e | 44,842 |
def _CredentialFrom(messages, credential_data):
"""Translate a dict of credential data into a message object.
Args:
messages: The API message to use.
credential_data: A dict containing credential data.
Returns:
An Credential message object derived from credential_data.
"""
basic_auth = messages.B... | c96acdf28dab1ba60acc0c5b1bee73585c20106f | 44,843 |
import os
def getppid(space):
""" getppid() -> ppid
Return the parent's process id.
"""
return space.wrap(os.getppid()) | bad3d172f38ebdcaa90c70de01876a76820dc08c | 44,844 |
def int_lin(y1, y2, x1, x2, score):
"""Interpolates score in a linear function.
"""
return y1 + (score - x1) * (y2 - y1) / (x2 - x1) | 2b188ec699cbadd0431bc159187b6674c3ac7f89 | 44,845 |
def display(
function=None, *, boolean=None, ordering=None, description=None, empty_value=None
):
"""
Conveniently add attributes to a display function::
@admin.display(
boolean=True,
ordering='-publish_date',
description='Is Published?',
)
def is... | 10e1a0b44ea34c705754e148370b0a24baf80323 | 44,847 |
def getMode(mode):
"""
Process EAST mode code and returns reveal class
Classes are chosen by closest resemblance
:param mode: EAST mode code
:return: Reveal class
"""
if(mode == "incremental_allume"):
return "fragment highlight-red"
if(mode == "incremental_ombre"):
return... | 9bb6222c0aa8be51b28323e981bc1521f89bdb8e | 44,849 |
import numpy
def ctype(a_type):
"""
Takes a numpy.dtype or any type that can be converted to a numpy.dtype
and returns its equivalent ctype.
Args:
a_type(type): the type to find an equivalent ctype to.
Returns:
(ctype): the ctype equivalent ... | 7a7a2779253c709c39ccab588df218801703ba98 | 44,851 |
from typing import List
def check_input(map_item_to_fraction: List[dict]) -> bool:
"""
### Examples of proper input
>>> check_input([{'x':0.5, 'y':0.5, 'z':0.5},{'x':0.5, 'y':0.5, 'z':0.5}])
True
>>> check_input([{'x':0.4, 'y':0, 'z':0.5},{'x':0.6, 'y':1, 'z':0.5}])
True
### Checks for val... | 662ac812c5d8a276c3e87054f1456a7e72c1057d | 44,852 |
def refresh_vm(context, vm):
""" Refresh the given virtual machine """
vapp = vm.getVirtualAppliance()
return vapp.getVirtualMachine(vm.getId()) | b473595fcd6c8ce4d94447be22032a8fc5d068af | 44,853 |
import argparse
def create_parser():
"""Create parser object"""
parser = argparse.ArgumentParser(
description=(
'Create an asciidoc file based on '
'https://github.com/metno/py-mmd-tools/tree/master/py_mmd_tools/mmd_elements.yaml.'
)
)
parser.add_argument('-o', ... | e3cea7dbaa504b52f33f0370ad2417c15dbefca2 | 44,854 |
def check_host(host):
"""
Returns SMTP host name and port
"""
if 'gmail' in host:
return 'smtp.gmail.com', 587
elif 'yahoo' in host:
return 'smtp.mail.yahoo.com', 465
elif 'hotmail' in host or 'outlook' in host:
return 'smtp.live.com', 25 | e828039a23d788b534a9df42d97dfd4aa782ec01 | 44,855 |
def in_memory_connection_info():
""" get mock db connection string """
return ':memory:' | e52687fb29118df4c4f8b7c2bb072359fc782ca1 | 44,857 |
def do_intersect(bb1, bb2):
"""
Helper function that returns True if two bounding boxes overlap.
"""
if bb1[0] + bb1[2] < bb2[0] or bb2[0] + bb2[2] < bb1[0]:
return False
if bb1[1] + bb1[3] < bb2[1] or bb2[1] + bb2[3] < bb1[1]:
return False
return True | 12b2797254f0bdfebcc646019e261bdc21474602 | 44,858 |
def single_number_3(nums):
"""
Find single number in given array
:param nums: given array
:type nums: list[int]
:return: single number
:rtype: int
"""
def twos_comp(val, bits):
"""
Compute the 2's compliment of int value val
e.g. -4 ==> 11100 == -(10000) + 0110... | 0564c235a00afd423da652d45b3e95cb5146b33c | 44,859 |
import torch
def class_reduce(num: torch.Tensor,
denom: torch.Tensor,
weights: torch.Tensor,
class_reduction: str = 'none') -> torch.Tensor:
"""
Function used to reduce classification metrics of the form `num / denom * weights`.
For example for calculatin... | d790cee3cf30f20a0eaeedaa15a6099dbe4b2508 | 44,860 |
def get_unique_patterns(query_result):
"""
Sorts all node names,
then returns a set of tuples with only unique node names.
:param query_result: Neo4j query outcome (list of dictionaries)
:return:
"""
all_motifs = [[y['name'] for y in x['p'] if type(y) == dict] for x in query_result]
if '... | 1e30259e9aaedf8d2668955231cd2ceffa1d3caf | 44,861 |
import sys
import http.client as hc
def _apply_cn_keys_patch():
"""
apply this patch due to an issue in http.client.parse_headers
when there're multi-bytes in headers. it will truncate some headers.
https://github.com/aliyun/aliyun-log-python-sdk/issues/79
"""
if sys.version_info[:2] == (3, 5)... | e92763510030528b221f257e51e41cb06815d3d3 | 44,862 |
import time
from pathlib import Path
def _get_anonymous_file_name(ds, target_root, file_type, patient_dict):
"""
input: ds, target_root, patient_dict, file_type
output: final full_file_path
"""
# get metadata
try:
AccessionNumber = ds.AccessionNumber # Acc number
except:
A... | 4fa24f58574858be3e80a3964d193a99a33a32fa | 44,863 |
def make_readline_completer(engine):
"""Return a readline completer function for the specified engine."""
commands = engine.list_commands()
def completer(text, state):
matches = [s for s in commands if s.startswith(text)]
try:
return matches[state] + " "
except IndexErro... | 43a9e2483c9bb47975a3d4c1a5786b974300243c | 44,864 |
def normalize_execute_kwargs(kwargs):
"""Replace alias names in keyword arguments for graphql()"""
if "root" in kwargs and "root_value" not in kwargs:
kwargs["root_value"] = kwargs.pop("root")
if "context" in kwargs and "context_value" not in kwargs:
kwargs["context_value"] = kwargs.pop("con... | ff10b2f52f3d19da9353a9bbca338e92dca75500 | 44,865 |
import importlib
def _vekt(self):
"""Spaltenvektoren"""
vekt = []
Vektor = importlib.import_module('agla.lib.objekte.vektor').Vektor
for j in range(self.shape[1]):
vekt.append(Vektor([self[i, j] for i in range(self.shape[0])]))
return vekt | ed2a377991facf9eacddb9edcebe14b00167fa27 | 44,866 |
def is_app_version_ok(version):
"""
Native apps should always send the app_version when they send a request to the API.
This function returns True if the version is compatible, false otherwise.
"""
if version=="1.0":
return True
return False | 54da1fcbfa3a6bda8a1fb3438f9360a1555cf292 | 44,867 |
def repr_opcode(opcode):
"""Returns a textual representation for the given opcode.
@type opcode: int
@rtype: str
"""
opmap = {1: "open", 2: "refresh", 3: "update", 4: "notify", 5: "status", 6: "delete"}
return opmap.get(opcode, "unknown (%d)" % opcode) | 31346162db7439ddc33192b63de74081ec04febc | 44,869 |
def to_char(num):
"""
Converts class index to char
:param num: class index
:return: corresponding char
"""
if num < 10:
return str(num)
elif num < 36:
return chr(num + 55)
else:
return chr(num + 61) | 7867c09f0faec11b4ba9dce0a97123affb2cdc26 | 44,871 |
def pip_to_rez_package_name(dist_name):
"""Convert a distribution name to a rez compatible name.
The rez package name can't be simply set to the dist name, because some
pip packages have hyphen in the name. In rez this is not a valid package
name (it would be interpreted as the start of the version).
... | 6a817d5dc11b072d3b44abb56c29e853c3722873 | 44,872 |
def check_parse_errors(options, args):
"""Do validations on command line options, returning error messages, if any."""
if not options.language:
return "language parameter not informed."
elif not args:
return "base path not informed."
else:
return None | cefa9608bc37b551d8ca3f93a196ff072f67b451 | 44,873 |
def strip_characters(text: str, *args: str) -> str:
"""Remove specified characters from given text."""
for char in args:
text = text.replace(char, "")
return text | a44788dcba864aa97b8165c6668008f692a2a45b | 44,874 |
import re
import html
def format_type(expr):
"""
Format type expression for popup
Set span 'type' for types and 'tyvar' for type variables
"""
if not expr:
return expr
tyname = re.search(r'([a-zA-Z]\w*)|(->|=>|::|\u2192|\u21d2|\u2237)', expr)
if tyname:
tyexpr = expr[tyname... | 967fbfffe751cccb51a0bb7384180d2813efaafa | 44,875 |
def create_fabric(cfmclient, data, fabric_type=None):
"""
Create :A Composable Fabric.
"""
path = 'fabrics'
params = {'type': fabric_type} if fabric_type else None
return cfmclient.post(path, params, data).json().get('result') | 55151c7027c80104a1f87f634eaca48a78bf477d | 44,876 |
def uescapejs(value):
"""
Hex encodes unicode characters for use in JavaScript unicode strings, with surrounding quotes.
We benefit from the fact that for the BSP, javascript and python have the same escape sequences.
"""
data = repr(value)
return data.lstrip("u") | 6a6265345a745d09c5ef99002709430c0894205a | 44,877 |
import os
def port():
"""Port of agent under test."""
return os.environ.get("AGENT_PORT", 3000) | 6223cdb31c1b4cdacc76727b29f9111dbd2ccc48 | 44,878 |
def wrong_task(param):
"""
Never divide by 0, until You really want exception.
"""
return param / 0 | e08c722bad7af431e15fdea6c3c1c5ded7b1dbb6 | 44,879 |
def null_guess(atomic, params={}):
"""Default guess type for testing, returns empty array"""
return [] | 2e2b9cec0759833f635b4f639f41c14e1c19a30e | 44,880 |
def reduce_func(nodes):
"""Collect messages and update node representations.
Parameters
----------
nodes : NodeBatch
A batch of nodes.
Returns
-------
dict mapping 'hv_new' to Float32 tensor of shape (V, K * T)
Updated node representations. V for the number of nodes, K for ... | 647f0bda0ea6a9b77972ce571f2bd868de0a032a | 44,881 |
import math
def error_ee_split(X, Wp, Wn, lam, memory=2, device=None):
"""Elastic embedding loss function deployed on GPU.
It splits X, Wp, Wn into pieces and summarizes respective loss values
to release computation stress.
:param X: sample-coordinates matrix
:type X: torch.FloatTensor
:para... | b59fc2abb510e17e87adce4cb4e7e8fcff9be7e7 | 44,883 |
import torch
def hsv_to_rgb(input_hsv_tensor):
"""
Differentiable HSV to RGB conversion function.
:param input_hsv_tensor: Batch of HSV images [batch_size, 3, height, width]
:return: Batch of RGB images [batch_size, 3, height, width]
"""
assert len(input_hsv_tensor.shape) == 4 and input_hsv_te... | 68a802433cf42d4f2d67931db7fe4a82ddb270a8 | 44,885 |
def get_profile_info(org_vm, inst):
"""
Get the org, name, and version from the profile instance and
return them as a tuple.
"""
org = org_vm.tovalues(inst['RegisteredOrganization'])
name = inst['RegisteredName']
vers = inst['RegisteredVersion']
return org, name, vers | 1206c4aec45b33bf6f865c80a0e354125d42c554 | 44,886 |
import pandas
import numpy
def readData(fname):
"""
read in a csv file that is of the right form - rotate it (so each column is a signal)
:param fname:
:return:
"""
pd = pandas.read_csv(fname)
return [numpy.array(pd[colname]) for colname in pd.columns[1:]] | 50622908038c2a01f5f5c7c68ec5d47e34f03a66 | 44,888 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.