# Time stuff, we only import the timeit module here if we actually need it. from timeit import Timer if verbose: print "Will now time the solver 3 times, this could take a while in " \ "some cases." t = Timer(lambda: solver(args.t0, args.t1, args.dt, n, m, np.copy(u), f, args.nu, verbose=verbose)) times = t.repeat(repeat=3, number=1) if verbose: print "All run times:" print times print "Best running time in 3 runs were {} seconds.".format(min(times)) # Plot, magic happens here. u = he.heat_equation_plot(args.t0, args.t1, args.dt, n, m, u, f, args.nu, solver, verbose, args.save_plot) # Handle potential output file. if args.output_file: if not isinstance(u, np.ndarray): # Convert potential list to numpy array. if verbose: print "Converting list to numpy array" u = np.array(u) if verbose: print "Writing array to file {}".format(args.output_file.name) pickle.dump(u, args.output_file)
} else { is_u = true; } } /* Return boolean to tell current u. */ return_val = is_u; """ # Exectute weave code. is_u = weave.inline(code, ["t0", "t1", "dt", "nu", "u", "f", "u_2"]) # Return the correct array. if is_u: return u else: return u_2 if __name__ == '__main__': # Set initial values for a run if we call the file. t0 = 0. t1 = 1000. dt = 0.1 n = 50 m = 100 u = np.zeros((m, n)) f = np.ones((m, n)) nu = 1. heat_equation_plot(t0, t1, dt, n, m, u, f, nu, heat_equation_weave)