code: def geometric_transform(
      input,
      mapping,
      output_shape=None,
      output=None,
      order=3,
      mode="constant",
      cval=0.0,
      prefilter=True,
      extra_arguments=(),
      extra_keywords={},
  ):
      """
      Apply an arbitrary geometric transform.
  
      The given mapping function is used to find, for each point in the
      output, the corresponding coordinates in the input. The value of the
      input at those coordinates is determined by spline interpolation of
      the requested order.
  
      Parameters
      ----------
      %(input)s
      mapping : {callable, scipy.LowLevelCallable}
          A callable object that accepts a tuple of length equal to the output
          array rank, and returns the corresponding input coordinates as a tuple
          of length equal to the input array rank.
      output_shape : tuple of ints, optional
          Shape tuple.
      %(output)s
      order : int, optional
          The order of the spline interpolation, default is 3.
          The order has to be in the range 0-5.
      %(mode_interp_constant)s
      %(cval)s
      %(prefilter)s
      extra_arguments : tuple, optional
          Extra arguments passed to `mapping`.
      extra_keywords : dict, optional
          Extra keywords passed to `mapping`.
  
      Returns
      -------
      output : ndarray
          The filtered input.
  
      See Also
      --------
      map_coordinates, affine_transform, spline_filter1d
  
  
      Notes
      -----
      This function also accepts low-level callback functions with one
      the following signatures and wrapped in `scipy.LowLevelCallable`:
  
      .. code:: c
  
         int mapping(npy_intp *output_coordinates, double *input_coordinates,
                     int output_rank, int input_rank, void *user_data)
         int mapping(intptr_t *output_coordinates, double *input_coordinates,
                     int output_rank, int input_rank, void *user_data)
  
      The calling function iterates over the elements of the output array,
      calling the callback function at each element. The coordinates of the
      current output element are passed through ``output_coordinates``. The
      callback function must return the coordinates at which the input must
      be interpolated in ``input_coordinates``. The rank of the input and
      output arrays are given by ``input_rank`` and ``output_rank``
      respectively. ``user_data`` is the data pointer provided
      to `scipy.LowLevelCallable` as-is.
  
      The callback function must return an integer error status that is zero
      if something went wrong and one otherwise. If an error occurs, you should
      normally set the Python error status with an informative message
      before returning, otherwise a default error message is set by the
      calling function.
  
      In addition, some other low-level function pointer specifications
      are accepted, but these are for backward compatibility only and should
      not be used in new code.
  
      For complex-valued `input`, this function transforms the real and imaginary
      components independently.
  
      .. versionadded:: 1.6.0
          Complex-valued support added.
  
      Examples
      --------
      >>> import numpy as np
      >>> from scipy.ndimage import geometric_transform
      >>> a = np.arange(12.).reshape((4, 3))
      >>> def shift_func(output_coords):
      ...     return (output_coords[0] - 0.5, output_coords[1] - 0.5)
      ...
      >>> geometric_transform(a, shift_func)
      array([[ 0.   ,  0.   ,  0.   ],
             [ 0.   ,  1.362,  2.738],
             [ 0.   ,  4.812,  6.187],
             [ 0.   ,  8.263,  9.637]])
  
      >>> b = [1, 2, 3, 4, 5]
      >>> def shift_func(output_coords):
      ...     return (output_coords[0] - 3,)
      ...
      >>> geometric_transform(b, shift_func, mode='constant')
      array([0, 0, 0, 1, 2])
      >>> geometric_transform(b, shift_func, mode='nearest')
      array([1, 1, 1, 1, 2])
      >>> geometric_transform(b, shift_func, mode='reflect')
      array([3, 2, 1, 1, 2])
      >>> geometric_transform(b, shift_func, mode='wrap')
      array([2, 3, 4, 1, 2])
  
      """
      if order < 0 or order > 5:
          raise RuntimeError("spline order not supported")
      input = numpy.asarray(input)
      if output_shape is None:
          output_shape = input.shape
      if input.ndim < 1 or len(output_shape) < 1:
          raise RuntimeError("input and output rank must be > 0")
      complex_output = numpy.iscomplexobj(input)
      output = _ni_support._get_output(
          output,
          input,
          shape=output_shape,
          complex_output=complex_output,
      )
      if complex_output:
          kwargs = dict(
              order=order,
              mode=mode,
              prefilter=prefilter,
              output_shape=output_shape,
              extra_arguments=extra_arguments,
              extra_keywords=extra_keywords,
          )
          geometric_transform(
              input.real,
              mapping,
              output=output.real,
              cval=numpy.real(cval),
              **kwargs,
          )
          geometric_transform(
              input.imag,
              mapping,
              output=output.imag,
              cval=numpy.imag(cval),
              **kwargs,
          )
          return output
  
      if prefilter and order > 1:
          padded, npad = _prepad_for_spline_filter(input, mode, cval)
          filtered = spline_filter(
              padded, order, output=numpy.float64, mode=mode
          )
      else:
          npad = 0
          filtered = input
      mode = _ni_support._extend_mode_to_code(mode)
      _nd_image.geometric_transform(
          filtered,
          mapping,
          None,
          None,
          None,
          output,
          order,
          mode,
          cval,
          npad,
          extra_arguments,
          extra_keywords,
      )
      return output
  
file_path: scipy/scipy/ndimage/_interpolation.py
imports: import itertools
  import warnings
  import numpy
  from scipy._lib._util import normalize_axis_index
  from scipy import special
  from .None import _ni_support
  from .None import _nd_image
  from ._ni_docstrings import docfiller
label_desc: Use image node_id 4 for calling a global function with example usage: geometric_transform(input, mapping, output_shape, output, order, mode, cval, prefilter, extra_arguments, extra_keywords) and returns: output, output