


"""simple docstring"""


from manim import *



class   _a      (      SCREAMING_SNAKE_CASE_ ):
    def      _UpperCamelCase       ( self							:					Optional[int]				):
          lowerCamelCase__           =		Rectangle(height=0.5							,					width=0.5				)
          lowerCamelCase__           =		Rectangle(height=0.46							,					width=0.46				).set_stroke(width=0				)

          lowerCamelCase__           =		Rectangle(height=0.25							,					width=0.25				)

          lowerCamelCase__           =		[mem.copy() for i in range(6				)]
          lowerCamelCase__           =		[mem.copy() for i in range(6				)]
          lowerCamelCase__           =		VGroup(*SCREAMING_SNAKE_CASE__				).arrange(SCREAMING_SNAKE_CASE__							,					buff=0				)
          lowerCamelCase__           =		VGroup(*SCREAMING_SNAKE_CASE__				).arrange(SCREAMING_SNAKE_CASE__							,					buff=0				)
          lowerCamelCase__           =		VGroup(SCREAMING_SNAKE_CASE__							,					SCREAMING_SNAKE_CASE__				).arrange(SCREAMING_SNAKE_CASE__							,					buff=0				)
          lowerCamelCase__           =		Text('CPU'							,					font_size=24				)
          lowerCamelCase__           =		Group(SCREAMING_SNAKE_CASE__							,					SCREAMING_SNAKE_CASE__				).arrange(SCREAMING_SNAKE_CASE__							,					buff=0.5							,					aligned_edge=SCREAMING_SNAKE_CASE__				)
          cpu.move_to([-2.5, -0.5, 0]				)
          self.add(SCREAMING_SNAKE_CASE__				)

          lowerCamelCase__           =		[mem.copy() for i in range(4				)]
          lowerCamelCase__           =		VGroup(*SCREAMING_SNAKE_CASE__				).arrange(SCREAMING_SNAKE_CASE__							,					buff=0				)
          lowerCamelCase__           =		Text('GPU'							,					font_size=24				)
          lowerCamelCase__           =		Group(SCREAMING_SNAKE_CASE__							,					SCREAMING_SNAKE_CASE__				).arrange(SCREAMING_SNAKE_CASE__							,					buff=0.5							,					aligned_edge=SCREAMING_SNAKE_CASE__				)
          gpu.move_to([-1, -1, 0]				)
          self.add(SCREAMING_SNAKE_CASE__				)

          lowerCamelCase__           =		[mem.copy() for i in range(6				)]
          lowerCamelCase__           =		VGroup(*SCREAMING_SNAKE_CASE__				).arrange(SCREAMING_SNAKE_CASE__							,					buff=0				)

          lowerCamelCase__           =		Text('Model'							,					font_size=24				)
          lowerCamelCase__           =		Group(SCREAMING_SNAKE_CASE__							,					SCREAMING_SNAKE_CASE__				).arrange(SCREAMING_SNAKE_CASE__							,					buff=0.5							,					aligned_edge=SCREAMING_SNAKE_CASE__				)
          model.move_to([3, -1.0, 0]				)
          self.add(SCREAMING_SNAKE_CASE__				)

          lowerCamelCase__           =		[]
          lowerCamelCase__           =		[]

          for i, rect in enumerate(SCREAMING_SNAKE_CASE__				):
                lowerCamelCase__           =		fill.copy().set_fill(SCREAMING_SNAKE_CASE__							,					opacity=0.8				)
                target.move_to(SCREAMING_SNAKE_CASE__				)
                model_arr.append(SCREAMING_SNAKE_CASE__				)

                lowerCamelCase__           =		Rectangle(height=0.46							,					width=0.46				).set_stroke(width=0.0				).set_fill(SCREAMING_SNAKE_CASE__							,					opacity=0.8				)
                cpu_target.move_to(cpu_left_col_base[i]				)
                model_cpu_arr.append(SCREAMING_SNAKE_CASE__				)

          self.add(*SCREAMING_SNAKE_CASE__							,					*SCREAMING_SNAKE_CASE__				)

          lowerCamelCase__           =		[meta_mem.copy() for i in range(6				)]
          lowerCamelCase__           =		[meta_mem.copy() for i in range(6				)]
          lowerCamelCase__           =		VGroup(*SCREAMING_SNAKE_CASE__				).arrange(SCREAMING_SNAKE_CASE__							,					buff=0				)
          lowerCamelCase__           =		VGroup(*SCREAMING_SNAKE_CASE__				).arrange(SCREAMING_SNAKE_CASE__							,					buff=0				)
          lowerCamelCase__           =		VGroup(SCREAMING_SNAKE_CASE__							,					SCREAMING_SNAKE_CASE__				).arrange(SCREAMING_SNAKE_CASE__							,					buff=0				)
          lowerCamelCase__           =		Text('Disk'							,					font_size=24				)
          lowerCamelCase__           =		Group(SCREAMING_SNAKE_CASE__							,					SCREAMING_SNAKE_CASE__				).arrange(SCREAMING_SNAKE_CASE__							,					buff=0.5							,					aligned_edge=SCREAMING_SNAKE_CASE__				)
          disk.move_to([-4, -1.25, 0]				)
          self.add(SCREAMING_SNAKE_CASE__							,					SCREAMING_SNAKE_CASE__				)

          lowerCamelCase__           =		Square(side_length=2.2				)
          key.move_to([-5, 2, 0]				)

          lowerCamelCase__           =		MarkupText(
              F'<b>Key:</b>\n\n<span fgcolor=\'{YELLOW}\'>●</span> Empty Model'							,					font_size=18							,					)

          key_text.move_to([-5, 2.4, 0]				)

          self.add(SCREAMING_SNAKE_CASE__							,					SCREAMING_SNAKE_CASE__				)

          lowerCamelCase__           =		MarkupText(
              F'<span fgcolor=\'{BLUE}\'>●</span> Checkpoint'							,					font_size=18							,					)

          blue_text.next_to(SCREAMING_SNAKE_CASE__							,					DOWN * 2.4							,					aligned_edge=key_text.get_left()				)
          self.add(SCREAMING_SNAKE_CASE__				)

          lowerCamelCase__           =		MarkupText(
              F'Now watch as an input is passed through the model\nand how the memory is utilized and handled.'							,					font_size=24							,					)
          step_a.move_to([2, 2, 0]				)

          self.play(Write(SCREAMING_SNAKE_CASE__				)				)

          lowerCamelCase__           =		Square(0.3				)
          input.set_fill(SCREAMING_SNAKE_CASE__							,					opacity=1.0				)
          input.set_stroke(width=0.0				)
          input.next_to(model_base[0]							,					SCREAMING_SNAKE_CASE__							,					buff=0.5				)

          self.play(Write(SCREAMING_SNAKE_CASE__				)				)

          input.generate_target()
          input.target.next_to(model_arr[0]							,					direction=SCREAMING_SNAKE_CASE__							,					buff=0.02				)
          self.play(MoveToTarget(SCREAMING_SNAKE_CASE__				)				)

          self.play(FadeOut(SCREAMING_SNAKE_CASE__				)				)

          lowerCamelCase__           =		Arrow(start=SCREAMING_SNAKE_CASE__							,					end=SCREAMING_SNAKE_CASE__							,					color=SCREAMING_SNAKE_CASE__							,					buff=0.5				)
          a.next_to(model_arr[0].get_left()							,					SCREAMING_SNAKE_CASE__							,					buff=0.2				)

          model_cpu_arr[0].generate_target()
          model_cpu_arr[0].target.move_to(gpu_rect[0]				)

          lowerCamelCase__           =		MarkupText(
              F'As the input reaches a layer, the hook triggers\nand weights are moved from the CPU\nto the GPU and back.'							,					font_size=24							,					)
          step_a.move_to([2, 2, 0]				)

          self.play(Write(SCREAMING_SNAKE_CASE__							,					run_time=3				)				)

          lowerCamelCase__           =		{'run_time': 1, 'fade_in': True, 'fade_out': True, 'buff': 0.02}

          self.play(
              Write(SCREAMING_SNAKE_CASE__				)							,					Circumscribe(model_arr[0]							,					color=SCREAMING_SNAKE_CASE__							,					**SCREAMING_SNAKE_CASE__				)							,					Circumscribe(model_cpu_arr[0]							,					color=SCREAMING_SNAKE_CASE__							,					**SCREAMING_SNAKE_CASE__				)							,					Circumscribe(gpu_rect[0]							,					color=SCREAMING_SNAKE_CASE__							,					**SCREAMING_SNAKE_CASE__				)							,					)
          self.play(MoveToTarget(model_cpu_arr[0]				)				)

          lowerCamelCase__           =		a.copy()
          for i in range(6				):
                a_c.next_to(model_arr[i].get_right() + 0.02							,					SCREAMING_SNAKE_CASE__							,					buff=0.2				)

                input.generate_target()
                input.target.move_to(model_arr[i].get_right() + 0.02				)

                lowerCamelCase__           =		AnimationGroup(
                    FadeOut(SCREAMING_SNAKE_CASE__							,					run_time=0.5				)							,					MoveToTarget(SCREAMING_SNAKE_CASE__							,					run_time=0.5				)							,					FadeIn(SCREAMING_SNAKE_CASE__							,					run_time=0.5				)							,					lag_ratio=0.2				)

                self.play(SCREAMING_SNAKE_CASE__				)

                model_cpu_arr[i].generate_target()
                model_cpu_arr[i].target.move_to(cpu_left_col_base[i]				)

                if i < 5:
                      model_cpu_arr[i + 1].generate_target()
                      model_cpu_arr[i + 1].target.move_to(gpu_rect[0]				)
                      if i >= 1:
                            lowerCamelCase__           =		0.7

                      self.play(
                          Circumscribe(model_arr[i]							,					**SCREAMING_SNAKE_CASE__				)							,					Circumscribe(cpu_left_col_base[i]							,					**SCREAMING_SNAKE_CASE__				)							,					Circumscribe(cpu_left_col_base[i + 1]							,					color=SCREAMING_SNAKE_CASE__							,					**SCREAMING_SNAKE_CASE__				)							,					Circumscribe(gpu_rect[0]							,					color=SCREAMING_SNAKE_CASE__							,					**SCREAMING_SNAKE_CASE__				)							,					Circumscribe(model_arr[i + 1]							,					color=SCREAMING_SNAKE_CASE__							,					**SCREAMING_SNAKE_CASE__				)							,					)
                      if i < 1:
                            self.play(
                                MoveToTarget(model_cpu_arr[i]				)							,					MoveToTarget(model_cpu_arr[i + 1]				)							,					)
                      else:
                            self.play(
                                MoveToTarget(model_cpu_arr[i]							,					run_time=0.7				)							,					MoveToTarget(model_cpu_arr[i + 1]							,					run_time=0.7				)							,					)
                else:
                      model_cpu_arr[i].generate_target()
                      model_cpu_arr[i].target.move_to(cpu_left_col_base[-1]				)
                      input.generate_target()
                      input.target.next_to(model_arr[-1].get_right()							,					RIGHT + 0.02							,					buff=0.2				)

                      self.play(
                          Circumscribe(model_arr[-1]							,					color=SCREAMING_SNAKE_CASE__							,					**SCREAMING_SNAKE_CASE__				)							,					Circumscribe(cpu_left_col_base[-1]							,					color=SCREAMING_SNAKE_CASE__							,					**SCREAMING_SNAKE_CASE__				)							,					Circumscribe(gpu_rect[0]							,					color=SCREAMING_SNAKE_CASE__							,					**SCREAMING_SNAKE_CASE__				)							,					)

                      self.play(MoveToTarget(model_cpu_arr[i]				)				)

                lowerCamelCase__           =		a_c
                lowerCamelCase__           =		a_c.copy()

          input.generate_target()
          input.target.next_to(model_base[-1]							,					RIGHT + 0.02							,					buff=0.5				)
          self.play(
              FadeOut(SCREAMING_SNAKE_CASE__				)							,					FadeOut(SCREAMING_SNAKE_CASE__							,					run_time=0.5				)							,					)

          lowerCamelCase__           =		MarkupText(F'Inference on a model too large for GPU memory\nis successfully completed.'							,					font_size=24				)
          step_a.move_to([2, 2, 0]				)

          self.play(Write(SCREAMING_SNAKE_CASE__							,					run_time=3				)							,					MoveToTarget(SCREAMING_SNAKE_CASE__				)				)

          self.wait()







