Skip to content

num::sparse_congruence

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

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

Compute the congruence \(W A W\) where \(W = \text{diag}(\mathbf{w})\).

Unlike a similarity, a congruence does not preserve the spectrum; it preserves inertia, so it carries a symmetric positive-definite matrix to another one.

Parameters

  • A: Square CSR matrix.
  • weights: Diagonal weight entries.

Return value

CSR matrix \(WAW\) with the pattern of A.

Exceptions

  • std::invalid_argument: If dimensions mismatch.