Skip to content

Commit dcbfbb1

Browse files
committed
yapf format
1 parent d6c62e8 commit dcbfbb1

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

python/paddle/v2/dataset/mnist.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,21 @@ def reader():
2222
# According to http://stackoverflow.com/a/38061619/724872, we
2323
# cannot use standard package gzip here.
2424
m = subprocess.Popen(["zcat", image_filename], stdout=subprocess.PIPE)
25-
m.stdout.read(16) # skip some magic bytes
25+
m.stdout.read(16) # skip some magic bytes
2626

2727
l = subprocess.Popen(["zcat", label_filename], stdout=subprocess.PIPE)
28-
l.stdout.read(8) # skip some magic bytes
28+
l.stdout.read(8) # skip some magic bytes
2929

3030
while True:
3131
labels = numpy.fromfile(
32-
l.stdout, 'ubyte', count=buffer_size
33-
).astype("int")
32+
l.stdout, 'ubyte', count=buffer_size).astype("int")
3433

3534
if labels.size != buffer_size:
36-
break # numpy.fromfile returns empty slice after EOF.
35+
break # numpy.fromfile returns empty slice after EOF.
3736

3837
images = numpy.fromfile(
39-
m.stdout, 'ubyte', count=buffer_size * 28 * 28
40-
).reshape((buffer_size, 28 * 28)
41-
).astype('float32')
38+
m.stdout, 'ubyte', count=buffer_size * 28 * 28).reshape(
39+
(buffer_size, 28 * 28)).astype('float32')
4240

4341
images = images / 255.0 * 2.0 - 1.0
4442

@@ -50,18 +48,18 @@ def reader():
5048

5149
return reader()
5250

51+
5352
def train():
5453
return reader_creator(
55-
paddle.v2.dataset.common.download(
56-
TRAIN_IMAGE_URL, 'mnist', TRAIN_IMAGE_MD5),
57-
paddle.v2.dataset.common.download(
58-
TRAIN_LABEL_URL, 'mnist', TRAIN_LABEL_MD5),
59-
100)
54+
paddle.v2.dataset.common.download(TRAIN_IMAGE_URL, 'mnist',
55+
TRAIN_IMAGE_MD5),
56+
paddle.v2.dataset.common.download(TRAIN_LABEL_URL, 'mnist',
57+
TRAIN_LABEL_MD5), 100)
58+
6059

6160
def test():
6261
return reader_creator(
63-
paddle.v2.dataset.common.download(
64-
TEST_IMAGE_URL, 'mnist', TEST_IMAGE_MD5),
65-
paddle.v2.dataset.common.download(
66-
TEST_LABEL_URL, 'mnist', TEST_LABEL_MD5),
67-
100)
62+
paddle.v2.dataset.common.download(TEST_IMAGE_URL, 'mnist',
63+
TEST_IMAGE_MD5),
64+
paddle.v2.dataset.common.download(TEST_LABEL_URL, 'mnist',
65+
TEST_LABEL_MD5), 100)

python/paddle/v2/dataset/tests/common_test.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import unittest
33
import tempfile
44

5+
56
class TestCommon(unittest.TestCase):
67
def test_md5file(self):
7-
_, temp_path =tempfile.mkstemp()
8+
_, temp_path = tempfile.mkstemp()
89
with open(temp_path, 'w') as f:
910
f.write("Hello\n")
10-
self.assertEqual(
11-
'09f7e02f1290be211da707a266f153b3',
12-
paddle.v2.dataset.common.md5file(temp_path))
11+
self.assertEqual('09f7e02f1290be211da707a266f153b3',
12+
paddle.v2.dataset.common.md5file(temp_path))
1313

1414
def test_download(self):
1515
yi_avatar = 'https://avatars0.githubusercontent.com/u/1548775?v=3&s=460'
@@ -18,5 +18,6 @@ def test_download(self):
1818
paddle.v2.dataset.common.download(
1919
yi_avatar, 'test', 'f75287202d6622414c706c36c16f8e0d'))
2020

21+
2122
if __name__ == '__main__':
2223
unittest.main()

python/paddle/v2/dataset/tests/mnist_test.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import paddle.v2.dataset.mnist
22
import unittest
33

4+
45
class TestMNIST(unittest.TestCase):
56
def check_reader(self, reader):
67
sum = 0
@@ -14,13 +15,11 @@ def check_reader(self, reader):
1415

1516
def test_train(self):
1617
self.assertEqual(
17-
self.check_reader(paddle.v2.dataset.mnist.train()),
18-
60000)
18+
self.check_reader(paddle.v2.dataset.mnist.train()), 60000)
1919

2020
def test_test(self):
2121
self.assertEqual(
22-
self.check_reader(paddle.v2.dataset.mnist.test()),
23-
10000)
22+
self.check_reader(paddle.v2.dataset.mnist.test()), 10000)
2423

2524

2625
if __name__ == '__main__':

0 commit comments

Comments
 (0)