"""simple docstring"""


from __future__ import annotations

from math import gcd



def   snake_case						(				_a:     int		,   _a:     int = 2		,   _a:     int = 1		,   _a:     int = 3		,   )->		int | None:
      '''simple docstring'''


      if num < 2:
            raise ValueError('The input value cannot be less than 2'							)

      # Because of the relationship between ``f(f(x))`` and ``f(x)``, this
      # algorithm struggles to find factors that are divisible by two.
      # As a workaround, we specifically check for two and even inputs.
      #   See: https://math.stackexchange.com/a/2856214/165820
      if num > 2 and num % 2 == 0:
            return 2

      # Pollard's Rho algorithm requires a function that returns pseudorandom
      # values between 0 <= X < ``num``.  It doesn't need to be random in the
      # sense that the output value is cryptographically secure or difficult
      # to calculate, it only needs to be random in the sense that all output
      # values should be equally likely to appear.
      # For this reason, Pollard suggested using ``f(x) = (x**2 - 1) % num``
      # However, the success of Pollard's algorithm isn't guaranteed and is
      # determined in part by the initial seed and the chosen random function.
      # To make retries easier, we will instead use ``f(x) = (x**2 + C) % num``
      # where ``C`` is a value that we can modify between each attempt.
      def rand_fn(_a:     int		,   _a:     int		,   _a:     int							) -> int:
            return (pow(_a		,   2							) + step) % modulus

      for _ in range(_a							):
            # These track the position within the cycle detection logic.
            lowerCamelCase__           =		seed
            lowerCamelCase__           =		seed

            while True:
                  # At each iteration, the tortoise moves one step and the hare moves two.
                  lowerCamelCase__           =		rand_fn(_a		,   _a		,   _a							)
                  lowerCamelCase__           =		rand_fn(_a		,   _a		,   _a							)
                  lowerCamelCase__           =		rand_fn(_a		,   _a		,   _a							)

                  # At some point both the tortoise and the hare will enter a cycle whose
                  # length ``p`` is a divisor of ``num``.  Once in that cycle, at some point
                  # the tortoise and hare will end up on the same value modulo ``p``.
                  # We can detect when this happens because the position difference between
                  # the tortoise and the hare will share a common divisor with ``num``.
                  lowerCamelCase__           =		gcd(hare - tortoise		,   _a							)

                  if divisor == 1:
                        # No common divisor yet, just keep searching.
                        continue
                  else:
                        # We found a common divisor!
                        if divisor == num:
                              # Unfortunately, the divisor is ``num`` itself and is useless.
                              break
                        else:
                              # The divisor is a nontrivial factor of ``num``!
                              return divisor

        # If we made it here, then this attempt failed.
        # We need to pick a new starting seed for the tortoise and hare
        # in addition to a new step value for the random function.
        # To keep this example implementation deterministic, the
        # new values will be generated based on currently available
        # values instead of using something like ``random.randint``.

        # We can use the hare's position as the new seed.
        # This is actually what Richard Brent's the "optimized" variant does.
            lowerCamelCase__           =		hare

            # The new step value for the random function can just be incremented.
            # At first the results will be similar to what the old function would
            # have produced, but the value will quickly diverge after a bit.
            step += 1

      # We haven't found a divisor within the requested number of attempts.
      # We were unlucky or ``num`` itself is actually prime.
      return None


if __name__ == "__main__":
   import argparse

   _snake_case          =							argparse.ArgumentParser()
   parser.add_argument(
       "num",
       type=int,
       help="The value to find a divisor of",
   )
   parser.add_argument(
       "--attempts",
       type=int,
       default=3,
       help="The number of attempts before giving up",
   )
   _snake_case          =							parser.parse_args()

   _snake_case          =							pollard_rho(args.num, attempts=args.attempts)
   if divisor is None:
      print(f"""{args.num} is probably prime""")
   else:
      _snake_case          =							args.num // divisor
      print(f"""{args.num} = {divisor} * {quotient}""")



