Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Untiful sparse arrays in matrix equation solvers #515

Open
StefanMathis opened this issue Jan 18, 2022 · 1 comment
Open

Untiful sparse arrays in matrix equation solvers #515

StefanMathis opened this issue Jan 18, 2022 · 1 comment

Comments

@StefanMathis
Copy link

Hello :-)

Does anyone know a non-allocating way to create a unit-stripped view into a SparseMatrixCSC? Let's assume I have the following sparse array:

A = (sprand(3, 3, 0.5))u"1/s"

Now if I want to use ustrip directly on that matrix, it'll default to ustrip.(A), which will allocate memory (which we want to avoid). A workaround could be using a reinterpretation of A, as it is done in the ustrip() implementation for the Matrix type:

reinterpret(Unitful.numtype(eltype(A)), A)
ERROR: `reinterpret` on sparse arrays is discontinued.
Try reinterpreting the value itself instead.

:-(

Now let's assume we have the following idea:

nzval_ustripped = ustrip(A.nzval)
A_new = SparseMatrixCSC(A.m, A.n, A.colptr, A.rowval, nzval_ustripped)
ERROR: MethodError: no method matching SparseMatrixCSC(::Int64, ::Int64, ::Vector{Int64}, ::Vector{Int64}, ::Base.ReinterpretArray{Float64, 1, Quantity{Float64, 𝐓 ^-1, Unitful.FreeUnits{(s^-1,), 𝐓 ^-1, nothing}}, Vector{Quantity{Float64, 𝐓 ^-1, Unitful.FreeUnits{(s^-1,), 𝐓 ^-1, nothing}}}, false})

The problem here is that Base.ReinterpretArray is not a Vector, which is required by the SparseMatrixCSC type. And now I'm out of ideas ;-)

Does anyone else have an idea how we can have unit-stripped views into sparse matrices which can then be used for efficient linear algebra?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants