Create a giant diagonal matrix with entries given by the entries of mat.
| 131 | |
| 132 | // Create a giant diagonal matrix with entries given by the entries of mat. |
| 133 | Matrix diagonalize(const Matrix &mat) { |
| 134 | Matrix diag(mat.rows() * mat.cols(), mat.rows() * mat.cols()); |
| 135 | std::vector<Triplet> tripletList; |
| 136 | tripletList.reserve(mat.nonZeros()); |
| 137 | for (int k = 0; k < mat.outerSize(); ++k) { |
| 138 | for (Matrix::InnerIterator it(mat, k); it; ++it) { |
| 139 | unsigned loc = it.row() + k * mat.rows(); |
| 140 | tripletList.push_back(Triplet(loc, loc, it.value())); |
| 141 | } |
| 142 | } |
| 143 | diag.setFromTriplets(tripletList.begin(), tripletList.end()); |
| 144 | diag.makeCompressed(); |
| 145 | return diag; |
| 146 | } |
no test coverage detected