signature
stringlengths
8
3.44k
body
stringlengths
0
1.41M
docstring
stringlengths
1
122k
id
stringlengths
5
17
def __init__(self):
super().__init__('''<STR_LIT>''', dependencies=(_find_inverse_gamma(), igam_fac(), igam()))<EOL>
Copied from Scipy (https://github.com/scipy/scipy/blob/master/scipy/special/cephes/igami.c), 05-05-2018.
f15550:c10:m0
def __init__(self):
super().__init__('''<STR_LIT>''', dependencies=(_find_inverse_gamma(), igam_fac(), igam()))<EOL>
Copied from Scipy (https://github.com/scipy/scipy/blob/master/scipy/special/cephes/igami.c), 05-05-2018.
f15550:c11:m0
def __init__(self):
super().__init__('''<STR_LIT>''', dependencies=(_igami_impl(), _igamci_impl(), _find_inverse_gamma(), igam_fac(), igamc()))<EOL>
Copied from Scipy (https://github.com/scipy/scipy/blob/master/scipy/special/cephes/igami.c), 05-05-2018.
f15550:c12:m0
def __init__(self):
super().__init__('''<STR_LIT>''', dependencies=(igam_series(), igamc(), igam_igamc_asymptotic_series()))<EOL>
Complemented incomplete Gamma integral Also known as the regularized lower incomplete gamma function. Copied from Scipy (https://github.com/scipy/scipy/blob/master/scipy/special/cephes/igam.c), 05-05-2018:: /* igam.c * ...
f15550:c13:m0
def __init__(self):
super().__init__('''<STR_LIT>''', dependencies=(igam_igamc_asymptotic_series(), igamc_series(),<EOL>igam_series(), igamc_continued_fraction()))<EOL>
Complemented incomplete Gamma integral Also known as the regularized upper incomplete gamma function. Copied from Scipy (https://github.com/scipy/scipy/blob/master/scipy/special/cephes/igam.c), 05-05-2018:: /* igamc() * * Complemented incomplete Gamma integr...
f15550:c14:m0
def __init__(self):
super().__init__('''<STR_LIT>''', dependencies=(log1pmx(), lanczos_sum_expg_scaled()))<EOL>
Compute x^a * exp(-x) / gamma(a) Copied from Scipy (https://github.com/scipy/scipy/blob/master/scipy/special/cephes/igam.c), 05-05-2018.
f15550:c15:m0
def __init__(self):
super().__init__('''<STR_LIT>''', dependencies=(igam_fac(),))<EOL>
Compute igamc using DLMF 8.9.2. Copied from Scipy (https://github.com/scipy/scipy/blob/master/scipy/special/cephes/igam.c), 05-05-2018.
f15550:c16:m0
def __init__(self):
super().__init__('''<STR_LIT>''', dependencies=(igam_fac(),))<EOL>
Compute igamc using DLMF 8.11.4 Copied from Scipy (https://github.com/scipy/scipy/blob/master/scipy/special/cephes/igam.c), 05-05-2018.
f15550:c17:m0
def __init__(self):
super().__init__('''<STR_LIT>''', dependencies=(lgam1p(),))<EOL>
Compute igamc using DLMF 8.7.3. This is related to the series in igam_series but extra care is taken to avoid cancellation. Copied from Scipy (https://github.com/scipy/scipy/blob/master/scipy/special/cephes/igam.c), 05-05-2018.
f15550:c18:m0
def __init__(self):
super().__init__('''<STR_LIT>''', dependencies=(log1pmx(),))<EOL>
Compute igam/igamc using DLMF 8.12.3/8.12.4. Copied from Scipy (https://github.com/scipy/scipy/blob/master/scipy/special/cephes/igam.c), 05-05-2018. The argument ``func`` should be 1 when computing for IGAM and 0 when computing for IGAMC.
f15550:c19:m0
def __init__(self):
super().__init__('''<STR_LIT>''')<EOL>
Compute the first term of the legendre polynomial for the given value x and the polynomial degree n. The Legendre polynomials, Pn(x), are orthogonal on the interval [-1,1] with weight function w(x) = 1 for -1 <= x <= 1 and 0 elsewhere. They are normalized so that Pn(1) = 1. The inner products are: ...
f15551:c0:m0
def __init__(self):
super().__init__('''<STR_LIT>''')<EOL>
Compute a range of Legendre terms for the given value x and the polynomial degree n. The Legendre polynomials, Pn(x), are orthogonal on the interval [-1,1] with weight function w(x) = 1 for -1 <= x <= 1 and 0 elsewhere. They are normalized so that Pn(1) = 1. The inner products are: .. code-b...
f15551:c1:m0
def __init__(self):
super().__init__('''<STR_LIT>''')<EOL>
Compute a range of even legendre terms for the given value x and the polynomial degree n. The Legendre polynomials, Pn(x), are orthogonal on the interval [-1,1] with weight function w(x) = 1 for -1 <= x <= 1 and 0 elsewhere. They are normalized so that Pn(1) = 1. The inner products are: .. c...
f15551:c2:m0
def __init__(self):
super().__init__('''<STR_LIT>''')<EOL>
Compute a range of odd legendre terms for the given value x and the polynomial degree n. The Legendre polynomials, Pn(x), are orthogonal on the interval [-1,1] with weight function w(x) = 1 for -1 <= x <= 1 and 0 elsewhere. They are normalized so that Pn(1) = 1. The inner products are: .. co...
f15551:c3:m0
def __init__(self, return_type, cl_function_name, parameter_list, cl_code_file,<EOL>var_replace_dict=None, **kwargs):
self._var_replace_dict = var_replace_dict<EOL>with open(os.path.abspath(cl_code_file), '<STR_LIT:r>') as f:<EOL><INDENT>code = f.read()<EOL><DEDENT>if var_replace_dict is not None:<EOL><INDENT>code = code % var_replace_dict<EOL><DEDENT>super().__init__(return_type, cl_function_name, parameter_list, code, **kwargs)<EOL>...
Create a CL function for a library function. These functions are not meant to be optimized, but can be used a helper functions in models. Args: cl_function_name (str): The name of the CL function cl_code_file (str): The location of the code file var_replace_dict (di...
f15552:c2:m0
def __init__(self):
super().__init__('''<STR_LIT>''', dependencies=(ratevl(),))<EOL>
Copied from Scipy (https://github.com/scipy/scipy/blob/master/scipy/special/cephes/lanczos.c), 2018-05-07.
f15553:c0:m0
def __init__(self):
super().__init__('''<STR_LIT>''')<EOL>
log(1 + x) - x
f15554:c0:m0
def __init__(self):
super().__init__('<STR_LIT>')<EOL>
Compute lgam(x + 1). This is a simplification of the corresponding function in scipy https://github.com/scipy/scipy/blob/master/scipy/special/cephes/unity.c 2018-05-14
f15554:c1:m0
def __init__(self):
super().__init__('''<STR_LIT>''')<EOL>
Returns (only) the real roots of a cubic polynomial. This computes :math:`p(x) = \\sum_i c[i] * x^i = 0`, i.e. tries to find x such that :math:`p(x) = 0` using the algebraic method. The coefficients and the roots may point to the same address space to save memory. This code is an Open...
f15555:c0:m0
def __init__(self):
super().__init__('''<STR_LIT>''')<EOL>
Routines for computing polynomials. Copied from Scipy (https://github.com/scipy/scipy/blob/master/scipy/special/cephes/polevl.h), 05-05-2018. Evaluates polynomial of degree N:: 2 N y = C + C x + C x +...+ C x 0 1 2 ...
f15555:c1:m0
def __init__(self):
super().__init__('''<STR_LIT>''')<EOL>
Routines for computing polynomials when coefficient of x^N is 1.0. Copied from Scipy (https://github.com/scipy/scipy/blob/master/scipy/special/cephes/polevl.h), 05-05-2018. Evaluates polynomial of degree N:: 2 N y = C + C x + C x +...+ C x ...
f15555:c2:m0
def __init__(self):
super().__init__('''<STR_LIT>''')<EOL>
Evaluates a rational integral. Copied from Scipy (https://github.com/scipy/scipy/blob/master/scipy/special/cephes/polevl.h), 2018-05-07.
f15555:c3:m0
def __init__(self):
super().__init__('''<STR_LIT>''')<EOL>
Return the zeroth-order modified Bessel function of the first kind Original author of C code: M.G.R. Vogelaar
f15556:c0:m0
def __init__(self):
super().__init__('''<STR_LIT>''', dependencies=(Besseli0(),))<EOL>
Return the log of the zeroth-order modified Bessel function of the first kind.
f15556:c1:m0
def __init__(self):
super().__init__('''<STR_LIT>''')<EOL>
Computes :math:`log(cosh(x))` For large x this will try to estimate it without overflow. For small x we use the opencl functions log and cos. The estimation for large numbers has been taken from: https://github.com/JaneliaSciComp/tmt/blob/master/basics/logcosh.m
f15556:c2:m0
def __init__(self, memspace='<STR_LIT>', memtype='<STR_LIT>'):
super().__init__(<EOL>memtype,<EOL>self.__class__.__name__ + '<STR_LIT:_>' + memspace + '<STR_LIT:_>' + memtype,<EOL>[],<EOL>resource_filename('<STR_LIT>', '<STR_LIT>'),<EOL>var_replace_dict={'<STR_LIT>': memspace, '<STR_LIT>': memtype})<EOL>
A CL functions for calculating the Euclidian distance between n values. Args: memspace (str): The memory space of the memtyped array (private, constant, global). memtype (str): the memory type to use, double, float, mot_float_type, ...
f15556:c4:m0
def __init__(self, function_name):
super().__init__('''<STR_LIT>'''.format(f=function_name))<EOL>
Create a CL function for integrating a function using Simpson's rule. This creates a CL function specifically meant for integrating the function of the given name. The name of the generated CL function will be 'simpsons_rule_<function_name>'. Args: function_name (str): the name of ...
f15556:c5:m0
def __init__(self):
super().__init__('''<STR_LIT>''')<EOL>
Cubic interpolation for a one-dimensional grid. This uses the theory of Cubic Hermite splines for interpolating a one-dimensional grid of values. At the borders, it will clip the values to the nearest border. For more information on this method, see https://en.wikipedia.org/wiki/Cubic_Hermite...
f15556:c6:m0
def __init__(self):
super().__init__('''<STR_LIT>''')<EOL>
Calculate the eigenvalues of a symmetric 3x3 matrix. This simple algorithm only works in case of a real and symmetric matrix. The input to this function is an array with the upper triangular elements of the matrix. The output are the eigenvalues such that eig1 >= eig2 >= eig3, i.e. from large ...
f15556:c7:m0
def __init__(self):
super().__init__('''<STR_LIT>''')<EOL>
Matrix multiplication of two square matrices. Having this as a special function is slightly faster than a more generic matrix multiplication algorithm. All matrices are expected to be in c/row-major order. Parameters: n: the rectangular size of the matrix (the number of rows / the...
f15556:c8:m0
def __init__(self):
super().__init__('''<STR_LIT>''', dependencies=[eispack_tred2(), eispack_tql2()])<EOL>
Computes eigenvalues and eigenvectors of real symmetric matrix. This uses the RS routine from the EISPACK code, to be found at: https://people.sc.fsu.edu/~jburkardt/c_src/eispack/eispack.html It first tri-diagonalizes the matrix using Householder transformations and then computes the diagonal ...
f15556:c9:m0
def __init__(self):
super().__init__('''<STR_LIT>''', dependencies=[eigen_decompose_real_symmetric_matrix()])<EOL>
Compute the pseudo-inverse of a real symmetric matrix stored as an upper triangular vector. Results are placed in the upper triangular input vector. Parameters: n: the size of the symmetric matrix A[n*(n+1)/2]: on input, the matrix to inverse. On output, the inverse of the matr...
f15556:c10:m0
def __init__(self, eval_func, nmr_parameters, patience=<NUM_LIT:2>, patience_line_search=None,<EOL>reset_method='<STR_LIT>', **kwargs):
dependencies = list(kwargs.get('<STR_LIT>', []))<EOL>dependencies.append(eval_func)<EOL>kwargs['<STR_LIT>'] = dependencies<EOL>params = {<EOL>'<STR_LIT>': eval_func.get_cl_function_name(),<EOL>'<STR_LIT>': nmr_parameters,<EOL>'<STR_LIT>': reset_method.upper(),<EOL>'<STR_LIT>': patience,<EOL>'<STR_LIT>': patience if pat...
The Powell CL implementation. Args: eval_func (mot.lib.cl_function.CLFunction): the function we want to optimize, Should be of signature: ``double evaluate(local mot_float_type* x, void* data_void);`` nmr_parameters (int): the number of parameters in the model, this will...
f15556:c11:m0
def get_kernel_data(self):
return {<EOL>'<STR_LIT>': LocalMemory(<EOL>'<STR_LIT>', <NUM_LIT:3> * self._var_replace_dict['<STR_LIT>'] + self._var_replace_dict['<STR_LIT>']**<NUM_LIT:2>)<EOL>}<EOL>
Get the kernel data needed for this optimization routine to work.
f15556:c11:m1
def __init__(self, function_name):
params = {<EOL>'<STR_LIT>': function_name<EOL>}<EOL>super().__init__(<EOL>'<STR_LIT:int>', '<STR_LIT>', [],<EOL>resource_filename('<STR_LIT>', '<STR_LIT>'),<EOL>var_replace_dict=params)<EOL>
The NMSimplex algorithm as a reusable library component. Args: function_name (str): the name of the evaluation function to call, defaults to 'evaluate'. This should point to a function with signature: ``double evaluate(local mot_float_type* x, void* data_void);`...
f15556:c12:m0
def get_kernel_data(self):
return {<EOL>'<STR_LIT>': LocalMemory(<EOL>'<STR_LIT>', self._nmr_parameters * <NUM_LIT:2> + (self._nmr_parameters + <NUM_LIT:1>) ** <NUM_LIT:2> + <NUM_LIT:1>),<EOL>'<STR_LIT>': LocalMemory('<STR_LIT>', self._nmr_parameters)<EOL>}<EOL>
Get the kernel data needed for this optimization routine to work.
f15556:c13:m1
def __init__(self, eval_func, nmr_parameters, patience=<NUM_LIT:10>,<EOL>patience_nmsimplex=<NUM_LIT:100>, alpha=<NUM_LIT:1.0>, beta=<NUM_LIT:0.5>, gamma=<NUM_LIT>, delta=<NUM_LIT:0.5>, scale=<NUM_LIT:1.0>, psi=<NUM_LIT>, omega=<NUM_LIT>,<EOL>adaptive_scales=True, min_subspace_length='<STR_LIT>', max_subspace_length='<...
dependencies = list(kwargs.get('<STR_LIT>', []))<EOL>dependencies.append(eval_func)<EOL>dependencies.append(LibNMSimplex('<STR_LIT>'))<EOL>kwargs['<STR_LIT>'] = dependencies<EOL>params = {<EOL>'<STR_LIT>': eval_func.get_cl_function_name(),<EOL>'<STR_LIT>': patience,<EOL>'<STR_LIT>': patience_nmsimplex,<EOL>'<STR_LIT>':...
The Subplex optimization routines.
f15556:c14:m0
def get_kernel_data(self):
return {<EOL>'<STR_LIT>': LocalMemory(<EOL>'<STR_LIT>', <NUM_LIT:4> + self._var_replace_dict['<STR_LIT>'] * <NUM_LIT:2><EOL>+ self._var_replace_dict['<STR_LIT>'] * <NUM_LIT:2><EOL>+ (self._var_replace_dict['<STR_LIT>'] * <NUM_LIT:2><EOL>+ self._var_replace_dict['<STR_LIT>']+<NUM_LIT:1>)**<NUM_LIT:2> + <NUM_LIT:1>),<EOL...
Get the kernel data needed for this optimization routine to work.
f15556:c14:m1
def __init__(self, eval_func, nmr_parameters, nmr_observations, jacobian_func, patience=<NUM_LIT>,<EOL>step_bound=<NUM_LIT>, scale_diag=<NUM_LIT:1>, usertol_mult=<NUM_LIT:30>, **kwargs):
dependencies = list(kwargs.get('<STR_LIT>', []))<EOL>dependencies.append(eval_func)<EOL>dependencies.append(jacobian_func)<EOL>kwargs['<STR_LIT>'] = dependencies<EOL>var_replace_dict = {<EOL>'<STR_LIT>': eval_func.get_cl_function_name(),<EOL>'<STR_LIT>': jacobian_func.get_cl_function_name(),<EOL>'<STR_LIT>': nmr_parame...
The Powell CL implementation. Args: eval_func (mot.lib.cl_function.CLFunction): the function we want to optimize, Should be of signature: ``void evaluate(local mot_float_type* x, void* data_void, local mot_float_type* result);`` nmr_parameters (int): the number of parame...
f15556:c15:m0
def get_kernel_data(self):
return {<EOL>'<STR_LIT>': LocalMemory(<EOL>'<STR_LIT>', <NUM_LIT:8> +<EOL><NUM_LIT:2> * self._var_replace_dict['<STR_LIT>'] +<EOL><NUM_LIT:5> * self._var_replace_dict['<STR_LIT>'] +<EOL>self._var_replace_dict['<STR_LIT>'] * self._var_replace_dict['<STR_LIT>']),<EOL>'<STR_LIT>': LocalMemory('<STR_LIT:int>', self._var_re...
Get the kernel data needed for this optimization routine to work.
f15556:c15:m1
def __init__(self, platform, device):
self._platform = platform<EOL>self._device = device<EOL>if (self._platform, self._device) not in _context_cache:<EOL><INDENT>context = cl.Context([device])<EOL>_context_cache[(self._platform, self._device)] = context<EOL><DEDENT>self._context = _context_cache[(self._platform, self._device)]<EOL>self._queue = cl.Command...
Storage unit for an OpenCL environment. Args: platform (pyopencl platform): An PyOpenCL platform. device (pyopencl device): An PyOpenCL device
f15558:c0:m0
@property<EOL><INDENT>def context(self):<DEDENT>
return self._context<EOL>
Get a CL context containing this device. Returns: cl.Context: a PyOpenCL device context
f15558:c0:m1
@property<EOL><INDENT>def queue(self):<DEDENT>
return self._queue<EOL>
Get a CL queue for this device and context. Returns: cl.Queue: a PyOpenCL queue
f15558:c0:m2
@property<EOL><INDENT>def supports_double(self):<DEDENT>
return device_supports_double(self.device)<EOL>
Check if the device listed by this environment supports double Returns: boolean: True if the device supports double, false otherwise.
f15558:c0:m3
@property<EOL><INDENT>def platform(self):<DEDENT>
return self._platform<EOL>
Get the platform associated with this environment. Returns: pyopencl platform: The platform associated with this environment.
f15558:c0:m4
@property<EOL><INDENT>def device(self):<DEDENT>
return self._device<EOL>
Get the device associated with this environment. Returns: pyopencl device: The device associated with this environment.
f15558:c0:m5
@property<EOL><INDENT>def is_gpu(self):<DEDENT>
return self._device.get_info(cl.device_info.TYPE) == cl.device_type.GPU<EOL>
Check if the device associated with this environment is a GPU. Returns: boolean: True if the device is an GPU, false otherwise.
f15558:c0:m6
@property<EOL><INDENT>def is_cpu(self):<DEDENT>
return self._device.get_info(cl.device_info.TYPE) == cl.device_type.CPU<EOL>
Check if the device associated with this environment is a CPU. Returns: boolean: True if the device is an CPU, false otherwise.
f15558:c0:m7
@property<EOL><INDENT>def device_type(self):<DEDENT>
return self._device.get_info(cl.device_info.TYPE)<EOL>
Get the device type of the device in this environment. Returns: the device type of this device.
f15558:c0:m8
def __eq__(self, other):
if isinstance(other, CLEnvironment):<EOL><INDENT>return other.platform == self.platform and other.device == self.device<EOL><DEDENT>return False<EOL>
A device is equal to another if the platform and the device are equal.
f15558:c0:m12
@staticmethod<EOL><INDENT>def single_device(cl_device_type='<STR_LIT>', platform=None, fallback_to_any_device_type=False):<DEDENT>
if isinstance(cl_device_type, str):<EOL><INDENT>cl_device_type = device_type_from_string(cl_device_type)<EOL><DEDENT>device = None<EOL>if platform is None:<EOL><INDENT>platforms = cl.get_platforms()<EOL><DEDENT>else:<EOL><INDENT>platforms = [platform]<EOL><DEDENT>for platform in platforms:<EOL><INDENT>devices = platfor...
Get a list containing a single device environment, for a device of the given type on the given platform. This will only fetch devices that support double (possibly only double with a pragma defined, but still, it should support double). Args: cl_device_type (cl.device_type.* or str...
f15558:c1:m0
@staticmethod<EOL><INDENT>def all_devices(cl_device_type=None, platform=None):<DEDENT>
if isinstance(cl_device_type, str):<EOL><INDENT>cl_device_type = device_type_from_string(cl_device_type)<EOL><DEDENT>runtime_list = []<EOL>if platform is None:<EOL><INDENT>platforms = cl.get_platforms()<EOL><DEDENT>else:<EOL><INDENT>platforms = [platform]<EOL><DEDENT>for platform in platforms:<EOL><INDENT>if cl_device_...
Get multiple device environments, optionally only of the indicated type. This will only fetch devices that support double point precision. Args: cl_device_type (cl.device_type.* or string): The type of the device we want, can be a opencl device type or a string matching 'GP...
f15558:c1:m1
@staticmethod<EOL><INDENT>def smart_device_selection(preferred_device_type=None):<DEDENT>
cl_environments = CLEnvironmentFactory.all_devices(cl_device_type=preferred_device_type)<EOL>platform_names = [env.platform.name for env in cl_environments]<EOL>has_amd_pro_platform = any('<STR_LIT>' in name for name in platform_names)<EOL>if has_amd_pro_platform:<EOL><INDENT>return list(filter(lambda env: '<STR_LIT>' ...
Get a list of device environments that is suitable for use in MOT. Basically this gets the total list of devices using all_devices() and applies a filter on it. This filter does the following: 1) if the 'AMD Accelerated Parallel Processing' is available remove all environments using the 'C...
f15558:c1:m2
def set_mot_float_dtype(self, mot_float_dtype):
raise NotImplementedError()<EOL>
Set the numpy data type corresponding to the ``mot_float_type`` ctype. This is set just prior to using this kernel data in the kernel. Args: mot_float_dtype (dtype): the numpy data type that is to correspond with the ``mot_float_type`` used in the kernels.
f15559:c0:m0
def get_data(self):
raise NotImplementedError()<EOL>
Get the underlying data of this kernel data object. Returns: dict, ndarray, scalar: the underlying data object, can return None if this input data has no actual data.
f15559:c0:m1
def get_scalar_arg_dtypes(self):
raise NotImplementedError()<EOL>
Get the numpy data types we should report in the kernel call for scalar elements. If we are inserting scalars in the kernel we need to provide the CL runtime with the correct data type of the function. If the kernel parameter is not a scalar, we should return None. If the kernel data does not r...
f15559:c0:m2
def enqueue_readouts(self, queue, buffers, range_start, range_end):
raise NotImplementedError()<EOL>
Enqueue readouts for this kernel input data object. This should add non-blocking readouts to the given queue. Args: queue (opencl queue): the queue on which to add the unmap buffer command buffers (List[pyopencl._cl.Buffer.Buffer]): the list of buffers corresponding to this ker...
f15559:c0:m3
def get_type_definitions(self):
raise NotImplementedError()<EOL>
Get possible type definitions needed to load this data into the kernel. These types are defined at the head of the CL script, before any functions. Returns: str: a CL compatible type declaration. This can for example be used for defining struct types. If no extra types are ...
f15559:c0:m4
def initialize_variable(self, variable_name, kernel_param_name, problem_id_substitute, address_space):
raise NotImplementedError()<EOL>
Initialize the variable inside the kernel function. This should initialize the variable as such that we can use it when calling the function acting on this data. Args: variable_name (str): the name for this variable kernel_param_name (str): the kernel parameter name (given in...
f15559:c0:m5
def get_function_call_input(self, variable_name, kernel_param_name, problem_id_substitute, address_space):
raise NotImplementedError()<EOL>
How this kernel data is used as input to the function that operates on the data. Args: variable_name (str): the name for this variable kernel_param_name (str): the kernel parameter name (given in :meth:`get_kernel_parameters`). problem_id_substitute (str): the substitute for...
f15559:c0:m6
def post_function_callback(self, variable_name, kernel_param_name, problem_id_substitute, address_space):
raise NotImplementedError()<EOL>
A callback to update or change data after the function has been applied Args: variable_name (str): the name for this variable kernel_param_name (str): the kernel parameter name (given in :meth:`get_kernel_parameters`). problem_id_substitute (str): the substitute for the ``{p...
f15559:c0:m7
def get_struct_declaration(self, name):
raise NotImplementedError()<EOL>
Get the variable declaration of this data object for use in a Struct. Args: name (str): the name for this data Returns: str: the variable declaration of this kernel data object
f15559:c0:m8
def get_struct_initialization(self, variable_name, kernel_param_name, problem_id_substitute):
raise NotImplementedError()<EOL>
Initialize the variable inside a struct. This should initialize the variable for use in a struct (should correspond to :meth:`get_struct_declaration`). Args: variable_name (str): the name for this variable kernel_param_name (str): the kernel parameter name (given in :meth:`ge...
f15559:c0:m9
def get_kernel_parameters(self, kernel_param_name):
raise NotImplementedError()<EOL>
Get the kernel argument declarations for this kernel data. Args: kernel_param_name (str): the parameter name for the parameter in the kernel function call Returns: List[str]: a list of kernel parameter declarations, or an empty list
f15559:c0:m10
def get_kernel_inputs(self, cl_context, workgroup_size):
raise NotImplementedError()<EOL>
Get the kernel input data matching the list of parameters of :meth:`get_kernel_parameters`. Since the kernels follow the map/unmap paradigm make sure to use the ``USE_HOST_PTR`` when making writable data objects. Args: cl_context (pyopencl.Context): the CL context in which we are w...
f15559:c0:m11
def get_nmr_kernel_inputs(self):
raise NotImplementedError()<EOL>
Get the number of kernel inputs this input data object has. Returns: int: the number of kernel inputs
f15559:c0:m12
def __init__(self, elements, ctype, anonymous=False):
self._elements = OrderedDict(sorted(elements.items()))<EOL>for key in list(self._elements):<EOL><INDENT>value = self._elements[key]<EOL>if isinstance(value, Mapping):<EOL><INDENT>self._elements[key] = Struct(value, key, anonymous=True)<EOL><DEDENT><DEDENT>self._ctype = ctype<EOL>self._anonymous = anonymous<EOL>
A kernel data element for structs. Please be aware that structs will always be passed as a pointer to the calling function. Args: elements (Dict[str, Union[Dict, KernelData]]): the kernel data elements to load into the kernel Can be a nested dictionary, in which case we loa...
f15559:c1:m0
def __init__(self, value, ctype=None):
if isinstance(value, str) and value == '<STR_LIT>':<EOL><INDENT>self._value = np.inf<EOL><DEDENT>elif isinstance(value, str) and value == '<STR_LIT>':<EOL><INDENT>self._value = -np.inf<EOL><DEDENT>else:<EOL><INDENT>self._value = np.array(value)<EOL><DEDENT>self._ctype = ctype or dtype_to_ctype(self._value.dtype)<EOL>se...
A kernel input scalar. This will insert the given value directly into the kernel's source code, and will not load it as a buffer. Args: value (number): the number to insert into the kernel as a scalar. ctype (str): the desired c-type for in use in the kernel, like ``int``, ``fl...
f15559:c2:m0
def __init__(self, ctype, nmr_items=None):
self._ctype = ctype<EOL>self._mot_float_dtype = None<EOL>if nmr_items is None:<EOL><INDENT>self._size_func = lambda workgroup_size: workgroup_size<EOL><DEDENT>elif isinstance(nmr_items, numbers.Number):<EOL><INDENT>self._size_func = lambda _: nmr_items<EOL><DEDENT>else:<EOL><INDENT>self._size_func = nmr_items<EOL><DEDE...
Indicates that a local memory array of the indicated size must be loaded as kernel input data. By default, this will create a local memory object the size of the local work group. Args: ctype (str): the desired c-type for this local memory object, like ``int``, ``float`` or ``mot_float_typ...
f15559:c3:m0
def __init__(self, nmr_items, ctype):
self._ctype = ctype<EOL>self._mot_float_dtype = None<EOL>self._nmr_items = nmr_items<EOL>
Adds a private memory array of the indicated size to the kernel data elements. This is useful if you want to have private memory arrays in kernel data structs. Args: nmr_items (int): the size of the private memory array ctype (str): the desired c-type for this local memory obje...
f15559:c4:m0
def __init__(self, data, ctype=None, mode='<STR_LIT:r>', offset_str=None, ensure_zero_copy=False, as_scalar=False):
self._is_readable = '<STR_LIT:r>' in mode<EOL>self._is_writable = '<STR_LIT:w>' in mode<EOL>self._requirements = ['<STR_LIT:C>', '<STR_LIT:A>', '<STR_LIT:O>']<EOL>if self._is_writable:<EOL><INDENT>self._requirements.append('<STR_LIT>')<EOL><DEDENT>self._data = np.require(data, requirements=self._requirements)<EOL>if ct...
Loads the given array as a buffer into the kernel. By default, this will try to offset the data in the kernel by the stride of the first dimension multiplied with the problem id by the kernel. For example, if a (n, m) matrix is provided, this will offset the data by ``{problem_id} * m``. ...
f15559:c5:m0
def __init__(self, shape, ctype, offset_str=None, mode='<STR_LIT:w>'):
super().__init__(np.zeros(shape, dtype=ctype_to_dtype(ctype)), ctype, offset_str=offset_str,<EOL>mode=mode, as_scalar=False)<EOL>
Allocate an output buffer of the given shape. This is meant to quickly allocate a buffer large enough to hold the data requested. After running an OpenCL kernel you can get the written data using the method :meth:`get_data`. Args: shape (int or tuple): the shape of the output array...
f15559:c6:m0
def __init__(self, elements, ctype, address_space='<STR_LIT>'):
self._elements = elements<EOL>self._ctype = ctype<EOL>self._address_space = address_space<EOL>if self._address_space == '<STR_LIT>':<EOL><INDENT>self._composite_array = PrivateMemory(len(self._elements), self._ctype)<EOL><DEDENT>elif self._address_space == '<STR_LIT>':<EOL><INDENT>self._composite_array = LocalMemory(se...
An array filled with the given kernel data elements. Each of the given elements should be a :class:`Scalar` or an :class:`Array` with the property `as_scalar` set to True. We will load each value of the given elements into a private array. Args: elements (List[KernelData]): the ker...
f15559:c7:m0
def add_include_guards(cl_str, guard_name=None):
if not guard_name:<EOL><INDENT>guard_name = '<STR_LIT>' + hashlib.md5(cl_str.encode('<STR_LIT:utf-8>')).hexdigest()<EOL><DEDENT>return '''<STR_LIT>'''.format(func_str=cl_str, guard_name=guard_name)<EOL>
Add include guards to the given string. If you are including the same body of CL code multiple times in a Kernel, it is important to add include guards (https://en.wikipedia.org/wiki/Include_guard) around them to prevent the kernel from registering the function twice. Args: cl_str (str): the p...
f15561:m0
def dtype_to_ctype(dtype):
from pyopencl.tools import dtype_to_ctype<EOL>return dtype_to_ctype(dtype)<EOL>
Get the CL type of the given numpy data type. Args: dtype (np.dtype): the numpy data type Returns: str: the CL type string for the corresponding type
f15561:m1
def ctype_to_dtype(cl_type, mot_float_type='<STR_LIT:float>'):
if is_vector_ctype(cl_type):<EOL><INDENT>raw_type, vector_length = split_vector_ctype(cl_type)<EOL>if raw_type == '<STR_LIT>':<EOL><INDENT>if is_vector_ctype(mot_float_type):<EOL><INDENT>raw_type, _ = split_vector_ctype(mot_float_type)<EOL><DEDENT>else:<EOL><INDENT>raw_type = mot_float_type<EOL><DEDENT><DEDENT>vector_t...
Get the numpy dtype of the given cl_type string. Args: cl_type (str): the CL data type to match, for example 'float' or 'float4'. mot_float_type (str): the C name of the ``mot_float_type``. The dtype will be looked up recursively. Returns: dtype: the numpy datatype
f15561:m2
def convert_data_to_dtype(data, data_type, mot_float_type='<STR_LIT:float>'):
scalar_dtype = ctype_to_dtype(data_type, mot_float_type)<EOL>if isinstance(data, numbers.Number):<EOL><INDENT>data = scalar_dtype(data)<EOL><DEDENT>if is_vector_ctype(data_type):<EOL><INDENT>shape = data.shape<EOL>dtype = ctype_to_dtype(data_type, mot_float_type)<EOL>ve = np.zeros(shape[:-<NUM_LIT:1>], dtype=dtype)<EOL...
Convert the given input data to the correct numpy type. Args: data (ndarray): The value to convert to the correct numpy type data_type (str): the data type we need to convert the data to mot_float_type (str): the data type of the current ``mot_float_type`` Returns: ndarray: the...
f15561:m3
def split_vector_ctype(ctype):
if not is_vector_ctype(ctype):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>for vector_length in [<NUM_LIT:2>, <NUM_LIT:3>, <NUM_LIT:4>, <NUM_LIT:8>, <NUM_LIT:16>]:<EOL><INDENT>if ctype.endswith(str(vector_length)):<EOL><INDENT>vector_str_len = len(str(vector_length))<EOL>return ctype[:-vector_str_len], int(ct...
Split a vector ctype into a raw ctype and the vector length. If the given ctype is not a vector type, we raise an error. I Args: ctype (str): the ctype to possibly split into a raw ctype and the vector length Returns: tuple: the raw ctype and the vector length
f15561:m4
def is_vector_ctype(ctype):
return any(ctype.endswith(str(i)) for i in [<NUM_LIT:2>, <NUM_LIT:3>, <NUM_LIT:4>, <NUM_LIT:8>, <NUM_LIT:16>])<EOL>
Test if the given ctype is a vector type. That is, if it ends with 2, 3, 4, 8 or 16. Args: ctype (str): the ctype to test if it is an OpenCL vector type Returns: bool: if it is a vector type or not
f15561:m5
def device_type_from_string(cl_device_type_str):
cl_device_type_str = cl_device_type_str.upper()<EOL>if hasattr(cl.device_type, cl_device_type_str):<EOL><INDENT>return getattr(cl.device_type, cl_device_type_str)<EOL><DEDENT>return None<EOL>
Converts values like ``gpu`` to a pyopencl device type string. Supported values are: ``accelerator``, ``cpu``, ``custom``, ``gpu``. If ``all`` is given, None is returned. Args: cl_device_type_str (str): The string we want to convert to a device type. Returns: cl.device_type: the pyopencl ...
f15561:m6
def device_supports_double(cl_device):
dev_extensions = cl_device.extensions.strip().split('<STR_LIT:U+0020>')<EOL>return '<STR_LIT>' in dev_extensions<EOL>
Check if the given CL device supports double Args: cl_device (pyopencl cl device): The device to check if it supports double. Returns: boolean: True if the given cl_device supports double, false otherwise.
f15561:m7
def get_float_type_def(double_precision, include_complex=True):
if include_complex:<EOL><INDENT>with open(os.path.abspath(resource_filename('<STR_LIT>', '<STR_LIT>')), '<STR_LIT:r>') as f:<EOL><INDENT>complex_number_support = f.read()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>complex_number_support = '<STR_LIT>'<EOL><DEDENT>scipy_constants = '''<STR_LIT>'''<EOL>if double_precision:<EOL...
Get the model floating point type definition. Args: double_precision (boolean): if True we will use the double type for the mot_float_type type. Else, we will use the single precision float type for the mot_float_type type. include_complex (boolean): if we include support for complex nu...
f15561:m8
def topological_sort(data):
def check_self_dependencies(input_data):<EOL><INDENT>"""<STR_LIT>"""<EOL>for k, v in input_data.items():<EOL><INDENT>if k in v:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(k))<EOL><DEDENT><DEDENT><DEDENT>def prepare_input_data(input_data):<EOL><INDENT>"""<STR_LIT>"""<EOL>return {k: set(v) for k, v in input_data.ite...
Topological sort the given dictionary structure. Args: data (dict); dictionary structure where the value is a list of dependencies for that given key. For example: ``{'a': (), 'b': ('a',)}``, where ``a`` depends on nothing and ``b`` depends on ``a``. Returns: tuple: the dependencie...
f15561:m9
def is_scalar(value):
return np.isscalar(value) or (isinstance(value, np.ndarray) and (len(np.squeeze(value).shape) == <NUM_LIT:0>))<EOL>
Test if the given value is a scalar. This function also works with memory mapped array values, in contrast to the numpy is_scalar method. Args: value: the value to test for being a scalar value Returns: boolean: if the given value is a scalar or not
f15561:m10
def all_elements_equal(value):
if is_scalar(value):<EOL><INDENT>return True<EOL><DEDENT>return np.array(value == value.flatten()[<NUM_LIT:0>]).all()<EOL>
Checks if all elements in the given value are equal to each other. If the input is a single value the result is trivial. If not, we compare all the values to see if they are exactly the same. Args: value (ndarray or number): a numpy array or a single number. Returns: bool: true if all...
f15561:m11
def get_single_value(value):
if not all_elements_equal(value):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if is_scalar(value):<EOL><INDENT>return value<EOL><DEDENT>return value.item(<NUM_LIT:0>)<EOL>
Get a single value out of the given value. This is meant to be used after a call to :func:`all_elements_equal` that returned True. With this function we return a single number from the input value. Args: value (ndarray or number): a numpy array or a single number. Returns: number: a s...
f15561:m12
@contextmanager<EOL>def all_logging_disabled(highest_level=logging.CRITICAL):
previous_level = logging.root.manager.disable<EOL>logging.disable(highest_level)<EOL>try:<EOL><INDENT>yield<EOL><DEDENT>finally:<EOL><INDENT>logging.disable(previous_level)<EOL><DEDENT>
Disable all logging temporarily. A context manager that will prevent any logging messages triggered during the body from being processed. Args: highest_level: the maximum logging level that is being blocked
f15561:m13
def cartesian(arrays, out=None):
arrays = [np.asarray(x) for x in arrays]<EOL>dtype = arrays[<NUM_LIT:0>].dtype<EOL>nmr_elements = np.prod([x.size for x in arrays])<EOL>if out is None:<EOL><INDENT>out = np.zeros([nmr_elements, len(arrays)], dtype=dtype)<EOL><DEDENT>m = nmr_elements // arrays[<NUM_LIT:0>].size<EOL>out[:, <NUM_LIT:0>] = np.repeat(arrays...
Generate a cartesian product of input arrays. Args: arrays (list of array-like): 1-D arrays to form the cartesian product of. out (ndarray): Array to place the cartesian product in. Returns: ndarray: 2-D array of shape (M, len(arrays)) containing cartesian products formed of input arra...
f15561:m14
def split_in_batches(nmr_elements, max_batch_size):
offset = <NUM_LIT:0><EOL>elements_left = nmr_elements<EOL>while elements_left > <NUM_LIT:0>:<EOL><INDENT>next_batch = (offset, offset + min(elements_left, max_batch_size))<EOL>yield next_batch<EOL>batch_size = min(elements_left, max_batch_size)<EOL>elements_left -= batch_size<EOL>offset += batch_size<EOL><DEDENT>
Split the total number of elements into batches of the specified maximum size. Examples:: split_in_batches(30, 8) -> [(0, 8), (8, 15), (16, 23), (24, 29)] for batch_start, batch_end in split_in_batches(2000, 100): array[batch_start:batch_end] Yields: tuple: the start and e...
f15561:m15
def covariance_to_correlations(covariance):
diagonal_ind = np.arange(covariance.shape[<NUM_LIT:1>])<EOL>diagonal_els = covariance[:, diagonal_ind, diagonal_ind]<EOL>result = covariance / np.sqrt(diagonal_els[:, :, None] * diagonal_els[:, None, :])<EOL>result[np.isinf(result)] = <NUM_LIT:0><EOL>return np.clip(np.nan_to_num(result), -<NUM_LIT:1>, <NUM_LIT:1>)<EOL>
Transform a covariance matrix into a correlations matrix. This can be seen as dividing a covariance matrix by the outer product of the diagonal. As post processing we replace the infinities and the NaNs with zeros and clip the result to [-1, 1]. Args: covariance (ndarray): a matrix of shape (n, p...
f15561:m16
def multiprocess_mapping(func, iterable):
if os.name == '<STR_LIT>': <EOL><INDENT>return list(map(func, iterable))<EOL><DEDENT>try:<EOL><INDENT>p = multiprocessing.Pool()<EOL>return_data = list(p.imap(func, iterable))<EOL>p.close()<EOL>p.join()<EOL>return return_data<EOL><DEDENT>except OSError:<EOL><INDENT>return list(map(func, iterable))<EOL><DEDENT>
Multiprocess mapping the given function on the given iterable. This only works in Linux and Mac systems since Windows has no forking capability. On Windows we fall back on single processing. Also, if we reach memory limits we fall back on single cpu processing. Args: func (func): the function to a...
f15561:m17
def parse_cl_function(cl_code, dependencies=()):
from mot.lib.cl_function import SimpleCLFunction<EOL>def separate_cl_functions(input_str):<EOL><INDENT>"""<STR_LIT>"""<EOL>class Semantics:<EOL><INDENT>def __init__(self):<EOL><INDENT>self._functions = []<EOL><DEDENT>def result(self, ast):<EOL><INDENT>return self._functions<EOL><DEDENT>def arglist(self, ast):<EOL><INDE...
Parse the given OpenCL string to a single SimpleCLFunction. If the string contains more than one function, we will return only the last, with all the other added as a dependency. Args: cl_code (str): the input string containing one or more functions. dependencies (Iterable[CLCodeObject]): ...
f15561:m18
def split_cl_function(cl_str):
class Semantics:<EOL><INDENT>def __init__(self):<EOL><INDENT>self._return_type = '<STR_LIT>'<EOL>self._function_name = '<STR_LIT>'<EOL>self._parameter_list = []<EOL>self._cl_body = '<STR_LIT>'<EOL><DEDENT>def result(self, ast):<EOL><INDENT>return self._return_type, self._function_name, self._parameter_list, self._cl_bo...
Split an CL function into a return type, function name, parameters list and the body. Args: cl_str (str): the CL code to parse and plit into components Returns: tuple: string elements for the return type, function name, parameter list and the body
f15561:m19
def apply_cl_function(cl_function, kernel_data, nmr_instances, use_local_reduction=False, cl_runtime_info=None):
cl_runtime_info = cl_runtime_info or CLRuntimeInfo()<EOL>cl_environments = cl_runtime_info.cl_environments<EOL>for param in cl_function.get_parameters():<EOL><INDENT>if param.name not in kernel_data:<EOL><INDENT>names = [param.name for param in cl_function.get_parameters()]<EOL>missing_names = [name for name in names i...
Run the given function/procedure on the given set of data. This class will wrap the given CL function in a kernel call and execute that that for every data instance using the provided kernel data. This class will respect the read write setting of the kernel data elements such that output can be written bac...
f15562:m0
def get_cl_code(self):
raise NotImplementedError()<EOL>
Get the CL code for this code object and all its dependencies, with include guards. Returns: str: The CL code for inclusion in a kernel.
f15562:c0:m0
def get_return_type(self):
raise NotImplementedError()<EOL>
Get the type (in CL naming) of the returned value from this function. Returns: str: The return type of this CL function. (Examples: double, int, double4, ...)
f15562:c1:m0
def get_cl_function_name(self):
raise NotImplementedError()<EOL>
Return the calling name of the implemented CL function Returns: str: The name of this CL function
f15562:c1:m1
def get_parameters(self):
raise NotImplementedError()<EOL>
Return the list of parameters from this CL function. Returns: list of :class:`mot.lib.cl_function.CLFunctionParameter`: list of the parameters in this model in the same order as in the CL function
f15562:c1:m2
def get_signature(self):
raise NotImplementedError()<EOL>
Get the CL signature of this function. Returns: str: the CL code for the signature of this CL function.
f15562:c1:m3
def get_cl_code(self):
raise NotImplementedError()<EOL>
Get the function code for this function and all its dependencies, with include guards. Returns: str: The CL code for inclusion in a kernel.
f15562:c1:m4