


'''simple docstring'''
import gc
import threading
import time

import psutil
import torch

class 						_lowerCamelCase					:




 '''simple docstring'''


 def __init__(      self						):

  """simple docstring"""







  __A  :		Optional[int]       =			psutil.Process()
  __A  :		Optional[Any]       =			False


 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		Optional[Any]       =			-1

  while True:
   __A  :		List[str]       =			max(self.process.memory_info().rss      ,      self.cpu_memory_peak						)

   # can't sleep or will not catch the peak right (this comment is here on purpose)
   if not self.peak_monitoring:
    break


 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		Dict       =			True
  __A  :		str       =			threading.Thread(target=self.peak_monitor						)
  __A  :		int       =			True
  self.thread.start()







 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		List[str]       =			False
  self.thread.join()
  return self.cpu_memory_peak


UpperCAmelCase_ :     List[Any]								=      PeakCPUMemory()


def 			_lowercase       (				):
 # Time
 __A  :		Tuple       =			{'time': time.time()}

 gc.collect()
 torch.cuda.empty_cache()

 # CPU mem
 __A  :		Optional[int]       =			psutil.Process().memory_info().rss
 cpu_peak_tracker.start()

 # GPU mem
 for i in range(torch.cuda.device_count()			):
  __A  :		List[Any]       =			torch.cuda.memory_allocated(UpperCamelCase__			)
 torch.cuda.reset_peak_memory_stats()

 return measures


def 			_lowercase       (				UpperCamelCase__       :					Optional[int]			):
 # Time
 __A  :		Optional[Any]       =			{'time': time.time() - start_measures['time']}

 gc.collect()
 torch.cuda.empty_cache()

 # CPU mem
 __A  :		Tuple       =			(psutil.Process().memory_info().rss - start_measures['cpu']) / 2**20
 __A  :		Optional[int]       =			(cpu_peak_tracker.stop() - start_measures['cpu']) / 2**20

 # GPU mem
 for i in range(torch.cuda.device_count()			):
  __A  :		Dict       =			(torch.cuda.memory_allocated(UpperCamelCase__			) - start_measures[str(UpperCamelCase__			)]) / 2**20
  __A  :		Optional[Any]       =			(torch.cuda.max_memory_allocated(UpperCamelCase__			) - start_measures[str(UpperCamelCase__			)]) / 2**20

 return measures


def 			_lowercase       (				UpperCamelCase__       :					List[Any],				UpperCamelCase__       :					Optional[int]			):
 print(f"""{description}:"""			)
 print(f"""- Time: {measures['time']:.2f}s"""			)
 for i in range(torch.cuda.device_count()			):
  print(f"""- GPU {i} allocated: {measures[str(UpperCamelCase__			)]:.2f}MiB"""			)
  __A  :		Tuple       =			measures[f"""{i}-peak"""]
  print(f"""- GPU {i} peak: {peak:.2f}MiB"""			)
 print(f"""- CPU RAM allocated: {measures['cpu']:.2f}MiB"""			)
 print(f"""- CPU RAM peak: {measures['cpu-peak']:.2f}MiB"""			)










'''simple docstring'''
from collections.abc import Sequence


def 			_lowercase       (				UpperCamelCase__       :					Sequence[float],				UpperCamelCase__       :					float			):
 return sum(c * (x**i) for i, c in enumerate(UpperCamelCase__			)			)


def 			_lowercase       (				UpperCamelCase__       :					Sequence[float],				UpperCamelCase__       :					float			):
 __A  :		Optional[Any]       =			0.0
 for coeff in reversed(UpperCamelCase__			):
  __A  :		List[str]       =			result * x + coeff
 return result


if __name__ == "__main__":
 UpperCAmelCase_ :     Any								=      (0.0, 0.0, 5.0, 9.3, 7.0)
 UpperCAmelCase_ :     Any								=      10.0
 print(evaluate_poly(poly, x))
 print(horner(poly, x))






