content stringlengths 35 762k | sha1 stringlengths 40 40 | id int64 0 3.66M |
|---|---|---|
def script(text, interpreter="sh"):
"""Execute a shell script.
The script is passed to the interpreter via stdin and the return
code of the interpreter is returned."""
process = Popen(interpreter, stdin=PIPE)
process.communicate(input=text)
process.wait()
return process.returncode | c4dcbe40f2868099bb8986b82753ab6e00c9a1c5 | 675 |
import warnings
from typing import Optional
def mask_to_image(
mask: _T_input, batch_first: bool = False,
color: Optional[str] = None,
origin: str = 'lower'
) -> np.ndarray:
"""
Creates an image from a mask `Tensor` or `ndarray`.
For more details of the output shape, see the tenso... | a4679d78fd9df003fe91742fb0eb0707ca3fd5f8 | 677 |
def lerp(x0, x1, t):
""" Linear interpolation """
return (1.0 - t) * x0 + t * x1 | 82d9ce36dd5879c7aab64dc5615a2fb298471383 | 678 |
def read_uint4(f):
"""
>>> import io
>>> read_uint4(io.BytesIO(b'\\xff\\x00\\x00\\x00'))
255
>>> read_uint4(io.BytesIO(b'\\x00\\x00\\x00\\x80')) == 2**31
True
"""
data = f.read(4)
if len(data) == 4:
return _unpack('<I', data)[0]
raise ValueError('not enough data in stream... | 4a2ffd3f58100d44f0e430847f5a7d8ef1f54a33 | 679 |
def get_onto_class_by_node_type(ont: owlready2.namespace.Ontology, node_label: str):
"""Get an object corresponding to an ontology class given the node label.
`owlready2` doesn't make it easy to dynamically retrieve ontology classes.
This uses some (relatively unsafe) string manipulation to hack together a... | 0da35b5dc63b49cddece1cf0886d53315c77bf43 | 681 |
def validate_dtype_freq(dtype, freq):
"""
If both a dtype and a freq are available, ensure they match. If only
dtype is available, extract the implied freq.
Parameters
----------
dtype : dtype
freq : DateOffset or None
Returns
-------
freq : DateOffset
Raises
------
... | 407f3c52781a1e6986feaa455f78224d64cb7ca8 | 682 |
def extract_filtered_series(data_frame, column_list):
"""
Returns a filtered Panda Series one-dimensional ndarray from a targeted column.
Duplicate values and NaN or blank values are dropped from the result set which is
returned sorted (ascending).
:param data_frame: Pandas DataFrame
:param column_list: list of c... | 33120a2abedd5e8a7801bd0dfd89b107b1b593cb | 683 |
from re import T
def event_rheader(r):
""" Resource headers for component views """
rheader = None
if r.representation == "html":
if r.name == "event":
# Event Controller
tabs = [(T("Event Details"), None)]
#if settings.has_module("req"):
# tab... | 8e63b275927f2ae1a98076185e56be4f5e565ce3 | 684 |
def backend_is_up(backend):
"""Returns whether a server is receiving traffic in HAProxy.
:param backend: backend dict, like one of those returned by smartstack_tools.get_multiple_backends.
:returns is_up: Whether the backend is in a state that receives traffic.
"""
return str(backend['status']).st... | 9cb729bc14821b97d21d3d864c3ca7a1d6d46085 | 686 |
import glob
def get_bot_files_glob(**kwargs):
"""Returns a `list` with the matching file names using the format string for BOT data """
outdict = {}
kwcopy = kwargs.copy()
test_name = kwcopy.pop('testName').lower()
nfiles = kwcopy.get('nfiles', None)
rafts = get_raft_names_dc(kwcopy['run'], kw... | 818abf757b09866afba712c114d1a87938cad990 | 687 |
def minutiae_selection(minutiae):
""" Selects the subset of most reliable minutiae.
"""
M = np.array([(m['x'], m['y'], m['direction'], m['reliability']) for m in minutiae])
M[:,2] = np.round(np.rad2deg(nbis_idx2angle(M[:,2], N=16)))
M[:,3] = np.round(M[:,3] * 100.0)
M = M.astype(int)
M = M[M[:,3] > np.percentile... | 2eff6c4f4f92b395da25aaa83a1de46fb07f4269 | 688 |
def alt_blend_value(data, i, j, k):
"""Computes the average value of the three vertices of a triangle in the
simplex triangulation, where two of the vertices are on the upper
horizontal."""
keys = alt_triangle_coordinates(i, j, k)
return blend_value(data, i, j, k, keys=keys) | 3ddf30c8bb983622d2df99eb76511270fcf62c1b | 689 |
def _BinaryCrossEntropy():
"""Returns a layer that computes prediction-target cross entropies."""
def f(model_output, target_category): # pylint: disable=invalid-name
shapes.assert_same_shape(model_output, target_category)
batch_size = model_output.shape[0]
j = jnp.dot(jnp.transpose(target_category), j... | 2def2ce8e8e32af94ac67de4d99e28e15ff07622 | 690 |
def normalize(subs, strict):
"""
Normalises subtitles.
:param subs: :py:class:`Subtitle` objects
:param bool strict: Whether to enable strict mode, see
:py:func:`Subtitle.to_srt` for more information
:returns: A single SRT formatted string, with each input
... | e0e90be189fe77b123bfe960e4e9b9e63977bbe3 | 691 |
def Stern_Brocot(n):
"""
Another way to iterate over rationals
References:
https://stackoverflow.com/questions/24997970/iterating-over-parts-of-the-stern-brocot-tree-in-python
"""
states = [(0, 1, 1, 1)]
result = []
while len(states) != 0:
a, b, c, d = states.pop()
i... | cdaa919932668b33e8233c59964c3ca9bbc30119 | 692 |
def compare_elements(prev_hash_dict, current_hash_dict):
"""Compare elements that have changed between prev_hash_dict and current_hash_dict.
Check if any elements have been added, removed or modified.
"""
changed = {}
for key in prev_hash_dict:
elem = current_hash_dict.get(key, '')
... | 2f24863a16aca86ccd3a82a4148b34282349e640 | 693 |
def generator_string(lang_uses: str = 'all', char_count: int = 1,
char_size: str = 'lower') -> str:
"""Generator string
:param lang_uses: набор символов
:type lang_uses: str
:param char_count: сколько символов отдать
:type char_count: int
:param char_size: размер символов
... | fc517613ce1df5f3d208b4d6b3e5a356ac2f7e13 | 694 |
def rate_string(rate, work_unit, computer_prefix=False):
"""Return a human-friendly string representing a rate. 'rate' is given
in 'work_unit's per second. If the rate is less than 0.1 then the inverse
is shown.
Examples:
>>> rate_string(200000, "B", True)
'195KB/s'
>>> rate_string(0.01, ... | 4e7f62684be770525812465014c35dae0ce1806b | 696 |
def get_queue_arn(sqs_client, queue_url: str) -> str:
"""Encapsulates SQS::get_queue_attributes with special attribute QueueArn.
:param sqs_client: The Boto3 AWS SQS client object.
:param queue_url: URL of the queue
:return: The Amazon Resource Name (ARN) of the queue.
"""
try:
respons... | a8fbf9e8271e8809494da7634fff682769020ecd | 697 |
import psutil
def any_flexloggers_running() -> bool:
"""Returns whether any FlexLogger.exe processes are running."""
for proc in psutil.process_iter(["pid", "name"]):
if proc.info["name"].lower() == "flexlogger.exe":
return True
return False | 3dc7fb6c5120e41ff26fda41b111dec9c08560a3 | 698 |
def _get_non_white_runs(mask):
"""Returns those runs that are delimeted by white cells."""
res = []
in_a_block = False
last_idx = len(mask) - 1
for idx, cell in enumerate(mask):
if cell != WHITE and not in_a_block:
in_a_block = True
start = idx
if cell == WHI... | 0a1c4251b0a86dc95f1cea8962827b88f4945edb | 699 |
def cov(x, y, w):
"""Calculates weighted covariance"""
return np.sum(
w
* (x - np.average(x, axis=0, weights=w))
* (y - np.average(y, axis=0, weights=w))
) / np.sum(w) | b590c43c02321c3503271c56f6eca1b48a3169d8 | 700 |
from typing import List
from typing import Dict
def eval_metrics_all(
y: List[np.ndarray],
y_hat: List[np.ndarray]
) -> Dict[str, float]:
"""Calculates combined accuracy, f1, precision, recall and AUC scores for
multiple arrays. The arrays are shorted to the minimum length of the
corresponding par... | 79374750a7bf648dc8b898b187fd4b19f470bc0d | 701 |
from re import A
def fake_dataset_no_label(path, range1, batch_size=32, shuffle=False):
"""
Create fake dataset with no label
Args:
path (str) : provide the data settings
range1 (tuple) : range of generated images
batch_size (int): number of samples contained in each generated bat... | 24db6921830cf775ee1c9a2a3797dcc521c202bb | 702 |
def number_of_songs_match(folder, songs):
"""
Checks if the number of music files in folder matches the number of tracks
listed in songs.
Arguments:
- folder: path to folder where music files are found
- songs: list of track numbers
Returns:
True / False
"""
file... | 0de44cfdce9add35fba61efd0b0351f450df0e9e | 703 |
def spaces_to_pluses(q, city, state):
"""
"""
if city and state:
return split_text(q), split_text(city), split_text(state)
else:
return split_text(q), 'Nationwide', ' ' | 5ad007d7a307fc58812dc5b1fd55542411a7a9dc | 704 |
from typing import Optional
from typing import List
def _check_str_input(var, input_name: str, valid_options: Optional[List[str]] = None) -> str:
"""
_check_str_input
Convenience function to check if an input is a string. If argument valid_options is given, this
function will also check that var is a... | 357a8516fe65dddb35b7799ddc68b892da75ea02 | 705 |
def run_U_fixed_dynamics(**kwargs):
"""
Run simulation for a given set of parameter values
and generate relevant plots
"""
# Steady state checks
#print('============================== U fixed, U='+str(kwargs['U']))
a = mpde(**kwargs)
#lib.disp_params(a) # display non-array paramete... | 735e70c9082ffd92d2e1f5c20b0ca222f5ca25be | 707 |
def removeDuplicates(bookmarks, newBookmarks):
"""Creates and returns a new list of bookmarks
without any duplicates"""
nodup = []
for bmNew in newBookmarks:
foundDup = False
for bm in bookmarks:
if (bm.linkURL == bmNew.linkURL):
foundDup = True
break
if (not foundDup):
nodup.append(bmNew)
... | 12280e827796b95be30f645c5ca0e495379d6a55 | 708 |
def TNaming_Naming_GetID(*args):
"""
* following code from TDesignStd ==============================
:rtype: Standard_GUID
"""
return _TNaming.TNaming_Naming_GetID(*args) | 4b9c6aa4b6b9029d5ac879853b85780e46984d50 | 709 |
def assigned_user_add(request, location_id, destination):
"""
Assigned user add is a POST function where it will ADD a user to a project/task/opportunity/requirement.
:param request:
:param location_id:
:param destination:
:return:
"""
# Load the template
t = loader.get_template('Nea... | 92f85aad0eb99f867c8c680ed6e6d49be002ee8c | 710 |
import re
def _parse_challenge(header):
# type: (str) -> Dict[str, str]
"""Parse challenge header into service and scope"""
ret = {}
if header.startswith(BEARER):
challenge_params = header[len(BEARER) + 1 :]
matches = re.split(AUTHENTICATION_CHALLENGE_PARAMS_PATTERN, challenge_params)... | dc9044cdfa585a9dfb2cb1de9349d945e7afc985 | 711 |
def test_get_batch(source):
""" Creates an input/target pair for evaluation """
seq_len = len(source) - 1
data = source[:seq_len]
target = source[1:1+seq_len].view(-1)
return data, target | 0c26f9f957063bb136f9fe77ed1a8bbdedc38a15 | 712 |
def getReceptorResidues(filename=None, data=None):
"""Accepts a PDB(TQ) file and returns a
nested dictionary of:
chain:residue:atoms
"""
if filename:
lines = getLines(filename)
else:
lines = data
structure = {}
for l in lines:
if l.startswith(... | e409a61bac880bd586a1a21865389b30c1c28838 | 713 |
def extract_first_compute_cell(text):
"""
INPUT: a block of wiki-like marked up text OUTPUT:
- ``meta`` - meta information about the cell (as a
dictionary)
- ``input`` - string, the input text
- ``output`` - string, the output text
- ``end`` - integer, first position after }}} in... | 0dabdb5ad7b4b1d6f513d485782d25f134cf3f62 | 714 |
from typing import Union
from typing import IO
from typing import Dict
def check_schema(loader_impl: LoaderImpl) -> LoaderImpl:
"""Wrapper method to check column names and types."""
@wraps(loader_impl)
def wrapped_loader(fp: Union[str, IO], extra_fields: Dict[str, str] = None) -> DataFrame:
name ... | 471153738204a4aabc7219c23f261a8761ff8e91 | 715 |
import logging
from datetime import datetime
def get_album_photos(album, offset, vk_session):
"""Retrieves list of photos within given album from VK.com
:param album:
:type album: str
:param offset:
:type offset: int or None
:param vk_session: instance of :class:`vk_api.VkApi`
:type vk_se... | e6bc3fae5c0c132d10eb0af200e8e6a9872fa04b | 716 |
def get_view_cursor(**kwargs) -> 'XTextViewCursor':
"""
Gets current view cursor which is a XTextViewCursor
Keyword Args:
o_doc (object, optional): current document (xModel)
Returns:
object: View Cursor
"""
o_doc = kwargs.get('o_doc', None)
if o_doc is None:
o_doc =... | 6fa8ce40425684e2238337da59c52e3004b18787 | 717 |
def get_common_metrics(test_values, predicted):
"""
Return some common classifier metrics
:param test_values: values to test with
:param predicted: predicted values
:return: accuracy, precision and recall value
"""
accuracy = metrics.accuracy_score(test_values, predicted)
precision = met... | badbe3db4641352c1f36db1996c498f3b467d8f4 | 718 |
def align_jp_and_en_boxes(pd_results) -> pd.DataFrame:
"""boxes are not ordered on the page, so heuristically must match them based on
location on page
"""
japanese_results = pd.DataFrame.copy(
pd_results[pd_results.language == "jp"]).reset_index()
english_results = pd.DataFrame.copy(
... | 8292cd2ac91c497ba3e8e737b0194b27ffee4455 | 720 |
def productivity_flag():
"""
Real Name: b'Productivity Flag'
Original Eqn: b'1'
Units: b'Dmnl'
Limits: (None, None)
Type: constant
b''
"""
return 1 | 5de320366584f3e2803172c9e97c5b3b1fc79715 | 721 |
def create_cartpole_network(hidden_layers=2, neurons=56):
"""
Network that can solve gyms 'CartPole-v1' environment.
"""
net = Sequential()
net.add(Dense(
neurons,
input_shape=(4,),
kernel_regularizer=l2(0.001),
kernel_initializer=GlorotNormal(),
activation=... | 52bdf8352595dcd0cb73951c0b2ca575357c38d6 | 722 |
def format_as_rfc2822(*args, **kwrags):
"""Alias of ``format_as_rss()``."""
return format_as_rss(*args, **kwrags) | 3eb94d85241b8a96ee841233c201acd65fc683f3 | 723 |
def train_model_exponentially(train_images, train_labels, parts, exponent):
"""
Trains a model incrementally, using training data partitions that increase exponentially, and exports it.
:param train_images:
:param train_labels:
:param parts:
:param exponent:
:return: The final model
"""
... | 0e107b2e3fa69233679b9c84a7a3caf015ba53e4 | 724 |
def get_config_of(tests, test_name):
"""
Find generic values of test
"""
for test in tests:
if test.name == test_name:
try:
return test._test_case._run._config # pylint: disable=protected-access
except AttributeError:
return test._run._con... | 821f0b180a1846b432fd55afc39b1b24b4a80de0 | 725 |
from typing import Union
from typing import List
def transmit_format(func):
"""Wrapper for dataset transforms that recreate a new Dataset to transmit the format of the original dataset to the new dataset"""
@wraps(func)
def wrapper(*args, **kwargs):
if args:
self: "Dataset" = args[0]
... | 3a20f6ad1d5f7b826742f7c55694e07a5c530273 | 726 |
def parse_version(version: str) -> Version:
"""Parses version string to Version class."""
parsed = version.split(".")
try:
return Version(int(parsed[0]), int(parsed[1]), int(parsed[2] if len(parsed) > 2 else -1))
except ValueError:
return Version(0, 0, -1) | 89a785e97fc40b6e4002f2d35e75777758d665d6 | 727 |
def rate_of_change(x, t_Δ=1):
"""
:param x: a series
:param t_Δ: the intervals between each observation (series or constant)
:return: rate of change for x
"""
diffs = np.diff(x) / t_Δ
return diffs | a6e07fbc8c29a66a6904eb36011d0c093e028d58 | 728 |
def draw_cutout(data, title, lower_bound=0, upper_bound=1, is_mobile=False):
""" Draw a cutout data
"""
# Update graph data for stamps
data = np.nan_to_num(data)
data = sigmoid_normalizer(data, lower_bound, upper_bound)
data = data[::-1]
data = convolve(data, smooth=1, kernel='gauss')
... | 016e624fab9aa3b170dafba509a2d61f5444e9bb | 729 |
def _check_sample(sample_pair: dict):
"""
Controls a sample.
Parameters
----------
sample_pair : dict
Sample must contain image and mask: " "{'image': image, 'mask': mask}
Returns
-------
sample : dict
Sample must contain image and mask: " "{'image': image, 'mask': mask}... | 112e9e46a753f8754d25ddbfe2505535c2f9ac96 | 730 |
def _make_cls(cls, attrs):
"""Make the custom config class."""
return type(f'Custom{cls.__name__}', (cls, ), attrs, ) | bbe1f7694fbb30bdcb3e3c5df0207ae641d022b3 | 731 |
from datetime import datetime
def get_date(delta):
"""Build a date object with given day offset"""
date = datetime.datetime.now()
if delta is not None:
offset = datetime.timedelta(days=delta)
date = date + offset
date = date.strftime("%A %-m/%-d")
return date | ef3762a088946e81a8a26165395dad356e103ec9 | 732 |
def mover_alfil(tablero, x_inicial, y_inicial, x_final, y_final):
"""
(list of list, int, int, int, int) -> list of list
:param tablero: list of list que representa el tablero
:param x_inicial: int que representa la posicion inicial en X
:param y_inicial: int que representa la posicion inicial en Y... | 4c31db653fd448878f3e629b1237173f3eb26a56 | 733 |
from scipy.interpolate import UnivariateSpline
def interpolate_atmosphere(data, Z, s=0.25):
""" This module generates a 1d array for the model plasma preesure, plasma
density, temperature and mean molecular weight.
"""
hdata = np.array(u.Quantity(data['Z']).to(u.m))
# interpolate total pressure, ... | 3bddc5972fe0e5d4c814a6311775e7fa9777ca79 | 735 |
def exponential_coulomb_uniform_correlation_density(
density,
amplitude=constants.EXPONENTIAL_COULOMB_AMPLITUDE,
kappa=constants.EXPONENTIAL_COULOMB_KAPPA):
"""Exchange energy density for uniform gas with exponential coulomb.
Equation 24 in the following paper provides the correlation energy per length... | dc2227f10cc64a3aa857494322f29f2b82b68da3 | 736 |
import torch
def val(model, dataloader, use_gpu):
"""val. the CNN model.
Args:
model (nn.model): CNN model.
dataloader (dataloader): val. dataset.
Returns:
tuple(int, in): average of image acc. and digit acc..
"""
model.eval() # turn model to eval. mode(enable droupout l... | 8cecc0204855a5267a11edf6936b6415fafc8120 | 737 |
def ps(s):
"""Process String: convert a string into a list of lowercased words."""
return s.lower().split() | 9bf25b31d00544d96f96564ce67ff5def9a16348 | 738 |
def login(username,password):
"""
使用账号(邮箱)和密码,选择“记住我”登录
:param username:
:param password:
:return:
"""
global a
a.get("https://account.fangcloud.com/login")
_token = a.b.find("input",{"name":"_token"})["value"]
_fstate = a.b.find("input",{"name":"_fstate"})["value"]
x=a.post(... | 7003be533ccb3edaff42d3f47c6882b1646a22d2 | 740 |
def rules():
"""Displays a markdown doc describing the predictive modeling contest.
Note ./content/contest/<url calling path>.md must be modified for contest.
"""
file = open('./contest/content/rules.md', 'r')
rawText = file.read()
file.close()
content = Markup(markdown(rawText,
ext... | 9a5b44b87fbcee378a958586511851ef455d7988 | 741 |
import requests
def get(server: t.Union[Server, str], view_or_url: str, view_data: Kwargs = None, session: requests.Session = None,
params: Kwargs = None, **kwargs) -> Response:
"""Sends a GET request."""
return request('get', server, view_or_url, view_data=view_data, session=session, params=params, *... | e9cecdb76f6b340a258c5bb1ca3be8cb9e257764 | 743 |
import pandas
def to_float(dataframe, column):
"""General Function to return floats"""
dataframe[column] = dataframe[column].dropna().astype(float)
dataframe[column] = dataframe[column].where(pandas.notnull(dataframe[column]), None)
return dataframe[column] | 2fdae992ec88e40c1e8c67711373d28390569166 | 746 |
import torch
def dadbt(a: torch.Tensor, diag_mat: torch.Tensor, b: torch.Tensor) -> torch.Tensor:
"""Batched computation of diagonal entries of (A * diag_mat * B^T) where A and B are batches of square matrices and
diag_mat is a batch of diagonal matrices (represented as vectors containing diagonal entries)
... | bb2f0c9858130c556ffc5c7dfd4e337e0437aadd | 749 |
from operator import invert
def local_minima(image, footprint=None, connectivity=None, indices=False,
allow_borders=True):
"""Find local minima of n-dimensional array.
The local minima are defined as connected sets of pixels with equal gray
level (plateaus) strictly smaller than the gray... | 9adaee108130b760077ba0c3698d07f37454d474 | 750 |
import torch
def kron(a, b):
"""
Kronecker product of matrices a and b with leading batch dimensions.
Batch dimensions are broadcast. The number of them mush
:type a: torch.Tensor
:type b: torch.Tensor
:rtype: torch.Tensor
"""
siz1 = torch.Size(tensor(a.shape[-2:]) * tensor(b.shape[-2:... | b108e123817692f70f0e501c7a515171a3b08270 | 751 |
from datetime import datetime
import pytz
def process_query(request):
"""the function is called upon "news/" URL. it processes the query and calls the apifunction to fetch news articles
from third party news APIs.
If a query is new, it makes a fresh request to third party APIs and returns the query res... | 000b6e4f47e06e29ff0e0ba1ba9d3311e9f40263 | 752 |
def fix_header(params, recipe, infile=None, header=None,
raise_exception=False, **kwargs):
"""
Instrument specific header fixes are define in pseudo_const.py for an
instrument and called here (function in pseudo_const.py is HEADER_FIXES)
:param params:
:param infile:
:return:
... | 37550406cb76b77ccb1d64e85f5f192989ad4bcd | 753 |
from typing import List
def encode(df: pd.DataFrame,
cols: List[str],
drop_first: bool = True) -> pd.DataFrame:
"""Do a dummy encoding for the columsn specified
Args:
df: DataFrame
cols: List of columns to perform dummy encoding on
drop_first: parameter for dummy... | 9299378d67c69ebd964a7187431c67c12556c43b | 754 |
from typing import Optional
def binary_search(pool: list, target) -> Optional[int]:
"""Search for a target in a list, using binary search.
Args:
pool (list): a pool of all elements being searched.
target: the target being searched.
Returns:
int: the index of the target.
"""
s... | 7e7ef70126e02b3dc706b3b88bd950aa6322904e | 755 |
def load_array(filename):
"""
Given a valid image, load the image and return the pixels as a numpy array
:param filename: The filename as a string
:returns: A numpy array which stores the pixel data from a snowmap
Convention is as follows: pixels that read 0,0,0, 255 are read as snow-free and conta... | 829e97936fb63486bc1c373bdf283f02dbb833bd | 756 |
def create_anchors_3d_stride(feature_size,
anchor_strides,
sizes=[1.6, 3.9, 1.56],
anchor_offsets=[0, -20, -1], # [0.2, -39.8, -1.78],
rotations=[0, 1.57], # np.pi / 2
dtype... | 2d6d31a45c5f2f0a9adfe39195ae37719d78fd73 | 757 |
def sample_unit(name='oz'):
"""Create and return a sample unit"""
return Unit.objects.create(name=name) | affa250d46b5b50e69af013035f6b73b45b787b4 | 758 |
def CreateBlendCurve2(curve0, t0, reverse0, continuity0, curve1, t1, reverse1, continuity1, multiple=False):
"""
Makes a curve blend between 2 curves at the parameters specified
with the directions and continuities specified
Args:
curve0 (Curve): First curve to blend from
t0 (double): P... | 08553ffbc307e792f5f794812c6b54d6bc995766 | 759 |
def make_raster_from_images(modeladmin, request, queryset):
"""Make a raster of the selected `ImageMeta`s.
This is an action on `ImageMeta`
"""
imset = make_image_set_from_images(modeladmin, request, queryset)
return _make_raster_from_image_set(imset) | 1d5d855d986ee37875b85ec119dacd51f4af5e69 | 761 |
def is_rotation(first, second):
"""Given two strings, is one a rotation of the other."""
if len(first) != len(second):
return False
double_second = second + second
return first in double_second | f02576761014e1dc395f88f937dfdd0de15508d2 | 762 |
def bin_entities(uri_set, delimiter="/", splitpos=-1):
""" Takes iteratable elemts and splits them according to the position
(splitpos) of the delimiter. The first part is used as a key,
whereas the second appended to a list connected to the former key.
return: dict {key1: [id11, id12, id13... | fcbcddbff909d74fe14fe7cb3a21560c8ca9549a | 763 |
def frequency(state_1, state_2):
""" The frequency interval between state_1 and state_2 in GHz.
"""
return 1e-9 * interval(state_1, state_2) / h | 6276f946e08d9b2e115f004395b5cf420f048c68 | 764 |
from typing import OrderedDict
def dac(dns_val=None) -> OrderedDict:
"""
Domain Availability Checker (DNS lookup)
:param _dns: URL string
:return: Availability [True, False]
"""
ip_values = None
avail = False
if dns_val is None:
raise ValueError("Sorry, DNS is needed")
if... | d2c4097686f2edb17fbd674098592ec797ecac46 | 765 |
def display_timestamp(num_seconds):
"""get a string to conveniently display a timestamp"""
seconds = num_seconds % 60
minutes = int(num_seconds / 60) % 60
hrs = int(num_seconds / 3600)
return "{}:{}:{}".format(hrs, minutes, seconds) | bdcc34ade38855df910d5005f6dac9b5e826f543 | 766 |
def get_bloglist(content_dict={}):
"""
输入的指令为-m,则列出博客的文章列表
:param content_dict:
:return:
"""
bloglist = crawlBlog.get_archives(5)
tousername = content_dict["FromUserName"]
fromusername = content_dict["ToUserName"]
return WeixinUtils.make_news(bloglist, tousername, fromusername) | 541fbf7f10f137b995fd0d9a91e8bc651b90b697 | 767 |
import bisect
def get_closest(arr, value):
"""
Return the array values closest to the request value, or +/-inf if
the request value is beyond the range of the array
Parameters
----------
arr : sequence
array of values
value : numeric
Returns
-------
2-tuple: largest v... | e59216c7d0332ae91e75583b7dc42f956c785e4c | 768 |
def filename(config, key, ext = '.h5', set = ''):
"""
Get the real file name by looking up the key in the config and suffixing.
:param key: key to use in the config
:type key: str
:param ext: extension to use
:type ext: str
:param set: set name
:type set: str
:return: filepath
:... | f389a48e7e06a31722423857814149f474e46316 | 769 |
def isUp():
""" Whether this docker container is up """
return 'True' | e99c32dee79c4df516193c1a9d3fb8d34f8b0abc | 771 |
def rand_perm_(img, x, y, x_max, y_max, kernel, flatten):
"""
Applies INPLACE the random permutation defined in `kernel` to the image
`img` on the zone defined by `x`, `y`, `x_max`, `y_max`
:param img: Input image of dimension (B*C*W*H)
:param x: offset on x axis
:param y: offset on y axis
:... | c838840c2428320825486c0cdacf23f5fb40a9a6 | 772 |
import torch
def test(model, data_loader, use_cuda, loss_func):
"""
The function to evaluate the testing data for the trained classifiers
:param model:
:param data_loader:
:param use_cuda:
:return:
"""
softmax = torch.nn.Softmax(dim=1)
columns = ['participant_id', 'session_id', 's... | 37859b0f477326a8a606205c84ea0827d43925d8 | 773 |
def is_fundamental_error(path, error):
"""
Returns True if error is not field related. (So type related, for example.)
"""
return not is_any_field_error(path, error) | 8eef548f9520cbd92ff3989f2f11b180e8099981 | 774 |
def migrate_to_latest(json_dict, info):
"""Migrates the STAC JSON to the latest version
Args:
json_dict (dict): The dict of STAC JSON to identify.
info (STACJSONDescription): The info from
:func:`~pystac.serialzation.identify.identify_stac_object` that describes
the STAC... | 0e159ea565038a4b8fa8b2525c8adc35cbd97dc6 | 776 |
def contact_infectivity_symptomatic_20x50():
"""
Real Name: b'contact infectivity symptomatic 20x50'
Original Eqn: b'contacts per person symptomatic 20x50*infectivity per contact'
Units: b'1/Day'
Limits: (None, None)
Type: component
b''
"""
return contacts_per_person_symptomatic_20x... | b6472192451dcf484cbe7ac802c06750c3d63fff | 777 |
def smart_wn_search(wn, query, pos=None, report_file=None, compact=True, lang='eng', with_eng=True):
""" Search synset in WordNet Gloss Corpus by term"""
if report_file is None:
report_file = TextReport() # Default to stdout
report_file.print("Search Wordnet: Query=%s | POS=%s" % (query, pos))
... | 4d600ca77c6e4012225dfc4b1212739542817c83 | 778 |
def _parse_integrator(int_method):
"""parse the integrator method to pass to C"""
#Pick integrator
if int_method.lower() == 'rk4_c':
int_method_c= 1
elif int_method.lower() == 'rk6_c':
int_method_c= 2
elif int_method.lower() == 'symplec4_c':
int_method_c= 3
elif int_metho... | 20a44b596860fdaa72b5aa37c7853bbcf47c3c91 | 779 |
import time
def get_diffusion_features(repo_path, branch):
"""
Function that extracts the first commits diffusion features. It then starts
a number of processes(equal to the number of cores on the computer), and then
distributes the remaining commits to them.
"""
repo = Repository(repo_path)
... | cd94b722c0f98d55206a5c5cad32e6f855ae304d | 780 |
def convert_example(example,
tokenizer,
label_list,
max_seq_length=512,
is_test=False):
"""
Builds model inputs from a sequence or a pair of sequence for sequence classification tasks
by concatenating and adding special tokens. ... | 986503a34f055b890f5979ca146708c1b45a45fe | 781 |
import yaml
import json
def load_config_file(filepath):
"""
Load a configuration as an options dict.
Format of the file is given with filepath extension.
:param filepath:
:type filepath:
:return:
:rtype:
"""
if filepath.endswith('.json'):
with open(filepath) as config_file... | 60b5ea592f8f101be279cfe5897e70fbef11f9b0 | 782 |
def coordinator_setup(start_heart=True):
"""
Sets up the client for the coordination service.
URL examples for connection:
zake://
file:///tmp
redis://username:password@host:port
mysql://username:password@host:port/dbname
"""
url = cfg.CONF.coordination.url
lock_... | b39b736e39b6c98badd148ac111b01dae85eea2f | 783 |
def _to_jraph(example):
"""Converts an example graph to jraph.GraphsTuple."""
example = jax.tree_map(lambda x: x._numpy(), example) # pylint: disable=protected-access
edge_feat = example['edge_feat']
node_feat = example['node_feat']
edge_index = example['edge_index']
labels = example['labels']
num_nodes ... | e3bc4bb468ae4e6dfbb4387c0a913a87ba76ac26 | 784 |
def get_urls(page_links):
"""Insert page links, return list of url addresses of the json"""
urls = []
for link in page_links:
link1 = link.replace('v3', 'VV')
game_id = ''.join([char for char in link1 if char in list(map(str, list(range(10))))])
json_url = f'http://www.afa.com.ar/dep... | 68c6796ad5a77676674252a0060776eabc4fb8e0 | 785 |
def KK_RC79_fit(params, w, t_values):
"""
Kramers-Kronig Function: -RC-
Kristian B. Knudsen (kknu@berkeley.edu / kristianbknudsen@gmail.com)
"""
Rs = params["Rs"]
R1 = params["R1"]
R2 = params["R2"]
R3 = params["R3"]
R4 = params["R4"]
R5 = params["R5"]
R6 = params["R6"]
... | 386f84adf3dd4a1b122ef1ef9572f1d3733fb94c | 786 |
def _resampling_from_str(resampling: str) -> Resampling:
"""
Match a rio.warp.Resampling enum from a string representation.
:param resampling: A case-sensitive string matching the resampling enum (e.g. 'cubic_spline')
:raises ValueError: If no matching Resampling enum was found.
:returns: A rio.war... | e0e4020361313205fd0afc90e19bb02ebe0d5abb | 787 |
def _call_twitter_api(query):
"""helper function to call twitter api
Args:
query (str): query string made by _preprocess_query function
Returns:
generator: response object in generator
"""
return sntwitter.TwitterSearchScraper(query=query).get_items() | 3b75150e7a83e7dfdbc5bd836745af13d3b5a90f | 788 |
from typing import List
import re
def parse_superfamilies(filepath: str) -> List[Method]:
"""
Parse the CathNames.txt file distributed with CATH-Gene3D releases
:param filepath:
:return:
"""
signatures = []
reg = re.compile(r"^(\d\.\d+\.\d+\.\d+)\s+([a-zA-Z0-9]+)\s+:(.*)$")
with open(... | db91d288133ed64b27ffdc1852ca5d62390792eb | 789 |
def Weekday(datetime):
"""Returns a weekday for display e.g. Mon."""
return datetime.strftime('%a') | bae413f0fa86f9e27bd6d7f6ee4480a6ddd564e7 | 790 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.