def dirichlet(a, times=1): a = np.array(a) normalize_scale = [ a.shape[-1], a.shape[-1] * times, int(a.size / a.shape[-1]) * times ] normal_block = int(500) normal_grid = int(normalize_scale[2] / normal_block + 1) normalize_scale = gpuarray.to_gpu(np.array(normalize_scale, dtype=np.int32)) a, b, output, matrix_scale, randomseed, partition, single_number = para_preprocess( times, np.float32, np.float32, a, 1.0) func = Sampler.get_function('rand_Gamma') func(randomseed, output, matrix_scale, a, b, grid=(partition[0], 1, 1), block=(partition[1], 1, 1)) func = Sampler.get_function('normalize') func(output, matrix_scale, normalize_scale, grid=(normal_grid, 1, 1), block=(normal_block, 1, 1)) output = output.get() return output
def chisquare(n, times=1, device='cpu'): n, output, matrix_scale, randomseed, partition, single_number = para_preprocess( times, np.int32, np.float32, n) func = Sampler.get_function('rand_Chisquare') func(randomseed, output, matrix_scale, n, grid=(partition[0], 1, 1), block=(partition[1], 1, 1)) if device == 'cpu': output = output.get() if single_number: return output[0] return output
def exponential(Lambda, times=1, device='cpu'): Lambda, output, matrix_scale, randomseed, partition, single_number = para_preprocess( times, np.float32, np.float32, Lambda) func = Sampler.get_function('rand_Exponential') func(randomseed, output, matrix_scale, Lambda, grid=(partition[0], 1, 1), block=(partition[1], 1, 1)) if device == 'cpu': output = output.get() if single_number: return output[0] return output
def hypergeometric(ng, nb, ns, times=1, device='cpu'): ng, nb, output, matrix_scale, randomseed, partition, single_number = para_preprocess( times, np.float32, np.int32, ng, nb) ns = gpuarray.to_gpu(np.array(ns, dtype=np.int32, order='C')) prob = ng / (ng + nb) func = Sampler.get_function('rand_Hypergeometric') func(randomseed, output, matrix_scale, prob, ns, grid=(partition[0], 1, 1), block=(partition[1], 1, 1)) if device == 'cpu': output = output.get() if single_number: return output[0] return output
def noncentral_chisquare(n, delta, times=1, var=1, device='cpu'): # n,delta,var must be same shape n = np.array(n, dtype=np.int32, order='C') delta, var, output, matrix_scale, randomseed, partition, single_number = para_preprocess( times, np.float32, np.float32, delta, var) func = Sampler.get_function('rand_Noncentral_Chisquare') func(randomseed, output, matrix_scale, n, delta, var, grid=(partition[0], 1, 1), block=(partition[1], 1, 1)) if device == 'cpu': output = output.get() if single_number: return output[0] return output
def triangular(left=0, mid=1, right=1, times=1, device='cpu'): left, output, matrix_scale, randomseed, partition, single_number = para_preprocess( times, np.float32, np.float32, left) mid = gpuarray.to_gpu(np.array(mid, dtype=np.float32, order='C')) right = gpuarray.to_gpu(np.array(right, dtype=np.float32, order='C')) func = Sampler.get_function('rand_Triangular') func(randomseed, output, matrix_scale, left, mid, right, grid=(partition[0], 1, 1), block=(partition[1], 1, 1)) if device == 'cpu': output = output.get() if single_number: return output[0] return output