Sparse Matrix

In block2, we support a few different representations of the block-sparse matrix.

Archived Sparse Matrix

template<typename S, typename FL>
struct block2::ArchivedSparseMatrix : public block2::SparseMatrix<S, FL>

Block-sparse Matrix associated with disk storage, representing sparse operator.

tparam S

Quantum label type.

tparam FL

float point type.

Public Functions

inline ArchivedSparseMatrix(const string &filename, int64_t offset, const shared_ptr<Allocator<FP>> &alloc = nullptr)

Constructor.

Parameters
  • filename – The name of the associated disk file.

  • offset – Byte offset in the file (where to read/write the content).

  • alloc – Memory allocator.

inline virtual SparseMatrixTypes get_type() const override

Get the type of this sparse matrix.

Returns

Type of this sparse matrix.

inline virtual void allocate(const shared_ptr<SparseMatrixInfo<S>> &info, FL *ptr = 0) override

Allocate memory for the sparse matrix non-zero elements. This method is not allowed here. Will cause assertion failure.

Parameters
  • info – The quantum label information for the sparse matrix.

  • ptr – If not zero, the given pointer is used as the data pointer (no allocation will happen).

inline virtual void deallocate() override

Release the allocated memory. This method does nothing here, since no memory is used by this object.

inline shared_ptr<SparseMatrix<S, FL>> load_archive()

Load the sparse matrix data from disk.

Returns

A normal or CSR sparse matrix (with data in memory).

inline void save_archive(const shared_ptr<SparseMatrix<S, FL>> &mat)

Write the sparse matrix data to disk.

Parameters

mat – A normal or CSR sparse matrix (with data in memory).

Public Members

string filename

The name of the associated disk file.

int64_t offset = 0

Byte offset in the file.

SparseMatrixTypes sparse_type

Type of the archived sparse matrix. Note that this is not the type of this sparse matrix.