dedalus.tools.array

Tools for array manipulations.

Module Contents

SPLIT_CSR_MATVECS
OLD_CSR_MATVECS
interleaved_view(data)

View n-dim complex array as (n+1)-dim real array, where the last axis separates real and imaginary parts.

reshape_vector(data, dim=2, axis=-1)

Reshape 1-dim array as a multidimensional vector.

axindex(axis, index)

Index array along specified axis.

axslice(axis, start, stop, step=None)

Slice array along a specified axis.

zeros_with_pattern(*args)

Create sparse matrix with the combined pattern of other sparse matrices.

expand_pattern(input, pattern)

Return copy of sparse matrix with extended pattern.

apply_matrix(matrix, array, axis, **kw)

Apply matrix along any axis of an array.

apply_dense_einsum(matrix, array, axis, optimize=True, **kw)

Apply dense matrix along any axis of an array.

move_single_axis(a, source, destination)

Similar to np.moveaxis but faster for just a single axis.

apply_dense(matrix, array, axis, out=None)

Apply dense matrix along any axis of an array.

splu_inverse(matrix, permc_spec='NATURAL', **kw)

Create LinearOperator implicitly acting as a sparse matrix inverse.

apply_sparse_dot(matrix, array, axis, out=None)

Apply sparse matrix along any axis of an array.

apply_sparse(matrix, array, axis, out=None, check_shapes=False, num_threads=1)

Apply sparse matrix along any axis of an array. Must be out of place if ouptut is specified.

solve_upper_sparse(matrix, rhs, axis, out=None, check_shapes=False, num_threads=1)

Solve upper triangular sparse matrix along any axis of an array. Matrix assumed to be nonzero on the diagonals.

csr_matvec(A_csr, x_vec, out_vec)

Fast CSR matvec with dense vector skipping output allocation. The result is added to the specificed output array, so the output should be manually zeroed prior to calling this routine, if necessary.

csr_matvecs(A_csr, x_vec, out_vec)

Fast CSR matvec with dense vector skipping output allocation. The result is added to the specificed output array, so the output should be manually zeroed prior to calling this routine, if necessary.

add_sparse(A, B)

Add sparse matrices, promoting scalars to multiples of the identity.

sparse_block_diag(blocks, shape=None)

Build a block diagonal sparse matrix allowing size 0 matrices.

kron(*factors)
nkron(factor, n)
permute_axis(array, axis, permutation, out=None)
copyto(dest, src)
perm_matrix(perm, M=None, source_index=False, sparse=True)

Build sparse permutation matrix from permutation vector.

Parameters:
  • perm (ndarray) – Permutation vector.

  • M (int, optional) – Output dimension. Default: len(perm).

  • source_index (bool, optional) –

    False (default) if perm entries indicate destination index:

    output[i,j] = (i == perm[j])

    True if perm entires indicate source index:

    output[i,j] = (j == perm[i])

  • sparse (bool, optional) – Whether to return sparse matrix or dense array (default: True).

drop_empty_rows(mat)
scipy_sparse_eigs(A, B, left, N, target, matsolver, **kw)

Perform targeted eigenmode search using the scipy/ARPACK sparse solver for the reformulated generalized eigenvalue problem

A.x = λ B.x ==> (A - σB)^I B.x = (1/(λ-σ)) x

for eigenvalues λ near the target σ.

Parameters:
  • A, B (scipy sparse matrices) – Sparse matrices for generalized eigenvalue problem

  • N (int) – Number of eigenmodes to return

  • left (boolean) – Whether to solve for the left eigenvectors or not

  • target (complex) – Target σ for eigenvalue search

  • matsolver (matrix solver class) – Class implementing solve method for solving sparse systems.

  • Other keyword options passed to scipy.sparse.linalg.eigs.

interleave_matrices(matrices)
sparse_allclose(A, B)
assert_sparse_pinv(A, B)