# Path: pyglm/utils/fftconv.py
# def fftconvolve(in1, in2, mode="full", fft_in1=None, fft_in2=None):
# def _centered(arr, newsize):


import os
import numpy as np
import scipy
    import scipy.signal as sig
    import scipy.signal as sig
    import pdb; pdb.set_trace()
from pyglm.utils import fftconv
    # assert D==Db, "Spatial dimension of basis must match spatial dimension of stimulus."

#    import scipy.signal as sig

    # First, by convention, the impulse responses are apply to times
    # (t-R:t-1). That means we need to prepend a row of zeros to make
    # sure the basis remains causal
    basis = np.vstack((np.zeros((1,Db)),basis))

    # Flip the spatial dimension for convolution
    # We are convolving the stimulus with the filter, so the temporal part does
    # NOT need to be flipped
    basis = basis[:,::-1]

    # Compute convolution using FFT
    if D==Db and shape[1] == 'valid':
        raise Warning("Use low rank convolution when D==Db!")

    # Look for fft_stim in _fft_cache
    fft_stim = None
    for (cache_stim, cache_fft_stim) in _fft_cache:
        if np.allclose(stim[-128:],cache_stim[-128:]) and \
           np.allclose(stim[:128],cache_stim[:128]):
            fft_stim = cache_fft_stim
            break

    if not fft_stim is None:
        fstim,_ = fftconv.fftconvolve(stim, basis, 'full',
                                      fft_in1=fft_stim)
    else:

# Path: pyglm/utils/fftconv.py
# def fftconvolve(in1, in2, mode="full", fft_in1=None, fft_in2=None):
# def _centered(arr, newsize):


# Path: pyglm/utils/basis.py
import os
import numpy as np
import scipy
    import scipy.signal as sig
    import scipy.signal as sig
    import pdb; pdb.set_trace()
from pyglm.utils import fftconv

    # assert D==Db, "Spatial dimension of basis must match spatial dimension of stimulus."

#    import scipy.signal as sig

    # First, by convention, the impulse responses are apply to times
    # (t-R:t-1). That means we need to prepend a row of zeros to make
    # sure the basis remains causal
    basis = np.vstack((np.zeros((1,Db)),basis))

    # Flip the spatial dimension for convolution
    # We are convolving the stimulus with the filter, so the temporal part does
    # NOT need to be flipped
    basis = basis[:,::-1]

    # Compute convolution using FFT
    if D==Db and shape[1] == 'valid':
        raise Warning("Use low rank convolution when D==Db!")

    # Look for fft_stim in _fft_cache
    fft_stim = None
    for (cache_stim, cache_fft_stim) in _fft_cache:
        if np.allclose(stim[-128:],cache_stim[-128:]) and \
           np.allclose(stim[:128],cache_stim[:128]):
            fft_stim = cache_fft_stim
            break

    if not fft_stim is None:
        fstim,_ = fftconv.fftconvolve(stim, basis, 'full',
                                      fft_in1=fft_stim)
    else:

        fstim,fft_stim,_ = fftconv.fftconvolve(stim, basis, 'full')