def schur_complement(
    mat_a: np.ndarray,
    mat_b: np.ndarray,
    mat_c: np.ndarray,
    pseudo_inv: np.ndarray | None = None,
) -> np.ndarray:
    shape_a = np.shape(mat_a)
    shape_b = np.shape(mat_b)
    shape_c = np.shape(mat_c)

    if shape_a[0] != shape_b[0]:
        raise ValueError(
            f"Expected the same number of rows for A and B. \
            Instead found A of size {shape_a} and B of size {shape_b}"
        )

    if shape_b[1] != shape_c[1]:
        raise ValueError(
            f"Expected the same number of columns for B and C. \
            Instead found B of size {shape_b} and C of size {shape_c}"
        )

    a_inv = pseudo_inv
    if a_inv is None:
        try:
            a_inv = np.linalg.inv(mat_a)
        except np.linalg.LinAlgError:
            raise ValueError(
                "Input matrix A is not invertible. Cannot compute Schur complement."
            )

    return mat_c - mat_b.T @ a_inv @ mat_b