微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

python – Numba错误:NotImplementedError:无法从{i64,i8 *} *强制转换为{i64,i8 *}

我和numba有一个奇怪的错误.

我正在使用Anacondas,Python 3.3

我试图自动执行的功能

@autojit
def _generate_broadcasted_forecasts(self):
    x = np.array( self.residuals[1:],dtype=float)
    y = np.array( self.sigma[1:-1],dtype=float)
    errors = x/y
    self.errors = errors

数据是:

完整的错误是:


设置一个breakpoit


190行,我看了几行之前发现错误是因为


不幸的是,我对numba了解不足以了解这意味着什么.

为完整起见,发生错误函数是:


我究竟做错了什么?我尝试在此处发布代码段,但无法重现错误.即以下工作在我的机器上:


self.residuals
Out[1]: 
array([ 0.00027274,0.
@autojit
def _generate_broadcasted_forecasts(self):
    x = np.array( self.residuals[1:],dtype=float)
    errors = x/y
    self.errors = errors   

376,0.01042219,0.02850773,-0.01411178,
-0.01929838,0.00385101,-0.01630044,0.03715821,0.02258934,
0.05662874,-0.02359702,-0.01823098,-0.03092986,0.02994069,
0.01090546,-0.02475619,-0.01020354,-0.00332659,-0.01734819,
0.01957363,-0.02706434,0.01215692,-0.05122325,-0.02016905,
-0.0472204,0.0183388,0.00319104,-0.04198954,0.00586023,
-0.03320624,0.0061127,-0.04101338,0.07630624,-0.04561496,
-0.01602609,0.03317164,-0.02177255,-0.001892,-0.01752149,
-0.01062089,-0.00036998,-0.02321696,-0.01139503,-0.04052122,
0.01033072,-0.04154074,0.00703859,0.01299577,0.0532591,
0.02145779,0.06422423,-0.02635143,-0.01230678,-0.00905247,
-0.03167185,0.02384259,0.03086425,0.02310251,-0.003188,
0.01928799,-0.02143164,-0.01694362,0.00274987,-0.03429799,
0.00123984,-0.01234553,-0.01822308,0.01739987,0.05260887,
-0.01671929,-0.0451185,-0.00253769,-0.01643629,0.0689997,
0.07316202,-0.05564215,0.02830494,0.02396265,-0.00335834,
-0.00328183,-0.01633152,-0.02944809,-0.01730992,0.02290413,
0.03344062,-0.03211203,0.00115551,-0.0348293,0.01106866,
-0.00334149,-0.000305,0.00499175,-0.00023061,0.00635803,
-0.01883831,-0.01078026,0.01491779,0.04605717,-0.01274995,
-0.00380779,0.03336405,-0.01263997,0.02967207,-0.00949215,
-0.0239608,0.02311184,-0.03347211,-0.01047334,0.02570358,
-0.02749113,0.01718504,-0.00012177,0.03942462,-0.02854834,
-0.00689199,0.00769279,0.01237644,-0.02212167,0.02312826,
-0.00335928,0.00626517,0.0127933,0.00980856,0.02102578,
-0.00291102,0.02605287,0.00453684,0.01697849,-0.01733679,
0.02957533,-0.00981372,0.01504038,-0.00308469,-0.01067471,
0.02550573,0.01636283,0.00386063,0.01584089,0.02774164,
0.01026229,-0.01319894,0.0047792,0.01137512,-0.00017363,
-0.0026951,0.023888,-0.0178131,-0.00043418,0.00078961,
-0.01046682,-0.01422187,0.02284845,0.01530962,-0.00277356,
-0.047021,-0.0233437,-0.00700932,-0.00461674,0.04386189,
0.03214708,0.02512427,0.05888554,0.00946264,-0.01649079,
-0.01824022,0.00305155,0.02141179,0.02040107,0.01223521,
0.04182406,0.01200173,-0.00666375,0.00839121,0.00601783,
0.00727748,-0.01839253,-0.02627941,0.00040831,-0.00348844,
0.0396223,0.01587524,0.05635961,0.00638051,0.03315842,
-0.02278018,-0.00149056,-0.00028848,-0.09895528,0.02313064,
0.02065743,-0.00115973,-0.00135562,-0.02609936,0.00146749,
0.01020923,-0.07006086,0.04481519,0.02428593,0.00513643,
0.00386419,-0.03904007,0.02584459,0.02042376,-0.00415313,
0.0250591,0.0078504,0.01071272,0.01446379,0.04678684,
-0.030569,0.00499873,-0.00121879,-0.00028605,-0.01341486,
-0.00119668,0.0102857,-0.03408491,-0.01151752,0.02421846,
-0.0126916,0.03427147,-0.00672604,0.00265135,0.04540966,
-0.05231339,0.00802635,0.02506964,0.00188135,0.03521239,
-0.01252548,-0.0487149,-0.01607805,0.06138833,-0.02267715,
-0.00883121,0.04540312,-0.02248676,0.01033092,-0.01845178,
-0.00950717,-0.03646932,0.05394227,-0.03149327,-0.02139244,
-0.00629822,-0.01885609,-0.00724694,0.01627761,0.02120749])

