content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def one_at(pos, size=8):
"""
Create a size-bit int which only has one '1' bit at specific position.
example:
one_at(0) -> 0b10000000
one_at(3) -> 0b00010000
one_at(5, 10) -> 0b0000010000
:param int pos: Position of '1' bit.
:param int size: Length of value by bit.
:rtype: int
... | 3075f1da6dd39aa24c64a51cb8422ab553deb680 | 63,666 |
def make_site_pin_map(site_pins):
""" Create map of site pin names to tile wire names. """
site_pin_map = {}
for site_pin in site_pins:
site_pin_map[site_pin.name] = site_pin.wire
return site_pin_map | c507802ec4e95a13ae26e1e3e48200eef72948cf | 63,669 |
import importlib
def load_method_fn_from_method_path(module, method_path):
"""
Args:
module (python module): module from which take the method.
method_path (string): path to the method.
Returns:
if method_path is None returns None
otherwise returns
module.method_p... | d0c88b4ebb24f5878d2eebeb77a587cf0b3a2bd2 | 63,671 |
def revcomp(seq: str) -> str:
"""
reverse complement a nucleotide sequence.
"""
rc_nuc = {
'A': 'T',
'C': 'G',
'T': 'A',
'G': 'C',
}
seq_rev = seq[::-1]
seq_rev_comp = ''.join([rc_nuc[n] for n in list(seq_rev)])
return seq_rev_comp | b2745b3b3cd29b339f9305414bdfdaf297fb53a9 | 63,674 |
def flatten_diff(diff):
"""
For spawning, a 'detailed' diff is not necessary, rather we just want instructions on how to
handle each root key.
Args:
diff (dict): Diff produced by `prototype_diff` and
possibly modified by the user. Note that also a pre-flattened diff will come out
... | 4b41ab2dd6fd377a3a323f108b853eec63b6e5be | 63,675 |
import yaml
def load_config_file(config_file):
"""
加载配置文件
Args:
config_file(str): 配置文件路径
Returns:
config_dict(dict): 配置词典
"""
with open(config_file, 'r', encoding='utf-8') as rf:
config_dict = yaml.load(rf, Loader=yaml.FullLoader)
return config_dict | 4937a16ed01b69c5fc2f37265a50f0cd33a9f2ad | 63,676 |
def update_postcode(postcode_value):
"""Update postcodes using mapping dictionary.
Takes postcode value, updates using postcode_mapping
dictionary and returns updated value.
"""
postcode_mapping = {'78621' : '78681', '787664' : '78664', '78728-1275' : '78728'}
if postcode_value not i... | 6a296e32d0af0a43e80d19b29060d31ca6fb6fa3 | 63,680 |
import re
def convert_gcs_json_url_to_gsutil_form(url: str) -> str:
"""
Convert a GCS JSON API url to its corresponding gsutil uri.
Parameters
----------
url: str
The url in GCS JSON API form.
Returns
-------
gsutil_url: str
The url in gsutil form. Returns empty strin... | cf2d16a23aa250fb6d6e87e48e151f9f73bd4d86 | 63,684 |
def can_merge_packages(package_info_list):
"""Returns true if all versions of a package can be replaced with
a package name
Args:
package_info_list: list of PackageInfo. Method assumes,
that all items in package_info_list have the same package name,
but different package version.
... | 43748072642d5c1a6d78da33e9e861262a1682fc | 63,686 |
def _gen_index_name(keys):
"""Generate an index name from the set of fields it is over.
"""
return u"_".join([u"%s_%s" % item for item in keys]) | b07c9bcbe829644b8cdcf3aa28ded9b1f57622eb | 63,690 |
def _isoformat(date):
"""Format a date or return None if no date exists"""
return date.isoformat() if date else None | 566e26fed7818874322f820e684c68940c726376 | 63,693 |
def get_cv(word, vowels, sep=None):
"""
Calculate the consonant ("C") and vowel ("V") structure of the
given word. Returns a string of the characters "C" and "V"
corresponding to the characters in the word.
*vowels* -- A list of the characters representing vowels.
*sep* -- String used to separ... | fbfe1c11e2b21f51fcd95bff454edd295e502314 | 63,694 |
import socket
def check_devserver_port_used(port):
"""check if port is ok to use for django devserver"""
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# immediately reuse a local socket in TIME_WAIT state
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try:
sock.bind(... | c32654af07e22122c62b521cf8af23880a131e4d | 63,702 |
import collections
def taxonomy_counts(checkins, beerstyle2cat, bid2beer):
"""
Aggregate beer checkins `checkins` list to given taxonomy `beerstyle2cat`.
`beerstyle2cat` is a dictionary mapping an Untappd beer style string
to a taxonomic category.
"""
counts = collections.Counter()
for c i... | 84fbcc5fa31a376d735b7392ecb553c55240e609 | 63,707 |
import torch
from typing import Dict
from typing import Any
import json
def inspect_parameters(module: torch.nn.Module, quiet: bool = False) -> Dict[str, Any]:
"""
Inspects the model/module parameters and their tunability. The output is structured
in a nested dict so that parameters in same sub-modules ar... | 54bf3ac16744ec61aede08fd66ec8f49ace22778 | 63,708 |
import re
def get_uninterpolated_placeholders(string):
"""Check if a string has any remaining uninterpolated values.
Args:
string (string): String object.
Returns:
list : List of uninterpolated values.
"""
# Regex to find matches
matches = re.findall(r'%\(([a-zA-Z0-9_-]+)... | ace5503d8e5cc23ab185314123e1fbb2579c43b6 | 63,709 |
from typing import Iterable
from typing import Callable
def quantify(it: Iterable, pred: Callable = bool) -> int:
"""
Count how many times the predicate is true
>>> quantify([[], (), None, 0, 1, -1, 'fsdfds', ''])
3
"""
return sum(map(pred, it)) | e2ce08256736dc893e5d3c8e4423b86a3039aac1 | 63,712 |
def merge_dicts(*dictionaries):
""" Merge multiple dictionaries. Last argument can be a boolean determining if the dicts can erase each other's content
Examples
--------
>>> dict1 = {'label': 'string'}
>>> dict2 = {'c': 'r', 'label': 'something'}
>>> merge_dicts(dict1, dict2, False)
{'labe... | 82690f2cfc26b897a55db08f609d5acb208955e3 | 63,722 |
def string_splitter(input_str, max_length=40):
"""
Returns a string that is the input string but with \n inserted every max_length chars
:param input_str:
:param max_length: int num of chars between \n
:return: string
"""
chunks = []
chunk = ''
pieces = input_str.split(' ')
fo... | a1b77c8652997fb1508cc9607431799e04d47059 | 63,728 |
def read_parameters_dict_lines_from_file_header(
outfile, comments="#", strip_spaces=True
):
"""Load a list of pretty-printed parameters dictionary lines from a commented file header.
Returns a list of lines from a commented file header
that match the pretty-printed parameters dictionary format
as ... | 6f06fade43b69da083b95b4ddc0d10f168779118 | 63,732 |
def extract_smali_method(method_name, smali_file):
"""
Extracts a smali method from a smali file
:param str method_name: the method to be extracted
:param str smali_file: the file to extract the method from
:return: the extracted method or empty string if not found
"""
with open(smali_file,... | e36f1d0dc1ac561ddcfb0fa237ead89f07780be4 | 63,733 |
def contains(list, value):
"""Test value is in the list"""
return value in list | 5dc8a462aeb6e23ff780e778c7a159528fa015cb | 63,737 |
import torch
def vectors_to_torch(vectors):
"""Convert numpy arrays in a vectors dictionary to torch double format.
Args:
vectors (:obj:`dict`): vectors dictionary as specified by s3dxrd.measurements.Id11.peaks_to_vectors()
Returns:
(:obj:`dict`): dictionary with same fields as ```ve... | 1e28ef30103cef27768ab24c1f16970211ab073c | 63,738 |
import hashlib
def _hash_sha1(buf):
"""
Produce a 20-bytes hash of *buf* using SHA1.
"""
return hashlib.sha1(buf).digest() | bc7e8f23e5b6dac25f6cdf7c95a9aaa9ee8b1d6b | 63,741 |
import uuid
def generate_uuid_from_guid(guid: str, number: int):
"""Generate UUID from MD5 Hash of GUID and sequence number.
Args:
guid (str): Hex digest of UUID.
number (int): Sequence number.
Returns:
str: Hex digest of generate UUID.
"""
return str(uuid.uuid3(uuid.UUI... | cf3d1830bd3f6993d8b607a9c3f9412fd5257ba0 | 63,752 |
from typing import Tuple
def get_pos(target: Tuple[float, ...], area: Tuple[int, ...]) -> Tuple[int, ...]:
"""Get absolute position, given relative position and target area
Parameters
----------
target : Tuple[float, float]
Relative position
area : Tuple[int, int]
Absolute area
... | 44c469a807ca9e256f87a32bb2c03e4e0a1b9cf3 | 63,756 |
import torch
def split_last_dimension(x,n):
"""Reshape x so that the last dimension becomes two dimensions.
The first of these two dimensions is n.
Args:
x: a Tensor with shape [..., m]
n: an integer.
Returns:
a Tensor with shape [..., n, m/n]
"""
chunk_size = int... | 5ef93c3cb4cd452c045b1686ee0bc890b8c76e82 | 63,766 |
import binascii
def bin2base64(bin_str):
""" Convert bytes to base64 """
return binascii.b2a_base64(bin_str) | 0482412894d339b97517bf100dc159084f482238 | 63,774 |
def read_cluster_file(clusters):
"""
Read a cluster output file. This file should have the form:
cluster_integer SEQUENCE1
cluster_integer SEQUENCE2
...
Returns two dictionaries. One maps sequence to cluster, the other maps
cluster number to sequence.
"""
# Read file
f = op... | da76c094fbdf75537b699d2b5a10e2dc8fab1ffd | 63,777 |
def is_in_line(to_keep, line):
"""
Checks if any of the class names in to_keep are in the line
:param to_keep: A list that holds the class names which the user wants to keep.
:param line: A single line in the file that is currently being examined.
:return: Returns True if a class name from to_keep i... | 3115d7932bfae59232592d35532aa2bc3d51f5ad | 63,778 |
import ast
def is_list_addition(node):
"""Check if operation is adding something to a list"""
list_operations = ["append", "extend", "insert"]
return (
isinstance(node.func.ctx, ast.Load)
and hasattr(node.func, "value")
and isinstance(node.func.value, ast.Name)
and node.fun... | bad2ce31661f0de763a9fdac9fb9793a77cdbef3 | 63,780 |
def _check(shape, problem):
"""
Check if all points of the shape are contained in problem.
"""
return all([ point in problem for point in shape ]) | 9395197d46eb56c91396029be2f5c94962420bf3 | 63,781 |
from typing import Optional
def gens_are_consistent(
complex_phase,
solvent_phase,
ngens: Optional[int] = 2,
nsigma: Optional[float] = 3,
) -> bool:
"""
Return True if GENs are consistent.
The last `ngens` generations will be checked for consistency with the overall estimate,
... | ced51ee927b80a225c840d4556d50a252ccbe77c | 63,784 |
def label_isolated(g):
"""label_isolated
Creates a vertex property map with True if a node has no neighbours,
else False.
Parameters
----------
g (graph_tool.Graph):
A graph.
Returns
-------
isolated_vp (graph_tool.VertexPropertyMap):
Property map la... | f14d60753cd50a4085a48620b19a8bce0c9397c4 | 63,786 |
def _is_valid_make_var(varname):
"""Check if the make variable name seems valid."""
if len(varname) == 0:
return False
# According to gnu make, any chars not whitespace, ':', '#', '=' are valid.
invalid_chars = ":#= \t\n\r"
for n in range(0, len(invalid_chars)):
if invalid_chars[n] ... | 5c233ff464dabc428bed9f5aa93a3f3f4aa60a0e | 63,788 |
def uniquify_labels(labels):
"""determines set of unique characters in labels (as returned by load_labels)
and the number of occurences of each unique character
Parameters
----------
labels : list
of str
Returns
-------
unique_labels : set
of char, e.g. {'0','a','b','c'... | b6eb2db46397c32b9a41f1c4affd2a1ca6a150a5 | 63,791 |
import hashlib
def get_etag(text):
""" Compute the etag for the rendered text"""
return hashlib.md5(text.encode('utf-8')).hexdigest() | fdf0d3c93b23fd25934653d15f262864ea82f595 | 63,794 |
def get_resource_limits(cursor, user, host):
"""Get user resource limits.
Args:
cursor (cursor): DB driver cursor object.
user (str): User name.
host (str): User host name.
Returns: Dictionary containing current resource limits.
"""
query = ('SELECT max_questions AS MAX_QU... | c0583c885b05194673fd474013b61a0637fa00e7 | 63,797 |
import inspect
def instantiate_class_and_inject_attributes(cls, **kwargs):
"""
instantiates a class with the given kwargs, picking those arguments that are in the signature of cls to
use for the __init__, and adding attributes to the constructed object with the remaining.
:param cls: class to insantia... | 2b36c4f78611cad66c74ae4a2485853c6e6b17ad | 63,800 |
def get_same_predictions(y_pred, y_pred_adv):
"""
Get the indexes of the predictions where the image and the adversarial image where
classified as the same class.
Parameters
----------
y_pred: array
Array with the predictions of the model in dataset.
y_pred_adv: array
Array... | fe6d56e49edc79e1b53c74fb27a568ca21842f18 | 63,803 |
import collections
import re
def _build_question_dictionary(vqa, min_thre=0):
"""
:param vqa: VQA instance
:param min_thre: only words that occur more than this number of times will be put in vocab
:return: word-index dictionary
"""
counter = collections.defaultdict(int)
for i, q in vqa.qq... | adc227095fbd92f661680ec66884d5ac2e4821f5 | 63,805 |
def map_ores_code_to_int(code):
"""
Takes a 1-2 letter code from OREs and turns in into an int
ORES Score map
Stub - 0
Start - 1
C - 2
B - 3
GA - 4
FA - 5
"""
return {
'Stub': 0,
'Start': 1,
'C': 2,
'B': 3,
'GA': 4,
'FA': 5,
... | 5730b720ebab91db0d9a5708b458404c233d6b94 | 63,810 |
def format_tuple(values, resolution):
"""Returns the string representation of a geobox tuple."""
format = "%%0.%df" % resolution
return "|".join(format % v for v in values) | 792020d9043ad0abf5062e574cfbdbbf35d8f803 | 63,812 |
def f_htmltag(name: str, path: str) -> str:
"""
Receives tha URL and the name of the object it points to in dorder to create the html link tag
:param name: str contains the name/title of the (html) plot.
:param path: str contains the path to the (html) plot.
:return: str. HTML tag with the link and... | cf6be68343137d1789d2e4e1e8b95119a32cd85b | 63,815 |
def attr_to_dict(obj, attr, dct):
"""
Add attribute to dict if it exists.
:param dct:
:param obj: object
:param attr: object attribute name
:return: dict
"""
if hasattr(obj, attr):
dct[attr] = getattr(obj, attr)
return dct | a6b3281cdbd887577354290b56ae95128d19198f | 63,817 |
def create_securitygroup_dialog(context, request, securitygroup_form=None, security_group_names=None):
""" Modal dialog for creating a security group."""
return dict(
securitygroup_form=securitygroup_form,
security_group_names=security_group_names,
) | affc450f86f20ad81a8a5750c3f817cc0245d220 | 63,818 |
def remove_species_and_rename_other(df, drop_species, rename_category):
"""
Remove the species in drop_species, and rename the "other" category to
"rarely_requested_species".
"""
reduced_df = df.loc[~df.species_group.isin(drop_species),:].copy()
reduced_df.species_group.cat.remove_categories(dr... | b5d453ebb4ed8ba5111e8ec909192927433224a8 | 63,821 |
def create_graph(V, color, label):
"""
Setup the graph informations: x values, y values, color and label name.
Parameters
----------
V : dict
V contains X and Y values.
color : str
color name.
label : str
label name
Returns
-------
... | 5e5153606becdcbc18b77359c541925c3bb77915 | 63,823 |
import string
def _normalize(word):
"""Convert word to a form we can look up in CMU dictionary."""
return word.strip().strip(string.punctuation).lower() | ae6bdaa9b05c68e2429464e8394bb8e40b8fe07a | 63,824 |
def anotate(name):
"""Annotate an object with a name."""
def decorator(obj):
setattr(obj, "_tea_ds_plugin", name)
return obj
return decorator | 2e2634508fd8a9554bca9510f8f4e09017451be3 | 63,826 |
def countEdges(halfEdge):
"""Given a half-edge of a polygon, count the number of edges in this polygon."""
numberOfEdges=1
startingEdge=halfEdge
edge=startingEdge.next
while edge is not startingEdge:
edge=edge.next
numberOfEdges+=1
return numberOfEdges | 9d7d67a4ffd9ecfd60104afa0307d2831adbcd08 | 63,834 |
def db_delete_from_user_fields(project_id: str, field: str) -> str:
"""Remove the specified project from the field in the UsersCollection."""
return f'db.UsersCollection.updateMany({{}}, {{ $unset: {{ "{field}.{project_id}" : ""}} }})' | 04f94e12e0ffb0765456b453ffb6e942f0cc39ef | 63,836 |
def find_missing_number(nums: list[int]) -> int:
"""
Complexity:
N = len(nums)
Time: O(N) (iterate the entire array)
Space: O(1) (in-place computations)
Args:
nums: array containing n distinct numbers
taken from the range [0,n]
(n+1 possi... | aae8fffbef86eaf2dcdf0bf166e57858a4a9aa75 | 63,840 |
import torch
def smooth_dice_beta_loss(pred: torch.Tensor, target: torch.Tensor,
beta: float=1., smooth: float=1., eps: float=1e-6) -> torch.Tensor:
"""
Smoothed dice beta loss. Computes
1 - (((1 + beta**2) * tp + smooth) / ((1 + beta**2) * tp + beta**2 * fn + fp + smooth + eps))... | 7b9086d8f7d0c94d405f04f55df787fcf406e1b1 | 63,853 |
def sort_dicts(dicts, sort_by):
"""
:param dicts: list of dictionaries
:param sort_by: key by which the list should be sorted
:return: sorted list of dicts
"""
return sorted(dicts, key=lambda k: k[sort_by]) | 1215b4f90de13ee45181a7573b3f5bd21fc36aab | 63,855 |
def map_label(row, label_map):
"""
Creating a touple using two pre-existing columns, then using this touple as the key to look up table label in the dictionary
Parameters
----------
row: row
this function will apply to every row in the dataframe
label_map: dictionary
... | 091f57783c995d1b69822b81bd264437ff5e1bcb | 63,857 |
import base64
def serializePemBytesForJson(pem: bytes) -> str:
"""Serializes the given PEM-encoded bytes for inclusion in a JSON request body."""
return base64.b64encode(pem).decode('utf-8') | 48f332bafadc18ccabd8f61715bee3d735296507 | 63,858 |
def mode(values):
"""Returns the mode of the values.
If multiples values tie, one value is returned.
Args:
values: A list of values.
Returns:
The mode.
"""
counts = {k: values.count(k) for k in set(values)}
return sorted(counts, key=counts.__getitem__)[-1] | 19b82c2d05cec4755608883dc76b328d07e8a72c | 63,862 |
import re
def clean_text(txt, regex_lst, RE_EMOJI, stopwords_hindi):
"""This function takes the regular expression for various things such as punctuations and all which we want to remove and returns the cleaned sentence.
Args:
txt (str): Sentence which we have to clean.
regex_lst (List[re]): List of all the... | 39a5662fec925fcf2ff3f2703c838cfdc36de412 | 63,865 |
def format_data(calendar, planning_parser):
"""
Parse every event in the calendar string given in parameter with the parser
also given in parameter and return a list with the events as formatted
data.
The calendar string must respect the iCalendar format in the first place.
The data returned c... | 3c90269bcf7c4bef3c3ad84807719f014a4da87d | 63,870 |
def get_frequency(key=88, pitch=440.0):
"""
Get frequency from piano key number
:param key: key number of the piano
:param pitch: convert pitch of the A4 note in Hz
:return: frequency in hz
"""
return pow(2, float(key - 49) / 12.0) * pitch | d73aa776d6a6760335b19d966b4198488eff4c21 | 63,871 |
def get_image_features(image):
"""Return image data as a list."""
return list(image.getdata()) | b17d2bacee1821f0dee82ca1eb30ce85aa648057 | 63,885 |
import re
def indention(str, front=re.compile(r"^\s+").match):
"""Find the number of leading spaces. If none, return 0.
"""
result = front(str)
if result is not None:
start, end = result.span()
return end-start
else:
return 0 # no leading spaces | 0586ce697116d9bc6a3c62acd2d054c9cb704888 | 63,888 |
def clip(n, start, stop=None):
"""Return n clipped to range(start,stop)."""
if stop is None:
stop = start
start = 0
if n < start:
return start
if n >= stop:
return stop-1
return n | bbb7091235d2bd24e704be31643f3ad3265533dd | 63,891 |
def istype(type, *obj):
"""
Returns whether or not all the inputs are of the specified type
Parameters
----------
type : type
the type to check against to
*obj : object...
a sequence of objects
Returns
-------
bool
True if the inputs are of the specified typ... | b626375b22a23aea6d21ba0df3acc1f84d2a4fc2 | 63,892 |
def _set_timelabel(obs, use_tref=True):
"""For a given observable, returns the timelabel to be used in plots
Parameters
----------
obs : Observable instance
use_tref : bool
whether to use tref (set False for stationary plotting)
Returns
-------
timelabel : str
"""
if ob... | 726e87d5122d3e3108c73d1b69c0ad6a0931503b | 63,900 |
import torch
def all_diffs(a, b):
""" Returns a tensor of all combinations of a - b.
Args:
a (2D tensor): A batch of vectors shaped (B1, F).
b (2D tensor): A batch of vectors shaped (B2, F).
Returns:
The matrix of all pairwise differences between all vectors in `a` and in
... | a7aac8eb876fad54af2dda38f97e0d7fdbd5f756 | 63,901 |
def wild2regex(string):
"""Convert a Unix wildcard glob into a regular expression"""
return string.replace('.','\.').replace('*','.*').replace('?','.').replace('!','^') | c30360076fde573b3865143b761579e2c7466877 | 63,904 |
def _local_median(img, x, y, k):
"""
Computes median for k-neighborhood of img[x,y]
"""
flat = img[x-k : x+k+1, y-k : y+k+1].flatten()
flat.sort()
return flat[len(flat)//2] | ddcb0ad6fd878142dc7d1ab5ee86503e7d2dc397 | 63,905 |
def crop_center(img, cropx, cropy, cropz):
"""
Take a center crop of the images.
If we are using a 2D model, then we'll just stack the
z dimension.
"""
x, y, z, c = img.shape
# Make sure starting index is >= 0
startx = max(x // 2 - (cropx // 2), 0)
starty = max(y // 2 - (cropy // 2... | 047144047667bafd02e5ef5691b3382391680e44 | 63,910 |
def slice_to_flow(arr, i, n):
""" slice to the ith flow value given a total of n possible flow values"""
assert(arr.shape[0] % n == 0)
incr = round(arr.shape[0]/n)
i_lower = i * incr
i_upper = (i+1) * incr
return arr[i_lower:i_upper, :] | 7772fc0684327cf771169c766ce733ef8e757359 | 63,911 |
def utility(game, state, player):
"""Return the value to player; 1 for win, -1 for loss, 0 otherwise."""
return state.utility if player == 'W' else -state.utility | 7e718af20e86967b4f7fff072e579c3acf9b2b5b | 63,916 |
def parenthesise(_value):
"""Adds a parenthesis around a values."""
return '(' + _value + ')' | 96b43a5b260ef6e26bc2c95c705350a9a8442430 | 63,917 |
import requests
def get_username(uuid):
"""Get the username of a player from the UUID"""
r = requests.get("https://api.mojang.com/user/profiles/{}/names".format(uuid))
if r.ok and r.status_code not in [204, 400]:
return r.json()[-1]["name"]
else:
if r.status_code in [204, 400]:
... | d852b4072e3619d415c25f3cb4eb5f0c7a91e0bd | 63,918 |
def _module_to_paths(module):
"""Get all API __init__.py file paths for the given module.
Args:
module: Module to get file paths for.
Returns:
List of paths for the given module. For e.g. module foo.bar
requires 'foo/__init__.py' and 'foo/bar/__init__.py'.
"""
submodules = []
module_segments =... | 3982259b0d22e9cea77297b5317cc57fbb8136b9 | 63,920 |
def is_long_book(book):
"""Does a book have 600+ pages?"""
return book.number_of_pages >= 600 | 1cf0daca0aa027ba9a33ceb6b9858b8540576e24 | 63,922 |
def expand_type_name(type_):
"""
Returns concatenated module and name of a type for identification.
:param type_: Type:
:type type_: type
:return: Type name, as ``<type's module name>.<type name>``.
:rtype: unicode | str
"""
return '{0.__module__}.{0.__name__}'.format(type_) | 0bed7e1dd71d623ad901cdf8c8ae39fa64246dad | 63,923 |
def comma_separate(elements) -> str:
"""Map a list to strings and make comma separated."""
return ", ".join(map(str, elements)) | 4bcc788228515bfb05bc8b931880ee28814582cb | 63,925 |
import pickle
def import_model(clf_path = '../models/disaster_response_clf.pkl'):
"""
Function: load model from pickle file
Args:
clf_path (str): path of pickle file
Return:
model (GridSearch obj): loaded model
"""
with open(clf_path, 'rb') as f:
model = pickle.load(f)
... | 201013d0c34479a65aab196f1840b18bdc6665e8 | 63,932 |
def to_esmf(ts):
"""
Convert a UTC datetime into a ESMF string.
:param ts: the datetime object
:return: the date time in ESMF format
"""
return '%04d-%02d-%02d_%02d:%02d:%02d' % (ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second) | 10ebddcdc7ab887b5fe25132d1b8591474dc9b11 | 63,933 |
from pathlib import Path
def does_exist(os_path: str) -> bool:
"""
Check whether the file exists.
"""
return Path(os_path).exists() | 11c2e6e32e3b0856b2e1faf547cddad0849cd55d | 63,936 |
def removeDotGit(url):
""" Remove trailing `.git` from the git remote url """
if url.endswith('.git'):
return url[:-4]
return url | 421900a7d78eece269545c674a8ce8013d47972f | 63,940 |
def log_message(source, *parts):
"""Build log message."""
message = source.__class__.__name__
for part in parts:
message += f": {part!s}"
return message | 18f004f6d76a05dacced5a3b1e437bb766f8d78b | 63,941 |
def interval_union(intervals):
"""
Returns total size of intervals, expect interval as (chr, left, right)
"""
intervals.sort()
total_len = 0
cur_chr, cur_left, cur_right = intervals[0] # left-most interval
for interval in intervals:
# open a new interval if left > cur_right or chr !... | c05495b91c2b61455ccec37398d8377ee27dc109 | 63,947 |
import typing
def selective_join(parts: typing.List[str], n: int) -> typing.List[str]:
"""
Given the list of N+1 strings, and an integer n in [0, 2**N - 1] range,
concatenate i-th and (i+1)-th string with space inbetween if bit i is not set in n.
Examples:
selective_join(['a', 'b', 'c'], 0b00... | fb9ea884284d0a71cba37ebbc9487cd17f1007d3 | 63,949 |
def get_totals(cpuinfo):
"""Compute totals:
- real: physical CPUs
- cores: cores x physical CPU
- total: logical CPUs real*cores*siblings
Note: Siblings are only counted if Hyperthreading is enabled
"""
# We assume same CPU architecture for multi CPU systems
real = len({cpui... | d54da926af84f0c588f329d3f17afdb5bac314ea | 63,950 |
def dos_line(f, ndos):
"""
Parses density of states data from DOSCAR
Parameters
----------
f : file object
File object containing data in DOSCAR file
ndos: int
Number of lines in f to be parsed
Returns
-------
data : list
List of density of ... | b9aa09f937b0a6199f5469c1b9332f04805977bf | 63,952 |
def attr_sum_of_nodes(con,attr_name,node_ids=None):
"""Get the SUM() of node_ids's values for attr_name.
con: a SQLite connection
attr_name: The name of the attr values to fetch.
node_ids: a list of ids to sompute the sum from.
Returns a number that is the requested sum.
"""
if node_ids... | e8d86652823e96bb9b8a6ad2b5c89011b166b061 | 63,959 |
def hamming(n):
"""Returns the nth hamming number"""
hamming = {1}
x = 1
while len(hamming) <= n * 3.5:
new_hamming = {1}
for i in hamming:
new_hamming.add(i * 2)
new_hamming.add(i * 3)
new_hamming.add(i * 5)
# merge new number into hamming set... | ef64b67810bff9ba6fbac0ca17a5b60f801279cb | 63,960 |
def get_amount_in_ml(dose, concentration):
"""Calculates the amount of liquid drug to be given in mls, given a dose(mg/kg) and concentration (mg/ml.
:params:
dose(mg/kg) - Float
concentration - Float
:returns:
Amount in mls - Float
Examples:
>>> get_amount_in_ml(2.5, 50)
0.05
... | 6dc9b0fe22c2e70984cd99145ecaad1ec6d3a906 | 63,965 |
def races_per_year(self):
"""Return total number of career starts for the horse divded by the horse's age as at the race date"""
if self.age is not None and self.age > 0:
return self.career.starts / self.age | 7a6371ac95b1fb78ba19b18595a5df101c2b5988 | 63,967 |
def compare_np_arrays(x, y):
"""checks if 2 numpy arrays are identical"""
return (x == y).all() | a694a5070063126d6930d9ced3f05047452593e9 | 63,971 |
def sql_select_one(tbl, col_key):
""" select one column from a table
"""
return tbl[col_key] | e9bb16d3cc1d6e1c7bf5f9b6e4467391c5e8d674 | 63,973 |
def _get_model_or_module(crypten_model):
"""
Returns `Module` if model contains only one module. Otherwise returns model.
"""
num_modules = len(list(crypten_model.modules()))
if num_modules == 1:
for crypten_module in crypten_model.modules():
return crypten_module
return cryp... | bd4bc0613f872f79302b704d6cd4648af7ebf02d | 63,976 |
def C_fingas(heavy, precent_dist_180):
"""
Returns the constant C used in fingas model
source : (Fingas, 2015)
Parameters
----------
heavy : True if the fuel need to follow a ln, else it will be a sqrt.
precent_dist_180 : Percentage distilled by weight at 180 °C []
"""
if heavy:
... | ba04d07b3e6a228fc28619c0d8ec7b2cb6af5b45 | 63,988 |
def build_speechlet_response(output, should_end_session):
""" Return a speech output after an Alexa function is executed.
Builds a simple speech response after the user invokes a particular Alexa
function. The response used here is a simple, plain text response but can be
enhanced by customizing the ca... | 76ad5983f8199b0786bba42fc997551d3f03a252 | 63,993 |
def user_select(client, file_=None, maxi=None):
"""Prompt user to select one or more dimensions, and return their selections.
client (obj):
creopyson Client.
`file_` (str, optional):
Model name. Defaults is current active model.
maxi (int, optional):
The ... | b122fbe89119c76f2b47df278cb546a3959f5175 | 63,994 |
def calculate_CHI(seq_target, seq_source, df_target_freq, df_source_freq):
"""Calculate Codon Harmonization Index (CHI)"""
df_source_freq = df_source_freq.set_index('codon')
df_target_freq = df_target_freq.set_index('codon')
diffsum = 0
for i in range(0, len(seq_source), 3):
codon_target =... | 04bc384be4137f4a10432e5d3fcd87953b2157db | 63,997 |
import re
def is_url_valid(string):
"""
This function checks whether input string follow URL format or not
Args:
string: Input string
Returns:
True: if string follows URL format
False: if string doesn't follow URL format
>>> is_url_valid("C:/users/sample/Desktop/image.jpg... | a6ff543fa68f1cdaef5f7a4c4be8f6e5979e6a5d | 63,998 |
def word_to_index(vocab):
"""
Encoding words by indexing.
Parameters
----------
vocab: list.
Returns
-------
word_to_idx dictionary.
"""
word_to_idx = {}
for word in vocab:
word_to_idx[word] = len(word_to_idx)
return word_to_idx | 24d0c71a27a1c337416d3a9bc29da1d3dac26996 | 64,007 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.