How to use the cupy.random.randn 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 bwohlberg / sporco / tests / cupy / dictlrn / test_onlinecdl.py View on Github external
def test_03(self):
        lmbda = 1e-1
        W = cp.random.randn(*self.S.shape[0:2])
        opt = onlinecdl.OnlineConvBPDNMaskDictLearn.Options()
        try:
            b = onlinecdl.OnlineConvBPDNMaskDictLearn(self.D0, lmbda, opt=opt)
            for it in range(5):
                img_index = cp.random.randint(0, self.S.shape[-1])
                b.solve(self.S[..., img_index], W)
        except Exception as e:
            print(e)
            assert 0
github bwohlberg / sporco / tests / cupy / admm / test_cbpdn.py View on Github external
def test_22(self):
        N = 32
        M = 4
        Nd = 8
        D = cp.random.randn(Nd, Nd, M)
        D /= cp.sqrt(cp.sum(D**2, axis=(0, 1)))
        X0 = cp.zeros((N, N, M))
        xr = cp.random.randn(N, N, M)
        xp = cp.abs(xr) > 3
        X0[xp] = cp.random.randn(X0[xp].size)
        S = cp.sum(sl.fftconv(D, X0), axis=2)
        lmbda = 1e-3
        opt = cbpdn.ConvBPDN.Options(
            {'Verbose': False, 'MaxMainIter': 500, 'RelStopTol': 1e-5,
             'rho': 5e-1, 'AutoRho': {'Enabled': False}})
        bp = cbpdn.ConvBPDN(D, S, lmbda, opt)
        Xp = bp.solve()
        epsilon = cp.linalg.norm(bp.reconstruct(Xp).squeeze() - S)
        opt = cbpdn.ConvMinL1InL2Ball.Options(
            {'Verbose': False, 'MaxMainIter': 500, 'RelStopTol': 1e-5,
             'rho': 2e2, 'RelaxParam': 1.0, 'AutoRho': {'Enabled': False}})
        bc = cbpdn.ConvMinL1InL2Ball(D, S, epsilon=epsilon, opt=opt)
        Xc = bc.solve()
        assert cp.linalg.norm(Xp - Xc) / cp.linalg.norm(Xp) < 1e-3
        assert(cp.abs(cp.linalg.norm(Xp.ravel(), 1) -
                      cp.linalg.norm(Xc.ravel(), 1)) < 1e-3)
github bwohlberg / sporco / tests / cupy / admm / test_cbpdn.py View on Github external
def test_18(self):
        Nr = 16
        Nc = 17
        Nd = 5
        M = 4
        D = cp.random.randn(Nd, Nd, M)
        s = cp.random.randn(Nr, Nc)
        lmbda = 1e-1
        mu = 1e-2
        try:
            b = cbpdn.ConvBPDNGradReg(D, s, lmbda, mu)
            b.solve()
        except Exception as e:
            print(e)
            assert 0
github bwohlberg / sporco / tests / cupy / admm / test_cbpdn.py View on Github external
def test_29(self):
        N = 16
        Nd = 5
        M = 4
        D = cp.random.randn(Nd, Nd, M)
        s = cp.random.randn(N, N)
        w = cp.ones(s.shape)
        lmbda = 1e-1
        try:
            b = cbpdn.AddMaskSim(cbpdn.ConvBPDN, D, s, w, lmbda)
            b.solve()
            b.reconstruct()
        except Exception as e:
            print(e)
            assert 0
github bwohlberg / sporco / tests / cupy / admm / test_bpdn.py View on Github external
def test_22(self):
        N = 8
        M = 16
        D = cp.random.randn(N, M)
        s = cp.random.randn(N, 1)
        lmbda = 1e-1
        opt = bpdn.BPDN.Options({'Verbose': False, 'MaxMainIter': 10,
                                 'Callback': CallbackTest, 'RelaxParam': 1.0})
        b = bpdn.BPDN(D, s, lmbda, opt=opt)
        assert b.getitstat() is None
        b.solve()
        assert b.runtime > 0.0
        assert b.k == 7
        assert b.var_x() is not None
        assert b.var_y() is not None
        assert b.var_u() is not None
github bwohlberg / sporco / tests / cupy / admm / test_bpdn.py View on Github external
def test_02(self):
        N = 8
        M = 16
        D = cp.random.randn(N, M)
        s = cp.random.randn(N, 1)
        try:
            b = bpdn.BPDN(D, s)
            b.solve()
        except Exception as e:
            print(e)
            assert 0
github bwohlberg / sporco / tests / cupy / admm / test_bpdn.py View on Github external
def test_06(self):
        N = 8
        M = 16
        D = cp.random.randn(N, M)
        s = cp.random.randn(N, 1)
        dt = cp.float32
        opt = bpdn.BPDN.Options({'Verbose': False, 'MaxMainIter': 20,
                                 'AutoRho': {'Enabled': True},
                                 'DataType': dt})
        b = bpdn.BPDN(D, s, lmbda=1.0, opt=opt)
        b.solve()
        assert b.X.dtype == dt
        assert b.Y.dtype == dt
        assert b.U.dtype == dt
github oreilly-japan / deep-learning-from-scratch-3 / tests / gpu / gpu_test_linear.py View on Github external
def test_backward2(self):
        x = np.random.randn(100, 200)
        W = np.random.randn(200, 300)
        b = None
        f = lambda x: F.linear(x, W, b)
        self.assertTrue(gradient_check(f, x))
github bwohlberg / sporco / tests / cupy / admm / test_cbpdn.py View on Github external
def test_12(self):
        N = 16
        Nd = 5
        Cs = 3
        M = 4
        D = cp.random.randn(Nd, Nd, M)
        s = cp.random.randn(N, N, Cs)
        lmbda = 1e-1
        try:
            opt = cbpdn.ConvBPDN.Options({'LinSolveCheck': True})
            b = cbpdn.ConvBPDN(D, s, lmbda, opt=opt, dimK=0)
            b.solve()
        except Exception as e:
            print(e)
            assert 0
        assert list2array(b.getitstat().XSlvRelRes).max() < 1e-5