# Can I use CuSpareMatrixCSC with Complex entries for ODE solving?

**URL:** <https://discourse.julialang.org/t/can-i-use-cusparematrixcsc-with-complex-entries-for-ode-solving/122080>\
**Category:** GPU\
**Tags:** cuda, differentialequation\
**Created:** [October 31, 2024, 2:44pm UTC](https://discourse.julialang.org/t/can-i-use-cusparematrixcsc-with-complex-entries-for-ode-solving/122080 "2024-10-31T14:44:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![joseph-t-lee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joseph-t-lee/32/212353_2.png) [@joseph-t-lee](https://discourse.julialang.org/u/joseph-t-lee)\
**Post date:** [October 31, 2024, 2:44pm UTC](https://discourse.julialang.org/t/can-i-use-cusparematrixcsc-with-complex-entries-for-ode-solving/122080/1 "2024-10-31T14:44:54Z")

</div>

(Apologies if this is confusing - this is my first post, and first time I haven’t been able to find my answer already on the forum!)

I have been trying to rewrite some old CPU code that used Sparse Matrices with ComplexF64 entries. My silly solution for this has been to take all of my sparse arrays and recast them via

```julia
A_d = CuSparseMatrixCSC(A)

```

giving me a typeof(A\_d) = CuSparseMatrixCSC{ComplexF64, Int32}.

When I try to solve my ODE using the DifferentialEquations package, I obtain the following error:

```julia
MethodError: no method matching CuSparseMatrixCSC{ComplexF64, Int32}(::SparseMatrixCSC{ComplexF64, Int64})
The type `CuSparseMatrixCSC{ComplexF64, Int32}` exists, but no method is defined for this combination of argument types when trying to construct it.

```

Is there a way for me to use sparse Cuda arrays with complex entries just by recasting them to the right type? Or will this require something much more involved. Happy to share whatever code excerpts that may be useful!

---

<div class="post-metadata">

**Author:** ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)\
**Post date:** [October 31, 2024, 6:02pm UTC](https://discourse.julialang.org/t/can-i-use-cusparematrixcsc-with-complex-entries-for-ode-solving/122080/2 "2024-10-31T18:02:47Z")

</div>

The constructors we have do not take an index type, because CUSPARSE only supports Int32 indices: [CUDA.jl/lib/cusparse/array.jl at 7d23bbf50bd8792f2ba81248c3e1f21079a39bff · JuliaGPU/CUDA.jl · GitHub](https://github.com/JuliaGPU/CUDA.jl/blob/7d23bbf50bd8792f2ba81248c3e1f21079a39bff/lib/cusparse/array.jl#L440-L514). So calling the constructor should work fine if you drop the `Int32`. This could probably be improved; PRs welcome.

Also note that you can simply create sparse CPU arrays by calling `cu` on sparse CPU arrays.
