4

How do I invert the following sparse matrix (named row_sparse_cupy below) created with the python library "cupy" using CUDA? The example code is

import cupy as cp
import numpy as np
import scipy.sparse as sp
N=100
row_sparse = sp.csr_matrix(np.identity(100))
add=np.random.standard_normal((10,10))
row_sparse[:10,:10]=add # (just creating some general non-identity matrix)
row_sparse_cupy=cp.sparse.csr_matrix(row_sparse,dtype=cp.float32)

My original problem is set up in terms of a general big sparse matrix (N=100000). My goal is to calculate the inverse on my GPU. The structure of my original matrix is of general form with a multitude of zero entries (and being invertible, of course).

talonmies
  • 70,661
  • 34
  • 192
  • 269
user823
  • 265
  • 2
  • 14
  • 1
    I don't think there is a direct way to invert it in cupy. The question is often asked "why do you want to invert a matrix?" because it is often considered [a bad idea](https://www.johndcook.com/blog/2010/01/19/dont-invert-that-matrix/). If you were inverting the matrix to solve a sparse linear system, then cupy provides [this](https://docs-cupy.chainer.org/en/stable/reference/generated/cupyx.scipy.sparse.linalg.lsqr.html#cupyx.scipy.sparse.linalg.lsqr). – Robert Crovella Jun 29 '19 at 15:31
  • @RobertCrovella Thank you for the pointer to cupyx.scipy.sparse.linalg.lsqr. It looks like it should have been mimicking [spsolve](https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.spsolve.html) (solving Ax=b for x given a square matrix A) rather than lsqr (an iterative least squares solver which is an entirely different beast). – egbit Dec 22 '20 at 02:33

0 Answers0