class_docstr: Encoding stage for bitpacking values into an integer type.
  
  This class performs a lossless transformation, and realizes representation
  savings.
  
  The encode method expects integer values in range `[0, 2**input_bits-1]` in a
  floating point type (`tf.float32` or `tf.float64`). It packs the values to
  `tf.int32` type, and returns a rank 1 `Tensor` of packed values. The packed
  values are in the range `[0, 2**28-1]`, as the serialization in protocol
  buffer for this type is varint, and this thus ensures every element fits into
  4 bytes.
class_docstr_tok: ["Encoding","stage","for","bitpacking","values","into","an","integer","type",".","This","class","performs","a","lossless","transformation",",","and","realizes","representation","savings",".","The","encode","method","expects","integer","values","in","range","`","[","0",",","2","*","*","input_bits-1","]","`","in","a","floating","point","type","(","`","tf.float32","`","or","`","tf.float64","`",")",".","It","packs","the","values","to","`","tf.int32","`","type",",","and","returns","a","rank","1","`","Tensor","`","of","packed","values",".","The","packed","values","are","in","the","range","`","[","0",",","2","*","*","28-1","]","`",",","as","the","serialization","in","protocol","buffer","for","this","type","is","varint",",","and","this","thus","ensures","every","element","fits","into","4","bytes","."]
docstr: See base class.
code: def encode(self, x, encode_params):
      """See base class."""
      del encode_params
      flat_x = tf.reshape(x, [-1])
      packed_x = tf_utils.pack_into_int(
          tf.cast(flat_x, tf.int32),
          self._input_bits,
          self._target_bitrange,
      )
  
      # The most common type will be tf.float32, which we keep as default.
      # If another type is provided, return a Tensor with a single value of that
      # type to be able to recover the type from encoded_tensors in decode method.
      if x.dtype == tf.float32:
          return collections.OrderedDict(
              [(self.ENCODED_VALUES_KEY, packed_x)]
          )
      elif x.dtype in [tf.float16, tf.bfloat16, tf.float64]:
          return collections.OrderedDict(
              [
                  (self.ENCODED_VALUES_KEY, packed_x),
                  (
                      self.DUMMY_TYPE_VALUES_KEY,
                      tf.constant(0.0, dtype=x.dtype),
                  ),
              ]
          )
      else:
          raise TypeError(
              "Unsupported packing type: %s. Supported types are tf.float32 and "
              "tf.float64 values" % x.dtype
          )
  
imports: import collections
  import numpy
  import tensorflow
  from tensorflow_model_optimization.python.core.internal.tensor_encoding.core import encoding_stage
  from tensorflow_model_optimization.python.core.internal.tensor_encoding.utils import tf_utils
label_desc: Use image node_id 7 for calling the BitpackingEncodingStage obj's underlying member method code with example usage: obj.encode(x, encode_params) and returns: collections, collections