
    ^Mh                         d Z ddlZddlmZ ddlZddlmZ ddlmZ 	 ddlZ	n# e
$ r Y nw xY wddZdd	Zd
 Zedk    r e             dS dS )a  Compute gammainc and gammaincc for large arguments and parameters
and save the values to data files for use in tests. We can't just
compare to mpmath's gammainc in test_mpmath.TestSystematic because it
would take too long.

Note that mpmath's gammainc is computed using hypercomb, but since it
doesn't allow the user to increase the maximum number of terms used in
the series it doesn't converge for many arguments. To get around this
we copy the mpmath implementation but use more terms.

This takes about 17 minutes to run on a 2.3 GHz Macbook Pro with 4GB
ram.

Sources:
[1] Fredrik Johansson and others. mpmath: a Python library for
    arbitrary-precision floating-point arithmetic (version 0.19),
    December 2013. http://mpmath.org/.

    N)time)pi)	mpf2float2    c                 l  	 t          j        |          5  t          j        |           t          j        |          t          j        |          c}} |gt          j        d          		fd}t          j        ||g|          }t          |          cddd           S # 1 swxY w Y   dS )zCompute gammainc exactly like mpmath does but allow for more
    summands in hypercomb. See

    mpmath/functions/expintegrals.py#L134

    in the mpmath GitHub repository.

    Texactc                 V    t          j                  | gd| dgg dgd| z   gf}|fS )N   mpexp)zT1Gbnegbs     g/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/scipy/special/_precompute/gammainc_data.pyhzgammainc.<locals>.h/   s;    &,,1%1bz2q1#!uaGB5L    maxtermsN)r   workdpsmpffneg	hypercombr   )
axdpsr   r   r   resr   r   r   s
          @@@r   gammaincr#   !   s    
C 
 
&))RVAYYq		1aCwq%%%	 	 	 	 	 	 	 l1qcH555~~
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   BB))B-0B-c           	      \    t          j        |          5   |c} t          j        |          rK	 t          t          j        | d                    cddd           S # t           j        j        $ r Y nw xY wt          j         d          |g	  fd}t          t          j        ||gd                    cddd           S # t           j        j        $ r;  fd}t          t          j        ||g|                    cY cddd           S w xY w# 1 swxY w Y   dS )	zCompute gammaincc exactly like mpmath does but allow for more
    terms in hypercomb. See

    mpmath/functions/expintegrals.py#L187

    in the mpmath GitHub repository.

    T)r   regularizedNr	   c                 Z    | dz
  }t          j                  gd|gg d| gg dz  fgS )Nr   r   )r   rr   r   negas     r   r   zgammaincc.<locals>.hM   s?    aC&,,*QFBAr7B$OPPr   )force_seriesc                 x    g d| dz
  g| gg g df}t          j                   | gd| dgg dgd| z   gf}||fS )Nr   r   r   r   )r   r   T2r   r   r(   s      r   r   zgammaincc.<locals>.hR   s]    !QqSA32r14vd||mQ*Q2JAsQqSE1L2vr   r   )	r   r   isintr   r#   libmpNoConvergencer   r   )r   r    r!   r   r   r   r   r(   s   `     @@r   	gammainccr/   7   s*    
C F F!18A;; 	 Q!!F!F!FGGF F F F F F F F 8)   wq%%%C
	FQ Q Q Q Q Q Q R\!aStDDDEE!F F F F F F F F" x% 	F 	F 	F       R\!aS8DDDEEEE-F F F F F F F F"	F#F F F F F F F F F FsM   D!#A##A:7D!9A::D!+CA DD!DD!!D%(D%c            
         t                      } t          t                     t          j                            t                    }t          j        ddd          }t          j        t          j	        t          dz            t          j	        t          j        d                    d          }t          j        t          j	        t          dz            t          j	        t          j        d                    d          }t          |ft          |fg}|D ]F\  }}t          j        ||          \  }}	|t          j        |	          z  |t          j        |	          z  }}
|
                                |                                }}
g }t%          t'          |
|                    D ]]\  }\  }}|t          k    r(t          j        |          t          j        |          }}|                    || |||          f           ^t          j        |          }t          j                            |dddd	|j         d
          }t          j        ||           Ht          t                      | z
  dz   d           d S )N         g333333?gffffff?z..testsdatalocalz.txt<   z minutes elapsed)r   print__doc__ospathdirname__file__nplogspacelog10r   arctanr#   r/   meshgridcossinflatten	enumeratezipfloorappendarrayjoin__name__savetxt)t0pwdr'   lthetauthetaregimesfuncthetargthetagr   r    datasetia0x0filenames                    r   mainr\   Y   s   	B 
'NNN
'//(
#
#C
Ar2A["Q$")C..)A)A2FFF["Q$")C..)A)A2FFF&!Iv#67G & &e[E**
F"&.. "RVF^^"31yy{{AIIKK1$SAYY// 	3 	3KAxBy   "rx||BNNBDDRLL12222(7##7<<T7FG#'= 6 6 68 8

8W%%%%	dffrk2
/
/
/00000r   __main__)r   r   )r9   r:   r   numpyr>   r   scipy.special._mptestutilsr   mpmathr   ImportErrorr#   r/   r\   rL    r   r   <module>rc      s    & 
			                 0 0 0 0 0 0	 	 	 	D	   ,F F F FD1 1 1D zDFFFFF s   # ++