pygsti.tools.matrixtools.csr_sum_flat_indices

pygsti.tools.matrixtools.csr_sum_flat_indices#

csr_sum_flat_indices(csr_matrices)#

Precomputes quantities allowing fast computation of linear combinations of CSR sparse matrices.

The returned quantities can later be used to quickly compute a linear combination of the CSR sparse matrices csr_matrices.

Computes the index and data arrays needed for use in csr_sum_flat(), along with the index pointer and column-indices arrays for constructing a “template” CSR matrix to be the destination of csr_sum_flat.

Parameters:

csr_matrices (list) – The SciPy CSR matrices to be summed.

Returns:

  • flat_dest_index_array (numpy array) – A 1D array of one element per nonzero element in any of csr_matrices, giving the destination-index of that element.

  • flat_csr_mx_data (numpy array) – A 1D array of the same length as flat_dest_index_array, which simply concatenates the data arrays of csr_matrices.

  • mx_nnz_indptr (numpy array) – A 1D array of length len(csr_matrices)+1 such that the data for the i-th element of csr_matrices lie in the index-range of mx_nnz_indptr[i] to mx_nnz_indptr[i+1]-1 of the flat arrays.

  • indptr, indices (numpy.ndarray) – The row-pointer and column-indices arrays specifying the sparsity structure of a the destination CSR matrix.

  • N (int) – The dimension of the destination matrix (and of each member of csr_matrices)