MCPcopy Create free account
hub / github.com/cvxpy/cvxpy / diagonalize

Function diagonalize

cvxpy/cvxcore/src/Utils.cpp:133–146  ·  view source on GitHub ↗

Create a giant diagonal matrix with entries given by the entries of mat.

Source from the content-addressed store, hash-verified

131
132// Create a giant diagonal matrix with entries given by the entries of mat.
133Matrix 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}

Callers 1

get_mul_elemwise_matFunction · 0.70

Calls 13

TripletClass · 0.85
setFromTripletsMethod · 0.80
makeCompressedMethod · 0.80
rowsMethod · 0.45
colsMethod · 0.45
reserveMethod · 0.45
nonZerosMethod · 0.45
outerSizeMethod · 0.45
rowMethod · 0.45
push_backMethod · 0.45
valueMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected