提交 1f618c4f 编写于 作者: M minqiyang

Fix the overfix of 2to3 in xrange

上级 5656f64b
......@@ -24,7 +24,7 @@ import tarfile
import gzip
import itertools
import paddle.dataset.common
from six.moves import zip
from six.moves import zip, range
__all__ = ['test, get_dict', 'get_embedding', 'convert']
......
......@@ -25,6 +25,7 @@ import collections
import tarfile
import re
import string
from six.moves import range
__all__ = ['build_dict', 'train', 'test', 'convert']
......@@ -66,7 +67,7 @@ def build_dict(pattern, cutoff):
dictionary = sorted(word_freq, key=lambda x: (-x[1], x[0]))
words, _ = list(zip(*dictionary))
word_idx = dict(list(zip(words, list(range(len(words))))))
word_idx = dict(list(zip(words, range(len(words)))))
word_idx['<unk>'] = len(words)
return word_idx
......
......@@ -21,6 +21,7 @@ into paddle reader creators.
import paddle.dataset.common
import collections
import tarfile
from six.moves import range
__all__ = ['train', 'test', 'build_dict', 'convert']
......@@ -68,7 +69,7 @@ def build_dict(min_word_freq=50):
word_freq_sorted = sorted(word_freq, key=lambda x: (-x[1], x[0]))
words, _ = list(zip(*word_freq_sorted))
word_idx = dict(list(zip(words, list(range(len(words))))))
word_idx = dict(list(zip(words, range(len(words)))))
word_idx['<unk>'] = len(words)
return word_idx
......
......@@ -21,6 +21,7 @@ import paddle.dataset.common
import subprocess
import numpy
import platform
from six.moves import range
__all__ = ['train', 'test', 'convert']
URL_PREFIX = 'http://yann.lecun.com/exdb/mnist/'
......
......@@ -16,6 +16,7 @@ import paddle.dataset.common
import unittest
import tempfile
import glob
from six.moves import range
class TestCommon(unittest.TestCase):
......
......@@ -22,6 +22,7 @@ parse training set and test set into paddle reader creators.
import os
import numpy as np
import six
import tempfile
import tarfile
import os
......@@ -74,7 +75,7 @@ def load_data(filename, feature_num=14, ratio=0.8):
maximums, minimums, avgs = data.max(axis=0), data.min(axis=0), data.sum(
axis=0) / data.shape[0]
feature_range(maximums[:-1], minimums[:-1])
for i in range(feature_num - 1):
for i in six.moves.range(feature_num - 1):
data[:, i] = (data[:, i] - avgs[i]) / (maximums[i] - minimums[i])
offset = int(data.shape[0] * ratio)
UCI_TRAIN_DATA = data[:offset]
......
......@@ -346,7 +346,7 @@ class Executor(object):
def _fetch_data(self, fetch_list, fetch_var_name, scope):
outs = [
core.get_fetch_variable(scope, fetch_var_name, i)
for i in range(len(fetch_list))
for i in six.moves.range(len(fetch_list))
]
return outs
......
......@@ -1497,7 +1497,9 @@ class Program(object):
else:
p = Program()
p.desc = core.ProgramDesc(self.desc)
p.blocks = [Block(p, i) for i in range(self.desc.num_blocks())]
p.blocks = [
Block(p, i) for i in six.moves.range(self.desc.num_blocks())
]
p._sync_with_cpp()
p._copy_param_info_from(self)
......@@ -1549,7 +1551,9 @@ class Program(object):
targets_idx.append([t.block.idx, t.idx])
res = Program()
res.desc = core.prune(self.desc, targets_idx)
res.blocks = [Block(res, i) for i in range(res.desc.num_blocks())]
res.blocks = [
Block(res, i) for i in six.moves.range(res.desc.num_blocks())
]
res._sync_with_cpp()
return res
......@@ -1590,13 +1594,15 @@ class Program(object):
root_block._remove_var(var.name())
# change all `is_test` attributes to True
for i in range(res.desc.num_blocks()):
for i in six.moves.range(res.desc.num_blocks()):
block = res.desc.block(i)
for j in range(block.op_size()):
for j in six.moves.range(block.op_size()):
op = block.op(j)
if op.has_attr('is_test'):
op.set_attr('is_test', True)
res.blocks = [Block(res, i) for i in range(res.desc.num_blocks())]
res.blocks = [
Block(res, i) for i in six.moves.range(res.desc.num_blocks())
]
res._sync_with_cpp()
return res
......@@ -1616,7 +1622,7 @@ class Program(object):
"""
p = Program()
p.desc = core.ProgramDesc(binary_str)
p.blocks = [Block(p, i) for i in range(p.desc.num_blocks())]
p.blocks = [Block(p, i) for i in six.moves.range(p.desc.num_blocks())]
p._sync_with_cpp()
return p
......
......@@ -85,7 +85,7 @@ class LayerHelper(object):
raise ValueError("parameter number mismatch")
elif len(param_attr) == 1 and length != 1:
tmp = [None] * length
for i in range(length):
for i in six.moves.range(length):
tmp[i] = copy.deepcopy(param_attr[0])
param_attr = tmp
return param_attr
......
......@@ -21,6 +21,7 @@ from ..layer_helper import LayerHelper
from . import tensor
from . import nn
import math
import six
from functools import reduce
__all__ = [
......@@ -1033,7 +1034,7 @@ def multi_box_head(inputs,
min_sizes = []
max_sizes = []
step = int(math.floor(((max_ratio - min_ratio)) / (num_layer - 2)))
for ratio in range(min_ratio, max_ratio + 1, step):
for ratio in six.moves.range(min_ratio, max_ratio + 1, step):
min_sizes.append(base_size * ratio / 100.)
max_sizes.append(base_size * (ratio + step) / 100.)
min_sizes = [base_size * .10] + min_sizes
......
......@@ -13,6 +13,7 @@
# limitations under the License.
import contextlib
import multiprocessing
import six
import threading
from ..data_feeder import DataFeeder
......@@ -69,7 +70,7 @@ def data(name,
"""
helper = LayerHelper('data', **locals())
shape = list(shape)
for i in range(len(shape)):
for i in six.moves.range(len(shape)):
if shape[i] is None:
shape[i] = -1
append_batch_size = False
......@@ -674,7 +675,7 @@ def py_reader(capacity,
def __tensor_provider__():
for slots in paddle_reader():
yield [slots[str(idx)] for idx in xrange(counter)]
yield [slots[str(idx)] for idx in six.moves.xrange(counter)]
__set_tensor_provider__(__tensor_provider__)
......@@ -1005,7 +1006,7 @@ class Preprocessor(object):
source_lod_levels = self.underlying_reader.desc.lod_levels()
self.source_var_names = [
unique_name("preprocessor_source")
for _ in range(len(source_shapes))
for _ in six.moves.range(len(source_shapes))
]
source_vars = []
for var_name, shape, dtype, lod_level in zip(
......
......@@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import six
from . import layers
__all__ = [
......@@ -210,7 +211,7 @@ def img_conv_group(input,
conv_with_batchnorm = __extend_list__(conv_with_batchnorm)
conv_batchnorm_drop_rate = __extend_list__(conv_batchnorm_drop_rate)
for i in range(len(conv_num_filter)):
for i in six.moves.range(len(conv_num_filter)):
local_conv_act = conv_act
if conv_with_batchnorm[i]:
local_conv_act = None
......
......@@ -19,6 +19,7 @@ from . import framework
from . import executor
import warnings
import sys
import six
import os
__all__ = ['ParallelExecutor', 'ExecutionStrategy', 'BuildStrategy']
......@@ -95,7 +96,7 @@ class ParallelExecutor(object):
self._places = []
self._act_places = []
if use_cuda:
for i in range(core.get_cuda_device_count()):
for i in six.moves.range(core.get_cuda_device_count()):
p = core.Place()
self._act_places.append(core.CUDAPlace(i))
p.set_place(self._act_places[-1])
......@@ -103,7 +104,7 @@ class ParallelExecutor(object):
else:
cpu_num = int(
os.environ.get('CPU_NUM', multiprocessing.cpu_count()))
for i in range(cpu_num):
for i in six.moves.range(cpu_num):
p = core.Place()
self._act_places.append(core.CPUPlace())
p.set_place(self._act_places[-1])
......
......@@ -13,6 +13,7 @@
# limitations under the License.
import numpy
import six
import paddle
import paddle.dataset.mnist as mnist
......@@ -31,7 +32,7 @@ def network(is_train):
hidden = img
for i in xrange(2):
for i in six.moves.xrange(2):
hidden = fluid.layers.fc(input=hidden, size=100, act='tanh')
hidden = fluid.layers.dropout(
hidden, dropout_prob=0.5, is_test=not is_train)
......@@ -74,7 +75,7 @@ def main():
test_reader.decorate_paddle_reader(paddle.batch(mnist.test(), 512))
for epoch_id in xrange(10):
for epoch_id in six.moves.xrange(10):
train_reader.start()
try:
while True:
......
......@@ -22,6 +22,7 @@ import paddle.fluid as fluid
from paddle.fluid import core
import os
import sys
import six
import transformer_model
import paddle.dataset.wmt16 as wmt16
......@@ -222,7 +223,7 @@ class DistTransformer2x2(object):
first_loss, = exe.run(fetch_list=[avg_cost.name])
print(first_loss)
for i in xrange(5):
for i in six.moves.xrange(5):
_ = exe.run(fetch_list=[avg_cost.name])
last_loss, = exe.run(fetch_list=[avg_cost.name])
print(last_loss)
......
......@@ -14,6 +14,7 @@
import unittest
import numpy as np
import six
from op_test import OpTest
import paddle.fluid.core as core
from paddle.fluid.op import Operator
......@@ -59,7 +60,7 @@ class TestSpliteIds(unittest.TestCase):
x_tensor = x.get_tensor()
x_tensor.set(np_array, place)
outs_name = ["out%d" % i for i in xrange(3)]
outs_name = ["out%d" % i for i in six.moves.xrange(3)]
outs = [
scope.var(var_name).get_selected_rows() for var_name in outs_name
]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册