



import warnings
from collections.abc import Callable
from typing import Any

import numpy
from matplotlib import pyplot

__lowerCamelCase								=   0.25 + 0.0J
__lowerCamelCase								=   -0.4 + 0.6J
__lowerCamelCase								=   -0.1 + 0.651J
__lowerCamelCase								=   -2.0
__lowerCamelCase								=   5_6
__lowerCamelCase								=   2.0
__lowerCamelCase								=   6_6_6




def       UpperCAmelCase__	(							__snake_case  ,			__snake_case							)				->	numpy.ndarray:
  return numpy.exp(__snake_case							) + c_parameter




def       UpperCAmelCase__	(							__snake_case  ,			__snake_case							)				->	numpy.ndarray:
  return z_values * z_values + c_parameter




def       UpperCAmelCase__	(							__snake_case  ,			__snake_case							)				->	numpy.ndarray:
  _A          =      numpy.linspace(-window_size  ,			__snake_case  ,			__snake_case							)
  _A          =      x.reshape((nb_pixels, 1)							)
  _A          =      numpy.linspace(-window_size  ,			__snake_case  ,			__snake_case							)
  _A          =      y.reshape((1, nb_pixels)							)
  return x + 1.0J * y




def       UpperCAmelCase__	(							__snake_case  ,			__snake_case  ,			__snake_case  ,			__snake_case  ,			__snake_case = None  ,			)				->	numpy.ndarray:
  _A          =      z_a.astype('''complex64'''							)
  for _ in range(__snake_case							):
    _A          =      eval_function(__snake_case  ,			__snake_case							)
    if infinity is not None:
      numpy.nan_to_num(__snake_case  ,			copy=__snake_case  ,			nan=__snake_case							)
      _A          =      infinity
  return z_n




def       UpperCAmelCase__	(							__snake_case  ,			__snake_case  ,			__snake_case  ,			__snake_case  ,			)				->	None:
  _A          =      (abs(__snake_case							)).transpose()
  _A          =      abs_z_final[::-1, :]
  pyplot.matshow(abs_z_final < escape_radius							)
  pyplot.title(F'''Julia set of ${function_label}$, $c={function_params}$'''							)
  pyplot.show()




def       UpperCAmelCase__	(							)				->	None:
  warnings.filterwarnings(
      '''ignore'''  ,			category=__snake_case  ,			message='''overflow encountered in multiply'''							)
  warnings.filterwarnings(
      '''ignore'''  ,			category=__snake_case  ,			message='''invalid value encountered in multiply'''  ,			)
  warnings.filterwarnings(
      '''ignore'''  ,			category=__snake_case  ,			message='''overflow encountered in absolute'''							)
  warnings.filterwarnings(
      '''ignore'''  ,			category=__snake_case  ,			message='''overflow encountered in exp'''							)


if __name__ == "__main__":
    __lowerCamelCase								=   prepare_grid(window_size, nb_pixels)

    ignore_overflow_warnings()  # See file header for explanations

    __lowerCamelCase								=   2_4
    __lowerCamelCase								=   2 * abs(c_cauliflower) + 1
    __lowerCamelCase								=   iterate_function(
        eval_quadratic_polynomial,
        c_cauliflower,
        nb_iterations,
        z_a,
        infinity=1.1 * escape_radius,
    )
    show_results("""z^2+c""", c_cauliflower, escape_radius, z_final)

    __lowerCamelCase								=   6_4
    __lowerCamelCase								=   2 * abs(c_polynomial_a) + 1
    __lowerCamelCase								=   iterate_function(
        eval_quadratic_polynomial,
        c_polynomial_a,
        nb_iterations,
        z_a,
        infinity=1.1 * escape_radius,
    )
    show_results("""z^2+c""", c_polynomial_a, escape_radius, z_final)

    __lowerCamelCase								=   1_6_1
    __lowerCamelCase								=   2 * abs(c_polynomial_a) + 1
    __lowerCamelCase								=   iterate_function(
        eval_quadratic_polynomial,
        c_polynomial_a,
        nb_iterations,
        z_a,
        infinity=1.1 * escape_radius,
    )
    show_results("""z^2+c""", c_polynomial_a, escape_radius, z_final)

    __lowerCamelCase								=   1_2
    __lowerCamelCase								=   1_00_00.0
    __lowerCamelCase								=   iterate_function(
        eval_exponential,
        c_exponential,
        nb_iterations,
        z_a + 2,
        infinity=1.0E10,
    )
    show_results("""e^z+c""", c_exponential, escape_radius, z_final)




import importlib.metadata
import subprocess
import sys




def       UpperCAmelCase__	(							__snake_case = False							)				->	List[Any]:
  _A          =      False
  if "IPython" in sys.modules:
    _A          =      '''google.colab''' in str(sys.modules['''IPython'''].get_ipython()							)

  if in_colab:
    if upgrade:
      _A          =      ['''pip''', '''install''', '''-U''', '''torch''']
      subprocess.run(__snake_case  ,			check=__snake_case							)
    # get the current version of torch
    _A          =      importlib.metadata.version('''torch'''							)
    _A          =      torch_version[: torch_version.rindex('''.'''							)]
    _A          =      F'''https://storage.googleapis.com/tpu-pytorch/wheels/colab/torch_xla-{torch_version_trunc}-cp37-cp37m-linux_x86_64.whl'''
    _A          =      ['''pip''', '''install''', xla_wheel]
    subprocess.run(__snake_case  ,			check=__snake_case							)
  else:
    raise RuntimeError('''`install_xla` utility works only on google colab.'''							)