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

FunctionLens for SparseMatrixCSC accessor functions #78

Open
tkf opened this issue Sep 13, 2019 · 4 comments
Open

FunctionLens for SparseMatrixCSC accessor functions #78

tkf opened this issue Sep 13, 2019 · 4 comments
Assignees

Comments

@tkf
Copy link
Collaborator

tkf commented Sep 13, 2019

Once AbstractSparseMatrixCSC API for accessors JuliaLang/julia#33054 is settled, I'd like to add set definitions for them. It'll let us use something like

@set nonzeros(A) = xs

The definition would be something like simply

set(A::SparseMatrixCSC, ::typeof(@lens nonzeros(_)), xs) = @set A.nzval = xs

@jw3126 Does it sound reasonable?

@tkf tkf self-assigned this Sep 13, 2019
@jw3126
Copy link
Owner

jw3126 commented Sep 13, 2019

Yeah sounds good. I guess this is a case, where you would really like to have a mutating @set most of the time?

@tkf
Copy link
Collaborator Author

tkf commented Sep 13, 2019

SparseMatrixCSC is a non-mutable struct so I think re-constructing lens is all we can do. If you want to reuse existing underlying vectors, you can just do:

nonzeros(A) .= xs

A concrete scenario I have in mind is to construct CSC matrices with shared nonzero structure like this

B = spzeros(size(A)...)
@set coloffsets(B) = coloffsets(A)
@set rowvals(B) = rowvals(A)
@set nonzeros(B) = similar(nonzeros(A))
compute!(nonzeros(B))

In this case, the above lens does what I need.

A scenario I can think of where the mutating lens is usable is something like

A = sprandn(ComplexF64, 100, 100, 0.1)
B = @set!! real(nonzeros(A)[1]) = x

where you'd want it to do

a = nonzeros(A)
b = a[1]
c = @set b.re = x
a[1] = c  # typeof(c) == typeof(b) so mutate `a`
B = @set nonzeros(A) = a  # `A` is immutable so use normal lens

@jw3126
Copy link
Owner

jw3126 commented Sep 13, 2019

I see thanks. Out of curiosity, do you want to share nonzero structure for PDE discretization?

@tkf
Copy link
Collaborator Author

tkf commented Sep 13, 2019

It's sparse (somewhat biological) neural network simulation. I found fusing Y = Y β + D₁ S₁' X₁ + ... + Dₙ Sₙ' Xₙ is beneficial when sparse matrices Sᵢs share nonzero structures: https://github.com/tkf/SparseXX.jl

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