From 18a52670331818dcdd29e9d02ef95d6911dd12aa Mon Sep 17 00:00:00 2001 From: romanstingler Date: Sat, 27 Sep 2014 18:34:51 +0200 Subject: [PATCH 1/7] Update julia1.py --- 01_profiling/cpu_profiling/julia1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/01_profiling/cpu_profiling/julia1.py b/01_profiling/cpu_profiling/julia1.py index 4cbb7a1..2d010f2 100644 --- a/01_profiling/cpu_profiling/julia1.py +++ b/01_profiling/cpu_profiling/julia1.py @@ -94,7 +94,7 @@ def calc_pure_python(draw_output, desired_width, max_iterations): output = calculate_z_serial_purepython(max_iterations, zs, cs) end_time = time.time() secs = end_time - start_time - print calculate_z_serial_purepython.func_name + " took", secs, "seconds" + print calculate_z_serial_purepython.__name__ + " took", secs, "seconds" # this sum is expected for 1000^2 grid with 300 iterations assert sum(output) == 33219980 From 8459566a05a065122022e1c5711e11162770216f Mon Sep 17 00:00:00 2001 From: romanstingler Date: Sat, 27 Sep 2014 19:27:07 +0200 Subject: [PATCH 2/7] Update julia1_decorator.py --- 01_profiling/decorator_time/julia1_decorator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/01_profiling/decorator_time/julia1_decorator.py b/01_profiling/decorator_time/julia1_decorator.py index 3f3aa3a..f975498 100644 --- a/01_profiling/decorator_time/julia1_decorator.py +++ b/01_profiling/decorator_time/julia1_decorator.py @@ -14,7 +14,7 @@ def measure_time(*args, **kwargs): result = fn(*args, **kwargs) t2 = time.time() print ( - "@timefn:" + fn.func_name + " took " + str(t2 - t1) + " seconds") + "@timefn:" + fn.__name__ + " took " + str(t2 - t1) + " seconds") return result return measure_time @@ -65,7 +65,7 @@ def calc_pure_python(draw_output, desired_width, max_iterations): output = calculate_z_serial_purepython(max_iterations, zs, cs) end_time = time.time() secs = end_time - start_time - print calculate_z_serial_purepython.func_name + " took", secs, "seconds" + print calculate_z_serial_purepython.__name__ + " took", secs, "seconds" # this sum is expected for 1000^2 grid with 300 iterations assert sum(output) == 33219980 From 0ebb7bec9a0f098e073eaffbf443cf74fa95c527 Mon Sep 17 00:00:00 2001 From: romanstingler Date: Sat, 27 Sep 2014 19:28:35 +0200 Subject: [PATCH 3/7] Update julia1_nopil.py --- 01_profiling/cpu_profiling/julia1_nopil.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/01_profiling/cpu_profiling/julia1_nopil.py b/01_profiling/cpu_profiling/julia1_nopil.py index 2d184c2..1584480 100644 --- a/01_profiling/cpu_profiling/julia1_nopil.py +++ b/01_profiling/cpu_profiling/julia1_nopil.py @@ -51,7 +51,7 @@ def calc_pure_python(draw_output, desired_width, max_iterations): output = calculate_z_serial_purepython(max_iterations, zs, cs) end_time = time.time() secs = end_time - start_time - print calculate_z_serial_purepython.func_name + " took", secs, "seconds" + print calculate_z_serial_purepython.__name__ + " took", secs, "seconds" # this sum is expected for 1000^2 grid with 300 iterations assert sum(output) == 33219980 From 0c2ef2c9beb8ea6de635227a349d3083bd007a59 Mon Sep 17 00:00:00 2001 From: romanstingler Date: Sat, 27 Sep 2014 20:07:59 +0200 Subject: [PATCH 4/7] python 2.7 and 3.4 compatibility --- 01_profiling/cpu_profiling/julia1.py | 8 ++++---- 01_profiling/cpu_profiling/julia1_nopil.py | 9 +++++---- 01_profiling/decorator_time/julia1_decorator.py | 11 ++++++----- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/01_profiling/cpu_profiling/julia1.py b/01_profiling/cpu_profiling/julia1.py index 2d010f2..7f0b81a 100644 --- a/01_profiling/cpu_profiling/julia1.py +++ b/01_profiling/cpu_profiling/julia1.py @@ -13,7 +13,7 @@ def show_greyscale(output_raw, width, height, max_iterations): # convert our output to PIL-compatible input # scale to [0...255] max_iterations = float(max(output_raw)) - print max_iterations + print (max_iterations) scale_factor = float(max_iterations) scaled = [int(o / scale_factor * 255) for o in output_raw] output = array.array('B', scaled) # array of unsigned ints @@ -88,13 +88,13 @@ def calc_pure_python(draw_output, desired_width, max_iterations): zs.append(complex(xcoord, ycoord)) cs.append(complex(c_real, c_imag)) - print "Length of x:", len(x) - print "Total elements:", len(zs) + print ("Length of x:", len(x)) + print ("Total elements:", len(zs)) start_time = time.time() output = calculate_z_serial_purepython(max_iterations, zs, cs) end_time = time.time() secs = end_time - start_time - print calculate_z_serial_purepython.__name__ + " took", secs, "seconds" + print (calculate_z_serial_purepython.__name__ + " took", secs, "seconds") # this sum is expected for 1000^2 grid with 300 iterations assert sum(output) == 33219980 diff --git a/01_profiling/cpu_profiling/julia1_nopil.py b/01_profiling/cpu_profiling/julia1_nopil.py index 1584480..e9c19f0 100644 --- a/01_profiling/cpu_profiling/julia1_nopil.py +++ b/01_profiling/cpu_profiling/julia1_nopil.py @@ -21,7 +21,8 @@ def calculate_z_serial_purepython(maxiter, zs, cs): def calc_pure_python(draw_output, desired_width, max_iterations): - """Create a list of complex co-ordinates (zs) and complex parameters (cs), build Julia set and display""" + """Create a list of complex co-ordinates (zs) and complex parameters (cs), + build Julia set and display""" x_step = (float(x2 - x1) / float(desired_width)) y_step = (float(y1 - y2) / float(desired_width)) x = [] @@ -45,13 +46,13 @@ def calc_pure_python(draw_output, desired_width, max_iterations): zs.append(complex(xcoord, ycoord)) cs.append(complex(c_real, c_imag)) - print "Length of x:", len(x) - print "Total elements:", len(zs) + print ("Length of x:", len(x)) + print ("Total elements:", len(zs)) start_time = time.time() output = calculate_z_serial_purepython(max_iterations, zs, cs) end_time = time.time() secs = end_time - start_time - print calculate_z_serial_purepython.__name__ + " took", secs, "seconds" + print (calculate_z_serial_purepython.__name__ + " took", secs, "seconds") # this sum is expected for 1000^2 grid with 300 iterations assert sum(output) == 33219980 diff --git a/01_profiling/decorator_time/julia1_decorator.py b/01_profiling/decorator_time/julia1_decorator.py index f975498..60ed8a0 100644 --- a/01_profiling/decorator_time/julia1_decorator.py +++ b/01_profiling/decorator_time/julia1_decorator.py @@ -13,7 +13,7 @@ def measure_time(*args, **kwargs): t1 = time.time() result = fn(*args, **kwargs) t2 = time.time() - print ( + print( "@timefn:" + fn.__name__ + " took " + str(t2 - t1) + " seconds") return result return measure_time @@ -35,7 +35,8 @@ def calculate_z_serial_purepython(maxiter, zs, cs): def calc_pure_python(draw_output, desired_width, max_iterations): - """Create a list of complex co-ordinates (zs) and complex parameters (cs), build Julia set and display""" + """Create a list of complex co-ordinates (zs) and complex parameters (cs), + build Julia set and display""" x_step = (float(x2 - x1) / float(desired_width)) y_step = (float(y1 - y2) / float(desired_width)) x = [] @@ -59,13 +60,13 @@ def calc_pure_python(draw_output, desired_width, max_iterations): zs.append(complex(xcoord, ycoord)) cs.append(complex(c_real, c_imag)) - print "Length of x:", len(x) - print "Total elements:", len(zs) + print("Length of x:", len(x)) + print("Total elements:", len(zs)) start_time = time.time() output = calculate_z_serial_purepython(max_iterations, zs, cs) end_time = time.time() secs = end_time - start_time - print calculate_z_serial_purepython.__name__ + " took", secs, "seconds" + print(calculate_z_serial_purepython.__name__ + " took", secs, "seconds") # this sum is expected for 1000^2 grid with 300 iterations assert sum(output) == 33219980 From 8fe1f263e798a65ef4d5f31d23e15813a123d027 Mon Sep 17 00:00:00 2001 From: romanstingler Date: Sat, 27 Sep 2014 20:20:11 +0200 Subject: [PATCH 5/7] python 2.7 and 3.4 compatibility --- 01_profiling/cpu_profiling/julia1.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/01_profiling/cpu_profiling/julia1.py b/01_profiling/cpu_profiling/julia1.py index 7f0b81a..5c53f1b 100644 --- a/01_profiling/cpu_profiling/julia1.py +++ b/01_profiling/cpu_profiling/julia1.py @@ -1,4 +1,6 @@ """Julia set generator without optional PIL-based image drawing""" +# Intall pillow (Python Imaging Library (Fork)) on python2 and python3 +# https://pypi.python.org/pypi/Pillow/2.5.3 import time from PIL import Image import array @@ -13,7 +15,7 @@ def show_greyscale(output_raw, width, height, max_iterations): # convert our output to PIL-compatible input # scale to [0...255] max_iterations = float(max(output_raw)) - print (max_iterations) + print(max_iterations) scale_factor = float(max_iterations) scaled = [int(o / scale_factor * 255) for o in output_raw] output = array.array('B', scaled) # array of unsigned ints @@ -88,13 +90,13 @@ def calc_pure_python(draw_output, desired_width, max_iterations): zs.append(complex(xcoord, ycoord)) cs.append(complex(c_real, c_imag)) - print ("Length of x:", len(x)) - print ("Total elements:", len(zs)) + print("Length of x:", len(x)) + print("Total elements:", len(zs)) start_time = time.time() output = calculate_z_serial_purepython(max_iterations, zs, cs) end_time = time.time() secs = end_time - start_time - print (calculate_z_serial_purepython.__name__ + " took", secs, "seconds") + print(calculate_z_serial_purepython.__name__ + " took", secs, "seconds") # this sum is expected for 1000^2 grid with 300 iterations assert sum(output) == 33219980 From 9aaff9790f6330565af2552a856a9725abb65907 Mon Sep 17 00:00:00 2001 From: romanstingler Date: Sat, 27 Sep 2014 20:43:58 +0200 Subject: [PATCH 6/7] python 2.7 and 3.4 compatibility --- 01_profiling/cpu_profiling/julia1.py | 2 ++ 01_profiling/cpu_profiling/julia1_nopil.py | 2 ++ 01_profiling/decorator_time/julia1_decorator.py | 2 ++ 02_understanding/check_prime.py | 8 +++++--- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/01_profiling/cpu_profiling/julia1.py b/01_profiling/cpu_profiling/julia1.py index 5c53f1b..e9938c4 100644 --- a/01_profiling/cpu_profiling/julia1.py +++ b/01_profiling/cpu_profiling/julia1.py @@ -1,10 +1,12 @@ """Julia set generator without optional PIL-based image drawing""" # Intall pillow (Python Imaging Library (Fork)) on python2 and python3 # https://pypi.python.org/pypi/Pillow/2.5.3 +from __future__ import print_function import time from PIL import Image import array + # area of complex space to investigate x1, x2, y1, y2 = -1.8, 1.8, -1.8, 1.8 c_real, c_imag = -0.62772, -.42193 diff --git a/01_profiling/cpu_profiling/julia1_nopil.py b/01_profiling/cpu_profiling/julia1_nopil.py index e9c19f0..93eb14d 100644 --- a/01_profiling/cpu_profiling/julia1_nopil.py +++ b/01_profiling/cpu_profiling/julia1_nopil.py @@ -1,6 +1,8 @@ """Julia set generator without optional PIL-based image drawing""" +from __future__ import print_function import time + # area of complex space to investigate x1, x2, y1, y2 = -1.8, 1.8, -1.8, 1.8 c_real, c_imag = -0.62772, -.42193 diff --git a/01_profiling/decorator_time/julia1_decorator.py b/01_profiling/decorator_time/julia1_decorator.py index 60ed8a0..01aff06 100644 --- a/01_profiling/decorator_time/julia1_decorator.py +++ b/01_profiling/decorator_time/julia1_decorator.py @@ -1,7 +1,9 @@ """Julia set generator with timing decorator""" +from __future__ import print_function import time from functools import wraps + # area of complex space to investigate x1, x2, y1, y2 = -1.8, 1.8, -1.8, 1.8 c_real, c_imag = -0.62772, -.42193 diff --git a/02_understanding/check_prime.py b/02_understanding/check_prime.py index 6c8d3a1..68e7dfd 100644 --- a/02_understanding/check_prime.py +++ b/02_understanding/check_prime.py @@ -1,14 +1,16 @@ +from __future__ import print_function import math + def check_prime(number): sqrt_number = math.sqrt(number) number_float = float(number) - for i in xrange(2, int(sqrt_number) + 1): + for i in range(2, int(sqrt_number) + 1): if (number_float / i).is_integer(): return False return True if __name__ == "__main__": - print "check_prime(10000000) = ", check_prime(10000000) - print "check_prime(10000019) = ", check_prime(10000019) + print ("check_prime(10000000) = ", check_prime(10000000)) + print ("check_prime(10000019) = ", check_prime(10000019)) From 432138950198e8d08ae1c329f286724152c791d0 Mon Sep 17 00:00:00 2001 From: romanstingler Date: Tue, 30 Sep 2014 20:54:40 +0200 Subject: [PATCH 7/7] Update julia1.py --- 01_profiling/cpu_profiling/julia1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/01_profiling/cpu_profiling/julia1.py b/01_profiling/cpu_profiling/julia1.py index e9938c4..7d89427 100644 --- a/01_profiling/cpu_profiling/julia1.py +++ b/01_profiling/cpu_profiling/julia1.py @@ -1,5 +1,5 @@ """Julia set generator without optional PIL-based image drawing""" -# Intall pillow (Python Imaging Library (Fork)) on python2 and python3 +# Intall pillow (Python Imaging Library (Fork)) on python2 or python3 # https://pypi.python.org/pypi/Pillow/2.5.3 from __future__ import print_function import time