def binarize(tensor: tf.Tensor, bitsize: Optional[int]=None) -> tf.Tensor:
    'Extract bits of values in `tensor`, returning a `tf.Tensor` with same\n  dtype.'
    with tf.name_scope('binarize'):
        bitsize = (bitsize or (tensor.dtype.size * 8))
        bit_indices_shape = (([1] * len(tensor.shape)) + [bitsize])
        bit_indices = tf.range(bitsize, dtype=tensor.dtype)
        bit_indices = tf.reshape(bit_indices, bit_indices_shape)
        val = tf.expand_dims(tensor, (- 1))
        val = tf.bitwise.bitwise_and(tf.bitwise.right_shift(val, bit_indices), 1)
        assert (val.dtype == tensor.dtype)
        return val
Extract bits of values in `tensor`, returning a `tf.Tensor` with same
dtype.
def binarize(tensor: tf.Tensor, bitsize: Optional[int]=None) -> tf.Tensor:
    'Extract bits of values in `tensor`, returning a `tf.Tensor` with same\n  dtype.'
    with tf.name_scope('binarize'):
        bitsize = (bitsize or (tensor.dtype.size * 8))
        bit_indices_shape = (([1] * len(tensor.shape)) + [bitsize])
        bit_indices = tf.range(bitsize, dtype=tensor.dtype)
        bit_indices = tf.reshape(bit_indices, bit_indices_shape)
        val = tf.expand_dims(tensor, (- 1))
        val = tf.bitwise.bitwise_and(tf.bitwise.right_shift(val, bit_indices), 1)
        assert (val.dtype == tensor.dtype)
        return val