pyPRISM.core.MatrixArray module

class pyPRISM.core.MatrixArray.MatrixArray(length, rank, data=None, space=<Space.Real: 1>, types=None)[source]

Bases: object

A container for creating and interacting with arrays of matrices

Description

The primary data structure of MatrixArray is simply a 3D Numpy array with the first dimension accessing each individual matrix in the array and the last two dimenions corresponding to the vertical and horizontal index of each matrix element.

The terminology pair-function is used to refer to the set of values from all matrices in the array at a given matrix index pair. In Numpy slicing parlance:

pair_11 = numpy_array[:,1,1]
pair_12 = numpy_array[:,1,2]

Access to the MatrixArray is either by supplied types or numerical indices. If types are not supplied, captial letters starting from ‘A’ are used.

See the example below and the pyPRISM Internals section of the Tutorial for more information.

Example

mArray = MatrixArray(length=1024,rank=2,types=['polymer','solvent'])

mArray['polymer','solvent'] == mArray['solvent','polymer'] == mArray.get(0,1)
SpaceError = 'Attempting MatrixArray math in non-matching spaces'
__getitem__(key)[source]

pair-function getter

Parameters:
  • key (tuple of types) – Type pair used to identify pair
  • val (np.ndarray) – Values of pair-function
__imul__(other)[source]

Scalar or elementwise multiplication

__init__(length, rank, data=None, space=<Space.Real: 1>, types=None)[source]

Constructor

Parameters:
  • length (int) – Number of matrices in array. For PRISM theory, this corresponds to the number of grid points in real- and Fourier-space i.e. Domain.size.
  • rank (int) – Number of rows/cols of each (square) matrix. For PRISM theory, this also equal to the number of site types.
  • data (np.ndarray, size (length,rank,rank)) – Interface for specifying the MatrixArray data directly. If not given, all values in all matrices will be set to zero.
  • space (pyPRISM.core.Space.Space) – Enumerated value tracking whether the array represents real or Fourier spaced data. As we will be transferring arrays to and from these spaces, it’s important for safety that we track this.
  • types (list, optional) – List of semantic types that are be used to reference data. These types will be output by the iterpair method as well. If not supplied, uppercase letters will be used.
__itruediv__(other)[source]

Scalar or elementwise division

__mul__(other)[source]

Scalar or elementwise multiplication

__setitem__(key, val)[source]

pair-function setter

Parameters:
  • key (tuple of types) – Type pair used to identify pair
  • val (np.ndarray) – Values of pair-function

Assumes all matrices are symmetric and enforces symmetry by setting the off-diagonal elements to be equal.

__truediv__(other)[source]

Scalar or elementwise division

dot(other, inplace=False)[source]

Matrix multiplication for each matrix in two MatrixArrays

Parameters:
  • other (object, MatrixArray) – Must be an object of MatrixArray type of the same length and dimension
  • inplace (bool) – If False, a new MatrixArray is returned, otherwise just update the internal data.
get(index1, index2)[source]

pair-function getter via indices

This method should be slightly more efficient than the standard __getitem__.

getMatrix(matrix_index)[source]

Matrix getter via indices

get_copy()[source]

Return an independent copy of this MatrixArray

invert(inplace=False)[source]

Perform matrix inversion on all matrices in the MatrixArray

Parameters:inplace (bool) – If False, a new MatrixArray is returned, otherwise just update the internal data.
itercurve()[source]
iterpairs()[source]

Iterate over the pair-function in this MatrixArray

Yields:
  • (i,j) (2-tuple of integers) – numerical index to the underlying data numpy array
  • (t1,t2) (2-tuple of string types) – string index to the underlying data numpy array
  • pair-function (np.ndarray, size (self.length)) – 1-D array representing a pair-function within the MatrixArray
setMatrix(matrix_index, value)[source]

Matrix setter via indices