pisa package

Subpackages

Module contents

Define globals available to all modules in PISA

pisa.CACHE_DIR = '/home/runner/.cache/pisa'

Root directory for storing PISA cache files

pisa.CTYPE

Global complex-valued floating-point data type. C, CUDA, and Numba datatype definitions are derived from this

pisa.EPSILON = 1e-12

Best precision considering HASH_SIGFIGS (which is chosen kinda ad-hoc but based on by FTYPE)

pisa.FTYPE

Global floating-point data type. C, CUDA, and Numba datatype definitions are derived from this

pisa.HASH_SIGFIGS = 12

Round to this many significant figures for hashing numbers, such that machine precision doesn’t cause effectively equivalent numbers to hash differently.

pisa.ITYPE

alias of int64

pisa.OMP_NUM_THREADS = 1

Number of threads OpenMP is allocated

class pisa.OrderedDict[source]

Bases: dict

Dictionary that remembers insertion order

clear() None.  Remove all items from od.
copy() a shallow copy of od
fromkeys(value=None)

Create a new ordered dictionary with keys from iterable and values set to value.

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
move_to_end(key, last=True)

Move an existing element to the end (or beginning if last is false).

Raise KeyError if the element does not exist.

pop(key[, default]) v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem(last=True)

Remove and return a (key, value) pair from the dictionary.

Pairs are returned in LIFO order if last is true or FIFO order if false.

setdefault(key, default=None)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() an object providing a view on D's values
pisa.PISA_NUM_THREADS = 1

Global limit for number of threads

pisa.Q_

Shortcut for Quantity that uses central PISA Pint unit regeistry

pisa.array()
array(object, dtype=None, *, copy=True, order=’K’, subok=False, ndmin=0,

like=None)

Create an array.

Parameters:
  • object (array_like) – An array, any object exposing the array interface, an object whose __array__ method returns an array, or any (nested) sequence. If object is a scalar, a 0-dimensional array containing object is returned.

  • dtype (data-type, optional) – The desired data-type for the array. If not given, then the type will be determined as the minimum type required to hold the objects in the sequence.

  • copy (bool, optional) – If true (default), then the object is copied. Otherwise, a copy will only be made if __array__ returns a copy, if obj is a nested sequence, or if a copy is needed to satisfy any of the other requirements (dtype, order, etc.).

  • order ({'K', 'A', 'C', 'F'}, optional) –

    Specify the memory layout of the array. If object is not an array, the newly created array will be in C order (row major) unless ‘F’ is specified, in which case it will be in Fortran order (column major). If object is an array the following holds.

    order

    no copy

    copy=True

    ’K’

    unchanged

    F & C order preserved, otherwise most similar order

    ’A’

    unchanged

    F order if input is F and not C, otherwise C order

    ’C’

    C order

    C order

    ’F’

    F order

    F order

    When copy=False and a copy is made for other reasons, the result is the same as if copy=True, with some exceptions for ‘A’, see the Notes section. The default order is ‘K’.

  • subok (bool, optional) – If True, then sub-classes will be passed-through, otherwise the returned array will be forced to be a base-class array (default).

  • ndmin (int, optional) – Specifies the minimum number of dimensions that the resulting array should have. Ones will be pre-pended to the shape as needed to meet this requirement.

  • like (array_like) –

    Reference object to allow the creation of arrays which are not NumPy arrays. If an array-like passed in as like supports the __array_function__ protocol, the result will be defined by it. In this case, it ensures the creation of an array object compatible with that passed in via this argument.

    Added in version 1.20.0.

Returns:

out – An array object satisfying the specified requirements.

Return type:

ndarray

See also

empty_like

Return an empty array with shape and type of input.

ones_like

Return an array of ones with shape and type of input.

zeros_like

Return an array of zeros with shape and type of input.

full_like

Return a new array with shape of input filled with value.

empty

Return a new uninitialized array.

ones

Return a new array setting values to one.

zeros

Return a new array setting values to zero.

full

Return a new array of given shape filled with value.

Notes

When order is ‘A’ and object is an array in neither ‘C’ nor ‘F’ order, and a copy is forced by a change in dtype, then the order of the result is not necessarily ‘C’ as expected. This is likely a bug.

