diff --git a/privacy/analysis/rdp_accountant.py b/privacy/analysis/rdp_accountant.py index 8c63dfe..b71edf8 100644 --- a/privacy/analysis/rdp_accountant.py +++ b/privacy/analysis/rdp_accountant.py @@ -45,11 +45,7 @@ import sys import numpy as np from scipy import special - -try: - long -except NameError: - long = int +import six ######################## # LOG-SPACE ARITHMETIC # @@ -91,7 +87,7 @@ def _log_print(logx): def _compute_log_a_int(q, sigma, alpha): """Compute log(A_alpha) for integer alpha. 0 < q < 1.""" - assert isinstance(alpha, (int, long)) + assert isinstance(alpha, six.integer_types) # Initialize with 0 in the log space. log_a = -np.inf diff --git a/privacy/optimizers/gaussian_query_test.py b/privacy/optimizers/gaussian_query_test.py index 37b8789..7de0e51 100644 --- a/privacy/optimizers/gaussian_query_test.py +++ b/privacy/optimizers/gaussian_query_test.py @@ -24,11 +24,6 @@ import tensorflow as tf from privacy.optimizers import gaussian_query -try: - xrange -except NameError: - xrange = range - def _run_query(query, records): """Executes query on the given set of records as a single sample. @@ -114,7 +109,7 @@ class GaussianQueryTest(tf.test.TestCase, parameterized.TestCase): query_result = _run_query(query, [record1, record2]) noised_averages = [] - for _ in xrange(1000): + for _ in range(1000): noised_averages.append(sess.run(query_result)) result_stddev = np.std(noised_averages) diff --git a/privacy/optimizers/nested_query_test.py b/privacy/optimizers/nested_query_test.py index add2fe1..9ec643b 100644 --- a/privacy/optimizers/nested_query_test.py +++ b/privacy/optimizers/nested_query_test.py @@ -30,11 +30,6 @@ nest = tf.contrib.framework.nest _basic_query = gaussian_query.GaussianSumQuery(1.0, 0.0) -try: - xrange -except NameError: - xrange = range - def _run_query(query, records): """Executes query on the given set of records as a single sample. @@ -145,7 +140,7 @@ class NestedQueryTest(tf.test.TestCase, parameterized.TestCase): query_result = _run_query(query, [record1, record2]) noised_averages = [] - for _ in xrange(1000): + for _ in range(1000): noised_averages.append(nest.flatten(sess.run(query_result))) result_stddev = np.std(noised_averages, 0)