
    `iq                        d dl Z i ddgddgddgddgddgddgd	g d
ddgddgddgdg ddg ddg dddgdg dddgddgg ddgdgdgdgg ddgg dg dd gd!gg d"d#gg d$d%Zd&Z e j        ed'          Zd)d(ZdS )*    N                        )r	   r   r   	   
         )r   r   r      )r   r   r
      )r   r   r         )r   r   r         )r   r   r         )      r   r   )         )   r   r   r      )      r	   r   )      r   )r   r   r   r   r   r   r   r   r   r   r   r!   r        a  
#include <cupy/math_constants.h>
#include <cupy/carray.cuh>
#include <cupy/complex.cuh>

extern "C" __global__ void max_len_seq(
        long long length, long long n_taps, int n_state, long long* taps,
        signed char* state, signed char* seq) {

    int idx = blockDim.x * blockIdx.x + threadIdx.x;
    for(long long i = 0; i < length; i++) {
        signed char next_state = state[(idx + 1) % n_state];
        if(idx == n_state - 1) {
            seq[i] = state[0];
            for(int n_tap = 0; n_tap < n_taps; n_tap++) {
                long long tap = taps[n_tap];
                next_state ^= state[tap];
            }
        }
        state[idx] = next_state;
    }
}
max_len_seqc           
         || t           vrrt          j        t          t                                                               }t          d|                                d|                                d          t          j        t           |          t          j                  }nt          j	        t          j        |t          j                            ddd         }t          j
        |dk               s#t          j
        || k              s|j        dk     rt          d          t          j        |          }d	| z  dz
  }||}n$t          |          }|dk     rt          d
          |"t          j        | t          j        d          }n9t          j        |t          d                              t          j                  }|j        dk    s|j        | k    rt          d          t          j        |dk              rt          d          t          j        |t          j        d          }t)          |          }t+          d| f||| |||f           ||fS )a  
    Maximum length sequence (MLS) generator.

    Parameters
    ----------
    nbits : int
        Number of bits to use. Length of the resulting sequence will
        be ``(2**nbits) - 1``. Note that generating long sequences
        (e.g., greater than ``nbits == 16``) can take a long time.
    state : array_like, optional
        If array, must be of length ``nbits``, and will be cast to binary
        (bool) representation. If None, a seed of ones will be used,
        producing a repeatable representation. If ``state`` is all
        zeros, an error is raised as this is invalid. Default: None.
    length : int, optional
        Number of samples to compute. If None, the entire length
        ``(2**nbits) - 1`` is computed.
    taps : array_like, optional
        Polynomial taps to use (e.g., ``[7, 6, 1]`` for an 8-bit sequence).
        If None, taps will be automatically selected (for up to
        ``nbits == 32``).

    Returns
    -------
    seq : array
        Resulting MLS sequence of 0's and 1's.
    state : array
        The final state of the shift register.

    Notes
    -----
    The algorithm for MLS generation is generically described in:

        https://en.wikipedia.org/wiki/Maximum_length_sequence

    The default values for taps are specifically taken from the first
    option listed for each value of ``nbits`` in:

        https://web.archive.org/web/20181001062252/http://www.newwaveinstruments.com/resources/articles/m_sequence_linear_feedback_shift_register_lfsr.htm

    Nznbits must be between z and z if taps is Noner   r   zEtaps must be non-empty with values between zero and nbits (inclusive)r   z)length must be greater than or equal to 0c)dtypeorderz'state must be a 1-D array of size nbitszstate must not be all zeros)r   )	_mls_tapscupyarraylistkeys
ValueErrorminmaxint64uniqueanysizeintonesint8boolastypendimallemptylen_max_len_seq)nbitsstatelengthtaps
known_tapsn_maxseqn_tapss           s/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupyx/scipy/signal/_max_len_seq.pyr#   r#   (   s4   T |	!!D)9)9$:$:;;J* * 0 0 0 0*..2B2B2B2BD E E Ez)E*DJ77{4:dDJ77882>8D1H 	;$,!7!7 	;49q== : ; ; ;z$%Z1E~VA::HIII }	%ty<<< 
5C888??	JJzQ%*--BCCCx
 86777
*V49C
8
8
8CYYFx&&%uc!JKKK:    )NNN)r*   r)   MAX_LEN_SEQ_KERNEL	RawKernelr>   r#    rH   rG   <module>rL      s   )Q )Q )Q )Q )Q )Q )Q			 ))!) 1#)');;;)8:KKK)) 2$)(*KKK)9;bT) ") (<<bTt"<<<bT|||B4bT{{{<<<) ) )	 0 t~0-@@O O O O O OrH   