@autojit def _generate_broadcasted_forecasts(self): x = np.array( self.residuals[1:],dtype=float) errors = x/y self.errors = erroRSSelf.sigma
Out[1]:
array([ 0.02647903,0.02580863,0.02854044,0.02781347,0.02778348,
0.02719822,0.02682252,0.02614003,0.02575487,0.02647783,
0.02629712,0.0285969,0.02826486,0.02776125,0.0278659,
0.02790585,0.02723722,0.02708099,0.02646327,0.02580474,
0.02548335,0.025272,0.02542612,0.0249857,0.02698342,
0.02665878,0.02803867,0.02755763,0.02681504,0.02775527,
0.02702024,0.02733631,0.02663591,0.0275261,0.0317507,
0.03234794,0.03145869,0.03131707,0.03068293,0.02970747,
0.02906351,0.02830046,0.02749342,0.02724532,0.02663881,
0.02749216,0.02684456,0.02774718,0.02702682,0.02647462,
0.02842004,0.02801799,0.03078638,0.03037759,0.02954908,
0.0287226,0.02876979,0.02843258,0.02846502,0.02812427,
0.02733939,0.026951,0.02667852,0.02626748,0.02562064,
0.02616582,0.02552095,0.02507717,0.02485235,0.02461849,
0.0268124,0.02638272,0.02762759,0.02687628,0.02643228,
0.03003171,0.0333827,0.03453727,0.03389183,0.03312942,
0.03199099,0.03093019,0.03015629,0.02994792,0.02927847,
0.02885815,0.0289911,0.02903535,0.0281757,0.02846391,
0.02775531,0.02699883,0.02628887,0.0256573,0.02505049,
0.02453268,0.02438172,0.02399769,0.02375888,0.02547854,
0.02504846,0.02450438,0.02512236,0.02471973,0.02508061,
0.02461088,0.02467567,0.02469342,0.02529554,0.02482779,
0.02495733,0.02516796,0.02489793,0.02435106,0.02542535,
0.02564393,0.02508549,0.02458393,0.02422082,0.02423858,
0.02430145,0.0238144,0.02339728,0.02315016,0.02285179,
0.02295964,0.02258121,0.02297639,0.02260993,0.02257341,
0.02255411,0.02316487,0.02286531,0.0227356,0.02237744,
0.0221682,0.02258031,0.02252393,0.02219001,0.02215312,
0.02269849,0.02245043,0.02230218,0.02199653,0.02184009,
0.02154876,0.02129164,0.02171611,0.02180259,0.02151474,
0.02125285,0.02114355,0.02115455,0.02153887,0.02154778,
0.02129126,0.02352853,0.02367564,0.0232808,0.02288927,
0.02455152,0.02508442,0.02515797,0.02789379,0.0271991,
0.0267295,0.02635739,0.02570532,0.02554735,0.02536272,
0.02492956,0.02611233,0.02561108,0.02505219,0.02456478,
0.02408222,0.0236572,0.02357261,0.02386815,0.0234048,
0.02299286,0.02427669,0.0240433,0.02672357,0.02607349,
0.02649293,0.02631903,0.02566302,0.02505579,0.03301026,
0.03228805,0.03153822,0.03050111,0.02953701,0.02922853,
0.02835562,0.02763884,0.03111266,0.03172814,0.03115373,
0.03016414,0.02923511,0.02967298,0.02934095,0.02882213,
0.0279922,0.0277788,0.02706721,0.02646064,0.02599358,
0.02743368,0.02755225,0.02682387,0.02612851,0.0254851,
0.02507182,0.02451255,0.02410654,0.02482254,0.02441787,
0.02451516,0.02416618,0.0248875,0.02438786,0.02388931,
0.02553014,0.02754089,0.02685012,0.02674541,0.026058,
0.02661146,0.02608169,0.02767567,0.02715383,0.0297839,
0.02931113,0.02849885,0.02948042,0.02902629,0.02826068,
0.02776472,0.02708077,0.0275969,0.02942746,0.02939432,
0.02890609,0.02808997,0.02762202,0.02691396,0.02646187,
0.02622503])
Traceback (most recent call last): File "C:\Anaconda\envs\p33\lib\site-packages\IPython\core\interactiveshell.py",line 2732,in run_code exec(code_obj,self.user_global_ns,self.user_ns) File "<ipython-input-1-d063d30a36f8>",line 1,in <module> execfile('C:\\Users\\Jon\\workspace\\FundsAnalysis\\src\\examples\\ar-garch\\ar_garch3.py') File "C:\eclipse_kepler\plugins\org.python.pydev_2.7.5.2013052819\pysrc\_pydev_execfile.py",line 38,in execfile exec(compile(contents+"\n",file,'exec'),glob,loc) #execute the script File "C:\Users\Jon\workspace\FundsAnalysis\src\examples\ar-garch\ar_garch3.py",line 225,in <module> ar_garch.evaluate() File "C:\Users\Jon\workspace\FundsAnalysis\src\examples\ar-garch\ar_garch3.py",line 158,in evaluate self._generate_broadcasted_forecasts() File "numbawrapper.pyx",line 287,in numba.numbawrapper.BoundSpecializingWrapper.__call__ (numba\numbawrapper.c:5041) File "numbawrapper.pyx",line 189,in numba.numbawrapper._NumbaSpecializingWrapper.__call__ (numba\numbawrapper.c:3726) File "C:\Anaconda\envs\p33\lib\site-packages\numba\wrapping\compiler.py",line 68,in compile_from_args return self.compile(signature) File "C:\Anaconda\envs\p33\lib\site-packages\numba\wrapping\compiler.py",line 83,in compile compiled_function = dec(self.py_func) File "C:\Anaconda\envs\p33\lib\site-packages\numba\decorators.py",line 222,in _jit_decorator env,func,argtys,restype=return_type,nopython=nopython,**kwargs) File "C:\Anaconda\envs\p33\lib\site-packages\numba\decorators.py",line 133,in compile_function func_env = pipeline.compile2(env,restype,argtypes,**kwds) File "C:\Anaconda\envs\p33\lib\site-packages\numba\pipeline.py",line 134,in compile2 post_ast = pipeline(func_ast,env) File "C:\Anaconda\envs\p33\lib\site-packages\numba\pipeline.py",line 181,in __call__ ast = self.transform(ast,line 602,in transform ast = stage(ast,line 587,in _stage return _check_stage_object(stage_obj)(ast,line 184,line 499,in transform func_env.translator.translate() File "C:\Anaconda\envs\p33\lib\site-packages\numba\codegen\translate.py",line 314,in translate self.visit(node) File "C:\Anaconda\envs\p33\lib\site-packages\numba\codegen\translate.py",line 128,in visit return fn(node) File "C:\Anaconda\envs\p33\lib\site-packages\numba\codegen\translate.py",line 554,in visit_Assign decref=decref,incref=incref) File "C:\Anaconda\envs\p33\lib\site-packages\numba\codegen\translate.py",line 566,in generate_assign_stack lvalue = self.caster.cast(lvalue,ltarget.type.pointee) File "C:\Anaconda\envs\p33\lib\site-packages\numba\llvm_types.py",line 91,in cast return self.build_cast(self.builder,lvalue,dst_ltype,*args,**kws) File "C:\Anaconda\envs\p33\lib\site-packages\numba\llvm_types.py",line 191,in build_cast (str(lty1),str(lty2))) NotImplementedError: Unable to cast from { i64,i8* }* to { i64,i8* }.File "C:\Anaconda\envs\p33\lib\site-packages\numba\llvm_types.py",in build_castlkind1==14 lkind2==12@classmethod def build_cast(cls,builder,lval1,lty2,**kws): ret_val = lval1 lty1 = lval1.type lkind1 = lty1.kind lkind2 = lty2.kind # This looks like the wrong place to enforce this # Todo: We need to pass in the numba types instead # if lc.TYPE_INTEGER in (lkind1,lkind2) and 'unsigned' not in kws: # # Be strict about having `unsigned` define when # # we have integer types # raise ValueError("UnkNown signedness for integer type",# '%s -> %s' % (lty1,lty2),args,kws) if lkind1 == lkind2: if lkind1 in cls.CAST_MAP: ret_val = cls.CAST_MAP[lkind1](cls,**kws) else: raise NotImplementedError(lkind1) else: map_index = (lkind1,lkind2) if map_index in cls.CAST_MAP: ret_val = cls.CAST_MAP[map_index](cls,**kws) else: raise NotImplementedError('Unable to cast from %s to %s.' % (str(lty1),str(lty2))) return ret_valfrom numba import autojit import numpy as np @autojit def numba1(): return np.array( [1,2,3] ) @autojit def numba2(): x = np.array([1.0,2.0,3.0,4.0]) y = np.array([1.0,4,5.0]) z = x[1:] / y[1:-1] return np.sqrt( z ) print( numba1() ) print( numba2() )

