
"""simple docstring"""

import numpy as np
from cva import COLOR_BGR2GRAY, CV_8UC3, cvtColor, filteraD, imread, imshow, waitKey






def 							A						(    snake_case				:int    , snake_case				:int    , snake_case				:int    , snake_case				:int    , snake_case				:int    , snake_case				:int		)				->     np.ndarray:

 # prepare kernel
 # the kernel size have to be odd
 if (ksize % 2) == 0:
  __UpperCamelCase      =	ksize + 1
 __UpperCamelCase      =	np.zeros((ksize, ksize)    , dtype=np.floataa		)

 # each value
 for y in range(snake_case		):
  for x in range(snake_case		):
   # distance from center
   __UpperCamelCase      =	x - ksize // 2
   __UpperCamelCase      =	y - ksize // 2

   # degree to radiant
   __UpperCamelCase      =	theta / 1_8_0 * np.pi
   __UpperCamelCase      =	np.cos(_theta		)
   __UpperCamelCase      =	np.sin(_theta		)

   # get kernel x
   __UpperCamelCase      =	cos_theta * px + sin_theta * py

   # get kernel y
   __UpperCamelCase      =	-sin_theta * px + cos_theta * py

   # fill kernel
   __UpperCamelCase      =	np.exp(
       -(_x**2 + gamma**2 * _y**2) / (2 * sigma**2)		) * np.cos(2 * np.pi * _x / lambd + psi		)

 return gabor


if __name__ == "__main__":
      import doctest

      doctest.testmod()
      # read original image
      UpperCamelCase     :    Union[str, Any]       =			imread("../image_data/lena.jpg")
      # turn image in gray scale value
      UpperCamelCase     :    str       =			cvtColor(img, COLOR_BGR2GRAY)

      # Apply multiple Kernel to detect edges
      UpperCamelCase     :    Tuple       =			np.zeros(gray.shape[:2])
      for theta in [0, 3_0, 6_0, 9_0, 1_2_0, 1_5_0]:
            UpperCamelCase     :    Union[str, Any]       =			gabor_filter_kernel(1_0, 8, theta, 1_0, 0, 0)
            out += filteraD(gray, CV_8UC3, kernel_aa)
      UpperCamelCase     :    Optional[Any]       =			out / out.max() * 2_5_5
      UpperCamelCase     :    Optional[Any]       =			out.astype(np.uinta)

      imshow("Original", gray)
      imshow("Gabor filter with 20x20 mask and 6 directions", out)

      waitKey(0)





"""simple docstring"""

def 							A						(    snake_case				:int		)				->     int:
 __UpperCamelCase      =	abs(snake_case		)
 __UpperCamelCase      =	0
 while n > 0:
  res += n % 1_0
  n //= 1_0
 return res






def 							A						(    snake_case				:int		)				->     int:
 __UpperCamelCase      =	abs(snake_case		)
 return n if n < 1_0 else n % 1_0 + sum_of_digits(n // 1_0		)






def 							A						(    snake_case				:int		)				->     int:
 return sum(int(snake_case		) for c in str(abs(snake_case		)		)		)






def 							A						(    )				->     None:
 from collections.abc import Callable
 from timeit import timeit

 def benchmark_a_function(snake_case				:Callable    , snake_case				:int		) -> None:
  __UpperCamelCase      =	f'{func.__name__}({value})'
  __UpperCamelCase      =	timeit(f'__main__.{call}'    , setup='import __main__'		)
  print(f'{call:56} = {func(snake_case		)} -- {timing:.4f} seconds'		)

 for value in (2_6_2_1_4_4, 1_1_2_5_8_9_9_9_0_6_8_4_2_6_2_4, 1_2_6_7_6_5_0_6_0_0_2_2_8_2_2_9_4_0_1_4_9_6_7_0_3_2_0_5_3_7_6):
  for func in (sum_of_digits, sum_of_digits_recursion, sum_of_digits_compact):
   benchmark_a_function(snake_case    , snake_case		)
  print()


if __name__ == "__main__":
      import doctest

      doctest.testmod()
      benchmark()



