Repository: pytorch
Issue: Spsolve for sparse, complex matrices
Labels: module: sparse,triaged

### 🐛 Describe the bug

Sparse linear algebra matrix solver doesn't work with complex numbers on a GPU (solver not available at all on the CPU)

Sample Code:
```
import torch
from torch import sparse

n = 10
A = torch.rand(n, n).type(torch.complex128).to_sparse_csr().cuda()
b = torch.rand(n).type(torch.complex128).cuda()
return sparse.spsolve(A, b)
```

Traceback:
```
  File "test.py", line 36, in solve_matrix_equation
    return sparse.spsolve(A, b)
RuntimeError: "create_matrix" not implemented for 'ComplexDouble'
```

### Versions

Collecting environment information...
PyTorch version: 2.6.0a0+git99a0321
Is debug build: False
CUDA used to build PyTorch: 12.4
ROCM used to build PyTorch: N/A

OS: Rocky Linux release 8.10 (Green Obsidian) (x86_64)
GCC version: (GCC) 8.5.0 20210514 (Red Hat 8.5.0-22)
Clang version: Could not collect
CMake version: version 3.31.0
Libc version: glibc-2.28

Python version: 3.10.15 (main, Oct  3 2024, 07:27:34) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-4.18.0-553.8.1.el8_10.x86_64-x86_64-with-glibc2.28
Is CUDA available: True
CUDA runtime version: 12.4.131
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: Tesla V100-SXM2-16GB
Nvidia driver version: 555.42.06
cuDNN version: Probably one of the following:
/usr/lib64/libcudnn.so.8.9.7
/usr/lib64/libcudnn_adv_infer.so.8.9.7
/usr/lib64/libcudnn_adv_train.so.8.9.7
/usr/lib64/libcudnn_cnn_infer.so.8.9.7
/usr/lib64/libcudnn_cnn_train.so.8.9.7
/usr/lib64/libcudnn_ops_infer.so.8.9.7
/usr/lib64/libcudnn_ops_train.so.8.9.7
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              8
On-line CPU(s) list: 0-7
Thread(s) per core:  2
Core(s) per socket:  4
Socket(s):           1
NUMA node(s):        1
Vendor ID:           GenuineIntel
CPU family:          6
Model:               79
Model name:          Intel(R) Xeon(R) CPU E5-2686 v4 @ 2.30GHz
Stepping:            1
CPU MHz:             2703.014
CPU max MHz:         3000.0000
CPU min MHz:         1200.0000
BogoMIPS:            4600.03
Hypervisor vendor:   Xen
Virtualization type: full
L1d cache:           32K
L1i cache:           32K
L2 cache:            256K
L3 cache:            46080K
NUMA node0 CPU(s):   0-7
Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single pti fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm rdseed adx xsaveopt

Versions of relevant libraries:
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.26.4
[pip3] optree==0.13.1
[pip3] torch==2.6.0a0+git99a0321
[conda] blas                      1.0                         mkl  
[conda] magma-cuda124             2.6.1                         1    pytorch
[conda] mkl                       2023.1.0         h213fc3f_46344  
[conda] mkl-include               2025.0.1                 pypi_0    pypi
[conda] mkl-service               2.4.0           py310h5eee18b_1  
[conda] mkl-static                2025.0.1                 pypi_0    pypi
[conda] mkl_fft                   1.3.11          py310h5eee18b_0  
[conda] mkl_random                1.2.8           py310h1128e8f_0  
[conda] numpy                     1.26.4          py310h5f9d8c6_0  
[conda] numpy-base                1.26.4          py310hb5e798b_0  
[conda] optree                    0.13.1                   pypi_0    pypi
[conda] torch                     2.6.0a0+git99a0321          pypi_0    pypi


cc @alexsamardzic @nikitaved @pearu @cpuhrsch @amjames @bhosmer @jcaip