
    :Sh'                         d Z ddlZddlZ ej        ej                    ej        e          Z ej        d          dz
  dz  Z	d ej        d          z
  dz  Z
d
d	ZdS )zPython program for golden section search (straight-up copied from Wikipedia).
   This implementation reuses function evaluations, saving 1/2 of the evaluations per
   iteration, and returns a bounding interval.    N)level            -C6?c                     t          ||          t          ||          }}||z
  }||k    r||fS t          t          j        t          j        ||z            t          j        t                    z                      }t                              d|            fd}|t          |z  z   }|t          |z  z   } |||dk              }	 |||dk              }
t          |dz
            D ]i}|	|
k     r1|}|}|	}
t          |z  }|t          |z  z   } ||||dz
  k              }	9|}|}|
}	t          |z  }|t          |z  z   }  |||dz
  k              }
j|	|
k     r||fS ||fS )ay  Golden-section search.

    Given a function f with a single local minimum in
    the interval [a,b], gss returns a subset interval
    [c,d] that contains the minimum with d-c <= tol.

    Example:
    >>> f = lambda x: (x-2)**2
    >>> a = 1
    >>> b = 5
    >>> tol = 1e-5
    >>> (c,d) = gss(f, a, b, tol)
    >>> print(c, d)
    1.9999959837979107 2.0000050911830893
    zRAbout to perform %d iterations of golden section search to find the best frameratec                 T    	  | |          S # t           $ r  |           cY S w xY w)N)	TypeError)xis_last_iterfs     e/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/ffsubsync/golden_section_search.py	f_wrappedzgss.<locals>.f_wrapped,   sF    	1Q%%% 	 	 	1Q44KKK	s    ''r   r   )minmaxintmathceilloginvphiloggerinfoinvphi2range)r   abtolhnr   cdycydks   `           r   gssr&      s   " !QiiQQ	AACxx!t 	DIdhsQw''$(6*:*::;;<<A
KK\	  
     	
GaKA	FQJA	1a1f		B	1a1f		B1q5\\ " "77AAB
AGaKA1a1q5j))BBAAB
AFQJA1a1q5j!!BB	Bww!t!t    )r   )__doc__loggingr   basicConfigINFO	getLogger__name__r   sqrtr   r   r&    r'   r   <module>r0      s   2 2    ', ' ' ' '		8	$	$ $)A,,
a	yty||q
 ; ; ; ; ; ;r'   