diff --git a/Part 3/Computation Data.xlsx b/Part 3/Computation Data.xlsx deleted file mode 100644 index 64908ab..0000000 Binary files a/Part 3/Computation Data.xlsx and /dev/null differ diff --git a/Part 3/Extra Features/mandelbrot_animation.py b/Part 3/Extra Features/mandelbrot_animation.py deleted file mode 100644 index 776ed83..0000000 --- a/Part 3/Extra Features/mandelbrot_animation.py +++ /dev/null @@ -1,73 +0,0 @@ -from matplotlib import pyplot as plt -import time -import numpy -import cv2 -import os -import datetime -import mandelbrot_vectorized -import multiprocessing -import video_creator - - -pRE = 1000 -pIM = 1000 -threshold = 2 -iterations = 1000 - -frame_rate = 60 -step_size = frame_rate*61 - - -def compute_set(x_0, y_0, x_1, y_1): - print("X:",x_0, x_1, "Y:", y_0, y_1, "") - - start_time = time.time() - - reshaped_solution = mandelbrot_vectorized.main(pRE=pRE, pIM=pIM, show_figure=False) - - print("Frame computation time:", time.time() - start_time) - - return reshaped_solution - - -if __name__ == '__main__': - output_video_destination = f'mandelbrot_animation_{str(datetime.datetime.now()).replace(":", "-").replace(".", "")}.avi' - print(f'Video save destination: {os.getcwd()}/{output_video_destination}') - start_render_time = time.time() - - start_point = [-2.25, 0.75, -1.25, 1.25] - end_point = [-0.7336438924199521-(4.5E-14)/2, -0.7336438924199521+(4.5E-14)/2, 0.2455211406714035-(4.5E-14)/2, 0.2455211406714035+(4.5E-14)/2] - - video_writer = video_creator.VideoCreator(output_video_destination, frame_rate, pRE, pIM) - - x0, x1, y0, y1 = start_point - a0, a1, b0, b1 = end_point - - for i in range(step_size): - t = 1-(1-i / step_size)**10 - - current_x = [x0 + t * (a0 - x0), x1 + t * (a1 - x1)] - current_y = [y0 + t * (b0 - y0), y1 + t * (b1 - y1)] - - # Apply the Mandelbrot formula and generate the image - complete_mandelbrot = compute_set(current_x[0], current_y[0], current_x[1], current_y[1]) - - video_writer.create_frame(complete_mandelbrot, [f'X: {round(current_x[0], 4)} : {round(current_x[1], 4)}', - f'Y: {round(current_y[0], 4)} : {round(current_y[1], 4)}']) - - # Progress bar and time estimation - progress_count = round((i / step_size) * 100, 2) - print(f'\n\nProgress: {progress_count}%') - if i != 0: - print("Remaining time:", round((time.time() - start_render_time) * (1 - (i / step_size)) / (i / step_size), 2), "seconds") - plt.pause(0.001) # Pause for 1ms to allow the plot to update - - # Hold the last frame for 3 seconds when the video ends - for i in range(frame_rate*3): - video_writer.save_frame(cv2.imread('tmp_hold.png')) - - video_writer.close() - os.remove('tmp_hold.png') # Remove the temporary image file - - print("Video saved to:", os.getcwd() + "/" + output_video_destination) - print("Complete! Total render time:", time.time() - start_render_time) diff --git a/Part 3/Extra Features/mandelbrot_iteration_animation.py b/Part 3/Extra Features/mandelbrot_iteration_animation.py deleted file mode 100644 index a342e3a..0000000 --- a/Part 3/Extra Features/mandelbrot_iteration_animation.py +++ /dev/null @@ -1,99 +0,0 @@ -from matplotlib import pyplot as plt -import time -import numpy -import cv2 -import os -import datetime - -pRE = 1000 -pIM = 1000 -threshold = 2 -iterations = 5000 - -frames_between_points = 30 -frame_rate = round(frames_between_points/6) - -output_video_destination = f'mandelbrot_animation_i{iterations}_s{pRE}_{str(datetime.datetime.now()).replace(":","-")}.avi' -print(f'Video save destination: {os.getcwd()}/{output_video_destination}') -video_writer = cv2.VideoWriter(output_video_destination, cv2.VideoWriter_fourcc(*'DIVX'), frame_rate, (pRE, pIM)) - - -def mandelbrot(c, iterations_get): - # Generate a 2D array of ones, which is then converted to a boolean data type array - mandelbrot_mask = numpy.ones_like(c, dtype=bool) - # Generate a 2D array of zeros, which is then converted to a complex data type array - z = numpy.zeros_like(c, dtype=numpy.complex128) - # z is iteratively updated with the Mandelbrot formula: z = z^2 + c - - divergence_time = numpy.zeros(c.shape, dtype=numpy.float64) - - # Iterate over the complex plane - for i in range(iterations_get): - # Apply the Mandelbrot formula - z[mandelbrot_mask] = z[mandelbrot_mask] * z[mandelbrot_mask] + c[mandelbrot_mask] - - # Check each element of the array for divergence - diverged = mandelbrot_mask & (numpy.abs(z) > threshold) - # Update the divergence time - divergence_time[diverged] = i - - # Check if the absolute value of z is greater than the threshold - mandelbrot_mask[numpy.abs(z) > threshold] = False - - save_frame(divergence_time, i) - - return divergence_time - - -def main(iterations_get): - start_time = time.time() - - # Generates linear spaces with pRE and pIM elements respectively around the plane of the Mandelbrot set - x_space = numpy.linspace(-2.5-(4.5E-14)/2, 1.5+(4.5E-14)/2, pRE, dtype=numpy.float64).reshape((1, pRE)) - y_space = numpy.linspace(-1.5-(4.5E-14)/2, 1.5+(4.5E-14)/2, pIM, dtype=numpy.float64).reshape((pIM, 1)) - - # Generate a 2D array for each dimension of the complex plane - complete_space = x_space + y_space * 1j - - # Apply the Mandelbrot formula - computed_mandelbrot = mandelbrot(complete_space, iterations_get) - - print("Frame computation time:", time.time() - start_time) - - return computed_mandelbrot - - -def save_frame(complete_mandelbrot, i): - plt.figure(figsize=(pRE, pIM), dpi=1) - plt.imshow(complete_mandelbrot, cmap='magma', interpolation='nearest', aspect='auto') - - plt.axis('off') - plt.bbox_inches = 'tight' - plt.pad_inches = 0 - plt.subplots_adjust(top=1, bottom=0, right=1, left=0, hspace=0, wspace=0) - plt.margins(0, 0) - plt.savefig(f'tmp_hold.png', bbox_inches='tight', pad_inches=0) - plt.close() - - loaded_image = cv2.imread('tmp_hold.png') - cv2.putText(loaded_image, f'Iterations: {i}', (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1.5, (255, 255, 255)) - video_writer.write(loaded_image) - - # Progress bar and time estimation - progress_count = round(i / iterations * 100, 2) - print(f'\n\nProgress: {progress_count}%') - plt.pause(0.001) # Pause for 1ms to allow the plot to update - - -if __name__ == '__main__': - start_render_time = time.time() - - main(iterations) - - # Hold the last frame for 3 seconds when the video ends - for i in range(frame_rate*3): - video_writer.write(cv2.imread('tmp_hold.png')) - video_writer.release() - os.remove('tmp_hold.png') # Remove the temporary image file - print("Video saved to:", os.getcwd() + "/" + output_video_destination) - print("Complete! Total render time:", time.time() - start_render_time) \ No newline at end of file diff --git a/Part 3/Extra Features/mandelbrot_navigator.py b/Part 3/Extra Features/mandelbrot_navigator.py deleted file mode 100644 index 389637a..0000000 --- a/Part 3/Extra Features/mandelbrot_navigator.py +++ /dev/null @@ -1,94 +0,0 @@ -""" - Author: Lukas Bisgaard Kristensen - Date: 26. April 2023 - Course: Numerical Scientific Computing, AAU - Description: This program computes the Mandelbrot set using OpenCL. -""" -import cv2.cv2 -import pyopencl -import matplotlib.pyplot as plt -import time -import numpy -import doctest -import os -import mandelbrot_opencl -import cv2 as cv - - -xmin, xmax, ymin, ymax = -2.3, 0.8, -1.2, 1.2 - - -def draw_window(): - start_time = time.time() - mandelbrot_figure = mandelbrot_opencl.mandelbrot_opencl(device=device, context=context, queue=queue, width=1000, height=1000, local_size=64, show_figure=False, x_min=xmin, x_max=xmax, y_min=ymin, y_max=ymax) - # Add opencv text - font = cv.FONT_HERSHEY_SIMPLEX - - # Controls - cv.putText(mandelbrot_figure, 'Controls:', (10, 50), font, 0.5, 255, 1, cv.LINE_AA) - cv.putText(mandelbrot_figure, 'w: up', (10, 100), font, 0.5, 255, 1, cv.LINE_AA) - cv.putText(mandelbrot_figure, 's: down', (10, 150), font, 0.5, 255, 1, cv.LINE_AA) - cv.putText(mandelbrot_figure, 'a: left', (10, 200), font, 0.5, 255, 1, cv.LINE_AA) - cv.putText(mandelbrot_figure, 'd: right', (10, 250), font, 0.5, 255, 1, cv.LINE_AA) - cv.putText(mandelbrot_figure, 'q: zoom in', (10, 300), font, 0.5, 255, 1, cv.LINE_AA) - cv.putText(mandelbrot_figure, 'e: zoom out', (10, 350), font, 0.5, 255, 1, cv.LINE_AA) - cv.putText(mandelbrot_figure, 'r: reset', (10, 400), font, 0.5, 255, 1, cv.LINE_AA) - - # Position - cv.putText(mandelbrot_figure, f'x {round(xmin, 5)} : {round(xmax, 5)}', (10, 500), font, 0.5, 255, 1, cv.LINE_AA) - cv.putText(mandelbrot_figure, f'y {round(ymin, 5)} : {round(ymax, 5)}', (10, 550), font, 0.5, 255, 1, cv.LINE_AA) - - # Computation time - cv.putText(mandelbrot_figure, f'Computation time: {round(time.time() - start_time, 3)} s', (10, 600), font, 0.5, - 255, 1, cv.LINE_AA) - - mandelbrot_figure = cv.convertScaleAbs(mandelbrot_figure) - mandelbrot_figure = cv.applyColorMap(mandelbrot_figure, cv.COLORMAP_HOT) - cv.imshow('Mandelbrot Set Navigator', mandelbrot_figure) - - -def main(): - """ - Script for navigating the Mandelbrot set. - - :return: - """ - global xmin, xmax, ymin, ymax - draw_window() - - while True: - y_scale = (ymax - ymin) / 10 - x_scale = (xmax - xmin) / 10 - - k = cv.waitKey(1) & 0xFF - if k == ord('w'): - ymin -= y_scale - ymax -= y_scale - elif k == ord('s'): - ymin += y_scale - ymax += y_scale - elif k == ord('a'): - xmin -= x_scale - xmax -= x_scale - elif k == ord('d'): - xmin += x_scale - xmax += x_scale - elif k == ord('e'): - ymin -= y_scale - ymax += y_scale - xmin -= x_scale - xmax += x_scale - elif k == ord('q'): - ymin += y_scale - ymax -= y_scale - xmin += x_scale - xmax -= x_scale - elif k == ord('r'): - xmin, xmax, ymin, ymax = -2.3, 0.8, -1.2, 1.2 - else: - continue - draw_window() - -if __name__ == '__main__': - context, queue, device, name = mandelbrot_opencl.create_opencl_context(pyopencl.get_platforms()[0]) - main() \ No newline at end of file diff --git a/Part 3/Extra Features/video_creator.py b/Part 3/Extra Features/video_creator.py deleted file mode 100644 index fc3c1bb..0000000 --- a/Part 3/Extra Features/video_creator.py +++ /dev/null @@ -1,36 +0,0 @@ -import cv2 -import matplotlib.pyplot as plt - - -class VideoCreator: - def __init__(self, output_video_destination, frame_rate, pRE, pIM): - self.video = cv2.VideoWriter(output_video_destination, cv2.VideoWriter_fourcc(*'DIVX'), frame_rate, (pRE, pIM)) - self.pRE = pRE - self.pIM = pIM - self.frame_rate = frame_rate - self.output_video_destination = output_video_destination - - def create_frame(self, frame, text): - plt.figure(figsize=(self.pRE, self.pIM), dpi=1) - plt.imshow(frame, cmap='magma', interpolation='nearest', aspect='auto') - plt.axis('off') - plt.bbox_inches = 'tight' - plt.pad_inches = 0 - plt.subplots_adjust(top=1, bottom=0, right=1, left=0, hspace=0, wspace=0) - plt.margins(0, 0) - plt.savefig(f'tmp_hold.png', bbox_inches='tight', pad_inches=0) - plt.close() - - loaded_image = cv2.imread('tmp_hold.png') - - for i in range(len(text)): - cv2.putText(loaded_image, text[i], (10, 20 + 20 * i), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1, cv2.LINE_AA) - - self.save_frame(loaded_image) - - def save_frame(self, frame): - self.video.write(frame) - - def close(self): - self.video.release() - diff --git a/Part 3/Mandelbrot Part 3 Mandelbrot.zip b/Part 3/Mandelbrot Part 3 Mandelbrot.zip deleted file mode 100644 index ece29b7..0000000 Binary files a/Part 3/Mandelbrot Part 3 Mandelbrot.zip and /dev/null differ diff --git a/Part 3/Mandelbrot Part 3a.zip b/Part 3/Mandelbrot Part 3a.zip deleted file mode 100644 index db5f08b..0000000 Binary files a/Part 3/Mandelbrot Part 3a.zip and /dev/null differ diff --git a/Part 3/Mandelbrot Part 3c.zip b/Part 3/Mandelbrot Part 3c.zip deleted file mode 100644 index b627dbe..0000000 Binary files a/Part 3/Mandelbrot Part 3c.zip and /dev/null differ diff --git a/Part 3/Mini Project Part 3 Mandel Brot.docx b/Part 3/Mini Project Part 3 Mandel Brot.docx deleted file mode 100644 index 7969ce9..0000000 Binary files a/Part 3/Mini Project Part 3 Mandel Brot.docx and /dev/null differ diff --git a/Part 3/Mini Project Part 3 Mandelbrot.pdf b/Part 3/Mini Project Part 3 Mandelbrot.pdf deleted file mode 100644 index 2efc5a4..0000000 Binary files a/Part 3/Mini Project Part 3 Mandelbrot.pdf and /dev/null differ diff --git a/Part 3/computations_local_sizes_across_platforms.png b/Part 3/computations_local_sizes_across_platforms.png deleted file mode 100644 index 3f4e5fc..0000000 Binary files a/Part 3/computations_local_sizes_across_platforms.png and /dev/null differ diff --git a/Part 3/mandelbrot_opencl.py b/Part 3/mandelbrot_opencl.py deleted file mode 100644 index 52f6da6..0000000 --- a/Part 3/mandelbrot_opencl.py +++ /dev/null @@ -1,193 +0,0 @@ -""" - Author: Lukas Bisgaard Kristensen - Date: 26. April 2023 - Course: Numerical Scientific Computing, AAU - Description: This program computes the Mandelbrot set using OpenCL. -""" - -import pyopencl -import matplotlib.pyplot as plt -import time -import numpy -import doctest -import os -# os.environ['PYOPENCL_COMPILER_OUTPUT'] = '1' - -compute_local_sizes = [[]] -compute_local_computations = [[]] - - -def mandelbrot_opencl(device, context, queue, x_min=-2.3, x_max=0.8, y_min=-1.2, y_max=1.2, width=5000, height=5000, show_figure=True, local_size=1) -> None: - """ - Computes the Mandelbrot set using OpenCL. - - :param device: Device name of CPU/GPU - :param context: Context of the device - :param queue: Queue of the device - :param x_min: Minimum real value - :param x_max: Maximum real value - :param y_min: Minimum imaginary value - :param y_max: Maximum imaginary value - :param width: Width of the image - :param height: Height of the image - :param show_figure: Show the figure - :return: Mandelbrot set - - >>> import pyopencl - >>> import numpy as np - >>> from matplotlib import pyplot as plt - >>> device = pyopencl.get_platforms()[0].get_devices()[0] - >>> context = pyopencl.Context([device]) - >>> queue = pyopencl.CommandQueue(context, device) - >>> x_min, x_max, y_min, y_max, width, height = -2.3, 0.8, -1.2, 1.2, 5000, 5000 - >>> mandelbrot_opencl(device, context, queue, x_min, x_max, y_min, y_max, width, height, show_figure=False, local_size=1) - array([[1., 1., 1., ..., 2., 2., 2.], - [1., 1., 1., ..., 2., 2., 2.], - [1., 1., 1., ..., 2., 2., 2.], - ..., - [1., 1., 1., ..., 2., 2., 2.], - [1., 1., 1., ..., 2., 2., 2.], - [1., 1., 1., ..., 2., 2., 2.]], dtype=float32) - """ - - start_time = time.time() - - x_space = numpy.linspace(x_min, x_max, width, dtype=numpy.float32) - y_space = numpy.linspace(y_min, y_max, height, dtype=numpy.float32) - complete_space = (x_space + y_space[:, numpy.newaxis] * 1j).astype(numpy.complex64) - - output = numpy.empty(width * height, dtype=numpy.float32) - - program = pyopencl.Program(context, """ - __kernel void mandelbrot(__global float2 *complete_space, __global float *output) - { - __private int gid = get_global_id(0); - __private float nreal, real = 0; - __private float imaginary = 0; - __private float real_pow_2, imaginary_pow_2; - - for (int i = 0; i < 1000; i++) - { - real_pow_2 = real * real; - imaginary_pow_2 = imaginary * imaginary; - - nreal = real_pow_2 - imaginary_pow_2 + complete_space[gid].x; - imaginary = 2 * real * imaginary + complete_space[gid].y; - real = nreal; - if (real_pow_2 + imaginary_pow_2 > 4) - { - output[gid] = i; - return; - } - } - } - """).build(devices=[device]) - - mf = pyopencl.mem_flags - q_opencl = pyopencl.Buffer(context, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=complete_space) - output_opencl = pyopencl.Buffer(context, mf.WRITE_ONLY, output.nbytes) - - program.mandelbrot(queue, output.shape, [local_size], q_opencl, output_opencl) - pyopencl.enqueue_copy(queue, output, output_opencl).wait() - - divergence_time = output.reshape((height, width)) - time_compute = computation_time(start_time, time.time()) - - compute_local_sizes[-1].append(local_size) - compute_local_computations[-1].append(time_compute) - - if show_figure: - plt.imshow(divergence_time, cmap='magma') - plt.show() - return divergence_time - - -def computation_time(start_time, end_time): - """ - Computes the time taken to compute the Mandelbrot set. - - :param start_time: Start time of computation - :param end_time: End time of computation - :return: Difference between the end time and the start time - - Usage examples: - >>> computation_time(0, 0.792) - 0.792 - """ - return round(end_time - start_time, 3) - - -def create_opencl_context(platform): - """ - Create OpenCL context, queue, device and platform - - Parameters - :param platform: Name of the platform to use - :return: context, queue, device, name: Output from the CPU/GPU - - Usage examples: - >>> import pyopencl - >>> platform = pyopencl.get_platforms()[0] - >>> context, queue, device, name = create_opencl_context(platform) - >>> isinstance(context, pyopencl.Context) - True - >>> isinstance(queue, pyopencl.CommandQueue) - True - >>> isinstance(device, pyopencl.Device) - True - >>> isinstance(name, str) - True - """ - - device = platform.get_devices()[0] - context = pyopencl.Context(devices=[device]) - queue = pyopencl.CommandQueue(context) - return context, queue, device, platform.name - - -def main(show_fig=False): - """ - Main function for running the comparisons between CPU and GPU and plot sizes. - - :param show_fig: Show the figure or not when finishing the computations - """ - global compute_local_sizes, compute_local_computations - compute_local_sizes = [] - compute_local_computations = [] - platform_name = [] - - global_sizes = [500, 1000, 2000, 5000, 10000] - local_sizes = [2, 4, 8, 16, 32, 64, 128, 256] - - for i in pyopencl.get_platforms(): - context, queue, device, name = create_opencl_context(i) - print("Platform:", name) - - platform_name.append(name) - compute_local_sizes.append([]) - compute_local_computations.append([]) - for size in local_sizes: - print("Local size:", size) - try: - mandelbrot_opencl(device=device, context=context, queue=queue, width=10000, height=10000, local_size=size, show_figure=False) - except: - print("Error in local size:", size) - break - - for i in range(len(platform_name)): - plt.plot(max(compute_local_sizes), compute_local_computations[i], label=platform_name[i]) - - plt.xlabel("Local Size") - plt.ylabel("Computation Time (s)") - plt.title("Computation Time vs Local Size") - plt.legend() - plt.show() - - if show_fig: - context, queue, device, name = create_opencl_context(pyopencl.get_platforms()[0]) - mandelbrot_opencl(device=device, context=context, queue=queue, width=10000, height=10000, local_size=1, show_figure=True) - - -if __name__ == '__main__': - doctest.testmod(report=True, verbose=True) - main(show_fig=True) diff --git a/Part 3/mandelbrot_vectorized.py b/Part 3/mandelbrot_vectorized.py deleted file mode 100644 index 9d6d94f..0000000 --- a/Part 3/mandelbrot_vectorized.py +++ /dev/null @@ -1,137 +0,0 @@ -""" - Author: Lukas Bisgaard Kristensen - Date: 26. April 2023 - Course: Numerical Scientific Computing, AAU - Description: This program computes the Mandelbrot set using OpenCL. -""" - -import matplotlib.pyplot as plt -import time -import numpy -import doctest - - -def mandelbrot(c): - """ - Computes the Mandelbrot set using vectorized numpy operations. - - :param c: Input complex array - :return mandelbrot: Divergence time - - Usage examples: - >>> mandelbrot(numpy.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) * 1j) - array([0., 0., 1., 0., 0., 0., 0., 0., 0., 0.], dtype=float16) - >>> mandelbrot(numpy.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) + numpy.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) * 1j) - array([0., 1., 0., 0., 0., 0., 0., 0., 0., 0.], dtype=float16) - """ - # Generate a 2D array of ones, which is then converted to a boolean data type array - mandelbrot_mask = numpy.ones_like(c, dtype=bool) - - # Generate a 2D array of zeros, which is then converted to a complex data type array - z = numpy.zeros_like(c, dtype=numpy.complex64) - - divergence_time = numpy.zeros(c.shape, dtype=numpy.float16) - - # Iterate over the complex plane - for i in range(100): - # Apply the Mandelbrot formula - z[mandelbrot_mask] = z[mandelbrot_mask] * z[mandelbrot_mask] + c[mandelbrot_mask] - - # Check each element of the array for divergence - diverged = mandelbrot_mask & (numpy.abs(z) > 2) - # Update the divergence time - divergence_time[diverged] = i - - # Check if the absolute value of z is greater than the threshold - mandelbrot_mask[numpy.abs(z) > 2] = False - - # doctest.testmod() - return divergence_time - - -def generate_space(pRE, pIM, data_type): - """ - Generates the space of the Mandelbrot set. - - :param pRE: Real part - :param pIM: Imaginary part - :param data_type: Data type of the array - :return: space - - Usage examples: - >>> generate_space(1000, 1000, numpy.float16) - array([[-2.3007812-1.2001953j, -2.296875 -1.2001953j, - -2.2929688-1.2001953j, ..., 0.7939453-1.2001953j, - 0.796875 -1.2001953j, 0.7998047-1.2001953j], - [-2.3007812-1.1972656j, -2.296875 -1.1972656j, - -2.2929688-1.1972656j, ..., 0.7939453-1.1972656j, - 0.796875 -1.1972656j, 0.7998047-1.1972656j], - [-2.3007812-1.1953125j, -2.296875 -1.1953125j, - -2.2929688-1.1953125j, ..., 0.7939453-1.1953125j, - 0.796875 -1.1953125j, 0.7998047-1.1953125j], - ..., - [-2.3007812+1.1953125j, -2.296875 +1.1953125j, - -2.2929688+1.1953125j, ..., 0.7939453+1.1953125j, - 0.796875 +1.1953125j, 0.7998047+1.1953125j], - [-2.3007812+1.1972656j, -2.296875 +1.1972656j, - -2.2929688+1.1972656j, ..., 0.7939453+1.1972656j, - 0.796875 +1.1972656j, 0.7998047+1.1972656j], - [-2.3007812+1.2001953j, -2.296875 +1.2001953j, - -2.2929688+1.2001953j, ..., 0.7939453+1.2001953j, - 0.796875 +1.2001953j, 0.7998047+1.2001953j]], dtype=complex64) - """ - - # Generates linear spaces with pRE and pIM elements respectively around the plane of the Mandelbrot set - x_space = numpy.linspace(-2.3, 0.8, pRE, dtype=data_type).reshape((1, pRE)) - y_space = numpy.linspace(-1.2, 1.2, pIM, dtype=data_type).reshape((pIM, 1)) - - # Generate a 2D array for each dimension of the complex plane - generated_space = x_space + y_space * 1j - return generated_space - - -def computation_time(start_time, end_time): - """ - Computes the time taken to compute the Mandelbrot set. - - :param start_time: Start time of computation - :param end_time: End time of computation - :return: Difference between the end time and the start time - - Usage examples: - >>> computation_time(0, 0.792) - 0.792 - """ - return round(end_time - start_time, 3) - - -def main(pRE, pIM, show_figure=True): - """ - :param pRE: Real part - :param pIM: Imaginary part - :param show_figure: Condition if matplotlib should show the figure - :return: Computation time - """ - - start_time = time.time() - - complete_space = generate_space(pRE, pIM, numpy.float16) - - # Apply the Mandelbrot formula - computed_mandelbrot = mandelbrot(complete_space) - - end_time = time.time() - - time_computed = computation_time(start_time, end_time) - print("Computation time:", time_computed,"s") - - if show_figure: - plt.imshow(computed_mandelbrot, cmap='magma') - plt.show() - return round(end_time - start_time, 3) - - -if __name__ == '__main__': - doctest.testmod(report=True, verbose=True) - main(1000, 1000) - diff --git a/Part 3/requirements.txt b/Part 3/requirements.txt deleted file mode 100644 index 1f970ff..0000000 --- a/Part 3/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -matplotlib==3.6.2 -numpy==1.22.3 -opencv_python==4.5.3.56 -pyopencl==2022.3.1