tftb package

Submodules

tftb.utils module

Miscellaneous utilities.

tftb.utils.divider(N)[source]

Compute two factors of N such that they are as close as possible to sqrt(N).

Parameters:N (int) – Number to be divided.
Returns:A tuple of two integers such that their product is N and they are the closest possible to \(\sqrt(N)\) # NOQA: W605
Return type:tuple(int)
Example:
>>> from __future__ import print_function
>>> print(divider(256))
(16.0, 16.0)
>>> print(divider(10))
(2.0, 5.0)
>>> print(divider(101))
(1.0, 101.0)
tftb.utils.is_linear(x, decimals=5)[source]

Check if an array is linear.

Parameters:
  • x (numpy.ndarray) – Array to be checked for linearity.
  • decimals (int) – decimal places upto which the derivative of the array should be rounded off (default=5)
Returns:

If the array is linear

Return type:

boolean

Example:
>>> import numpy as np
>>> x = np.linspace(0, 2 * np.pi, 100)
>>> is_linear(x)
True
>>> is_linear(np.sin(x))
False
tftb.utils.izak(x)[source]

Inverse Zak transform.

tftb.utils.modulo(x, N)[source]

Compute the congruence of each element of x modulo N.

Returns:array-like
Example:
>>> from __future__ import print_function
>>> print(modulo(range(1, 11), 2))
[1 2 1 2 1 2 1 2 1 2]
tftb.utils.nearest_odd(N)[source]

Get the nearest odd number for each value of N.

Parameters:N – int / sequence of ints
Returns:int / sequence of ints
Example:
>>> from __future__ import print_function
>>> print(nearest_odd(range(1, 11)))
[  1.   3.   3.   5.   5.   7.   7.   9.   9.  11.]
>>> nearest_odd(0)
1
>>> nearest_odd(3)
3.0
tftb.utils.nextpow2(n)[source]

Compute the integer exponent of the next higher power of 2.

Parameters:n (int, np.ndarray) – Number whose next higest power of 2 needs to be computed.
Return type:int, np.ndarray
Example:
>>> from __future__ import print_function
>>> import numpy as np
>>> x = np.arange(1, 9)
>>> print(nextpow2(x))
[ 0.  1.  2.  2.  3.  3.  3.  3.]

Module contents