code: def _scale_to_gaussian_internal(
      x: common_types.ConsistentTensorType,
      elementwise: bool = False,
      output_dtype: Optional[tf.DType] = None,
  ) -> common_types.ConsistentTensorType:
      """Implementation for scale_to_gaussian."""
      # x_mean will be float16, float32, or float64, depending on type of x.
      (
          x_loc,
          x_scale,
          hl,
          hr,
      ) = analyzers._tukey_parameters(  # pylint: disable=protected-access
          x,
          reduce_instance_dims=not elementwise,
          output_dtype=output_dtype,
      )
  
      compose_result_fn = _make_composite_tensor_wrapper_if_composite(x)
      x_values = tf_utils.get_values(x)
  
      x_var = analyzers.var(
          x,
          reduce_instance_dims=not elementwise,
          output_dtype=output_dtype,
      )
  
      if isinstance(x, tf.SparseTensor):
          if elementwise:
              x_loc = tf.gather_nd(x_loc, x.indices[:, 1:])
              x_scale = tf.gather_nd(x_scale, x.indices[:, 1:])
              hl = tf.gather_nd(hl, x.indices[:, 1:])
              hr = tf.gather_nd(hr, x.indices[:, 1:])
              x_var = tf.gather_nd(x_var, x.indices[:, 1:])
      elif isinstance(x, tf.RaggedTensor):
          if elementwise:
              raise NotImplementedError(
                  "Elementwise scale_to_gaussian does not support RaggedTensors."
              )
  
      numerator = tf.cast(x_values, x_loc.dtype) - x_loc
      is_long_tailed = tf.math.logical_or(hl > 0.0, hr > 0.0)
  
      # If the distribution is long-tailed, we apply the robust scale computed
      # with L-moments; otherwise, we scale using the standard deviation so that
      # we obtain the same result of scale_to_z_score.
      denominator = tf.where(is_long_tailed, x_scale, tf.sqrt(x_var))
      cond = tf.not_equal(denominator, 0)
  
      if cond.shape.as_list() != x_values.shape.as_list():
          # Repeats cond when necessary across the batch dimension for it to be
          # compatible with the shape of numerator.
          cond = tf.cast(
              tf.zeros_like(numerator) + tf.cast(cond, numerator.dtype),
              dtype=tf.bool,
          )
  
      scaled_values = tf.where(
          cond, tf.divide(numerator, denominator), numerator
      )
      gaussianized_values = gaussianization.inverse_tukey_hh(
          scaled_values, hl, hr
      )
      return compose_result_fn(gaussianized_values)
  
imports: import os
  from typing import Any, Callable, Iterable, Optional, Tuple, Union
  import tensorflow
  from tensorflow_transform import analyzers
  from tensorflow_transform import common
  from tensorflow_transform import common_types
  from tensorflow_transform import gaussianization
  from tensorflow_transform import schema_inference
  from tensorflow_transform import tf_utils
  from tfx_bsl.types import tfx_namedtuple
label_desc: Use image node_id 2 for calling a global function with example usage: _scale_to_gaussian_internal(x, elementwise, output_dtype) and returns: compose_result_fn