def runInertial(self, nPts): clocks = self.clocks dt = self.dt tVals = np.linspace(0, dt*(nPts-1), nPts) for cl in self.clocks.values(): for i in xrange(1,nPts): nextT = tVals[i] while True: tau1, tau2 = cl.accelLimits() x = cl.x v = cl.v tau = cl.pt g = cl.acceleration() v1, x1, tau1 = self.hypTStep(dt, v, x, tau, g) if tau1 > tau2: dtau = tau2-tau cl.v, cl.x, cl.t = self.tauStep(dtau, v, x, cl.t, g) cl.pt = tau2 else: cl.v, cl.x, cl.pt = v1, x1, tau1 cl.t += dt if cl.t >= nextT: cl.refx = cl.x cl.refv = cl.v cl.reft = cl.t cl.recordFrame(i) break
def runReference(self, nPts): clocks = self.clocks ref = self.ref dt = self.dt dur = self.duration ## make sure reference clock is not present in the list of clocks--this will be handled separately. clocks = clocks.copy() for k,v in clocks.items(): if v is ref: del clocks[k] break ref.refx = 0 ref.refv = 0 ref.refm = ref.m0 ## These are the set of proper times (in the reference frame) that will be simulated ptVals = np.linspace(ref.pt, ref.pt + dt*(nPts-1), nPts) for i in xrange(1,nPts): ## step reference clock ahead one time step in its proper time nextPt = ptVals[i] ## this is where (when) we want to end up while True: tau1, tau2 = ref.accelLimits() dtau = min(nextPt-ref.pt, tau2-ref.pt) ## do not step past the next command boundary g = ref.acceleration() v, x, t = Simulation.tauStep(dtau, ref.v, ref.x, ref.t, g) ref.pt += dtau ref.v = v ref.x = x ref.t = t ref.reft = ref.pt if ref.pt >= nextPt: break #else: #print "Stepped to", tau2, "instead of", nextPt ref.recordFrame(i) ## determine plane visible to reference clock ## this plane goes through the point ref.x, ref.t and has slope = ref.v ## update all other clocks for cl in clocks.values(): while True: g = cl.acceleration() tau1, tau2 = cl.accelLimits() ##Given current position / speed of clock, determine where it will intersect reference plane #t1 = (ref.v * (cl.x - cl.v * cl.t) + (ref.t - ref.v * ref.x)) / (1. - cl.v) t1 = Simulation.hypIntersect(ref.x, ref.t, ref.v, cl.x, cl.t, cl.v, g) dt1 = t1 - cl.t ## advance clock by correct time step v, x, tau = Simulation.hypTStep(dt1, cl.v, cl.x, cl.pt, g) ## check to see whether we have gone past an acceleration command boundary. ## if so, we must instead advance the clock to the boundary and start again if tau < tau1: dtau = tau1 - cl.pt cl.v, cl.x, cl.t = Simulation.tauStep(dtau, cl.v, cl.x, cl.t, g) cl.pt = tau1-0.000001 continue if tau > tau2: dtau = tau2 - cl.pt cl.v, cl.x, cl.t = Simulation.tauStep(dtau, cl.v, cl.x, cl.t, g) cl.pt = tau2 continue ## Otherwise, record the new values and exit the loop cl.v = v cl.x = x cl.pt = tau cl.t = t1 cl.m = None break ## transform position into reference frame x = cl.x - ref.x t = cl.t - ref.t gamma = (1.0 - ref.v**2) ** -0.5 vg = -ref.v * gamma cl.refx = gamma * (x - ref.v * t) cl.reft = ref.pt # + gamma * (t - ref.v * x) # this term belongs here, but it should always be equal to 0. cl.refv = (cl.v - ref.v) / (1.0 - cl.v * ref.v) cl.refm = None cl.recordFrame(i) t += dt
## tasks = range(10) results = [None] * len(tasks) results2 = results[:] results3 = results[:] size = 2000000 pg.mkQApp() ### Purely serial processing start = time.time() with pg.ProgressDialog('processing serially..', maximum=len(tasks)) as dlg: for i, x in enumerate(tasks): tot = 0 for j in xrange(size): tot += j * x results[i] = tot dlg += 1 if dlg.wasCanceled(): raise Exception('processing canceled') print("Serial time: %0.2f" % (time.time() - start)) ### Use parallelize, but force a single worker ### (this simulates the behavior seen on windows, which lacks os.fork) start = time.time() with mp.Parallelize( enumerate(tasks), results=results2, workers=1, progressDialog='processing serially (using Parallelizer)..') as tasker:
## tasks = range(10) results = [None] * len(tasks) results2 = results[:] results3 = results[:] size = 2000000 pg.mkQApp() ### Purely serial processing start = time.time() with pg.ProgressDialog('processing serially..', maximum=len(tasks)) as dlg: for i, x in enumerate(tasks): tot = 0 for j in xrange(size): tot += j * x results[i] = tot dlg += 1 if dlg.wasCanceled(): raise Exception('processing canceled') print( "Serial time: %0.2f" % (time.time() - start)) ### Use parallelize, but force a single worker ### (this simulates the behavior seen on windows, which lacks os.fork) start = time.time() with mp.Parallelize(enumerate(tasks), results=results2, workers=1, progressDialog='processing serially (using Parallelizer)..') as tasker: for i, x in tasker: tot = 0 for j in xrange(size): tot += j * x
] sort_methods = [ bubble, insertion, selection, quick, merge, shell, heap, counting, radix, bucket, gnome, comb, cocktail ] while True: print('\n\n\tSorting Algorithms\n\n') a_length = int(input('Size of the array to be sorted: ')) minimun = int(input('Smallest possible number: ')) maximun = int(input('Greater possible number: ')) vet = [random.randint(minimun, maximun) for r in xrange(a_length)] print('\nOriginal array: ') print(vet) print('\nChoose a Sort Algorithm: ') for i, x in enumerate(algorithms): print(i, ' - ', x) op = input() if op == '13': test_all_algoithms() elif int(op) > 13 or int(op) < 0: print('Invalid option.') else: