
    !Цi                     v   S r SSKrSSKrSSKJr  SSKJr  SSKrSSKJ	r	J
r
Jr  SSKJr  SSKJrJr  SS	KJrJrJrJrJr  SS
KJrJrJrJr  / SQrS rS%S jrS&S jrS'S jr S(S jr!S r"S)S jr#S r$S*S jr%S r&S r'S r(S r)S+S jr*S,S jr+S)S jr,S r-S-S jr.S-S jr/S,S jr0S  r1 " S! S"5      r2S)S# jr3S$ r4g).zY
Multilevel 1D and 2D Discrete Wavelet Transform
and Inverse Discrete Wavelet Transform.
    N)copy)product   )dwtdwt_coeff_lenidwt)dwt_max_level)ModesWavelet)_fix_coeffsdwt2dwtnidwt2idwtn)	AxisError_as_wavelet_modes_per_axis_wavelets_per_axis)wavedecwaverecwavedec2waverec2wavedecnwaverecncoeffs_to_arrayarray_to_coeffsravel_coeffsunravel_coeffsdwtn_max_levelwavedecn_sizewavedecn_shapes
fswavedecn
fswaverecnFswavedecnResultc           
      x   [         R                  " U 5      (       a  U 4n [         R                  " U5      (       a  U4n[         R                  " [        X5       VVs/ s H  u  p4[	        X45      PM     snn5      nUc  UnU$ US:  a  [        SU-  5      eX%:  a  [        R                  " SU S35        U$ s  snnf )Nr   z2Level value of %d is too low . Minimum level is 0.zLevel value of z@ is too high: all coefficients will experience boundary effects.)npisscalarminzipr	   
ValueErrorwarningswarn)sizesdec_lenslevelsd	max_levels         O/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/pywt/_multilevel.py_check_levelr4      s    	{{5		{{8<E8LM8La+8LMNI} L 
@5HJ 	J		eW %! !	" L Ns   B6
c                 r   [         R                  " U 5      n [        U5      n U R                  U   n[        XQR                  U5      n/ nU n[        U5       H"  n[        XqX$5      u  pyUR                  U	5        M$     UR                  U5        UR                  5         U$ ! [         a    [        S5      ef = f)a9  
Multilevel 1D Discrete Wavelet Transform of data.

Parameters
----------
data: array_like
    Input data
wavelet : Wavelet object or name string
    Wavelet to use
mode : str, optional
    Signal extension mode, see :ref:`Modes <ref-modes>`.
level : int, optional
    Decomposition level (must be >= 0). If level is None (default) then it
    will be calculated using the ``dwt_max_level`` function.
axis: int, optional
    Axis over which to compute the DWT. If not given, the
    last axis is used.

Returns
-------
[cA_n, cD_n, cD_n-1, ..., cD2, cD1] : list
    Ordered list of coefficients arrays
    where ``n`` denotes the level of decomposition. The first element
    (``cA_n``) of the result is approximation coefficients array and the
    following elements (``cD_n`` - ``cD_1``) are details coefficients
    arrays.

Examples
--------
>>> from pywt import wavedec
>>> coeffs = wavedec([1,2,3,4,5,6,7,8], 'db1', level=2)
>>> cA2, cD2, cD1 = coeffs
>>> cD1
array([-0.70710678, -0.70710678, -0.70710678, -0.70710678])
>>> cD2
array([-2., -2.])
>>> cA2
array([  5.,  13.])

!Axis greater than data dimensions)r&   asarrayr   shape
IndexErrorr   r4   dec_lenranger   appendreverse)
datawaveletmoder/   axis
axes_shapecoeffs_listair1   s
             r3   r   r   1   s    R ::dD'"G=ZZ%
 __e<EKA5\1t*1  q  =;<<=s   B   B6c                 ~   [        U [        [        45      (       d  [        S5      e[	        U 5      S:  a  [        S5      e[	        U 5      S:X  a  U S   $ U S   U SS pTU H  nUb7  [        U[
        R                  5      (       d  [        S[        U5       S35      eUbs  Ubp   UR                  U   UR                  U   S-   :X  a   U[        S UR                   5       5         nO,UR                  U   UR                  U   :w  a  [        S	5      e [        XFXU5      nM     U$ ! [         a    [        S
5      ef = f)a  
Multilevel 1D Inverse Discrete Wavelet Transform.

Parameters
----------
coeffs : array_like
    Coefficients list [cAn, cDn, cDn-1, ..., cD2, cD1]
wavelet : Wavelet object or name string
    Wavelet to use
mode : str, optional
    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.

Notes
-----
It may sometimes be desired to run ``waverec`` with some sets of
coefficients omitted.  This can best be done by setting the corresponding
arrays to zero arrays of matching shape and dtype.  Explicitly removing
list entries or setting them to None is not supported.

Specifically, to ignore detail coefficients at level 2, one could do::

    coeffs[-2] = np.zeros_like(coeffs[-2])

Examples
--------
>>> import pywt
>>> coeffs = pywt.wavedec([1,2,3,4,5,6,7,8], 'db1', level=2)
>>> pywt.waverec(coeffs, 'db1')
array([ 1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.])
(Expected sequence of coefficient arrays.r   z7Coefficient list too short (minimum 1 arrays required).r   N$Unexpected detail coefficient type: z. Detail coefficients must be arrays as returned by wavedec. If you are using pywt.array_to_coeffs or pywt.unravel_coeffs, please specify output_format='wavedec'c              3   8   #    U  H  n[        U5      v   M     g 7fNslice.0r0   s     r3   	<genexpr>waverec.<locals>.<genexpr>   s     :'Qa'   zcoefficient shape mismatchz(Axis greater than coefficient dimensions)
isinstancelisttupler*   lenr&   ndarraytyper8   r9   r   r   )coeffsr?   r@   rA   rD   dsr1   s          r3   r   r   p   sN   F ftUm,,CDD
6{QEG 	G	V	ay1Ivabzr=Arzz!:!:6tAwi @* *+ +
 ML774=AGGDMA$55%:!''::;AWWT]aggdm3$%ABB 4 wd+ " H	  L JKKLs   $AD&'+D&&D<c                    [         R                  " U 5      n U R                  S:  a  [        S5      e[	        U5      n[        U5      S:w  a  [        S5      e[        U5      [        [        U5      5      :w  a  [        S5      e U Vs/ s H  oPR                  U   PM     nn[        X5      nU Vs/ s H  oR                  PM     n	n[        XiU5      n/ n
U n[        U5       H"  n[        XX$5      u  pU
R                  U5        M$     U
R                  U5        U
R!                  5         U
$ s  snf ! [         a    [        S5      ef = fs  snf )a  
Multilevel 2D Discrete Wavelet Transform.

Parameters
----------
data : ndarray
    2D input data
wavelet : Wavelet object or name string, or 2-tuple of wavelets
    Wavelet to use.  This can also be a tuple containing a wavelet to
    apply along each axis in ``axes``.
mode : str or 2-tuple of str, optional
    Signal extension mode, see :ref:`Modes <ref-modes>`. This can
    also be a tuple containing a mode to apply along each axis in ``axes``.
level : int, optional
    Decomposition level (must be >= 0). If level is None (default) then it
    will be calculated using the ``dwt_max_level`` function.
axes : 2-tuple of ints, optional
    Axes over which to compute the DWT. Repeated elements are not allowed.

Returns
-------
[cAn, (cHn, cVn, cDn), ... (cH1, cV1, cD1)] : list
    Coefficients list.  For user-specified ``axes``, ``cH*``
    corresponds to ``axes[0]`` while ``cV*`` corresponds to ``axes[1]``.
    The first element returned is the approximation coefficients for the
    nth level of decomposition.  Remaining elements are tuples of detail
    coefficients in descending order of decomposition level.
    (i.e. ``cH1`` are the horizontal detail coefficients at the first
    level)

Examples
--------
>>> import pywt
>>> import numpy as np
>>> coeffs = pywt.wavedec2(np.ones((4,4)), 'db1')
>>> # Levels:
>>> len(coeffs)-1
2
>>> pywt.waverec2(coeffs, 'db1')
array([[ 1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.]])
   z2Expected input data to have at least 2 dimensions.zExpected 2 axesz+The axes passed to wavedec2 must be unique.r6   )r&   r7   ndimr*   rT   rU   setr8   r9   r   r   r:   r4   r;   r   r<   r=   )r>   r?   r@   r/   axesax
axes_sizeswaveletswdec_lengthsrC   rD   rE   rY   s                 r3   r   r      s1   Z ::dDyy1}MNN;D
4yA~*++
4yCD	N"FGG=/34tjjnt
4 "'0H&./h99hK/%8EKA5\Q,2  q' 5 =;<<= 0s$   D1 D, D1 1E
,D1 1Ec                 .  ^	 [        U [        [        45      (       d  [        S5      e[	        U5      [	        [        U5      5      :w  a  [        S5      e[	        U 5      S:  a  [        S5      e[	        U 5      S:X  a  U S   $ U S   U SS pT[        R                  " U5      nU H  n[        U[        [        45      (       a  [	        U5      S:w  a  [        S[        U5       S	35      e[        S
 U 5       5      nS U 5       n [        U5      m	[        U	4S jU 5       5      (       d  [        S5      e[        S [        UR                  T	5       5       5      n[        XH   U4XU5      nM     U$ ! [         a    [        S5      [        S5      4n N9f = f)a_  
Multilevel 2D Inverse Discrete Wavelet Transform.

coeffs : list or tuple
    Coefficients list [cAn, (cHn, cVn, cDn), ... (cH1, cV1, cD1)]
wavelet : Wavelet object or name string, or 2-tuple of wavelets
    Wavelet to use.  This can also be a tuple containing a wavelet to
    apply along each axis in ``axes``.
mode : str or 2-tuple of str, optional
    Signal extension mode, see :ref:`Modes <ref-modes>`. This can
    also be a tuple containing a mode to apply along each axis in ``axes``.
axes : 2-tuple of ints, optional
    Axes over which to compute the IDWT. Repeated elements are not allowed.

Returns
-------
2D array of reconstructed data.

Notes
-----
It may sometimes be desired to run ``waverec2`` with some sets of
coefficients omitted.  This can best be done by setting the corresponding
arrays to zero arrays of matching shape and dtype.  Explicitly removing
list or tuple entries or setting them to None is not supported.

Specifically, to ignore all detail coefficients at level 2, one could do::

    coeffs[-2] == tuple([np.zeros_like(v) for v in coeffs[-2]])

Examples
--------
>>> import pywt
>>> import numpy as np
>>> coeffs = pywt.wavedec2(np.ones((4,4)), 'db1')
>>> # Levels:
>>> len(coeffs)-1
2
>>> pywt.waverec2(coeffs, 'db1')
array([[ 1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.]])
rG   z+The axes passed to waverec2 must be unique.r   6Coefficient list too short (minimum 1 array required).r   N   rH   z. Detail coefficients must be a 3-tuple of arrays as returned by wavedec2. If you are using pywt.array_to_coeffs or pywt.unravel_coeffs, please specify output_format='wavedec2'c              3   X   #    U  H   nUb  [         R                  " U5      OS v   M"     g 7frJ   )r&   r7   rN   coeffs     r3   rO   waverec2.<locals>.<genexpr>C  s*      " e (-'8"**U#dB s   (*c              3   B   #    U  H  oc  M  UR                   v   M     g 7frJ   )r8   rh   s     r3   rO   rj   E  s     DQEKEKKQs   c              3   ,   >#    U  H	  oT:H  v   M     g 7frJ    )rN   r0   d_shapes     r3   rO   rj   K  s     6XG|Xs   z*All detail shapes must be the same length.c              3   R   #    U  H  u  p[        S XS-   :X  a  SOS 5      v   M     g 7f)Nr   rK   )rN   a_lend_lens      r3   rO   rj   M  s/      D-B\U t5AI+=R4HH-Bs   %')rR   rS   rT   r*   rU   r]   r&   r7   rW   nextallr)   r8   StopIterationrL   r   )
rX   r?   r@   r^   rD   rY   r1   d_shapesidxsrn   s
            @r3   r   r      s   X ftUm,,CDD
4yCD	N"FGG
6{QDF 	F	V	ay1Ivabzr


1A!dE]++s1v{6tAwi @: :; ;
  " " "DQD	D8nG 6X666 !MNN D-0'-BD DD17A,t4' * H  	,;d+D	,s   E11 FFc                    [        U 5      S:  a  [        S5      e[        U 5      n[        R                  " U5      (       a  U4nUc  [	        U5      nO[        U5      n[        U5      [        [        U5      5      :w  a  [        S5      e U Vs/ s H  o0U   PM	     nn[        U5      nXU4$ s  snf ! [         a    [        S5      ef = f)Nr   z Expected at least 1D input data.z+The axes passed to wavedecn must be unique.r6   )	rU   r*   r&   r'   r;   rT   r]   r9   r   )r8   r^   r\   r_   axes_shapesndim_transforms         r3   _prep_axes_wavedecnr{   T  s    
5zA~;<<u:D	{{4x|T{T{
4yCD	N"FGG=+/04RRy40 YNn,,	 1 =;<<=s   B3 B.B3 .B3 3C	c                    [         R                  " U 5      n [        U R                  U5      u  pEn[	        X5      nU Vs/ s H  oR
                  PM     n	n[        XYU5      n/ n
U n[        U5       H4  n[        XX$5      nUR                  SU-  5      nU
R                  U5        M6     U
R                  U5        U
R                  5         U
$ s  snf )a8  
Multilevel nD Discrete Wavelet Transform.

Parameters
----------
data : ndarray
    nD input data
wavelet : Wavelet object or name string, or tuple of wavelets
    Wavelet to use.  This can also be a tuple containing a wavelet to
    apply along each axis in ``axes``.
mode : str or tuple of str, optional
    Signal extension mode, see :ref:`Modes <ref-modes>`. This can
    also be a tuple containing a mode to apply along each axis in ``axes``.
level : int, optional
    Decomposition level (must be >= 0). If level is None (default) then it
    will be calculated using the ``dwt_max_level`` function.
axes : sequence of ints, optional
    Axes over which to compute the DWT. Axes may not be repeated. The
    default is None, which means transform all axes
    (``axes = range(data.ndim)``).

Returns
-------
[cAn, {details_level_n}, ... {details_level_1}] : list
    Coefficients list.  Coefficients are listed in descending order of
    decomposition level.  ``cAn`` are the approximation coefficients at
    level ``n``.  Each ``details_level_i`` element is a dictionary
    containing detail coefficients at level ``i`` of the decomposition. As
    a concrete example, a 3D decomposition would have the following set of
    keys in each ``details_level_i`` dictionary::

        {'aad', 'ada', 'daa', 'add', 'dad', 'dda', 'ddd'}

    where the order of the characters in each key map to the specified
    ``axes``.

Examples
--------
>>> import numpy as np
>>> from pywt import wavedecn, waverecn
>>> coeffs = wavedecn(np.ones((4, 4, 4)), 'db1')
>>> # Levels:
>>> len(coeffs)-1
2
>>> waverecn(coeffs, 'db1')
array([[[ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.]],
       [[ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.]],
       [[ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.]],
       [[ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.]]])

rD   )r&   r7   r{   r8   r   r:   r4   r;   r   popr<   r=   )r>   r?   r@   r/   r^   ry   rz   ra   rb   rc   rC   rD   rE   rX   s                 r3   r   r   h  s    @ ::dD(;DJJ(M%D~!'0H&./h99hK/59EKA5\a$-JJs^+,6" 
 q 0s   Cc                 R   U c  g U(       d  U $ U[        [        U5      5         n[        R                  " U R                  UR                  5      n[        R
                  " US:  US:  -  5      (       a  [        U5        [        S5      eU [        S UR                   5       5         $ )Nr   r   z$incompatible coefficient array sizesc              3   8   #    U  H  n[        U5      v   M     g 7frJ   rK   rM   s     r3   rO   $_match_coeff_dims.<locals>.<genexpr>  s     9=aq=rQ   )	rs   iterr&   subtractr8   anyprintr*   rT   )a_coeffd_coeff_dictd_coeff
size_diffss       r3   _match_coeff_dimsr     s     4\ 234GW]]GMM:J	vvzA~*q.122j?@@597==99::    c                    [        U 5      S:  a  [        S5      eU S   U SS pT[        U5      S:  a2  [        S U 5       5      (       d  [        S[        US   5       S35      e[	        [        [        U5      5      nU(       d  U S   $ Uc  [        U5      (       d  [        S5      e/ nUb1  [        R                  " U5      nUR                  UR                  5        U H4  nXgR                  5        VV	s/ s H  u  pU	R                  PM     sn	n-  nM6     [        R                  " U5      n
[        U
5      S:X  a  U
S   nO[        S	5      e[        R                  " U5      (       a  U4nUc  [        U5      nO[!        U5      n[        U5      [        [#        U5      5      :w  a  [        S
5      e[        U5      n[%        U5       H5  u  pUc	  U(       d  M  US:  a  ['        XG5      nXGSU-  '   [)        XqX#5      nM7     U$ s  sn	nf )a  
Multilevel nD Inverse Discrete Wavelet Transform.

coeffs : array_like
    Coefficients list [cAn, {details_level_n}, ... {details_level_1}]
wavelet : Wavelet object or name string, or tuple of wavelets
    Wavelet to use.  This can also be a tuple containing a wavelet to
    apply along each axis in ``axes``.
mode : str or tuple of str, optional
    Signal extension mode, see :ref:`Modes <ref-modes>`. This can
    also be a tuple containing a mode to apply along each axis in ``axes``.
axes : sequence of ints, optional
    Axes over which to compute the IDWT.  Axes may not be repeated.

Returns
-------
nD array of reconstructed data.

Notes
-----
It may sometimes be desired to run ``waverecn`` with some sets of
coefficients omitted.  This can best be done by setting the corresponding
arrays to zero arrays of matching shape and dtype.  Explicitly removing
list or dictionary entries or setting them to None is not supported.

Specifically, to ignore all detail coefficients at level 2, one could do::

    coeffs[-2] = {k: np.zeros_like(v) for k, v in coeffs[-2].items()}

Examples
--------
>>> import numpy as np
>>> from pywt import wavedecn, waverecn
>>> coeffs = wavedecn(np.ones((4, 4, 4)), 'db1')
>>> # Levels:
>>> len(coeffs)-1
2
>>> waverecn(coeffs, 'db1')
array([[[ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.]],
       [[ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.]],
       [[ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.]],
       [[ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.]]])

r   re   r   Nc              3   B   #    U  H  n[        U[        5      v   M     g 7frJ   )rR   dict)rN   r1   s     r3   rO   waverecn.<locals>.<genexpr>  s     ?Bqz!T22B   rH   z. Detail coefficients must be a dictionary of arrays as returned by wavedecn. If you are using pywt.array_to_coeffs or pywt.unravel_coeffs, please specify output_format='wavedecn'z4At least one coefficient must contain a valid value.z:All coefficients must have a matching number of dimensionsz+The axes passed to waverecn must be unique.rD   )rU   r*   rt   rW   rS   mapr   r   r&   r7   r<   r\   itemsuniquer'   r;   rT   r]   	enumerater   r   )rX   r?   r@   r^   rD   rY   coeff_ndimsr1   kvunique_coeff_ndimsr\   rz   idxs                 r3   r   r     s   r 6{QDF 	F 1Ivabzr 2w{3?B???241;- @6 67 	7 
c+r"	#BayyRBD 	D K}JJqM166"7795941955  ;/
!#!!$HJ 	J 
{{4x|T{T{
4yCD	N"FGGYNB-9Q 7!!'A"##
!d)   H? 6s   6H
c                     [        U 5      S:X  a  U $ [        U 5      n [        S[        U 5      5       H/  nX   c  M
  X   R                  S:w  a  [	        S5      eSX   0X'   M1     U $ )z4Convert wavedec coefficients to the wavedecn format.r   r   zexpected a 1D coefficient arrayr1   )rU   r   r;   r\   r*   )rX   ns     r3   _coeffs_wavedec_to_wavedecnr   E  sk    
6{a&\F1c&k"99>>Q>??&)$	 # Mr   c                 ,   [        U 5      S:X  a  U $ [        U 5      n [        S[        U 5      5       H^  n[        X   [        [
        45      (       a  [        X   5      S:w  a  [        S5      eX   u  p#nUb  Ub  Uc  [        S5      eX2US.X'   M`     U $ )z5Convert wavedec2 coefficients to the wavedecn format.r   r   rf   z)expected a 3-tuple of detail coefficientsz\Expected numpy arrays of detail coefficients. Setting coefficients to None is not supported.)addadd)rU   r   r;   rR   rT   rS   r*   )rX   r   r   r   r   s        r3   _coeffs_wavedec2_to_wavedecnr   S  s    
6{a&\F1c&k"&)eT]33s69~7JHIIy:rz9: : r2	 # Mr   c           	         [         R                  " U S   R                  5      n[         R                  " U5      n[        U5      nU S   R                  nU SS   H]  nX!==   [         R                  " USU-     R                  5      U   -  ss'   UR                  5        H  u  pgXGR                  -  nM     M_     [        UR                  5       5      n[         R                  " U5      U:H  nX(4$ )Nr   r   r1   )	r&   r7   r8   rU   sizer   rT   tolistprod)	rX   r^   	arr_shaperz   ncoeffsr1   r   r   is_tight_packings	            r3   _determine_coeff_array_shaper   d  s    

6!9??+I::dDYNQinnGABZ2::aN(:&;&A&AB4HHGGIDAvvG   i&&()I 	*g5&&r   c                    [        U [        5      (       a  [        U 5      S:X  a  [        S5      eU S   c  [        S5      e[        U S   [        R
                  5      (       d  [        S5      eU S   R                  n[        U 5      S:  a|  [        U S   [        5      (       a  Oc[        U S   [        R
                  5      (       a  [        U 5      n O5[        U S   [        [        45      (       a  [        U 5      n O[        S5      e[        U 5      S:X  a  XUS4$ [        [        U S   R                  5       5      S   5      nUc&  X2:  a  [        S5      e[        R                  " U5      n[        U5      U:w  a  [        S	5      eXX#4$ )
zoHelper function to check type of coeffs and axes.

This code is used by both coeffs_to_array and ravel_coeffs.
r   z2input must be a list of coefficients from wavedecnN6coeffs_to_array does not support missing coefficients.z(first list element must be a numpy arrayr   zinvalid coefficient listzlcoeffs corresponds to a DWT performed over only a subset of the axes.  In this case, axes must be specified.zFThe length of axes doesn't match the number of dimensions transformed.)rR   rS   rU   r*   r&   rV   r\   r   r   rT   r   keysarange)rX   r^   r\   rz   s       r3   _prepare_coeffs_axesr   t  so   
 fd##s6{a'7MNNay ) * 	*fQi,,CDD!9>>D
6{QfQi&&q	2::..08Fq	E4=111&9F788
6{aT4'' fQinn./23N| CD D yy
4yN" 	 --r   c           	      ~   [        X5      u  pp4U S   nUR                  n[        U 5      S:X  a  U[        [	        S5      /U-  5      /4$ [        X5      u  pxUc1  U(       d  [        S5      e[        R                  " XuR                  S9n	O[        R                  " XqUR                  S9n	[        U V
s/ s H  n
[	        U
5      PM     sn
5      nXYU'   / nUR                  U5        U SS nU GH;  nUR                  0 5        [        R                  " UR                  5        Vs/ s H  oSL PM     sn5      (       a  [        S5      eUSU-     R                  nU H  nUU   n[	        S5      /U-  n[        U5       Hg  u  nnUU   nUS:X  a  [	        UR                  U   5      UU'   M.  US:X  a'  [	        UU   UU   UR                  U   -   5      UU'   M[  [        S	U 35      e   [        U5      nXU'   UUS
   U'   M     [        U5       Vs/ s H  nUU   UU   -   PM     nnGM>     X4$ s  sn
f s  snf s  snf )aW  
Arrange a wavelet coefficient list from ``wavedecn`` into a single array.

Parameters
----------

coeffs : array-like
    Dictionary of wavelet coefficients as returned by pywt.wavedecn
padding : float or None, optional
    The value to use for the background if the coefficients cannot be
    tightly packed. If None, raise an error if the coefficients cannot be
    tightly packed.
axes : sequence of ints, optional
    Axes over which the DWT that created ``coeffs`` was performed.  The
    default value of None corresponds to all axes.

Returns
-------
coeff_arr : array-like
    Wavelet transform coefficient array.
coeff_slices : list
    List of slices corresponding to each coefficient.  As a 2D example,
    ``coeff_arr[coeff_slices[1]['dd']]`` would extract the first level
    detail coefficients from ``coeff_arr``.

See Also
--------
array_to_coeffs : the inverse of coeffs_to_array

Notes
-----
Assume a 2D coefficient dictionary, c, from a two-level transform.

Then all 2D coefficients will be stacked into a single larger 2D array
as follows::

    +---------------+---------------+-------------------------------+
    |               |               |                               |
    |     c[0]      |  c[1]['da']   |                               |
    |               |               |                               |
    +---------------+---------------+           c[2]['da']          |
    |               |               |                               |
    | c[1]['ad']    |  c[1]['dd']   |                               |
    |               |               |                               |
    +---------------+---------------+ ------------------------------+
    |                               |                               |
    |                               |                               |
    |                               |                               |
    |          c[2]['ad']           |           c[2]['dd']          |
    |                               |                               |
    |                               |                               |
    |                               |                               |
    +-------------------------------+-------------------------------+

If the transform was not performed with mode "periodization" or the signal
length was not a multiple of ``2**level``, coefficients at each subsequent
scale will not be exactly 1/2 the size of those at the previous level due
to additional coefficients retained to handle the boundary condition. In
these cases, the default setting of `padding=0` indicates to pad the
individual coefficient arrays with 0 as needed so that they can be stacked
into a single, contiguous array.

Examples
--------
>>> import pywt
>>> cam = pywt.data.camera()
>>> coeffs = pywt.wavedecn(cam, wavelet='db2', level=3)
>>> arr, coeff_slices = pywt.coeffs_to_array(coeffs)

r   r   Nz+array coefficients cannot be tightly packeddtyper   r1   rD   zunexpected letter: rp   )r   r8   rU   rT   rL   r   r*   r&   emptyr   fullr<   r   valuesr   r;   )rX   paddingr^   r\   rz   a_coeffsa_shaper   r   	coeff_arrr0   a_slicescoeff_slicesrY   
coeff_dictr1   rn   keyslice_arrayrE   letax_ir   s                          r3   r   r     sW   P *>f)K&F$ ayHnnG
6{a%t 45666 #?v"LI JKKHHYnn=	GGIhnnE	01eAh01H"h L! 
B
B66j&7&7&9:&99&9:;; - . .S>1288C3A ;/D0K#C.3Aw#:(-aggdm(<K%CZ(-gdm.5dmaggdm.K)MK% %':3%%@AA )  ,K%&k"$/LS!  5:$K@Kq71:
*K@+ , ""? 1 ;& As   3H0$H5
H:c                    [         R                  " U 5      n / n[        U5      S:X  a  [        S5      eUR	                  XS      5        [        S[        U5      5       H  nUS:X  a  XU   S      nO\US:X  a  XU   S      XU   S      XU   S	      4nO8US
:X  a$  0 nX   R                  5        H  u  pgX   XV'   M     O[        SU 35      eUR	                  U5        M     U$ )a	  
Convert a combined array of coefficients back to a list compatible with
``waverecn``.

Parameters
----------

arr : array-like
    An array containing all wavelet coefficients.  This should have been
    generated via ``coeffs_to_array``.
coeff_slices : list of tuples
    List of slices corresponding to each coefficient as obtained from
    ``array_to_coeffs``.
output_format : {'wavedec', 'wavedec2', 'wavedecn'}
    Make the form of the coefficients compatible with this type of
    multilevel transform.

Returns
-------
coeffs: array-like
    Wavelet transform coefficient array.

See Also
--------
coeffs_to_array : the inverse of array_to_coeffs

Notes
-----
A single large array containing all coefficients will have subsets stored,
into a ``waverecn`` list, c, as indicated below::

    +---------------+---------------+-------------------------------+
    |               |               |                               |
    |     c[0]      |  c[1]['da']   |                               |
    |               |               |                               |
    +---------------+---------------+           c[2]['da']          |
    |               |               |                               |
    | c[1]['ad']    |  c[1]['dd']   |                               |
    |               |               |                               |
    +---------------+---------------+ ------------------------------+
    |                               |                               |
    |                               |                               |
    |                               |                               |
    |          c[2]['ad']           |           c[2]['dd']          |
    |                               |                               |
    |                               |                               |
    |                               |                               |
    +-------------------------------+-------------------------------+

Examples
--------
>>> import pywt
>>> from numpy.testing import assert_array_almost_equal
>>> cam = pywt.data.camera()
>>> coeffs = pywt.wavedecn(cam, wavelet='db2', level=3)
>>> arr, coeff_slices = pywt.coeffs_to_array(coeffs)
>>> coeffs_from_arr = pywt.array_to_coeffs(arr, coeff_slices,
...                                        output_format='wavedecn')
>>> cam_recon = pywt.waverecn(coeffs_from_arr, wavelet='db2')
>>> assert_array_almost_equal(cam, cam_recon)

r    empty list of coefficient slicesr   r   r1   r   r   r   r   r   Unrecognized output format: )r&   r7   rU   r*   r<   r;   r   )arrr   output_formatrX   r   r1   r   r   s           r3   r   r   !  s   ~ **S/CF
<A;<<cq/*+ 1c,'(I%OC()Aj(!_T*+!_T*+!_T*+-A j(A$--/v 0 .}o>@ @a ) Mr   c                    [        X5      u  pEn[        X5      n[        X$5      nU V	s/ s H  oR                  PM     n
n	[	        [        U5      [        U
5      U5      n/ n[        U5       H  n[        S[        U5      S9 Vs/ s H  nSR                  U5      PM     nnU Vs0 s H  o[        U 5      _M     nn[        XGU5       H0  u  nnn[        U U   UR                  US9nU H  nUUU   U'   M     M2     UR                  5        H  u  nn[        U5      UU'   M     UR!                  U5        UR#                  SU-  5      n M     UR!                  U 5        UR%                  5         U$ s  sn	f s  snf s  snf )a  Subband shapes for a multilevel nD discrete wavelet transform.

Parameters
----------
shape : sequence of ints
    The shape of the data to be transformed.
wavelet : Wavelet object or name string, or tuple of wavelets
    Wavelet to use.  This can also be a tuple containing a wavelet to
    apply along each axis in ``axes``.
mode : str or tuple of str, optional
    Signal extension mode, see :ref:`Modes <ref-modes>`. This can
    also be a tuple containing a mode to apply along each axis in ``axes``.
level : int, optional
    Decomposition level (must be >= 0). If level is None (default) then it
    will be calculated using the ``dwt_max_level`` function.
axes : sequence of ints, optional
    Axes over which to compute the DWT. Axes may not be repeated. The
    default is None, which means transform all axes
    (``axes = range(data.ndim)``).

Returns
-------
shapes : [cAn, {details_level_n}, ... {details_level_1}] : list
    Coefficients shape list.  Mirrors the output of ``wavedecn``, except
    it contains only the shapes of the coefficient arrays rather than the
    arrays themselves.

Examples
--------
>>> import pywt
>>> pywt.wavedecn_shapes((64, 32), wavelet='db2', level=3, axes=(0, ))
[(10, 32), {'d': (10, 32)}, {'d': (18, 32)}, {'d': (33, 32)}]
r   )repeat )
filter_lenr@   rD   )r{   r   r   r:   r4   r(   maxr;   r   rU   joinrS   r)   r   r   rT   r<   r}   r=   )r8   r?   r@   r/   r^   ry   rz   ra   modesrb   rc   shapesrE   cdetail_keysr   
new_shapesrA   wavr0   r   s                        r3   r!   r!   z  sa   D )<E(H%D~!'0HD'E&./h99hK/[)3{+;UCEF5\+24D	+JK+Jarwwqz+JK.9:kenk
:"459OD#teDkckkMA &'
1d# !  : $$&DAq!!HJqM 'j!s^34  MM%
NNM% 0 L:s   E0E5%E:c                     S nU" U S   5      nU SS  H4  nUR                  5        H  u  pEUc  [        S5      eX!" U5      -  nM     M6     U$ )a  Compute the total number of wavedecn coefficients.

Parameters
----------
shapes : list of coefficient shapes
    A set of coefficient shapes as returned by ``wavedecn_shapes``.
    Alternatively, the user can specify a set of coefficients as returned
    by ``wavedecn``.

Returns
-------
size : int
    The total number of coefficients.

Examples
--------
>>> import numpy as np
>>> import pywt
>>> data_shape = (64, 32)
>>> shapes = pywt.wavedecn_shapes(data_shape, 'db2', mode='periodization')
>>> pywt.wavedecn_size(shapes)
2048
>>> coeffs = pywt.wavedecn(np.ones(data_shape), 'sym4', mode='symmetric')
>>> pywt.wavedecn_size(coeffs)
3087
c                     [        U [        R                  5      (       a  U R                  $ [        R                  " U 5      $ )z?Size corresponding to ``x`` as either a shape tuple or ndarray.)rR   r&   rV   r   r   )xs    r3   _sizewavedecn_size.<locals>._size  s*    a$$66M771:r   r   r   Nz4Setting coefficient arrays to None is not supported.)r   r*   )r   r   r   r1   r   r   s         r3   r    r      se    6 F1IGABZGGIDAy JL LuQxG	   Nr   c                     [        X5      u  p#n[        X5      n[        X55       VVs/ s H  u  pg[        XgR                  5      PM     nnn[        U5      $ s  snnf )a  Compute the maximum level of decomposition for n-dimensional data.

This returns the maximum number of levels of decomposition suitable for use
with ``wavedec``, ``wavedec2`` or ``wavedecn``.

Parameters
----------
shape : sequence of ints
    Input data shape.
wavelet : Wavelet object or name string, or tuple of wavelets
    Wavelet to use. This can also be a tuple containing a wavelet to
    apply along each axis in ``axes``.
axes : sequence of ints, optional
    Axes over which to compute the DWT. Axes may not be repeated.

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

Notes
-----
The level returned is the smallest ``dwt_max_level`` over all axes.

Examples
--------
>>> import pywt
>>> pywt.dwtn_max_level((64, 32), 'db2')
3
)r{   r   r)   r	   r:   r(   )	r8   r?   r^   ry   rz   ra   r   r   
max_levelss	            r3   r   r     sa    @ )<E(H%D~ "'0H !$K :< :fa  ;;/ :  <z?<s   !Ac                    [        X5      u  pp#U S   nUR                  n[        U 5      S:X  a(  UR                  5       [	        U5      /UR
                  /4$ [        U 5      n[        R                  " U4UR                  S9n[	        U5      nUR                  5       Xx'   / n	/ n
U	R                  U5        U
R                  U S   R
                  5        U SS nUnU H  nU	R                  0 5        U
R                  0 5        [        R                  " UR                  5        Vs/ s H  oSL PM     sn5      (       a  [        S5      e[        UR                  5       5      nU H[  nUU   n[	        XUR                  -   5      nXR                  -  nUR                  5       UU'   UU	S   U'   UR
                  U
S   U'   M]     M     XyU
4$ s  snf )a7  Ravel a set of multilevel wavelet coefficients into a single 1D array.

Parameters
----------
coeffs : array-like
    A list of multilevel wavelet coefficients as returned by
    ``wavedec``, ``wavedec2`` or ``wavedecn``. This function is also
    compatible with the output of ``swt``, ``swt2`` and ``swtn`` if those
    functions were called with ``trim_approx=True``.
axes : sequence of ints, optional
    Axes over which the DWT that created ``coeffs`` was performed. The
    default value of None corresponds to all axes.

Returns
-------
coeff_arr : array-like
    Wavelet transform coefficient array. All coefficients have been
    concatenated into a single array.
coeff_slices : list
    List of slices corresponding to each coefficient. As a 2D example,
    ``coeff_arr[coeff_slices[1]['dd']]`` would extract the first level
    detail coefficients from ``coeff_arr``.
coeff_shapes : list
    List of shapes corresponding to each coefficient. For example, in 2D,
    ``coeff_shapes[1]['dd']`` would contain the original shape of the first
    level detail coefficients array.

See Also
--------
unravel_coeffs : the inverse of ravel_coeffs

Examples
--------
>>> import pywt
>>> cam = pywt.data.camera()
>>> coeffs = pywt.wavedecn(cam, wavelet='db2', level=3)
>>> arr, coeff_slices, coeff_shapes = pywt.ravel_coeffs(coeffs)

r   r   r   Nr   rp   )r   r   rU   ravelrL   r8   r    r&   r   r   r<   r   r   r*   sortedr   )rX   r^   r\   rz   r   a_sizearr_sizer   a_slicer   coeff_shapesrY   offsetr   r1   r   r   sls                     r3   r   r   
  s   P *>f)K&F$ ayH]]F
6{a~~%-!2X^^4FFF V$H(X^^<IFmG!)I LL q	( 
BF
BB66j&7&7&9:&99&9:;; - . . joo'(C3Av/BffFGGIIbM$&LS!$%GGLS!    L00 ;s   "G
c                    [         R                  " U 5      n / n[        U5      S:X  a  [        S5      e[        U5      S:X  a  [        S5      e[        U5      [        U5      :w  a  [        S5      eUR	                  XS      R                  US   5      5        [        S[        U5      5       H  nX   nX%   nUS;   a  XS      R                  US   5      nOUS;   aK  XS	      R                  US	   5      XS
      R                  US
   5      XS      R                  US   5      4nOIUS;   a5  0 nX   R                  5        H  u  pX
   R                  Xy   5      X'   M     O[        SU 35      eUR	                  U5        M     U$ )a  Unravel a raveled array of multilevel wavelet coefficients.

Parameters
----------
arr : array-like
    An array containing all wavelet coefficients. This should have been
    generated by applying ``ravel_coeffs`` to the output of ``wavedec``,
    ``wavedec2`` or ``wavedecn`` (or via ``swt``, ``swt2`` or ``swtn``
    with ``trim_approx=True``).
coeff_slices : list of tuples
    List of slices corresponding to each coefficient as obtained from
    ``ravel_coeffs``.
coeff_shapes : list of tuples
    List of shapes corresponding to each coefficient as obtained from
    ``ravel_coeffs``.
output_format : {'wavedec', 'wavedec2', 'wavedecn', 'swt', 'swt2', 'swtn'}, optional
    Make the form of the unraveled coefficients compatible with this type
    of multilevel transform. The default is ``'wavedecn'``.

Returns
-------
coeffs: list
    List of wavelet transform coefficients. The specific format of the list
    elements is determined by ``output_format``.

See Also
--------
ravel_coeffs : the inverse of unravel_coeffs

Examples
--------
>>> import pywt
>>> from numpy.testing import assert_array_almost_equal
>>> cam = pywt.data.camera()
>>> coeffs = pywt.wavedecn(cam, wavelet='db2', level=3)
>>> arr, coeff_slices, coeff_shapes = pywt.ravel_coeffs(coeffs)
>>> coeffs_from_arr = pywt.unravel_coeffs(arr, coeff_slices, coeff_shapes,
...                                       output_format='wavedecn')
>>> cam_recon = pywt.waverecn(coeffs_from_arr, wavelet='db2')
>>> assert_array_almost_equal(cam, cam_recon)

r   r   z empty list of coefficient shapesz1coeff_shapes and coeff_slices have unequal lengthr   )r   swtr1   )r   swt2r   r   r   )r   swtnr   )r&   r7   rU   r*   r<   reshaper;   r   )r   r   r   r   rX   r   
slice_dict
shape_dictr1   r   r   s              r3   r   r   _  s   V **S/CF
<A;<<	\	a	;<<	\	c,/	/LMMcq/*22<?CD 1c,'(!_
!_
..sO$,,Z_=A22%&..z$/?@%&..z$/?@%&..z$/?@BA 22A$--/v~~jm4 0 .}o>@ @a! )" Mr   c                     [        U5      [        [        U5      5      :w  a  [        S5      e U Vs/ s H  o R                  U   PM       ngs  snf ! [         a    [        S5      ef = f)z-Axes checks common to fswavedecn, fswaverecn.z-The axes passed to fswavedecn must be unique.r6   N)rU   r]   r   r8   r9   )r>   r^   r_   s      r3   _check_fswavedecn_axesr     s]    
4yCD	N"GHH="&'$BB$'' =;<<=s   A A
A A A(c                   $   \ rS rSrSrS r\S 5       r\R                  S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       r\S
 5       r\S 5       r\S 5       r\S 5       rS r\S 5       r\R                  S 5       rS rS rS rS rSrg)r$   i  a/  Object representing fully separable wavelet transform coefficients.

Parameters
----------
coeffs : ndarray
    The coefficient array.
coeff_slices : list
    List of slices corresponding to each detail or approximation
    coefficient array.
wavelets : list of pywt.DiscreteWavelet objects
    The wavelets used.  Will be a list with length equal to
    ``len(axes)``.
mode_enums : list of int
    The border modes used.  Will be a list with length equal to
    ``len(axes)``.
axes : tuple of int
    The set of axes over which the transform was performed.

c                     Xl         X l        XPl        [        R                  " S U 5       5      (       d  [        S5      eX0l        [        R                  " S U 5       5      (       d  [        S5      eX@l        g )Nc              3   B   #    U  H  n[        U[        5      v   M     g 7frJ   )rR   r   )rN   rb   s     r3   rO   ,FswavedecnResult.__init__.<locals>.<genexpr>  s     ?hjG,,hr   z*wavelets must contain pywt.Wavelet objectsc              3   B   #    U  H  n[        U[        5      v   M     g 7frJ   )rR   int)rN   ms     r3   rO   r     s     =*QjC((*r   zmode_enums must be integers)_coeffs_coeff_slices_axesr&   rt   r*   	_wavelets_mode_enums)selfrX   r   ra   
mode_enumsr^   s         r3   __init__FswavedecnResult.__init__  sg    )
vv?h???<> >!vv=*===-/ /%r   c                     U R                   $ )z6ndarray: All coefficients stacked into a single array.)r   r   s    r3   rX   FswavedecnResult.coeffs  s     ||r   c                 n    UR                   U R                  R                   :w  a  [        S5      eXl        g )Nz?new coefficient array must match the existing coefficient shape)r8   r   r*   )r   r   s     r3   rX   r     s/    77dll((( 1 2 2r   c                     U R                   $ )z!List: List of coefficient slices.)r   r   s    r3   r   FswavedecnResult.coeff_slices  s     !!!r   c                 .    U R                   R                  $ )zint: Number of data dimensions.)rX   r\   r   s    r3   r\   FswavedecnResult.ndim  s     {{r   c                 ,    [        U R                  5      $ )z int: Number of axes transformed.)rU   r^   r   s    r3   rz   FswavedecnResult.ndim_transform  s     499~r   c                     U R                   $ )z8List of str: The axes the transform was performed along.)r   r   s    r3   r^   FswavedecnResult.axes  s     zzr   c                 ^    U R                    Vs/ s H  n[        U5      S-
  PM     sn$ s  snf )zAList of int: Levels of decomposition along each transformed axis.r   )r   rU   )r   r0   s     r3   levelsFswavedecnResult.levels  s,     %)$5$56$5qA
$5666s   *c                     U R                   $ z@List of pywt.DiscreteWavelet: wavelet for each transformed axis.)r   r   s    r3   ra   FswavedecnResult.wavelets  s     ~~r   c                 X    U R                    Vs/ s H  oR                  PM     sn$ s  snf r	  )r   name)r   rb   s     r3   wavelet_namesFswavedecnResult.wavelet_names   s"     !%/1///s   'c                     [         R                   Vs0 s H  n[        [         U5      U_M     nnU R                   Vs/ s H  o2U   PM	     sn$ s  snf s  snf )z>List of str: The border mode used along each transformed axis.)r
   r   getattrr   )r   r@   
names_dictr   s       r3   r   FswavedecnResult.modes  s[     #(++/"-$ eT*D0"- 	 /'+'7'78'7!1'788/8s
   AAc                     [        S 5      /U R                  -  n[        [        U R                  U5      5       H  u  nu  pEU R
                  U   U   X$'   M     [        U5      $ rJ   )rL   r\   r   r)   r^   r   rT   )r   r  r   r   r_   levs         r3   _get_coef_slFswavedecnResult._get_coef_sl  sW    Dk_tyy(%c$))V&<=LAy&&q)#.BF >Ryr   c                 \    U R                  SU R                  -  5      nU R                  U   $ )z(ndarray: The approximation coefficients.r   )r  r\   r   )r   r   s     r3   approxFswavedecnResult.approx  s+     uTYY/||Br   c                     U R                  SU R                  -  5      nU R                  U   R                  UR                  :w  a  [	        S5      eXR                  U'   g )Nr  7x does not match the shape of the requested coefficient)r  r\   r   r8   r*   )r   rD   r   s      r3   r  r    sS    uTYY/<<!!QWW,IK KRr   c           	         [        U5      n[        U5      [        U R                  5      :w  a  [        S5      e[        R
                  " U Vs/ s H  n[        U[        R                  5      PM     sn5      (       ac  [        R                  " [        R                  " U5      S-  S:  5      (       d.  [        R                  " U Vs/ s H  o"S:  PM	     sn5      (       a  [        S5      e[        U Vs/ s H  n[        U5      PM     sn5      n[        R                  " [        XR                  5       VVs/ s H	  u  p#X#:  PM     snn5      (       a  [        S5      eg s  snf s  snf s  snf s  snnf )Nz0levels must match the number of transformed axesr   r   z.Index must be a tuple of non-negative integersz8Specified indices exceed the number of transform levels.)rT   rU   r^   r*   r&   rt   rR   numbersNumberr   r7   r   r)   r  )r   r  r  maxlevs       r3   _validate_index FswavedecnResult._validate_index   s"   vv;#dii.(BD D 6J6C
376JKKrzz&)A-122626Ca6233MNNF3FSCF34 663v{{3KL3KKC3<3KLMMJL L N K2 4 Ms   $E!E&4E+8E0
c                 d    U R                  U5        U R                  U5      nU R                  U   $ )zRetrieve a coefficient subband.

Parameters
----------
levels : tuple of int
    The number of degrees of decomposition along each transformed
    axis.
)r!  r  r   )r   r  r   s      r3   __getitem__FswavedecnResult.__getitem__4  s1     	V$v&||Br   c                 L   U R                  U5        U R                  U5      nU R                  U   R                  nU R                  U   R                  UR                  :w  a  [        S5      eUR                  U:w  a  [        R                  " SU 35        X R                  U'   g)a  Assign values to a coefficient subband.

Parameters
----------
levels : tuple of int
    The number of degrees of decomposition along each transformed
    axis.
x : ndarray
    The data corresponding to assign. It must match the expected
    shape and dtype of the specified subband.
r  z7dtype mismatch:  converting the provided array todtype N)r!  r  r   r   r8   r*   r+   r,   )r   r  r   r   current_dtypes        r3   __setitem__FswavedecnResult.__setitem__A  s     	V$v&R(..<<!!QWW,IK K77m#MM ##0/3 4Rr   c                     [        [        S U R                   5       6 5      nUR                  S[	        U R
                  5      -  5        [        U5      $ )z{Return a list of all detail coefficient keys.

Returns
-------
keys : list of str
    List of all detail coefficient keys.
c              3   >   #    U  H  n[        US -   5      v   M     g7f)r   N)r;   )rN   ls     r3   rO   /FswavedecnResult.detail_keys.<locals>.<genexpr>`  s     >+QeAaCjj+s   r  )rS   r   r  removerU   r^   r   )r   r   s     r3   r   FswavedecnResult.detail_keysX  s@     G>$++>?@E#dii.()d|r   )r   r   r   r   r   N)__name__
__module____qualname____firstlineno____doc__r   propertyrX   setterr   r\   rz   r^   r  ra   r  r   r  r  r!  r$  r(  r   __static_attributes__rm   r   r3   r$   r$     s   &&   ]]  " "         7 7   0 0 9 9    
 ]] L( .
r   r$   c           
      0   [         R                  " U 5      n Uc)  [        [         R                  " U R                  5      5      n[        X5        Ub  [         R                  " U5      (       a  U/[        U5      -  n[        U5      [        U5      :w  a  [        S5      e[        X$5      n[        X5      n[        S5      /[        U5      -  nU n[        [        XCXe5      5       H  u  n	u  pp[        XX+U
S9nU Vs/ s H  oR                  U
   PM     nn[         R                   " S/U-   5      n[#        [        U5      5       Vs/ s H  n[        UU   UUS-      5      PM     snXy'   [         R$                  " XS9nM     ['        XXeU5      $ s  snf s  snf )a+  Fully Separable Wavelet Decomposition.

This is a variant of the multilevel discrete wavelet transform where all
levels of decomposition are performed along a single axis prior to moving
onto the next axis.  Unlike in ``wavedecn``, the number of levels of
decomposition are not required to be the same along each axis which can be
a benefit for anisotropic data.

Parameters
----------
data: array_like
    Input data
wavelet : Wavelet object or name string, or tuple of wavelets
    Wavelet to use.  This can also be a tuple containing a wavelet to
    apply along each axis in ``axes``.
mode : str or tuple of str, optional
    Signal extension mode, see :ref:`Modes <ref-modes>`. This can
    also be a tuple containing a mode to apply along each axis in ``axes``.
levels : int or sequence of ints, optional
    Decomposition levels along each axis (must be >= 0). If an integer is
    provided, the same number of levels are used for all axes. If
    ``levels`` is None (default), ``dwt_max_level`` will be used to compute
    the maximum number of levels possible for each axis.
axes : sequence of ints, optional
    Axes over which to compute the transform. Axes may not be repeated. The
    default is to transform along all axes.

Returns
-------
fswavedecn_result : FswavedecnResult object
    Contains the wavelet coefficients, slice objects to allow obtaining
    the coefficients per detail or approximation level, and more.
    See ``FswavedecnResult`` for details.

Examples
--------
>>> import numpy as np
>>> from pywt import fswavedecn
>>> fs_result = fswavedecn(np.ones((32, 32)), 'sym2', levels=(1, 3))
>>> print(fs_result.detail_keys())
[(0, 1), (0, 2), (0, 3), (1, 0), (1, 1), (1, 2), (1, 3)]
>>> approx_coeffs = fs_result.approx
>>> detail_1_2 = fs_result[(1, 2)]


Notes
-----
This transformation has been variously referred to as the (fully) separable
wavelet transform (e.g. refs [1]_, [3]_), the tensor-product wavelet
([2]_) or the hyperbolic wavelet transform ([4]_).  It is well suited to
data with anisotropic smoothness.

In [2]_ it was demonstrated that fully separable transform performs at
least as well as the DWT for image compression.  Computation time is a
factor 2 larger than that for the DWT.

See Also
--------
fswaverecn : inverse of fswavedecn

References
----------
.. [1] PH Westerink. Subband Coding of Images. Ph.D. dissertation, Dept.
   Elect. Eng., Inf. Theory Group, Delft Univ. Technol., Delft, The
   Netherlands, 1989.  (see Section 2.3)
   http://resolver.tudelft.nl/uuid:a4d195c3-1f89-4d66-913d-db9af0969509

.. [2] CP Rosiene and TQ Nguyen. Tensor-product wavelet vs. Mallat
   decomposition: A comparative analysis, in Proc. IEEE Int. Symp.
   Circuits and Systems, Orlando, FL, Jun. 1999, pp. 431-434.

.. [3] V Velisavljevic, B Beferull-Lozano, M Vetterli and PL Dragotti.
   Directionlets: Anisotropic Multidirectional Representation With
   Separable Filtering. IEEE Transactions on Image Processing, Vol. 15,
   No. 7, July 2006.

.. [4] RA DeVore, SV Konyagin and VN Temlyakov. "Hyperbolic wavelet
   approximation," Constr. Approx. 14 (1998), 1-26.
Nz-levels must match the length of the axes list)r@   r/   rA   r   r   )rA   )r&   r7   rT   r   r\   r   r'   rU   r*   r   r   rL   r   r)   r   r8   cumsumr;   concatenater$   )r>   r?   r@   r  r^   r   ra   r   
coeffs_arrax_countr_   r  r   rX   r   c_shapes	c_offsetsr1   s                     r3   r"   r"   e  sl   ` ::dD|RYYtyy)*4&~V,,c$i'
6{c$iHIID'E!'0H$K?SY.LJ*3h.+0&&2CtRH
 *00AGGBK0IIqeh./	9>s8}9M"O9MAE)A,	!A#/9M"O ^^F4
+0 JhtLL 1"Os   ;FFc                    U R                   nU R                  nU R                  nU R                  nU R                  n[        X5        [        U5      [        U5      :w  a  [        S5      eUn[        S5      /UR                  -  n[        [        X5U5      5       HN  u  nu  pn/ nX(    H$  nXU	'   UR                  U[        U5         5        M&     [        S5      Xy'   [        XXS9nMP     U$ )a!  Fully Separable Inverse Wavelet Reconstruction.

Parameters
----------
fswavedecn_result : FswavedecnResult object
    FswavedecnResult object from ``fswavedecn``.

Returns
-------
reconstructed : ndarray
    Array of reconstructed data.

Notes
-----
This transformation has been variously referred to as the (fully) separable
wavelet transform (e.g. refs [1]_, [3]_), the tensor-product wavelet
([2]_) or the hyperbolic wavelet transform ([4]_).  It is well suited to
data with anisotropic smoothness.

In [2]_ it was demonstrated that the fully separable transform performs at
least as well as the DWT for image compression. Computation time is a
factor 2 larger than that for the DWT.

See Also
--------
fswavedecn : inverse of fswaverecn

References
----------
.. [1] PH Westerink. Subband Coding of Images. Ph.D. dissertation, Dept.
   Elect. Eng., Inf. Theory Group, Delft Univ. Technol., Delft, The
   Netherlands, 1989.  (see Section 2.3)
   http://resolver.tudelft.nl/uuid:a4d195c3-1f89-4d66-913d-db9af0969509

.. [2] CP Rosiene and TQ Nguyen. Tensor-product wavelet vs. Mallat
   decomposition: A comparative analysis, in Proc. IEEE Int. Symp.
   Circuits and Systems, Orlando, FL, Jun. 1999, pp. 431-434.

.. [3] V Velisavljevic, B Beferull-Lozano, M Vetterli and PL Dragotti.
   Directionlets: Anisotropic Multidirectional Representation With
   Separable Filtering. IEEE Transactions on Image Processing, Vol. 15,
   No. 7, July 2006.

.. [4] RA DeVore, SV Konyagin and VN Temlyakov. "Hyperbolic wavelet
   approximation," Constr. Approx. 14 (1998), 1-26.
zdimension mismatchN)r@   rA   )rX   r   r^   r   ra   r   rU   r*   rL   r\   r   r)   r<   rT   r   )fswavedecn_resultr;  r   r^   r   ra   r   cslr<  r_   r   r@   rX   r   s                 r3   r#   r#     s    ^ #))J$11L!!D##E ))H:,
4yC%%-..
C;/CHH
$C &/s45/I%J!/2D(BGMM#eCj/* ) +f6 &K Jr   )	symmetricNrp   )rB  rp   )rB  Nrp   )rB  rC  )rB  NN)rB  N)r   N)r   rJ   )5r4  r  r+   r   	itertoolsr   numpyr&   _dwtr   r   r   _extensions._dwtr	   _extensions._pywtr
   r   	_multidimr   r   r   r   r   _utilsr   r   r   r   __all__r4   r   r   r   r   r{   r   r   r   r   r   r   r   r   r   r!   r    r   r   r   r   r$   r"   r#   rm   r   r3   <module>rM     s         * * + - < < O ON$<~@FJZQh-(Rj; up"' +.\|#~Vr7t(V(VR1jHV=n nbnMbDr   