tf_quant_finance.math.qmc.utils.filter_tensor

Last updated: 2023-03-16.

tf_quant_finance.math.qmc.utils.filter_tensor#

View source

Filters an input Tensor based on bits set in a mask Tensor.

tf_quant_finance.math.qmc.utils.filter_tensor(
    value, bit_mask, bit_index
)

Examples#

import tensorflow as tf
import tf_quant_finance as tff

# Example: Filtering a given vector based on a mask.

tff.math.qmc.utils.filter_tensor(
    tf.constant([5, 6, 7, 8]),
    tf.constant([1, 2, 3, 4]),
    tf.constant([1, 1, 2, 2]))
# ==> tf.Tensor([0, 6, 0, 8], shape=(4,), dtype=int32)

Args:#

  • value: Scalar Tensor of integers.

  • bit_mask: Positive scalar Tensor of integers with the same shape and dtype as value.

  • bit_index: Positive scalar Tensor of integers with the same shape and dtype as value.

Returns:#

Tensor with the same shape as value equal to value if the bit_index-th bit in LSB 0 order is set in bit_mask, or zero otherwise i.e.: value * (1 & (bit_mask >>> bit_index))