Examples

>>> np.array([1, 2, 3])
array([1, 2, 3])

Upcasting:

>>> np.array([1, 2, 3.0])
array([ 1.,  2.,  3.])

More than one dimension:

>>> np.array([[1, 2], [3, 4]])
array([[1, 2],
       [3, 4]])

Minimum dimensions 2:

>>> np.array([1, 2, 3], ndmin=2)
array([[1, 2, 3]])

Type provided:

>>> np.array([1, 2, 3], dtype=complex)
array([ 1.+0.j,  2.+0.j,  3.+0.j])

Data-type consisting of more than one element:

>>> x = np.array([(1,2),(3,4)],dtype=[('a','<i4'),('b','<i4')])
>>> x['a']
array([1, 3])

Creating an array from sub-classes:

>>> np.array(np.mat('1 2; 3 4'))
array([[1, 2],
       [3, 4]])
>>> np.array(np.mat('1 2; 3 4'), subok=True)
matrix([[1, 2],
        [3, 4]])
class pisa.complex128(real=0, imag=0)

Bases: complexfloating, complex

Complex number type composed of two double-precision floating-point numbers, compatible with Python complex.

Character code:

'D'

Canonical name:

numpy.cdouble

Alias:

numpy.cfloat

Alias:

numpy.complex_

Alias on this platform (Linux x86_64):

numpy.complex128: Complex number type composed of 2 64-bit-precision floating-point numbers.

class pisa.complex256

Bases: complexfloating

Complex number type composed of two extended-precision floating-point numbers.

Character code:

'G'

Canonical name:

numpy.clongdouble

Alias:

numpy.clongfloat

Alias:

numpy.longcomplex

Alias on this platform (Linux x86_64):

numpy.complex256: Complex number type composed of 2 128-bit extended-precision floating-point numbers.

class pisa.complex64

Bases: complexfloating

Complex number type composed of two single-precision floating-point numbers.

Character code:

'F'

Canonical name:

numpy.csingle

Alias:

numpy.singlecomplex

Alias on this platform (Linux x86_64):

numpy.complex64: Complex number type composed of 2 32-bit-precision floating-point numbers.

class pisa.float32

Bases: floating

Single-precision floating-point number type, compatible with C float.

Character code:

'f'

Canonical name:

numpy.single

Alias on this platform (Linux x86_64):

numpy.float32: 32-bit-precision floating-point number type: sign bit, 8 bits exponent, 23 bits mantissa.

as_integer_ratio()

Return a pair of integers, whose ratio is exactly equal to the original floating point number, and with a positive denominator. Raise OverflowError on infinities and a ValueError on NaNs.

>>> np.single(10.0).as_integer_ratio()
(10, 1)
>>> np.single(0.0).as_integer_ratio()
(0, 1)
>>> np.single(-.25).as_integer_ratio()
(-1, 4)
is_integer() bool

Return True if the floating point number is finite with integral value, and False otherwise.

Added in version 1.22.

Examples

>>> np.single(-2.0).is_integer()
True
>>> np.single(3.2).is_integer()
False
class pisa.float64(x=0, /)

Bases: floating, float

Double-precision floating-point number type, compatible with Python float and C double.

Character code:

'd'

Canonical name:

numpy.double

Alias:

numpy.float_

Alias on this platform (Linux x86_64):

numpy.float64: 64-bit precision floating-point number type: sign bit, 11 bits exponent, 52 bits mantissa.

as_integer_ratio()

Return a pair of integers, whose ratio is exactly equal to the original floating point number, and with a positive denominator. Raise OverflowError on infinities and a ValueError on NaNs.

>>> np.double(10.0).as_integer_ratio()
(10, 1)
>>> np.double(0.0).as_integer_ratio()
(0, 1)
>>> np.double(-.25).as_integer_ratio()
(-1, 4)
is_integer() bool

Return True if the floating point number is finite with integral value, and False otherwise.

Added in version 1.22.

Examples

>>> np.double(-2.0).is_integer()
True
>>> np.double(3.2).is_integer()
False
pisa.int0

alias of int64

class pisa.int16

Bases: signedinteger

Signed integer type, compatible with C short.

