JuliaGPU / Adapt.jl

Other
86 stars 24 forks source link

Handling possibly sparse arrays #19

Closed tkf closed 4 years ago

tkf commented 4 years ago

Currently, converting a matrix that could be dense or sparse requires explicit branching:

if x isa SparseMatrixCSC
    # adapt(CuSparseMatrixCSC, x) does not work, BTW
    CuSparseMatrixCSC(x)
else
    adapt(CuArray, x)
end

It would be nice if adapt can do something like

to = Union{CuArray, CuSparseMatrixCSC, CuSparseMatrixCSR}

adapt(to, zeros(2, 2)) :: CuArray
adapt(to, spzeros(2, 2)) :: CuSparseMatrixCSC
adapt(to, transpose(spzeros(2, 2))) :: CuSparseMatrixCSR

Is it in the scope of this package?

MikeInnes commented 4 years ago

I think it'd be fine for adapt(CuArray, x) to support sparse arrays like this. However, that would have to happen in CuArrays.jl, not adapt.jl itself.

tkf commented 4 years ago

Thanks for the clarification. So I'll close this issue for now. Maybe I'll open a PR in CuArrays.jl later.