Esempio n. 1
0
def run_bench(num_iter, s, k):
    wrld = ctf.comm()
    M = ctf.random.random((s,s))
    X = ctf.random.random((k,s))
    [U,S,VT] = ctf.svd(M)
    S = np.arange(0,s)+1
    M = ctf.dot(U*S,U.T())
    te = ctf.timer_epoch("BENCHMARK: SPD SOLVE")
    te.begin()
    times = []
    for i in range(num_iter):
        t0 = time.time()
        X = ctf.solve_spd(M,X)
        times.append(time.time()-t0)
    te.end()
    if ctf.comm().rank() == 0:
        print("ctf.solve_spd average time:",np.sum(times)/num_iter,"sec")
        print("ctf.solve_spd iteration timings:",times)
    te = ctf.timer_epoch("BENCHMARK: Manual Cholesky+TRSM SPD SOLVE")
    te.begin()
    times = []
    for i in range(num_iter):
        t0 = time.time()
        L = ctf.cholesky(M)
        X = ctf.solve_tri(M,X,from_left=False)
        times.append(time.time()-t0)
    te.end()
    if ctf.comm().rank() == 0:
        print("ctf.cholesky+solve_tri average time:",np.sum(times)/num_iter,"sec")
        print("ctf.cholesky+solve_tri iteration timings:",times)
Esempio n. 2
0
def solve(A, b, factor, r, regParam):
    n = A.shape[0]
    L = ctf.cholesky(A + regParam * ctf.eye(n))
    factor = ctf.solve_tri(L, b.reshape((n, 1)), True, True, False)
    factor = ctf.solve_tri(L, factor, True, True, True).reshape((n, ))

    return factor
Esempio n. 3
0
 def test_cholesky(self):
     n = 4
     for dt in [numpy.float32, numpy.float64]:
         A = ctf.random.random((n,n))
         A = ctf.astensor(A,dtype=dt)
         A = ctf.dot(A.T(), A)
         L = ctf.cholesky(A)
         D = L.T() * L
         D.i("ii") << -1.0*L.i("ii")*L.i("ii")
         self.assertTrue(abs(ctf.vecnorm(D))<= 1.e-6)
         self.assertTrue(allclose(A, ctf.dot(L,L.T())))
def cholesky(A):
    return ctf.cholesky(A)