Skip to content

Commit

Permalink
Merge pull request #459 from rht/import
Browse files Browse the repository at this point in the history
quad: Import sympy only when necessary
  • Loading branch information
mmcky authored Dec 14, 2018
2 parents 29ab692 + e265b25 commit 0a34310
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions quantecon/arma.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""
import numpy as np
from numpy import conj, pi
from scipy.signal import dimpulse, freqz, dlsim
from .util import check_random_state


Expand Down Expand Up @@ -61,7 +60,6 @@ class ARMA:
processing we desire. Corresponds with the theta values
"""

def __init__(self, phi, theta=0, sigma=1):
self._phi, self._theta = phi, theta
self.sigma = sigma
Expand Down Expand Up @@ -165,6 +163,7 @@ def impulse_response(self, impulse_length=30):
We take psi[0] as unity.
"""
from scipy.signal import dimpulse
sys = self.ma_poly, self.ar_poly, 1
times, psi = dimpulse(sys, n=impulse_length)
psi = psi[0].flatten() # Simplify return value into flat array
Expand Down Expand Up @@ -205,6 +204,7 @@ def spectral_density(self, two_pi=True, res=1200):
The frequency response
"""
from scipy.signal import freqz
w, h = freqz(self.ma_poly, self.ar_poly, worN=res, whole=two_pi)
spect = h * conj(h) * self.sigma**2

Expand Down Expand Up @@ -249,6 +249,7 @@ def simulation(self, ts_length=90, random_state=None):
A simulation of the model that corresponds to this class
"""
from scipy.signal import dlsim
random_state = check_random_state(random_state)

sys = self.ma_poly, self.ar_poly, 1
Expand Down
2 changes: 1 addition & 1 deletion quantecon/quad.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import numpy as np
import scipy.linalg as la
from numba import jit, vectorize
import sympy as sym
from .ce_util import ckron, gridmake
from .util import check_random_state

Expand Down Expand Up @@ -141,6 +140,7 @@ def qnwequi(n, a, b, kind="N", equidist_pp=None, random_state=None):
random_state = check_random_state(random_state)

if equidist_pp is None:
import sympy as sym
equidist_pp = np.sqrt(np.array(list(sym.primerange(0, 7920))))

n, a, b = list(map(np.atleast_1d, list(map(np.asarray, [n, a, b]))))
Expand Down
6 changes: 4 additions & 2 deletions quantecon/random/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ def _probvec(r, out):
out[n] = 1 - r[n-1]

_probvec_parallel = guvectorize(
['(f8[:], f8[:])'], '(n), (k)', nopython=True, target='parallel'
['(f8[:], f8[:])'], '(n), (k)', nopython=True, target='parallel',
cache=True
)(_probvec)
_probvec_cpu = guvectorize(
['(f8[:], f8[:])'], '(n), (k)', nopython=True, target='cpu'
['(f8[:], f8[:])'], '(n), (k)', nopython=True, target='cpu',
cache=True
)(_probvec)


Expand Down
2 changes: 1 addition & 1 deletion quantecon/util/notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"""

import os
import requests
import warnings

#-Remote Structure-#
Expand Down Expand Up @@ -72,6 +71,7 @@ def fetch_nb_dependencies(files, repo=REPO, raw=RAW, branch=BRANCH, folder=FOLDE
by setting ``overwrite=True``.
"""
import requests

#-Generate Common Data Structure-#
if type(files) == list:
Expand Down

0 comments on commit 0a34310

Please sign in to comment.