1. A method for encoding a sparse matrix into a data structure, the data structure including a first array, the method comprising: receiving the sparse matrix; traversing a set of designated rows of the sparse matrix according to a deterministic sequence until all non-zero elements in the sparse matrix have been placed in the first array; each time a row of the set is traversed according to the deterministic sequence, placing a next non-zero element in that row in the first array, wherein each row in the set has a first non-zero element placed in the first array before a second element from that row is placed in the first array; if all non-zero elements for a given row of the set of designated rows have been placed in the first array, replacing the given row in the set of designated rows with a next unprocessed row of the sparse matrix; and outputting the data structure in which the sparse matrix is encoded.