dedalus.tools.array

Tools for array manipulations.

Module Contents

add_sparse(A, B)

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

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

Apply dense 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.

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

Apply 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.

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

Apply sparse matrix along any axis of an array.

assert_sparse_pinv(A, B)
axindex(axis, index)

Index array along specified axis.

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

Slice array along a specified axis.

copy_from_device(dest, src)
copy_to_device(dest, src)
copyto(dest, src)
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.

drop_empty_rows(mat)
expand_pattern(input, pattern)

Return copy of sparse matrix with extended pattern.

get_axpy(array_namespace, dtype)
interleave_matrices(matrices)
interleaved_view(data)

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

kron(*factors)
move_single_axis(a, source, destination)

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

nkron(factor, n)
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).

permute_axis(array, axis, permutation, out=None)
reshape_vector(data, dim=2, axis=-1)

Reshape 1-dim array as a multidimensional vector.

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.

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.

sparse_allclose(A, B)
sparse_block_diag(blocks, shape=None)

Build a block diagonal sparse matrix allowing size 0 matrices.

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

Create LinearOperator implicitly acting as a sparse matrix inverse.

zeros_with_pattern(*args)

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

OLD_CSR_MATVECS
SPLIT_CSR_MATVECS