def add_noise(h, test, sigma=0.2): xp = cuda.get_array_module(h.data) if test: return h else: return h + sigma * xp.random.randn(*h.data.shape)