def generate(self, ary, size=None): """Generate quasi random number in ary. :param ary: Numpy array or cuda device array. :param size: Number of samples; Default to array size. Must be multiple of ndim. """ self._require_array(ary) size = size or ary.size dary, conv = cuda._auto_device(ary, stream=self.stream) self._gen.generate(dary, size) if conv: dary.copy_to_host(ary, stream=self.stream)
def poisson(self, ary, lmbd, size=None): '''Generate floating point random number sampled from a poisson distribution and fill into ary. :param ary: Numpy array or cuda device array. :param lmbda: Lambda for the distribution. :param size: Number of samples. Default to array size. ''' self._require_array(ary) size = size or ary.size dary, conv = cuda._auto_device(ary, stream=self.stream) self._gen.generate_poisson(dary, lmbd, size) if conv: dary.copy_to_host(ary, stream=self.stream)
def lognormal(self, ary, mean, sigma, size=None): '''Generate floating point random number sampled from a log-normal distribution and fill into ary. :param ary: Numpy array or cuda device array. :param mean: Center of the distribution. :param sigma: Standard deviation of the distribution. :param size: Number of samples. Default to array size. ''' self._require_array(ary) size = size or ary.size dary, conv = cuda._auto_device(ary, stream=self.stream) self._gen.generate_log_normal(dary, size, mean, sigma) if conv: dary.copy_to_host(ary, stream=self.stream)
def to_device(ary): dary, _ = cuda._auto_device(ary) return dary
def to_device(ary): dary, _ = cuda._auto_device(ary) return dary
def _readonly(*arys): ds = [] for a in arys: dmem, _ = cuda._auto_device(a) ds.append(dmem) yield ds