
    xfY                         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	  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j.                  d        Zd Zy)    )NumberN   )	good_sizec                     t        | t              r| f} 	 | D cg c]  }t        j                  |       } }| S c c}w # t        $ r&}|xs d}t        dj                  |            |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format)xnameaes       =/usr/lib/python3/dist-packages/scipy/fft/_pocketfft/helper.py_iterable_of_intr      sw     !VD/()*1X^^A** H + /wF &,(-.	//s!   > 9> > 	A-!A((A-c                 r    |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      ||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>2   s%     2qAFF{#a!e#2s    #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>I   s     
 Q1q5
 s   invalid number of data points () specified)
r   r   anyr   lensetrangezipr   list)r   r   r   noshapenoaxesr   r   s   `      r   _init_nd_shape_and_axesr)   )   s   tmGT\Ff-489qa!eAFF
*9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$!QqBwA-KK	QWWQVV}%)***

 %
  -eWK@B 	B $;; :$ L
 +s   F) F.,F4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    }t        j                  | ||      S )zl
    Convert to array with floating or complex dtype.

    float16 values are also promoted to float32.
    dtypefc=ALIGNED)r+   copy)hasattrnpasarrayr+   float16float32kindfloat64newbyteorderflagsarray)r   r+   r/   s      r   	_asfarrayr:   P   s     1gJJqMww"**zz!RZZ((	
T	!zz!RZZ(( GG  %Ewwy!!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   r1   ndarrayr0   base)arroriginals     r   _datacopiedrB   d   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   tupler&   r1   zerosr+   )
r   r   r   	must_copyr
   naxr   axiszs
             r   
_fix_shaperL   p   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   rL   )r   rH   rJ   s      r   _fix_shape_1drN      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 argumentrO   zInvalid norm value z,, should be "backward", "ortho" or "forward"N)	_NORM_MAPKeyErrorr   )normrR   inorms      r   _normalizationrX      sQ    =$u0a%i0 =!$ *2 238<	==s     .c                     | t        t        dd      S | dk  r8| t         k\  r| dt        z   z  } | S t        dj	                  | t                     | dk(  rt        d      | S )Ndefault_workersr   r   z<workers value out of range; got {}, must not be less than {}zworkers must not be zero)getattr_config
_cpu_countr   r   )workerss    r   _workersr_      sy    w 1155{zk!q:~%G N  --3VGj[-IK K	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)get_workersr_   r	   r
   r\   rZ   )r^   old_workerss     r   set_workersrc      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
    rZ   r   )r[   r\   r   r;   r   ra   ra      s     7-q11r;   )N)numbersr   r	   os	threading
contextlibnumpyr1   pypocketfftr   localr\   	cpu_countr]   r   r)   r:   rB   rL   rN   rT   rX   r_   contextmanagerrc   ra   r   r;   r   <module>rn      s      	    "
)//
R\\^
4$N/(	6( !aA>	=  . .42r;   