class_docstr: Encoding stage multiplying input by appropriate randomized Hadamard matrix.
  
  This encoding stage implements the fast Walsh-Hadamard transform to
  efficiently compute matrix-vector product in O(n log n) time.
  https://en.wikipedia.org/wiki/Fast_Walsh%E2%80%93Hadamard_transform
  
  The useful property of randomized Hadamard transform is that it spreads the
  information in a vector more uniformly across its coefficients. This work well
  together with uniform quantization, as it reduces the dynamic range of the
  coefficients to be quantized, decreasing the error incurred by quantization.
  
  The encoding works as follows:
  The shape of the input `x` to the `encode` method must be either `(dim)` or
  `(b, dim)`, where `dim` is the dimenion of the vector to which the transform
  is to be applied, and must be statically known. `b` represents an optional
  batch dimension, and does not need to be statically known.
  
  If the shape of the input is `(dim)`, it is first expanded to `(1, dim)`. The
  input of shape `(b, dim)` has signs randomly flipped (as determined by random
  seed to be reused in decoding) and is padded with zeros to dimension
  `(b, dim_2)`, where `dim_2` is the smallest power of 2 larger than or equal
  to `dim`.
  
  The same transform is then applied to each of the `b` vectors of shape
  `dim_2`. If `H` represents the `(dim_2, dim_2)` Hadamard matrix and `D`
  represents the `(dim, dim_2)` diagonal matrix with randomly sampled `+1/-1`
  elements, the `encode` method computes `x[i, :]*D*H` for every `i`. In other
  words, if the leading dimension represents a batch, the transform is applied
  to every element in the batch. The encoded value then has shape `(b, dim_2)`,
  where `dim_2` is the smallest power of 2 larger than or equal to `dim`.
class_docstr_tok: ["Encoding","stage","multiplying","input","by","appropriate","randomized","Hadamard","matrix",".","This","encoding","stage","implements","the","fast","Walsh-Hadamard","transform","to","efficiently","compute","matrix-vector","product","in","O","(","n","log","n",")","time",".","https",":","\/\/en.wikipedia.org\/wiki\/Fast_Walsh","%","E2","%","80","%","93Hadamard_transform","The","useful","property","of","randomized","Hadamard","transform","is","that","it","spreads","the","information","in","a","vector","more","uniformly","across","its","coefficients",".","This","work","well","together","with","uniform","quantization",",","as","it","reduces","the","dynamic","range","of","the","coefficients","to","be","quantized",",","decreasing","the","error","incurred","by","quantization",".","The","encoding","works","as","follows",":","The","shape","of","the","input","`","x","`","to","the","`","encode","`","method","must","be","either","`","(","dim",")","`","or","`","(","b",",","dim",")","`",",","where","`","dim","`","is","the","dimenion","of","the","vector","to","which","the","transform","is","to","be","applied",",","and","must","be","statically","known",".","`","b","`","represents","an","optional","batch","dimension",",","and","does","not","need","to","be","statically","known",".","If","the","shape","of","the","input","is","`","(","dim",")","`",",","it","is","first","expanded","to","`","(","1",",","dim",")","`",".","The","input","of","shape","`","(","b",",","dim",")","`","has","signs","randomly","flipped","(","as","determined","by","random","seed","to","be","reused","in","decoding",")","and","is","padded","with","zeros","to","dimension","`","(","b",",","dim_2",")","`",",","where","`","dim_2","`","is","the","smallest","power","of","2","larger","than","or","equal","to","`","dim","`",".","The","same","transform","is","then","applied","to","each","of","the","`","b","`","vectors","of","shape","`","dim_2","`",".","If","`","H","`","represents","the","`","(","dim_2",",","dim_2",")","`","Hadamard","matrix","and","`","D","`","represents","the","`","(","dim",",","dim_2",")","`","diagonal","matrix","with","randomly","sampled","`","+1\/-1","`","elements",",","the","`","encode","`","method","computes","`","x","[","i",",",":","]","*","D","*","H","`","for","every","`","i","`",".","In","other","words",",","if","the","leading","dimension","represents","a","batch",",","the","transform","is","applied","to","every","element","in","the","batch",".","The","encoded","value","then","has","shape","`","(","b",",","dim_2",")","`",",","where","`","dim_2","`","is","the","smallest","power","of","2","larger","than","or","equal","to","`","dim","`","."]
docstr: Pads with zeros to the next power of two.
code: def _pad(self, x):
      """Pads with zeros to the next power of two."""
      dim = x.shape.as_list()[1]
      pad_dim = 2 ** int(np.ceil(np.log2(dim)))
      if pad_dim != dim:
          x = tf.pad(x, [[0, 0], [0, pad_dim - dim]])
      return x
  
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 9 for calling the HadamardEncodingStage obj's underlying member method code with example usage: obj._pad(x) and returns: x