解决方法

我在 This Examples Page的Classes部分找到了一个修复程序

要做的是在init(…)中声明self.errors

def __init__( self ):        
    self.errors = np.ndarray(0)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


我最近重新拾起了计算机视觉,借助Python的opencv还有face_recognition库写了个简单的图像识别demo,额外定制了一些内容,原本想打包成exe然后发给朋友,不过在这当中遇到了许多小问题,都解决了,记录一下踩过的坑。 1、Pyinstaller打包过程当中出现warning,跟d
说到Pooling,相信学习过CNN的朋友们都不会感到陌生。Pooling在中文当中的意思是“池化”,在神经网络当中非常常见,通常用的比较多的一种是Max Pooling,具体操作如下图: 结合图像理解,相信你也会大概明白其中的本意。不过Pooling并不是只可以选取2x2的窗口大小,即便是3x3,
记得大一学Python的时候,有一个题目是判断一个数是否是复数。当时觉得比较复杂不好写,就琢磨了一个偷懒的好办法,用异常处理的手段便可以大大程度帮助你简短代码(偷懒)。以下是判断整数和复数的两段小代码: 相信看到这里,你也有所顿悟,能拓展出更多有意思的方法~
文章目录 3 直方图Histogramplot1. 基本直方图的绘制 Basic histogram2. 数据分布与密度信息显示 Control rug and density on seaborn histogram3. 带箱形图的直方图 Histogram with a boxplot on t
文章目录 5 小提琴图Violinplot1. 基础小提琴图绘制 Basic violinplot2. 小提琴图样式自定义 Custom seaborn violinplot3. 小提琴图颜色自定义 Control color of seaborn violinplot4. 分组小提琴图 Group
文章目录 4 核密度图Densityplot1. 基础核密度图绘制 Basic density plot2. 核密度图的区间控制 Control bandwidth of density plot3. 多个变量的核密度图绘制 Density plot of several variables4. 边
首先 import tensorflow as tf tf.argmax(tenso,n)函数会返回tensor中参数指定的维度中的最大值的索引或者向量。当tensor为矩阵返回向量,tensor为向量返回索引号。其中n表示具体参数的维度。 以实际例子为说明: import tensorflow a
seaborn学习笔记章节 seaborn是一个基于matplotlib的Python数据可视化库。seaborn是matplotlib的高级封装,可以绘制有吸引力且信息丰富的统计图形。相对于matplotlib,seaborn语法更简洁,两者关系类似于numpy和pandas之间的关系,seabo
Python ConfigParser教程显示了如何使用ConfigParser在Python中使用配置文件。 文章目录 1 介绍1.1 Python ConfigParser读取文件1.2 Python ConfigParser中的节1.3 Python ConfigParser从字符串中读取数据
1. 处理Excel 电子表格笔记(第12章)(代码下载) 本文主要介绍openpyxl 的2.5.12版处理excel电子表格,原书是2.1.4 版,OpenPyXL 团队会经常发布新版本。不过不用担心,新版本应该在相当长的时间内向后兼容。如果你有新版本,想看看它提供了什么新功能,可以查看Open