code: def _pre_cast_out_to_input_dtype(
      cast, is_floating, is_complex, as_dtype, dtype_as_str
  ):
      def _cast_out_to_input_dtype(target=None):
          """Cast out func if float or complex and not accordingly to input.
  
          How it works?
          -------------
          Function is called normally.
          If output is float, then it checks if is of expected dtype
          (input dtype). If not, cast is performed.
          If output is complex, then if first check if input is complex, if not
          it verifies the required precision for complex dtype and casts
          accordingly (if necessary)
          """
  
          def _decorator(func):
              @functools.wraps(func)
              def _wrapped(x, *args, **kwargs):
                  out = func(x, *args, **kwargs)
  
                  if is_floating(out):
                      if out.dtype != x.dtype:
                          return cast(out, x.dtype)
                  elif is_complex(out):
                      if is_complex(x):
                          cmp_dtype = x.dtype
                      else:
                          float_name = dtype_as_str(x.dtype)
                          cmp_dtype = as_dtype(
                              f"complex{int((float_name[-2:]))*2}"
                          )
  
                      if out.dtype != cmp_dtype:
                          return cast(out, cmp_dtype)
  
                  return out
  
              return _wrapped
  
          if target is None:
              return _decorator
  
          return _decorator(target)
  
      return _cast_out_to_input_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 12 for calling a global function with example usage: _pre_cast_out_to_input_dtype(cast, is_floating, is_complex, as_dtype, dtype_as_str) and returns: _cast_out_to_input_dtype, _decorator, _wrapped, _decorator, out, cast, cast