# tfc.ops.upper_bound

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/compression/blob/v2.14.1/tensorflow_compression/python/ops/math_ops.py#L27-L89) |

Same as [`tf.minimum`](https://www.tensorflow.org/api_docs/python/tf/math/minimum), but with helpful gradient for `inputs > bound`.

#### View aliases


**Main aliases**

[`tfc.upper_bound`](https://www.tensorflow.org/api_docs/python/tfc/ops/upper_bound)

<br />

    tfc.ops.upper_bound(
        inputs,
        bound,
        gradient='identity_if_towards',
        name='upper_bound'
    )

This function behaves just like [`tf.minimum`](https://www.tensorflow.org/api_docs/python/tf/math/minimum), but the behavior of the gradient
with respect to `inputs` for input values that hit the bound depends on
`gradient`:

If set to `'disconnected'`, the returned gradient is zero for values that hit
the bound. This is identical to the behavior of [`tf.minimum`](https://www.tensorflow.org/api_docs/python/tf/math/minimum).

If set to `'identity'`, the gradient is unconditionally replaced with the
identity function (i.e., pretending this function does not exist).

If set to `'identity_if_towards'`, the gradient is replaced with the identity
function, but only if applying gradient descent would push the values of
`inputs` towards the bound. For gradient values that push away from the bound,
the returned gradient is still zero.

> [!NOTE]
> **Note:** In the latter two cases, no gradient is returned for `bound`. Also, the implementation of `gradient == 'identity_if_towards'` currently assumes that the shape of `inputs` is the same as the shape of the output. It won't work reliably for all possible broadcasting scenarios.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `inputs` | Input tensor. |
| `bound` | Upper bound for the input tensor. |
| `gradient` | 'disconnected', 'identity', or 'identity_if_towards' (default). |
| `name` | Name for this op. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| [`tf.minimum(inputs, bound)`](https://www.tensorflow.org/api_docs/python/tf/math/minimum) ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | for invalid value of `gradient`. |

<br />