Have a question? Connect with the community at the TensorFlow Forum

# tensorflow:: ops:: CompareAndBitpack

``` #include <math_ops.h> ```

Compare values of ``` input ``` to ``` threshold ``` and pack resulting bits into a ``` uint8 ``` .

## Summary

Each comparison returns a boolean ``` true ``` (if ``` input_value > threshold ``` ) or and ``` false ``` otherwise.

This operation is useful for Locality-Sensitive-Hashing (LSH) and other algorithms that use hashing approximations of cosine and ``` L2 ``` distances; codes can be generated from an input via:

```codebook_size = 50
codebook_bits = codebook_size * 32
codebook = tf.get_variable('codebook', [x.shape[-1].value, codebook_bits],
dtype=x.dtype,
initializer=tf.orthogonal_initializer())
codes = compare_and_threshold(tf.matmul(x, codebook), threshold=0.)
codes = tf.bitcast(codes, tf.int32)  # go from uint8 to int32
# now codes has shape x.shape[:-1] + [codebook_size]
```

NOTE : Currently, the innermost dimension of the tensor must be divisible by 8.

Given an ``` input ``` shaped ``` [s0, s1, ..., s_n] ``` , the output is a ``` uint8 ``` tensor shaped ``` [s0, s1, ..., s_n / 8] ``` .

Args:

• scope: A Scope object
• input: Values to compare against ``` threshold ``` and bitpack.
• threshold: Threshold to compare against.

Returns:

• ``` Output ``` : The bitpacked comparisons.

### Constructors and Destructors

``` CompareAndBitpack (const :: tensorflow::Scope & scope, :: tensorflow::Input input, :: tensorflow::Input threshold) ```

### Public attributes

``` operation ```
``` Operation ```
``` output ```
``` :: tensorflow::Output ```

### Public functions

``` node () const ```
``` ::tensorflow::Node * ```
``` operator::tensorflow::Input () const ```
``` ```
``` operator::tensorflow::Output () const ```
``` ```

## Public attributes

### operation

`Operation operation`

### output

`::tensorflow::Output output`

## Public functions

### CompareAndBitpack

``` CompareAndBitpack(
const ::tensorflow::Scope & scope,
::tensorflow::Input input,
::tensorflow::Input threshold
)```

### node

`::tensorflow::Node * node() const `

### operator::tensorflow::Input

` operator::tensorflow::Input() const `

### operator::tensorflow::Output

` operator::tensorflow::Output() const `
[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"Missing the information I need" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"Too complicated / too many steps" },{ "type": "thumb-down", "id": "outOfDate", "label":"Out of date" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"Samples / code issue" },{ "type": "thumb-down", "id": "otherDown", "label":"Other" }]
[{ "type": "thumb-up", "id": "easyToUnderstand", "label":"Easy to understand" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"Solved my problem" },{ "type": "thumb-up", "id": "otherUp", "label":"Other" }]