import tensorflow as tf

        mask_shape = list(map(int, self.mask.shape))
        graph_typecheck.assert_shape(expanded_tensor, mask_shape + expected_extra_dims)

        value_if_masked = expanded_tensor.dtype.as_numpy_dtype(value_if_masked)
        if_masked_tensor = tf.fill(expanded_tensor.shape, value_if_masked)
        mask = self.mask
        for i in range(2, 2 + len(expected_extra_dims)):
            mask = tf.expand_dims(mask, axis=i)
