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.
min_blocks
(length, block)¶ Returns minimum number of blocks with length
block
necessary to cover the array with lengthlength
.
-
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
.