示例#1
0
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())
示例#2
0
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)
示例#3
0
 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
示例#4
0
    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