% (D, P, N, N)) A_data = numpy.random.rand(N, N, P, D) Qbar_data = numpy.random.rand(1, N, N, P, D) Rbar_data = numpy.random.rand(1, N, N, P, D) #---------------------------------------------- # STEP 1: # QR decomposition by Givens Rotations # using pyadolc for the differentiation #---------------------------------------------- A = A_data[:, :, 0, 0] # trace QR decomposition with adolc AP = AdolcProgram() AP.trace_on(1) aA = adouble(A) AP.independent(aA) aQ, aR = qr(aA) AP.dependent(aQ) AP.dependent(aR) AP.trace_off() for r in range(repetitions): A = A_data[:, :, 0, 0] # compute push forward VA = A_data[:, :, :, 1:] tic = time() out = AP.forward([A], [VA]) toc = time() runtime_pyadolc_push_forward = toc - tic
print 'running runtime tests for A.shape = (D,P,N,N) = %d, %d, %d, %d'%(D,P,N,N) A_data = numpy.random.rand(N,N,P,D) Qbar_data = numpy.random.rand(1,N,N,P,D) Rbar_data = numpy.random.rand(1,N,N,P,D) #---------------------------------------------- # STEP 1: # QR decomposition by Givens Rotations # using pyadolc for the differentiation #---------------------------------------------- A = A_data[:,:,0,0] # trace QR decomposition with adolc AP = AdolcProgram() AP.trace_on(1) aA = adouble(A) AP.independent(aA) aQ, aR = qr(aA) AP.dependent(aQ) AP.dependent(aR) AP.trace_off() for r in range(repetitions): A = A_data[:,:,0,0] # compute push forward VA = A_data[:,:,:,1:] tic = time() out = AP.forward([A],[VA]) toc = time() runtime_pyadolc_push_forward = toc - tic
x = adolc.adouble(numpy.random.rand(N)) adolc.independent(x) y = f(x) adolc.dependent(y) adolc.trace_off() end_time = time.time() time_trace_adolc = end_time - start_time # trace with PYADOLC.cgraph from adolc.cgraph import AdolcProgram start_time = time.time() ap = AdolcProgram() ap.trace_on(2) x = adolc.adouble(numpy.random.rand(N)) ap.independent(x) y = f(x) ap.dependent(y) ap.trace_off() end_time = time.time() time_trace_cgraph = end_time - start_time # time ALGOPY hos_forward x = UTP(numpy.random.rand(D, N)) start_time = time.time() for rep in range(reps): cg.pushforward([x]) end_time = time.time() time_hos_forward_algopy = end_time - start_time # time PYADOLC hos_forward
adolc.trace_on(1) x = adolc.adouble(numpy.random.rand(N)) adolc.independent(x) y = f(x) adolc.dependent(y) adolc.trace_off() end_time = time.time() time_trace_adolc = end_time - start_time # trace with PYADOLC.cgraph from adolc.cgraph import AdolcProgram start_time = time.time() ap = AdolcProgram() ap.trace_on(2) x = adolc.adouble(numpy.random.rand(N)) ap.independent(x) y = f(x) ap.dependent(y) ap.trace_off() end_time = time.time() time_trace_cgraph = end_time - start_time # time ALGOPY hos_forward x = UTP(numpy.random.rand(D, N)) start_time = time.time() for rep in range(reps): cg.pushforward([x]) end_time = time.time() time_hos_forward_algopy = end_time - start_time # time PYADOLC hos_forward