<commit_before>"""
Wrapper functions for writing code that is compatible with many versions
of TensorFlow.
"""
from distutils.version import LooseVersion
import warnings
import tensorflow as tf
# Strange import to work around pylint bug affecting python 3 / tf 1.8
from tensorflow import python # pylint: disable=no-name-in-module

# Assignment rather than import to work around pylint bug affecting python 3 / tf 1.8
app = python.platform.app
device_lib = python.client.device_lib
flags = python.platform.flags

def reduce_function(op_func, input_tensor, axis=None, keepdims=None,
                    name=None, reduction_indices=None):
  """
  Handler function for Tensorflow depreciation of keep_dims for tf 1.8
  and above, but tf 1.4 requires keep_dims
  :param op_func: expects the function to handle eg: tf.reduce_sum.
  :param input_tensor: The tensor to reduce. Should have numeric type.
  :param axis: The dimensions to reduce. If None (the default),
          reduces all dimensions. Must be in the range
          [-rank(input_tensor), rank(input_tensor)).
  :param keepdims: If true, retains reduced dimensions with length 1.
  :param name: A name for the operation (optional).
  :param reduction_indices: The old (deprecated) name for axis.
  :param keep_dims: Deprecated alias for keepdims.
  :return: outputs same value as op_func.<commit_msg>further fix to imports<commit_after>"""
Wrapper functions for writing code that is compatible with many versions
of TensorFlow.
"""
from distutils.version import LooseVersion
import warnings
import tensorflow as tf
# The following 2 imports are not used in this module. They are imported so that users of cleverhans.compat can
# get access to device_lib, app, and flags. A pylint bug makes these imports cause errors when using python3+tf1.8.
# Doing the sanitized import here once makes it possible to do "from cleverhans.compat import flags" throughout the
# library without needing to repeat the pylint boilerplate.
from tensorflow.python.client import device_lib # pylint: disable=no-name-in-module,unused-import
from tensorflow.python.platform import app, flags # pylint: disable=no-name-in-module,unused-import

def reduce_function(op_func, input_tensor, axis=None, keepdims=None,
                    name=None, reduction_indices=None):
  """
  Handler function for Tensorflow depreciation of keep_dims for tf 1.8
  and above, but tf 1.4 requires keep_dims
  :param op_func: expects the function to handle eg: tf.reduce_sum.
  :param input_tensor: The tensor to reduce. Should have numeric type.
  :param axis: The dimensions to reduce. If None (the default),
          reduces all dimensions. Must be in the range
          [-rank(input_tensor), rank(input_tensor)).
  :param keepdims: If true, retains reduced dimensions with length 1.
  :param name: A name for the operation (optional).
  :param reduction_indices: The old (deprecated) name for axis.
  :param keep_dims: Deprecated alias for keepdims.
  :return: outputs same value as op_func.
{'fraction_non_alphanumeric': 0.06841580870142809, 'fraction_numerical': 0.006642311524410495, 'mean_word_length': 4.229166666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4969845', 'n_tokens_mistral': 834, 'n_tokens_neox': 817, 'n_words': 365}