# tensorflow::ops::CompareAndBitpack Class Reference

# 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]
```

<br />


**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](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object
- input: Values to compare against `
  threshold
  ` and bitpack.
- threshold: Threshold to compare against.

<br />


Returns:

- `
  https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output
  ` : The bitpacked comparisons.

<br />

| ### Constructors and Destructors ||
|---|---|
| ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/compare-and-bitpack#classtensorflow_1_1ops_1_1_compare_and_bitpack_1aa00f05feb63c6001dbeb274f30d67977 (const :: https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope & scope, :: https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input input, :: https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input threshold) ` ||

| ### Public attributes ||
|---|---|
| ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/compare-and-bitpack#classtensorflow_1_1ops_1_1_compare_and_bitpack_1a844ac2bc7be66b00b7165a65b4fd7b5c ` | ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation ` |
| ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/compare-and-bitpack#classtensorflow_1_1ops_1_1_compare_and_bitpack_1a52739fa1033fe1e93ee013270d8adb3c ` | ` :: https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output ` |

| ### Public functions ||
|---|---|
| ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/compare-and-bitpack#classtensorflow_1_1ops_1_1_compare_and_bitpack_1af6f8f9c40e4b60d75a6a6eb9d0c39ae8 () const ` | ` ::tensorflow::Node * ` |
| ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/compare-and-bitpack#classtensorflow_1_1ops_1_1_compare_and_bitpack_1a107c8a31460e12f5d2c4892c9e3c6c1e () const ` | ` ` |
| ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/compare-and-bitpack#classtensorflow_1_1ops_1_1_compare_and_bitpack_1ade9a5b902ca0f3af8969b0157da966de () 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 
```