inlining_usecases.py 700 Bytes
Newer Older
dugupeiwen's avatar
dugupeiwen committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
""" Test cases for inlining IR from another module """
from numba import njit
from numba.core.extending import overload

_GLOBAL1 = 100


@njit(inline='always')
def bar():
    return _GLOBAL1 + 10


def baz_factory(a):
    b = 17 + a

    @njit(inline='always')
    def baz():
        return _GLOBAL1 + a - b
    return baz


def baz():
    return _GLOBAL1 + 10


@overload(baz, inline='always')
def baz_ol():
    def impl():
        return _GLOBAL1 + 10
    return impl


def bop_factory(a):
    b = 17 + a

    def bop():
        return _GLOBAL1 + a - b

    @overload(bop, inline='always')
    def baz():
        def impl():
            return _GLOBAL1 + a - b
        return impl

    return bop