repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
benvanwerkhoven/kernel_tuner | kernel_tuner/core.py | DeviceInterface.create_kernel_instance | def create_kernel_instance(self, kernel_options, params, verbose):
"""create kernel instance from kernel source, parameters, problem size, grid divisors, and so on"""
instance_string = util.get_instance_string(params)
grid_div = (kernel_options.grid_div_x, kernel_options.grid_div_y, kernel_optio... | python | def create_kernel_instance(self, kernel_options, params, verbose):
"""create kernel instance from kernel source, parameters, problem size, grid divisors, and so on"""
instance_string = util.get_instance_string(params)
grid_div = (kernel_options.grid_div_x, kernel_options.grid_div_y, kernel_optio... | [
"def",
"create_kernel_instance",
"(",
"self",
",",
"kernel_options",
",",
"params",
",",
"verbose",
")",
":",
"instance_string",
"=",
"util",
".",
"get_instance_string",
"(",
"params",
")",
"grid_div",
"=",
"(",
"kernel_options",
".",
"grid_div_x",
",",
"kernel_... | create kernel instance from kernel source, parameters, problem size, grid divisors, and so on | [
"create",
"kernel",
"instance",
"from",
"kernel",
"source",
"parameters",
"problem",
"size",
"grid",
"divisors",
"and",
"so",
"on"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/core.py#L216-L240 |
benvanwerkhoven/kernel_tuner | kernel_tuner/core.py | DeviceInterface.run_kernel | def run_kernel(self, func, gpu_args, instance):
""" Run a compiled kernel instance on a device """
logging.debug('run_kernel %s', instance.name)
logging.debug('thread block dims (%d, %d, %d)', *instance.threads)
logging.debug('grid dims (%d, %d, %d)', *instance.grid)
try:
... | python | def run_kernel(self, func, gpu_args, instance):
""" Run a compiled kernel instance on a device """
logging.debug('run_kernel %s', instance.name)
logging.debug('thread block dims (%d, %d, %d)', *instance.threads)
logging.debug('grid dims (%d, %d, %d)', *instance.grid)
try:
... | [
"def",
"run_kernel",
"(",
"self",
",",
"func",
",",
"gpu_args",
",",
"instance",
")",
":",
"logging",
".",
"debug",
"(",
"'run_kernel %s'",
",",
"instance",
".",
"name",
")",
"logging",
".",
"debug",
"(",
"'thread block dims (%d, %d, %d)'",
",",
"*",
"instan... | Run a compiled kernel instance on a device | [
"Run",
"a",
"compiled",
"kernel",
"instance",
"on",
"a",
"device"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/core.py#L254-L269 |
benvanwerkhoven/kernel_tuner | kernel_tuner/runners/noodles.py | _chunk_list | def _chunk_list(l, n):
"""Yield successive n-sized chunks from l."""
for i in range(0, len(l), n):
yield l[i:i + n] | python | def _chunk_list(l, n):
"""Yield successive n-sized chunks from l."""
for i in range(0, len(l), n):
yield l[i:i + n] | [
"def",
"_chunk_list",
"(",
"l",
",",
"n",
")",
":",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"l",
")",
",",
"n",
")",
":",
"yield",
"l",
"[",
"i",
":",
"i",
"+",
"n",
"]"
] | Yield successive n-sized chunks from l. | [
"Yield",
"successive",
"n",
"-",
"sized",
"chunks",
"from",
"l",
"."
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/runners/noodles.py#L21-L24 |
benvanwerkhoven/kernel_tuner | kernel_tuner/runners/noodles.py | NoodlesRunner.run | def run(self, parameter_space, kernel_options, tuning_options):
""" Tune all instances in parameter_space using a multiple threads
:param parameter_space: The parameter space as an iterable.
:type parameter_space: iterable
:param kernel_options: A dictionary with all options for the ke... | python | def run(self, parameter_space, kernel_options, tuning_options):
""" Tune all instances in parameter_space using a multiple threads
:param parameter_space: The parameter space as an iterable.
:type parameter_space: iterable
:param kernel_options: A dictionary with all options for the ke... | [
"def",
"run",
"(",
"self",
",",
"parameter_space",
",",
"kernel_options",
",",
"tuning_options",
")",
":",
"workflow",
"=",
"self",
".",
"_parameter_sweep",
"(",
"parameter_space",
",",
"kernel_options",
",",
"self",
".",
"device_options",
",",
"tuning_options",
... | Tune all instances in parameter_space using a multiple threads
:param parameter_space: The parameter space as an iterable.
:type parameter_space: iterable
:param kernel_options: A dictionary with all options for the kernel.
:type kernel_options: kernel_tuner.interface.Options
... | [
"Tune",
"all",
"instances",
"in",
"parameter_space",
"using",
"a",
"multiple",
"threads"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/runners/noodles.py#L34-L70 |
benvanwerkhoven/kernel_tuner | kernel_tuner/runners/noodles.py | NoodlesRunner._parameter_sweep | def _parameter_sweep(self, parameter_space, kernel_options, device_options, tuning_options):
"""Build a Noodles workflow by sweeping the parameter space"""
results = []
#randomize parameter space to do pseudo load balancing
parameter_space = list(parameter_space)
random.shuffle(... | python | def _parameter_sweep(self, parameter_space, kernel_options, device_options, tuning_options):
"""Build a Noodles workflow by sweeping the parameter space"""
results = []
#randomize parameter space to do pseudo load balancing
parameter_space = list(parameter_space)
random.shuffle(... | [
"def",
"_parameter_sweep",
"(",
"self",
",",
"parameter_space",
",",
"kernel_options",
",",
"device_options",
",",
"tuning_options",
")",
":",
"results",
"=",
"[",
"]",
"#randomize parameter space to do pseudo load balancing",
"parameter_space",
"=",
"list",
"(",
"param... | Build a Noodles workflow by sweeping the parameter space | [
"Build",
"a",
"Noodles",
"workflow",
"by",
"sweeping",
"the",
"parameter",
"space"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/runners/noodles.py#L76-L94 |
benvanwerkhoven/kernel_tuner | kernel_tuner/runners/noodles.py | NoodlesRunner._run_chunk | def _run_chunk(self, chunk, kernel_options, device_options, tuning_options):
"""Benchmark a single kernel instance in the parameter space"""
#detect language and create high-level device interface
self.dev = DeviceInterface(kernel_options.kernel_string, iterations=tuning_options.iterations, **d... | python | def _run_chunk(self, chunk, kernel_options, device_options, tuning_options):
"""Benchmark a single kernel instance in the parameter space"""
#detect language and create high-level device interface
self.dev = DeviceInterface(kernel_options.kernel_string, iterations=tuning_options.iterations, **d... | [
"def",
"_run_chunk",
"(",
"self",
",",
"chunk",
",",
"kernel_options",
",",
"device_options",
",",
"tuning_options",
")",
":",
"#detect language and create high-level device interface",
"self",
".",
"dev",
"=",
"DeviceInterface",
"(",
"kernel_options",
".",
"kernel_stri... | Benchmark a single kernel instance in the parameter space | [
"Benchmark",
"a",
"single",
"kernel",
"instance",
"in",
"the",
"parameter",
"space"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/runners/noodles.py#L99-L122 |
benvanwerkhoven/kernel_tuner | kernel_tuner/strategies/random_sample.py | tune | def tune(runner, kernel_options, device_options, tuning_options):
""" Tune a random sample of sample_fraction fraction in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:t... | python | def tune(runner, kernel_options, device_options, tuning_options):
""" Tune a random sample of sample_fraction fraction in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:t... | [
"def",
"tune",
"(",
"runner",
",",
"kernel_options",
",",
"device_options",
",",
"tuning_options",
")",
":",
"tune_params",
"=",
"tuning_options",
".",
"tune_params",
"#compute cartesian product of all tunable parameters",
"parameter_space",
"=",
"itertools",
".",
"produc... | Tune a random sample of sample_fraction fraction in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:type kernel_options: kernel_tuner.interface.Options
:param device_opti... | [
"Tune",
"a",
"random",
"sample",
"of",
"sample_fraction",
"fraction",
"in",
"the",
"parameter",
"space"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/strategies/random_sample.py#L9-L55 |
benvanwerkhoven/kernel_tuner | kernel_tuner/util.py | check_argument_type | def check_argument_type(dtype, kernel_argument, i):
"""check if the numpy.dtype matches the type used in the code"""
types_map = {"uint8": ["uchar", "unsigned char", "uint8_t"],
"int8": ["char", "int8_t"],
"uint16": ["ushort", "unsigned short", "uint16_t"],
"in... | python | def check_argument_type(dtype, kernel_argument, i):
"""check if the numpy.dtype matches the type used in the code"""
types_map = {"uint8": ["uchar", "unsigned char", "uint8_t"],
"int8": ["char", "int8_t"],
"uint16": ["ushort", "unsigned short", "uint16_t"],
"in... | [
"def",
"check_argument_type",
"(",
"dtype",
",",
"kernel_argument",
",",
"i",
")",
":",
"types_map",
"=",
"{",
"\"uint8\"",
":",
"[",
"\"uchar\"",
",",
"\"unsigned char\"",
",",
"\"uint8_t\"",
"]",
",",
"\"int8\"",
":",
"[",
"\"char\"",
",",
"\"int8_t\"",
"]... | check if the numpy.dtype matches the type used in the code | [
"check",
"if",
"the",
"numpy",
".",
"dtype",
"matches",
"the",
"type",
"used",
"in",
"the",
"code"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/util.py#L16-L32 |
benvanwerkhoven/kernel_tuner | kernel_tuner/util.py | check_argument_list | def check_argument_list(kernel_name, kernel_string, args):
""" raise an exception if a kernel arguments do not match host arguments """
kernel_arguments = list()
collected_errors = list()
for iterator in re.finditer(kernel_name + "[ \n\t]*" + "\(", kernel_string):
kernel_start = iterator.end()
... | python | def check_argument_list(kernel_name, kernel_string, args):
""" raise an exception if a kernel arguments do not match host arguments """
kernel_arguments = list()
collected_errors = list()
for iterator in re.finditer(kernel_name + "[ \n\t]*" + "\(", kernel_string):
kernel_start = iterator.end()
... | [
"def",
"check_argument_list",
"(",
"kernel_name",
",",
"kernel_string",
",",
"args",
")",
":",
"kernel_arguments",
"=",
"list",
"(",
")",
"collected_errors",
"=",
"list",
"(",
")",
"for",
"iterator",
"in",
"re",
".",
"finditer",
"(",
"kernel_name",
"+",
"\"[... | raise an exception if a kernel arguments do not match host arguments | [
"raise",
"an",
"exception",
"if",
"a",
"kernel",
"arguments",
"do",
"not",
"match",
"host",
"arguments"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/util.py#L34-L68 |
benvanwerkhoven/kernel_tuner | kernel_tuner/util.py | check_tune_params_list | def check_tune_params_list(tune_params):
""" raise an exception if a tune parameter has a forbidden name """
forbidden_names = ("grid_size_x", "grid_size_y", "grid_size_z")
forbidden_name_substr = ("time", "times")
for name, param in tune_params.items():
if name in forbidden_names:
r... | python | def check_tune_params_list(tune_params):
""" raise an exception if a tune parameter has a forbidden name """
forbidden_names = ("grid_size_x", "grid_size_y", "grid_size_z")
forbidden_name_substr = ("time", "times")
for name, param in tune_params.items():
if name in forbidden_names:
r... | [
"def",
"check_tune_params_list",
"(",
"tune_params",
")",
":",
"forbidden_names",
"=",
"(",
"\"grid_size_x\"",
",",
"\"grid_size_y\"",
",",
"\"grid_size_z\"",
")",
"forbidden_name_substr",
"=",
"(",
"\"time\"",
",",
"\"times\"",
")",
"for",
"name",
",",
"param",
"... | raise an exception if a tune parameter has a forbidden name | [
"raise",
"an",
"exception",
"if",
"a",
"tune",
"parameter",
"has",
"a",
"forbidden",
"name"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/util.py#L71-L80 |
benvanwerkhoven/kernel_tuner | kernel_tuner/util.py | check_restrictions | def check_restrictions(restrictions, element, keys, verbose):
""" check whether a specific instance meets the search space restrictions """
params = OrderedDict(zip(keys, element))
for restrict in restrictions:
if not eval(replace_param_occurrences(restrict, params)):
if verbose:
... | python | def check_restrictions(restrictions, element, keys, verbose):
""" check whether a specific instance meets the search space restrictions """
params = OrderedDict(zip(keys, element))
for restrict in restrictions:
if not eval(replace_param_occurrences(restrict, params)):
if verbose:
... | [
"def",
"check_restrictions",
"(",
"restrictions",
",",
"element",
",",
"keys",
",",
"verbose",
")",
":",
"params",
"=",
"OrderedDict",
"(",
"zip",
"(",
"keys",
",",
"element",
")",
")",
"for",
"restrict",
"in",
"restrictions",
":",
"if",
"not",
"eval",
"... | check whether a specific instance meets the search space restrictions | [
"check",
"whether",
"a",
"specific",
"instance",
"meets",
"the",
"search",
"space",
"restrictions"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/util.py#L106-L114 |
benvanwerkhoven/kernel_tuner | kernel_tuner/util.py | detect_language | def detect_language(lang, kernel_source):
"""attempt to detect language from the kernel_string if not specified"""
if lang is None:
if callable(kernel_source):
raise TypeError("Please specify language when using a code generator function")
kernel_string = get_kernel_string(kernel_sou... | python | def detect_language(lang, kernel_source):
"""attempt to detect language from the kernel_string if not specified"""
if lang is None:
if callable(kernel_source):
raise TypeError("Please specify language when using a code generator function")
kernel_string = get_kernel_string(kernel_sou... | [
"def",
"detect_language",
"(",
"lang",
",",
"kernel_source",
")",
":",
"if",
"lang",
"is",
"None",
":",
"if",
"callable",
"(",
"kernel_source",
")",
":",
"raise",
"TypeError",
"(",
"\"Please specify language when using a code generator function\"",
")",
"kernel_string... | attempt to detect language from the kernel_string if not specified | [
"attempt",
"to",
"detect",
"language",
"from",
"the",
"kernel_string",
"if",
"not",
"specified"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/util.py#L124-L136 |
benvanwerkhoven/kernel_tuner | kernel_tuner/util.py | get_config_string | def get_config_string(params, units=None):
""" return a compact string representation of a dictionary """
compact_str_items = []
# first make a list of compact strings for each parameter
for k, v in params.items():
unit = ""
if isinstance(units, dict): #check if not None not enough, unit... | python | def get_config_string(params, units=None):
""" return a compact string representation of a dictionary """
compact_str_items = []
# first make a list of compact strings for each parameter
for k, v in params.items():
unit = ""
if isinstance(units, dict): #check if not None not enough, unit... | [
"def",
"get_config_string",
"(",
"params",
",",
"units",
"=",
"None",
")",
":",
"compact_str_items",
"=",
"[",
"]",
"# first make a list of compact strings for each parameter",
"for",
"k",
",",
"v",
"in",
"params",
".",
"items",
"(",
")",
":",
"unit",
"=",
"\"... | return a compact string representation of a dictionary | [
"return",
"a",
"compact",
"string",
"representation",
"of",
"a",
"dictionary"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/util.py#L139-L150 |
benvanwerkhoven/kernel_tuner | kernel_tuner/util.py | get_grid_dimensions | def get_grid_dimensions(current_problem_size, params, grid_div, block_size_names):
"""compute grid dims based on problem sizes and listed grid divisors"""
def get_dimension_divisor(divisor_list, default, params):
if divisor_list is None:
if default in params:
divisor_list = [... | python | def get_grid_dimensions(current_problem_size, params, grid_div, block_size_names):
"""compute grid dims based on problem sizes and listed grid divisors"""
def get_dimension_divisor(divisor_list, default, params):
if divisor_list is None:
if default in params:
divisor_list = [... | [
"def",
"get_grid_dimensions",
"(",
"current_problem_size",
",",
"params",
",",
"grid_div",
",",
"block_size_names",
")",
":",
"def",
"get_dimension_divisor",
"(",
"divisor_list",
",",
"default",
",",
"params",
")",
":",
"if",
"divisor_list",
"is",
"None",
":",
"... | compute grid dims based on problem sizes and listed grid divisors | [
"compute",
"grid",
"dims",
"based",
"on",
"problem",
"sizes",
"and",
"listed",
"grid",
"divisors"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/util.py#L153-L163 |
benvanwerkhoven/kernel_tuner | kernel_tuner/util.py | get_kernel_string | def get_kernel_string(kernel_source, params=None):
""" retrieve the kernel source and return as a string
This function processes the passed kernel_source argument, which could be
a function, a string with a filename, or just a string with code already.
If kernel_source is a function, the function is c... | python | def get_kernel_string(kernel_source, params=None):
""" retrieve the kernel source and return as a string
This function processes the passed kernel_source argument, which could be
a function, a string with a filename, or just a string with code already.
If kernel_source is a function, the function is c... | [
"def",
"get_kernel_string",
"(",
"kernel_source",
",",
"params",
"=",
"None",
")",
":",
"#logging.debug('get_kernel_string called with %s', str(kernel_source))",
"logging",
".",
"debug",
"(",
"'get_kernel_string called'",
")",
"kernel_string",
"=",
"None",
"if",
"callable",... | retrieve the kernel source and return as a string
This function processes the passed kernel_source argument, which could be
a function, a string with a filename, or just a string with code already.
If kernel_source is a function, the function is called with instance
parameters in 'params' as the only ... | [
"retrieve",
"the",
"kernel",
"source",
"and",
"return",
"as",
"a",
"string"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/util.py#L171-L209 |
benvanwerkhoven/kernel_tuner | kernel_tuner/util.py | get_problem_size | def get_problem_size(problem_size, params):
"""compute current problem size"""
if isinstance(problem_size, (str, int, numpy.integer)):
problem_size = (problem_size, )
current_problem_size = [1, 1, 1]
for i, s in enumerate(problem_size):
if isinstance(s, str):
current_problem_... | python | def get_problem_size(problem_size, params):
"""compute current problem size"""
if isinstance(problem_size, (str, int, numpy.integer)):
problem_size = (problem_size, )
current_problem_size = [1, 1, 1]
for i, s in enumerate(problem_size):
if isinstance(s, str):
current_problem_... | [
"def",
"get_problem_size",
"(",
"problem_size",
",",
"params",
")",
":",
"if",
"isinstance",
"(",
"problem_size",
",",
"(",
"str",
",",
"int",
",",
"numpy",
".",
"integer",
")",
")",
":",
"problem_size",
"=",
"(",
"problem_size",
",",
")",
"current_problem... | compute current problem size | [
"compute",
"current",
"problem",
"size"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/util.py#L211-L223 |
benvanwerkhoven/kernel_tuner | kernel_tuner/util.py | get_temp_filename | def get_temp_filename(suffix=None):
""" return a string in the form of temp_X, where X is a large integer """
file = tempfile.mkstemp(suffix=suffix or "", prefix="temp_", dir=os.getcwd()) # or "" for Python 2 compatibility
os.close(file[0])
return file[1] | python | def get_temp_filename(suffix=None):
""" return a string in the form of temp_X, where X is a large integer """
file = tempfile.mkstemp(suffix=suffix or "", prefix="temp_", dir=os.getcwd()) # or "" for Python 2 compatibility
os.close(file[0])
return file[1] | [
"def",
"get_temp_filename",
"(",
"suffix",
"=",
"None",
")",
":",
"file",
"=",
"tempfile",
".",
"mkstemp",
"(",
"suffix",
"=",
"suffix",
"or",
"\"\"",
",",
"prefix",
"=",
"\"temp_\"",
",",
"dir",
"=",
"os",
".",
"getcwd",
"(",
")",
")",
"# or \"\" for ... | return a string in the form of temp_X, where X is a large integer | [
"return",
"a",
"string",
"in",
"the",
"form",
"of",
"temp_X",
"where",
"X",
"is",
"a",
"large",
"integer"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/util.py#L225-L229 |
benvanwerkhoven/kernel_tuner | kernel_tuner/util.py | get_thread_block_dimensions | def get_thread_block_dimensions(params, block_size_names=None):
"""thread block size from tuning params, currently using convention"""
if not block_size_names:
block_size_names = default_block_size_names
block_size_x = params.get(block_size_names[0], 256)
block_size_y = params.get(block_size_na... | python | def get_thread_block_dimensions(params, block_size_names=None):
"""thread block size from tuning params, currently using convention"""
if not block_size_names:
block_size_names = default_block_size_names
block_size_x = params.get(block_size_names[0], 256)
block_size_y = params.get(block_size_na... | [
"def",
"get_thread_block_dimensions",
"(",
"params",
",",
"block_size_names",
"=",
"None",
")",
":",
"if",
"not",
"block_size_names",
":",
"block_size_names",
"=",
"default_block_size_names",
"block_size_x",
"=",
"params",
".",
"get",
"(",
"block_size_names",
"[",
"... | thread block size from tuning params, currently using convention | [
"thread",
"block",
"size",
"from",
"tuning",
"params",
"currently",
"using",
"convention"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/util.py#L231-L239 |
benvanwerkhoven/kernel_tuner | kernel_tuner/util.py | looks_like_a_filename | def looks_like_a_filename(kernel_source):
""" attempt to detect whether source code or a filename was passed """
logging.debug('looks_like_a_filename called')
result = False
if isinstance(kernel_source, str):
result = True
#test if not too long
if len(kernel_source) > 250:
... | python | def looks_like_a_filename(kernel_source):
""" attempt to detect whether source code or a filename was passed """
logging.debug('looks_like_a_filename called')
result = False
if isinstance(kernel_source, str):
result = True
#test if not too long
if len(kernel_source) > 250:
... | [
"def",
"looks_like_a_filename",
"(",
"kernel_source",
")",
":",
"logging",
".",
"debug",
"(",
"'looks_like_a_filename called'",
")",
"result",
"=",
"False",
"if",
"isinstance",
"(",
"kernel_source",
",",
"str",
")",
":",
"result",
"=",
"True",
"#test if not too lo... | attempt to detect whether source code or a filename was passed | [
"attempt",
"to",
"detect",
"whether",
"source",
"code",
"or",
"a",
"filename",
"was",
"passed"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/util.py#L241-L261 |
benvanwerkhoven/kernel_tuner | kernel_tuner/util.py | prepare_kernel_string | def prepare_kernel_string(kernel_name, kernel_string, params, grid, threads, block_size_names):
""" prepare kernel string for compilation
Prepends the kernel with a series of C preprocessor defines specific
to this kernel instance:
* the thread block dimensions
* the grid dimensions
* tunab... | python | def prepare_kernel_string(kernel_name, kernel_string, params, grid, threads, block_size_names):
""" prepare kernel string for compilation
Prepends the kernel with a series of C preprocessor defines specific
to this kernel instance:
* the thread block dimensions
* the grid dimensions
* tunab... | [
"def",
"prepare_kernel_string",
"(",
"kernel_name",
",",
"kernel_string",
",",
"params",
",",
"grid",
",",
"threads",
",",
"block_size_names",
")",
":",
"logging",
".",
"debug",
"(",
"'prepare_kernel_string called for %s'",
",",
"kernel_name",
")",
"grid_dim_names",
... | prepare kernel string for compilation
Prepends the kernel with a series of C preprocessor defines specific
to this kernel instance:
* the thread block dimensions
* the grid dimensions
* tunable parameters
Additionally the name of kernel is replace with an instance specific name. This
i... | [
"prepare",
"kernel",
"string",
"for",
"compilation"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/util.py#L263-L315 |
benvanwerkhoven/kernel_tuner | kernel_tuner/util.py | prepare_list_of_files | def prepare_list_of_files(kernel_name, kernel_file_list, params, grid, threads, block_size_names):
""" prepare the kernel string along with any additional files
The first file in the list is allowed to include or read in the others
The files beyond the first are considered additional files that may also co... | python | def prepare_list_of_files(kernel_name, kernel_file_list, params, grid, threads, block_size_names):
""" prepare the kernel string along with any additional files
The first file in the list is allowed to include or read in the others
The files beyond the first are considered additional files that may also co... | [
"def",
"prepare_list_of_files",
"(",
"kernel_name",
",",
"kernel_file_list",
",",
"params",
",",
"grid",
",",
"threads",
",",
"block_size_names",
")",
":",
"temp_files",
"=",
"dict",
"(",
")",
"kernel_string",
"=",
"get_kernel_string",
"(",
"kernel_file_list",
"["... | prepare the kernel string along with any additional files
The first file in the list is allowed to include or read in the others
The files beyond the first are considered additional files that may also contain tunable parameters
For each file beyond the first this function creates a temporary file with
... | [
"prepare",
"the",
"kernel",
"string",
"along",
"with",
"any",
"additional",
"files"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/util.py#L317-L358 |
benvanwerkhoven/kernel_tuner | kernel_tuner/util.py | read_file | def read_file(filename):
""" return the contents of the file named filename or None if file not found """
if os.path.isfile(filename):
with open(filename, 'r') as f:
return f.read() | python | def read_file(filename):
""" return the contents of the file named filename or None if file not found """
if os.path.isfile(filename):
with open(filename, 'r') as f:
return f.read() | [
"def",
"read_file",
"(",
"filename",
")",
":",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"filename",
")",
":",
"with",
"open",
"(",
"filename",
",",
"'r'",
")",
"as",
"f",
":",
"return",
"f",
".",
"read",
"(",
")"
] | return the contents of the file named filename or None if file not found | [
"return",
"the",
"contents",
"of",
"the",
"file",
"named",
"filename",
"or",
"None",
"if",
"file",
"not",
"found"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/util.py#L360-L364 |
benvanwerkhoven/kernel_tuner | kernel_tuner/util.py | replace_param_occurrences | def replace_param_occurrences(string, params):
"""replace occurrences of the tuning params with their current value"""
for k, v in params.items():
string = string.replace(k, str(v))
return string | python | def replace_param_occurrences(string, params):
"""replace occurrences of the tuning params with their current value"""
for k, v in params.items():
string = string.replace(k, str(v))
return string | [
"def",
"replace_param_occurrences",
"(",
"string",
",",
"params",
")",
":",
"for",
"k",
",",
"v",
"in",
"params",
".",
"items",
"(",
")",
":",
"string",
"=",
"string",
".",
"replace",
"(",
"k",
",",
"str",
"(",
"v",
")",
")",
"return",
"string"
] | replace occurrences of the tuning params with their current value | [
"replace",
"occurrences",
"of",
"the",
"tuning",
"params",
"with",
"their",
"current",
"value"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/util.py#L366-L370 |
benvanwerkhoven/kernel_tuner | kernel_tuner/util.py | setup_block_and_grid | def setup_block_and_grid(problem_size, grid_div, params, block_size_names=None):
"""compute problem size, thread block and grid dimensions for this kernel"""
threads = get_thread_block_dimensions(params, block_size_names)
current_problem_size = get_problem_size(problem_size, params)
grid = get_grid_dime... | python | def setup_block_and_grid(problem_size, grid_div, params, block_size_names=None):
"""compute problem size, thread block and grid dimensions for this kernel"""
threads = get_thread_block_dimensions(params, block_size_names)
current_problem_size = get_problem_size(problem_size, params)
grid = get_grid_dime... | [
"def",
"setup_block_and_grid",
"(",
"problem_size",
",",
"grid_div",
",",
"params",
",",
"block_size_names",
"=",
"None",
")",
":",
"threads",
"=",
"get_thread_block_dimensions",
"(",
"params",
",",
"block_size_names",
")",
"current_problem_size",
"=",
"get_problem_si... | compute problem size, thread block and grid dimensions for this kernel | [
"compute",
"problem",
"size",
"thread",
"block",
"and",
"grid",
"dimensions",
"for",
"this",
"kernel"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/util.py#L372-L377 |
benvanwerkhoven/kernel_tuner | kernel_tuner/util.py | write_file | def write_file(filename, string):
"""dump the contents of string to a file called filename"""
import sys
#ugly fix, hopefully we can find a better one
if sys.version_info[0] >= 3:
with open(filename, 'w', encoding="utf-8") as f:
f.write(string)
else:
with open(filename, '... | python | def write_file(filename, string):
"""dump the contents of string to a file called filename"""
import sys
#ugly fix, hopefully we can find a better one
if sys.version_info[0] >= 3:
with open(filename, 'w', encoding="utf-8") as f:
f.write(string)
else:
with open(filename, '... | [
"def",
"write_file",
"(",
"filename",
",",
"string",
")",
":",
"import",
"sys",
"#ugly fix, hopefully we can find a better one",
"if",
"sys",
".",
"version_info",
"[",
"0",
"]",
">=",
"3",
":",
"with",
"open",
"(",
"filename",
",",
"'w'",
",",
"encoding",
"=... | dump the contents of string to a file called filename | [
"dump",
"the",
"contents",
"of",
"string",
"to",
"a",
"file",
"called",
"filename"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/util.py#L379-L388 |
benvanwerkhoven/kernel_tuner | kernel_tuner/opencl.py | OpenCLFunctions.ready_argument_list | def ready_argument_list(self, arguments):
"""ready argument list to be passed to the kernel, allocates gpu mem
:param arguments: List of arguments to be passed to the kernel.
The order should match the argument list on the OpenCL kernel.
Allowed values are numpy.ndarray, and/or ... | python | def ready_argument_list(self, arguments):
"""ready argument list to be passed to the kernel, allocates gpu mem
:param arguments: List of arguments to be passed to the kernel.
The order should match the argument list on the OpenCL kernel.
Allowed values are numpy.ndarray, and/or ... | [
"def",
"ready_argument_list",
"(",
"self",
",",
"arguments",
")",
":",
"gpu_args",
"=",
"[",
"]",
"for",
"arg",
"in",
"arguments",
":",
"# if arg i is a numpy array copy to device",
"if",
"isinstance",
"(",
"arg",
",",
"numpy",
".",
"ndarray",
")",
":",
"gpu_a... | ready argument list to be passed to the kernel, allocates gpu mem
:param arguments: List of arguments to be passed to the kernel.
The order should match the argument list on the OpenCL kernel.
Allowed values are numpy.ndarray, and/or numpy.int32, numpy.float32, and so on.
:type ... | [
"ready",
"argument",
"list",
"to",
"be",
"passed",
"to",
"the",
"kernel",
"allocates",
"gpu",
"mem"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/opencl.py#L52-L70 |
benvanwerkhoven/kernel_tuner | kernel_tuner/opencl.py | OpenCLFunctions.compile | def compile(self, kernel_name, kernel_string):
"""call the OpenCL compiler to compile the kernel, return the device function
:param kernel_name: The name of the kernel to be compiled, used to lookup the
function after compilation.
:type kernel_name: string
:param kernel_str... | python | def compile(self, kernel_name, kernel_string):
"""call the OpenCL compiler to compile the kernel, return the device function
:param kernel_name: The name of the kernel to be compiled, used to lookup the
function after compilation.
:type kernel_name: string
:param kernel_str... | [
"def",
"compile",
"(",
"self",
",",
"kernel_name",
",",
"kernel_string",
")",
":",
"prg",
"=",
"cl",
".",
"Program",
"(",
"self",
".",
"ctx",
",",
"kernel_string",
")",
".",
"build",
"(",
"options",
"=",
"self",
".",
"compiler_options",
")",
"func",
"=... | call the OpenCL compiler to compile the kernel, return the device function
:param kernel_name: The name of the kernel to be compiled, used to lookup the
function after compilation.
:type kernel_name: string
:param kernel_string: The OpenCL kernel code that contains the function `ke... | [
"call",
"the",
"OpenCL",
"compiler",
"to",
"compile",
"the",
"kernel",
"return",
"the",
"device",
"function"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/opencl.py#L72-L87 |
benvanwerkhoven/kernel_tuner | kernel_tuner/opencl.py | OpenCLFunctions.benchmark | def benchmark(self, func, gpu_args, threads, grid, times):
"""runs the kernel and measures time repeatedly, returns average time
Runs the kernel and measures kernel execution time repeatedly, number of
iterations is set during the creation of OpenCLFunctions. Benchmark returns
a robust ... | python | def benchmark(self, func, gpu_args, threads, grid, times):
"""runs the kernel and measures time repeatedly, returns average time
Runs the kernel and measures kernel execution time repeatedly, number of
iterations is set during the creation of OpenCLFunctions. Benchmark returns
a robust ... | [
"def",
"benchmark",
"(",
"self",
",",
"func",
",",
"gpu_args",
",",
"threads",
",",
"grid",
",",
"times",
")",
":",
"global_size",
"=",
"(",
"grid",
"[",
"0",
"]",
"*",
"threads",
"[",
"0",
"]",
",",
"grid",
"[",
"1",
"]",
"*",
"threads",
"[",
... | runs the kernel and measures time repeatedly, returns average time
Runs the kernel and measures kernel execution time repeatedly, number of
iterations is set during the creation of OpenCLFunctions. Benchmark returns
a robust average, from all measurements the fastest and slowest runs are
... | [
"runs",
"the",
"kernel",
"and",
"measures",
"time",
"repeatedly",
"returns",
"average",
"time"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/opencl.py#L89-L136 |
benvanwerkhoven/kernel_tuner | kernel_tuner/opencl.py | OpenCLFunctions.run_kernel | def run_kernel(self, func, gpu_args, threads, grid):
"""runs the OpenCL kernel passed as 'func'
:param func: An OpenCL Kernel
:type func: pyopencl.Kernel
:param gpu_args: A list of arguments to the kernel, order should match the
order in the code. Allowed values are either ... | python | def run_kernel(self, func, gpu_args, threads, grid):
"""runs the OpenCL kernel passed as 'func'
:param func: An OpenCL Kernel
:type func: pyopencl.Kernel
:param gpu_args: A list of arguments to the kernel, order should match the
order in the code. Allowed values are either ... | [
"def",
"run_kernel",
"(",
"self",
",",
"func",
",",
"gpu_args",
",",
"threads",
",",
"grid",
")",
":",
"global_size",
"=",
"(",
"grid",
"[",
"0",
"]",
"*",
"threads",
"[",
"0",
"]",
",",
"grid",
"[",
"1",
"]",
"*",
"threads",
"[",
"1",
"]",
","... | runs the OpenCL kernel passed as 'func'
:param func: An OpenCL Kernel
:type func: pyopencl.Kernel
:param gpu_args: A list of arguments to the kernel, order should match the
order in the code. Allowed values are either variables in global memory
or single values passed b... | [
"runs",
"the",
"OpenCL",
"kernel",
"passed",
"as",
"func"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/opencl.py#L138-L160 |
benvanwerkhoven/kernel_tuner | kernel_tuner/opencl.py | OpenCLFunctions.memset | def memset(self, buffer, value, size):
"""set the memory in allocation to the value in value
:param allocation: An OpenCL Buffer to fill
:type allocation: pyopencl.Buffer
:param value: The value to set the memory to
:type value: a single 32-bit int
:param size: The siz... | python | def memset(self, buffer, value, size):
"""set the memory in allocation to the value in value
:param allocation: An OpenCL Buffer to fill
:type allocation: pyopencl.Buffer
:param value: The value to set the memory to
:type value: a single 32-bit int
:param size: The siz... | [
"def",
"memset",
"(",
"self",
",",
"buffer",
",",
"value",
",",
"size",
")",
":",
"if",
"isinstance",
"(",
"buffer",
",",
"cl",
".",
"Buffer",
")",
":",
"try",
":",
"cl",
".",
"enqueue_fill_buffer",
"(",
"self",
".",
"queue",
",",
"buffer",
",",
"n... | set the memory in allocation to the value in value
:param allocation: An OpenCL Buffer to fill
:type allocation: pyopencl.Buffer
:param value: The value to set the memory to
:type value: a single 32-bit int
:param size: The size of to the allocation unit in bytes
:type... | [
"set",
"the",
"memory",
"in",
"allocation",
"to",
"the",
"value",
"in",
"value"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/opencl.py#L162-L180 |
benvanwerkhoven/kernel_tuner | kernel_tuner/opencl.py | OpenCLFunctions.memcpy_dtoh | def memcpy_dtoh(self, dest, src):
"""perform a device to host memory copy
:param dest: A numpy array in host memory to store the data
:type dest: numpy.ndarray
:param src: An OpenCL Buffer to copy data from
:type src: pyopencl.Buffer
"""
if isinstance(src, cl.Bu... | python | def memcpy_dtoh(self, dest, src):
"""perform a device to host memory copy
:param dest: A numpy array in host memory to store the data
:type dest: numpy.ndarray
:param src: An OpenCL Buffer to copy data from
:type src: pyopencl.Buffer
"""
if isinstance(src, cl.Bu... | [
"def",
"memcpy_dtoh",
"(",
"self",
",",
"dest",
",",
"src",
")",
":",
"if",
"isinstance",
"(",
"src",
",",
"cl",
".",
"Buffer",
")",
":",
"cl",
".",
"enqueue_copy",
"(",
"self",
".",
"queue",
",",
"dest",
",",
"src",
")"
] | perform a device to host memory copy
:param dest: A numpy array in host memory to store the data
:type dest: numpy.ndarray
:param src: An OpenCL Buffer to copy data from
:type src: pyopencl.Buffer | [
"perform",
"a",
"device",
"to",
"host",
"memory",
"copy"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/opencl.py#L182-L192 |
benvanwerkhoven/kernel_tuner | kernel_tuner/strategies/diff_evo.py | tune | def tune(runner, kernel_options, device_options, tuning_options):
""" Find the best performing kernel configuration in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:type... | python | def tune(runner, kernel_options, device_options, tuning_options):
""" Find the best performing kernel configuration in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:type... | [
"def",
"tune",
"(",
"runner",
",",
"kernel_options",
",",
"device_options",
",",
"tuning_options",
")",
":",
"results",
"=",
"[",
"]",
"cache",
"=",
"{",
"}",
"tuning_options",
"[",
"\"scaling\"",
"]",
"=",
"False",
"#build a bounds array as needed for the optimiz... | Find the best performing kernel configuration in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:type kernel_options: kernel_tuner.interface.Options
:param device_options... | [
"Find",
"the",
"best",
"performing",
"kernel",
"configuration",
"in",
"the",
"parameter",
"space"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/strategies/diff_evo.py#L8-L48 |
benvanwerkhoven/kernel_tuner | kernel_tuner/strategies/pso.py | tune | def tune(runner, kernel_options, device_options, tuning_options):
""" Find the best performing kernel configuration in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:type... | python | def tune(runner, kernel_options, device_options, tuning_options):
""" Find the best performing kernel configuration in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:type... | [
"def",
"tune",
"(",
"runner",
",",
"kernel_options",
",",
"device_options",
",",
"tuning_options",
")",
":",
"results",
"=",
"[",
"]",
"cache",
"=",
"{",
"}",
"#scale variables in x because PSO works with velocities to visit different configurations",
"tuning_options",
"[... | Find the best performing kernel configuration in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:type kernel_options: dict
:param device_options: A dictionary with all op... | [
"Find",
"the",
"best",
"performing",
"kernel",
"configuration",
"in",
"the",
"parameter",
"space"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/strategies/pso.py#L10-L79 |
benvanwerkhoven/kernel_tuner | kernel_tuner/strategies/genetic_algorithm.py | tune | def tune(runner, kernel_options, device_options, tuning_options):
""" Find the best performing kernel configuration in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:type... | python | def tune(runner, kernel_options, device_options, tuning_options):
""" Find the best performing kernel configuration in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:type... | [
"def",
"tune",
"(",
"runner",
",",
"kernel_options",
",",
"device_options",
",",
"tuning_options",
")",
":",
"dna_size",
"=",
"len",
"(",
"tuning_options",
".",
"tune_params",
".",
"keys",
"(",
")",
")",
"pop_size",
"=",
"20",
"generations",
"=",
"100",
"t... | Find the best performing kernel configuration in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:type kernel_options: kernel_tuner.interface.Options
:param device_options... | [
"Find",
"the",
"best",
"performing",
"kernel",
"configuration",
"in",
"the",
"parameter",
"space"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/strategies/genetic_algorithm.py#L8-L73 |
benvanwerkhoven/kernel_tuner | kernel_tuner/strategies/genetic_algorithm.py | weighted_choice | def weighted_choice(population):
"""Randomly select, fitness determines probability of being selected"""
random_number = random.betavariate(1, 2.5) #increased probability of selecting members early in the list
#random_number = random.random()
ind = int(random_number*len(population))
ind = min(max(in... | python | def weighted_choice(population):
"""Randomly select, fitness determines probability of being selected"""
random_number = random.betavariate(1, 2.5) #increased probability of selecting members early in the list
#random_number = random.random()
ind = int(random_number*len(population))
ind = min(max(in... | [
"def",
"weighted_choice",
"(",
"population",
")",
":",
"random_number",
"=",
"random",
".",
"betavariate",
"(",
"1",
",",
"2.5",
")",
"#increased probability of selecting members early in the list",
"#random_number = random.random()",
"ind",
"=",
"int",
"(",
"random_numbe... | Randomly select, fitness determines probability of being selected | [
"Randomly",
"select",
"fitness",
"determines",
"probability",
"of",
"being",
"selected"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/strategies/genetic_algorithm.py#L77-L83 |
benvanwerkhoven/kernel_tuner | kernel_tuner/strategies/genetic_algorithm.py | random_population | def random_population(dna_size, pop_size, tune_params):
"""create a random population"""
population = []
for _ in range(pop_size):
dna = []
for i in range(dna_size):
dna.append(random_val(i, tune_params))
population.append(dna)
return population | python | def random_population(dna_size, pop_size, tune_params):
"""create a random population"""
population = []
for _ in range(pop_size):
dna = []
for i in range(dna_size):
dna.append(random_val(i, tune_params))
population.append(dna)
return population | [
"def",
"random_population",
"(",
"dna_size",
",",
"pop_size",
",",
"tune_params",
")",
":",
"population",
"=",
"[",
"]",
"for",
"_",
"in",
"range",
"(",
"pop_size",
")",
":",
"dna",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"dna_size",
")",
":",... | create a random population | [
"create",
"a",
"random",
"population"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/strategies/genetic_algorithm.py#L85-L93 |
benvanwerkhoven/kernel_tuner | kernel_tuner/strategies/genetic_algorithm.py | random_val | def random_val(index, tune_params):
"""return a random value for a parameter"""
key = list(tune_params.keys())[index]
return random.choice(tune_params[key]) | python | def random_val(index, tune_params):
"""return a random value for a parameter"""
key = list(tune_params.keys())[index]
return random.choice(tune_params[key]) | [
"def",
"random_val",
"(",
"index",
",",
"tune_params",
")",
":",
"key",
"=",
"list",
"(",
"tune_params",
".",
"keys",
"(",
")",
")",
"[",
"index",
"]",
"return",
"random",
".",
"choice",
"(",
"tune_params",
"[",
"key",
"]",
")"
] | return a random value for a parameter | [
"return",
"a",
"random",
"value",
"for",
"a",
"parameter"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/strategies/genetic_algorithm.py#L95-L98 |
benvanwerkhoven/kernel_tuner | kernel_tuner/strategies/genetic_algorithm.py | mutate | def mutate(dna, dna_size, tune_params):
"""Mutate DNA with 1/mutation_chance chance"""
dna_out = []
mutation_chance = 10
for i in range(dna_size):
if int(random.random()*mutation_chance) == 1:
dna_out.append(random_val(i, tune_params))
else:
dna_out.append(dna[i])... | python | def mutate(dna, dna_size, tune_params):
"""Mutate DNA with 1/mutation_chance chance"""
dna_out = []
mutation_chance = 10
for i in range(dna_size):
if int(random.random()*mutation_chance) == 1:
dna_out.append(random_val(i, tune_params))
else:
dna_out.append(dna[i])... | [
"def",
"mutate",
"(",
"dna",
",",
"dna_size",
",",
"tune_params",
")",
":",
"dna_out",
"=",
"[",
"]",
"mutation_chance",
"=",
"10",
"for",
"i",
"in",
"range",
"(",
"dna_size",
")",
":",
"if",
"int",
"(",
"random",
".",
"random",
"(",
")",
"*",
"mut... | Mutate DNA with 1/mutation_chance chance | [
"Mutate",
"DNA",
"with",
"1",
"/",
"mutation_chance",
"chance"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/strategies/genetic_algorithm.py#L100-L109 |
benvanwerkhoven/kernel_tuner | kernel_tuner/strategies/genetic_algorithm.py | crossover | def crossover(dna1, dna2):
"""crossover dna1 and dna2 at a random index"""
pos = int(random.random()*len(dna1))
if random.random() < 0.5:
return (dna1[:pos]+dna2[pos:], dna2[:pos]+dna1[pos:])
else:
return (dna2[:pos]+dna1[pos:], dna1[:pos]+dna2[pos:]) | python | def crossover(dna1, dna2):
"""crossover dna1 and dna2 at a random index"""
pos = int(random.random()*len(dna1))
if random.random() < 0.5:
return (dna1[:pos]+dna2[pos:], dna2[:pos]+dna1[pos:])
else:
return (dna2[:pos]+dna1[pos:], dna1[:pos]+dna2[pos:]) | [
"def",
"crossover",
"(",
"dna1",
",",
"dna2",
")",
":",
"pos",
"=",
"int",
"(",
"random",
".",
"random",
"(",
")",
"*",
"len",
"(",
"dna1",
")",
")",
"if",
"random",
".",
"random",
"(",
")",
"<",
"0.5",
":",
"return",
"(",
"dna1",
"[",
":",
"... | crossover dna1 and dna2 at a random index | [
"crossover",
"dna1",
"and",
"dna2",
"at",
"a",
"random",
"index"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/strategies/genetic_algorithm.py#L111-L117 |
benvanwerkhoven/kernel_tuner | kernel_tuner/strategies/minimize.py | tune | def tune(runner, kernel_options, device_options, tuning_options):
""" Find the best performing kernel configuration in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:type... | python | def tune(runner, kernel_options, device_options, tuning_options):
""" Find the best performing kernel configuration in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:type... | [
"def",
"tune",
"(",
"runner",
",",
"kernel_options",
",",
"device_options",
",",
"tuning_options",
")",
":",
"results",
"=",
"[",
"]",
"cache",
"=",
"{",
"}",
"method",
"=",
"tuning_options",
".",
"method",
"#scale variables in x to make 'eps' relevant for multiple ... | Find the best performing kernel configuration in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:type kernel_options: kernel_tuner.interface.Options
:param device_options... | [
"Find",
"the",
"best",
"performing",
"kernel",
"configuration",
"in",
"the",
"parameter",
"space"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/strategies/minimize.py#L10-L57 |
benvanwerkhoven/kernel_tuner | kernel_tuner/strategies/minimize.py | _cost_func | def _cost_func(x, kernel_options, tuning_options, runner, results, cache):
""" Cost function used by minimize """
error_time = 1e20
logging.debug('_cost_func called')
logging.debug('x: ' + str(x))
x_key = ",".join([str(i) for i in x])
if x_key in cache:
return cache[x_key]
#snap v... | python | def _cost_func(x, kernel_options, tuning_options, runner, results, cache):
""" Cost function used by minimize """
error_time = 1e20
logging.debug('_cost_func called')
logging.debug('x: ' + str(x))
x_key = ",".join([str(i) for i in x])
if x_key in cache:
return cache[x_key]
#snap v... | [
"def",
"_cost_func",
"(",
"x",
",",
"kernel_options",
",",
"tuning_options",
",",
"runner",
",",
"results",
",",
"cache",
")",
":",
"error_time",
"=",
"1e20",
"logging",
".",
"debug",
"(",
"'_cost_func called'",
")",
"logging",
".",
"debug",
"(",
"'x: '",
... | Cost function used by minimize | [
"Cost",
"function",
"used",
"by",
"minimize"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/strategies/minimize.py#L60-L103 |
benvanwerkhoven/kernel_tuner | kernel_tuner/strategies/minimize.py | get_bounds_x0_eps | def get_bounds_x0_eps(tuning_options):
"""compute bounds, x0 (the initial guess), and eps"""
values = tuning_options.tune_params.values()
if tuning_options.scaling:
#bounds = [(0, 1) for _ in values]
#x0 = [0.5 for _ in bounds]
eps = numpy.amin([1.0/len(v) for v in values])
... | python | def get_bounds_x0_eps(tuning_options):
"""compute bounds, x0 (the initial guess), and eps"""
values = tuning_options.tune_params.values()
if tuning_options.scaling:
#bounds = [(0, 1) for _ in values]
#x0 = [0.5 for _ in bounds]
eps = numpy.amin([1.0/len(v) for v in values])
... | [
"def",
"get_bounds_x0_eps",
"(",
"tuning_options",
")",
":",
"values",
"=",
"tuning_options",
".",
"tune_params",
".",
"values",
"(",
")",
"if",
"tuning_options",
".",
"scaling",
":",
"#bounds = [(0, 1) for _ in values]",
"#x0 = [0.5 for _ in bounds]",
"eps",
"=",
"nu... | compute bounds, x0 (the initial guess), and eps | [
"compute",
"bounds",
"x0",
"(",
"the",
"initial",
"guess",
")",
"and",
"eps"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/strategies/minimize.py#L107-L133 |
benvanwerkhoven/kernel_tuner | kernel_tuner/strategies/minimize.py | get_bounds | def get_bounds(tune_params):
""" create a bounds array from the tunable parameters """
bounds = []
for values in tune_params.values():
sorted_values = numpy.sort(values)
bounds.append((sorted_values[0], sorted_values[-1]))
return bounds | python | def get_bounds(tune_params):
""" create a bounds array from the tunable parameters """
bounds = []
for values in tune_params.values():
sorted_values = numpy.sort(values)
bounds.append((sorted_values[0], sorted_values[-1]))
return bounds | [
"def",
"get_bounds",
"(",
"tune_params",
")",
":",
"bounds",
"=",
"[",
"]",
"for",
"values",
"in",
"tune_params",
".",
"values",
"(",
")",
":",
"sorted_values",
"=",
"numpy",
".",
"sort",
"(",
"values",
")",
"bounds",
".",
"append",
"(",
"(",
"sorted_v... | create a bounds array from the tunable parameters | [
"create",
"a",
"bounds",
"array",
"from",
"the",
"tunable",
"parameters"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/strategies/minimize.py#L136-L142 |
benvanwerkhoven/kernel_tuner | kernel_tuner/strategies/minimize.py | setup_method_options | def setup_method_options(method, tuning_options):
""" prepare method specific options """
kwargs = {}
#pass size of parameter space as max iterations to methods that support it
#it seems not all methods iterpret this value in the same manner
maxiter = numpy.prod([len(v) for v in tuning_options.tune... | python | def setup_method_options(method, tuning_options):
""" prepare method specific options """
kwargs = {}
#pass size of parameter space as max iterations to methods that support it
#it seems not all methods iterpret this value in the same manner
maxiter = numpy.prod([len(v) for v in tuning_options.tune... | [
"def",
"setup_method_options",
"(",
"method",
",",
"tuning_options",
")",
":",
"kwargs",
"=",
"{",
"}",
"#pass size of parameter space as max iterations to methods that support it",
"#it seems not all methods iterpret this value in the same manner",
"maxiter",
"=",
"numpy",
".",
... | prepare method specific options | [
"prepare",
"method",
"specific",
"options"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/strategies/minimize.py#L154-L173 |
benvanwerkhoven/kernel_tuner | kernel_tuner/strategies/minimize.py | snap_to_nearest_config | def snap_to_nearest_config(x, tune_params):
"""helper func that for each param selects the closest actual value"""
params = []
for i, k in enumerate(tune_params.keys()):
values = numpy.array(tune_params[k])
idx = numpy.abs(values-x[i]).argmin()
params.append(int(values[idx]))
ret... | python | def snap_to_nearest_config(x, tune_params):
"""helper func that for each param selects the closest actual value"""
params = []
for i, k in enumerate(tune_params.keys()):
values = numpy.array(tune_params[k])
idx = numpy.abs(values-x[i]).argmin()
params.append(int(values[idx]))
ret... | [
"def",
"snap_to_nearest_config",
"(",
"x",
",",
"tune_params",
")",
":",
"params",
"=",
"[",
"]",
"for",
"i",
",",
"k",
"in",
"enumerate",
"(",
"tune_params",
".",
"keys",
"(",
")",
")",
":",
"values",
"=",
"numpy",
".",
"array",
"(",
"tune_params",
... | helper func that for each param selects the closest actual value | [
"helper",
"func",
"that",
"for",
"each",
"param",
"selects",
"the",
"closest",
"actual",
"value"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/strategies/minimize.py#L176-L183 |
benvanwerkhoven/kernel_tuner | kernel_tuner/strategies/minimize.py | unscale_and_snap_to_nearest | def unscale_and_snap_to_nearest(x, tune_params, eps):
"""helper func that snaps a scaled variable to the nearest config"""
x_u = [i for i in x]
for i, v in enumerate(tune_params.values()):
#create an evenly spaced linear space to map [0,1]-interval
#to actual values, giving each value an equ... | python | def unscale_and_snap_to_nearest(x, tune_params, eps):
"""helper func that snaps a scaled variable to the nearest config"""
x_u = [i for i in x]
for i, v in enumerate(tune_params.values()):
#create an evenly spaced linear space to map [0,1]-interval
#to actual values, giving each value an equ... | [
"def",
"unscale_and_snap_to_nearest",
"(",
"x",
",",
"tune_params",
",",
"eps",
")",
":",
"x_u",
"=",
"[",
"i",
"for",
"i",
"in",
"x",
"]",
"for",
"i",
",",
"v",
"in",
"enumerate",
"(",
"tune_params",
".",
"values",
"(",
")",
")",
":",
"#create an ev... | helper func that snaps a scaled variable to the nearest config | [
"helper",
"func",
"that",
"snaps",
"a",
"scaled",
"variable",
"to",
"the",
"nearest",
"config"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/strategies/minimize.py#L186-L204 |
benvanwerkhoven/kernel_tuner | kernel_tuner/runners/sequential.py | SequentialRunner.run | def run(self, parameter_space, kernel_options, tuning_options):
""" Iterate through the entire parameter space using a single Python process
:param parameter_space: The parameter space as an iterable.
:type parameter_space: iterable
:param kernel_options: A dictionary with all options ... | python | def run(self, parameter_space, kernel_options, tuning_options):
""" Iterate through the entire parameter space using a single Python process
:param parameter_space: The parameter space as an iterable.
:type parameter_space: iterable
:param kernel_options: A dictionary with all options ... | [
"def",
"run",
"(",
"self",
",",
"parameter_space",
",",
"kernel_options",
",",
"tuning_options",
")",
":",
"logging",
".",
"debug",
"(",
"'sequential runner started for '",
"+",
"kernel_options",
".",
"kernel_name",
")",
"results",
"=",
"[",
"]",
"#iterate over pa... | Iterate through the entire parameter space using a single Python process
:param parameter_space: The parameter space as an iterable.
:type parameter_space: iterable
:param kernel_options: A dictionary with all options for the kernel.
:type kernel_options: kernel_tuner.interface.Options... | [
"Iterate",
"through",
"the",
"entire",
"parameter",
"space",
"using",
"a",
"single",
"Python",
"process"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/runners/sequential.py#L38-L79 |
benvanwerkhoven/kernel_tuner | kernel_tuner/strategies/basinhopping.py | tune | def tune(runner, kernel_options, device_options, tuning_options):
""" Find the best performing kernel configuration in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:type... | python | def tune(runner, kernel_options, device_options, tuning_options):
""" Find the best performing kernel configuration in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:type... | [
"def",
"tune",
"(",
"runner",
",",
"kernel_options",
",",
"device_options",
",",
"tuning_options",
")",
":",
"results",
"=",
"[",
"]",
"cache",
"=",
"{",
"}",
"method",
"=",
"tuning_options",
".",
"method",
"#scale variables in x to make 'eps' relevant for multiple ... | Find the best performing kernel configuration in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:type kernel_options: dict
:param device_options: A dictionary with all op... | [
"Find",
"the",
"best",
"performing",
"kernel",
"configuration",
"in",
"the",
"parameter",
"space"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/strategies/basinhopping.py#L8-L57 |
benvanwerkhoven/kernel_tuner | examples/cuda/convolution_streams.py | allocate | def allocate(n, dtype=numpy.float32):
""" allocate context-portable pinned host memory """
return drv.pagelocked_empty(int(n), dtype, order='C', mem_flags=drv.host_alloc_flags.PORTABLE) | python | def allocate(n, dtype=numpy.float32):
""" allocate context-portable pinned host memory """
return drv.pagelocked_empty(int(n), dtype, order='C', mem_flags=drv.host_alloc_flags.PORTABLE) | [
"def",
"allocate",
"(",
"n",
",",
"dtype",
"=",
"numpy",
".",
"float32",
")",
":",
"return",
"drv",
".",
"pagelocked_empty",
"(",
"int",
"(",
"n",
")",
",",
"dtype",
",",
"order",
"=",
"'C'",
",",
"mem_flags",
"=",
"drv",
".",
"host_alloc_flags",
"."... | allocate context-portable pinned host memory | [
"allocate",
"context",
"-",
"portable",
"pinned",
"host",
"memory"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/examples/cuda/convolution_streams.py#L10-L12 |
benvanwerkhoven/kernel_tuner | kernel_tuner/cuda.py | CudaFunctions.ready_argument_list | def ready_argument_list(self, arguments):
"""ready argument list to be passed to the kernel, allocates gpu mem
:param arguments: List of arguments to be passed to the kernel.
The order should match the argument list on the CUDA kernel.
Allowed values are numpy.ndarray, and/or nu... | python | def ready_argument_list(self, arguments):
"""ready argument list to be passed to the kernel, allocates gpu mem
:param arguments: List of arguments to be passed to the kernel.
The order should match the argument list on the CUDA kernel.
Allowed values are numpy.ndarray, and/or nu... | [
"def",
"ready_argument_list",
"(",
"self",
",",
"arguments",
")",
":",
"gpu_args",
"=",
"[",
"]",
"for",
"arg",
"in",
"arguments",
":",
"# if arg i is a numpy array copy to device",
"if",
"isinstance",
"(",
"arg",
",",
"numpy",
".",
"ndarray",
")",
":",
"alloc... | ready argument list to be passed to the kernel, allocates gpu mem
:param arguments: List of arguments to be passed to the kernel.
The order should match the argument list on the CUDA kernel.
Allowed values are numpy.ndarray, and/or numpy.int32, numpy.float32, and so on.
:type ar... | [
"ready",
"argument",
"list",
"to",
"be",
"passed",
"to",
"the",
"kernel",
"allocates",
"gpu",
"mem"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/cuda.py#L85-L106 |
benvanwerkhoven/kernel_tuner | kernel_tuner/cuda.py | CudaFunctions.compile | def compile(self, kernel_name, kernel_string):
"""call the CUDA compiler to compile the kernel, return the device function
:param kernel_name: The name of the kernel to be compiled, used to lookup the
function after compilation.
:type kernel_name: string
:param kernel_strin... | python | def compile(self, kernel_name, kernel_string):
"""call the CUDA compiler to compile the kernel, return the device function
:param kernel_name: The name of the kernel to be compiled, used to lookup the
function after compilation.
:type kernel_name: string
:param kernel_strin... | [
"def",
"compile",
"(",
"self",
",",
"kernel_name",
",",
"kernel_string",
")",
":",
"try",
":",
"no_extern_c",
"=",
"'extern \"C\"'",
"in",
"kernel_string",
"compiler_options",
"=",
"[",
"'-Xcompiler=-Wall'",
"]",
"if",
"self",
".",
"compiler_options",
":",
"comp... | call the CUDA compiler to compile the kernel, return the device function
:param kernel_name: The name of the kernel to be compiled, used to lookup the
function after compilation.
:type kernel_name: string
:param kernel_string: The CUDA kernel code that contains the function `kernel... | [
"call",
"the",
"CUDA",
"compiler",
"to",
"compile",
"the",
"kernel",
"return",
"the",
"device",
"function"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/cuda.py#L109-L140 |
benvanwerkhoven/kernel_tuner | kernel_tuner/cuda.py | CudaFunctions.benchmark | def benchmark(self, func, gpu_args, threads, grid, times):
"""runs the kernel and measures time repeatedly, returns average time
Runs the kernel and measures kernel execution time repeatedly, number of
iterations is set during the creation of CudaFunctions. Benchmark returns
a robust av... | python | def benchmark(self, func, gpu_args, threads, grid, times):
"""runs the kernel and measures time repeatedly, returns average time
Runs the kernel and measures kernel execution time repeatedly, number of
iterations is set during the creation of CudaFunctions. Benchmark returns
a robust av... | [
"def",
"benchmark",
"(",
"self",
",",
"func",
",",
"gpu_args",
",",
"threads",
",",
"grid",
",",
"times",
")",
":",
"start",
"=",
"drv",
".",
"Event",
"(",
")",
"end",
"=",
"drv",
".",
"Event",
"(",
")",
"time",
"=",
"[",
"]",
"for",
"_",
"in",... | runs the kernel and measures time repeatedly, returns average time
Runs the kernel and measures kernel execution time repeatedly, number of
iterations is set during the creation of CudaFunctions. Benchmark returns
a robust average, from all measurements the fastest and slowest runs are
... | [
"runs",
"the",
"kernel",
"and",
"measures",
"time",
"repeatedly",
"returns",
"average",
"time"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/cuda.py#L143-L193 |
benvanwerkhoven/kernel_tuner | kernel_tuner/cuda.py | CudaFunctions.copy_constant_memory_args | def copy_constant_memory_args(self, cmem_args):
"""adds constant memory arguments to the most recently compiled module
:param cmem_args: A dictionary containing the data to be passed to the
device constant memory. The format to be used is as follows: A
string key is used to name... | python | def copy_constant_memory_args(self, cmem_args):
"""adds constant memory arguments to the most recently compiled module
:param cmem_args: A dictionary containing the data to be passed to the
device constant memory. The format to be used is as follows: A
string key is used to name... | [
"def",
"copy_constant_memory_args",
"(",
"self",
",",
"cmem_args",
")",
":",
"logging",
".",
"debug",
"(",
"'copy_constant_memory_args called'",
")",
"logging",
".",
"debug",
"(",
"'current module: '",
"+",
"str",
"(",
"self",
".",
"current_module",
")",
")",
"f... | adds constant memory arguments to the most recently compiled module
:param cmem_args: A dictionary containing the data to be passed to the
device constant memory. The format to be used is as follows: A
string key is used to name the constant memory symbol to which the
value ... | [
"adds",
"constant",
"memory",
"arguments",
"to",
"the",
"most",
"recently",
"compiled",
"module"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/cuda.py#L195-L214 |
benvanwerkhoven/kernel_tuner | kernel_tuner/cuda.py | CudaFunctions.copy_texture_memory_args | def copy_texture_memory_args(self, texmem_args):
"""adds texture memory arguments to the most recently compiled module
:param texmem_args: A dictionary containing the data to be passed to the
device texture memory. TODO
"""
filter_mode_map = { 'point': drv.filter_mode.POIN... | python | def copy_texture_memory_args(self, texmem_args):
"""adds texture memory arguments to the most recently compiled module
:param texmem_args: A dictionary containing the data to be passed to the
device texture memory. TODO
"""
filter_mode_map = { 'point': drv.filter_mode.POIN... | [
"def",
"copy_texture_memory_args",
"(",
"self",
",",
"texmem_args",
")",
":",
"filter_mode_map",
"=",
"{",
"'point'",
":",
"drv",
".",
"filter_mode",
".",
"POINT",
",",
"'linear'",
":",
"drv",
".",
"filter_mode",
".",
"LINEAR",
"}",
"address_mode_map",
"=",
... | adds texture memory arguments to the most recently compiled module
:param texmem_args: A dictionary containing the data to be passed to the
device texture memory. TODO | [
"adds",
"texture",
"memory",
"arguments",
"to",
"the",
"most",
"recently",
"compiled",
"module"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/cuda.py#L216-L269 |
benvanwerkhoven/kernel_tuner | kernel_tuner/cuda.py | CudaFunctions.run_kernel | def run_kernel(self, func, gpu_args, threads, grid):
"""runs the CUDA kernel passed as 'func'
:param func: A PyCuda kernel compiled for this specific kernel configuration
:type func: pycuda.driver.Function
:param gpu_args: A list of arguments to the kernel, order should match the
... | python | def run_kernel(self, func, gpu_args, threads, grid):
"""runs the CUDA kernel passed as 'func'
:param func: A PyCuda kernel compiled for this specific kernel configuration
:type func: pycuda.driver.Function
:param gpu_args: A list of arguments to the kernel, order should match the
... | [
"def",
"run_kernel",
"(",
"self",
",",
"func",
",",
"gpu_args",
",",
"threads",
",",
"grid",
")",
":",
"func",
"(",
"*",
"gpu_args",
",",
"block",
"=",
"threads",
",",
"grid",
"=",
"grid",
",",
"texrefs",
"=",
"self",
".",
"texrefs",
")"
] | runs the CUDA kernel passed as 'func'
:param func: A PyCuda kernel compiled for this specific kernel configuration
:type func: pycuda.driver.Function
:param gpu_args: A list of arguments to the kernel, order should match the
order in the code. Allowed values are either variables in... | [
"runs",
"the",
"CUDA",
"kernel",
"passed",
"as",
"func"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/cuda.py#L271-L290 |
benvanwerkhoven/kernel_tuner | kernel_tuner/cuda.py | CudaFunctions.memset | def memset(self, allocation, value, size):
"""set the memory in allocation to the value in value
:param allocation: A GPU memory allocation unit
:type allocation: pycuda.driver.DeviceAllocation
:param value: The value to set the memory to
:type value: a single 8-bit unsigned in... | python | def memset(self, allocation, value, size):
"""set the memory in allocation to the value in value
:param allocation: A GPU memory allocation unit
:type allocation: pycuda.driver.DeviceAllocation
:param value: The value to set the memory to
:type value: a single 8-bit unsigned in... | [
"def",
"memset",
"(",
"self",
",",
"allocation",
",",
"value",
",",
"size",
")",
":",
"drv",
".",
"memset_d8",
"(",
"allocation",
",",
"value",
",",
"size",
")"
] | set the memory in allocation to the value in value
:param allocation: A GPU memory allocation unit
:type allocation: pycuda.driver.DeviceAllocation
:param value: The value to set the memory to
:type value: a single 8-bit unsigned int
:param size: The size of to the allocation ... | [
"set",
"the",
"memory",
"in",
"allocation",
"to",
"the",
"value",
"in",
"value"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/cuda.py#L292-L305 |
benvanwerkhoven/kernel_tuner | kernel_tuner/cuda.py | CudaFunctions.memcpy_dtoh | def memcpy_dtoh(self, dest, src):
"""perform a device to host memory copy
:param dest: A numpy array in host memory to store the data
:type dest: numpy.ndarray
:param src: A GPU memory allocation unit
:type src: pycuda.driver.DeviceAllocation
"""
if isinstance(s... | python | def memcpy_dtoh(self, dest, src):
"""perform a device to host memory copy
:param dest: A numpy array in host memory to store the data
:type dest: numpy.ndarray
:param src: A GPU memory allocation unit
:type src: pycuda.driver.DeviceAllocation
"""
if isinstance(s... | [
"def",
"memcpy_dtoh",
"(",
"self",
",",
"dest",
",",
"src",
")",
":",
"if",
"isinstance",
"(",
"src",
",",
"drv",
".",
"DeviceAllocation",
")",
":",
"drv",
".",
"memcpy_dtoh",
"(",
"dest",
",",
"src",
")",
"else",
":",
"dest",
"=",
"src"
] | perform a device to host memory copy
:param dest: A numpy array in host memory to store the data
:type dest: numpy.ndarray
:param src: A GPU memory allocation unit
:type src: pycuda.driver.DeviceAllocation | [
"perform",
"a",
"device",
"to",
"host",
"memory",
"copy"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/cuda.py#L308-L320 |
benvanwerkhoven/kernel_tuner | kernel_tuner/cuda.py | CudaFunctions.memcpy_htod | def memcpy_htod(self, dest, src):
"""perform a host to device memory copy
:param dest: A GPU memory allocation unit
:type dest: pycuda.driver.DeviceAllocation
:param src: A numpy array in host memory to store the data
:type src: numpy.ndarray
"""
if isinstance(d... | python | def memcpy_htod(self, dest, src):
"""perform a host to device memory copy
:param dest: A GPU memory allocation unit
:type dest: pycuda.driver.DeviceAllocation
:param src: A numpy array in host memory to store the data
:type src: numpy.ndarray
"""
if isinstance(d... | [
"def",
"memcpy_htod",
"(",
"self",
",",
"dest",
",",
"src",
")",
":",
"if",
"isinstance",
"(",
"dest",
",",
"drv",
".",
"DeviceAllocation",
")",
":",
"drv",
".",
"memcpy_htod",
"(",
"dest",
",",
"src",
")",
"else",
":",
"dest",
"=",
"src"
] | perform a host to device memory copy
:param dest: A GPU memory allocation unit
:type dest: pycuda.driver.DeviceAllocation
:param src: A numpy array in host memory to store the data
:type src: numpy.ndarray | [
"perform",
"a",
"host",
"to",
"device",
"memory",
"copy"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/cuda.py#L322-L334 |
benvanwerkhoven/kernel_tuner | kernel_tuner/strategies/simulated_annealing.py | tune | def tune(runner, kernel_options, device_options, tuning_options):
""" Find the best performing kernel configuration in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:type... | python | def tune(runner, kernel_options, device_options, tuning_options):
""" Find the best performing kernel configuration in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:type... | [
"def",
"tune",
"(",
"runner",
",",
"kernel_options",
",",
"device_options",
",",
"tuning_options",
")",
":",
"results",
"=",
"[",
"]",
"cache",
"=",
"{",
"}",
"# SA works with real parameter values and does not need scaling",
"tuning_options",
"[",
"\"scaling\"",
"]",... | Find the best performing kernel configuration in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:type kernel_options: dict
:param device_options: A dictionary with all op... | [
"Find",
"the",
"best",
"performing",
"kernel",
"configuration",
"in",
"the",
"parameter",
"space"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/strategies/simulated_annealing.py#L10-L78 |
benvanwerkhoven/kernel_tuner | kernel_tuner/strategies/simulated_annealing.py | acceptance_prob | def acceptance_prob(old_cost, new_cost, T):
"""annealing equation, with modifications to work towards a lower value"""
#if start pos is not valid, always move
if old_cost == 1e20:
return 1.0
#if we have found a valid ps before, never move to nonvalid pos
if new_cost == 1e20:
return 0... | python | def acceptance_prob(old_cost, new_cost, T):
"""annealing equation, with modifications to work towards a lower value"""
#if start pos is not valid, always move
if old_cost == 1e20:
return 1.0
#if we have found a valid ps before, never move to nonvalid pos
if new_cost == 1e20:
return 0... | [
"def",
"acceptance_prob",
"(",
"old_cost",
",",
"new_cost",
",",
"T",
")",
":",
"#if start pos is not valid, always move",
"if",
"old_cost",
"==",
"1e20",
":",
"return",
"1.0",
"#if we have found a valid ps before, never move to nonvalid pos",
"if",
"new_cost",
"==",
"1e2... | annealing equation, with modifications to work towards a lower value | [
"annealing",
"equation",
"with",
"modifications",
"to",
"work",
"towards",
"a",
"lower",
"value"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/strategies/simulated_annealing.py#L80-L92 |
benvanwerkhoven/kernel_tuner | kernel_tuner/strategies/simulated_annealing.py | neighbor | def neighbor(pos, tune_params):
"""return a random neighbor of pos"""
size = len(pos)
pos_out = []
# random mutation
# expected value is set that values all dimensions attempt to get mutated
for i in range(size):
key = list(tune_params.keys())[i]
values = tune_params[key]
... | python | def neighbor(pos, tune_params):
"""return a random neighbor of pos"""
size = len(pos)
pos_out = []
# random mutation
# expected value is set that values all dimensions attempt to get mutated
for i in range(size):
key = list(tune_params.keys())[i]
values = tune_params[key]
... | [
"def",
"neighbor",
"(",
"pos",
",",
"tune_params",
")",
":",
"size",
"=",
"len",
"(",
"pos",
")",
"pos_out",
"=",
"[",
"]",
"# random mutation",
"# expected value is set that values all dimensions attempt to get mutated",
"for",
"i",
"in",
"range",
"(",
"size",
")... | return a random neighbor of pos | [
"return",
"a",
"random",
"neighbor",
"of",
"pos"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/strategies/simulated_annealing.py#L95-L117 |
benvanwerkhoven/kernel_tuner | kernel_tuner/strategies/brute_force.py | tune | def tune(runner, kernel_options, device_options, tuning_options):
""" Tune all instances in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:type kernel_options: kernel_tun... | python | def tune(runner, kernel_options, device_options, tuning_options):
""" Tune all instances in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:type kernel_options: kernel_tun... | [
"def",
"tune",
"(",
"runner",
",",
"kernel_options",
",",
"device_options",
",",
"tuning_options",
")",
":",
"tune_params",
"=",
"tuning_options",
".",
"tune_params",
"restrictions",
"=",
"tuning_options",
".",
"restrictions",
"verbose",
"=",
"tuning_options",
".",
... | Tune all instances in the parameter space
:params runner: A runner from kernel_tuner.runners
:type runner: kernel_tuner.runner
:param kernel_options: A dictionary with all options for the kernel.
:type kernel_options: kernel_tuner.interface.Options
:param device_options: A dictionary with all opt... | [
"Tune",
"all",
"instances",
"in",
"the",
"parameter",
"space"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/strategies/brute_force.py#L8-L45 |
benvanwerkhoven/kernel_tuner | kernel_tuner/wrappers.py | cpp | def cpp(function_name, kernel_source, args, convert_to_array=None):
""" Generate a wrapper to call C++ functions from Python
This function allows Kernel Tuner to call templated C++ functions
that use primitive data types (double, float, int, ...).
There is support to convert function arguments from pl... | python | def cpp(function_name, kernel_source, args, convert_to_array=None):
""" Generate a wrapper to call C++ functions from Python
This function allows Kernel Tuner to call templated C++ functions
that use primitive data types (double, float, int, ...).
There is support to convert function arguments from pl... | [
"def",
"cpp",
"(",
"function_name",
",",
"kernel_source",
",",
"args",
",",
"convert_to_array",
"=",
"None",
")",
":",
"if",
"convert_to_array",
"and",
"len",
"(",
"args",
")",
"!=",
"len",
"(",
"convert_to_array",
")",
":",
"raise",
"ValueError",
"(",
"\"... | Generate a wrapper to call C++ functions from Python
This function allows Kernel Tuner to call templated C++ functions
that use primitive data types (double, float, int, ...).
There is support to convert function arguments from plain pointers
to array references. If this is needed, there should be a T... | [
"Generate",
"a",
"wrapper",
"to",
"call",
"C",
"++",
"functions",
"from",
"Python"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/wrappers.py#L18-L119 |
benvanwerkhoven/kernel_tuner | kernel_tuner/c.py | CFunctions.ready_argument_list | def ready_argument_list(self, arguments):
"""ready argument list to be passed to the C function
:param arguments: List of arguments to be passed to the C function.
The order should match the argument list on the C function.
Allowed values are numpy.ndarray, and/or numpy.int32, n... | python | def ready_argument_list(self, arguments):
"""ready argument list to be passed to the C function
:param arguments: List of arguments to be passed to the C function.
The order should match the argument list on the C function.
Allowed values are numpy.ndarray, and/or numpy.int32, n... | [
"def",
"ready_argument_list",
"(",
"self",
",",
"arguments",
")",
":",
"ctype_args",
"=",
"[",
"None",
"for",
"_",
"in",
"arguments",
"]",
"for",
"i",
",",
"arg",
"in",
"enumerate",
"(",
"arguments",
")",
":",
"if",
"not",
"isinstance",
"(",
"arg",
","... | ready argument list to be passed to the C function
:param arguments: List of arguments to be passed to the C function.
The order should match the argument list on the C function.
Allowed values are numpy.ndarray, and/or numpy.int32, numpy.float32, and so on.
:type arguments: lis... | [
"ready",
"argument",
"list",
"to",
"be",
"passed",
"to",
"the",
"C",
"function"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/c.py#L72-L102 |
benvanwerkhoven/kernel_tuner | kernel_tuner/c.py | CFunctions.compile | def compile(self, kernel_name, kernel_string):
"""call the C compiler to compile the kernel, return the function
:param kernel_name: The name of the kernel to be compiled, used to lookup the
function after compilation.
:type kernel_name: string
:param kernel_string: The C c... | python | def compile(self, kernel_name, kernel_string):
"""call the C compiler to compile the kernel, return the function
:param kernel_name: The name of the kernel to be compiled, used to lookup the
function after compilation.
:type kernel_name: string
:param kernel_string: The C c... | [
"def",
"compile",
"(",
"self",
",",
"kernel_name",
",",
"kernel_string",
")",
":",
"logging",
".",
"debug",
"(",
"'compiling '",
"+",
"kernel_name",
")",
"if",
"self",
".",
"lib",
"!=",
"None",
":",
"self",
".",
"cleanup_lib",
"(",
")",
"compiler_options",... | call the C compiler to compile the kernel, return the function
:param kernel_name: The name of the kernel to be compiled, used to lookup the
function after compilation.
:type kernel_name: string
:param kernel_string: The C code that contains the function `kernel_name`
:type... | [
"call",
"the",
"C",
"compiler",
"to",
"compile",
"the",
"kernel",
"return",
"the",
"function"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/c.py#L104-L201 |
benvanwerkhoven/kernel_tuner | kernel_tuner/c.py | CFunctions.benchmark | def benchmark(self, func, c_args, threads, grid, times):
"""runs the kernel repeatedly, returns averaged returned value
The C function tuning is a little bit more flexible than direct CUDA
or OpenCL kernel tuning. The C function needs to measure time, or some
other quality metric you wi... | python | def benchmark(self, func, c_args, threads, grid, times):
"""runs the kernel repeatedly, returns averaged returned value
The C function tuning is a little bit more flexible than direct CUDA
or OpenCL kernel tuning. The C function needs to measure time, or some
other quality metric you wi... | [
"def",
"benchmark",
"(",
"self",
",",
"func",
",",
"c_args",
",",
"threads",
",",
"grid",
",",
"times",
")",
":",
"time",
"=",
"[",
"]",
"for",
"_",
"in",
"range",
"(",
"self",
".",
"iterations",
")",
":",
"value",
"=",
"self",
".",
"run_kernel",
... | runs the kernel repeatedly, returns averaged returned value
The C function tuning is a little bit more flexible than direct CUDA
or OpenCL kernel tuning. The C function needs to measure time, or some
other quality metric you wish to tune on, on its own and should
therefore return a sing... | [
"runs",
"the",
"kernel",
"repeatedly",
"returns",
"averaged",
"returned",
"value"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/c.py#L204-L264 |
benvanwerkhoven/kernel_tuner | kernel_tuner/c.py | CFunctions.run_kernel | def run_kernel(self, func, c_args, threads, grid):
"""runs the kernel once, returns whatever the kernel returns
:param func: A C function compiled for this specific configuration
:type func: ctypes._FuncPtr
:param c_args: A list of arguments to the function, order should match the
... | python | def run_kernel(self, func, c_args, threads, grid):
"""runs the kernel once, returns whatever the kernel returns
:param func: A C function compiled for this specific configuration
:type func: ctypes._FuncPtr
:param c_args: A list of arguments to the function, order should match the
... | [
"def",
"run_kernel",
"(",
"self",
",",
"func",
",",
"c_args",
",",
"threads",
",",
"grid",
")",
":",
"logging",
".",
"debug",
"(",
"\"run_kernel\"",
")",
"logging",
".",
"debug",
"(",
"\"arguments=\"",
"+",
"str",
"(",
"[",
"str",
"(",
"arg",
".",
"c... | runs the kernel once, returns whatever the kernel returns
:param func: A C function compiled for this specific configuration
:type func: ctypes._FuncPtr
:param c_args: A list of arguments to the function, order should match the
order in the code. The list should be prepared using
... | [
"runs",
"the",
"kernel",
"once",
"returns",
"whatever",
"the",
"kernel",
"returns"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/c.py#L267-L294 |
benvanwerkhoven/kernel_tuner | kernel_tuner/c.py | CFunctions.memset | def memset(self, allocation, value, size):
"""set the memory in allocation to the value in value
:param allocation: An Argument for some memory allocation unit
:type allocation: Argument
:param value: The value to set the memory to
:type value: a single 8-bit unsigned int
... | python | def memset(self, allocation, value, size):
"""set the memory in allocation to the value in value
:param allocation: An Argument for some memory allocation unit
:type allocation: Argument
:param value: The value to set the memory to
:type value: a single 8-bit unsigned int
... | [
"def",
"memset",
"(",
"self",
",",
"allocation",
",",
"value",
",",
"size",
")",
":",
"C",
".",
"memset",
"(",
"allocation",
".",
"ctypes",
",",
"value",
",",
"size",
")"
] | set the memory in allocation to the value in value
:param allocation: An Argument for some memory allocation unit
:type allocation: Argument
:param value: The value to set the memory to
:type value: a single 8-bit unsigned int
:param size: The size of to the allocation unit in... | [
"set",
"the",
"memory",
"in",
"allocation",
"to",
"the",
"value",
"in",
"value"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/c.py#L296-L308 |
benvanwerkhoven/kernel_tuner | kernel_tuner/c.py | CFunctions.cleanup_lib | def cleanup_lib(self):
""" unload the previously loaded shared library """
if not self.using_openmp:
#this if statement is necessary because shared libraries that use
#OpenMP will core dump when unloaded, this is a well-known issue with OpenMP
logging.debug('unloading... | python | def cleanup_lib(self):
""" unload the previously loaded shared library """
if not self.using_openmp:
#this if statement is necessary because shared libraries that use
#OpenMP will core dump when unloaded, this is a well-known issue with OpenMP
logging.debug('unloading... | [
"def",
"cleanup_lib",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"using_openmp",
":",
"#this if statement is necessary because shared libraries that use",
"#OpenMP will core dump when unloaded, this is a well-known issue with OpenMP",
"logging",
".",
"debug",
"(",
"'unloadi... | unload the previously loaded shared library | [
"unload",
"the",
"previously",
"loaded",
"shared",
"library"
] | train | https://github.com/benvanwerkhoven/kernel_tuner/blob/cfcb5da5e510db494f8219c22566ab65d5fcbd9f/kernel_tuner/c.py#L332-L338 |
pengutronix/aiohttp-json-rpc | examples/publish_subscribe_example.py | clock | def clock(rpc):
"""
This task runs forever and notifies all clients subscribed to
'clock' once a second.
"""
while True:
yield from rpc.notify('clock', str(datetime.datetime.now()))
yield from asyncio.sleep(1) | python | def clock(rpc):
"""
This task runs forever and notifies all clients subscribed to
'clock' once a second.
"""
while True:
yield from rpc.notify('clock', str(datetime.datetime.now()))
yield from asyncio.sleep(1) | [
"def",
"clock",
"(",
"rpc",
")",
":",
"while",
"True",
":",
"yield",
"from",
"rpc",
".",
"notify",
"(",
"'clock'",
",",
"str",
"(",
"datetime",
".",
"datetime",
".",
"now",
"(",
")",
")",
")",
"yield",
"from",
"asyncio",
".",
"sleep",
"(",
"1",
"... | This task runs forever and notifies all clients subscribed to
'clock' once a second. | [
"This",
"task",
"runs",
"forever",
"and",
"notifies",
"all",
"clients",
"subscribed",
"to",
"clock",
"once",
"a",
"second",
"."
] | train | https://github.com/pengutronix/aiohttp-json-rpc/blob/24ec9ae9ae0633b2deaae7e29f6056f150cb4025/examples/publish_subscribe_example.py#L12-L20 |
pengutronix/aiohttp-json-rpc | aiohttp_json_rpc/django/__init__.py | patch_db_connections | def patch_db_connections():
"""
This wraps django.db.connections._connections with a TaskLocal object.
The Django transactions are only thread-safe, using threading.local,
and don't know about coroutines.
"""
global __already_patched
if not __already_patched:
from django.db import... | python | def patch_db_connections():
"""
This wraps django.db.connections._connections with a TaskLocal object.
The Django transactions are only thread-safe, using threading.local,
and don't know about coroutines.
"""
global __already_patched
if not __already_patched:
from django.db import... | [
"def",
"patch_db_connections",
"(",
")",
":",
"global",
"__already_patched",
"if",
"not",
"__already_patched",
":",
"from",
"django",
".",
"db",
"import",
"connections",
"connections",
".",
"_connections",
"=",
"local",
"(",
"connections",
".",
"_connections",
")"... | This wraps django.db.connections._connections with a TaskLocal object.
The Django transactions are only thread-safe, using threading.local,
and don't know about coroutines. | [
"This",
"wraps",
"django",
".",
"db",
".",
"connections",
".",
"_connections",
"with",
"a",
"TaskLocal",
"object",
"."
] | train | https://github.com/pengutronix/aiohttp-json-rpc/blob/24ec9ae9ae0633b2deaae7e29f6056f150cb4025/aiohttp_json_rpc/django/__init__.py#L42-L56 |
pengutronix/aiohttp-json-rpc | aiohttp_json_rpc/protocol.py | decode_msg | def decode_msg(raw_msg):
"""
Decodes jsonrpc 2.0 raw message objects into JsonRpcMsg objects.
Examples:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "subtract",
"params": [42, 23]
}
Notification:
... | python | def decode_msg(raw_msg):
"""
Decodes jsonrpc 2.0 raw message objects into JsonRpcMsg objects.
Examples:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "subtract",
"params": [42, 23]
}
Notification:
... | [
"def",
"decode_msg",
"(",
"raw_msg",
")",
":",
"try",
":",
"msg_data",
"=",
"json",
".",
"loads",
"(",
"raw_msg",
")",
"except",
"ValueError",
":",
"raise",
"RpcParseError",
"# check jsonrpc version",
"if",
"'jsonrpc'",
"not",
"in",
"msg_data",
"or",
"not",
... | Decodes jsonrpc 2.0 raw message objects into JsonRpcMsg objects.
Examples:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "subtract",
"params": [42, 23]
}
Notification:
{
"jsonrpc":... | [
"Decodes",
"jsonrpc",
"2",
".",
"0",
"raw",
"message",
"objects",
"into",
"JsonRpcMsg",
"objects",
"."
] | train | https://github.com/pengutronix/aiohttp-json-rpc/blob/24ec9ae9ae0633b2deaae7e29f6056f150cb4025/aiohttp_json_rpc/protocol.py#L23-L131 |
maciej-gol/tenant-schemas-celery | tenant_schemas_celery/app.py | switch_schema | def switch_schema(task, kwargs, **kw):
""" Switches schema of the task, before it has been run. """
# Lazily load needed functions, as they import django model functions which
# in turn load modules that need settings to be loaded and we can't
# guarantee this module was loaded when the settings were re... | python | def switch_schema(task, kwargs, **kw):
""" Switches schema of the task, before it has been run. """
# Lazily load needed functions, as they import django model functions which
# in turn load modules that need settings to be loaded and we can't
# guarantee this module was loaded when the settings were re... | [
"def",
"switch_schema",
"(",
"task",
",",
"kwargs",
",",
"*",
"*",
"kw",
")",
":",
"# Lazily load needed functions, as they import django model functions which",
"# in turn load modules that need settings to be loaded and we can't",
"# guarantee this module was loaded when the settings w... | Switches schema of the task, before it has been run. | [
"Switches",
"schema",
"of",
"the",
"task",
"before",
"it",
"has",
"been",
"run",
"."
] | train | https://github.com/maciej-gol/tenant-schemas-celery/blob/277ad98a756826d0fe311b9be6870988de3cd661/tenant_schemas_celery/app.py#L25-L51 |
maciej-gol/tenant-schemas-celery | tenant_schemas_celery/app.py | restore_schema | def restore_schema(task, **kwargs):
""" Switches the schema back to the one from before running the task. """
from .compat import get_public_schema_name
schema_name = get_public_schema_name()
include_public = True
if hasattr(task, '_old_schema'):
schema_name, include_public = task._old_sch... | python | def restore_schema(task, **kwargs):
""" Switches the schema back to the one from before running the task. """
from .compat import get_public_schema_name
schema_name = get_public_schema_name()
include_public = True
if hasattr(task, '_old_schema'):
schema_name, include_public = task._old_sch... | [
"def",
"restore_schema",
"(",
"task",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
".",
"compat",
"import",
"get_public_schema_name",
"schema_name",
"=",
"get_public_schema_name",
"(",
")",
"include_public",
"=",
"True",
"if",
"hasattr",
"(",
"task",
",",
"'_old... | Switches the schema back to the one from before running the task. | [
"Switches",
"the",
"schema",
"back",
"to",
"the",
"one",
"from",
"before",
"running",
"the",
"task",
"."
] | train | https://github.com/maciej-gol/tenant-schemas-celery/blob/277ad98a756826d0fe311b9be6870988de3cd661/tenant_schemas_celery/app.py#L54-L68 |
GiulioRossetti/dynetx | dynetx/readwrite/json_graph/node_link.py | node_link_data | def node_link_data(G, attrs=_attrs):
"""Return data in node-link format that is suitable for JSON serialization
and use in Javascript documents.
Parameters
----------
G : DyNetx graph
attrs : dict
A dictionary that contains three keys 'id', 'source' and 'target'.
The correspon... | python | def node_link_data(G, attrs=_attrs):
"""Return data in node-link format that is suitable for JSON serialization
and use in Javascript documents.
Parameters
----------
G : DyNetx graph
attrs : dict
A dictionary that contains three keys 'id', 'source' and 'target'.
The correspon... | [
"def",
"node_link_data",
"(",
"G",
",",
"attrs",
"=",
"_attrs",
")",
":",
"id_",
"=",
"attrs",
"[",
"'id'",
"]",
"data",
"=",
"{",
"}",
"data",
"[",
"'directed'",
"]",
"=",
"G",
".",
"is_directed",
"(",
")",
"data",
"[",
"'graph'",
"]",
"=",
"G",... | Return data in node-link format that is suitable for JSON serialization
and use in Javascript documents.
Parameters
----------
G : DyNetx graph
attrs : dict
A dictionary that contains three keys 'id', 'source' and 'target'.
The corresponding values provide the attribute names for ... | [
"Return",
"data",
"in",
"node",
"-",
"link",
"format",
"that",
"is",
"suitable",
"for",
"JSON",
"serialization",
"and",
"use",
"in",
"Javascript",
"documents",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/readwrite/json_graph/node_link.py#L10-L63 |
GiulioRossetti/dynetx | dynetx/readwrite/json_graph/node_link.py | node_link_graph | def node_link_graph(data, directed=False, attrs=_attrs):
"""Return graph from node-link data format.
Parameters
----------
data : dict
node-link formatted graph data
directed : bool
If True, and direction not specified in data, return a directed graph.
attrs : dict
A d... | python | def node_link_graph(data, directed=False, attrs=_attrs):
"""Return graph from node-link data format.
Parameters
----------
data : dict
node-link formatted graph data
directed : bool
If True, and direction not specified in data, return a directed graph.
attrs : dict
A d... | [
"def",
"node_link_graph",
"(",
"data",
",",
"directed",
"=",
"False",
",",
"attrs",
"=",
"_attrs",
")",
":",
"directed",
"=",
"data",
".",
"get",
"(",
"'directed'",
",",
"directed",
")",
"graph",
"=",
"dn",
".",
"DynGraph",
"(",
")",
"if",
"directed",
... | Return graph from node-link data format.
Parameters
----------
data : dict
node-link formatted graph data
directed : bool
If True, and direction not specified in data, return a directed graph.
attrs : dict
A dictionary that contains three keys 'id', 'source', 'target'.
... | [
"Return",
"graph",
"from",
"node",
"-",
"link",
"data",
"format",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/readwrite/json_graph/node_link.py#L66-L117 |
GiulioRossetti/dynetx | dynetx/utils/transform.py | compact_timeslot | def compact_timeslot(sind_list):
"""
Test method. Compact all snapshots into a single one.
:param sind_list:
:return:
"""
tls = sorted(sind_list)
conversion = {val: idx for idx, val in enumerate(tls)}
return conversion | python | def compact_timeslot(sind_list):
"""
Test method. Compact all snapshots into a single one.
:param sind_list:
:return:
"""
tls = sorted(sind_list)
conversion = {val: idx for idx, val in enumerate(tls)}
return conversion | [
"def",
"compact_timeslot",
"(",
"sind_list",
")",
":",
"tls",
"=",
"sorted",
"(",
"sind_list",
")",
"conversion",
"=",
"{",
"val",
":",
"idx",
"for",
"idx",
",",
"val",
"in",
"enumerate",
"(",
"tls",
")",
"}",
"return",
"conversion"
] | Test method. Compact all snapshots into a single one.
:param sind_list:
:return: | [
"Test",
"method",
".",
"Compact",
"all",
"snapshots",
"into",
"a",
"single",
"one",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/utils/transform.py#L11-L20 |
GiulioRossetti/dynetx | dynetx/classes/dyngraph.py | DynGraph.nodes_iter | def nodes_iter(self, t=None, data=False):
"""Return an iterator over the nodes with respect to a given temporal snapshot.
Parameters
----------
t : snapshot id (default=None).
If None the iterator returns all the nodes of the flattened graph.
data : boolean, optional... | python | def nodes_iter(self, t=None, data=False):
"""Return an iterator over the nodes with respect to a given temporal snapshot.
Parameters
----------
t : snapshot id (default=None).
If None the iterator returns all the nodes of the flattened graph.
data : boolean, optional... | [
"def",
"nodes_iter",
"(",
"self",
",",
"t",
"=",
"None",
",",
"data",
"=",
"False",
")",
":",
"if",
"t",
"is",
"not",
"None",
":",
"return",
"iter",
"(",
"[",
"n",
"for",
"n",
"in",
"self",
".",
"degree",
"(",
"t",
"=",
"t",
")",
".",
"values... | Return an iterator over the nodes with respect to a given temporal snapshot.
Parameters
----------
t : snapshot id (default=None).
If None the iterator returns all the nodes of the flattened graph.
data : boolean, optional (default=False)
If False the iterator... | [
"Return",
"an",
"iterator",
"over",
"the",
"nodes",
"with",
"respect",
"to",
"a",
"given",
"temporal",
"snapshot",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyngraph.py#L124-L151 |
GiulioRossetti/dynetx | dynetx/classes/dyngraph.py | DynGraph.nodes | def nodes(self, t=None, data=False):
"""Return a list of the nodes in the graph at a given snapshot.
Parameters
----------
t : snapshot id (default=None)
If None the the method returns all the nodes of the flattened graph.
data : boolean, optional (default=False)
... | python | def nodes(self, t=None, data=False):
"""Return a list of the nodes in the graph at a given snapshot.
Parameters
----------
t : snapshot id (default=None)
If None the the method returns all the nodes of the flattened graph.
data : boolean, optional (default=False)
... | [
"def",
"nodes",
"(",
"self",
",",
"t",
"=",
"None",
",",
"data",
"=",
"False",
")",
":",
"return",
"list",
"(",
"self",
".",
"nodes_iter",
"(",
"t",
"=",
"t",
",",
"data",
"=",
"data",
")",
")"
] | Return a list of the nodes in the graph at a given snapshot.
Parameters
----------
t : snapshot id (default=None)
If None the the method returns all the nodes of the flattened graph.
data : boolean, optional (default=False)
If False return a list of nodes. If... | [
"Return",
"a",
"list",
"of",
"the",
"nodes",
"in",
"the",
"graph",
"at",
"a",
"given",
"snapshot",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyngraph.py#L153-L180 |
GiulioRossetti/dynetx | dynetx/classes/dyngraph.py | DynGraph.interactions_iter | def interactions_iter(self, nbunch=None, t=None):
"""Return an iterator over the interaction present in a given snapshot.
Edges are returned as tuples
in the order (node, neighbor).
Parameters
----------
nbunch : iterable container, optional (default= all nodes)
... | python | def interactions_iter(self, nbunch=None, t=None):
"""Return an iterator over the interaction present in a given snapshot.
Edges are returned as tuples
in the order (node, neighbor).
Parameters
----------
nbunch : iterable container, optional (default= all nodes)
... | [
"def",
"interactions_iter",
"(",
"self",
",",
"nbunch",
"=",
"None",
",",
"t",
"=",
"None",
")",
":",
"seen",
"=",
"{",
"}",
"# helper dict to keep track of multiply stored interactions",
"if",
"nbunch",
"is",
"None",
":",
"nodes_nbrs",
"=",
"self",
".",
"_adj... | Return an iterator over the interaction present in a given snapshot.
Edges are returned as tuples
in the order (node, neighbor).
Parameters
----------
nbunch : iterable container, optional (default= all nodes)
A container of nodes. The container will be iterated
... | [
"Return",
"an",
"iterator",
"over",
"the",
"interaction",
"present",
"in",
"a",
"given",
"snapshot",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyngraph.py#L238-L291 |
GiulioRossetti/dynetx | dynetx/classes/dyngraph.py | DynGraph.add_interaction | def add_interaction(self, u, v, t=None, e=None):
"""Add an interaction between u and v at time t vanishing (optional) at time e.
The nodes u and v will be automatically added if they are
not already in the graph.
Parameters
----------
u, v : nodes
Nodes can ... | python | def add_interaction(self, u, v, t=None, e=None):
"""Add an interaction between u and v at time t vanishing (optional) at time e.
The nodes u and v will be automatically added if they are
not already in the graph.
Parameters
----------
u, v : nodes
Nodes can ... | [
"def",
"add_interaction",
"(",
"self",
",",
"u",
",",
"v",
",",
"t",
"=",
"None",
",",
"e",
"=",
"None",
")",
":",
"if",
"t",
"is",
"None",
":",
"raise",
"nx",
".",
"NetworkXError",
"(",
"\"The t argument must be specified.\"",
")",
"if",
"u",
"not",
... | Add an interaction between u and v at time t vanishing (optional) at time e.
The nodes u and v will be automatically added if they are
not already in the graph.
Parameters
----------
u, v : nodes
Nodes can be, for example, strings or numbers.
Nodes must ... | [
"Add",
"an",
"interaction",
"between",
"u",
"and",
"v",
"at",
"time",
"t",
"vanishing",
"(",
"optional",
")",
"at",
"time",
"e",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyngraph.py#L293-L419 |
GiulioRossetti/dynetx | dynetx/classes/dyngraph.py | DynGraph.add_interactions_from | def add_interactions_from(self, ebunch, t=None, e=None):
"""Add all the interaction in ebunch at time t.
Parameters
----------
ebunch : container of interaction
Each interaction given in the container will be added to the
graph. The interaction must be given as a... | python | def add_interactions_from(self, ebunch, t=None, e=None):
"""Add all the interaction in ebunch at time t.
Parameters
----------
ebunch : container of interaction
Each interaction given in the container will be added to the
graph. The interaction must be given as a... | [
"def",
"add_interactions_from",
"(",
"self",
",",
"ebunch",
",",
"t",
"=",
"None",
",",
"e",
"=",
"None",
")",
":",
"# set up attribute dict",
"if",
"t",
"is",
"None",
":",
"raise",
"nx",
".",
"NetworkXError",
"(",
"\"The t argument must be a specified.\"",
")... | Add all the interaction in ebunch at time t.
Parameters
----------
ebunch : container of interaction
Each interaction given in the container will be added to the
graph. The interaction must be given as as 2-tuples (u,v) or
3-tuples (u,v,d) where d is a dictio... | [
"Add",
"all",
"the",
"interaction",
"in",
"ebunch",
"at",
"time",
"t",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyngraph.py#L421-L449 |
GiulioRossetti/dynetx | dynetx/classes/dyngraph.py | DynGraph.neighbors | def neighbors(self, n, t=None):
"""Return a list of the nodes connected to the node n at time t.
Parameters
----------
n : node
A node in the graph
t : snapshot id (default=None)
If None will be returned the neighbors of the node on the flattened graph.
... | python | def neighbors(self, n, t=None):
"""Return a list of the nodes connected to the node n at time t.
Parameters
----------
n : node
A node in the graph
t : snapshot id (default=None)
If None will be returned the neighbors of the node on the flattened graph.
... | [
"def",
"neighbors",
"(",
"self",
",",
"n",
",",
"t",
"=",
"None",
")",
":",
"try",
":",
"if",
"t",
"is",
"None",
":",
"return",
"list",
"(",
"self",
".",
"_adj",
"[",
"n",
"]",
")",
"else",
":",
"return",
"[",
"i",
"for",
"i",
"in",
"self",
... | Return a list of the nodes connected to the node n at time t.
Parameters
----------
n : node
A node in the graph
t : snapshot id (default=None)
If None will be returned the neighbors of the node on the flattened graph.
Returns
-------
nli... | [
"Return",
"a",
"list",
"of",
"the",
"nodes",
"connected",
"to",
"the",
"node",
"n",
"at",
"time",
"t",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyngraph.py#L539-L575 |
GiulioRossetti/dynetx | dynetx/classes/dyngraph.py | DynGraph.neighbors_iter | def neighbors_iter(self, n, t=None):
"""Return an iterator over all neighbors of node n at time t.
Parameters
----------
n : node
A node in the graph
t : snapshot id (default=None)
If None will be returned an iterator over the neighbors of the node on the ... | python | def neighbors_iter(self, n, t=None):
"""Return an iterator over all neighbors of node n at time t.
Parameters
----------
n : node
A node in the graph
t : snapshot id (default=None)
If None will be returned an iterator over the neighbors of the node on the ... | [
"def",
"neighbors_iter",
"(",
"self",
",",
"n",
",",
"t",
"=",
"None",
")",
":",
"try",
":",
"if",
"t",
"is",
"None",
":",
"return",
"iter",
"(",
"self",
".",
"_adj",
"[",
"n",
"]",
")",
"else",
":",
"return",
"iter",
"(",
"[",
"i",
"for",
"i... | Return an iterator over all neighbors of node n at time t.
Parameters
----------
n : node
A node in the graph
t : snapshot id (default=None)
If None will be returned an iterator over the neighbors of the node on the flattened graph.
Examples
-----... | [
"Return",
"an",
"iterator",
"over",
"all",
"neighbors",
"of",
"node",
"n",
"at",
"time",
"t",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyngraph.py#L577-L600 |
GiulioRossetti/dynetx | dynetx/classes/dyngraph.py | DynGraph.degree | def degree(self, nbunch=None, t=None):
"""Return the degree of a node or nodes at time t.
The node degree is the number of interaction adjacent to that node in a given time frame.
Parameters
----------
nbunch : iterable container, optional (default=all nodes)
A cont... | python | def degree(self, nbunch=None, t=None):
"""Return the degree of a node or nodes at time t.
The node degree is the number of interaction adjacent to that node in a given time frame.
Parameters
----------
nbunch : iterable container, optional (default=all nodes)
A cont... | [
"def",
"degree",
"(",
"self",
",",
"nbunch",
"=",
"None",
",",
"t",
"=",
"None",
")",
":",
"if",
"nbunch",
"in",
"self",
":",
"# return a single node",
"return",
"next",
"(",
"self",
".",
"degree_iter",
"(",
"nbunch",
",",
"t",
")",
")",
"[",
"1",
... | Return the degree of a node or nodes at time t.
The node degree is the number of interaction adjacent to that node in a given time frame.
Parameters
----------
nbunch : iterable container, optional (default=all nodes)
A container of nodes. The container will be iterated
... | [
"Return",
"the",
"degree",
"of",
"a",
"node",
"or",
"nodes",
"at",
"time",
"t",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyngraph.py#L602-L637 |
GiulioRossetti/dynetx | dynetx/classes/dyngraph.py | DynGraph.degree_iter | def degree_iter(self, nbunch=None, t=None):
"""Return an iterator for (node, degree) at time t.
The node degree is the number of edges adjacent to the node in a given timeframe.
Parameters
----------
nbunch : iterable container, optional (default=all nodes)
A contai... | python | def degree_iter(self, nbunch=None, t=None):
"""Return an iterator for (node, degree) at time t.
The node degree is the number of edges adjacent to the node in a given timeframe.
Parameters
----------
nbunch : iterable container, optional (default=all nodes)
A contai... | [
"def",
"degree_iter",
"(",
"self",
",",
"nbunch",
"=",
"None",
",",
"t",
"=",
"None",
")",
":",
"if",
"nbunch",
"is",
"None",
":",
"nodes_nbrs",
"=",
"self",
".",
"_adj",
".",
"items",
"(",
")",
"else",
":",
"nodes_nbrs",
"=",
"(",
"(",
"n",
",",... | Return an iterator for (node, degree) at time t.
The node degree is the number of edges adjacent to the node in a given timeframe.
Parameters
----------
nbunch : iterable container, optional (default=all nodes)
A container of nodes. The container will be iterated
... | [
"Return",
"an",
"iterator",
"for",
"(",
"node",
"degree",
")",
"at",
"time",
"t",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyngraph.py#L639-L687 |
GiulioRossetti/dynetx | dynetx/classes/dyngraph.py | DynGraph.size | def size(self, t=None):
"""Return the number of edges at time t.
Parameters
----------
t : snapshot id (default=None)
If None will be returned the size of the flattened graph.
Returns
-------
nedges : int
The number of edges
See... | python | def size(self, t=None):
"""Return the number of edges at time t.
Parameters
----------
t : snapshot id (default=None)
If None will be returned the size of the flattened graph.
Returns
-------
nedges : int
The number of edges
See... | [
"def",
"size",
"(",
"self",
",",
"t",
"=",
"None",
")",
":",
"s",
"=",
"sum",
"(",
"self",
".",
"degree",
"(",
"t",
"=",
"t",
")",
".",
"values",
"(",
")",
")",
"/",
"2",
"return",
"int",
"(",
"s",
")"
] | Return the number of edges at time t.
Parameters
----------
t : snapshot id (default=None)
If None will be returned the size of the flattened graph.
Returns
-------
nedges : int
The number of edges
See Also
--------
numb... | [
"Return",
"the",
"number",
"of",
"edges",
"at",
"time",
"t",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyngraph.py#L689-L715 |
GiulioRossetti/dynetx | dynetx/classes/dyngraph.py | DynGraph.number_of_nodes | def number_of_nodes(self, t=None):
"""Return the number of nodes in the t snpashot of a dynamic graph.
Parameters
----------
t : snapshot id (default=None)
If None return the number of nodes in the flattened graph.
Returns
-------
nnodes : int
... | python | def number_of_nodes(self, t=None):
"""Return the number of nodes in the t snpashot of a dynamic graph.
Parameters
----------
t : snapshot id (default=None)
If None return the number of nodes in the flattened graph.
Returns
-------
nnodes : int
... | [
"def",
"number_of_nodes",
"(",
"self",
",",
"t",
"=",
"None",
")",
":",
"if",
"t",
"is",
"None",
":",
"return",
"len",
"(",
"self",
".",
"_node",
")",
"else",
":",
"nds",
"=",
"sum",
"(",
"[",
"1",
"for",
"n",
"in",
"self",
".",
"degree",
"(",
... | Return the number of nodes in the t snpashot of a dynamic graph.
Parameters
----------
t : snapshot id (default=None)
If None return the number of nodes in the flattened graph.
Returns
-------
nnodes : int
The number of nodes in the graph.
... | [
"Return",
"the",
"number",
"of",
"nodes",
"in",
"the",
"t",
"snpashot",
"of",
"a",
"dynamic",
"graph",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyngraph.py#L717-L746 |
GiulioRossetti/dynetx | dynetx/classes/dyngraph.py | DynGraph.has_node | def has_node(self, n, t=None):
"""Return True if the graph, at time t, contains the node n.
Parameters
----------
n : node
t : snapshot id (default None)
If None return the presence of the node in the flattened graph.
Examples
--------
>>... | python | def has_node(self, n, t=None):
"""Return True if the graph, at time t, contains the node n.
Parameters
----------
n : node
t : snapshot id (default None)
If None return the presence of the node in the flattened graph.
Examples
--------
>>... | [
"def",
"has_node",
"(",
"self",
",",
"n",
",",
"t",
"=",
"None",
")",
":",
"if",
"t",
"is",
"None",
":",
"try",
":",
"return",
"n",
"in",
"self",
".",
"_node",
"except",
"TypeError",
":",
"return",
"False",
"else",
":",
"deg",
"=",
"list",
"(",
... | Return True if the graph, at time t, contains the node n.
Parameters
----------
n : node
t : snapshot id (default None)
If None return the presence of the node in the flattened graph.
Examples
--------
>>> G = dn.DynGraph() # or DiGraph, MultiG... | [
"Return",
"True",
"if",
"the",
"graph",
"at",
"time",
"t",
"contains",
"the",
"node",
"n",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyngraph.py#L775-L807 |
GiulioRossetti/dynetx | dynetx/classes/dyngraph.py | DynGraph.add_star | def add_star(self, nodes, t=None):
"""Add a star at time t.
The first node in nodes is the middle of the star. It is connected
to all other nodes.
Parameters
----------
nodes : iterable container
A container of nodes.
t : snapshot id (default=None)
... | python | def add_star(self, nodes, t=None):
"""Add a star at time t.
The first node in nodes is the middle of the star. It is connected
to all other nodes.
Parameters
----------
nodes : iterable container
A container of nodes.
t : snapshot id (default=None)
... | [
"def",
"add_star",
"(",
"self",
",",
"nodes",
",",
"t",
"=",
"None",
")",
":",
"nlist",
"=",
"list",
"(",
"nodes",
")",
"v",
"=",
"nlist",
"[",
"0",
"]",
"interaction",
"=",
"(",
"(",
"v",
",",
"n",
")",
"for",
"n",
"in",
"nlist",
"[",
"1",
... | Add a star at time t.
The first node in nodes is the middle of the star. It is connected
to all other nodes.
Parameters
----------
nodes : iterable container
A container of nodes.
t : snapshot id (default=None)
See Also
--------
add... | [
"Add",
"a",
"star",
"at",
"time",
"t",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyngraph.py#L809-L833 |
GiulioRossetti/dynetx | dynetx/classes/dyngraph.py | DynGraph.add_path | def add_path(self, nodes, t=None):
"""Add a path at time t.
Parameters
----------
nodes : iterable container
A container of nodes.
t : snapshot id (default=None)
See Also
--------
add_path, add_cycle
Examples
--------
... | python | def add_path(self, nodes, t=None):
"""Add a path at time t.
Parameters
----------
nodes : iterable container
A container of nodes.
t : snapshot id (default=None)
See Also
--------
add_path, add_cycle
Examples
--------
... | [
"def",
"add_path",
"(",
"self",
",",
"nodes",
",",
"t",
"=",
"None",
")",
":",
"nlist",
"=",
"list",
"(",
"nodes",
")",
"interaction",
"=",
"zip",
"(",
"nlist",
"[",
":",
"-",
"1",
"]",
",",
"nlist",
"[",
"1",
":",
"]",
")",
"self",
".",
"add... | Add a path at time t.
Parameters
----------
nodes : iterable container
A container of nodes.
t : snapshot id (default=None)
See Also
--------
add_path, add_cycle
Examples
--------
>>> G = dn.DynGraph()
>>> G.add_path(... | [
"Add",
"a",
"path",
"at",
"time",
"t",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyngraph.py#L835-L855 |
GiulioRossetti/dynetx | dynetx/classes/dyngraph.py | DynGraph.to_directed | def to_directed(self):
"""Return a directed representation of the graph.
Returns
-------
G : DynDiGraph
A dynamic directed graph with the same name, same nodes, and with
each edge (u,v,data) replaced by two directed edges
(u,v,data) and (v,u,data).
... | python | def to_directed(self):
"""Return a directed representation of the graph.
Returns
-------
G : DynDiGraph
A dynamic directed graph with the same name, same nodes, and with
each edge (u,v,data) replaced by two directed edges
(u,v,data) and (v,u,data).
... | [
"def",
"to_directed",
"(",
"self",
")",
":",
"from",
".",
"dyndigraph",
"import",
"DynDiGraph",
"G",
"=",
"DynDiGraph",
"(",
")",
"G",
".",
"name",
"=",
"self",
".",
"name",
"G",
".",
"add_nodes_from",
"(",
"self",
")",
"for",
"it",
"in",
"self",
"."... | Return a directed representation of the graph.
Returns
-------
G : DynDiGraph
A dynamic directed graph with the same name, same nodes, and with
each edge (u,v,data) replaced by two directed edges
(u,v,data) and (v,u,data).
Notes
-----
... | [
"Return",
"a",
"directed",
"representation",
"of",
"the",
"graph",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyngraph.py#L879-L931 |
GiulioRossetti/dynetx | dynetx/classes/dyngraph.py | DynGraph.stream_interactions | def stream_interactions(self):
"""Generate a temporal ordered stream of interactions.
Returns
-------
nd_iter : an iterator
The iterator returns a 4-tuples of (node, node, op, timestamp).
Examples
--------
>>> G = dn.DynGraph()
>>> G.add_pat... | python | def stream_interactions(self):
"""Generate a temporal ordered stream of interactions.
Returns
-------
nd_iter : an iterator
The iterator returns a 4-tuples of (node, node, op, timestamp).
Examples
--------
>>> G = dn.DynGraph()
>>> G.add_pat... | [
"def",
"stream_interactions",
"(",
"self",
")",
":",
"timestamps",
"=",
"sorted",
"(",
"self",
".",
"time_to_edge",
".",
"keys",
"(",
")",
")",
"for",
"t",
"in",
"timestamps",
":",
"for",
"e",
"in",
"self",
".",
"time_to_edge",
"[",
"t",
"]",
":",
"y... | Generate a temporal ordered stream of interactions.
Returns
-------
nd_iter : an iterator
The iterator returns a 4-tuples of (node, node, op, timestamp).
Examples
--------
>>> G = dn.DynGraph()
>>> G.add_path([0,1,2,3], t=0)
>>> G.add_path([... | [
"Generate",
"a",
"temporal",
"ordered",
"stream",
"of",
"interactions",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyngraph.py#L933-L953 |
GiulioRossetti/dynetx | dynetx/classes/dyngraph.py | DynGraph.time_slice | def time_slice(self, t_from, t_to=None):
"""Return an new graph containing nodes and interactions present in [t_from, t_to].
Parameters
----------
t_from : snapshot id, mandatory
t_to : snapshot id, optional (default=None)
If None t_to will be se... | python | def time_slice(self, t_from, t_to=None):
"""Return an new graph containing nodes and interactions present in [t_from, t_to].
Parameters
----------
t_from : snapshot id, mandatory
t_to : snapshot id, optional (default=None)
If None t_to will be se... | [
"def",
"time_slice",
"(",
"self",
",",
"t_from",
",",
"t_to",
"=",
"None",
")",
":",
"# create new graph and copy subgraph into it",
"H",
"=",
"self",
".",
"__class__",
"(",
")",
"if",
"t_to",
"is",
"not",
"None",
":",
"if",
"t_to",
"<",
"t_from",
":",
"... | Return an new graph containing nodes and interactions present in [t_from, t_to].
Parameters
----------
t_from : snapshot id, mandatory
t_to : snapshot id, optional (default=None)
If None t_to will be set equal to t_from
Returns
-... | [
"Return",
"an",
"new",
"graph",
"containing",
"nodes",
"and",
"interactions",
"present",
"in",
"[",
"t_from",
"t_to",
"]",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyngraph.py#L955-L1005 |
GiulioRossetti/dynetx | dynetx/classes/dyngraph.py | DynGraph.interactions_per_snapshots | def interactions_per_snapshots(self, t=None):
"""Return the number of interactions within snapshot t.
Parameters
----------
t : snapshot id (default=None)
If None will be returned total number of interactions across all snapshots
Returns
-------
nd... | python | def interactions_per_snapshots(self, t=None):
"""Return the number of interactions within snapshot t.
Parameters
----------
t : snapshot id (default=None)
If None will be returned total number of interactions across all snapshots
Returns
-------
nd... | [
"def",
"interactions_per_snapshots",
"(",
"self",
",",
"t",
"=",
"None",
")",
":",
"if",
"t",
"is",
"None",
":",
"return",
"{",
"k",
":",
"v",
"/",
"2",
"for",
"k",
",",
"v",
"in",
"self",
".",
"snapshots",
".",
"items",
"(",
")",
"}",
"else",
... | Return the number of interactions within snapshot t.
Parameters
----------
t : snapshot id (default=None)
If None will be returned total number of interactions across all snapshots
Returns
-------
nd : dictionary, or number
A dictionary with sn... | [
"Return",
"the",
"number",
"of",
"interactions",
"within",
"snapshot",
"t",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyngraph.py#L1027-L1060 |
GiulioRossetti/dynetx | dynetx/classes/dyngraph.py | DynGraph.inter_event_time_distribution | def inter_event_time_distribution(self, u=None, v=None):
"""Return the distribution of inter event time.
If u and v are None the dynamic graph intere event distribution is returned.
If u is specified the inter event time distribution of interactions involving u is returned.
If u and v ar... | python | def inter_event_time_distribution(self, u=None, v=None):
"""Return the distribution of inter event time.
If u and v are None the dynamic graph intere event distribution is returned.
If u is specified the inter event time distribution of interactions involving u is returned.
If u and v ar... | [
"def",
"inter_event_time_distribution",
"(",
"self",
",",
"u",
"=",
"None",
",",
"v",
"=",
"None",
")",
":",
"dist",
"=",
"{",
"}",
"if",
"u",
"is",
"None",
":",
"# global inter event",
"first",
"=",
"True",
"delta",
"=",
"None",
"for",
"ext",
"in",
... | Return the distribution of inter event time.
If u and v are None the dynamic graph intere event distribution is returned.
If u is specified the inter event time distribution of interactions involving u is returned.
If u and v are specified the inter event time distribution of (u, v) interactions... | [
"Return",
"the",
"distribution",
"of",
"inter",
"event",
"time",
".",
"If",
"u",
"and",
"v",
"are",
"None",
"the",
"dynamic",
"graph",
"intere",
"event",
"distribution",
"is",
"returned",
".",
"If",
"u",
"is",
"specified",
"the",
"inter",
"event",
"time",
... | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyngraph.py#L1062-L1136 |
GiulioRossetti/dynetx | dynetx/classes/dyndigraph.py | DynDiGraph.degree_iter | def degree_iter(self, nbunch=None, t=None):
"""Return an iterator for (node, degree) at time t.
The node degree is the number of edges adjacent to the node in a given timeframe.
Parameters
----------
nbunch : iterable container, optional (default=all nodes)
... | python | def degree_iter(self, nbunch=None, t=None):
"""Return an iterator for (node, degree) at time t.
The node degree is the number of edges adjacent to the node in a given timeframe.
Parameters
----------
nbunch : iterable container, optional (default=all nodes)
... | [
"def",
"degree_iter",
"(",
"self",
",",
"nbunch",
"=",
"None",
",",
"t",
"=",
"None",
")",
":",
"if",
"nbunch",
"is",
"None",
":",
"nodes_nbrs",
"=",
"(",
"(",
"n",
",",
"succs",
",",
"self",
".",
"_pred",
"[",
"n",
"]",
")",
"for",
"n",
",",
... | Return an iterator for (node, degree) at time t.
The node degree is the number of edges adjacent to the node in a given timeframe.
Parameters
----------
nbunch : iterable container, optional (default=all nodes)
A container of nodes. The container will b... | [
"Return",
"an",
"iterator",
"for",
"(",
"node",
"degree",
")",
"at",
"time",
"t",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyndigraph.py#L294-L341 |
GiulioRossetti/dynetx | dynetx/classes/dyndigraph.py | DynDiGraph.interactions_iter | def interactions_iter(self, nbunch=None, t=None):
"""Return an iterator over the interaction present in a given snapshot.
Edges are returned as tuples
in the order (node, neighbor).
Parameters
----------
nbunch : iterable container, optional (default= all nodes)
... | python | def interactions_iter(self, nbunch=None, t=None):
"""Return an iterator over the interaction present in a given snapshot.
Edges are returned as tuples
in the order (node, neighbor).
Parameters
----------
nbunch : iterable container, optional (default= all nodes)
... | [
"def",
"interactions_iter",
"(",
"self",
",",
"nbunch",
"=",
"None",
",",
"t",
"=",
"None",
")",
":",
"seen",
"=",
"{",
"}",
"# helper dict to keep track of multiply stored interactions",
"if",
"nbunch",
"is",
"None",
":",
"nodes_nbrs_succ",
"=",
"self",
".",
... | Return an iterator over the interaction present in a given snapshot.
Edges are returned as tuples
in the order (node, neighbor).
Parameters
----------
nbunch : iterable container, optional (default= all nodes)
A container of nodes. The container will be iterated
... | [
"Return",
"an",
"iterator",
"over",
"the",
"interaction",
"present",
"in",
"a",
"given",
"snapshot",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyndigraph.py#L382-L433 |
GiulioRossetti/dynetx | dynetx/classes/dyndigraph.py | DynDiGraph.in_interactions_iter | def in_interactions_iter(self, nbunch=None, t=None):
"""Return an iterator over the in interactions present in a given snapshot.
Edges are returned as tuples in the order (node, neighbor).
Parameters
----------
nbunch : iterable container, optional (default= all nodes)
... | python | def in_interactions_iter(self, nbunch=None, t=None):
"""Return an iterator over the in interactions present in a given snapshot.
Edges are returned as tuples in the order (node, neighbor).
Parameters
----------
nbunch : iterable container, optional (default= all nodes)
... | [
"def",
"in_interactions_iter",
"(",
"self",
",",
"nbunch",
"=",
"None",
",",
"t",
"=",
"None",
")",
":",
"if",
"nbunch",
"is",
"None",
":",
"nodes_nbrs_pred",
"=",
"self",
".",
"_pred",
".",
"items",
"(",
")",
"else",
":",
"nodes_nbrs_pred",
"=",
"[",
... | Return an iterator over the in interactions present in a given snapshot.
Edges are returned as tuples in the order (node, neighbor).
Parameters
----------
nbunch : iterable container, optional (default= all nodes)
A container of nodes. The container will be iterated
... | [
"Return",
"an",
"iterator",
"over",
"the",
"in",
"interactions",
"present",
"in",
"a",
"given",
"snapshot",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyndigraph.py#L591-L638 |
GiulioRossetti/dynetx | dynetx/classes/dyndigraph.py | DynDiGraph.out_interactions_iter | def out_interactions_iter(self, nbunch=None, t=None):
"""Return an iterator over the out interactions present in a given snapshot.
Edges are returned as tuples
in the order (node, neighbor).
Parameters
----------
nbunch : iterable container, optional (default= all nodes... | python | def out_interactions_iter(self, nbunch=None, t=None):
"""Return an iterator over the out interactions present in a given snapshot.
Edges are returned as tuples
in the order (node, neighbor).
Parameters
----------
nbunch : iterable container, optional (default= all nodes... | [
"def",
"out_interactions_iter",
"(",
"self",
",",
"nbunch",
"=",
"None",
",",
"t",
"=",
"None",
")",
":",
"if",
"nbunch",
"is",
"None",
":",
"nodes_nbrs_succ",
"=",
"self",
".",
"_succ",
".",
"items",
"(",
")",
"else",
":",
"nodes_nbrs_succ",
"=",
"[",... | Return an iterator over the out interactions present in a given snapshot.
Edges are returned as tuples
in the order (node, neighbor).
Parameters
----------
nbunch : iterable container, optional (default= all nodes)
A container of nodes. The container will be iterat... | [
"Return",
"an",
"iterator",
"over",
"the",
"out",
"interactions",
"present",
"in",
"a",
"given",
"snapshot",
"."
] | train | https://github.com/GiulioRossetti/dynetx/blob/634e2b38f8950885aebfa079dad7d5e8d7563f1d/dynetx/classes/dyndigraph.py#L640-L687 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.