
    4[g                     
   d dl mZ d dlZd dlZd dlZd dlZd dlZd dlm	Z	 ddl
mZmZ g dZ ej                         Z ej                          ZddZd Zd	 Zd
 Zd Zd Zd d dddZd Zd Zej6                  d        Zd Zy)    )NumberN)copy_if_needed   )	good_sizeprev_good_size)r   r   set_workersget_workersc                     t        | t              r| f} 	 | D cg c]  }t        j                  |       } }| S c c}w # t        $ r}|xs d}t        | d      |d}~ww xY w)a  Convert ``x`` to an iterable sequence of int

    Parameters
    ----------
    x : value, or sequence of values, convertible to int
    name : str, optional
        Name of the argument being converted, only used in the error message

    Returns
    -------
    y : ``List[int]``
    valuez) must be a scalar or iterable of integersN)
isinstancer   operatorindex	TypeError
ValueError)xnameaes       V/var/www/html/bid-api/venv/lib/python3.12/site-packages/scipy/fft/_pocketfft/helper.py_iterable_of_intr      su     !VDT()*1X^^A*
 H + TwD6!JKLRSSTs!   > 9> > 	A!AA!c                     |du }|du }|syt        |d      }|D cg c]  }|dk  r| j                  z   n| }}t         fd|D              rt        d      t	        t        |            t	        |      k7  rt        d      |st        |d      }|r"t	        |      t	        |      k7  rt        d      |rOt	        |       j                  kD  rt        d	      t         j                  t	        |      z
   j                        }t        ||      D cg c]  \  }}|d
k(  r j                  |   n| }}}nI|r+t         j                        }t         j                        }n|D cg c]  } j                  |    }}t        d |D              rt        d| d      t        |      t        |      fS c c}w c c}}w c c}w )z2Handles shape and axes arguments for nd transformsNaxesr   c              3   J   K   | ]  }|j                   k\  xs |d k    yw)r   N)ndim).0r   r   s     r   	<genexpr>z*_init_nd_shape_and_axes.<locals>.<genexpr>7   s&     2TqAFF{#a!e#Ts    #z$axes exceeds dimensionality of inputzall axes must be uniqueshapezBwhen given, axes and shape arguments have to be of the same lengthz)shape requires more axes than are presentc              3   &   K   | ]	  }|d k    yw)r   N )r   ss     r   r   z*_init_nd_shape_and_axes.<locals>.<genexpr>N   s     
 %Q1q5%s   invalid number of data points () specified)r   r   anyr   lensetrangezipr   listtuple)r   r   r   noshapenoaxesr   r!   s   `      r   _init_nd_shape_and_axesr-   .   s   tmGT\Ff-489Dqa!eAFF
*D92T22CDDs4y>SY&677 0CIU+ > ? ?5zAFF" !LMM#e*,aff5D:=eT:JK:J$!QqBwA-:JK	QWWQVV}%)*TT*

 %
  -eWK@B 	B <d##; :$ L
 +s   F; G ,Gc                    t        | d      st        j                  |       } | j                  t        j                  k(  r$t        j                  | t        j
                        S | j                  j                  dvr$t        j                  | t        j                        S | j                  j                  d      }| j                  d   sdnt        }t        j                  | ||      S )zl
    Convert to array with floating or complex dtype.

    float16 values are also promoted to float32.
    dtypefc=ALIGNEDT)r/   copy)hasattrnpasarrayr/   float16float32kindfloat64newbyteorderflagsr   array)r   r/   r3   s      r   	_asfarrayr>   U   s     1gJJqMww"**zz!RZZ((	
T	!zz!RZZ(( GG  %Ewwy)4~D88AU..    c                 v    | |u ryt        |t        j                        st        |d      ry| j                  du S )z|
    Strict check for `arr` not sharing any data with `original`,
    under the assumption that arr = asarray(original)
    F	__array__N)r   r5   ndarrayr4   base)arroriginals     r   _datacopiedrF   i   s7    
 hh

++0N88tr?   c                    d}t        d      g| j                  z  }t        ||      D ]E  \  }}| j                  |   |k\  rt        d|      ||<   (t        d| j                  |         ||<   d}G t	        |      }|s| |   dfS t        | j                        }t        ||      D ]
  \  }}|||<    t        j                  || j                        }	| |   |	|<   |	dfS )z5Internal auxiliary function for _raw_fft, _raw_fftnd.FNr   T)	slicer   r(   r   r*   r)   r5   zerosr/   )
r   r   r   	must_copyr   naxr!   axiszs
             r   
_fix_shaperO   u   s    I 4[M!&& EUD!2772;!aE"Ia-E"II " %LExQWWAud#4$ $ 	AGGAxAeHd7Nr?   c                 H    |dk  rt        d| d      t        | |f|f      S )Nr   r"   r#   )r   rO   )r   rK   rM   s      r   _fix_shape_1drQ      s7    1u-aS<> 	> a!w''r?      )Nbackwardorthoforwardc                 b    	 t         |    }|r|S d|z
  S # t        $ r t        d| d      dw xY w)zAReturns the pypocketfft normalization mode from the norm argumentrR   zInvalid norm value z,, should be "backward", "ortho" or "forward"N)	_NORM_MAPKeyErrorr   )normrU   inorms      r   _normalizationr[      sQ    =$u0a%i0 =!$ *2 238<	==s     .c                     | t        t        dd      S | dk  r.| t         k\  r| dt        z   z  } | S t        d|  dt                | dk(  rt        d      | S )Ndefault_workersr   r   z workers value out of range; got z, must not be less than zworkers must not be zero)getattr_config
_cpu_countr   )workerss    r   _workersrb      s}    w 1155{zk!q:~%G N ?y I+,6;-9 : :	A344Nr?   c              #      K   t               }t        t        j                  |             t        _        	 d |t        _        y# |t        _        w xY ww)a  Context manager for the default number of workers used in `scipy.fft`

    Parameters
    ----------
    workers : int
        The default number of workers to use

    Examples
    --------
    >>> import numpy as np
    >>> from scipy import fft, signal
    >>> rng = np.random.default_rng()
    >>> x = rng.standard_normal((128, 64))
    >>> with fft.set_workers(4):
    ...     y = signal.fftconvolve(x, x)

    N)r	   rb   r   r   r_   r]   )ra   old_workerss     r   r   r      s=     & -K&x~~g'>?G."-+s   2AA AAAc                  $    t        t        dd      S )zReturns the default number of workers within the current context

    Examples
    --------
    >>> from scipy import fft
    >>> fft.get_workers()
    1
    >>> with fft.set_workers(4):
    ...     fft.get_workers()
    4
    r]   r   )r^   r_   r    r?   r   r	   r	      s     7-q11r?   )N)numbersr   r   os	threading
contextlibnumpyr5   scipy._lib._utilr   pypocketfftr   r   __all__localr_   	cpu_countr`   r   r-   r>   rF   rO   rQ   rW   r[   rb   contextmanagerr   r	   r    r?   r   <module>rq      s      	    + 3 H
)//
R\\^
2$$N/(	6( !aA>	=  . .42r?   