cora.util.nputil

Utility functions to help with pure numpy stuff.

Functions

complex_std_normal(shape[, rng])

Get a set of complex standard normal variables.

load_ndarray_list(fname)

Load a list of arrays saved by save_ndarray_list.

matrix_root_manynull(mat[, threshold, truncate])

Square root a matrix.

save_ndarray_list(fname, la)

Save a list of numpy arrays to disk.

cora.util.nputil.save_ndarray_list(fname, la)

Save a list of numpy arrays to disk.

This is designed so it can be reloaded exactly (with the exact same ordering) by load_ndarray_list.

Parameters:
  • fname (string) – filename to save to.

  • la (list of np.ndarrays) – list of arrays to save.

cora.util.nputil.load_ndarray_list(fname)

Load a list of arrays saved by save_ndarray_list.

Parameters:

fname (string) – filename to load.

Returns:

la – The list of loaded numpy arrays. This should be identical tp what was saved by save_ndarray_list.

Return type:

list of np.ndarrays

cora.util.nputil.matrix_root_manynull(mat, threshold=1e-16, truncate=True)

Square root a matrix.

An inefficient alternative to the Cholesky decomposition for a matrix with a large dynamic range in eigenvalues. Numerical roundoff causes Cholesky to fail as if the matrix were not positive semi-definite. This does an explicit eigen-decomposition, setting small and negative eigenvalue to zero.

Parameters:
  • ndarray (mat -) – An N x N matrix to decompose.

  • threshold (scalar, optional) – Set any eigenvalues a factor threshold smaller than the largest eigenvalue to zero.

  • truncate (boolean, optional) – If True (default), truncate the matrix root, to the number of positive eigenvalues.

Returns:

  • root (ndarray) – The decomposed matrix. This is truncated to the number of non-zero eigen values (if truncate is set).

  • num_pos (integer) – The number of positive eigenvalues (returned only if truncate is set).

cora.util.nputil.complex_std_normal(shape, rng=None)

Get a set of complex standard normal variables.

Parameters:
  • shape (tuple) – Shape of the array of variables.

  • rng (numpy RNG, optional) – Seeded random number generator to use. Default: None.

Returns:

var – Complex gaussian variates.

Return type:

np.ndarray[shape]