通过numba在Python中高效模拟任意动力系统?

通过numba在Python中高效模拟任意动力系统?,python,numba,Python,Numba,一段时间以来,我一直在想,在Python中模拟任意非线性(确定性或随机性)动态系统最有效的方法是什么。我经常在教学或研究中这样做。我深信,必须有一种简单有效的方法来做到这一点 今晚在酒吧里,我想到了以下几点 def iterate(F, X, T, **params): """Iterate a non-linear map F starting from some initial condition X for T periods.""" t = 0 while t &

一段时间以来,我一直在想,在Python中模拟任意非线性(确定性或随机性)动态系统最有效的方法是什么。我经常在教学或研究中这样做。我深信,必须有一种简单有效的方法来做到这一点

今晚在酒吧里,我想到了以下几点

def iterate(F, X, T, **params):
    """Iterate a non-linear map F starting from some initial condition X for T periods."""
    t = 0
    while t < T:
        yield X
        X = F(X, **params)
        t += 1
…产生

%timeit -n 1 -r 3 [X for X in iterate(tinker_bell_map, [-0.72, -0.64], 10, a=0.9, b=-0.6013, c=2.0, d=0.5)]
1 loops, best of 3: 26 µs per loop

%timeit -n 1 -r 3 [X for X in iterate(tinker_bell_map, [-0.72, -0.64], 100, a=0.9, b=-0.6013, c=2.0, d=0.5)]
1 loops, best of 3: 254 µs per loop

%timeit -n 1 -r 3 [X for X in iterate(tinker_bell_map, [-0.72, -0.64], 1000, a=0.9, b=-0.6013, c=2.0, d=0.5)]
1 loops, best of 3: 2.36 ms per loop

%timeit -n 1 -r 3 [X for X in iterate(tinker_bell_map, [-0.72, -0.64], 10000, a=0.9, b=-0.6013, c=2.0, d=0.5)]
1 loops, best of 3: 19.6 ms per loop

%timeit -n 1 -r 3 [X for X in iterate(tinker_bell_map, [-0.72, -0.64], 100000, a=0.9, b=-0.6013, c=2.0, d=0.5)]
1 loops, best of 3: 192 ms per loop

%timeit -n 1 -r 3 [X for X in iterate(tinker_bell_map, [-0.72, -0.64], 1000000, a=0.9, b=-0.6013, c=2.0, d=0.5)] 
1 loops, best of 3: 2.02 s per loop

%timeit -n 1 -r 3 [X for X in iterate(tinker_bell_map, [-0.72, -0.64], 10000000, a=0.9, b=-0.6013, c=2.0, d=0.5)]
1 loops, best of 3: 20.5 s per loop
…我已经尝试了其他几个确定性和随机系统的测试用例,上面的工作很有魅力。虽然我认为上面的方法很好,但我想知道是否可以使用它来更快地实现

这里有两个我一直在玩的尝试性解决方案

@njit
def tinker_bell_map(X, params):
    out = [X[0]**2 - X[1]**2 + params[0] * X[0] + params[1] * X[1],
           2 * X[0] * X[1] + params[2] * X[0] + params[3] * X[1]]
    return out

def simulator_factory(F):

    @njit
    def simulator(initial_condition, T, params):
        """Iterate a non-linear map starting from some X for T periods."""
        X = np.empty((initial_condition.shape[0], T + 1))
        X[:, 0] = initial_condition  # here is the offending line!
        for t in xrange(T):
            X[:, t+1] = F(X[:, t], params)
        return X

    return simulator


def iterator_factory(F):

    @njit
    def iterator(X, T, params):
        """Iterate a non-linear map starting from some X for T periods."""
        t = 0
        while t < T:
            yield X
            X = F(X, params)  # this is the offending line!
            t += 1

    return iterator
