The sparse_mat data type is designed to hold the interaction matrix , which is generally a sparse matrix. It is built up of array<double> and iarray<int> components:

class sparse_mat
  array diag, val;
  iarray row, col;
  sparse_mat(int s=0, int o=0)
    {diag=array(s); val=array(o); row=iarray(o); col=iarray(o);}
  array operator*(iarray& x);  /* matrix multiplication */
  sparse_mat operator=(sparse_mat x);
  void init_rand(int conn, double sigma);

diag stores the diagonal components of the array, val is the packed list of offdiagonal values, with row and col being the index lists. The only important operator defined for this class is the matrix operation, which is defined as

beta*x == beta.diag*x + (beta.val*x[beta.col])[beta.row]
but is implemented separately for efficiency reasons.

init_rand is a utility routine for randomly initialising the nonzero pattern of the offdiagonal elements. The average number of nonzeros per row is conn, and the standard deviation of the number of nonzeros is sigma.

It is possible to represent the offdiagonal array differently for efficiency reasons. For example, if it is desired to represent the offdiagonal elements as a dense 2D array, one can create an extra pointer in the underlying implementation of array. Most of the time, this pointer is NULL, but when the cs_arrays routine offmul is called, it will check this pointer for the val array. If it is NULL, it will create the efficient representation, otherwise it will reuse the existing one. Because the only way the array's actual value will get out of synch with the efficient representation is by index assignment, put_double() and put_double_array (as well as obviously delete_array()) will need to be modified to deallocate the efficient representation.