Helpers¶
This module contains various auxiliary functions which are used throughout the library.
-
reikna.helpers.
bounding_power_of_2
(num)¶ Returns the minimal number of the form
2**m
such that it is greater or equal ton
.
-
reikna.helpers.
factors
(num, limit=None)¶ Returns the list of pairs
(factor, num/factor)
for all factors ofnum
(including 1 andnum
), sorted byfactor
. Iflimit
is set, only pairs withfactor <= limit
are returned.
-
class
reikna.helpers.
ignore_integer_overflow
¶ Context manager for ignoring integer overflow in numpy operations on scalars (not ignored by default because of a bug in numpy).
-
reikna.helpers.
log2
(num)¶ Integer-valued logarigthm with base 2. If
n
is not a power of 2, the result is rounded to the smallest number.
-
reikna.helpers.
make_axes_innermost
(ndim, axes)¶ Given the total number of array axes and a list of axes in this range, produce a transposition plan (suitable e.g. for
numpy.transpose()
) that will move make the given axes innermost (in the order they’re given). Returns the transposition plan, and the plan to transpose the resulting array back to the original axes order.
-
reikna.helpers.
min_blocks
(length, block)¶ Returns minimum number of blocks with length
block
necessary to cover the array with lengthlength
.
-
reikna.helpers.
normalize_axes
(ndim, axes)¶ Transform an iterable of array axes (which can be negative) or a single axis into a tuple of non-negative axes.
-
reikna.helpers.
product
(seq)¶ Returns the product of elements in the iterable
seq
.
-
reikna.helpers.
template_def
(signature, code)¶ Returns a
Mako
template with the givensignature
.Parameters: signature – a list of postitional argument names, or a Signature
object fromfuncsigs
module.Code: a body of the template.
-
reikna.helpers.
template_for
(filename)¶ Returns the Mako template object created from the file which has the same name as
filename
and the extension.mako
. Typically used in computation modules astemplate_for(__filename__)
.
-
reikna.helpers.
template_from
(template)¶ Creates a Mako template object from a given string. If
template
already hasrender()
method, does nothing.
-
reikna.helpers.
wrap_in_tuple
(seq_or_elem)¶ If
seq_or_elem
is a sequence, converts it to atuple
, otherwise returns a tuple with a single elementseq_or_elem
.