What is the best way to create a sparse array in C++?

后端 未结 11 2181
心在旅途
心在旅途 2020-11-29 01:45

I am working on a project that requires the manipulation of enormous matrices, specifically pyramidal summation for a copula calculation.

In short, I need to keep

11条回答
  •  心在旅途
    2020-11-29 01:52

    Complete list of solutions can be found in the wikipedia. For convenience, I have quoted relevant sections as follows.

    https://en.wikipedia.org/wiki/Sparse_matrix#Dictionary_of_keys_.28DOK.29

    Dictionary of keys (DOK)

    DOK consists of a dictionary that maps (row, column)-pairs to the value of the elements. Elements that are missing from the dictionary are taken to be zero. The format is good for incrementally constructing a sparse matrix in random order, but poor for iterating over non-zero values in lexicographical order. One typically constructs a matrix in this format and then converts to another more efficient format for processing.[1]

    List of lists (LIL)

    LIL stores one list per row, with each entry containing the column index and the value. Typically, these entries are kept sorted by column index for faster lookup. This is another format good for incremental matrix construction.[2]

    Coordinate list (COO)

    COO stores a list of (row, column, value) tuples. Ideally, the entries are sorted (by row index, then column index) to improve random access times. This is another format which is good for incremental matrix construction.[3]

    Compressed sparse row (CSR, CRS or Yale format)

    The compressed sparse row (CSR) or compressed row storage (CRS) format represents a matrix M by three (one-dimensional) arrays, that respectively contain nonzero values, the extents of rows, and column indices. It is similar to COO, but compresses the row indices, hence the name. This format allows fast row access and matrix-vector multiplications (Mx).

提交回复
热议问题