code: def _pre_cast_out_from_dtype(cast, is_floating, is_complex):
      def _cast_out_from_dtype(dtype_pos=None, target=None):
          """Cast output based on default dtype.
  
          Useful to wrap functions which output dtype cannot be (fully) controlled
          or for which is useful to run it without controlling dtype and cast
          afterwards (e.g. array).
  
          Parameters
          ----------
          dtype_pos : int
              Position of "dtype" argument.
  
          How it works?
          -------------
          Function is called normally. If output is float or complex, then it
          checks if is of expected dtype. If not, cast is performed.
          """
  
          def _decorator(func):
              @functools.wraps(func)
              def _wrapped(*args, **kwargs):
                  out = func(*args, **kwargs)
  
                  if is_floating(out) or is_complex(out):
                      if (
                          dtype_pos is not None
                          and len(args) > dtype_pos
                      ):
                          dtype = args[dtype_pos]
                      else:
                          dtype = kwargs.get(
                              "dtype",
                              _config.DEFAULT_DTYPE
                              if is_floating(out)
                              else _config.DEFAULT_COMPLEX_DTYPE,
                          )
  
                      if out.dtype != dtype:
                          return cast(out, dtype)
  
                  return out
  
              return _wrapped
  
          if target is None:
              return _decorator
  
          return _decorator(target)
  
      return _cast_out_from_dtype
  
file_path: geomstats/geomstats/_backend/_dtype_utils.py
imports: import functools
  import inspect
  import types
  from geomstats._backend import _backend_config
label_desc: Use image node_id 9 for calling a global function with example usage: _pre_cast_out_from_dtype(cast, is_floating, is_complex) and returns: _cast_out_from_dtype, _decorator, _wrapped, _decorator, out, cast