code: public static INDArray pinvert(INDArray arr, boolean inPlace) {
  
          // TODO : do it natively instead of relying on commons-maths
  
          RealMatrix realMatrix = CheckUtil.convertToApacheMatrix(arr);
          QRDecomposition decomposition = new QRDecomposition(realMatrix, 0);
          DecompositionSolver solver = decomposition.getSolver();
  
          if (!solver.isNonSingular()) {
              throw new IllegalArgumentException("invalid array: must be singular matrix");
          }
  
          RealMatrix pinvRM = solver.getInverse();
  
          INDArray pseudoInverse = CheckUtil.convertFromApacheMatrix(pinvRM, arr.dataType());
  
          if (inPlace)
              arr.assign(pseudoInverse);
          return pseudoInverse;
  
      }
docs: Calculates pseudo inverse of a matrix using QR decomposition
  @param arr the array to invert
  @return the pseudo inverted matrix