def num_to_str(num): if isinstance(num, COMPLEX_TYPES): num = complex(num) #cast to python complex if num == 0: return '0' #value is zero elif num.imag == 0: return '%s'%eng_notation.num_to_str(num.real) #value is real elif num.real == 0: return '%sj'%eng_notation.num_to_str(num.imag) #value is imaginary elif num.imag < 0: return '%s-%sj'%(eng_notation.num_to_str(num.real), eng_notation.num_to_str(abs(num.imag))) else: return '%s+%sj'%(eng_notation.num_to_str(num.real), eng_notation.num_to_str(num.imag)) else: return str(num)
def time_it(tb): start = os.times() tb.run() stop = os.times() delta = map((lambda a, b: a-b), stop, start) user, sys, childrens_user, childrens_sys, real = delta total_user = user + childrens_user total_sys = sys + childrens_sys if tb.machine_readable: print "%3d %3d %.3e %7.3f %7.3f %7.3f %7.3f %.6e %.3e" % ( tb.npipes, tb.nstages, tb.nsamples, real, total_user, total_sys, (total_user+total_sys)/real, tb.flop, tb.flop/real) else: print "npipes %7d" % (tb.npipes,) print "nstages %7d" % (tb.nstages,) print "nsamples %s" % (eng_notation.num_to_str(tb.nsamples),) print "real %7.3f" % (real,) print "user %7.3f" % (total_user,) print "sys %7.3f" % (total_sys,) print "(user+sys)/real %7.3f" % ((total_user + total_sys)/real,) print "pseudo_flop %s" % (eng_notation.num_to_str(tb.flop),) print "pseudo_flop/real %s" % (eng_notation.num_to_str(tb.flop/real),)
def __init__(self): gr.top_block.__init__(self) default_nsamples = 10e6 parser=OptionParser(option_class=eng_option) parser.add_option("-p", "--npipelines", type="intx", default=1, metavar="NPIPES", help="the number of pipelines to create (default=%default)") parser.add_option("-s", "--nstages", type="intx", default=1, metavar="NSTAGES", help="the number of stages in each pipeline (default=%default)") parser.add_option("-N", "--nsamples", type="eng_float", default=default_nsamples, help=("the number of samples to run through the graph (default=%s)" % (eng_notation.num_to_str(default_nsamples)))) parser.add_option("-m", "--machine-readable", action="store_true", default=False, help="enable machine readable output") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() raise SystemExit, 1 self.npipes = options.npipelines self.nstages = options.nstages self.nsamples = options.nsamples self.machine_readable = options.machine_readable ntaps = 256 # Something vaguely like floating point ops self.flop = 2 * ntaps * options.npipelines * options.nstages * options.nsamples src = blocks.null_source(gr.sizeof_float) head = blocks.head(gr.sizeof_float, int(options.nsamples)) self.connect(src, head) for n in range(options.npipelines): self.connect(head, pipeline(options.nstages, ntaps))