code: def linspace_helper(
      start, stop, num, axis=None, *, dtype=None, device
  ):
      num = (
          num.detach().numpy().item()
          if isinstance(num, torch.Tensor)
          else num
      )
      start_is_array = isinstance(start, torch.Tensor)
      stop_is_array = isinstance(stop, torch.Tensor)
      linspace_method = torch.linspace
      sos_shape = []
      if start_is_array:
          start_shape = list(start.shape)
          sos_shape = start_shape
          if num == 1:
              if axis is not None:
                  return start.unsqueeze(axis).to(device)
              else:
                  return start.unsqueeze(-1).to(device)
          start = start.reshape((-1,))
          linspace_method = (
              _differentiable_linspace
              if start.requires_grad
              else torch.linspace
          )
      if stop_is_array:
          stop_shape = list(stop.shape)
          sos_shape = stop_shape
          if num == 1:
              return (
                  torch.ones(
                      stop_shape[:axis] + [1] + stop_shape[axis:],
                      device=device,
                  )
                  * start
              )
          stop = stop.reshape((-1,))
          linspace_method = (
              _differentiable_linspace
              if stop.requires_grad
              else torch.linspace
          )
      if start_is_array and stop_is_array:
          if num < start.shape[0]:
              start = start.unsqueeze(-1)
              stop = stop.unsqueeze(-1)
              diff = stop - start
              inc = diff / (num - 1)
              res = [start]
              res += [start + inc * i for i in range(1, num - 1)]
              res.append(stop)
          else:
              res = [
                  linspace_method(strt, stp, num, device=device)
                  for strt, stp in zip(start, stop)
              ]
      elif start_is_array and not stop_is_array:
          if num < start.shape[0]:
              start = start.unsqueeze(-1)
              diff = stop - start
              inc = diff / (num - 1)
              res = [start]
              res += [start + inc * i for i in range(1, num - 1)]
              res.append(torch.ones_like(start, device=device) * stop)
          else:
              res = [
                  linspace_method(strt, stop, num, device=device)
                  for strt in start
              ]
      elif not start_is_array and stop_is_array:
          if num < stop.shape[0]:
              stop = stop.unsqueeze(-1)
              diff = stop - start
              inc = diff / (num - 1)
              res = [torch.ones_like(stop, device=device) * start]
              res += [start + inc * i for i in range(1, num - 1)]
              res.append(stop)
          else:
              res = [
                  linspace_method(start, stp, num, device=device)
                  for stp in stop
              ]
      else:
          return linspace_method(
              start, stop, num, dtype=dtype, device=device
          )
      res = torch.cat(res, -1).reshape(sos_shape + [num])
      if axis is not None:
          ndim = res.ndim
          perm = list(range(0, ndim - 1))
          perm.insert(axis % (ndim + 1), ndim - 1)
          res = res.permute(perm)
      return res.to(device)
  
imports: import copy
  from numbers import Number
  from typing import Union, List, Optional, Sequence, Tuple
  import numpy
  import torch
  from torch import Tensor
  import ivy
  from ivy.func_wrapper import with_unsupported_dtypes, with_unsupported_device_and_dtypes
  from ivy.functional.ivy.creation import _asarray_to_native_arrays_and_back, _asarray_infer_device, _asarray_infer_dtype, _asarray_handle_nestable, NestedSequence, SupportsBufferProtocol, _asarray_inputs_to_native_shapes, _remove_np_bfloat16
  from .None import backend_version
label_desc: Use image node_id 14 for calling a global function with example usage: linspace_helper(start, stop, num, axis) and returns: res, unknown, start, start, linspace_method