How to use the cupy.random function in cupy

To help you get started, we’ve selected a few cupy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github musyoku / chainer-glow / run / debug / check_reverse.py View on Github external
# for k in range(size):
    #     rev_conv_1x1 = layers[size - k - 1][1]
    #     rev_x, _ = rev_conv_1x1(rev_x)
    # error = cf.mean(abs(x - rev_x))
    # print("lu_1x1:", error)

    # affine coupling layer
    params = glow.nn.additive_coupling.Parameters(
        channels_x=channels_x // 2, channels_h=128)
    params.to_gpu()
    params.conv_1(x[:, 0::2])
    params.conv_1.W.data = xp.random.uniform(
        -1.0, 1.0, size=params.conv_1.W.data.shape).astype("float32")
    params.conv_2.W.data = xp.random.uniform(
        -1.0, 1.0, size=params.conv_2.W.data.shape).astype("float32")
    params.conv_3.W.data = xp.random.uniform(
        -1.0, 1.0, size=params.conv_3.W.data.shape).astype("float32")
    params.scale.data = xp.random.uniform(
        -1.0, 1.0, size=params.scale.data.shape).astype("float32")
    nonlinear_mapping = glow.nn.additive_coupling.NonlinearMapping(params)
    coupling_layer = glow.nn.additive_coupling.AdditiveCoupling(
        nn=nonlinear_mapping)
    rev_coupling_layer = coupling_layer.reverse_copy()

    y = x
    for _ in range(size):
        y, _ = coupling_layer(y)
    rev_x = y
    for _ in range(size):
        rev_x, _ = rev_coupling_layer(rev_x)
    error = cf.mean(abs(x - rev_x))
    print("coupling:", error)
github oreilly-japan / deep-learning-from-scratch-3 / tests / gpu / gpu_test_pooling.py View on Github external
def test_backward1(self):
        n, c, h, w = 1, 5, 16, 16
        ksize, stride, pad = 2, 2, 0
        x = np.random.randn(n, c, h, w).astype('f') * 100
        f = lambda x: F.pooling_simple(x, ksize, stride, pad)
        self.assertTrue(gradient_check(f, x))
github oreilly-japan / deep-learning-from-scratch-3 / tests / gpu / gpu_test_pooling.py View on Github external
def test_backward1(self):
        n, c, h, w = 1, 5, 16, 16
        ksize, stride, pad = 2, 2, 0
        x = np.random.randn(n, c, h, w).astype('f') * 1000
        f = lambda x: F.pooling(x, ksize, stride, pad)
        self.assertTrue(gradient_check(f, x))
github bwohlberg / sporco / tests / cupy / admm / test_cbpdn.py View on Github external
def test_25(self):
        N = 16
        Nd = 5
        Cs = 3
        K = 2
        M = 4
        D = cp.random.randn(Nd, Nd, M)
        s = cp.random.randn(N, N, Cs, K)
        lmbda = 1e-1
        try:
            b = cbpdn.ConvBPDNMaskDcpl(D, s, lmbda)
            b.solve()
        except Exception as e:
            print(e)
            assert 0
github chainer / chainer / tests / cupy_tests / creation_tests / test_from_data.py View on Github external
def test_copy_multigpu(self, dtype, order):
        with cuda.Device(0):
            src = cupy.random.uniform(-1, 1, (2, 3)).astype(dtype)
        with cuda.Device(1):
            dst = src.copy(order)
        testing.assert_allclose(src, dst, rtol=0, atol=0)
github chainer / chainer / tests / cupy_tests / random_tests / test_sample.py View on Github external
def test_randn_invalid_argument(self):
        with self.assertRaises(TypeError):
            random.randn(1, 2, 3, unnecessary='unnecessary_argument')
github oreilly-japan / deep-learning-from-scratch-3 / tests / gpu / gpu_test_conv2d.py View on Github external
def test_forward2(self):
        n, c, h, w = 1, 5, 15, 15
        o, k, s, p = 8, (3, 3), (3, 1), (2, 1)
        x = np.random.randn(n, c, h, w).astype('f')
        W = np.random.randn(o, c, k[0], k[1]).astype('f')
        b = None
        y = F.conv2d_simple(x, W, b, s, p)
        expected = CF.convolution_2d(x, W, b, s, p)
        self.assertTrue(array_allclose(expected.data, y.data))
github Pinafore / qb / qanta / old_buzzer / rnn_0.py View on Github external
def main():
    np.random.seed(0)
    try: 
        import cupy
        cupy.random.seed(0)
    except Exception:
        pass

    option2id, all_guesses = load_quizbowl()
    train_iter = QuestionIterator(all_guesses[c.BUZZER_TRAIN_FOLD], option2id,
            batch_size=128, make_vector=dense_vector0)
    dev_iter = QuestionIterator(all_guesses[c.BUZZER_DEV_FOLD], option2id,
            batch_size=128, make_vector=dense_vector0)
    devtest_iter = QuestionIterator(all_guesses['test'], option2id,
            batch_size=128, make_vector=dense_vector0)
    expo_iter = QuestionIterator(all_guesses['expo'], option2id,
            batch_size=128, make_vector=dense_vector0)

    n_hidden = 300
    model_name = 'neo_0'
    model_dir = 'output/buzzer/neo/{}.npz'.format(model_name)