content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def _find_properties(parent, name):
""" Find properties with a given name.
"""
properties = [p for p in parent if p.attrib.get('name') == name]
return properties | 9a1b82d68dac9f34e26be75f4583d963bbb8f152 | 106,897 |
def vec_to_midpoint(array):
"""
Computes the midpoint between elements in an array.
Args:
array: (np.array)
Returns: (np.array)
"""
return (array[1:] + array[:-1]) / 2 | 29dc067910e9ac7bb72ce5dd6cb19fada3d29fc4 | 106,899 |
def char_to_bool(letter):
"""Transform character (J/N) to Bool."""
if letter.upper() == 'J':
return True
elif letter.upper() == 'N':
return False
else:
raise ValueError('Invalid character, only J or N allowed.') | 0dcde16fce2c116f640c3eb8d21ac20ed6514bcb | 106,901 |
def backend_extras(*requirements):
"""Construct list of requirements for backend integration.
All built-in backends depend on PyOpenGL so add it as default requirement.
"""
return ["PyOpenGL"] + list(requirements) | a7f96d47e4943c8e774671380d630afb215652d7 | 106,903 |
def _legend_add_subtitle(handles, labels, text, func):
"""Add a subtitle to legend handles."""
if text and len(handles) > 1:
# Create a blank handle that's not visible, the
# invisibillity will be used to discern which are subtitles
# or not:
blank_handle = func([], [], label=tex... | 01175234617193b101a062d58649e1589d492340 | 106,904 |
def set_independent_variables(data, dependent_variable):
"""
Set independent variables.
This helper functions isolates the independent variables in a data.frame.
:param data: An object of class pandas.DataFrame; the data to be analyzed.
:param dependent_variable: A string; the dependent va... | db29610c91a7a6351d162289744b4554ac41bf02 | 106,905 |
def normalize_constraints(constraints, flds):
"""
This method renders local constraints such that return value is:
* a list, not None
* a list of dicts
* a list of non-optional constraints or optional with defined field
.. note:: We use a new variable 'local_constraints' because the const... | 3d603d3331fced20d1e3f3ca1e527c6dec957bea | 106,906 |
def unify_columns(data, name1, name2, new_name, col_index):
""" Unify two columns using boolean disjunction
Args:
data: Pandas DataFrame
name1: Name of the first column
name2: Name of the second column
new_name: Name of the new column to introduce
col_index: Column index ... | a9750b048258183fe15eccf411f36732bdf20b64 | 106,913 |
def _get_unique_identifier(primary_unique_identifier: str, secondary_unique_identifier: str, tertiary_unique_identifier: str) -> str:
""" Return a unique identifier starting with the last possibility """
if tertiary_unique_identifier:
return tertiary_unique_identifier
elif secondary_unique_identifie... | 5af639b64ca923dc423e6172713a71b2e4d1afaa | 106,916 |
def simple_invert(data):
"""Invert the input image
Parameters
----------
data : np.ndarray (D,H,W)
Input image
Returns
-------
np.ndarray (D,H,W)
Inverted image
"""
return 1.0 - data | 25c91894917e8ff93d112e33f45c38c3adb5935e | 106,917 |
from typing import Sequence
from typing import List
def inverse_power_scale(data: Sequence[float], power: float) -> List[float]:
"""Scale a sequence of numbers based on the ``inverse_power_scale``.
The ``inverse_power_scale`` scales the distribution of numbers inversely
proportional to the ``power_scale`... | 93d41751c86cccc4b0180344252234183ccd32f3 | 106,918 |
import pytz
def parse_timezone(tz):
"""
Parse a timezone description into a tzinfo object
>>> parse_timezone("America/Los Angeles")
<DstTzInfo 'America/Los_Angeles' PST-1 day, 16:00:00 STD>
>>> parse_timezone("America/Los_Angeles")
<DstTzInfo 'America/Los_Angeles' PST-1 day, 16:00:00 STD>
"""
return p... | 7fb4f4f6506afb3f2057fae5020cb904f88e16a6 | 106,920 |
def dif(x, y, afrund = None):
"""
Calculate the difference between two arrays
"""
result = []
if afrund == None:
afrund = 2
for index, element in enumerate(x):
result.append(round((element - y[index]), afrund))
return result | f7a1ed998e66eb4f497124a3647a7ed04a82fce4 | 106,931 |
def get_dims(x):
"""
Get values of each dimension.
Arguments
----------
x: tensor scalar or array
"""
dims = x.get_shape()
if len(dims) == 0: # scalar
return [1]
else: # array
return [dim.value for dim in dims] | 2dc27f628770eca2fd70c0b202c2873f09626a19 | 106,934 |
def get_unaligned_spans(x1, x2, ptrs):
"""Get unaligned spans from an edit distance pointer matrix."""
n1, n2 = len(x1), len(x2)
i1, i2 = n1, n2
spans = []
end1, end2 = None, None
while i1 != 0 or i2 != 0:
i1_new, i2_new = ptrs[i1][i2]
if i1_new == i1 or i2_new == i2 or x1[i1_new] != x2[i2_new]: # ... | ac6017a17bd0d666a28dac981f66c8254712a082 | 106,935 |
def format_remove_duplicates(text, patterns):
"""Removes duplicated line-basis patterns.
Based on simple pattern matching, removes duplicated lines in a block
of lines. Lines that match with a same pattern are considered as
duplicates.
Designed to be used as a filter function for Jinja2.
Arg... | 0547ec746f0d2d8bce916916c2b235de1569886b | 106,936 |
import torch
def _get_grid_locations(image_height, image_width, device):
"""Wrapper for `torch.meshgrid`."""
y_range = torch.arange(0., image_height, device=device, requires_grad=False)
x_range = torch.arange(0., image_width, device=device, requires_grad=False)
y_grid, x_grid = torch.meshgrid(y_range,... | 089945f4058b14d8508c690a4709f65006dd9bb4 | 106,940 |
def calc_bmi(mass, height):
"""Calculates BMI from specified height and mass
BMI(kg/m2) = mass(kg) / height(m)2
Arguments:
mass {float} -- mass of the person in KG
height {float} -- height of the person in meters
Returns:
bmi {float} -- Body Mass Index of the person from speci... | 2b8aa82cc627913e55d721b6cc3548c227b1e1b2 | 106,941 |
def parse_server(node):
"""Return hostname and presence_id for given server.presence node."""
if '#' not in node:
return node, '-1'
hostname, presence_id = node.split('#')
return hostname, presence_id | 53e0fb2c28ddac25f5592f3bf1b91b4123e3496a | 106,942 |
from typing import Callable
import ast
def eval_lambda(val: str) -> Callable:
"""Parse a lambda from a string safely.
Args:
val: string representing a lambda.
Returns:
a callable.
Raises:
ValueError: in case the lambda can not be parsed.
"""
parsed_lamba = ast.parse(... | aa2081f66471d483ea76cc9723c632cb354d5f42 | 106,943 |
def average_above_zero (items):
"""
Compute the average of an given array only for positive values.
@type items: list
@param items: List of positive values
@rtype: float
@return: Return the average of the list
"""
# Don't compute if items isn't an List (array)
if type(items) is not list:
... | ba9770de1c594c6bd5d0dbabe89ec9b8e55b06c5 | 106,947 |
from typing import OrderedDict
def state_dict_to_cpu(state_dict: OrderedDict):
"""Moves a state_dict to cpu and removes the module. added by DataParallel.
Parameters
----------
state_dict : OrderedDict
State_dict containing the tensors to move to cpu.
Returns
-------
new_state_dict... | 50c0ac1cd44c3983fa5a86086535ff3af422462c | 106,948 |
def ndim(tensor):
"""
returns number of dimensions for tensor
"""
return len(tensor.get_shape()) | 47f3d2753a49ee049d4219fa7327f0ea7fa5fa00 | 106,951 |
def needs_binary_relocation(m_type, m_subtype):
"""Returns True if the file with MIME type/subtype passed as arguments
needs binary relocation, False otherwise.
Args:
m_type (str): MIME type of the file
m_subtype (str): MIME subtype of the file
"""
if m_type == 'application':
... | 8dac0cd20e782be24a8ffb35c5870aadc1001d0f | 106,952 |
import struct
def str64(s):
"""Convert a string to an int64."""
s = s + "\0" * (8 - len(s))
s = s.encode("ascii")
return struct.unpack("@q", s)[0] | 2017a9d25f1644a563506bf6e6e0e512b03ccbe3 | 106,958 |
import math
def rms_to_db(rms: float):
"""Root Mean Square to dB.
Args:
rms ([float]): root mean square
Returns:
float: dB
"""
return 20.0 * math.log10(max(1e-16, rms)) | 24dd5a58320283d33641ddff501feb4dd6580566 | 106,959 |
def classify_code_type(raw_string):
"""
A very simple function to detect HTML/XML.
"""
search_for_words = [
'</div>',
'</p>',
]
for word in search_for_words:
if word not in raw_string:
return 'XML'
return 'HTML' | 7f9963d6eb273c5b5f76e67943e8ee3ae6cb85ec | 106,962 |
def read_file(f):
"""
Read an entire file and return the contents
"""
with open(f) as f:
return f.read() | 5fd04024806fc529df539d051ab15da88eaf6562 | 106,964 |
import click
def include_option(func):
"""Option for including keyword(s)."""
return click.option(
'--include', 'include_keywords', help="Include pages with keyword(s) (comma-separated)."
)(func) | 6b9c5473480e9265be9604f7f51eae5a661ac6e9 | 106,969 |
import io
def isfile(f):
"""
Returns True if the given object represents an OS-level file (that is,
``isinstance(f, file)``).
On Python 3 this also returns True if the given object is higher level
wrapper on top of a FileIO object, such as a TextIOWrapper.
"""
if isinstance(f, io.FileIO)... | ac8f746c047f7ca616fd1c8d87d72f75fbfa0f9f | 106,978 |
from typing import Union
import re
def join(*args: Union[None, str], trailing_slash: bool = False) -> str:
"""
Return a url path joined from the arguments. It correctly handles blank/None
arguments, and removes back-to-back slashes, eg::
assert join('/', 'foo', None, 'bar', '', 'baz') == '/foo/ba... | 66cfb908d927091dc664809c3edbdc44cae3f323 | 106,989 |
def __consolidate_stability(df_vim_structured, ranked=True):
"""Calculates the variance of each feature's VIMs.
"""
return_val = df_vim_structured.var(axis=0)
return_val.name = 'VIM_var'
if ranked:
return_val.sort()
return return_val | 8a9acf812af6f72d3c2d232f8f5f3c6156227dd6 | 106,991 |
import traceback
def fetch_data(datagen, idx):
""" Fetch one batch of data from a data generator """
try:
return datagen[idx]
except Exception as exp:
traceback.print_exc()
print()
raise exp | 449ca1a8ee22022295dc989672e5cae1dc177338 | 106,995 |
import base64
def encode_to_b16(inp: str) -> bytes:
"""
Encodes a given utf-8 string into base-16.
>>> encode_to_b16('Hello World!')
b'48656C6C6F20576F726C6421'
>>> encode_to_b16('HELLO WORLD!')
b'48454C4C4F20574F524C4421'
>>> encode_to_b16('')
b''
"""
encoded = inp.encode("utf... | 15e451f01d46525bb3a9c4a5e8b009cff6683191 | 106,997 |
from datetime import datetime
def generate_fig_save_string(filename):
"""Save Figures
======================================
Saves figures using prescribed filename, date/timestamp and directory.
Args:
filename (string) - Filename to be used for figure.
Returns:
save_... | 4ede3fded795617defd74881dbef8d1c903b2046 | 106,999 |
import json
def load_json(file_path):
"""
Loads json from a file
:param file_path: the path to the file
:return: dictionary
"""
try:
with open(file_path, "r+") as file:
return json.loads(file.read())
except (OSError, IOError):
with open(file_path, "r+") as file... | 7203397948b2c227d697169f6bcd663f5f818674 | 107,001 |
import re
def match1(text, *patterns):
"""Scans through a string for substrings matched some patterns (first-subgroups only).
Args:
text: A string to be scanned.
patterns: Arbitrary number of regex patterns.
Returns:
When only one pattern is given, returns a string (None if no matc... | 1f01b9c2ba44cdbf84db67584af7524d67297dd1 | 107,002 |
import json
def load_element_list(filename):
"""
Load the list of elements in the ADAS database as
defined for this script in the 'elemenets.json' file,
located in the same directory as this script.
elements.json:
Define which datasets to use. The value indicates which year
the datase... | 41e0bb79f4a234ea48251ab173717afeddf8ce8a | 107,008 |
from json import dumps
def return_pyvpc_objects_json(pyvpc_objects):
"""
Return list of PyVPCBlock as json
:param pyvpc_objects: list of PyVPCBlock
:return: json formatted string
"""
result = []
for pyvpc_object in pyvpc_objects:
result.append({'start_address': str(pyvpc_object.get... | 61dde328d9ce5ecdae2af8dc861980053321b836 | 107,010 |
def parse_line(line):
"""Parse a line of instructions and return a (step, requires) tuple"""
assert line.startswith("Step ") and line.endswith(" can begin.")
word = line.split()
return word[7], word[1] | 47dca266cd19feccc41985947c646ada50b8da36 | 107,011 |
def read_blacklist_file(blacklist_file_path):
"""
Input is path to blacklist file. Blacklist file can be either
structured as <taxonID>\t<any other stuff, i.e. lineage...>
or just as <taxonID>.
This function returns a set of taxonIDs that are in the blacklist
"""
blacklist = set()
with ... | e59ebe40fd40db2365d334e993e788d4e2e2c3a0 | 107,012 |
import yaml
def load_yaml(yaml_file):
"""
Load *yaml_file*. Ruturn a dictionary.
"""
with open(yaml_file) as f:
config = yaml.safe_load(f)
return config | c24c64db5d491b784e018b3e2e5920c23366dd6d | 107,014 |
def add_config(cmd, config):
"""
Adds config information to cmd either by appending to an existing
--config/-C argument or appending to end of command.
cmd (list of strings): passed snakemake commands.
config (list of strings): additional values to add.
"""
config_flag = list(set(["--config"... | 57dda916a8f35a9c44f09ce60b65d9fabb885e1f | 107,016 |
def slurp(path):
"""Read the contents of a file, stripping leading and trailing whitespace."""
with open(path) as f:
return f.read().strip() | a87d703ab8c85772195714d080418f3cb99794f1 | 107,026 |
import json
def format_json(json_object, indent, default):
""" Pretty-format json data """
indent_str = "\n" + " " * indent
json_str = json.dumps(json_object, indent=2, default=default)
return indent_str.join(json_str.split("\n")) | 0b4942451524eb81bfa6d4396bee003de85181ca | 107,028 |
import pickle
def read(fnIn):
"""
Method to read a FourierICA object from disk
Parameters
----------
fnIn: filename of the FourierICA object
"""
# import necessary modules
filehandler = open(fnIn, "rb")
fourier_ica_obj = pickle.load(filehandler)
filehandler.clos... | 07dae75599f1d3931a4d6c389762e1cb96c9da0f | 107,030 |
def skip_label(what):
"""Generate a "skip" label name."""
return f"skip {what}" | 60c32ec2636cb3c14216b604dfa1987381f52dd5 | 107,035 |
from typing import Counter
def make_freq_table(stream):
"""
Given an input stream, will construct a frequency table
(i.e. mapping of each byte to the number of times it occurs in the stream).
The frequency table is actually a counter.
"""
freqs = Counter()
buffer = bytearray(512)
whi... | ee34be52e8274d90dc74308aad6b1b27c42ccd9c | 107,036 |
import importlib
def import_module(module):
"""Protected import of a module
"""
try:
ret = importlib.import_module(module)
except ImportError:
raise ImportError("Requested module '{}' not found.".format(module))
return ret | 7126404b74cf457e824f5ca316161ea78bd73a10 | 107,037 |
def _consonant_or_vowel_stem_verb(forms, *, strong):
"""Return the consonant root of a verb if it exists, otherwise the vowel root"""
# https://kaino.kotus.fi/visk/sisallys.php?p=55
return forms.get('imperatiivi_yks_3', '')[:-4] | 0580cfc2348f1b64a498968eec607c3824293d04 | 107,038 |
from typing import Union
def calculate_bmi(mass: Union[int, float], height: Union[int, float]) -> Union[int, float]:
"""That func calculate body mass index(bmi)
mass in kg
height in m
"""
return mass / (height ** 2) | 1811b45cb0d971e9dc6da0bc7ec8e2cd4ff43994 | 107,039 |
import math
def cone_volume(radius, height):
"""Compute and return the volume of a right circular cone."""
volume = math.pi * radius**2 * height / 3
return volume | d216dd45db741d085215a4b7842d17e97fcb3e00 | 107,042 |
def get_incoming_message_sub_id(ad):
""" Get incoming message subscription id
"""
if hasattr(ad, "incoming_message_sub_id"):
return ad.incoming_message_sub_id
else:
return ad.droid.subscriptionGetDefaultSmsSubId() | 1fed30d31b0b515bff806aacec02816dcb782b05 | 107,045 |
def PmfMean(pmf):
"""Computes the mean of a PMF.
Returns:
float mean
"""
mean = 0.0
for x, p in pmf.d.items():
mean += p * x
return mean | 0dce710f7fdc02313ff75c2e873400470f78ef90 | 107,048 |
def primes_till_N(N:int):
""" Generate all primes less than N
Args:
N (int): upper bound
Returns:
list: list of prime numbers
"""
nums = [True] * N
primes = []
for x in range(2,N):
if nums[x]:
primes.append(x)
for i in range(x, len(nums), x)... | f5324512b5db787e8353afd9ce5917dc9df7efc7 | 107,049 |
def is_parenthesis(char):
"""
Checks whether a char is a parenthesis
Parameters
----------
char : char
The charactere that is going to be checked
Returns
-------
bool: Whether the character is a parenthesis
"""
if char in ["(", ")"]:
... | 752fb4efb7bbd5ca5ba8f9dc4f12afa71ef4c0fc | 107,050 |
import re
from pathlib import Path
from typing import Union
from typing import List
from typing import Tuple
def find_files(
data_path: Union[str, Path], skip_str: Union[str, List[str]] = "sf6"
) -> List[Tuple[Path, Path]]:
"""A helper file to find GCWERKS data and precisions file in a given folder.
It se... | d83baf3b8819a1edc580034799a05123b5a5c973 | 107,053 |
def r_split(_, text, char):
""" Strips string to left of and including specified characters."""
return text.split(char)[-1] | 7ec4ccbdb7920640e5fdbf45737915e3b8f64e8c | 107,059 |
def filter_by_extension(ext):
"""
A higher-order function that returns a function
that given a filename filters by the extension
argument.
:param ext: the return function will return true if a filename ends with ext
:return: a one-arg function that takes a filename and returns true if filename e... | f4ec9e30bf867af29101226c23335c6328e6d032 | 107,071 |
import operator
def max_tuple_dict(tuple_dict, key_index):
"""Calculates the maximum of a dict of tuples
Uses the element at key_index as the key for comparisons.
In case of an empty dict, this returns (None, None).
"""
if len(tuple_dict):
return max(tuple_dict.items(), key=operator.itemg... | 6504cbe9ad39ac79ba6f6ed50395db31b3b476e6 | 107,077 |
def _incorrect_data_type_message(
data_dict: dict, field_name: str, expected_type: str
) -> str:
"""
Creates a string explaining to the user that the field input did not have the expected type.
:param data_dict: The dictionary containing the different data fields for the disk chopper.
:param field_n... | a8e39b48e75b8aa42e745891716ffd6726dcaef2 | 107,080 |
def parse_values_to_remove(options):
"""Manual parsing of remove arguments.
:param options: list of arguments following --remove argument
:return: dictionary containing key paths with values to be removed
:rtype: dict
EXAMPLE: {'identity.username': [myname],
'identity-feature-enabled.... | 0d9ff5fbc8f5db5a40c38c84206699b98fe49af6 | 107,082 |
import base64
def B64(val: bytes) -> str:
"""Return base64-encoded string representation of input binary data."""
return base64.b64encode(val).decode() | 4525d982cbb80d97dce14b446fc8e203b9176d68 | 107,083 |
def s_and(*args):
"""Logical and."""
result = True
for i in args:
result = result and i
if not result:
break
return result | 022f3a14e0430210a636828daf2056c653107c58 | 107,088 |
def is_frequent_individual(itemset, dico, ds, minFrequency):
"""
Checks if the itemset contains only frequent items
:param itemset: the itemset
:param dico: dictionary containing the transactions
:param ds: dataset
:param minFrequency: the minimum frequency for the items
:return: True if all items in itemset are... | 7de7f137710fe92490db564a5000b8a1074f793d | 107,091 |
def fatorial(n, show=False): # o show é o parâmetro opcional e ele começa com false porque não quer mostrar o fatorial
"""
-> Calcule o fatorial de um número.
:param n: O número a ser calculado.
:param show: (opcional) Mostrar ou não a conta.
:return: O valor do Fatorial de um número n.
"""
... | e901e36904dddd820973820be19e3549a3946c87 | 107,095 |
import random
def random_book(json_data):
"""
selects a random book out of all books on a given user shelf via json_data
:param json_data: json data provided by the Goodreads API for a given user shelf
:return: string of a books title and author
"""
total = json_data["GoodreadsResponse"]['revi... | b36c800461240e3844c3586c75b6d2be8b18968a | 107,096 |
def read_dataset(spark, file_path, file_type, file_configs={}):
"""
This function reads the input data path and return a Spark DataFrame. Under the hood, this function is based
on generic Load functionality of Spark SQL.
Parameters
----------
spark
Spark Session
file_path
Pa... | e9fb4d2195162ce880048fee262bfa489f741bbd | 107,097 |
def compute_scale_down(input_size, output_size):
"""compute scale down factor of neural network, given input and output size"""
return output_size[0] / input_size[0] | fa1ebfa7fc0adc850121736f54ffd89cb560be93 | 107,100 |
def compute_line_col(text, size_tab):
"""Computes the line and column in which each letter of text is located."""
at_what_line = [0] * len(text)
at_what_col = [0] * len(text)
line = 1
col = 1
for (position, letter) in enumerate(text):
at_what_line[position] = line
at_what_col[pos... | 438ba529d67e196e9f7f14c1c4653c51994c0e85 | 107,101 |
def encode_byte_array(value: bytes) -> bytes:
"""Encodes a byte array.
"""
return bytes([]) if isinstance(value, type(None)) else value | 98377bdab13bd4dce7e19efe5ab4392b1343e35f | 107,102 |
def read_other(config):
"""
Read other options.
"""
other = {}
section = 'other'
if 'print models' in config[section]:
other['print_models'] = config.getboolean(section, 'print models')
plot = config.get(section, 'plot time').split()
other['plot_time'] = [float(t)-2450000. for t ... | d66e1f1145dea774263fdd4fe1a74fd1eb153c6c | 107,104 |
def les(prop, value):
"""Check if a property is less than a value"""
return prop < value | 3793119aeb6f053b3fd240ec1d74d1d562d473d4 | 107,108 |
from typing import Sequence
def extract_coordinates(dicom, field):
"""Given a field that is provided for a dicom, extract coordinates"""
field = field.replace("from:", "", 1)
coordinates = []
if field not in dicom:
return coordinates
regions = []
region = dicom.get(field)
# First... | e51e4e2eefa1f2ce370e565ab9b02b28f6eeb33c | 107,111 |
import jinja2
def get_jinja2_template (
template_file: str,
) -> jinja2.Template:
"""
Load a Jinja2 template.
"""
env = jinja2.Environment(
loader=jinja2.FileSystemLoader("."),
autoescape=True,
)
return env.get_template(template_file) | b6b1d08c8e0c1db8fcb11962606bd9cfdad32760 | 107,113 |
from typing import Set
from typing import Dict
from typing import Optional
import math
def compute_minimum(open_set: Set[str], f_scores: Dict[str, float]) -> Optional[str]:
"""Compute the node_id in open_set with the minimum f_score"""
min_id: Optional[str] = None
min_f_score = math.inf
for identifier... | 5e88285aef816c7a3d4bc4584b76ffedb689c865 | 107,115 |
import re
def is_relative_path(s):
"""
Return True if s looks like a relative posix path.
Example: usr/lib/librt.so.1 or ../usr/lib
"""
relative = re.compile('^(?:([^/]|\\.\\.)[\\w_\\-]+/.*$)', re.IGNORECASE).match
return relative(s) | 7b817849c79d92ef442da5c609df450379d1d9f8 | 107,121 |
def get_collection(collection, key, default=None):
"""
Retrieves a key from a collection, replacing None and unset values with the
default value. If default is None, an empty dictionary will be the
default.
If key is a list, it is treated as a key traversal.
This is useful for configs, where ... | e6983b67ec746c6839e332471ef540b6199a861b | 107,123 |
from typing import List
from typing import Set
def reference_descendent(
current_package: List[str], imports: Set[str], py_package: List[str], py_type: str
) -> str:
"""
Returns a reference to a python type in a package that is a descendent of the
current package, and adds the required import that is ... | 47115a27317a340f9b467a9834a930512bb86979 | 107,124 |
def get_home_page(pypi_pkg):
"""Retrieve home page link"""
home_page = pypi_pkg["pypi_data"]["info"]["home_page"]
return home_page | 4ccdcc48cf6329fad6e338be88fc80150e38826c | 107,127 |
def create_nodenames_from_branching_factors(BFS):
"""
This function creates the node names of a tree without creating the whole tree.
Parameters
----------
BFS : list of integers
Branching factors.
Returns
-------
nodenames : list of str
a list of the node names induced... | aa869af9a7929b63ec3a02ccb6dd955e7472efb0 | 107,137 |
def strip_all (lst):
""" Strips leading and trailing whitespace from all strings in a list.
Args:
lst (list of str): The list of strings to strip.
Returns:
list of str: The list of stripped strings.
"""
return list(map(lambda x: x.strip(), lst)) | faae74c3b868d02ba4e69fde72101ef5bbb4ca3b | 107,140 |
def DictGetNotNone( d, k, dflt ):
"""Get a value from the dictionary; if not such value, return the specified default"""
return d[k] if k in d and d[k] is not None else dflt | 19b987f3f862352e64ef26449979a08b37754eda | 107,141 |
def _sum_frts(results:dict):
"""
Get total number of FRTs
Arguments:
results {dict} -- Result set from `get_total_frts`
Returns:
int -- Total number of FRTs in the nation
"""
if results == None:
return 0
total_frts = 0
for result in results:
if result['... | 44d56d9e35c2b910ea10e25bb3de7ba9ae0c6294 | 107,152 |
def get_file_ext(f):
"""
takes in a filename.ext, finds extension by looking for the last . delimiter, and returns the filetype as str
:param f: str, required; filename with extension
:return: file extension
"""
delim = f.rfind('.') + 1 # locate the delim... | bfb9b77aa14325c4888511473a975839992a0f18 | 107,154 |
def filter_to_economic(df):
"""filter to educational attainment indicators"""
df = df.filter(regex="GeoID|P25pl|LTHS|HSGrd|SClgA|BchD")
return df | 0d4b78f177af6a02407e069e7b4bb89a4a14eb39 | 107,164 |
def name_sorted(indexes):
"""Sort indexes by name"""
return sorted(indexes, key=lambda x: x['name']) | 5dcf99e99f98d686c4afa9def73c44f46116c6de | 107,165 |
def _reactome_wrapper(pathways):
"""Filter down the human pathways.
:param list[Pathway] pathways: list of pathways
:rtype: list[Pathway]
:return: human pathways
"""
return [
pathway
for pathway in pathways
if pathway.species.name == 'Homo sapiens'
] | e6c56438ea12ddfb4968511ea2721a6643f8b4d5 | 107,173 |
import collections
def build_hitmap(data):
"""
Build a hitmap from the given list of address.
A hitmap is a map of address --> number of executions.
The list of input addresses can be any sort of runtime trace, coverage,
or profiiling data that one would like to build a hitmap for.
"""
o... | 38bea2a1e2814edd5f5a81dc1c5c54bd93fede7e | 107,175 |
def sqrt(x):
"""for x>=0, return non-negative y such that y^2 = x"""
estimate = x/2.0
while True:
newestimate = ((estimate+(x/estimate))/2.0)
if newestimate == estimate:
break
estimate = newestimate
return estimate | 34112bd08bfbf64699503548556380313e032320 | 107,177 |
def _get_shared_bottom_tops(top, layers):
"""
Get the layers that have the same bottom layer as given top layer's.
This happens for most pooling layers and all concat layers, where
outputs are branched to several convolution layers on top.
"""
tops = []
for l in layers:
if set(top.bottom).intersection(l.bottom... | a05f4ecff3144e92d06ebacd8680998f13cd3fa7 | 107,179 |
def moedaBR(vlr):
"""
-> Formata um número em moeda Brasileira (R$)
:param vlr: é o valor que será formatado. Ex.: 32.65
:return: vai retornar R$ 32,65
"""
return f'R$ {vlr:_.2f}'.replace('.', ',').replace('_', '.') | d846e0d57faebcc6141d730657873929ad8d0586 | 107,182 |
def create_steer_command(packer, angle_cmd, enabled, action, angleReq):
"""Creates a CAN message for the Ford Steer Command."""
values = {
"ApaSys_D_Stat": action,
"EPASExtAngleStatReq": angleReq,
"ExtSteeringAngleReq2": angle_cmd,
}
return packer.make_can_msg("ParkAid_Data", 2, values) | 75cfc9a881f11bfdb46de7f1dfb2c09fb0096518 | 107,185 |
def convert_to_str(value):
"""convert True/False to yes/no and all values to strongs"""
if isinstance(value, bool):
if value:
return "yes"
return "no"
return str(value) | dfa9dbaa31e18ec8c1433dd81e80b578fd8fe541 | 107,191 |
def indent(level, size=2):
"""Return indentation."""
return ' ' * level * size | 8208680da30f43b582dc25fe106e1e805a85064d | 107,192 |
def Hex8_node_coords(n): #Test function written
"""Get the local coordinates for node n (0-7)"""
coords = [[-1,-1,-1],[ 1,-1,-1],[ 1, 1,-1],[-1, 1,-1],\
[-1,-1, 1],[ 1,-1, 1],[ 1, 1, 1],[-1, 1, 1]]
return coords[n] | f063cd266d31b24e84cf101ee0ae961624e0fe5d | 107,196 |
def binary_search(target, lst):
"""
Perform binary search over the specified list with the specified target.
The type of the target should match the types of the elements of the list and the list should be sorted.
Parameters
----------
target : Any
The element to search for in the ... | b7a1c8e9e9212107bef66835b7eece7e8562d9aa | 107,199 |
def is_power_of_two(a):
""" Figures out if an int is a power of two. """
return not ((a-1) & a) | af8e7eef4c74267642345cf2d47ef6f4919c76cd | 107,201 |
def read_data(filepath: str):
"""
function to read the actual data
:param filepath: the relative path to the file containing the specifications of the data
:return: the data in filepath as a two-dimensional list where each row represents one instance and
its values
"""
with open(filepa... | 2f37b90c3831a9d64a7d0081083bdcfadcfcd179 | 107,205 |
def vec_dotprod(vector1, vector2):
"""
Dot product of 2 vectors
Parameters
----------
vector1 : list
Input vector 1.
vector2 : list
Input vector 2.
Returns
-------
dotp_res : float
Resulting dot product.
"""
dotp_res = sum(v1_i * v2_i for v1_i, v2_i... | b910b2e978e46665a6e977d7686b90813ef30157 | 107,206 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.