def test_computation_uniqueness(thr): """ A regression test for the bug with a non-updating counter. """ size = 10000 batch = 1 rng = CBRNG.normal_bm(Type(numpy.complex64, shape=(batch, size)), 1) dest1_dev = thr.empty_like(rng.parameter.randoms) dest2_dev = thr.empty_like(rng.parameter.randoms) counters = rng.create_counters() counters_dev = thr.to_device(counters) rngc = rng.compile(thr) rngc(counters_dev, dest1_dev) rngc(counters_dev, dest2_dev) assert not diff_is_negligible(dest1_dev.get(), dest2_dev.get())
def test_computation_uniqueness(thr): """ A regression test for the bug with a non-updating counter. """ size = 10000 batch = 1 rng = CBRNG.normal_bm(Type(numpy.complex64, shape=(batch, size)), 1) dest1_dev = thr.empty_like(rng.parameter.randoms) dest2_dev = thr.empty_like(rng.parameter.randoms) counters = rng.create_counters() counters_dev = thr.to_device(counters) rngc = rng.compile(thr) rngc(counters_dev, dest1_dev) rngc(counters_dev, dest2_dev) assert not diff_is_negligible(dest1_dev.get(), dest2_dev.get(), verbose=False)
def normal(self, array, mean, std, seed=None): kernel_cache, thread = self.kernel_cache, self.thread key = (self.normal, array.shape, array.dtype, mean, std, thread) if key not in kernel_cache.keys(): log.info("compiling " + str(key)) rng = CBRNG.normal_bm(Type(array.dtype, shape=array.shape), len(array.shape), # @UndefinedVariable sampler_kwds=dict(mean=numpy.float32(mean), std=numpy.float32(std)), seed=seed) counters = thread.to_device(rng.create_counters()) kernel_cache[key] = (rng.compile(thread), counters) (rng, counters) = kernel_cache[key] rng(counters, array) return array
def normal(self, array, mean, std, seed=None): kernel_cache, thread = self.kernel_cache, self.thread key = (self.normal, array.shape, array.dtype, mean, std, thread) if key not in kernel_cache.keys(): log.info("compiling " + str(key)) rng = CBRNG.normal_bm( Type(array.dtype, shape=array.shape), len(array.shape), # @UndefinedVariable sampler_kwds=dict(mean=numpy.float32(mean), std=numpy.float32(std)), seed=seed) counters = thread.to_device(rng.create_counters()) kernel_cache[key] = (rng.compile(thread), counters) (rng, counters) = kernel_cache[key] rng(counters, array) return array