Skip to content

num::sparse_diagonal_similarity

Defined in header <linear/sparse/sparse.hpp>

spmat sparse_diagonal_similarity(const spmat &A, view<const real> weights);

Compute \(D^{-1} A D\) without leaving the sparse representation.

A diagonal similarity rescales entries in place, so the result carries the pattern of A. Use this form when the transformed matrix is factored or multiplied rather than inspected, since diagonal_similarity densifies it.

Parameters

  • A: Square CSR matrix.
  • weights: Positive diagonal weight entries \(w_i > 0\).

Return value

CSR matrix \(D^{-1} A D\) with the pattern of A.

Exceptions

  • std::invalid_argument: If dimensions mismatch or any weight is non-positive.