code: private static int[] findDiagonalIndices(CompRowMatrix A) {
              int[] rowptr = A.getRowPointers();
              int[] colind = A.getColumnIndices();
  
              int[] diagIndices = new int[A.numRows()];
  
              for (int i = 0; i < A.numRows(); ++i) {
                  diagIndices[i] = no.uib.cipr.matrix.sparse.Arrays.binarySearch(
                          colind, i, rowptr[i], rowptr[i + 1]);
                  if (diagIndices[i] < 0)
                      throw new RuntimeException(
                              "Matrix is missing a diagonal entry on row "
                                      + (i + 1));
              }
  
              return diagIndices;
          }
docs: Finds the diagonal indices of the matrix