
    bMh|                         d dl Z d dlmZ d dlZddlmZ ddlmZ ddl	m
Z
mZmZ ddlmZ ddlmZ dd	lmZ dd
lmZmZ ddlmZmZmZ g dZd Z	 	 ddZddZ	 	 ddZddZ	 	 ddZddZ dS )    N)product   )_have_c99_complex)idwt_single)ModesWavelet_check_dtype)swt)swt_axis)swt_max_level)idwt2idwtn)	AxisError_as_wavelet_wavelets_per_axis)r
   r   iswtswt2iswt2swtniswtnc                     t          | j        dz   fd| j        D                       }| j        |_        | j        |_        |S )Nrc                 >    g | ]}t          j        |          z  S  )npasarray).0fsfs     I/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pywt/_swt.py
<listcomp>z/_rescale_wavelet_filterbank.<locals>.<listcomp>   s&    CCC!2:a==2%CCC    )r   namefilter_bank
orthogonalbiorthogonal)waveletr   wavs    ` r    _rescale_wavelet_filterbankr)      sS    
',$CCCCw/BCCCE EC 'CN+CJr"   Fc                 n   t           st          j        |           rt          j        |           } ||||||d}t	          | j        fi |}t	          | j        fi |}	|sBg }
t          ||	          D ].\  \  }}\  }}|
                    |d|z  z   |d|z  z   f           /nd t          ||	          D             }
|
S t          |           }t          j
        | |          } t          |          }|r@|j        st          j        d           t          |dt          j        d          z            }|dk     r
|| j        z   }d|cxk    r| j        k     sn t%          d	          |t'          | j        |                   }| j        dk    rt+          | ||||          }nt-          | |||||          }|S )
ah  
    Multilevel 1D stationary wavelet transform.

    Parameters
    ----------
    data :
        Input signal
    wavelet :
        Wavelet to use (Wavelet object or name)
    level : int, optional
        The number of decomposition steps to perform.
    start_level : int, optional
        The level at which the decomposition will begin (it allows one to
        skip a given number of transform steps and compute
        coefficients starting from start_level) (default: 0)
    axis: int, optional
        Axis over which to compute the SWT. If not given, the
        last axis is used.
    trim_approx : bool, optional
        If True, approximation coefficients at the final level are retained.
    norm : bool, optional
        If True, transform is normalized so that the energy of the coefficients
        will be equal to the energy of ``data``. In other words,
        ``np.linalg.norm(data.ravel())`` will equal the norm of the
        concatenated transform coefficients when ``trim_approx`` is True.

    Returns
    -------
    coeffs : list
        List of approximation and details coefficients pairs in order
        similar to wavedec function::

            [(cAn, cDn), ..., (cA2, cD2), (cA1, cD1)]

        where n equals input parameter ``level``.

        If ``start_level = m`` is given, then the beginning m steps are
        skipped::

            [(cAm+n, cDm+n), ..., (cAm+1, cDm+1), (cAm, cDm)]

        If ``trim_approx`` is ``True``, then the output list is exactly as in
        ``pywt.wavedec``, where the first coefficient in the list is the
        approximation coefficient at the final level and the rest are the
        detail coefficients::

            [cAn, cDn, ..., cD2, cD1]

    Notes
    -----
    The implementation here follows the "algorithm a-trous" and requires that
    the signal length along the transformed axis be a multiple of ``2**level``.
    If this is not the case, the user should pad up to an appropriate size
    using a function such as ``numpy.pad``.

    A primary benefit of this transform in comparison to its decimated
    counterpart (``pywt.wavedecn``), is that it is shift-invariant. This comes
    at cost of redundancy in the transform (the size of the output coefficients
    is larger than the input).

    When the following three conditions are true:

        1. The wavelet is orthogonal
        2. ``swt`` is called with ``norm=True``
        3. ``swt`` is called with ``trim_approx=True``

    the transform has the following additional properties that may be
    desirable in applications:

        1. energy is conserved
        2. variance is partitioned across scales

    When used with ``norm=True``, this transform is closely related to the
    multiple-overlap DWT (MODWT) as popularized for time-series analysis,
    although the underlying implementation is slightly different from the one
    published in [1]_. Specifically, the implementation used here requires a
    signal that is a multiple of ``2**level`` in length.

    References
    ----------
    .. [1] DB Percival and AT Walden. Wavelet Methods for Time Series Analysis.
        Cambridge University Press, 2000.
    )r'   levelstart_leveltrim_approxaxisnorm              ?c                 $    g | ]\  }}|d |z  z   S r1   r   )r   crcis      r    r!   zswt.<locals>.<listcomp>}   s:     J J J'B 2: J J Jr"   dtypezinorm=True, but the wavelet is not orthogonal: 
	The conditions for energy preservation are not satisfied.r      r   !Axis greater than data dimensions)r   r   iscomplexobjr   r
   realimagzipappendr	   arrayr   r%   warningswarnr)   sqrtndimr   r   shape_swt	_swt_axis)datar'   r,   r-   r/   r.   r0   kwargscoeffs_realcoeffs_imagcoeffs_cplxcA_rcD_rcA_icD_idtrets                    r    r
   r
      s-   l  !6!6 z$$u[%0$N N$)..v..$)..v.. 	JK.1+{.K.K E E*tltT""D2d7ND2d7N#CDDDDEJ J+.{K+H+HJ J JK 
d		B8D###D'""G E! 	OMNO O O .gq|DDaxxdi    ty    ;<<<}dj.//yA~~4%kBBguk4MMJr"   c                    t          | d         t          t          f           }|r| d         n| d         d         }|j        dk    r;|r|gd | dd         D             z   }nd | D             }t	          |||f|          S |dk    r|dk    rt          d          t          slt          j        |          rX|rd	 | D             }d
 | D             }nd | D             }d | D             }||d}	t          |fi |	}
|
dt          |fi |	z  z   S |r
| dd         } |j        dk    rt          d          t          |          }t          j        ||d          }t          |           }t          |          }|r"t          |t          j        d                    }t#          j        d          }t'          |dd          D ]|}t)          t+          d|dz
                      }|}|r
| |          }n| |          \  }}t          j        |t          |                    }|j        |j        k    re|j        j        dk    s|j        j        dk    rt          j        }nt          j        }t          j        ||          }t          j        ||          }t'          |          D ]}t          j        |t          |          |          }|ddd         }|ddd         }t9          ||         ||         ||          }t9          ||         ||         ||          }t          j        |d          }||z   dz  ||<   ~|S )aq  
    Multilevel 1D inverse discrete stationary wavelet transform.

    Parameters
    ----------
    coeffs : array_like
        Coefficients list of tuples::

            [(cAn, cDn), ..., (cA2, cD2), (cA1, cD1)]

        where cA is approximation, cD is details.  Index 1 corresponds to
        ``start_level`` from ``pywt.swt``.
    wavelet : Wavelet object or name string
        Wavelet to use
    norm : bool, optional
        Controls the normalization used by the inverse transform. This must
        be set equal to the value that was used by ``pywt.swt`` to preserve the
        energy of a round-trip transform.

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

    Examples
    --------
    >>> import pywt
    >>> coeffs = pywt.swt([1,2,3,4,5,6,7,8], 'db2', level=2)
    >>> pywt.iswt(coeffs, 'db2')
    array([ 1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.])
    r   r   c                     g | ]}d |iS )dr   )r   rT   s     r    r!   ziswt.<locals>.<listcomp>   s    ===Qa===r"   Nc                     g | ]
\  }}||d S ))arT   r   )r   rV   rT   s      r    r!   ziswt.<locals>.<listcomp>   s$    ===daqq))===r"   axesr0   r*   r9   c                     g | ]	}|j         
S r   r;   r   cs     r    r!   ziswt.<locals>.<listcomp>       222a16222r"   c                     g | ]	}|j         
S r   r<   r[   s     r    r!   ziswt.<locals>.<listcomp>   r]   r"   c                 0    g | ]\  }}|j         |j         fS r   rZ   r   cacds      r    r!   ziswt.<locals>.<listcomp>   %    CCC&"bBGRW-CCCr"   c                 0    g | ]\  }}|j         |j         fS r   r_   ra   s      r    r!   ziswt.<locals>.<listcomp>   rd   r"   r'   r0   r1   ziswt only supports 1D dataTr7   copyr8   periodizationr6   r\   g       @)
isinstancetuplelistrC   r   r   r   r   r:   r   
ValueErrorr	   r?   lenr   r)   rB   r   from_objectrangeintpowr   r7   kind
complex128float64aranger   roll)coeffsr'   r0   r/   r.   cA	coeffs_ndrI   rJ   rH   yrP   output
num_levelsmodej	step_size
last_indexcD_r7   firstindiceseven_indicesodd_indicesx1x2s                              r    r   r      s   B !UDM:::K!	3vay|B	w{{ 	>==&*====II==f===IYtgDAAAA	trzz;<<< 	4!4!4 	4 	D226222K226222KKCCFCCCKCCFCCCK$d33''''2[33F33333 	w!||5666	b		BXb...F VJ'""G C-grwqzzBB_--D:q"%% )+ )+Aqs$$	
 	BBA2JEArZ,r"2"23338v|##| C''28=C+?+?
Ze444FBe,,,B:&& 	+ 	+E is2ww	::G #14a4=L!!$Q$-K VL1-$d, ,B VK0_$d, ,B
 QB  "BwlF7OO3	+6 Mr"   r*   c           	         t          |          }t          j        |           } t          |          dk    rt	          d          t          |          t          t          |                    k    rt	          d          | j        t          t          j        |                    k     rt	          d          t          | ||||||          }g }|r%|	                    |d                    |dd         }|D ]a}	|r+|	                    |	d         |	d	         |	d
         f           /|	                    |	d         |	d         |	d	         |	d
         ff           b|S )a  
    Multilevel 2D stationary wavelet transform.

    Parameters
    ----------
    data : array_like
        2D array with input data
    wavelet : Wavelet object or name string, or 2-tuple of wavelets
        Wavelet to use.  This can also be a tuple of wavelets to apply per
        axis in ``axes``.
    level : int
        The number of decomposition steps to perform.
    start_level : int, optional
        The level at which the decomposition will start (default: 0)
    axes : 2-tuple of ints, optional
        Axes over which to compute the SWT. Repeated elements are not allowed.
    trim_approx : bool, optional
        If True, approximation coefficients at the final level are retained.
    norm : bool, optional
        If True, transform is normalized so that the energy of the coefficients
        will be equal to the energy of ``data``. In other words,
        ``np.linalg.norm(data.ravel())`` will equal the norm of the
        concatenated transform coefficients when ``trim_approx`` is True.

    Returns
    -------
    coeffs : list
        Approximation and details coefficients (for ``start_level = m``).
        If ``trim_approx`` is ``False``, approximation coefficients are
        retained for all levels::

            [
                (cA_m+level,
                    (cH_m+level, cV_m+level, cD_m+level)
                ),
                ...,
                (cA_m+1,
                    (cH_m+1, cV_m+1, cD_m+1)
                ),
                (cA_m,
                    (cH_m, cV_m, cD_m)
                )
            ]

        where cA is approximation, cH is horizontal details, cV is
        vertical details, cD is diagonal details and m is ``start_level``.

        If ``trim_approx`` is ``True``, approximation coefficients are only
        retained at the final level of decomposition. This matches the format
        used by ``pywt.wavedec2``::

            [
                cA_m+level,
                (cH_m+level, cV_m+level, cD_m+level),
                ...,
                (cH_m+1, cV_m+1, cD_m+1),
                (cH_m, cV_m, cD_m),
            ]

    Notes
    -----
    The implementation here follows the "algorithm a-trous" and requires that
    the signal length along the transformed axes be a multiple of ``2**level``.
    If this is not the case, the user should pad up to an appropriate size
    using a function such as ``numpy.pad``.

    A primary benefit of this transform in comparison to its decimated
    counterpart (``pywt.wavedecn``), is that it is shift-invariant. This comes
    at cost of redundancy in the transform (the size of the output coefficients
    is larger than the input).

    When the following three conditions are true:

        1. The wavelet is orthogonal
        2. ``swt2`` is called with ``norm=True``
        3. ``swt2`` is called with ``trim_approx=True``

    the transform has the following additional properties that may be
    desirable in applications:

        1. energy is conserved
        2. variance is partitioned across scales

    r8   zExpected 2 axesz'The axes passed to swt2 must be unique.z8Input array has fewer dimensions than the specified axesr   r   Ndaadddaa)
rk   r   r   rn   rm   setrC   uniquer   r>   )
rG   r'   r,   r-   rX   r.   r0   coefsrQ   r\   s
             r    r   r     s]   l ;;D:dD
4yyA~~*+++
4yyCD		NN""BCCCy3ry''''   ! ! 	! w{D+tLLE
C 

58abb	 ? ? 	?JJ$4!D'23333JJ$!D'1T7AdG!<=>>>>Jr"   c                 	   t          | d         t          t          f           }|r| d         n| d         d         }|j        dk    s|dk    r:|r|gd | dd         D             z   }nd | D             }t	          ||||          S t
          st          j        |          r~|r?|j        g}|d	 | dd         D             z  }|j	        g}|d
 | dd         D             z  }nd | D             }d | D             }||d}	t          |fi |	}
|
dt          |fi |	z  z   S |r
| dd         } t          |          }t          j        ||d          }|j        dk    rt          d          t          |           }t          |d          }|rd |D             }t!          |          D ]}t#          t%          d||z
  dz
                      }|}|r| |         \  }}}n| |         \  }\  }}}|j        |j        k    s|j        |j        k    rt)          d          t          j        |gd |||fD             z    }|j        |k    r|                    |          }t!          |          D ]}t!          |          D ]}t1          ||j        d         |          }t1          ||j        d         |          }t1          ||j        d         d|z            }t1          ||j        d         d|z            }t1          ||z   |j        d         d|z            }t1          ||z   |j        d         d|z            }t3          |||f         |||f         |||f         |||f         ff|d          }t3          |||f         |||f         |||f         |||f         ff|d          } t3          |||f         |||f         |||f         |||f         ff|d          }!t3          |||f         |||f         |||f         |||f         ff|d          }"t          j        | dd          } t          j        |!dd          }!t          j        |"dd          }"t          j        |"dd          }"|| z   |!z   |"z   dz  |||f<   |S )a  
    Multilevel 2D inverse discrete stationary wavelet transform.

    Parameters
    ----------
    coeffs : list
        Approximation and details coefficients::

            [
                (cA_n,
                    (cH_n, cV_n, cD_n)
                ),
                ...,
                (cA_2,
                    (cH_2, cV_2, cD_2)
                ),
                (cA_1,
                    (cH_1, cV_1, cD_1)
                )
            ]

        where cA is approximation, cH is horizontal details, cV is
        vertical details, cD is diagonal details and n is the number of
        levels.  Index 1 corresponds to ``start_level`` from ``pywt.swt2``.
    wavelet : Wavelet object or name string, or 2-tuple of wavelets
        Wavelet to use.  This can also be a 2-tuple of wavelets to apply per
        axis.
    norm : bool, optional
        Controls the normalization used by the inverse transform. This must
        be set equal to the value that was used by ``pywt.swt2`` to preserve
        the energy of a round-trip transform.

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

    Examples
    --------
    >>> import pywt
    >>> coeffs = pywt.swt2([[1,2,3,4],[5,6,7,8],
    ...                     [9,10,11,12],[13,14,15,16]],
    ...                    'db1', level=2)
    >>> pywt.iswt2(coeffs, 'db1')
    array([[  1.,   2.,   3.,   4.],
           [  5.,   6.,   7.,   8.],
           [  9.,  10.,  11.,  12.],
           [ 13.,  14.,  15.,  16.]])

    r   r8   r   c                 "    g | ]\  }}}|||d S ))r   r   r   r   r   hvrT   s       r    r!   ziswt2.<locals>.<listcomp>  s8      ;  ;  ;$+Aq! () ; ;  ;  ;  ;r"   r   Nc                 *    g | ]\  }\  }}}||||d S ))r   r   r   r   r   r   rV   r   r   rT   s        r    r!   ziswt2.<locals>.<listcomp>  s>     5 5 5)Q	Aq !"!1== 5 5 5r"   rW   c                 >    g | ]\  }}}|j         |j         |j         fS r   rZ   r   s       r    r!   ziswt2.<locals>.<listcomp>  +    OOOAqQVQVQV4OOOr"   c                 >    g | ]\  }}}|j         |j         |j         fS r   r_   r   s       r    r!   ziswt2.<locals>.<listcomp>  r   r"   c                 R    g | ]$\  }\  }}}|j         |j         |j         |j         ff%S r   rZ   r   s        r    r!   ziswt2.<locals>.<listcomp>  F     8 8 8 ,9Aq! FQVQVQV$<= 8 8 8r"   c                 R    g | ]$\  }\  }}}|j         |j         |j         |j         ff%S r   r_   r   s        r    r!   ziswt2.<locals>.<listcomp>  r   r"   rf   r1   Trg   zKiswt2 only supports 2D arrays.  see iswtn for a general n-dimensionsal ISWTr   r   rX   c                 R    g | ]$}t          |t          j        d                     %S r8   r)   r   rB   r   r(   s     r    r!   ziswt2.<locals>.<listcomp>  :     ) ) ) 0RWQZZ@@ ) ) )r"   4Mismatch in shape of intermediate coefficient arraysc                 ,    g | ]}t          |          S r   )r	   r[   s     r    r!   ziswt2.<locals>.<listcomp>  s    <<<!l1oo<<<r"   ri   r/      )rj   rk   rl   rC   r   r   r   r:   r;   r<   r   r	   r?   rm   rn   r   rp   rq   rr   rD   RuntimeErrorresult_typer7   astypeslicer   rw   )#rx   r'   r0   rX   r.   ry   rz   rI   rJ   rH   r{   rP   r|   r}   waveletsr   r   r   cHcVr   r   common_dtypefirst_hfirst_w	indices_h	indices_w
even_idx_h
even_idx_w	odd_idx_h	odd_idx_wr   r   x3x4s#                                      r    r   r   }  s   h !UDM:::K!	3vay|B	w!||tx'' 	5  ;  ;/5abbz ;  ;  ; ;II5 5-35 5 5IYd>>>> 5!4!4 5 		87)KOOF122JOOOOK7)KOOF122JOOOOKK8 8068 8 8K8 8068 8 8K$d33+((((2k44V44444  
b		BXb...F{a"# # 	# VJ!'777H )) )') ) ) : :G :GAz!|A~..//	
 	(!!9LRRR$QiOA|BH  bh"(&:&:FH H H
 ~F<<B|<<<<?<<'']]<00FZ(( '	G '	GG ,, &G &G!'28A;	BB	!'28A;	BB	"7BHQK9EE
"7BHQK9EE
!'I"5rx{AiKPP	!'I"5rx{AiKPP	 F:z#9:z:56z:56z:5689 $_	6 6
 F:y#89z945z945z94578 $_	6 6
 F9j#89y*45y*45y*4578 $_	6 6
 F9i#78y)34y)34y)3467 $_	6 6 WR+++WR+++WR+++WR+++02R"r0AQ/Fy)+,,M&G'	GR Mr"   c           
          t          j                    t          st          j                   r||||||d}t	           j        fi |}t	           j        fi |}	|r|d         d|	d         z  z   g}
d}ng }
d}t          ||d         |	|d                   D ]'\  |
                    fdD                        (|
S  j	        t          j	        d          k    rt          d           j        dk     rt          d	          |t           j                  } fd
|D             }t           fd|D                       rt          d          t!          |          t!          t#          |                    k    rt          d          t!          |          }t%          ||          }|r>t          j        d |D                       st)          j        d           d |D             }g }t          |||z             D ]}d fg}t          ||          D ]O\  }}g }|D ]C\  }}t-          ||d||          d         \  }}|                    |dz   |f|dz   |fg           D|}Pt1          |          }|                    |           |d|z            |r|                    d|z             |r|                                |                                 |S )aI  
    n-dimensional stationary wavelet transform.

    Parameters
    ----------
    data : array_like
        n-dimensional array with input data.
    wavelet : Wavelet object or name string, or tuple of wavelets
        Wavelet to use.  This can also be a tuple of wavelets to apply per
        axis in ``axes``.
    level : int
        The number of decomposition steps to perform.
    start_level : int, optional
        The level at which the decomposition will start (default: 0)
    axes : sequence of ints, optional
        Axes over which to compute the SWT. A value of ``None`` (the
        default) selects all axes. Axes may not be repeated.
    trim_approx : bool, optional
        If True, approximation coefficients at the final level are retained.
    norm : bool, optional
        If True, transform is normalized so that the energy of the coefficients
        will be equal to the energy of ``data``. In other words,
        ``np.linalg.norm(data.ravel())`` will equal the norm of the
        concatenated transform coefficients when ``trim_approx`` is True.

    Returns
    -------
    [{coeffs_level_n}, ..., {coeffs_level_1}]: list of dict
        Results for each level are arranged in a dictionary, where the key
        specifies the transform type on each dimension and value is a
        n-dimensional coefficients array.

        For example, for a 2D case the result at a given level will look
        something like this::

            {'aa': <coeffs>  # A(LL) - approx. on 1st dim, approx. on 2nd dim
             'ad': <coeffs>  # V(LH) - approx. on 1st dim, det. on 2nd dim
             'da': <coeffs>  # H(HL) - det. on 1st dim, approx. on 2nd dim
             'dd': <coeffs>  # D(HH) - det. on 1st dim, det. on 2nd dim
            }

        For user-specified ``axes``, the order of the characters in the
        dictionary keys map to the specified ``axes``.

        If ``trim_approx`` is ``True``, the first element of the list contains
        the array of approximation coefficients from the final level of
        decomposition, while the remaining coefficient dictionaries contain
        only detail coefficients. This matches the behavior of `pywt.wavedecn`.

    Notes
    -----
    The implementation here follows the "algorithm a-trous" and requires that
    the signal length along the transformed axes be a multiple of ``2**level``.
    If this is not the case, the user should pad up to an appropriate size
    using a function such as ``numpy.pad``.

    A primary benefit of this transform in comparison to its decimated
    counterpart (``pywt.wavedecn``), is that it is shift-invariant. This comes
    at cost of redundancy in the transform (the size of the output coefficients
    is larger than the input).

    When the following three conditions are true:

        1. The wavelet is orthogonal
        2. ``swtn`` is called with ``norm=True``
        3. ``swtn`` is called with ``trim_approx=True``

    the transform has the following additional properties that may be
    desirable in applications:

        1. energy is conserved
        2. variance is partitioned across scales

    )r'   r,   r-   r.   rX   r0   r   r1   r   Nc                 :    i | ]}||         d |         z  z   S r3   r   )r   kidictrdicts     r    
<dictcomp>zswtn.<locals>.<dictcomp>v  s,    <<<E!HrE!H},<<<r"   objectz"Input must be a numeric array-likezInput data must be at least 1Dc                 4    g | ]}|d k     r
|j         z   n|S r   rC   r   rV   rG   s     r    r!   zswtn.<locals>.<listcomp>  s+    888aQUUA	MM888r"   c              3   :   K   | ]}|d k     p
|j         k    V  dS )r   Nr   r   s     r    	<genexpr>zswtn.<locals>.<genexpr>  s2      
1
1q1q5"AN
1
1
1
1
1
1r"   r9   'The axes passed to swtn must be unique.c                     g | ]	}|j         
S r   )r%   r   s     r    r!   zswtn.<locals>.<listcomp>  s    :::#s~:::r"   zpnorm=True, but the wavelets used are not orthogonal: 
	The conditions for energy preservation are not satisfied.c           	      X    g | ]'}t          |d t          j        d          z            (S )r   r8   r   r   s     r    r!   zswtn.<locals>.<listcomp>  s>     ) ) ) 0Qrwqzz\BB ) ) )r"    )r,   r-   r/   rV   rT   )r   r   r   r:   r   r;   r<   r=   r>   r7   	TypeErrorrC   rm   rp   anyr   rn   r   r   allr@   rA   rF   extenddictpopreverse)rG   r'   r,   r-   rX   r.   r0   rH   r;   r<   cplxoffsetnum_axesr   rQ   irx   r/   
new_coeffssubbandxry   r   r   r   s   `                      @@r    r   r     s   X :dD !6!6 $u[%0$N NDI((((DI(((( 	Gb47l*+DFFDFVWWtFGG}== 	> 	>LE5KK<<<<<e<<<> > > >zRXh''''<===y1}}9:::|TY88884888D

1
1
1
1D
1
1
111 =;<<<
4yyCD		NN""BCCC4yyH!'400H )v:::::;; 	OMNO O O) )') ) )
C;e 344 ' 't* x00 	  	 MD'J$ 9 9
"1gQA(,. . ../1B!!GcM2#6$+cM2#6#8 9 9 9 9FFf

6 cHn% 	'JJsX~&&& 

4KKMMMJr"   c           	      	  &' t          d | d         D                       }t          | d         t                     }|r| d         n| d         d|z           }t          st	          j        |          rq|r'| d         j        g}| d         j        g}| dd         } ng }g }|d | D             z  }|d | D             z  }|||d	}	t          |fi |	}
|
d
t          |fi |	z  z   S |r
| dd         } t          |          }t	          j
        ||d          }|j        &|t          |j                  }&fd|D             }t          |          t          t          |                    k    rt          d          |t          |          k    rt          d          t          |           }t!          ||          }|rd |D             }t#          d          g&z  }t#          d          g&z  }t#          d          g&z  }t#          d          g&z  }t          |          D ]}t%          t'          d||z
  dz
                      }|}|s| |                             d|z            }| |         }t	          j        |gd |                                D             z    }|j        |k    r|                    |          }d |                                D             't          t          '                    dk    rt5          d          t7          'fd|D                       }t9          t          |          g|z   D ]}t;          |||          D ]K\  }}}t#          |||          ||<   t#          ||d|z            ||<   t#          ||z   |d|z            ||<   L|                                }d|t7          |          <   d}t9          dg|z   D ]} t;          | |          D ]\  }!}|!r||         ||<   ||         ||<   i }"|                                D ]\  }#}$|$t7          |                   |"|#<   |t7          |                   |"d|z  <   t?          |"|d|          }%t;          | |          D ]\  }!}|!rt	          j         |%d|          }%|t7          |          xx         |%z  cc<   |dz  }|t7          |          xx         |z  cc<   |s|| |         d|z  <   |S )a  
    Multilevel nD inverse discrete stationary wavelet transform.

    Parameters
    ----------
    coeffs : list
        [{coeffs_level_n}, ..., {coeffs_level_1}]: list of dict
    wavelet : Wavelet object or name string, or tuple of wavelets
        Wavelet to use.  This can also be a tuple of wavelets to apply per
        axis in ``axes``.
    axes : sequence of ints, optional
        Axes over which to compute the inverse SWT. Axes may not be repeated.
        The default is ``None``, which means transform all axes
        (``axes = range(data.ndim)``).
    norm : bool, optional
        Controls the normalization used by the inverse transform. This must
        be set equal to the value that was used by ``pywt.swtn`` to preserve
        the energy of a round-trip transform.

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

    Examples
    --------
    >>> import pywt
    >>> coeffs = pywt.swtn([[1,2,3,4],[5,6,7,8],
    ...                     [9,10,11,12],[13,14,15,16]],
    ...                    'db1', level=2)
    >>> pywt.iswtn(coeffs, 'db1')
    array([[  1.,   2.,   3.,   4.],
           [  5.,   6.,   7.,   8.],
           [  9.,  10.,  11.,  12.],
           [ 13.,  14.,  15.,  16.]])

    c              3   4   K   | ]}t          |          V  d S )N)rn   )r   keys     r    r   ziswtn.<locals>.<genexpr>  s(      88cS888888r"   r*   r   rV   r   Nc                 J    g | ] }d  |                                 D             !S )c                 $    i | ]\  }}||j         S r   rZ   r   r   r   s      r    r   z$iswtn.<locals>.<listcomp>.<dictcomp>       999tq!AF999r"   itemsr[   s     r    r!   ziswtn.<locals>.<listcomp>  /    JJJa99qwwyy999JJJr"   c                 J    g | ] }d  |                                 D             !S )c                 $    i | ]\  }}||j         S r   r_   r   s      r    r   z$iswtn.<locals>.<listcomp>.<dictcomp>  r   r"   r   r[   s     r    r!   ziswtn.<locals>.<listcomp>  r   r"   )r'   rX   r0   r1   Trg   c                 *    g | ]}|d k     r|z   n|S r   r   )r   rV   rC   s     r    r!   ziswtn.<locals>.<listcomp>  s)    333AAHH1333r"   r   zYThe number of axes used in iswtn must match the number of dimensions transformed in swtn.c                 R    g | ]$}t          |t          j        d                     %S r   r   r   s     r    r!   ziswtn.<locals>.<listcomp>  r   r"   r8   c                     g | ]	}|j         
S r   r6   )r   r   s     r    r!   ziswtn.<locals>.<listcomp>  s    888!ag888r"   c                 "    g | ]\  }}|j         S r   )rD   r   s      r    r!   ziswtn.<locals>.<listcomp>  s    666da!'666r"   r   c                 ,    g | ]}d          |         S r   r   )r   axshapess     r    r!   ziswtn.<locals>.<listcomp>  s!    "@"@"@R6!9R="@"@"@r"   r   ri   r   r   )!maxrj   r   r   r   r:   r;   r<   r   r	   r?   rC   rp   rn   r   rm   r   r   rq   rr   r   r   valuesr7   r   r   r   rk   r   r=   rh   r   rw   )(rx   r'   rX   r0   ndim_transformr.   ry   rI   rJ   rH   r{   rP   r|   r}   r   r   r   r   odd_even_slicesr   r   r   rV   detailsr   coeff_trans_shapefirstsr   shr   approxntransformsoddsodetails_slicer   valuer   rC   r   s(                                         @@r    r   r     s   N 88VBZ88888N D111K!	Dvay^1C'DB 5!4!4 5 	!!9>*K!!9>*KABBZFFKKJJ6JJJJJJ6JJJJ$dDAA+((((2k44V44444  
b		BXb...F;D|V[!!3333d333D
4yyCD		NN""BCCCT"" E F F 	F VJ!'400H )) )') ) )
 T{{od"G$KK?4'L;;/$&KT{{od*O: 8. 8.Az!|A~..//	
 	2q	c.011A)~F88w~~'7'78888;<<'']]<00F 76gmmoo666s6{{q  FH H H ""@"@"@"@4"@"@"@AA z!2!2 5n DF  	2  	2F!$V->!E!E J Jr2#E2y99#(AiK#@#@R "'iQy["I"IB [[]]F%&F5>>"K6*^";= ! ! t__ ? ?EAr ?.9"o++.:2.>++ "")--// G GJC).u_/E/E)FM#&&4:/**5,c.01
 -?NNN t__ 3 3EAr 3GAqr222uW~~&&&!+&&&q 5>>"""k1"""" 	.,-F1Ic.()Mr"   )Nr   r*   FF)Fr*   )r   r   FF)Fr   )r   NFF)NF)!r@   	itertoolsr   numpyr   _c99_configr   _extensions._dwtr   _extensions._pywtr   r   r	   _extensions._swtr
   rE   r   rF   r   	_multidimr   r   _utilsr   r   r   __all__r)   r   r   r   r   r   r   r"   r    <module>r     s              * * * * * * ) ) ) ) ) ) ; ; ; ; ; ; ; ; ; ; ) ) ) ) ) ) 3 3 3 3 3 3 + + + + + + # # # # # # # # > > > > > > > > > >
L
L
L   8: %} } } }@q q q qh 4<!&j j j jZ\ \ \ \~ FKI I I IXQ Q Q Q Q Qr"   