content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def spatial_binning(info_dict):
""" Compute the spatial binning representing the number of pixels affected by the light in the spatial direction
Parameters
----------
info_dict: dictionnary
wavelength: float
wavelength in angstrom
Returns
----------
spabin: float
... | a6af35e8e7afabc6dea2aa89937aecd096f265c2 | 697,640 |
def keep_alpha_numeric(input_text: str) -> str:
""" Remove any character except alphanumeric characters """
return ''.join(c for c in input_text if c.isalnum()) | 6775d7ba72ae06c294acde9bc2964ae51a954ce3 | 697,641 |
def reunion(set1, set2):
"""Given the two sets, returns their reunion."""
return set1 | set2 | 3e7af2a784d570d2a28c6665905242f5b6e812de | 697,642 |
def numberList(listItems):
"""Convert a string list into number
@param listItems (list) list of numbers
@return list of number list
"""
return [float(node) for node in listItems] | df50b5ce22f63c22cfa67051422cc4b13718cb57 | 697,643 |
import six
def _safe_write(function):
"""Avoid issues related to unicode strings handling."""
def _wrapper(message):
# Unicode strings are not properly handled by the serial module
if isinstance(message, six.text_type):
function(message.encode("utf-8"))
else:
fu... | b467c959e0833f8cb016b48fc031e0223fc2809e | 697,644 |
def results_ok(api, cfg, utils, size, packets):
"""
Returns true if stats are as expected, false otherwise.
"""
port_results, flow_results = utils.get_all_stats(api)
return packets == sum(
[p.frames_tx for p in port_results if p.name == "raw_tx"]
) | 618106436b0de5403f9f325c61fb2066a9493b31 | 697,645 |
def are_brackets_balanced(expr):
"""
Checks to see if there are parens or brackets that are unbalanced
"""
stack = []
# Traversing the Expression
for char in expr:
if char in ["(", "{", "["]:
# Push the element in the stack
stack.append(char)
e... | 3e548cb2999c404d6ed0587ef1a959767c11d479 | 697,646 |
def clean_rows(all_rows, original_rows):
"""
Remove duplicated values and remove original rows
"""
all_set = set(all_rows)
original_set = set(original_rows)
return all_set - original_set | 76de02aa72e8753481b58b4eddcabc4330a92e0b | 697,647 |
import re
def parse_phmmer_output(result_path):
"""
Read the fasta header of the sequence with highest homology
from a phmmer result file
returns: string
"""
with open(result_path, "r") as infile:
results_str = infile.read()
# Hacky regex solution to parsing results...
... | 4e7f40ff0f16316ee88096d8f3f4084706cef42b | 697,648 |
from typing import Optional
import subprocess
def get_command_output(command: str, cwd: Optional[str] = None):
"""
Executes the given "command" and returns the output of the command as string
The additional "cwd" option can be used to pass a string path description, which is supposed to be used as the
... | 7740f0a94212e2f47394cc55b55a13b127bc9c13 | 697,650 |
import sys
def is_linux():
"""
Is the current platform Linux?
"""
return sys.platform.startswith('linux') | 31368146cdfee5ee81627084a1d055d59c697262 | 697,651 |
from pathlib import Path
import requests
from bs4 import BeautifulSoup
def Soup(s, features='lxml', **kw):
""" A fake class, of what BeautifulSoup should have been
It accepts a url or a file, in addition to html/xml as usual
"""
if isinstance(s, Path):
src = s.read_text()
elif s.star... | 71ac4ad935caf5a97c45710d98a9bf6980751a81 | 697,652 |
import sqlite3
def is_unique_failure(e: sqlite3.IntegrityError) -> bool:
"""
Return if the given error is representing a foreign key
failure, where an insertion was expecting something to
exist already in the DB but it didn't.
"""
return str(e).startswith("UNIQUE constraint") | 1292002a1296cd9ced4b35b59b3f58e9040b59a7 | 697,653 |
import torch
def evaluate(model, dataset, labels):
""" Evaluate the valid_data on the current model.
:param model: Module
:param train_data: 2D FloatTensor
:param valid_data: A dictionary {user_id: list,
question_id: list, is_correct: list}
:return: float
"""
# Tell PyTorch you are ev... | 498b5c62a8921d698a31d8030b248ba391677536 | 697,654 |
def _get_p_y_z_halfspace(particles):
"""
This function calcualtes the probabilities of y and z half space
for a given set of particles
Parameters
----------
particles : list
List of SourceParticle
Returns
-------
p_y_halfspace : float
The probability of y half space... | fb822d7b03b4fc387fff8723d5a8d7dafe8f9bfc | 697,655 |
import torch
def get_data(generic_iterator, generic_loader):
"""Code to get minibatch from data iterator
Inputs:
- generic_iterator; iterator for dataset
- generic_loader; loader for dataset
Outputs:
- data; minibatch of data from iterator
- generic_iterator; iterator for dataset, reset i... | e827ab7cea13c96953260d6b157a3e6ab370c6c9 | 697,656 |
import json
def split_cmd(cmdstr):
"""Interprets JSON and method and params"""
cmd = json.loads(cmdstr)
return cmd['method'], cmd.get('params', {}), cmd.get('rune') | cb580c244699fe9657e7e43b243ddc48e8f5d6f6 | 697,657 |
def get_name(schema_url):
""" Extract the item name from it's URL
:param schema_url: the URL of the schema
:return name: the name of the schema (eg: 'item_schema.json')
"""
name = schema_url.split("/")[-1].replace("#", '')
return name | e7632dc959a4503b51cc5c3f851a063056893507 | 697,658 |
def create_time(t):
"""之后加入日 月 星期等条件"""
return (f"null null null null null {t}") | 1e5ae6c5cac9b984c4f02b8c02e58a2da5b7972f | 697,659 |
import torch
from typing import Callable
def encode_and_aggregate(input_tensor: torch.Tensor,
encoder: torch.nn.Module,
num_encoder_input_channels: int,
num_image_channels: int,
encode_channels_jointly: bool,
... | f2d65e1c2c214cfddae40dd235fba86a61866277 | 697,661 |
def max_dot_product(a, b):
"""
Given two sequences 𝑎1, 𝑎2, . . . , 𝑎𝑛 (𝑎𝑖 is the profit per click of the
𝑖-th ad) and 𝑏1, 𝑏2, . . . , 𝑏𝑛 (𝑏𝑖 is the average number of clicks per day
of the 𝑖-th slot), we need to partition them into 𝑛 pairs (𝑎𝑖, 𝑏𝑗) such
that the sum of their produc... | afdf565cf32c3bcc9e0a69a4ea565a3dcdd8f8a4 | 697,662 |
def apply_each(functions, *args, **kwargs):
"""Returns list containing result of applying each function to args."""
return [f(*args, **kwargs) for f in functions] | 15dc85cb155db030f4eaf2eccdbd40ed20585b82 | 697,663 |
def _model_delete_by_id_function_name(model):
"""Returns the name of the function to delete a model by id"""
return '{}_delete_by_id'.format(model.get_table_name()) | df3e1de727b585c1cab403dfcfea08eafe25aeec | 697,664 |
def mark_all_tables_per_draw(draw, boards_data_dict):
"""
Once a draw has been drawn,
we need to update the table
with a say a * at that point
:param draw: int [number drawn]
:param boards_data_dict: dictionary of tables
"""
for key in boards_data_dict:
table = boards_data_dict[k... | e1c3fc89e5082e6b365299be86b0ba5bb8ce46b5 | 697,665 |
import os
import click
def conf_file_exists(ctx, param, value):
"""
Validate conf file exists
"""
conf_file = "configuration.py"
if value[-len(conf_file) :] != conf_file:
value = os.path.join(value, conf_file)
value = os.path.realpath(value)
if os.path.isfile(value):
return... | 114b836d52f7fe1f7491a5e20ad8e994ce04399b | 697,666 |
def Hex2Rgb(hex="#ffffff"):
"""
将十六进制的颜色字符串转换为 RGB 格式
https://blog.csdn.net/sinat_37967865/article/details/93203689
"""
r = int(hex[1:3], 16)
g = int(hex[3:5], 16)
b = int(hex[5:7], 16)
rgb = str(r) + "+" + str(g) + "+" + str(b) # 自定义 rgb 连接符号
return rgb | 7a71fdac7907252e945774429a61ac60702b92a1 | 697,667 |
def subset_matrix(matrix, name_list_1, name_list_2):
"""Subsetting matrix into two symetric matrices given two label lists
Parameter:
----------
matrix : Pandas DataFrame
Full similarity matrix
name_list_1 : list
list of names
name_list_2 : list
list of names
Returns:
--------
list:
list with subset... | 1b36308c73c864fa446b0bc756240d4d2a8639a6 | 697,668 |
def sanitize_image(author_img_url):
""" Sanitizes the text from the author string. """
if author_img_url is None:
author_img_url = "https://www.pngkey.com/png/detail/230-2301779_best-classified-apps-default-user-profile.png"
return author_img_url | e980126e589a19f0ae750dfebdcc4095c700081b | 697,669 |
def capitalize_all(line):
"""Amos has a habit of capitalizing the first letter of all words in a statement."""
words = line.split(" ")
words = [word.capitalize() for word in words]
return " ".join(words) | ab2b02bc8df4eb010fb040368724879ac129e5c6 | 697,670 |
import re
def is_hash(text):
"""
>>> is_hash(sha256(b'blode'))
True
"""
return bool(re.match(r'^[0-9a-f]{64}$', text)) | 23d821357a794dadc86a9becad7d0da709c05b1e | 697,671 |
import torch
def tokenize(
seq,
tokenizer,
add_special_tokens=True,
max_length=10,
dynamic_padding=True,
truncation=True,
):
"""
:param seq: sequence of sequences of text
:param tokenizer: bert_tokenizer
:return: torch tensor padded up to length max_length of bert tokens
""... | 8573b19ab395c2957f8a95c80ca9e5514cdbea73 | 697,672 |
def my_sum(x_val: int, y_val: int) -> int:
"""Sum 2 integers.
Args:
x_val (int): integer to sum.
y_val (int): integer to sum.
Returns:
int: result of the summation.
"""
assert isinstance(x_val, int) and isinstance(
y_val, int
), "Input parameters should be integ... | c10001f9ff720ce3d180aaa89af555ac1860ae33 | 697,673 |
def which_axis(df, series):
"""Returns the axis matching the series' index (0=rows, 1=columns) or None if no
match.
Not exact, but sufficient.
"""
series_indices = set(series.index)
if series_indices == set(df.index):
return 0
elif series_indices == set(df.columns):
return 1
... | ebc28c2a5f0e796e1a1c95c0e0efdaf31783f76a | 697,674 |
def get_beta(matrix_list, List=True):
"""function to get a beta from a list of cov matrices"""
if List:
beta_list = []
for matrix in matrix_list:
beta = matrix[1][1]/matrix[0][1]
beta_list.append(beta)
return beta_list
else:
beta = matrix_list[1][1... | c43607162dd70439e04fea66eda8cc18b703673c | 697,675 |
def cidr_to_mask(cidr):
"""
Converts decimal CIDR notation to a quad dotted subnetmask.
:param cidr: Decimal CIDR number
:return: Quad dotted subnetmask as string
"""
cidr = int(cidr)
mask = (0xffffffff >> (32 - cidr)) << (32 - cidr)
return (str((0xff000000 & mask) >> 24) + '.' +
str((0x00ff00... | 037e1cacfb392fad4a06edf1d9c16c4f27c0468b | 697,676 |
import random
def computer_choice() -> str:
"""
This function takes no inputs and returns either "rock", "paper", or
"scissors" randomly to simulate the computer's decision.
"""
# 'random' is a library. A library is essentially a collection of code that
# contains some kind of feature(s) that we want to use in... | 1f8e064adfbd6242f2bb199caf98b77acf38c596 | 697,677 |
def filter_ps(ps):
"""
ps -> List of paths
Out of all the paths, select only the lowest weight paths that lead to the same end.
"""
best_ps = {}
for p in ps:
w_4 = p[0][1]
w_5 = p[1][1]
x = (w_4 + w_5, w_4)
state_5 = p[1][0]
if (state_5 not in best_ps) o... | d534d47a5faa04a5d207a8dff54c43c8ef966626 | 697,678 |
def convert_training_shape(args_training_shape):
"""Convert training shape"""
training_shape = [int(args_training_shape), int(args_training_shape)]
return training_shape | 391a85eed34483461910be9bf0f94b936660abb0 | 697,679 |
def csm_value_repr(self):
"""
String representation for the CSMValue namedtuple which excludes
the "created" attribute that changes with each execution. Needed for
consistency of ddt-generated test methods across pytest-xdist workers.
"""
return f'<CSMValue exists={self.exists} raw_earned={self... | 07917e16e6e3539916aac6e114375b598fad446b | 697,680 |
def wants_child_support(responses, derived):
""" Return whether or not the user wants an order for child_support """
return 'Child support' in derived['orders_wanted'] | 3468f83f541eee7cba2e8ee3664c9efee1c0225a | 697,681 |
def get_valid_config():
"""Helper function to return a valid config for the rule processor. This
simulates what stream_alert.rule_processor.load_config will return in a
very simplified format.
Returns:
dict: contents of a valid config file
"""
return {
'logs': {
'jso... | 774e0d9b40b8b0ea25ce10907b0f9954d0b7f966 | 697,682 |
import os
def relpath(path, start='.'):
"""Create a relative path from the start directory.
Adds './' if the file is in the start directory.
"""
path = os.path.relpath(path, start)
if not os.path.dirname(path):
path = "./{0}".format(path)
return path | 14872032783f933d352f8dad36d54bb8d4f95e81 | 697,683 |
def add_missing_columns(df1, df2, fill_value=0):
"""
Updates df1 to have all the columns of df2
"""
# Things that are in df2 but not df1
for c in set(df2.columns) - set(df1.columns):
df1[str(c)] = [fill_value] * len(df1)
# Sort the columns to be the same for bo... | 1d038aecb8df1149467d98a6816b42e0e3bae12f | 697,684 |
def _serial_from_status(status):
"""Find the best serialvalue from the status."""
serial = status.get("device.serial") or status.get("ups.serial")
if serial and (serial.lower() == "unknown" or serial.count("0") == len(serial)):
return None
return serial | 5075493926a946878d2263dc79879809a2af4fca | 697,685 |
import os
def read_from_handle_truncated(file_handle, max_len):
"""Read from file handle, limiting output to |max_len| by removing output in
the middle."""
file_handle.seek(0, os.SEEK_END)
file_size = file_handle.tell()
file_handle.seek(0, os.SEEK_SET)
if file_size <= max_len:
return file_handle.read... | 446f09fa2bf13a1199a7b3edf133b3ff8bf181d1 | 697,686 |
def craft_sms(machine, check, message, time_check):
"""Create a valuable alert with less text."""
# keep just the hour, i.e. strip year/month/day
time_check = time_check[-5:]
# remove the domain
machine = machine.split('.')[0]
alert = f'{time_check} {machine}!{check} {message}'
return alert[... | 3e926b44fdfca29ba731bd29c15790c53f395c85 | 697,687 |
def outside(chart,psg,start_beta=1.,start='S'):
"""
Calculates the outside probabilities of the CKY entries and adds them into the chart
I have the starting prob for the top right equal to the proportion of the sentence probability that the parse contributes. We might not need this: We might be able to mul... | 48c1a3c2695dae639e0b19baac2937c849aff438 | 697,690 |
def head(your_list, default=None):
"""Simple head function implementation."""
return next(iter(your_list or []), default) | 382e6f069b7aa15c710b41007bbd03be23d63bde | 697,692 |
import collections
def dict_merge(xs):
"""
>>> dict_merge([{1: 2}, {3: 4}, {3: 5}])
{1: 2, 3: 4}
"""
return dict(collections.ChainMap(*xs)) | fff3a615c44df45b83b6bb8c9368c4f12ecd94bc | 697,693 |
from typing import Iterable
from typing import Any
def is_empty(iterable: Iterable[Any]) -> bool:
"""
Check whether provided iterable is empty.
:param iterable: iterable whose emptiness is to be checked.
:return: flag indicating if the provided iterable is empty.
"""
return not any(map(lambda... | cef865deec6a7fd4241e15abaac7fced9ac114b0 | 697,694 |
def gen_xacro_macro(name, links, joints):
"""
Generates (as a string) the complete urdf element sequence for a simple
ROS-Industrial xacro macro that defines geometry (links, joints). It takes
a single argument ``prefix`` that should be used when instantiating the
macro in a composite parent scene.
... | 4be7f3353a9fba1f7127e81e29e3536150ed834e | 697,695 |
def solution(A): # O(N)
"""
Given an integer array nums, find the contiguous subarray
(containing at least one number) which has the largest sum and
return its sum.
>>> solution([-2, 1, -3, 4, -1, 2, 1, -5, 4])
6
>>> solution([-2, -1, -3, 1... | 9c41707940d563ba10c97af53e72f8bbf30fd071 | 697,696 |
import re
def re_comp_num_pos_name():
"""
Compiles the regex pattern that extracts the pattern (num) (position) (last), (first)
Example:
s = '21 C Stepan, Derek'
reg = re_comp_num_pos_name()
num, pos, last, first = reg.findall(s)[0]
:return: compiled regex
"""
... | 5994efcca453cef7201b92ca53863fc34791c0f1 | 697,697 |
def _index(key, sequence, testfn=None, keyfn=None):
"""Return the index of key within sequence, using testfn for
comparison and transforming items of sequence by keyfn first.
>>> _index('e', 'hello')
1
>>> _index('E', 'hello', testfn=_equalsIgnoreCase)
1
>>> _index('x', 'hello')
"""... | 0595726f9e14e8f4a3fd4b925de04c801be317a3 | 697,698 |
import platform
import os
def default_license_dir():
"""Get license file location.
Raises:
Exception: Works only on Windows/Linux
Returns:
[str]: License file directory
"""
if platform.system() == "Windows":
return os.path.join(os.environ["LOCALAPPDATA"], "Cubemos", "Skel... | baa547820801bd73a61e959941fa00a77de2b7c6 | 697,700 |
import six
def like_filter(query, cls, search_opts):
"""Add 'like' filters for specified columns.
Add a sqlalchemy 'like' filter to the query for any entry in the
'search_opts' dict where the key is the name of a column in
'cls' and the value is a string containing '%'.
This allows the value of ... | c42318350a9c19715fc6a2e0c74d8bec423b4cfc | 697,701 |
def CalculateTFD(torsions1, torsions2, weights=None):
""" Calculate the torsion deviation fingerprint (TFD) given two lists of
torsion angles.
Arguments;
- torsions1: torsion angles of conformation 1
- torsions2: torsion angles of conformation 2
- weights: list of torsion weights (... | 621bdf9c51130b33721e48c52f72053d9a0b5f19 | 697,702 |
def compare_values(answer, submitted_answer):
"""Comparing values"""
if answer["value_type"] == "number":
if "comparison_type" in answer and answer["comparison_type"] == "absolute":
return abs(answer["value"]) == abs(submitted_answer)
if answer["value_type"] != "string":
return a... | 7f1e7a9a2b2eb5943fd15562fe3e1d376f30c8db | 697,703 |
def read_file(filename):
"""
Return the contents of the file with the given filename as a string
>>> write_file('read_write_file.txt', 'Hello World')
>>> read_file('read_write_file.txt')
'Hello World'
>>> os.unlink('read_write_file.txt')
"""
with open(filename) as in_fh:
return ... | 756187a755a54b2d6e96ad6d297ceb2472afbb6c | 697,704 |
import warnings
def _hideWarnings(func):
"""
Decorator function that hides annoying deprecation warnings in find_peaks_cwt
"""
def func_wrapper(*args, **kwargs):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
return func(*args, **kwargs)
return fun... | cfbd9af74bb08cbfe4d6429c3b4ba2511fa3aa43 | 697,705 |
def whatLName(fName, listOfStudents):
"""
return the major of first student in listOfStudents with first name fName, False if none found
>>> whatLName("FRED",[Student("MARY","KAY","MATH"), Student("FRED","CRUZ","HISTORY"), Student("CHRIS","GAUCHO","UNDEC")])
'CRUZ'
>>>
"""
for i in range(... | 81b070be78083697c51abdfed5da2287440b2717 | 697,706 |
def last_in_array(array, operation = None):
"""Return the last element in an array.
I think this is just [-1]
"""
if len(array) == 0:
return None
return array[-1] | fb93f365368b31ed31ab9f4c2dde066b1add4425 | 697,707 |
from typing import Callable
def linear_schedule(initial_value: float) -> Callable[[float], float]:
"""
Linear learning rate schedule.
:param initial_value: Initial learning rate.
:return: schedule that computes
current learning rate depending on remaining progress
"""
def func(progress_... | 47a580788c745b7566c22daa97c3aecee0bb8ff2 | 697,708 |
def fieldnames(cursor):
"""
최근 실행한 쿼리의 field names 리스트
:param cursor:
:return: list[str]
"""
return [f[0] for f in cursor.description] | f369ce8e904464082c65d855071bc2e1ebc2a21d | 697,709 |
from datetime import datetime
def is_datenum(datenum):
""" Return True if given str is a date in format %Y%m%d """
try:
datetime.strptime(datenum, "%Y%m%d")
return True
except (ValueError, TypeError):
return False | c61998ebf18a3fbdd4c87463a2ab0790864c62b4 | 697,710 |
import math
def special_case(sku_data, free_trigger, trigger_amount, free_sku, free_sku_value, free_deal=None):
"""free_deal can be tuple of amount and value"""
free_items = 0
total = 0
if sku_data[free_trigger] / trigger_amount >= 1:
# for every <trigger_amount> of <free_trigger> we get a fr... | 924c1c6f612d98f8b99f1622c2827d97481a7a30 | 697,711 |
def convert_crlf(value):
"""
Replace carriage return and line feed character by their javascript value
Make possible to include title with those characters in the aloha links
"""
return value.replace('\r', '\\r').replace('\n', '\\n') | 17210472fcccb27f02fc8dcf5ebbe654bfa58278 | 697,712 |
def _compute_position(input, index):
"""Compute line/column position given an index in a string."""
line = 1
col = 1
eol = None # last end of line character
for c in input[:index]:
if c == '\n' or c == '\r':
if eol is None or eol == c:
eol = c
lin... | f08217651d11ed09c1e100368aa8cc869c37e386 | 697,713 |
import itertools
def flatten(sequence):
"""
Get a flat list out of a list of lists.
"""
return list(itertools.chain(*sequence)) | 1c3c7c41969c7e172083e73f2e2aa5731fb56ada | 697,715 |
def equal_nan(request):
"""Fixture to whether consider nan as equal when comparing fields."""
return request.config.getoption("equal_nan") | 8fce969c2c84201822db735d46574644124c5c1a | 697,716 |
def round2(number: float) -> float:
"""
Rounds a number to the second decimal.
"""
return round(number, 2) | 5c788d01bce28831145391dcb261362b8a2208f3 | 697,717 |
def flipslash(value):
""" Convert all backslashes to forward slashes (for apache) """
return value.replace("\\", '/') | 8fa5abe7c334e0b229aa7e9b2477c3c9aecf38e3 | 697,718 |
def merge_lists(a, b):
"""
a function to zip together two linked lists augmenting the first linked list
passed in to have the second LL values in it alternating
"""
if b.head == None:
return a
if a.head == None:
return b
if a._size >= b._size:
temp1, temp2 = a.head, ... | 6a979d6f63c59531b202fcad6f0d3701c483a18b | 697,719 |
import re
def clean_label_or_catalog_number(string):
"""Clean label or catalog ID: '[TMZ12006]', '[Kalahari Oyster Cult]' """
string = string.replace('【', '[')
string = string.replace('】', ']')
result = re.search(r'(\[.*\])', string)
if result is not None:
label_or_catalog_number = result.... | 3f52df574bf3c1676b67f2affac5287488982c1c | 697,720 |
def binary_search(items, desired_item, start=0, end=None,):
"""Standard Binary search program takes
Parameters:
items= a sorted list
desired_item = single looking for a match (groovy baby)
start= int value representing the index position of search section
end = end boundary of the sea... | 7adb942e73e5c3945190c7d88882763f9f7b4f08 | 697,721 |
def max_intensities(burst_list):
"""Removes all but the max intensity for each burst interval."""
max_bursts = [{(j, k): i for i, j, k in x} for x in burst_list]
return max_bursts | f29d7cb955904981fee31b6d6a98bf193dbc9d69 | 697,722 |
def probabilistic_mapping(codon, productions):
""" Probabilistic mapping, using a PCFG."""
idx_selected_rule = len(productions) - 1
prob_aux = 0.0
for i in range(len(productions)):
prob_aux += productions[i][1]
if codon < prob_aux:
idx_selected_rule = i
break
... | 7dd3e5cd78cd6b32d59c1d62f761e8aeb1db1160 | 697,723 |
import importlib
def get_class(m):
"""Import class from string
:param m: string or class to be imported
:type m: str or class
:rtype: class
>>> get_class('microtc.textmodel.TextModel')
<class 'microtc.textmodel.TextModel'>
"""
if isinstance(m, str):
a = m.split('.')
... | 9a8c55524a47224a4e916191d66428aad2bc08d5 | 697,724 |
import math
def vec3(a, b, norm=1.0):
"""
x,y,z <- vec3(a, b, norm=1.0)
returns the vector a, b scale to norm
"""
dx = b[0]-a[0]
dy = b[1]-a[1]
dz = b[2]-a[2]
l = norm / math.sqrt( dx*dx + dy*dy +dz*dz)
return [dx*l, dy*l, dz*l] | db0f53cad9c472dd903cb18aabd1a6fad275b5bd | 697,726 |
import math
def is_nan(value):
""" Function which identifies the "nan" on empty cells """
try:
return math.isnan(float(value))
except ValueError:
return False | a76abc6c047461786109d84cb002867eeec77888 | 697,727 |
def path_to_url(path):
"""Convert a system path to a URL."""
return '/'.join(path.split('\\')) | 79bfd1715420002371fe4201863d736bf9e3b2bf | 697,728 |
def _use_reasonable_speed(preset, frame_count):
"""Return a reasonable speed parameter for the given animation length."""
return preset.settings.get("speed", 0.25) * (frame_count / 30.0) | 9327131fbe8f55ba1ee5c1ccc932132ad3d3162a | 697,729 |
def blend_color_dodge(cb: float, cs: float) -> float:
"""Blend mode 'dodge'."""
if cb == 0:
return 0
elif cs == 1:
return 1
else:
return min(1, cb / (1 - cs)) | 5a96383ce6f71aca42639c7ac4962ea74ecd02c6 | 697,730 |
def radix_sort(array):
"""
Radix Sort
Complexity: O((N + B) * logb(max)
Where B is the base for representing numbers and
max is the maximum element of the input array. We
basically try to lower the complexity of counting sort.
Even though it seems good, it's good in specific cases only.
... | 2ca57406f0d0190ce8849c50e1ffcadf382db328 | 697,731 |
def sphere(x):
"""Minimum at 0"""
return x.dot(x) | 67c24f0b5fd711ec9618284f800b75d1db894938 | 697,732 |
def tens2rgb(t):
"""Tensor (HWC) to RGB, [0, 1] -> [0, 255]"""
t = t.detach().cpu().numpy()
return (t * 255).astype('uint8') | 63b8977b69517ed3f5ab5aba006e7d121dc43d53 | 697,733 |
def create_imagelist(pd_dataframe, img_dir, ext):
"""
Creates a list of image paths of the thumbnails
Keyword arguments:
pd_dataframe -- pandas DataFrame object containing the stub info
stub_directory -- location of stub info files
ext -- File extension of the thumbnail
"""
imgs = []... | 1d41b1b02eab9123624c765b1529739b387e3e9c | 697,734 |
import sys
import logging
import json
def read_json():
"""Function that reads json from stdin
and returns json"""
try:
with sys.stdin as f:
logging.info('\nReading input')
json_file = json.loads(f.read())
return json_file
except AttributeError as e:
... | 3c6ecb83a3f1d4491532bb7b27c12e6687de0514 | 697,735 |
def drop(n, xs):
"""
drop :: Int -> [a] -> [a]
drop(n, xs) returns the suffix of xs after the first n elements, or [] if n >
length xs
"""
return xs[n:] | e9261686022f5419edade3b47e82c68bd52b5cd8 | 697,737 |
def backwards_search(p, cl, rank, total_length):
"""Perform backwards search using pattern p, count lookup cl and rank rank
reference http://alexbowe.com/fm-index/"""
start = 0
end = total_length - 1
for i in range(len(p)-1,-1,-1):
if end < start:
break
ch... | f8e87dc65b3838d99b7162e1c2ff0eb12b815180 | 697,738 |
def formatIntervalHours(cHours):
""" Format a hours interval into a nice 1w 2d 1h string. """
# Simple special cases.
if cHours < 24:
return '%sh' % (cHours,);
# Generic and a bit slower.
cWeeks = cHours / (7 * 24);
cHours %= 7 * 24;
cDays = cHours / 24;
cHours %= 24;... | d7c9be3110eb1ecbfb57ae51854d2e576519ced3 | 697,739 |
def swap_http_https(url):
"""Get the url with the other of http/https to start"""
for (one, other) in [("https:", "http:"),
("http:", "https:")]:
if url.startswith(one):
return other+url[len(one):]
raise ValueError("URL doesn't start with http: or https: ({0})".f... | b0af8770ef31f73afa5c95c6bc2a17488eb3d1e2 | 697,740 |
def list_to_dict(lst):
"""
Takes a list an turns it into a list
:param lst: the list that will be turned into a dict
"""
if len(lst) % 2 != 1:
odd_indexes = []
even_indexes = []
for i in range(len(lst)):
if i % 2 == 0:
odd_indexes.append(lst[i])
... | 2c84950f68cb2e8180511f010a558f370d3ac1ac | 697,742 |
def Liquid_Enthalpy_Ref_Liquid(T, Cn_l, T_ref, H_ref):
"""Enthapy (kJ/kmol) disregarding pressure and assuming the specified phase."""
return H_ref + Cn_l.T_dependent_property_integral(T_ref, T) | 5ac806600e59777ee64cc1564677d5d5f38d6540 | 697,743 |
import copy
def sortindexes(self):
"""Sorts a list of indexes in an ascending order with no regard to parity"""
selfcopy = copy.deepcopy(self)
alwaystrue = 1
while (alwaystrue):
done = 1
for nindexa in range(len(selfcopy)):
if (not done):
break
indexa = selfcopy[n... | f791bfe39130645ad2e33ef54c3a8c25e5964998 | 697,744 |
def attachURI(metaDict, acc, con, obj):
"""Add URI to dict as `label`"""
if obj != "" and obj is not None:
uri = '/'.join(['', acc, con, obj])
elif con != "" and con is not None:
uri = '/'.join(['', acc, con])
else:
uri = '/' + acc
return {uri: metaDict} | a4b584a041fc9c02b6bdfed9ba61eb3029cc34d2 | 697,745 |
import requests
import json
def get_records_from_imoox(endpoint: str) -> dict:
"""Get the response from imoox."""
response = requests.get(endpoint)
return json.loads(response.text.encode("utf-8")) | 8ec1b2aa62341e2c126a9d42a212d2b592385a64 | 697,746 |
def get_both_filenames(filename):
""" Get a list of both filenames for FUV data
Regardless if rootname_corrtag_a.fits or rootname_corrtag_b.fits
is passed in, both will be returned in a list.
Parameters
----------
filename : str
full path to COS file
Returns
-------
files ... | 76449b6f2719d5c6b7ee6dd01f730b9193e368da | 697,747 |
def get_data(data_creator):
"""
使用参数data_creator来获取测试数据
Args:
data_creator: 数据来源,可以是train()或者test()
Return:
result: 包含测试数据(image)和标签(label)的python字典
"""
data_creator = data_creator
data_image = []
data_label = []
for item in data_creator():
data_image.append... | 03023a6f90ede92da05efee12ff17601b96fb2be | 697,748 |
def _get_greensf_group_name(hdffile):
"""
Return the name of the group containing the Green's function elements
:param hdffile: h5py.File of the greensf.hdf file
:returns: str of the group name containing the Green's Function elements
"""
if '/GreensFunctionElements' in hdffile:
return... | fa5a8c65cad63b3053d8b55af95c9c4547493793 | 697,749 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.