content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def _scale(dimen: str, scale: float = 1) -> int | str:
"""Get a scaled dimen.
Args:
dimen (str): dimension in px
scale (float): scale
Returns:
Optional[int, str]: scaled dimen (min=1)
"""
if scale == 1:
return dimen
return max(int(int(dimen) * scale), 1) | 450a969f658f5768b1e3988859c4f20ff6b2dfd3 | 49,005 |
from typing import Any
from typing import Union
def _batch_set_tuple(batch: Any, key: Union[int, str], value: Any) -> Any:
""""Sets key value pairs in tuples and NamedTuples."""
if hasattr(batch, '_fields'): # NamedTuple
if isinstance(key, str):
batch = batch._replace(**{key: value})
... | d725614cd7fc1795d76ea22c204b8f446ff8cab2 | 49,006 |
from typing import List
def scale_prev(prev_vals: List[float], fraction: float) -> float:
"""
Apply a multiplier to the previous value.
"""
return prev_vals[-1] * fraction | 9685214aaece3a6935886cbf91472e877f7e3619 | 49,008 |
import numpy
def _default_processing(data, dist_func, type=numpy.float_):
"""Creates a dict and calculates the distance matrix for a 2D tsp problem.
Parameters
----------
data : list of list
The lists in the list always contain the name of a point,
the x coordinate and the y coordinat... | 44f47bc42c6f1eb0ac12dd50771cd6a7cc7e294c | 49,009 |
def convert (hour):
"""
converts Hours in to seconds (hours * 3600)
Args: hours(int)
return: (int value) number of seconds in hours
"""
seconds = 3600
result = hour * seconds
return result | 1c7d06da2582c0c580ed48ddc18f142727001fa8 | 49,011 |
import json
def load_spam_rounds(path):
"""Load spam round transaction XDRs."""
spam_rounds = []
with open(path) as f:
for rnd in f:
spam_rounds.append(json.loads(rnd))
return spam_rounds | 3ff640a1f529fadb76d08cd55063cb471568c683 | 49,012 |
def _r_count_num_m(n, factors_d, i):
"""Count of numbers coprime to d less than end; sum( gcd(m, d) == 1 for m in range(n, n+i) )
Uses inclusion exclusion on prime factorization of d
"""
if n == 0:
return 0
if i < 0:
return n
return _r_count_num_m(n, factors_d, i-1) - _r_coun... | 2d5eacf6d1df2d4277bd9abd760bc132a09452d8 | 49,013 |
def NormalizeLineEndings(s):
"""Convert string containing various line endings like \n, \r or \r\n,
to uniform \n."""
return '\n'.join(s.splitlines()) | 8dc5c3cf579427fe402ee84cc15b73ccc2bbe88d | 49,014 |
def tags_from(element):
"""Receive element from dataset and return separated tags"""
tags = list(map(lambda token: token[1], element["tags"]))
return tags | bd4338440052eb0c80995f996c21d7fde0831c55 | 49,015 |
def hi_there(name="joseangel"):
""" Hi There Function """
return "hi " + name | be432539bd19ded67704355a068886fa80c7c32d | 49,019 |
import collections
def extract_selection_info(datalog_rule):
""" Non-Recursive datalog rule
Extract and store the information for attributes selected (computed) from the query
Args:
datalog_rule:
data structure storing the information of the datalog rule
Return:
... | f6eadf82045bc74234dd5c0a007b78eee38b8a05 | 49,021 |
def get_version(diff_file, ix=True):
"""Determine the product version from the diff file name.
param ix denotes if the diff file was generated by APIx or CLIx
"""
split_ver = diff_file.split("/")[-1].split("-")
if "-comp.yaml" in diff_file:
return split_ver[0]
else:
return f"{spl... | a1d899abdea8ee59c76b6103bd27cb0b40e100cd | 49,022 |
from typing import Optional
from typing import Union
from typing import cast
from typing import Dict
def validate_axis(axis: Optional[Union[int, str]] = 0, none_axis: int = 0) -> int:
"""Check the given axis is valid."""
# convert to numeric axis
axis = cast(
Dict[Optional[Union[int, str]], int], ... | 654cd35d1ddd4ff27c0a37635a211ddfca710c6e | 49,024 |
def aes_unpad(s, block_size=32, padding='{'):
""" Removes padding to get the value from @s for AES decryption
@s: #str being AES encrypted or decrypted
@block_size: the AES block size
@padding: character to pad with
-> unpadded #str
..
from vital.security impor... | 2d2e956cd24a900ecd6b1c431c40ca5d9550beaf | 49,025 |
def cos_series(x):
"""Returns cos(x) for x in reange -pi/2 .. pi/2"""
# https://en.wikipedia.org/wiki/Trigonometric_functions#Power_series_expansion
C=[1.,0.5,0.08333333333333333,0.03333333333333333,0.017857142857142856,0.011111111111111111,0.007575757575757576,0.005494505494505495,0.004166666666666667,0.00... | 28ebfa85a7162a666ce8fcf5c852e3d2d2577ba5 | 49,026 |
def _for_new_texts_get_ngrams_vector(text, vectorizer):
"""Not called here, just used to store a method that contains a vectorizer to be used later.
"""
vector = vectorizer.transform([text]).toarray()[0]
return(vector) | c23a6c7d6d631a4329719aba1cea410cc130b9dd | 49,028 |
import torch
def so3_log_abs_det_jacobian(x):
"""
Return element wise log abs det jacobian of exponential map
:param x: Algebra tensor of shape (..., 3)
:return: Tensor of shape (..., 3)
Removable pole: (2-2 cos x)/x^2 -> 1-x^2/12 as x->0
"""
x_norm = x.double().norm(dim=-1)
mask = x_... | 82d22cef96578a90d677d4d631dfb2ed7c783d05 | 49,029 |
def inherits_from(obj, a_class):
""" Returns booleanType response
for class inheritance test
Args:
obj: object to evaluate
a_class: class value for testing
"""
if (type(obj) != a_class):
return isinstance(obj, a_class)
else:
return False | 8cca684124a4c948bbfde7c147bd3be439f79931 | 49,030 |
def a1(row_index, column_index):
"""Get an A1 notation for a cell specified by its row index
and column index"""
ord_first = ord('A')
ord_last = ord('Z')
letters_count = ord_last - ord_first + 1
level, letter_index = divmod(column_index, letters_count)
letter = chr(ord_first + letter_index) ... | d319600fcdddfbe7c0a715b56e8d00b6b9198d84 | 49,031 |
def get_E2K_lookup_dict(the_dict, main_key, sub_key):
"""Returns a lookup dictionary specified by main_key
and sub_key, returning an empty dictionary if any is missing.
This is for use in the post-processing functions."""
subdict = the_dict[main_key].get(sub_key, {}) \
if the_dict.get(main_key) ... | 56dbb81592a00e873dc5bda1234377a48bde9e94 | 49,032 |
def make_feat_paths(feat_path):
"""
Make a feature path into a list.
Args:
feat_path (str): feature path
Returns:
paths (list): list of paths
"""
if feat_path is not None:
paths = [feat_path]
else:
paths = None
return paths | 6a7960c86a7f97afbe7b248970fd7f7f8efeda1e | 49,034 |
def add_fea_prfx(df, prfx: str, id0: int):
""" Add prefix feature columns. """
return df.rename(columns={s: prfx+str(s) for s in df.columns[id0:]}) | a7c35073fb610a8e6d8f9f37f998ff0b943f1183 | 49,035 |
def annuity_factor(n, i):
"""
Calculate annuity factor
Args:
n: depreciation period (40 = 40 years)
i: interest rate (0.06 = 6%)
Returns:
annuity factor derived by formula (1+i)**n * i / ((1+i)**n - 1)
"""
return (1 + i) ** n * i / ((1 + i) ** n - 1) | 9efb7062c609c260482a3f870350148518dba5d9 | 49,036 |
import os
def castep_bin_SiO2():
"""Binary output from a singlepoint with `calculate_stress: true`. """
return os.path.join(os.path.split(__file__)[0], 'test_data/SiO2.castep_bin') | 1cc221b479b1da528cc6cea335c23c66c7fda1b5 | 49,037 |
import struct
def get_floatDAWG(freqs, word, small):
"""
Извлечение слова из BytesDAWG
"""
if word in freqs:
return struct.unpack("f", freqs[word][0])[0]
return small | 7e1c66abfd3a157212665316d8939261e54461a3 | 49,038 |
def trim_to_preferred_protocols(hosts_and_urls):
""" remove all but http and ftp URLs,
and if both http and ftp are offered,
leave only http. Return [(hostid, url), ...] """
results = []
try_protocols = ('https', 'http', 'ftp')
for (hostid, hcurls) in hosts_and_urls:
protocols = {}
... | c4e108e4a650431a39d3a689153f516c1b711143 | 49,039 |
def is_invalid_schema(schema, test_value):
"""
Checks schema against tests with dictionary nesting
>>> is_invalid_schema({"valid_key": "some_value"}, {"valid_key": "some_value"})
False
>>> is_invalid_schema({"invalid_key": "some_value"}, {"valid_key": "some_value"})
True
>>> is_invalid_sc... | 894109fc9910fc708d9a8800e1169d6e00876e0d | 49,040 |
import sys
def read_stdin():
"""Read data from stdin."""
if sys.version_info < (3, 0):
return sys.stdin.read()
else:
return sys.stdin.buffer.read() | 61018f2fc55ad1b31814fb0baad4522ba4df426f | 49,041 |
import click
def lprint(ctx, out):
""" echo output of stdout and stderr if it's not a watch invoked command """
if out.stdout:
click.echo(out.stdout)
if out.stderr:
click.echo(out.stderr)
return out | 0b44b9312cd3a347aecdfe382ed766b1459ff39d | 49,042 |
def create_state(current_version, lr, total_ite, optimizer):
""" Create a checkpoint to be saved """
state = {
'version': current_version,
'lr': lr,
'total_ite': total_ite,
'optimizer': optimizer.state_dict()
}
return state | e318b02c6e2a5a15e9e3d65741962dbd95cfdd84 | 49,044 |
from typing import Union
import os
def find_caltable(field_name: str, rcu_mode: Union[str, int], caltable_dir='caltables'):
"""
Find the file of a caltable.
Args:
field_name: Name of the antenna field, e.g. 'DE602LBA' or 'DE602'
rcu_mode: Receiver mode for which the calibration table is r... | 2548c7b0c097f62bc40719fbcb6939ff58817d4b | 49,045 |
def formed_bond_keys(tra):
""" keys for bonds that are formed in the transformation
"""
#print('tra test:', len(tra), tra)
#if len(tra) == 1:
# frm_bnd_keys = tra
#else:
frm_bnd_keys, _ = tra
return frm_bnd_keys | 7190e308c86f3c453696379e5b914c9665e8b482 | 49,046 |
import re
def handle_lambda(call, line, file):
"""
Resolve calls that point to <lambda>. Finds the lambda definition in the file/line
pointed to by the `call` and extracts the name of the variable that gets assigned
the lambda.
:param call: call dictionary
:param line: line dictionary
:pa... | ff9c99f123596d7554bebdeb8c607fd8864ef1a4 | 49,047 |
import math
def filter_greater_135deg(arc, columns=13):
"""function for calculating endpoints of a line, starting at (0/0). When connecting endpoints with start points applying a
given angle, a line can be drawn that serves as filter for angles between 91° and 134°.
It decides on the fly how big ... | a75a1a82c4517a2b8a308abcb3fe39a7cf485dcd | 49,048 |
import collections
def get_month_most_posts(dates):
"""Receives a list of datetimes and returns the month (format YYYY-MM)
that occurs most"""
c = collections.Counter()
for d in dates:
c[str(d.year) + '-' + str(d.month).zfill(2)] += 1
return c.most_common(1)[0][0] | 6c71301657e45529706688cdb51e4bbe43284d41 | 49,049 |
import os
def _read_control_file(file_dir, cfg):
"""Read '*.ctl' file."""
ctl_path = os.path.join(file_dir, cfg['binary_prefix'] + '.ctl')
with open(ctl_path, mode='r') as ctl_file:
contents = ctl_file.read()
contents = contents.split()
ctl = {}
ctl['binary_prefix'] = cfg['binary_prefi... | c4975e99db043ca19949e3b433c6d917dfc79bc4 | 49,052 |
import math
def get_data_file(lon, lat):
"""
Returns the correct HGT data file to get elevation from.
Credit: Aatish Neupane
Link: https://librenepal.com/article/reading-srtm-data-with-python/
:param lat: The latitude of the desired point.
:param lon: The longitude of the desired point.
:r... | c454df12af58fc1174fec591d5d32b3b97f85118 | 49,053 |
import random
def generateRandomPort():
"""Generate random number between 30000 and 32767 for External Condor Port"""
random.seed()
port = random.randrange(30000, 32767)
print("Now using port: {}".format(port))
return port | 55bf41c5e0cc5afb8029c8a33b408eba0efc3d72 | 49,054 |
def initialDataLists(D):
""" Initialize grid, scalars, and vectors lists used in convertToVtk function. """
grid = []; # simple
scalars = [list(x) for x in [()]*len(D["scalar"].keys())]; # more complicated
vectors = [list(x) for x in [()]*len(D["vector"].keys())]; # more complicated
return [grid, scalars, vec... | 96dab994f29c79d874fd4be55cc96757a3b7c8f4 | 49,055 |
from typing import Optional
from typing import Union
from typing import Type
from enum import Enum
def enum_or_raise(value: Optional[Union[str, int]], enum: Type[Enum]) -> Enum:
"""Return Enum or raise exception."""
if value is None:
raise Exception("Received None value for enum %s" % enum)
retur... | d1a5346ea1facce984bdbcc5b854559c9d335387 | 49,057 |
def get_list_of_new_entries(device_entries: list, file_entries: list) -> list:
"""
Compares log entries from the local logfile with the log entries from the device
Args:
device_entries (list): List of LogEntry Objects, fetched from the device
file_entries (list): List of LogEntry Objects, f... | baa16c9999f42e6d71a1d6bc62305f42239b61b0 | 49,058 |
def get_region_start(region: str) -> int:
"""Return the start position of the region string."""
if ":" not in region:
return 1
contig, start_end = region.split(":")
start, end = start_end.split("-")
return int(start) | 4dc1392815560d6e3886addaef7837ecf21069ba | 49,059 |
def sign():
"""Show sign for positive numbers: + ↔ yes, - ↔ no, ' ' ↔ show space."""
return "x may be {0:*^+5}, {0:*^-5}, {0:*^ 5}!".format(1) | f7df67e735dc1c66cdbda3a615d064a8ac4b704d | 49,060 |
def _parse_attrib(text):
"""
Parses a string of the form 'key=val'and
returns a key, value pair.
@type text: C{str}
@param text: textual representation of key, value pair
@rtype: C{tuple}
@return: key, value pair
"""
key, val = [s.strip() for s in text.split('=')]
if '... | bd6c43799c5aa7259d5c610fd2c6374f987b6057 | 49,062 |
import os
import subprocess
import sys
import time
import socket
import requests
def spawnFireflyServer(port=5000,frames_per_second=30,decimation_factor=1,max_time=10):
"""Wrapper to :func:`Firefly.server.startFireflyServer` that instead starts a background process.
:param port: port number to serve the :cod... | b66ca0cb46ff5fce8d17b70a36f2473de672d6ff | 49,064 |
def parse_datetitle(raw_metadata):
"""
uses tags to try to find title and date
:param raw_metadata:
:return:
"""
try:
date_temp = raw_metadata["date"][0]["datetime"]
except:
date_temp = ""
return {
"date": date_temp,
"title": raw_metadata["title"].text
... | d63c66f6ed9d5ebdafc7075c5f8c76b497134f25 | 49,065 |
def instjoin(*instnames):
"""Return hierarchical instance names from instance name components
>>> instjoin('I1','VS')
'I1.VS'
>>> instjoin('','VS')
'VS'
"""
return '.'.join([part for part in instnames if len(part) > 0]) | 3bd842de4bc6026d41d36267d2cca1b6d9d4b575 | 49,066 |
def calculate_average_precision(precision_list,recall_list):
"""
compute average_precision
Args:
precision_list: list of precision
recall_list: list of recall
Returns:
"""
count = len(precision_list)
if len(recall_list) != count:
raise ValueError("the number in ... | cd95b94347eac22d7572e99920df480663b87770 | 49,067 |
import os
def ExpandSconsPath(path):
"""Expands a directory path into the path to the
scons file that our build uses.
Ex: magiflute/plugin/common => magicflute/plugin/common/common.scons
Args:
path: The directory path to expand.
Returns:
The expanded path.
"""
return '%s/%s.scons' % (pat... | 78823b95cdee301974545bef20afc911846b9683 | 49,068 |
import os
def clean_extension(filename):
"""Return clean file extension
- lowercase
- without .gz
- without . prefix
examples:
file.fa.gz -> fa
file.pdb -> pdb
nosuffix -> ''
"""
filename = filename.lower()
if filename.endswith('.gz'):
filename = filename[:-3]
... | 43e2ec2d89fc0226d1306923b00a32a8049f5073 | 49,069 |
import os
import tempfile
def get_plugin_tempdir(mytempdir):
"""If mytempdir is not set, set to a save directory for saving state."""
if mytempdir:
return mytempdir
if os.name != 'nt':
nag_temppaths = ['/var/log/nagios', '/var/lib/nagios3']
else:
nag_temppaths = [tempfile.gette... | 72a6f0f7e7b360516c750104da9088276d4aa0f6 | 49,070 |
def same_first_last(L: list) -> bool:
"""Precondition: len(L) >= 2
Return True if and only if first item of the list is the same as the
last.
>>> same_first_last([3, 4, 2, 8, 3])
True
>>> same_first_last(['apple', 'banana', 'pear'])
False
>>> same_first_last([4.0, 4.5])
False
"""... | 734cfdbfebaa957848414f7ba16f3235d751e038 | 49,071 |
import numpy
def dotprod(u,v):
"""
This is a wrapper around general dense or sparse dot products.
It is not necessary except as a common interface for supporting
ndarray, scipy spmatrix, and PySparse arrays.
Returns the dot product of the (1 x m) sparse array u with the
(m x 1) (dense) numpy... | ca9d6d4bb7bc577ee510410d0e2a0890c7bae197 | 49,073 |
def _records_match(old_ttl, old_record_data, new_ttl, new_record_data):
"""Checks to see if original and new TTL and values match."""
matches = True
if old_ttl != new_ttl:
matches = False
if old_record_data != new_record_data:
matches = False
return matches | 982f8d5b9f6c72b95a5d6b76d4909eb89906e3df | 49,074 |
def htmlDataset(dataset = {}, title=""):
""" Utility function to generate HTML Table from a Dataset"""
content = "<TABLE cellpadding=5> <caption align=top>" + title + " </caption><TR></TR><TR></TR>"
for row in dataset['DATA']:
content += "<TR>"
for col in dataset['DATA'][row]:
... | 871c44487fadacdb8c255389a57065b0887df1c6 | 49,075 |
import logging
def get_logger():
"""
The function returns the common logger for all OTE
training tests.
"""
logger_name = ".".join(__name__.split(".")[:-1])
return logging.getLogger(logger_name) | 26fa81856262a0a0964c0323f14e4cb8a432993e | 49,076 |
def get_bprop_npu_alloc_float_status(self):
"""Grad definition for `NPUAllocFloatStatus` operation."""
def bprop(out, dout):
return ()
return bprop | 4fa3c9f6e6bf099ca43779071be93e383897c72e | 49,077 |
def clamp(n, lower, upper):
"""
:param n: Number to clamp
:param lower: Lower bound
:param upper: Upper bound
:return: Clamped number
"""
return max(lower, min(n, upper)) | df283f640cfee371b44d8ab33c90ac959f3601e2 | 49,078 |
def _passthrough(folder_out: str) -> str:
"""
Pass the state from the main thread to the mergeing function
"""
return folder_out | 7ac97ca389bfb75470238309986a3bafbe7260a2 | 49,079 |
import six
def GetLabels(args, client, instance_properties=False):
"""Gets labels for the instance message."""
labels_value = client.messages.Instance.LabelsValue
if instance_properties:
labels_value = client.messages.InstanceProperties.LabelsValue
if args.labels:
return labels_value(additionalPropert... | f32e135a211c151d97062e5535e7b0149f081ea9 | 49,080 |
import re
def clean_text(string):
"""
Remove links, mentions, special characters and numbers
"""
return ' '.join(re.sub("(@[A-Za-z]+)|([^A-Za-z \t])|(\w+:\/\/\S+)", "", string.lower()).split()) | 6dd7dc754ca77f2a7667cf470735a47e6afa069a | 49,081 |
def pivot_index(df):
"""Extrai os indexadores de uma pivot table, exlcuindo a linha de total"""
rows = df.shape[0]
return df.index[:rows - 1] | 7fce4bf9b236aab07882c0fc26e6af650437aedc | 49,082 |
def get_video_parts(video_path):
"""Given a full path to a video, return its parts."""
video_path = video_path.replace('\\','/') # Adapt for win
parts = video_path.split('/')
filename = parts[3]
filename_no_ext = filename.split('.')[0]
classname = parts[2]
train_or_test = parts[1]
retur... | 9f514909f398b0abf5b929c5ca384971168a268e | 49,084 |
def find_cal_by_type(standards, std_type):
"""
:param standards: list, of CalEvent objects
:param std_type: string, in ['high', 'mid', 'low']
:return: returns the first CalEvent in the list with the matching standard type
"""
return next((ce for ce in standards if ce.standard_used == std_type)... | f87e011534e6aa16c1c508bcafd334d7886f5568 | 49,085 |
import re
def match_mm3_angle(mm3_label):
"""Matches MM3* label for angles."""
return re.match('[\sa-z]2', mm3_label) | bb9d3a41e9b0aabb6efe36efc251ceb83c134911 | 49,086 |
def _getcnstr(obj, enum):
"""Get the constraint object"""
ac = obj.AccessConstraints
if ac.IsConstraintActive(enum):
cnstr = ac.GetActiveConstraint(enum)
else:
cnstr = ac.AddConstraint(enum)
return cnstr | fe8852cc4e1cd4e1e862135f245fdabb246ed8e7 | 49,088 |
def dict2json(dictionary):
"""
字典转json
"""
content = ''
for key in dictionary:
if content:
content = content + ','
content = content + '"' + key + '": "'
content = content + dictionary.get(key).replace('"', '\"').replace('\\', '\\\\') + '"'
return "{" + co... | 3e0d00aec2617926aead36b43f5719fb86ecff36 | 49,089 |
from typing import Any
def _float_val(col: Any) -> float:
"""Convert marker data to float values so we can put them in a
typed np.array. The marker column has type float if it has a 0.0
value, and would only have type str for a marker value."""
if isinstance(col, str):
return 1.0
return fl... | 8bd8636a21bb7e72eb6f585702462a34a63575a5 | 49,090 |
def getkeyval(key,commentdct):
"""
returns the value of the key
commentdct can be {'default': ['4'], 'maximum': ['6'], 'required-field': [''],
'note':['this is', ' a note']}
now key='default' will return the number 4
key='note' will return 'this is\\n a note'
"""
#--------minimum, minimum>, maximum, maximum<... | 66cd513619253d07d9750df9594050dc2884aad5 | 49,091 |
def __collatz_recursivo(numero: int, pasos: list) -> list:
"""Calcula recursivamente la conjetura de Collatz, devuelve los pasos realizados"""
pasos.append(numero)
if numero == 1:
return pasos
if numero % 2 == 0:
return __collatz_recursivo(numero // 2, pasos)
return __collatz_recurs... | 249a5de371528e5fe0f3aee247a0ce525461ca32 | 49,092 |
import base64
def validate_signature(value):
"""
Validate a JSON input for signature.
Parameters:
value (any): Input value
Returns:
boolean: True if value has the format required for a signature
"""
try:
return base64.b64encode(base64.b64decode(value.split(',')[1])) == \
... | 05000297dc7593e7a2073fef93e606d3164cac5d | 49,093 |
def get_multiple_ranges(service, spreadsheet_id, range_names):
"""
Get multiple ranges from Google Sheets.
:param service: Authenticated sheets service object
:param spreadsheet_id: Id of the spreadsheet
:param range_names: Ranges to get
:return: Results of the query
"""
result = servic... | 36bf548fe3d444909854317490379e5c64a0da33 | 49,094 |
def get_finishers(df):
"""
Filters the DataFrame for complete replies.
:param df:
:return:
"""
return df[(df['dispcode'] >= 31) & (df['dispcode'] <= 34)] | 8493943ed38f3a62b6a3d742ab2b4febccb34429 | 49,095 |
def payload_satisfies(pred):
"""This wraps a predicate so it is applied to the payloads of intervals.
The output function expects one or more Intervals as input (depending on
how many arguments ``pred`` expects) and applies the predicate to the
payloads of the Intervals instead of the Intervals themsel... | 8d758587d9a361740cfcb88c9ea29b7bea6f1ff7 | 49,096 |
def get_clusterequipment(api):
"""
Tests and tools should not use this directly. This is for hooking the
libraries together.
Parameter:
api (qalib.api.Api)
Returns a qalib.corelibs.equipmentprovider.ClusterEquipment object
"""
if hasattr(api, '_context'):
return api._context... | c08d9b756159ce49d164881bb09e7db2141a0fff | 49,099 |
import os
def create_xvfb_cmd():
"""Creates the Xvfb command with a write descriptor.
Returns:
List: Containing 2 lists.
The second List contains a read and a write descriptor.
The first List is the command to launch Xvfb process with the same write descriptor(from the first list) embedded i... | 9052ec9652d845fa6c3e531a2825e0fb0e200b1d | 49,100 |
def reshape_(dat, len_lv1, len_lv2):
"""
lstm reshaping
"""
# raw shape
shp = dat.shape
# length to discard
len_lv3, len_dsc = divmod(shp[0], len_lv1 * len_lv2)
remove_leftover = dat if len_dsc == 0 else dat[:-len_dsc]
## if there are leftover signal that doesn't divide evenly, remov... | f4076f42d76d51c55a4b66aafd59aa4f0a3f10eb | 49,101 |
def fix_label_length(labels: list, max_length: int=20) -> list:
"""
:param labels: a list of textual labels
:return: a list of updated labels
Ensure that all labels are shorter than a given length;
"""
fixed_labels = []
for l in labels:
if len(l) <= max_length:
fixed... | 25f20ceff1cfc2419837dc3fb0bdb8cf13b88082 | 49,102 |
def mongodb_str_filter(base_field, base_field_type):
"""Prepare filters (kwargs{}) for django queryset for mongodb
where fields contain strings are checked like
exact | startswith | contains | endswith
>>> mongodb_str_filter(21, '1')
'21'
>>> mongodb_str_filter(21, '2')
{'$regex': '^2... | 02c81184002946e57ac97b5fabe1412be6759821 | 49,106 |
def PI(improvements):
"""
Format a string of percent improvements.
"""
Z = sum(improvements)
if Z == 0:
return f"[{0.0:6.2f},{0.0:6.2f},{0.0:6.2f}]"
z = improvements/Z
return "[" + ",".join(f"{x*100.0:6.2f}" for x in z) + "]" | 3a986310c710d169aff956a11353b83ad3a489b5 | 49,108 |
def get_eso_file_version(raw_version):
"""Return eso file version as an integer (i.e.: 860, 890)."""
version = raw_version.strip()
start = version.index(" ")
return int(version[(start + 1) : (start + 6)].replace(".", "")) | d456ce65585a8aad0c08d9e53b6aeb77132a0d49 | 49,109 |
def have_readme(answer):
"""Check if project has a readme"""
return answer['check_readme'] | 47e963d36a18211e40580dae26e1c44b82f12375 | 49,111 |
from datetime import datetime
def is_expired(dt):
"""
判断时间是否过期
:param dt:日期字符串
:return:True or False
"""
if isinstance(dt, str):
dt = datetime.strptime(dt, '%Y-%m-%d %H:%M:%S')
return datetime.now() > dt | 3adfb90674e0173fc91ae1a6d007e02729c3eaee | 49,112 |
def io(graph):
""" finde input und output nodes (funktioniert nicht)
notizen:
sachen die keine outputs sind (normalerweise):
VarIsInitializedOp, ReadVariableOp, Identity, Const, AssignVariableOp (?)
"""
ops = graph.get_operations()
outputs_set = set(ops)
inputs = []
for op in ops:
if len(op.inputs) == 0 and ... | 5b735c85669dfcf6966cadfd2641cbbdce8cef3d | 49,113 |
import re
def is_valid_position(password: str) -> bool:
"""
Check if given password is valid.
Example: '1-3 b: cdefg' is invalid: neither position 1 nor position 3 contains b.
:type password: str
:rtype: bool
"""
first_index, second_index, letter, pwd = re.split(': |-| ',password)
ret... | 1222d27a99ff26e5bcf0be8e4fb98d28d792830f | 49,114 |
import subprocess
def is_git_repo(git_dir=''):
"""
Check if a directory is a valid git repo or not.
:param git_dir: the git directory
returns True if git_dir is a valid git repo, otherwise, False
"""
cmds = ['git', 'status']
if git_dir:
ret = subprocess.run(cmds, cwd=git_dir).retur... | 751ba992de6f09fd5dadb8df2988132035c053ad | 49,115 |
def int_to_bytes(x, length):
"""Converts bigendian integer to byte array with fixed length."""
res = bytearray(length)
for i in range(length):
res[length - i - 1] = int(x) % 256
x = int(x) // 256
return res | f8cfceca1c51483115c7d2d877b9d4a6c7c5fef9 | 49,117 |
def strip_linebreaks(s):
""" Strip excess line breaks from a string """
return u"\n".join([c for c in s.split(u'\n') if c]) | 537b835608e8697da4d9c05f1983fe39ef09b980 | 49,119 |
def find_output_node(nodetree):
"""
Get first output node that has incoming links.
"""
for n in nodetree.nodes:
if n.type.startswith('OUTPUT'):
for inp in n.inputs:
if inp.is_linked:
return n
return None | f3dafd1873baacdc1568a3ab6d7d8d70602127ec | 49,120 |
import socket
def is_unused_port(port, protocol):
"""
Check whether the port is unused
Args:
port (int): port
protocol (str): application protocol (tcp or udp)
Return:
bool: whether the port is unused
"""
protocols = {
'udp': socket.SOCK_DGRAM,
'tcp': so... | 6a40d4a1b9882d1f8cf2d9bfa56b59e2f81c7737 | 49,121 |
import glob
def filebrowser(ext=''):
"""
returns files with an extension
"""
target = "**/*.{}".format(ext)
return [filepath for filepath in glob.iglob(target, recursive = True)] | 63cf4bc4d26054340ffc481cdcf34783f4de982d | 49,122 |
def _make_rv_params_variable(rv, **params):
"""
Wraps the random variable rv, allowing it
to accept time-dependent parameters.
"""
if any(callable(x) for x in params.values()):
return lambda t: rv(
**{k: (x(t) if callable(x) else x)
for k, x in params.items()})
... | a497962b67f88a9bc01855e695d17a0aceaa8958 | 49,124 |
def _call_initialize(klass):
"""Call `_initialize` when the class is created"""
klass._initialize()
return klass | 367642e8c53bf1bf4d7e8625dbe60938a5b0d7ff | 49,126 |
import torch
def tsp_get_min_dist(dist_matrix):
"""
Takes a distance matrix dist_matrix of shape (n,n) or (bs,n,n)
Returns the mean minimal distance between two distinct nodes for each of the *bs* instances
"""
if not isinstance(dist_matrix,torch.Tensor):
try:
dist_matrix = to... | 1eea80f43b062567b58d9938016e6dce6c46e731 | 49,127 |
import os
def read_filenames_with_ending(path_to_dir, ending):
""" Reads filenames from a directory with a given ending
"""
res = []
for filename in os.listdir(path_to_dir):
if filename.endswith(ending):
res.append(filename)
return res | 29dd6114971d5e80f0124f44d27b679660b869cc | 49,128 |
import math
def isclose(a: float, b: float, rel_tol: float = 0.25, abs_tol: float = 1) -> bool:
"""Wraps math.isclose with very generous defaults.
This is useful for many floating-point operations where the spec does not
make accuracy requirements.
"""
if not (math.isfinite(a) and math.isfinite(b... | 5cbfbd4087a895ea634d3a5432930b18edf1e40a | 49,129 |
import os
import csv
def symbol_map(gene_symbols):
"""
This gene code map was generated on February 18th, 2019
at this URL: https://www.genenames.org/cgi-bin/download/custom?col=gd_app_sym&col=gd_prev_sym&status=Approved&status=Entry%20Withdrawn&hgnc_dbtag=on&order_by=gd_app_sym_sort&format=text&submit=su... | 67f19263f7a026dd29c0ec6a6ea4c6afad2b5057 | 49,130 |
def clean_data(df_):
"""
Clean and update DataFrames
"""
df_['CALL_TYPE'] = df_['CALL_TYPE'].map({'A': 0, 'B': 1, 'C': 2})
df_['DAY_TYPE'] = df_['DAY_TYPE'].map({'A': 0, 'B': 1, 'C': 2})
df_['WEEK'] = df_['TIMESTAMP'].apply(lambda x: x % (7*24*3600))
df_['DAY'] = df_['TIMESTAMP'].apply(l... | 2cf6342d98bfef372b9cc6b372ee59ba7601285f | 49,131 |
import os
def get_models(path):
"""
Get the path to the 3d model
"""
models = []
for f in os.listdir(path):
if ((f.endswith(extension) for extension in
['npy']) and not f.startswith('.DS_Store')):
models.append(os.path.join(path, f))
return models | 4333044805934fb26b80ae666f21aa043bc01c07 | 49,132 |
import re
def get_orbit_number(the_file):
"""
GET_ORBIT_NUMBER
Returns the orbit number from filename (last serie of 6 consecutives number
in filename
"""
to_return = re.findall("[0-9]{6}", the_file)[-1] #Get orbit number
return to_return | 8d7d8ce3d093ab5790a4a1f5f44928b18a169f3c | 49,133 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.