def compile_rc_model_sia():
    import cea.demand.rc_model_SIA
    reload(cea.demand.rc_model_SIA)
    cc = CC('rc_model_sia_cc')

    # cc.export('calc_h_ec', "f8(f8)")(cea.demand.rc_model_SIA.calc_h_ec)
    # cc.export('calc_h_ac', "f8(f8)")(cea.demand.rc_model_SIA.calc_h_ac)
    # cc.export('calc_h_ea', "f8(f8, f8, f8)")(cea.demand.rc_model_SIA.calc_h_ea)
    # cc.export('calc_f_sc', "f8(f8, f8, f8, f8)")(cea.demand.rc_model_SIA.calc_f_sc)
    cc.export('calc_phi_m', "f8(f8, f8, f8, f8, f8, f8, f8)")(
        cea.demand.rc_model_SIA.calc_phi_m)
    cc.export('calc_phi_c', "f8(f8, f8, f8, f8, f8, f8, f8)")(
        cea.demand.rc_model_SIA.calc_phi_c)
    cc.export('calc_theta_c', "f8(f8, f8, f8, f8, f8, f8, f8, f8, f8)")(
        cea.demand.rc_model_SIA.calc_theta_c)
    cc.export('calc_phi_m_tot',
              "f8(f8, f8, f8, f8, f8, f8, f8, f8, f8, f8, f8, f8)")(
                  cea.demand.rc_model_SIA.calc_phi_m_tot)
    cc.export('calc_phi_a',
              "f8(f8, f8, f8, f8, f8)")(cea.demand.rc_model_SIA.calc_phi_a)
    cc.export('calc_theta_m',
              "f8(f8, f8)")(cea.demand.rc_model_SIA.calc_theta_m)
    cc.export('calc_h_ea', "f8(f8, f8, f8)")(cea.demand.rc_model_SIA.calc_h_ea)
    cc.export('calc_theta_m_t',
              "f8(f8, f8, f8, f8, f8)")(cea.demand.rc_model_SIA.calc_theta_m_t)
    cc.export('calc_theta_ea',
              "f8(f8, f8, f8, f8, f8)")(cea.demand.rc_model_SIA.calc_theta_ea)
    cc.export('calc_h_em', "f8(f8, f8)")(cea.demand.rc_model_SIA.calc_h_em)
    cc.export('calc_h_3', "f8(f8, f8)")(cea.demand.rc_model_SIA.calc_h_3)

    cc.compile()
def compile_storagetank():
    import cea.technologies.storage_tank
    reload(cea.technologies.storage_tank)
    cc = CC('storagetank_cc')

    cc.export('ode', "f8(f8[:], f8, f8, f8, f8, f8, f8, f8)")(cea.technologies.storage_tank.ode_hot_water_tank)

    cc.compile()
def compile_radiators():
    import cea.technologies.radiators
    reload(cea.technologies.radiators)
    cc = CC('calc_radiator')

    cc.export('fh', "f8(f8, f8, f8, f8, f8, f8, f8)")(cea.technologies.radiators.fh)
    cc.export('lmrt', "f8(f8, f8, f8)")(cea.technologies.radiators.lmrt)

    cc.compile()
def compile_radiators():
    import cea.technologies.radiators
    reload(cea.technologies.radiators)
    cc = CC('calc_radiator')

    cc.export('fh', "f8(f8, f8, f8, f8, f8, f8, f8)")(cea.technologies.radiators.fh)
    cc.export('lmrt', "f8(f8, f8, f8)")(cea.technologies.radiators.lmrt)

    cc.compile()
Esempio n. 5
0
def compile_modules():
    from numba.pycc import CC

    cc = CC("aot")

    # collect AOT-compiled modules
    directory = os.path.dirname(os.path.abspath(__file__))
    for importer, module_name, _ in pkgutil.walk_packages([directory]):
        if module_name not in {"cc", "aot"}:
            module = importer.find_module(module_name).load_module(module_name)
            for function_name, (function, signature) in module.exports.items():
                cc.export(function_name, signature)(function)

    cc.compile()
def compile_sensible_loads():
    import cea.demand.sensible_loads
    reload(cea.demand.sensible_loads)
    cc = CC('calc_tm')

    cc.export('calc_tm', "UniTuple(f8, 2)(f8, f8, f8, f8, f8)")(cea.demand.sensible_loads.calc_tm)
    cc.export('calc_ts', "f8(f8, f8, f8, f8, i4, f8, f8, f8, f8)")(cea.demand.sensible_loads.calc_ts)
    cc.export('calc_ts_tabs', "f8(f8, f8, f8, f8, i4, f8, f8, f8, f8)")(cea.demand.sensible_loads.calc_ts_tabs)
    cc.export('calc_ta', "f8(f8, f8, i4, f8, f8, f8)")(cea.demand.sensible_loads.calc_ta)
    cc.export('calc_ta_tabs', "f8(f8, f8, i4, f8, f8, f8)")(cea.demand.sensible_loads.calc_ta_tabs)
    cc.export('calc_top', "f8(f8, f8)")(cea.demand.sensible_loads.calc_top)
    cc.export('calc_Im_tot', "f8(f8, f8, f8, f8, f8, f8, f8, f8, i4, f8, f8)")(cea.demand.sensible_loads.calc_Im_tot)
    cc.export('calc_Im_tot_tabs', "f8(f8, f8, f8, f8, f8, f8, f8, f8, i4, f8, f8)")(cea.demand.sensible_loads.calc_Im_tot_tabs)

    cc.compile()
