StatMech
Loading...
Searching...
No Matches
SparseCompressed_test.cpp File Reference

Functions

int main ()
 

Function Documentation

◆ main()

int main ( void  )
6 {
7 Eigen::MatrixXcd dense = Eigen::MatrixXcd::Zero(4, 4);
8 std::cout << dense << std::endl;
9
10 SparseCompressed mat2(4, 4);
11 std::cout << mat2 << std::endl;
12
13 SparseCompressed mat(4, 4);
14 std::cout << mat << std::endl;
15
16 int dim = 6;
17 int maxNonZeros = std::rand() % (dim * dim);
18 Eigen::SparseMatrix<Complex_t<double>> sparse(dim, dim);
19 for(int j = 0; j != maxNonZeros; ++j) {
20 sparse.coeffRef(std::rand() % dim, std::rand() % dim)
21 = {(std::rand() + 1) / double(RAND_MAX + 1), (std::rand() + 1) / double(RAND_MAX + 1)};
22 }
23 sparse.makeCompressed();
24 std::cout << sparse << std::endl;
25 std::cout << "sparse.nonZeros() = " << sparse.nonZeros() << std::endl;
26
27 mat.resize(dim, dim, sparse.nonZeros());
28 mat.nonZeros() = sparse.nonZeros();
29 for(int j = 0; j != dim + 1; ++j) mat.outerIndexPtr()[j] = sparse.outerIndexPtr()[j];
30 for(int j = 0; j != mat.nonZeros(); ++j) {
31 mat.innerIndexPtr()[j] = sparse.innerIndexPtr()[j];
32 mat.valuePtr()[j] = sparse.valuePtr()[j];
33 }
34 std::cout << mat << std::endl;
35 std::cout << "mat.nonZeros() = " << sparse.nonZeros() << std::endl;
36
37 mat2 = mat.adjoint();
38 std::cout << mat << std::endl;
39 std::cout << mat2 << std::endl;
40
41 return EXIT_SUCCESS;
42}
Definition MatrixUtils.cuh:280