code: def solve_kkt_ir(Q, D, G, A, rx, rs, rz, ry, niter=1):
      
      nineq, nz, neq, nBatch = get_sizes(G, A)
  
      eps = 1e-7
      Q_tilde = Q + eps * torch.eye(nz).type_as(Q).repeat(nBatch, 1, 1)
      D_tilde = D + eps * torch.eye(nineq).type_as(Q).repeat(nBatch, 1, 1)
  
      dx, ds, dz, dy = factor_solve_kkt_reg(
          Q_tilde, D_tilde, G, A, rx, rs, rz, ry, eps)
      res = kkt_resid_reg(Q, D, G, A, eps,
                          dx, ds, dz, dy, rx, rs, rz, ry)
      resx, ress, resz, resy = res
      res = resx
      for k in range(niter):
          ddx, dds, ddz, ddy = factor_solve_kkt_reg(Q_tilde, D_tilde, G, A, -resx, -ress, -resz,
                                                    -resy if resy is not None else None,
                                                    eps)
          dx, ds, dz, dy = [v + dv if v is not None else None
                            for v, dv in zip((dx, ds, dz, dy), (ddx, dds, ddz, ddy))]
          res = kkt_resid_reg(Q, D, G, A, eps,
                              dx, ds, dz, dy, rx, rs, rz, ry)
          resx, ress, resz, resy = res
          # res = torch.cat(resx)
          res = resx
  
      return dx, ds, dz, dy
docs: Inefficient iterative refinement.