Search code examples
pythonnumba

How to specify numba tuple function signature?


I would like to specify numba tuple function signature. Here is my code

@njit(boolean(Tuple(float64, 2), Tuple(float64, 4)))
def IsInside(point, box2):
    ''' Checks if point is inside box2'''
    xc, yc = point
    x1, y1, x2, y2 = box2
    return (x1 <= xc <= x2) and (y1 <= yc <= y2)

Point is a tuple (x,y) and box2 is a tuple (x1, y1, x2, y2). I have an error

_____________________________________________________________________ ERROR collecting test_boxes.py ______________________________________________________________________
test_boxes.py:6: in <module>
    import helpers.boxes as boxes
helpers/boxes.py:286: in <module>
    @njit(boolean(Tuple(float64, 2), Tuple(float64, 4)))
../../../.local/lib/python3.6/site-packages/numba/core/types/abstract.py:66: in __call__
    inst = type.__call__(cls, *args, **kwargs)
E   TypeError: __new__() takes 2 positional arguments but 3 were given

What i am doing wrong?


Solution

  • Found answer - should be

    @njit(boolean(UniTuple(float64, 2), UniTuple(float64, 4)))
    def IsInside(point, box2):
        ''' Checks if point is inside box2'''
        xc, yc = point
        x1, y1, x2, y2 = box2
        return (x1 <= xc <= x2) and (y1 <= yc <= y2)