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)
def test_cholesky_grad_indef(): x = aesara.tensor.matrix() matrix = np.array([[1, 0.2], [0.2, -2]]).astype(config.floatX) cholesky = GpuCholesky(lower=True) chol_f = aesara.function([x], aesara.tensor.grad(cholesky(x).sum(), [x])) with pytest.raises(LinAlgError): chol_f(matrix)
def get_gpu_cholesky_func(self, lower=True, inplace=False): # Helper function to compile function from GPU Cholesky op. A = matrix("A", dtype="float64") cholesky_op = GpuCholesky(lower=lower, inplace=inplace) chol_A = cholesky_op(A) return aesara.function([A], chol_A, accept_inplace=inplace, mode=mode_with_gpu)
def invalid_input_func(): A = aesara.tensor.tensor3("A", dtype="float64") GpuCholesky(lower=True, inplace=False)(A)
def invalid_input_func(): A = vector("A", dtype="float64") GpuCholesky(lower=True, inplace=False)(A)