code: def kthvalue(input, k, dim=-1, keepdim=False, *, out=None):
      sorted_input = ivy.sort(input, axis=dim)
      sort_indices = ivy.argsort(input, axis=dim)
  
      values = ivy.asarray(
          ivy.gather(sorted_input, ivy.array(k - 1), axis=dim),
          dtype=input.dtype,
      )
      indices = ivy.asarray(
          ivy.gather(sort_indices, ivy.array(k - 1), axis=dim),
          dtype="int64",
      )
  
      if keepdim:
          values = ivy.expand_dims(values, axis=dim)
          indices = ivy.expand_dims(indices, axis=dim)
  
      ret = namedtuple("sort", ["values", "indices"])(values, indices)
      if ivy.exists(out):
          return ivy.inplace_update(out, ret)
      return ret
  
imports: import ivy
  import ivy.functional.frontends.torch
  from ivy.func_wrapper import with_unsupported_dtypes
  from ivy.functional.frontends.torch.func_wrapper import to_ivy_arrays_and_back
  from collections import namedtuple
label_desc: Use image node_id 19 for calling a global function with example usage: kthvalue(input, k, dim, keepdim) and returns: ret, ivy