text stringlengths 89 104k | code_tokens list | avg_line_len float64 7.91 980 | score float64 0 630 |
|---|---|---|---|
def draw_dithered_color(cb, x, y, palette, dither, n, n_max, crosshairs_coord=None):
"""
Draws a dithered color block on the terminal, given a palette.
:type cb: cursebox.CurseBox
"""
i = n * (len(palette) - 1) / n_max
c1 = palette[int(math.floor(i))]
c2 = palette[int(math.ceil(i))]
valu... | [
"def",
"draw_dithered_color",
"(",
"cb",
",",
"x",
",",
"y",
",",
"palette",
",",
"dither",
",",
"n",
",",
"n_max",
",",
"crosshairs_coord",
"=",
"None",
")",
":",
"i",
"=",
"n",
"*",
"(",
"len",
"(",
"palette",
")",
"-",
"1",
")",
"/",
"n_max",
... | 35.192308 | 15.269231 |
def gelu(x):
"""Gaussian Error Linear Unit.
This is a smoother version of the RELU.
Original paper: https://arxiv.org/abs/1606.08415
Args:
x: float Tensor to perform activation.
Returns:
x with the GELU activation applied.
"""
cdf = 0.5 * (1.0 + tf.tanh(
(np.sqrt(2 / np.pi) * (x + 0.04471... | [
"def",
"gelu",
"(",
"x",
")",
":",
"cdf",
"=",
"0.5",
"*",
"(",
"1.0",
"+",
"tf",
".",
"tanh",
"(",
"(",
"np",
".",
"sqrt",
"(",
"2",
"/",
"np",
".",
"pi",
")",
"*",
"(",
"x",
"+",
"0.044715",
"*",
"tf",
".",
"pow",
"(",
"x",
",",
"3",
... | 22.866667 | 18.666667 |
def makeCustomSpecificationsMapping(func):
'''
Creates the "pickleable" dictionary that will be used with
:data:`~exhale.configs.customSpecificationsMapping` supplied to ``exhale_args`` in
your ``conf.py``.
**Parameters**
``func`` (types.FunctionType)
A callable function that ta... | [
"def",
"makeCustomSpecificationsMapping",
"(",
"func",
")",
":",
"# Make sure they gave us a function",
"if",
"not",
"isinstance",
"(",
"func",
",",
"types",
".",
"FunctionType",
")",
":",
"raise",
"ValueError",
"(",
"\"The input to exhale.util.makeCustomSpecificationsMappi... | 39.2 | 25.9 |
def split_unbalanced(chunks):
"""Return (unbalanced_start, balanced, unbalanced_end), where each is
a list of text and tag chunks.
unbalanced_start is a list of all the tags that are opened, but
not closed in this span. Similarly, unbalanced_end is a list of
tags that are closed but were not opene... | [
"def",
"split_unbalanced",
"(",
"chunks",
")",
":",
"start",
"=",
"[",
"]",
"end",
"=",
"[",
"]",
"tag_stack",
"=",
"[",
"]",
"balanced",
"=",
"[",
"]",
"for",
"chunk",
"in",
"chunks",
":",
"if",
"not",
"chunk",
".",
"startswith",
"(",
"'<'",
")",
... | 35.512821 | 15.128205 |
def watch(project_path, output_path, host='0.0.0.0', port=8000, min_reload_time=2.0,
open_browser=True, safe_mode=False, error_context=None):
"""Watches the given project path for filesystem changes, and automatically rebuilds the project when
changes are detected. Also serves an HTTP server on the gi... | [
"def",
"watch",
"(",
"project_path",
",",
"output_path",
",",
"host",
"=",
"'0.0.0.0'",
",",
"port",
"=",
"8000",
",",
"min_reload_time",
"=",
"2.0",
",",
"open_browser",
"=",
"True",
",",
"safe_mode",
"=",
"False",
",",
"error_context",
"=",
"None",
")",
... | 44.836364 | 25.236364 |
def check_status(content, response):
"""
Check the response that is returned for known exceptions and errors.
:param response: Response that is returned from the call.
:raise:
MalformedRequestException if `response.status` is 400
UnauthorisedException if `response.statu... | [
"def",
"check_status",
"(",
"content",
",",
"response",
")",
":",
"if",
"response",
".",
"status",
"==",
"400",
":",
"raise",
"MalformedRequestException",
"(",
"content",
",",
"response",
")",
"if",
"response",
".",
"status",
"==",
"401",
":",
"raise",
"Un... | 37.147059 | 19.5 |
def sortByColumn(self, index, direction):
"""
Sorts the data for this widget based on the inputed index & direction.
:param index | <int>
direction | <Qt.SortOrder
"""
if self.isPaged() and not self.isFullyLoaded():
self.reord... | [
"def",
"sortByColumn",
"(",
"self",
",",
"index",
",",
"direction",
")",
":",
"if",
"self",
".",
"isPaged",
"(",
")",
"and",
"not",
"self",
".",
"isFullyLoaded",
"(",
")",
":",
"self",
".",
"reorder",
"(",
"index",
",",
"direction",
")",
"else",
":",... | 37.909091 | 14.454545 |
def _validate_bagittxt(self):
"""
Verify that bagit.txt conforms to specification
"""
bagit_file_path = os.path.join(self.path, "bagit.txt")
with open(bagit_file_path, 'r') as bagit_file:
first_line = bagit_file.readline()
if first_line.startswith(BOM):
... | [
"def",
"_validate_bagittxt",
"(",
"self",
")",
":",
"bagit_file_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"path",
",",
"\"bagit.txt\"",
")",
"with",
"open",
"(",
"bagit_file_path",
",",
"'r'",
")",
"as",
"bagit_file",
":",
"first_line",... | 44.222222 | 13.111111 |
def write(self, content=None):
"""
Write report to file.
Parameters
----------
content: str
'summary', 'extended', 'powerflow'
"""
if self.system.files.no_output is True:
return
t, _ = elapsed()
if not content:
... | [
"def",
"write",
"(",
"self",
",",
"content",
"=",
"None",
")",
":",
"if",
"self",
".",
"system",
".",
"files",
".",
"no_output",
"is",
"True",
":",
"return",
"t",
",",
"_",
"=",
"elapsed",
"(",
")",
"if",
"not",
"content",
":",
"logger",
".",
"wa... | 33.344828 | 18.413793 |
def start_server(self):
"""start the selenium Remote Server."""
self.__subp = subprocess.Popen(self.command)
#print("\tselenium jar pid[%s] is running." %self.__subp.pid)
time.sleep(2) | [
"def",
"start_server",
"(",
"self",
")",
":",
"self",
".",
"__subp",
"=",
"subprocess",
".",
"Popen",
"(",
"self",
".",
"command",
")",
"#print(\"\\tselenium jar pid[%s] is running.\" %self.__subp.pid) \r",
"time",
".",
"sleep",
"(",
"2",
")"
] | 48 | 18.8 |
def _handle_paired_with(self, paired_with):
'''Handle input option paired_with'''
if paired_with is None or not paired_with:
var_name = []
var_value = []
elif isinstance(paired_with, str):
var_name = ['_' + paired_with]
if paired_with not in env.so... | [
"def",
"_handle_paired_with",
"(",
"self",
",",
"paired_with",
")",
":",
"if",
"paired_with",
"is",
"None",
"or",
"not",
"paired_with",
":",
"var_name",
"=",
"[",
"]",
"var_value",
"=",
"[",
"]",
"elif",
"isinstance",
"(",
"paired_with",
",",
"str",
")",
... | 41.264706 | 13.441176 |
async def mget(self, keys, *args):
"""
Returns a list of values ordered identically to ``keys``
"""
args = list_or_args(keys, args)
return await self.execute_command('MGET', *args) | [
"async",
"def",
"mget",
"(",
"self",
",",
"keys",
",",
"*",
"args",
")",
":",
"args",
"=",
"list_or_args",
"(",
"keys",
",",
"args",
")",
"return",
"await",
"self",
".",
"execute_command",
"(",
"'MGET'",
",",
"*",
"args",
")"
] | 35.833333 | 7.833333 |
def impute_dataframe_zero(df_impute):
"""
Replaces all ``NaNs``, ``-infs`` and ``+infs`` from the DataFrame `df_impute` with 0s.
The `df_impute` will be modified in place. All its columns will be into converted into dtype ``np.float64``.
:param df_impute: DataFrame to impute
:type df_impute: pandas... | [
"def",
"impute_dataframe_zero",
"(",
"df_impute",
")",
":",
"df_impute",
".",
"replace",
"(",
"[",
"np",
".",
"PINF",
",",
"np",
".",
"NINF",
"]",
",",
"0",
",",
"inplace",
"=",
"True",
")",
"df_impute",
".",
"fillna",
"(",
"0",
",",
"inplace",
"=",
... | 33.5 | 18.944444 |
def new(self, bytes_to_skip):
# type: (int) -> None
'''
Create a new Rock Ridge Sharing Protocol record.
Parameters:
bytes_to_skip - The number of bytes to skip.
Returns:
Nothing.
'''
if self._initialized:
raise pycdlibexception.PyCdl... | [
"def",
"new",
"(",
"self",
",",
"bytes_to_skip",
")",
":",
"# type: (int) -> None",
"if",
"self",
".",
"_initialized",
":",
"raise",
"pycdlibexception",
".",
"PyCdlibInternalError",
"(",
"'SP record already initialized!'",
")",
"self",
".",
"bytes_to_skip",
"=",
"by... | 28.8 | 21.733333 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.