Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop hacking #381

Merged
merged 5 commits into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ install:
# atari_py==0.1.4 causes an error
- pip install atari_py==0.1.1
- pip install autopep8
- pip install hacking
- pip install flake8
- pip install coveralls
- pip install opencv-python
- pip install pybullet
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ To test examples, run `test_examples.sh [gpu device id]`. `-1` would run example

## Coding style

We use PEP8. To check your code, use `autopep8` and `flake8` command installed by `hacking` package.
We use PEP8. To check your code, use `autopep8` and `flake8` packages.
```
$ pip install autopep8 hacking
$ pip install autopep8 flake8
$ autopep8 --diff path/to/your/code.py
$ flake8 path/to/your/code.py
```
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-r requirements.txt
autopep8
atari_py
hacking
flake8
mock
opencv-python
pytest
Expand Down
24 changes: 12 additions & 12 deletions tests/links_tests/test_noisy_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,34 @@
class TestFactorizedNoisyLinear(unittest.TestCase):
def setUp(self):
mu = chainer.links.Linear(*self.size_args, nobias=self.nobias)
self.l = noisy_linear.FactorizedNoisyLinear(mu)
self.linear = noisy_linear.FactorizedNoisyLinear(mu)

def _test_calls(self, xp):
x_data = xp.arange(12).astype(numpy.float32).reshape((2, 6))
x = chainer.Variable(x_data)
self.l(x)
self.l(x_data + 1)
self.l(x_data.reshape((2, 3, 2)))
self.linear(x)
self.linear(x_data + 1)
self.linear(x_data.reshape((2, 3, 2)))

def test_calls_cpu(self):
self._test_calls(numpy)

@attr.gpu
def test_calls_gpu(self):
self.l.to_gpu(0)
self.linear.to_gpu(0)
self._test_calls(cuda.cupy)

@attr.gpu
def test_calls_gpu_after_to_gpu(self):
mu = self.l.mu
mu = self.linear.mu
mu.to_gpu(0)
self.l = noisy_linear.FactorizedNoisyLinear(mu)
self.linear = noisy_linear.FactorizedNoisyLinear(mu)
self._test_calls(cuda.cupy)

def _test_randomness(self, xp):
x = xp.random.standard_normal((10, 6)).astype(numpy.float32)
y1 = self.l(x).array
y2 = self.l(x).array
y1 = self.linear(x).array
y2 = self.linear(x).array
d = float(xp.mean(xp.square(y1 - y2)))

# The parameter name suggests that
Expand All @@ -72,20 +72,20 @@ def test_randomness_cpu(self):
@attr.gpu
@condition.retry(3)
def test_randomness_gpu(self):
self.l.to_gpu(0)
self.linear.to_gpu(0)
self._test_randomness(cuda.cupy)

def _test_non_randomness(self, xp):
# Noises should be the same in a batch
x0 = xp.random.standard_normal((1, 6)).astype(numpy.float32)
x = xp.broadcast_to(x0, (2, 6))
y = self.l(x).array
y = self.linear(x).array
xp.testing.assert_allclose(y[0], y[1], rtol=1e-4)

def test_non_randomness_cpu(self):
self._test_non_randomness(numpy)

@attr.gpu
def test_non_randomness_gpu(self):
self.l.to_gpu(0)
self.linear.to_gpu(0)
self._test_non_randomness(cuda.cupy)