@njit
def tinker_bell_映射(X,参数):
out=[X[0]**2-X[1]**2+参数[0]*X[0]+参数[1]*X[1],
2*X[0]*X[1]+参数[2]*X[0]+参数[3]*X[1]]
返回
def模拟器工厂(F):
@njit
def模拟器(初始条件、T、参数):
“”“迭代从某个X开始的一个非线性映射,持续T个周期。”“”
X=np.empty((初始条件形状[0],T+1))
X[:,0]=初始条件#这是违规的一行!
对于X范围内的t(t):
X[:,t+1]=F(X[:,t],参数)
返回X
返回模拟器
def迭代器工厂(F):
@njit
def迭代器(X,T,params):
“”“迭代从某个X开始的一个非线性映射,持续T个周期。”“”
t=0
而t
…不幸的是,两者都不起作用

In [8]: f(np.array([-0.72, -0.64]), 10, np.array([0.9, -0.6013, 2.0, 0.5]))
---------------------------------------------------------------------------
TypingError                               Traceback (most recent call last)
<ipython-input-8-d4c0195e7f4e> in <module>()
----> 1 f(np.array([-0.72, -0.64]), 10, np.array([0.9, -0.6013, 2.0, 0.5]))

/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/dispatcher.pyc in _compile_for_args(self, *args, **kws)
    163         assert not kws
    164         sig = tuple([self.typeof_pyval(a) for a in args])
--> 165         return self.compile(sig)
    166 
    167     def inspect_llvm(self, signature=None):

/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/dispatcher.pyc in compile(self, sig)
    301                                           self.py_func,
    302                                           args=args, return_type=return_type,
--> 303                                           flags=flags, locals=self.locals)
    304 
    305             # Check typing error if object mode is used

/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.pyc in compile_extra(typingctx, targetctx, func, args, return_type, flags, locals, library)
    593     pipeline = Pipeline(typingctx, targetctx, library,
    594                         args, return_type, flags, locals)
--> 595     return pipeline.compile_extra(func)
    596 
    597 

/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.pyc in compile_extra(self, func)
    316                 raise e
    317 
--> 318         return self.compile_bytecode(bc, func_attr=self.func_attr)
    319 
    320     def compile_bytecode(self, bc, lifted=(), lifted_from=None,

/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.pyc in compile_bytecode(self, bc, lifted, lifted_from, func_attr)
    325         self.lifted_from = lifted_from
    326         self.func_attr = func_attr
--> 327         return self._compile_bytecode()
    328 
    329     def compile_internal(self, bc, func_attr=DEFAULT_FUNCTION_ATTRIBUTES):

/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.pyc in _compile_bytecode(self)
    580 
    581         pm.finalize()
--> 582         return pm.run(self.status)
    583 
    584 

/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.pyc in run(self, status)
    207                     # No more fallback pipelines?
    208                     if is_final_pipeline:
--> 209                         raise patched_exception
    210                     # Go to next fallback pipeline
    211                     else:

TypingError: Caused By:
Traceback (most recent call last):
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 201, in run
    res = stage()
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 415, in stage_nopython_frontend
    self.locals)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 710, in type_inference_stage
    infer.propagate()
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 408, in propagate
    self.constrains.propagate(self.context, self.typevars)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 113, in propagate
    loc=constrain.loc)
TypingError: Internal error at <numba.typeinfer.CallConstrain object at 0x10c5a7d50>:
Caused By:
Traceback (most recent call last):
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 201, in run
    res = stage()
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 415, in stage_nopython_frontend
    self.locals)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 709, in type_inference_stage
    infer.build_constrain()
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 395, in build_constrain
    self.constrain_statement(inst)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 519, in constrain_statement
    self.typeof_assign(inst)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 555, in typeof_assign
    self.typeof_expr(inst, inst.target, value)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 672, in typeof_expr
    raise NotImplementedError(type(expr), expr)
NotImplementedError: (<class 'numba.ir.Expr'>, build_list(items=[Var($0.27, /Users/drpugh/Research/python-dev/ramseyPy/sandbox.py (18)), Var($0.52, /Users/drpugh/Research/python-dev/ramseyPy/sandbox.py (19))]))

Failed at nopython (nopython frontend)
(<class 'numba.ir.Expr'>, build_list(items=[Var($0.27, /Users/drpugh/Research/python-dev/ramseyPy/sandbox.py (18)), Var($0.52, /Users/drpugh/Research/python-dev/ramseyPy/sandbox.py (19))]))
File "sandbox.py", line 45

Failed at nopython (nopython frontend)
Internal error at <numba.typeinfer.CallConstrain object at 0x10c5a7d50>:
Caused By:
Traceback (most recent call last):
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 201, in run
    res = stage()
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 415, in stage_nopython_frontend
    self.locals)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 709, in type_inference_stage
    infer.build_constrain()
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 395, in build_constrain
    self.constrain_statement(inst)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 519, in constrain_statement
    self.typeof_assign(inst)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 555, in typeof_assign
    self.typeof_expr(inst, inst.target, value)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 672, in typeof_expr
    raise NotImplementedError(type(expr), expr)
NotImplementedError: (<class 'numba.ir.Expr'>, build_list(items=[Var($0.27, /Users/drpugh/Research/python-dev/ramseyPy/sandbox.py (18)), Var($0.52, /Users/drpugh/Research/python-dev/ramseyPy/sandbox.py (19))]))

Failed at nopython (nopython frontend)
(<class 'numba.ir.Expr'>, build_list(items=[Var($0.27, /Users/drpugh/Research/python-dev/ramseyPy/sandbox.py (18)), Var($0.52, /Users/drpugh/Research/python-dev/ramseyPy/sandbox.py (19))]))
File "sandbox.py", line 45
[8]中的
:f(np.数组([-0.72,-0.64]),10,np.数组([0.9,-0.6013,2.0,0.5]))
---------------------------------------------------------------------------
打字机错误回溯(最近一次呼叫最后一次)
在()
---->1f(np.数组([-0.72,-0.64]),10,np.数组([0.9,-0.6013,2.0,0.5]))
/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/dispatcher.pyc in _compile_for_args(self,*args,**kws)
163非kws
164 sig=元组([args中a的self.typeof_pyval(a)])
-->165返回自编译(sig)
166
167 def inspect_llvm(自身,签名=无):
/编译中的Users/drpugh/anaconda/lib/python2.7/site-packages/numba/dispatcher.pyc(self,sig)
301 self.py_func,
302 args=args,return\u type=return\u type,
-->303标志=标志,局部变量=自身。局部变量)
304
305#如果使用对象模式,则检查键入错误
/compile_extra中的Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.pyc(键入ctx、targetctx、func、args、返回类型、标志、局部变量、库)
593管道=管道(键入CTX、targetctx、库、,
594参数,返回类型,标志,局部变量)
-->595返回管道。编译_额外(func)
596
597
/compile_extra(self,func)中的Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.pyc
316升e
317
-->318返回self.compile\u字节码(bc,func\u attr=self.func\u attr)
319
320 def compile_字节码(self,bc,lifted=(),lifted_from=None,
/编译字节码中的Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.pyc(self、bc、lifted、lifted、from、func\u attr)
325自举自举=自举自举
326 self.func\u attr=func\u attr
-->327返回self.\u编译\u字节码()
328
329 def compile_internal(self、bc、func_attr=默认函数属性):
/字节码(self)中的Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.pyc
580
下午581时
-->582返回下午运行(自我状态)
583
584
/运行中的Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.pyc(self,status)
207#没有备用管道了吗?
208如果是最终管道:
-->209提高补丁_异常
210#转到下一个备用管道
211其他:
打字员:由以下原因引起:
回溯(最近一次呼叫最后一次):
文件“/Users/drpugh/anaconda/lib/python2.7/site packages/numba/compiler.py”,第201行,正在运行
res=阶段()
文件“/Users/drpugh/anaconda/lib/python2.7/site packages/numba/compiler.py”,第415行,在stage_nopython_frontend中
(本地人)
文件“/Users/drpugh/anaconda/lib/python2.7/site packages/numba/compiler.py”,第710行,在类型推理阶段
推断.传播()
文件“/Users/drpugh/anaconda/lib/python2.7/site packages/numba/typeinfer.py”,第408行,在propagate中
self.constraints.propagate(self.context、self.typevars)
文件“/Users/drpugh/anaconda/lib/python2.7/site packages/numba/typeinfer.py”,第113行,在propagate中
loc=约束.loc)
TypingError:内部错误位于:
原因:
回溯(最近一次呼叫最后一次):
文件“/Users/drpugh/anaconda/lib/python2.7/site packages/numba/compiler.py”,第201行,正在运行
res=阶段()
文件“/Users/drpugh/anaconda/lib/python2.7/site packages/numba/compiler.py”,第415行,在stage_nopython_frontend中
(本地人)
文件“/Users/drpugh/anaconda/lib/python2.7/site packages/numba/compiler.py”,第709行,在类型推理阶段
推断.构建约束()
文件“/Users/drpugh/anaconda/lib/python2.7/site packages/numba/typeinfer.py”,第395行,内部版本
self.constraint_语句(inst)
文件“/Users/drpugh/anaconda/lib/python2.7/site packages/numba/typeinfer.py”,第519行,在CONSTRINT_语句中
分配的自身类型(inst)
文件“/Users/drpugh/anaconda/lib/python2.7/site packages/numba/typeinfer.py”,第555行,在typeof_assign中
expr的自身类型(指令、指令目标、值)
文件“/Users/drpugh/anaconda/lib/python2.7/site packages/numba/typeinfer.py”,第672行,在typeof_expr中
类风湿关节炎
In [8]: f(np.array([-0.72, -0.64]), 10, np.array([0.9, -0.6013, 2.0, 0.5]))
---------------------------------------------------------------------------
TypingError                               Traceback (most recent call last)
<ipython-input-8-d4c0195e7f4e> in <module>()
----> 1 f(np.array([-0.72, -0.64]), 10, np.array([0.9, -0.6013, 2.0, 0.5]))

/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/dispatcher.pyc in _compile_for_args(self, *args, **kws)
    163         assert not kws
    164         sig = tuple([self.typeof_pyval(a) for a in args])
--> 165         return self.compile(sig)
    166 
    167     def inspect_llvm(self, signature=None):

/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/dispatcher.pyc in compile(self, sig)
    301                                           self.py_func,
    302                                           args=args, return_type=return_type,
--> 303                                           flags=flags, locals=self.locals)
    304 
    305             # Check typing error if object mode is used

/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.pyc in compile_extra(typingctx, targetctx, func, args, return_type, flags, locals, library)
    593     pipeline = Pipeline(typingctx, targetctx, library,
    594                         args, return_type, flags, locals)
--> 595     return pipeline.compile_extra(func)
    596 
    597 

/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.pyc in compile_extra(self, func)
    316                 raise e
    317 
--> 318         return self.compile_bytecode(bc, func_attr=self.func_attr)
    319 
    320     def compile_bytecode(self, bc, lifted=(), lifted_from=None,

/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.pyc in compile_bytecode(self, bc, lifted, lifted_from, func_attr)
    325         self.lifted_from = lifted_from
    326         self.func_attr = func_attr
--> 327         return self._compile_bytecode()
    328 
    329     def compile_internal(self, bc, func_attr=DEFAULT_FUNCTION_ATTRIBUTES):

/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.pyc in _compile_bytecode(self)
    580 
    581         pm.finalize()
--> 582         return pm.run(self.status)
    583 
    584 

/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.pyc in run(self, status)
    207                     # No more fallback pipelines?
    208                     if is_final_pipeline:
--> 209                         raise patched_exception
    210                     # Go to next fallback pipeline
    211                     else:

TypingError: Caused By:
Traceback (most recent call last):
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 201, in run
    res = stage()
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 415, in stage_nopython_frontend
    self.locals)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 710, in type_inference_stage
    infer.propagate()
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 408, in propagate
    self.constrains.propagate(self.context, self.typevars)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 113, in propagate
    loc=constrain.loc)
TypingError: Internal error at <numba.typeinfer.CallConstrain object at 0x10c5a7d50>:
Caused By:
Traceback (most recent call last):
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 201, in run
    res = stage()
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 415, in stage_nopython_frontend
    self.locals)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 709, in type_inference_stage
    infer.build_constrain()
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 395, in build_constrain
    self.constrain_statement(inst)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 519, in constrain_statement
    self.typeof_assign(inst)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 555, in typeof_assign
    self.typeof_expr(inst, inst.target, value)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 672, in typeof_expr
    raise NotImplementedError(type(expr), expr)
NotImplementedError: (<class 'numba.ir.Expr'>, build_list(items=[Var($0.27, /Users/drpugh/Research/python-dev/ramseyPy/sandbox.py (18)), Var($0.52, /Users/drpugh/Research/python-dev/ramseyPy/sandbox.py (19))]))

Failed at nopython (nopython frontend)
(<class 'numba.ir.Expr'>, build_list(items=[Var($0.27, /Users/drpugh/Research/python-dev/ramseyPy/sandbox.py (18)), Var($0.52, /Users/drpugh/Research/python-dev/ramseyPy/sandbox.py (19))]))
File "sandbox.py", line 45

Failed at nopython (nopython frontend)
Internal error at <numba.typeinfer.CallConstrain object at 0x10c5a7d50>:
Caused By:
Traceback (most recent call last):
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 201, in run
    res = stage()
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 415, in stage_nopython_frontend
    self.locals)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 709, in type_inference_stage
    infer.build_constrain()
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 395, in build_constrain
    self.constrain_statement(inst)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 519, in constrain_statement
    self.typeof_assign(inst)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 555, in typeof_assign
    self.typeof_expr(inst, inst.target, value)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 672, in typeof_expr
    raise NotImplementedError(type(expr), expr)
NotImplementedError: (<class 'numba.ir.Expr'>, build_list(items=[Var($0.27, /Users/drpugh/Research/python-dev/ramseyPy/sandbox.py (18)), Var($0.52, /Users/drpugh/Research/python-dev/ramseyPy/sandbox.py (19))]))

Failed at nopython (nopython frontend)
(<class 'numba.ir.Expr'>, build_list(items=[Var($0.27, /Users/drpugh/Research/python-dev/ramseyPy/sandbox.py (18)), Var($0.52, /Users/drpugh/Research/python-dev/ramseyPy/sandbox.py (19))]))
File "sandbox.py", line 45
In [10]: s = simulator_factory(tinker_bell_map)

In [11]: s(np.array([-0.72, -0.64]), 10, np.array([0.9, -0.6013, 2.0, 0.5]))
---------------------------------------------------------------------------
TypingError                               Traceback (most recent call last)
<ipython-input-11-049d0797e27e> in <module>()
----> 1 s(np.array([-0.72, -0.64]), 10, np.array([0.9, -0.6013, 2.0, 0.5]))

/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/dispatcher.pyc in _compile_for_args(self, *args, **kws)
    163         assert not kws
    164         sig = tuple([self.typeof_pyval(a) for a in args])
--> 165         return self.compile(sig)
    166 
    167     def inspect_llvm(self, signature=None):

/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/dispatcher.pyc in compile(self, sig)
    301                                           self.py_func,
    302                                           args=args, return_type=return_type,
--> 303                                           flags=flags, locals=self.locals)
    304 
    305             # Check typing error if object mode is used

/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.pyc in compile_extra(typingctx, targetctx, func, args, return_type, flags, locals, library)
    593     pipeline = Pipeline(typingctx, targetctx, library,
    594                         args, return_type, flags, locals)
--> 595     return pipeline.compile_extra(func)
    596 
    597 

/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.pyc in compile_extra(self, func)
    316                 raise e
    317 
--> 318         return self.compile_bytecode(bc, func_attr=self.func_attr)
    319 
    320     def compile_bytecode(self, bc, lifted=(), lifted_from=None,

/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.pyc in compile_bytecode(self, bc, lifted, lifted_from, func_attr)
    325         self.lifted_from = lifted_from
    326         self.func_attr = func_attr
--> 327         return self._compile_bytecode()
    328 
    329     def compile_internal(self, bc, func_attr=DEFAULT_FUNCTION_ATTRIBUTES):

/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.pyc in _compile_bytecode(self)
    580 
    581         pm.finalize()
--> 582         return pm.run(self.status)
    583 
    584 

/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.pyc in run(self, status)
    207                     # No more fallback pipelines?
    208                     if is_final_pipeline:
--> 209                         raise patched_exception
    210                     # Go to next fallback pipeline
    211                     else:

TypingError: Caused By:
Traceback (most recent call last):
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 201, in run
    res = stage()
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 415, in stage_nopython_frontend
    self.locals)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 710, in type_inference_stage
    infer.propagate()
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 408, in propagate
    self.constrains.propagate(self.context, self.typevars)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 107, in propagate
    constrain(context, typevars)
  File "/Users/drpugh/anaconda/lib/python2.7/site-packages/numba/typeinfer.py", line 304, in __call__
    (ty, it, vt), loc=self.loc)
TypingError: Cannot resolve setitem: array(float64, 2d, C)[(slice3_type, int32)] = array(float64, 1d, C)
File "sandbox.py", line 29

Failed at nopython (nopython frontend)
Cannot resolve setitem: array(float64, 2d, C)[(slice3_type, int32)] = array(float64, 1d, C)
File "sandbox.py", line 29
```
import numba
from numba import *
from numpy import *
import numpy as np

@njit
def simulator(initial_condition, params, X):
    a = params[0]
    b = params[1]
    c = params[2]
    d = params[3]
    X[0, 0] = initial_condition[0]
    X[1, 0] = initial_condition[1]
    for t in range(1, X.shape[1]):
        u = X[0, t-1]
        v = X[1, t-1]
        X[0, t] = u**2 - v**2 + a * u + b * v
        X[1, t] = 2 * u * v + c * u + d * v
    return X
x0 = np.array([-0.72, -0.64])
params = np.array([0.9, -0.6013, 2.0,0.5])

xs = np.zeros((2, 10000000 ))
%timeit -n 1 -r 3 simulator(x0, params, xs)
1 loops, best of 3: 70.7 ms per loop

xs = np.zeros((2, 100000000 ))
%timeit -n 1 -r 3 simulator(x0, params, xs)
1 loops, best of 3: 715 ms per loop
@njit
def tinker_bell_map(X, params, out):
    out[0] = X[0]**2 - X[1]**2 + params[0] * X[0] + params[1] * X[1]
    out[1] = 2 * X[0] * X[1] + params[2] * X[0] + params[3] * X[1]

def simulator_factory(f):
    def simulator(x0, params, x):
        for i in xrange(2):
            x[i,0] = x0[i]
        for t in xrange(1, x.shape[1]):
            f(x[:,t-1], params, x[:,t])
        return x
    return njit(simulator)

xs = np.zeros((2, 10))
sim = simulator_factory(tinker_bell_map)
print sim(x0, params, xs)
xs = np.zeros((2, 10000000 ))
%timeit -n 1 -r 3 sim(x0, params, xs)
1 loops, best of 3: 272 ms per loop

xs = np.zeros((2, 100000000 ))
%timeit -n 1 -r 3 sim(x0, params, xs)
1 loops, best of 3: 2.73 s per loop