code: private static Preconditioner diagonalPreconditioner(Matrix A) {
          return new Preconditioner() {
              public void asolve(double[] b, double[] x) {
                  double[] diag = A.diag();
                  int n = diag.length;
  
                  for (int i = 0; i < n; i++) {
                      x[i] = diag[i] != 0.0 ? b[i] / diag[i] : b[i];
                  }
              }
          };
      }
docs: Returns a simple preconditioner matrix that is the
  trivial diagonal part of A in some cases.