コード例 #1
0
def test_cholesky_grad():
    rng = np.random.RandomState(utt.fetch_seed())
    r = rng.randn(5, 5).astype(config.floatX)

    # The dots are inside the graph since Cholesky needs separable matrices

    # Check the default.
    utt.verify_grad(lambda r: gpu_cholesky(r.dot(r.T)), [r], 3, rng)
    # Explicit lower-triangular.
    utt.verify_grad(lambda r: GpuCholesky(lower=True)(r.dot(r.T)), [r], 3, rng)
    # Explicit upper-triangular.
    utt.verify_grad(lambda r: GpuCholesky(lower=False)(r.dot(r.T)), [r], 3, rng)
コード例 #2
0
def test_cholesky_grad_indef():
    x = theano.tensor.matrix()
    matrix = np.array([[1, 0.2], [0.2, -2]]).astype(config.floatX)
    cholesky = GpuCholesky(lower=True)
    chol_f = theano.function([x], theano.tensor.grad(cholesky(x).sum(), [x]))
    with pytest.raises(LinAlgError):
        chol_f(matrix)
コード例 #3
0
 def get_gpu_cholesky_func(self, lower=True, inplace=False):
     # Helper function to compile function from GPU Cholesky op.
     A = theano.tensor.matrix("A", dtype="float64")
     cholesky_op = GpuCholesky(lower=lower, inplace=inplace)
     chol_A = cholesky_op(A)
     return theano.function([A],
                            chol_A,
                            accept_inplace=inplace,
                            mode=mode_with_gpu)
コード例 #4
0
 def invalid_input_func():
     A = theano.tensor.tensor3("A", dtype="float64")
     GpuCholesky(lower=True, inplace=False)(A)