code: def cores_orthogonalization_step(coresX, dim, left_to_right=True):
      
      cc = coresX[dim]
      r1, n, r2 = cc.shape
      if left_to_right:
          # Left to right orthogonalization step.
          assert(0 <= dim < len(coresX) - 1)
          cc, rr = np.linalg.qr(reshape(cc, (-1, r2)))
          r2 = cc.shape[1]
          coresX[dim] = reshape(cc, (r1, n, r2))
          coresX[dim+1] = np.tensordot(rr, coresX[dim+1], 1)
      else:
          # Right to left orthogonalization step.
          assert(0 < dim < len(coresX))
          cc, rr = np.linalg.qr(reshape(cc, (r1, -1)).T)
          r1 = cc.shape[1]
          coresX[dim] = reshape(cc.T, (r1, n, r2))
          coresX[dim-1] = np.tensordot(coresX[dim-1], rr.T, 1)
      return coresX
docs: TT-Tensor X orthogonalization step.
  
      The function can change the shape of some cores.