Skip to content

Instantly share code, notes, and snippets.

@fperez

fperez/error.py

Created Nov 15, 2011
Embed
What would you like to do?
A simple file with an error for testing interactive debugging
#!/usr/bin/env python
"""
file with deliberate errors to check IPython.
"""
from numpy import *
import time,sys
import sys
#from IPython.Debugger import Tracer; debug_here = Tracer()
g1='a global'
def explode():
a = 'a local variable'
print 'now, we blow up!'
1/0
class foo:
"""foo class docstring"""
def __init__(self):
"""init ds"""
pass
class bar:
"""bar class docstring"""
def __init__(self):
"""bar init ds"""
pass
def __call__(self):
"""call ds"""
print 'bar called!'
def Ramp(result, size, start, end):
step = (end-start)/(size-1)
for i in xrange(size):
result[i] = start + step*i
def RampNum(result, size, start, end):
tmp = zeros(size+1)
step = (end-start)/(size-1-tmp)
result[:] = arange(size)*step + start
def main():
#print 'hi'
size = 6
reps = 5
print 'reps:',reps
array_normal = [0]*size
t0=time.clock()
for i in xrange(reps): # <<<<< ERROR (fork instead of for)
Ramp(array_normal, size, 0.0, 1.0)
Rtime = time.clock()-t0
#print 'Ramp time:', Rtime
t0=time.clock()
array_num = zeros(size,'d')
for i in xrange(reps):
RampNum(array_num, size, 0.0, 1.0)
RNtime = time.clock()-t0
print 'RampNum time:', RNtime
print 'speedup:',Rtime/RNtime
#main()
if __name__ == '__main__':
#explode()
x = 'hi'
main()
g2='another global'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment