code: @Override
      public DenseMatrix inverse() {
          int m = lu.nrows();
          int n = lu.ncols();
  
          if (m != n) {
              throw new IllegalArgumentException(String.format("Matrix is not square: %d x %d", m, n));
          }
  
          int nb = LAPACK.getInstance().ilaenv(1, "DGETRI", "", n, -1, -1, -1);
          if (nb < 0) {
              logger.warn("LAPACK ILAENV error code: {}", nb);
          }
  
          if (nb < 1) nb = 1;
  
          int lwork = lu.ncols() * nb;
          double[] work = new double[lwork];
          intW info = new intW(0);
          LAPACK.getInstance().dgetri(lu.ncols(), lu.data(), lu.ld(), piv, work, lwork, info);
  
          if (info.val != 0) {
              logger.error("LAPACK DGETRI error code: {}", info.val);
              throw new IllegalArgumentException("LAPACK DGETRI error code: " + info.val);
          }
  
          return lu;
      }
docs: Returns the matrix inverse. The LU matrix will overwritten with
  the inverse of the original matrix.