Character code:

'h'

Canonical name:

numpy.short

Alias on this platform (Linux x86_64):

numpy.int16: 16-bit signed integer (-32_768 to 32_767).

bit_count() int

Computes the number of 1-bits in the absolute value of the input. Analogous to the builtin int.bit_count or popcount in C++.

Examples

>>> np.int16(127).bit_count()
7
>>> np.int16(-127).bit_count()
7
class pisa.int32

Bases: signedinteger

Signed integer type, compatible with C int.

Character code:

'i'

Canonical name:

numpy.intc

Alias on this platform (Linux x86_64):

numpy.int32: 32-bit signed integer (-2_147_483_648 to 2_147_483_647).

bit_count() int

Computes the number of 1-bits in the absolute value of the input. Analogous to the builtin int.bit_count or popcount in C++.

Examples

>>> np.int32(127).bit_count()
7
>>> np.int32(-127).bit_count()
7
class pisa.int64

Bases: signedinteger

Signed integer type, compatible with Python int and C long.

Character code:

'l'

Canonical name:

numpy.int_

Alias on this platform (Linux x86_64):

numpy.int64: 64-bit signed integer (-9_223_372_036_854_775_808 to 9_223_372_036_854_775_807).

Alias on this platform (Linux x86_64):

numpy.intp: Signed integer large enough to fit pointer, compatible with C intptr_t.

bit_count() int

Computes the number of 1-bits in the absolute value of the input. Analogous to the builtin int.bit_count or popcount in C++.

Examples

>>> np.int64(127).bit_count()
7
>>> np.int64(-127).bit_count()
7
class pisa.int8

Bases: signedinteger

Signed integer type, compatible with C char.

Character code:

'b'

Canonical name:

numpy.byte

Alias on this platform (Linux x86_64):

numpy.int8: 8-bit signed integer (-128 to 127).

bit_count() int

Computes the number of 1-bits in the absolute value of the input. Analogous to the builtin int.bit_count or popcount in C++.

Examples

>>> np.int8(127).bit_count()
7
>>> np.int8(-127).bit_count()
7
pisa.namedtuple(typename, field_names, *, rename=False, defaults=None, module=None)[source]

Returns a new subclass of tuple with named fields.

>>> Point = namedtuple('Point', ['x', 'y'])
>>> Point.__doc__                   # docstring for the new class
'Point(x, y)'
>>> p = Point(11, y=22)             # instantiate with positional args or keywords
>>> p[0] + p[1]                     # indexable like a plain tuple
33
>>> x, y = p                        # unpack like a regular tuple
>>> x, y
(11, 22)
>>> p.x + p.y                       # fields also accessible by name
33
>>> d = p._asdict()                 # convert to a dictionary
>>> d['x']
11
>>> Point(**d)                      # convert from a dictionary
Point(x=11, y=22)
>>> p._replace(x=100)               # _replace() is like str.replace() but targets named fields
Point(x=100, y=22)
pisa.numba_jit(signature_or_function=None, locals={}, cache=False, pipeline_class=None, boundscheck=None, **options)

This decorator is used to compile a Python function into native code.

