Hi, I wanted to store some information as a sparse matrix of vectors (or a tuple) to save on memory requirements.
I am simulating a system of N(~50) particles in a box. If two particles contact then there are interactions between them which requires me to store an 8 vector array for each contact.
I wanted to create a sparse matrix S such than
S[particle_id1, particle_id2] = [1,2,3,..8] if contact
S[particle_id1, particle_id2] = empty if no contact
I am able to assign the values by S[particle_id1, particle_id2] = [1,2,3,..8]
. But how do I delete a value that is no longer needed? I saw a function dropzeros
but that would require defining a “zero”. Whenever I try to access any “zero” element in the matrix, I am faced with the following error:
MethodError: no method matching zero(::Type{Vector{Int64}})
I tried defining a function zero(::Type{Vector{Int64}}) = 0
but that didn’t help.
I am just interested in storing, and retrieving data and don’t want to do any algebra with the matrix. Having a sparse matrix makes it easy to retrieve things by doing findnnz(S[particle_id1,:])
.
What I want to know is:
- How do I define a “zero” in such scenario?
- Is there a better approach to achieve my goals?
I haven’t worked with sparse arrays before, so any help is appreciated. Thanks
Edit: I realized I could just do Base.zero(::Type{Vector{Int64}}) = 0
and that does the job.