class_docstr: Switch layer of Neural Shuffle-Exchange network.
docstr: Apply SwitchLayer to inputs.
  
  Args:
    inputs: Input tensor
    residual_inputs: Residual connections from previous block
  
  Returns:
    tf.Tensor: New candidate value
docstr_tok: ["Apply","SwitchLayer","to","inputs",".","Args",":","inputs",":","Input","tensor","residual_inputs",":","Residual","connections","from","previous","block","Returns",":","tf.Tensor",":","New","candidate","value"]
code: def __call__(self, inputs, residual_inputs):
      """Apply SwitchLayer to inputs.
  
      Args:
        inputs: Input tensor
        residual_inputs: Residual connections from previous block
  
      Returns:
        tf.Tensor: New candidate value
      """
      input_shape = tf.shape(inputs)
      self.batch_size = input_shape[0]
      self.length = input_shape[1]
      self.num_units = inputs.shape.as_list()[2]
  
      self.n_bits = tf.log(
          tf.cast(self.length - 1, tf.float32)
      ) / tf.log(2.0)
      self.n_bits = tf.floor(self.n_bits) + 1
  
      initializer = tf.constant_initializer(0.5)
      residual_scale = tf.get_variable(
          self.prefix + "/residual_scale",
          [self.num_units],
          initializer=initializer,
      )
  
      shuffled_input = self.swap_halves(inputs)
      mem_all = inputs + residual_inputs * residual_scale
  
      # calculate the new value
      candidate = self.gated_linear_map(
          mem_all, "c", 0.5, self.num_units, self.num_units
      )
      gate = tf.nn.sigmoid(
          self.linear_map(
              mem_all, "g", 0.5, self.num_units, self.num_units
          )
      )
  
      candidate = gate * shuffled_input + (1 - gate) * candidate
  
      if self.dropout > 0:
          candidate = tf.nn.dropout(
              candidate, rate=self.dropout / self.n_bits
          )
      if (
          self.dropout != 0.0
          and self.mode == tf_estimator.ModeKeys.TRAIN
      ):
          noise = tf.random_normal(
              tf.shape(candidate), mean=1.0, stddev=0.001
          )
          candidate = candidate * noise
  
      return candidate
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import math
  from tensor2tensor.layers import common_hparams
  from tensor2tensor.utils import registry
  from tensor2tensor.utils import t2t_model
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
label_desc: Use image node_id 4 for calling the SwitchLayer obj's underlying member method code with example usage: obj.__call__(inputs, residual_inputs) and returns: candidate