Parameters:
  • signature_or_function – The (optional) signature or list of signatures to be compiled. If not passed, required signatures will be compiled when the decorated function is called, depending on the argument values. As a convenience, you can directly pass the function to be compiled instead.

  • locals (dict) – Mapping of local variable names to Numba types. Used to override the types deduced by Numba’s type inference engine.

  • pipeline_class (type numba.compiler.CompilerBase) – The compiler pipeline type for customizing the compilation stages.

  • options

    For a cpu target, valid options are:
    nopython: bool

    Set to True to disable the use of PyObjects and Python API calls. The default behavior is to allow the use of PyObjects and Python API. Default value is True.

    forceobj: bool

    Set to True to force the use of PyObjects for every value. Default value is False.

    looplift: bool

    Set to True to enable jitting loops in nopython mode while leaving surrounding code in object mode. This allows functions to allocate NumPy arrays and use Python objects, while the tight loops in the function can still be compiled in nopython mode. Any arrays that the tight loop uses should be created before the loop is entered. Default value is True.

    error_model: str

    The error-model affects divide-by-zero behavior. Valid values are ‘python’ and ‘numpy’. The ‘python’ model raises exception. The ‘numpy’ model sets the result to +/-inf or nan. Default value is ‘python’.

    inline: str or callable

    The inline option will determine whether a function is inlined at into its caller if called. String options are ‘never’ (default) which will never inline, and ‘always’, which will always inline. If a callable is provided it will be called with the call expression node that is requesting inlining, the caller’s IR and callee’s IR as arguments, it is expected to return Truthy as to whether to inline. NOTE: This inlining is performed at the Numba IR level and is in no way related to LLVM inlining.

    boundscheck: bool or None

    Set to True to enable bounds checking for array indices. Out of bounds accesses will raise IndexError. The default is to not do bounds checking. If False, bounds checking is disabled, out of bounds accesses can produce garbage results or segfaults. However, enabling bounds checking will slow down typical functions, so it is recommended to only use this flag for debugging. You can also set the NUMBA_BOUNDSCHECK environment variable to 0 or 1 to globally override this flag. The default value is None, which under normal execution equates to False, but if debug is set to True then bounds checking will be enabled.

Returns:

  • A callable usable as a compiled function. Actual compiling will be

  • done lazily if no explicit signatures are passed.

Examples

The function can be used in the following ways:

  1. jit(signatures, **targetoptions) -> jit(function)

    Equivalent to:

    d = dispatcher(function, targetoptions) for signature in signatures:

    d.compile(signature)

    Create a dispatcher object for a python function. Then, compile the function with the given signature(s).

    Example:

    @jit(“int32(int32, int32)”) def foo(x, y):

    return x + y

    @jit([“int32(int32, int32)”, “float32(float32, float32)”]) def bar(x, y):

    return x + y

  2. jit(function, **targetoptions) -> dispatcher

    Create a dispatcher function object that specializes at call site.

    Examples:

    @jit def foo(x, y):

    return x + y

    @jit(nopython=True) def bar(x, y):

    return x + y

pisa.uint0

alias of uint64

class pisa.uint16

Bases: unsignedinteger

Unsigned integer type, compatible with C unsigned short.

Character code:

'H'

Canonical name:

numpy.ushort

Alias on this platform (Linux x86_64):

numpy.uint16: 16-bit unsigned integer (0 to 65_535).

bit_count() int

Computes the number of 1-bits in the absolute value of the input. Analogous to the builtin int.bit_count or popcount in C++.

Examples

>>> np.uint16(127).bit_count()
7
class pisa.uint32

Bases: unsignedinteger

Unsigned integer type, compatible with C unsigned int.

Character code:

'I'

Canonical name:

numpy.uintc

Alias on this platform (Linux x86_64):

numpy.uint32: 32-bit unsigned integer (0 to 4_294_967_295).

bit_count() int

Computes the number of 1-bits in the absolute value of the input. Analogous to the builtin int.bit_count or popcount in C++.

Examples

>>> np.uint32(127).bit_count()
7
class pisa.uint64

Bases: unsignedinteger

Unsigned integer type, compatible with C unsigned long.

Character code:

'L'

Canonical name:

numpy.uint

Alias on this platform (Linux x86_64):

numpy.uint64: 64-bit unsigned integer (0 to 18_446_744_073_709_551_615).

Alias on this platform (Linux x86_64):

numpy.uintp: Unsigned integer large enough to fit pointer, compatible with C uintptr_t.

bit_count() int

Computes the number of 1-bits in the absolute value of the input. Analogous to the builtin int.bit_count or popcount in C++.

Examples

>>> np.uint64(127).bit_count()
7
class pisa.uint8

Bases: unsignedinteger

Unsigned integer type, compatible with C unsigned char.

Character code:

'B'

Canonical name:

numpy.ubyte

Alias on this platform (Linux x86_64):

numpy.uint8: 8-bit unsigned integer (0 to 255).

bit_count() int

Computes the number of 1-bits in the absolute value of the input. Analogous to the builtin int.bit_count or popcount in C++.

Examples

>>> np.uint8(127).bit_count()
7
pisa.ureg = <pint.registry.UnitRegistry object>

Single Pint unit registry that should be used by all PISA code