Esempio n. 7
0
def aot_compile(file_name):
    """

    :param file_name:
    :return:
    """
    cc = CC(config['module_name'])
    func = []
    signatures = []
    if os.path.exists(config['example']):
        f = os.open(config['example'], os.O_RDONLY)
        stdin_bk = os.dup(0)
        os.dup2(f, 0)
        try:
            module = runpy.run_module(file_name, run_name="__main__")
            for k in module:
                e = module[k]
                if type(e) == numba.targets.registry.CPUDispatcher \
                        and e.nopython_signatures:
                    cc.export(k, e.nopython_signatures[0])(e)
                    func.append(k)
                    signatures.append(str(e.nopython_signatures[0]))
            auto_jit = True
        finally:
            os.dup2(stdin_bk, 0)
            os.close(f)
    else:
        module = importlib.import_module(file_name)
        for dir_ in dir(module):
            e = eval('module.' + dir_)
            if type(e) == numba.targets.registry.CPUDispatcher \
                    and e.nopython_signatures:
                cc.export(dir_, e.nopython_signatures[0])(e)
                func.append(dir_)
                signatures.append(str(e.nopython_signatures[0]))
        auto_jit = False

    cc.output_dir = os.curdir
    if func:
        cc.compile()
    return cc, func, signatures, auto_jit
Esempio n. 8
0
def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(
            f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}"
        )
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr)
Esempio n. 9
0
def compile_sensible_loads():
    import cea.demand.sensible_loads
    reload(cea.demand.sensible_loads)
    cc = CC('calc_tm')

    cc.export('calc_tm', "UniTuple(f8, 2)(f8, f8, f8, f8, f8)")(
        cea.demand.sensible_loads.calc_tm)
    cc.export('calc_ts', "f8(f8, f8, f8, f8, i4, f8, f8, f8, f8)")(
        cea.demand.sensible_loads.calc_ts)
    cc.export('calc_ts_tabs', "f8(f8, f8, f8, f8, i4, f8, f8, f8, f8)")(
        cea.demand.sensible_loads.calc_ts_tabs)
    cc.export('calc_ta',
              "f8(f8, f8, i4, f8, f8, f8)")(cea.demand.sensible_loads.calc_ta)
    cc.export('calc_ta_tabs', "f8(f8, f8, i4, f8, f8, f8)")(
        cea.demand.sensible_loads.calc_ta_tabs)
    cc.export('calc_top', "f8(f8, f8)")(cea.demand.sensible_loads.calc_top)
    cc.export('calc_Im_tot', "f8(f8, f8, f8, f8, f8, f8, f8, f8, i4, f8, f8)")(
        cea.demand.sensible_loads.calc_Im_tot)
    cc.export('calc_Im_tot_tabs',
              "f8(f8, f8, f8, f8, f8, f8, f8, f8, i4, f8, f8)")(
                  cea.demand.sensible_loads.calc_Im_tot_tabs)

    cc.compile()
Esempio n. 10
0
            y = 5 * v
            dist_y = dist_x + (-dist_x) % K
            if dist_y < dist[y]:
                dist[y] = dist_y
                heappush(q, B * dist_y + y)
    x = dist[5 * T]
    if x == INF:
        return -1
    return dist[5 * T] // K


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', '(b1[:],i8,i8,i8,i8,i8)')(main)
    cc.compile()
    exit()
from my_module import main

H, W, K = map(int, readline().split())
x1, y1, x2, y2 = map(int, readline().split())

C = np.zeros((H + 2, W + 2), np.bool_)
C[1:-1, 1:-1] = np.frombuffer(read(), 'S1').reshape(H, -1)[:, :W] == b'.'
C = C.ravel()
H += 2
W += 2

S = W * x1 + y1
T = W * x2 + y2
Esempio n. 11
0
@numba.njit
def _stats_variance_1d_2d(data, ddof=0):
    a_a, b_b = 0, 0
    for i in data:
        a_a = a_a + i
        b_b = b_b + i * i
    var = b_b / (len(data)) - ((a_a / (len(data)))**2)
    var = var * (len(data) / (len(data) - ddof))
    return var


@module.export("stats_variance_2d", "f8[:](f8[:,:],i8,i8)")
def stats_variance_2d(data, ddof=0, axis=1):
    """Pre compiled method to get 2d variance."""
    a_a, b_b = data.shape
    if axis == 1:
        var = np.zeros(a_a)
        for i in range(a_a):
            var[i] = _stats_variance_1d_2d(data[i], ddof=ddof)
        return var
    else:
        var = np.zeros(b_b)
        for i in range(b_b):
            var[i] = _stats_variance_1d_2d(data[:, i], ddof=ddof)
        return var


if __name__ == "__main__":
    module.compile()
Esempio n. 12
0
    iter_diff = l2_target + 1

    n = 0
    while iter_diff > l2_target and n <= 500:
        pn = p.copy()
        for i in range(1, I - 1):
            for j in range(1, J - 1):
                p[i, j] = (.25 * (pn[i, j + 1] +
                                  pn[i, j - 1] +
                                  pn[i + 1, j] +
                                  pn[i - 1, j]) -
                                  b[i, j])

        for i in range(I):
            p[i, 0] = p[i, 1]
            p[i, -1] = 0

        for j in range(J):
            p[0, j] = p[1, j]
            p[-1, j] = p[-2, j]

        if n % 10 == 0:
            iter_diff = sqrt(numpy.sum((p - pn)**2)/numpy.sum(pn**2))

        n += 1

    return p

cc.compile()
Esempio n. 13
0
def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
Esempio n. 14
0
def cc_export():
    from numba.pycc import CC

    cc = CC("my_module")
    cc.export("solve", "(i8[:],)")(solve)
    cc.compile()
Esempio n. 15
0
def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', 'i8(i8[:])')(main)
    cc.compile()