How to use the julia.Main.eval function in julia

To help you get started, we’ve selected a few julia examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thautwarm / restrain-jit / tests / bejl / test_array_op.py View on Github external
# print(test_repeat_append_jit())

# print(test_repeat_append_jit_foreach())
#
# for e in (test_repeat_append_jit_foreach.__func_info__.r_codeinfo.instrs):
#     print(e)
# show_instrs(test_repeat_append_jit_foreach.__func_info__.r_codeinfo.instrs)
#
# %timeit test_repeat_append_jit()
# %timeit test_repeat_append_nojit()
# %timeit test_repeat_append_jit_foreach()

from julia import Main

tt = Main.eval("""
function tt()
    x = []
    for i in 0:9999
        push!(x, i)
    end
    x
end
""")
tt()

import timeit

print(timeit.timeit("tt()", globals=dict(tt=tt), number=1000))
print(timeit.timeit(
    "tt()", globals=dict(tt=test_repeat_append_nojit), number=1000))
github rizalzaf / ap_perf_py / metric.py View on Github external
# set package
from julia import Main

Main.eval("using AdversarialPrediction")
Main.eval("import AdversarialPrediction: define, constraint")

class Metric:
    def __init__(self, metric_str):
        self.metric_str = metric_str

        # check name and args
        name_args = metric_str.split("@metric")[1].strip().split("\n")[0].split()
        self.name = name_args[0]
        self.args = name_args[1:]

        # run on julia
        Main.eval(metric_str)

    def initialize(self, *args):
        init_str = self.name + "(" + ( ", ".join(map(str, args)) ) + ")"
github rizalzaf / ap_perf_py / metric.py View on Github external
# set package
from julia import Main

Main.eval("using AdversarialPrediction")
Main.eval("import AdversarialPrediction: define, constraint")

class Metric:
    def __init__(self, metric_str):
        self.metric_str = metric_str

        # check name and args
        name_args = metric_str.split("@metric")[1].strip().split("\n")[0].split()
        self.name = name_args[0]
        self.args = name_args[1:]

        # run on julia
        Main.eval(metric_str)

    def initialize(self, *args):
        init_str = self.name + "(" + ( ", ".join(map(str, args)) ) + ")"
        # construct metric object
github rizalzaf / ap_perf_py / metric.py View on Github external
def __init__(self, metric_str):
        self.metric_str = metric_str

        # check name and args
        name_args = metric_str.split("@metric")[1].strip().split("\n")[0].split()
        self.name = name_args[0]
        self.args = name_args[1:]

        # run on julia
        Main.eval(metric_str)
github rizalzaf / ap_perf_py / metric.py View on Github external
def initialize(self, *args):
        init_str = self.name + "(" + ( ", ".join(map(str, args)) ) + ")"
        # construct metric object
        self.pm = Main.eval(init_str)