labtools/_src/util.py
def topylist(x) -> list:
  """ Convert a list-like object to a python list.

  Converts a list-like object into a python list. This function requires no
  additional packages to be installed, and checks each input using a string of
  the type. This can be useful for reliably converting tensors to a format
  supported by json or other logging libraries.

  Args:
    x: A list-like object, which can be a torch Tensor, numpy array, or jax
      array. If `x` is not any of these, the default is to try `x.tolist()`, or
      just return `x` if that fails.
  """
  x_type = str(type(x))
  if x_type == '<class \'torch.Tensor\'>':
    x = x.tolist()
  elif x_type.endswith('DeviceArray\'>'):
    onp = maybe_import('numpy')
    if onp is not None:
      x = onp.asarray(x).tolist()
  else:
    try:
      x = x.tolist()
    except:
      pass
  return x
 Convert a list-like object to a python list.

  Converts a list-like object into a python list. This function requires no
  additional packages to be installed, and checks each input using a string of
  the type. This can be useful for reliably converting tensors to a format
  supported by json or other logging libraries.

  Args:
    x: A list-like object, which can be a torch Tensor, numpy array, or jax
      array. If `x` is not any of these, the default is to try `x.tolist()`, or
      just return `x` if that fails.
  
Convert a list-like object to a python list.
Converts a list-like object into a python list. This function requires no
additional packages to be installed, and checks each input using a string of
the type. This can be useful for reliably converting tensors to a format
supported by json or other logging libraries.
Convert a list - like object to a python list . Converts a list - like object into a python list . This function requires no additional packages to be installed and checks each input using a string of the type . This can be useful for reliably converting tensors to a format supported by json or other logging libraries .
def topylist(x) -> list:
  x_type = str(type(x))
  if x_type == '<class \'torch.Tensor\'>':
    x = x.tolist()
  elif x_type.endswith('DeviceArray\'>'):
    onp = maybe_import('numpy')
    if onp is not None:
      x = onp.asarray(x).tolist()
  else:
    try:
      x = x.tolist()
    except:
      pass
  return x
def topylist ( x ) -> list : x_type = str ( type ( x ) ) if x_type == '<class \'torch.Tensor\'>' : x = x . tolist ( ) elif x_type . endswith ( 'DeviceArray\'>' ) : onp = maybe_import ( 'numpy' ) if onp is not None : x = onp . asarray ( x ) . tolist ( ) else : try : x = x . tolist ( ) except : pass return x
Convert a list-like object to a python list.
Convert a list - like object to a python list .
""" Convert a list-like object to a python list.

  Converts a list-like object into a python list. This function requires no
  additional packages to be installed, and checks each input using a string of
  the type. This can be useful for reliably converting tensors to a format
  supported by json or other logging libraries.

  Args:
    x: A list-like object, which can be a torch Tensor, numpy array, or jax
      array. If `x` is not any of these, the default is to try `x.tolist()`, or
      just return `x` if that fails.
  """
x
A list-like object, which can be a torch Tensor, numpy array, or jax
array. If `x` is not any of these, the default is to try `x.tolist()`, or
just return `x` if that fails.
A list - like object which can be a torch Tensor numpy array or jax array . If ` x ` is not any of these the default is to try ` x . tolist () ` or just return ` x ` if that fails .