Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numba error: NotImplementedError: Unable to cast from { i64, i8* }* to { i64, i8* }

I am getting a strange error with numba.

I am using Anacondas, Python 3.3

The function I am trying to autojit is

@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   

The data is:

self.residuals
Out[1]: 
array([ 0.00027274,  0.06000376,  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])

self.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])

The full error is:

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, func, 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, env)
  File "C:\Anaconda\envs\p33\lib\site-packages\numba\pipeline.py", line 602, in transform
    ast = stage(ast, env)
  File "C:\Anaconda\envs\p33\lib\site-packages\numba\pipeline.py", line 587, in _stage
    return _check_stage_object(stage_obj)(ast, env)
  File "C:\Anaconda\envs\p33\lib\site-packages\numba\pipeline.py", line 184, in __call__
    ast = self.transform(ast, env)
  File "C:\Anaconda\envs\p33\lib\site-packages\numba\pipeline.py", 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* }.

Setting a breakpoit in

   File "C:\Anaconda\envs\p33\lib\site-packages\numba\llvm_types.py", line 191, in build_cast

line 190, I look a few lines before and find the error is triggered because

lkind1==14
lkind2==12

Unfortunately, I do not know enough about numba to understand what that means.

For completeness, the function where the error occurs is:

@classmethod
def build_cast(cls, builder, lval1, lty2, *args, **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, builder, lval1, lty2,
                                           *args, **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, builder, lval1, lty2,
                                              *args, **kws)
        else:
            raise NotImplementedError('Unable to cast from %s to %s.' %
                                      (str(lty1), str(lty2)))
    return ret_val

What am I doing wrong? I tried making a code snippet to post here, but cannot reproduce the error. i.e. the below works on my machine:

from 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,2.0,3.0,4,5.0])    
    z = x[1:] / y[1:-1]    
    return np.sqrt( z )


print( numba1() )
print( numba2() )
like image 894
Ginger Avatar asked Oct 20 '22 17:10

Ginger


1 Answers

I found a fix from the Classes section of This Examples Page

What I had to do was declare self.errors in init(...)

i.e.

def __init__( self ):        
    self.errors = np.ndarray(0)
like image 69
Ginger Avatar answered Oct 23 '22 11:10

Ginger