
    !Цi#C                         S SK Jr  S SKrSSKJr  SSKJr  SSKJ	r	J
r
JrJr  SSKJr  SSKJr  SS	KJr  SS
KJrJrJrJr  SSKJrJr  / SQrS rS rSS jrSS jrSS jrSS jrS rg)    )NumberN   )_have_c99_complex)downcoef)dwt_axis
dwt_single	idwt_axisidwt_single)dwt_coeff_len)dwt_max_level)upcoef)ModesWavelet_check_dtypewavelist)	AxisError_as_wavelet)dwtidwtr   r   r   r   padc                 ^   [        U[        5      (       a  UR                  nOp[        U[        5      (       a2  U[	        SS9;   a  [        U5      R                  nO8[        SU S35      e[        U[        5      (       a	  US-  S:X  d  [        S5      eUS:  a  [        S	5      e[        X5      $ )
a"  
dwt_max_level(data_len, filter_len)

Compute the maximum useful level of decomposition.

Parameters
----------
data_len : int
    Input data length.
filter_len : int, str or Wavelet
    The wavelet filter length.  Alternatively, the name of a discrete
    wavelet or a Wavelet object can be specified.

Returns
-------
max_level : int
    Maximum level.

Notes
-----
The rational for the choice of levels is the maximum level where at least
one coefficient in the output is uncorrupted by edge effects caused by
signal extension.  Put another way, decomposition stops when the signal
becomes shorter than the FIR filter length for a given wavelet.  This
corresponds to:

.. max_level = floor(log2(data_len/(filter_len - 1)))

.. math::
    \mathtt{max\_level} = \left\lfloor\log_2\left(\mathtt{
        \frac{data\_len}{filter\_len - 1}}\right)\right\rfloor

Examples
--------
>>> import pywt
>>> w = pywt.Wavelet('sym5')
>>> pywt.dwt_max_level(data_len=1000, filter_len=w.dec_len)
6
>>> pywt.dwt_max_level(1000, w)
6
>>> pywt.dwt_max_level(1000, 'sym5')
6
discrete)kind'z~', is not a recognized discrete wavelet.  A list of supported wavelet names can be obtained via pywt.wavelist(kind='discrete')r   r   zZfilter_len must be an integer, discrete Wavelet object, or the name of a discrete wavelet.   zinvalid wavelet filter length)
isinstancer   dec_lenstrr   
ValueErrorr   _dwt_max_level)data_len
filter_lens     H/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/pywt/_dwt.pyr   r      s    X *g&&''
	J	$	$z22 ,44JJ<  2 23 3 V,,a11D*+ 	+ A~899(//    c                     [        U[        5      (       a  UR                  n[        X[        R
                  " U5      5      $ )a-  
dwt_coeff_len(data_len, filter_len, mode='symmetric')

Returns length of dwt output for given data length, filter length and mode

Parameters
----------
data_len : int
    Data length.
filter_len : int
    Filter length.
mode : str, optional
    Signal extension mode, see :ref:`Modes <ref-modes>`.

Returns
-------
len : int
    Length of dwt output.

Notes
-----
For all modes except periodization::

    len(cA) == len(cD) == floor((len(data) + wavelet.dec_len - 1) / 2)

for periodization mode ("per")::

    len(cA) == len(cD) == ceil(len(data) / 2)

)r   r   r   _dwt_coeff_lenr   from_object)r!   r"   modes      r#   r   r   S   s4    > *g&&''
(0A0A$0GHHr$   c                    [         (       ds  [        R                  " U 5      (       aX  [        R                  " U 5      n [	        U R
                  XU5      u  pE[	        U R                  XU5      u  pgUSU-  -   USU-  -   4$ [        U 5      n[        R                  " XSS9n [        R                  " U5      n[        U5      nUS:  a  X0R                  -   nSUs=::  a  U R                  :  d  O  [        S5      eU R                  S:X  a<  [        XU5      u  p[        R                  " X5      [        R                  " X5      pX4$ [        XX#S9u  pX4$ )a  
dwt(data, wavelet, mode='symmetric', axis=-1)

Single level Discrete Wavelet Transform.

Parameters
----------
data : array_like
    Input signal
wavelet : Wavelet object or name
    Wavelet to use
mode : str, optional
    Signal extension mode, see :ref:`Modes <ref-modes>`.
axis: int, optional
    Axis over which to compute the DWT. If not given, the
    last axis is used.

Returns
-------
(cA, cD) : tuple
    Approximation and detail coefficients.

Notes
-----
Length of coefficients arrays depends on the selected mode.
For all modes except periodization:

    ``len(cA) == len(cD) == floor((len(data) + wavelet.dec_len - 1) / 2)``

For periodization mode ("per"):

    ``len(cA) == len(cD) == ceil(len(data) / 2)``

Examples
--------
>>> import pywt
>>> (cA, cD) = pywt.dwt([1, 2, 3, 4, 5, 6], 'db1')
>>> cA
array([ 2.12132034,  4.94974747,  7.77817459])
>>> cD
array([-0.70710678, -0.70710678, -0.70710678])

              ?Cdtypeorderr   z!Axis greater than data dimensionsr   axis)r   npiscomplexobjasarrayr   realimagr   r   r'   r   ndimr   r   r   )datawaveletr(   r0   cA_rcD_rcA_icD_idtcAcDs              r#   r   r   x   s"   X !6!6zz$G48
G48
r$wr$w// 
d	B::dC0DT"D'"Gaxii tyy ;<<yyA~D40B#RZZ%7B 8O $98Or$   c           	         U c  Uc  [        S5      e[        (       d  [        R                  " U 5      (       d  [        R                  " U5      (       a  U c-  [        R                  " U5      n[        R
                  " U5      n O/Uc,  [        R                  " U 5      n [        R
                  " U 5      n[        U R                  UR                  X#U5      S[        U R                  UR                  X#U5      -  -   $ U b   [        U 5      n[        R                  " XSS9n Ub   [        U5      n[        R                  " XSS9nU b  Ub  U R                  UR                  :w  aw  U R                  R                  S:X  d  UR                  R                  S:X  a  [        R                  nO[        R                  nU R                  U5      n UR                  U5      nO3U c  [        R
                  " U5      n OUc  [        R
                  " U 5      nU R                  n[         R"                  " U5      n[%        U5      nUS:  a  XG-   nSUs=::  a  U:  d  O  ['        S5      eUS:X  a  [)        XX#5      nU$ [+        XX#US	9nU$ )
ah  
idwt(cA, cD, wavelet, mode='symmetric', axis=-1)

Single level Inverse Discrete Wavelet Transform.

Parameters
----------
cA : array_like or None
    Approximation coefficients.  If None, will be set to array of zeros
    with same shape as ``cD``.
cD : array_like or None
    Detail coefficients.  If None, will be set to array of zeros
    with same shape as ``cA``.
wavelet : Wavelet object or name
    Wavelet to use
mode : str, optional (default: 'symmetric')
    Signal extension mode, see :ref:`Modes <ref-modes>`.
axis: int, optional
    Axis over which to compute the inverse DWT. If not given, the
    last axis is used.

Returns
-------
rec: array_like
    Single level reconstruction of signal from given coefficients.

Examples
--------
>>> import pywt
>>> (cA, cD) = pywt.dwt([1,2,3,4,5,6], 'db2', 'smooth')
>>> pywt.idwt(cA, cD, 'db2', 'smooth')
array([ 1.,  2.,  3.,  4.,  5.,  6.])

One of the neat features of ``idwt`` is that one of the ``cA`` and ``cD``
arguments can be set to None.  In that situation the reconstruction will be
performed using only the other one.  Mathematically speaking, this is
equivalent to passing a zero-filled array as one of the arguments.

>>> (cA, cD) = pywt.dwt([1,2,3,4,5,6], 'db2', 'smooth')
>>> A = pywt.idwt(cA, None, 'db2', 'smooth')
>>> D = pywt.idwt(None, cD, 'db2', 'smooth')
>>> A + D
array([ 1.,  2.,  3.,  4.,  5.,  6.])

z5At least one coefficient parameter must be specified.r*   r+   r,   cr   z(Axis greater than coefficient dimensionsr   r/   )r   r   r1   r2   r3   
zeros_liker   r4   r5   r   r-   r   
complex128float64astyper6   r   r'   r   r   r
   r	   )	r>   r?   r8   r(   r0   r=   r-   r6   recs	            r#   r   r      s   b 
zbj & ' 	' "//""5"59L9L:BBr"BZBBr"BRWWbggwd;4'>>? 	@ 
~"ZZC0	~"ZZC0	~".88rxxxx}}#rxx}}';

5!B5!B	]]2	]]2 77DT"D'"Gax{tBCCqy"'0 J D9Jr$   c           	         [         (       dM  [        R                  " U5      (       a2  [        XR                  X#U5      S[        XR
                  X#U5      -  -   $ [        U5      n[        R                  " XSS9nUR                  S:  a  [        S5      eU S;  a  [        SU  S35      e[        R                  " U5      n[        U5      n[        R                  " [        U S	:H  XX45      5      $ )
a  
downcoef(part, data, wavelet, mode='symmetric', level=1)

Partial Discrete Wavelet Transform data decomposition.

Similar to ``pywt.dwt``, but computes only one set of coefficients.
Useful when you need only approximation or only details at the given level.

Parameters
----------
part : str
    Coefficients type:

    * 'a' - approximations reconstruction is performed
    * 'd' - details reconstruction is performed

data : array_like
    Input signal.
wavelet : Wavelet object or name
    Wavelet to use
mode : str, optional
    Signal extension mode, see :ref:`Modes <ref-modes>`.
level : int, optional
    Decomposition level.  Default is 1.

Returns
-------
coeffs : ndarray
    1-D array of coefficients.

See Also
--------
upcoef

r*   r+   r,   r   zdowncoef only supports 1d data.ad$Argument 1 must be 'a' or 'd', not ''.a)r   r1   r2   r   r4   r5   r   r3   r6   r   r   r'   r   	_downcoef)partr7   r8   r(   levelr=   s         r#   r   r   '  s    H !6!6yy'?8D))WEBBC 	D 
d	B::dC0Dyy1}:;;4?vRHIIT"D'"G::iTDHIIr$   c           	         [         (       dM  [        R                  " U5      (       a2  [        XR                  X#U5      S[        XR
                  X#U5      -  -   $ [        U5      n[        R                  " XSS9nUR                  S:  a  [        S5      e[        U5      nU S;  a  [        SU  S35      e[        R                  " [        U S	:H  XX45      5      $ )
aO  
upcoef(part, coeffs, wavelet, level=1, take=0)

Direct reconstruction from coefficients.

Parameters
----------
part : str
    Coefficients type:
    * 'a' - approximations reconstruction is performed
    * 'd' - details reconstruction is performed
coeffs : array_like
    Coefficients array to reconstruct
wavelet : Wavelet object or name
    Wavelet to use
level : int, optional
    Multilevel reconstruction level.  Default is 1.
take : int, optional
    Take central part of length equal to 'take' from the result.
    Default is 0.

Returns
-------
rec : ndarray
    1-D array with reconstructed data from coefficients.

See Also
--------
downcoef

Examples
--------
>>> import pywt
>>> data = [1,2,3,4,5,6]
>>> (cA, cD) = pywt.dwt(data, 'db2', 'smooth')
>>> pywt.upcoef('a', cA, 'db2') + pywt.upcoef('d', cD, 'db2')
array([-0.25      , -0.4330127 ,  1.        ,  2.        ,  3.        ,
        4.        ,  5.        ,  6.        ,  1.78589838, -1.03108891])
>>> n = len(data)
>>> pywt.upcoef('a', cA, 'db2', take=n) + pywt.upcoef('d', cD, 'db2', take=n)
array([ 1.,  2.,  3.,  4.,  5.,  6.])

r*   r+   r,   r   zupcoef only supports 1d coeffs.rH   rI   rJ   rK   )r   r1   r2   r   r4   r5   r   r3   r6   r   r   _upcoef)rM   coeffsr8   rN   taker=   s         r#   r   r   Z  s    X !8!8t[['$?6$WTBBC 	D 
f	BZZ4F{{Q:;;'"G4?vRHII::gdck6EHIIr$   c                    [         R                  " U 5      n [         R                  " U5      n[         R                  " U5      R	                  [         R
                  SS9nUR                  5       S:  a  [        S5      e[         R                  " XR                  S45      R                  5       nUS;   a  [         R                  " XUS9nU$ US;   ai  US	:X  aL  [        U R                  5       Vs/ s H  nSU R                  U   S-  4PM     nn[         R                  " XS
S9n [         R                  " XSS9nU$ US:X  a  [         R                  " XSSS9nU$ US:X  a  [         R                  " XS
S9nU$ US:X  a  S n[         R                  " XU5      nU$ US:X  a  S n[         R                  " XU5      nU$ US:X  a  [         R                  " XSSS9nU$ [        SU S[        R                   35      es  snf )u  Extend a 1D signal using a given boundary mode.

This function operates like :func:`numpy.pad` but supports all signal
extension modes that can be used by PyWavelets discrete wavelet transforms.

Parameters
----------
x : ndarray
    The array to pad
pad_widths : {sequence, array_like, int}
    Number of values padded to the edges of each axis.
    ``((before_1, after_1), … (before_N, after_N))`` unique pad widths for
    each axis. ``((before, after),)`` yields same before and after pad for
    each axis. ``(pad,)`` or int is a shortcut for
    ``before = after = pad width`` for all axes.
mode : str, optional
    Signal extension mode, see :ref:`Modes <ref-modes>`.

Returns
-------
pad : ndarray
    Padded array of rank equal to array with shape increased according to
    ``pad_widths``.

Notes
-----
The performance of padding in dimensions > 1 may be substantially slower
for modes ``'smooth'`` and ``'antisymmetric'`` as these modes are not
supported efficiently by the underlying :func:`numpy.pad` function.

Note that the behavior of the ``'constant'`` mode here follows the
PyWavelets convention which is different from NumPy (it is equivalent to
``mode='edge'`` in :func:`numpy.pad`).
F)copyr   zpad_widths must be > 0r   )	symmetricreflectr(   )periodicperiodizationrY   edgewrapzeroconstant)r(   constant_valuessmoothc                     XS      nX@US   S-      -
  nU[         R                  " US   SS5      U-  -   U S US   & XS   * S-
     nX`US   * S-
     -
  nU[         R                  " SUS   S-   5      U-  -   XS   * S & U $ )Nr   r   r   )r1   arange)vector	pad_widthiaxiskwargsleft
slope_leftrightslope_rights           r#   
pad_smoothpad.<locals>.pad_smooth  s    A,'D	!q(8!99Jryy1q"5
BB =IaL! aL=1,-E 9Q<-!*;#<<K		!Yq\A%56DD aL=>"Mr$   antisymmetricc                    Uu  pEU R                   U-
  U-
  n[        R                  " XS   US   *  USS9U S S & U nXF-   S-
  nUn	Un
SnXR                   ::  aY  [        US-   [	        US-   U
-   UR                   5      5      nUS-  (       a  X|==   S-  ss'   X-  nUS-  nXR                   ::  a  MY  SnU	S:  a?  [        [        SX-
  5      U	5      nUS-  (       a  X|==   S-  ss'   X-  n	US-  nU	S:  a  M?  U $ )Nr   ra   rU   rW   r   r   )sizer1   r   sliceminmax)rc   rd   re   rf   npad_lnpad_rvsize_nonpadvpr_edgel_edge	seg_widthnsegment_slices                r#   pad_antisymmetricpad.<locals>.pad_antisymmetric  s%    'NF!;;/&8LvlIbM>B({<F1IB*Q.FF$IAGG# %fqj&)&1*y*@"''&J!Lq5%+%#Q GG# AA+ %c!V-?&@& Iq5%+%#Q A+ Mr$   antireflectrV   odd)r(   reflect_typezunsupported mode: z. The supported modes are )r1   
asanyarrayarrayroundrE   intprq   r   broadcast_tor6   tolistr   rangeshaper   modes)x
pad_widthsr(   xpaxedge_pad_widthsrk   r|   s           r#   r   r     s   F 	aA *%J*%,,RWW5,AJ~~!122ffa[9@@BJ''VVA-F IE 
.	.?" */qvv8)62 !"1772;?3)6  8q7AVVA/v Iu 
VVA
AFr Iq 
	VVA/n Im 
		 VVA:.P IO 
	 	@ VVA#45 I 
	VVA	F I  &@NP 	Py8s   .G6)rU   ra   )rU   r   )r   r   )numbersr   numpyr1   _c99_configr   _extensions._dwtr   rL   r   r   r	   r
   r   r&   r   r    r   rP   _extensions._pywtr   r   r   r   _utilsr   r   __all__r   r   r    r$   r#   <module>r      s_      * 3 J J = = / E E *#>0B"IJDNeP0Jf7Jtpr$   