Sparse matrix of vectors

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:

  1. How do I define a “zero” in such scenario?
  2. 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.

that’s quite small, can’t you just use an Array that is 50 by 50 by 8? And this would be a symmetric matrix (since contact is mutual?)

Thats true, but in future I might have to increase the box size and the number of particles. So I started looking into sparse matrices.

btw this is a bad idea because this is type-piracy and this particular definition doesn’t make a lot of sense. The “zero” element of a matrix should be additive identity.

In any case, you want to initialize the sparse matrix to have element type of a statically-sized vector, check out StaticArrays.jl maybe, and then, you can probably just use @SVector(0,0,0,0,0,0,0,0) as your zero element

The SVector{8,Int} suggestion sounds like it would fit your needs.

Another option is to use a Dict{Tuple{Int,Int}, Vector{Int}} rather than SparseMatrixCSC. If particles i and j interact then set dict[minmax(i,j)] = thevector (the minmax is there to sort the values so that (i,j) and (j,i) refer to the same thing).

You can use get(dict, minmax(i,j), VALUE_IF_MISSING) to return the vector (if it’s there) or else whatever fallback value you want.

I feel using a dict would be better for my case, so that I can dynamically add and delete elements easily depending on when a contact forms or breaks.
Thanks!