Ejemplo n.º 1
0
import sys

testmodule = sys.modules[module_name].lib
print(testmodule.addfunc(2, 3))

######################################################################
# 4: test the mixed serialization protocol on the binary module
######################################################################

from seamless.mixed.get_form import get_form
from seamless.mixed.io import to_stream, from_stream
from seamless.mixed.io.util import is_identical_debug

storage, form = get_form(binary_module)
x = to_stream(binary_module, storage, form)
binary_module2 = from_stream(x, storage, form)

assert (is_identical_debug(binary_module, binary_module2))

######################################################################
# 5: test it in a debugging context
######################################################################

print("START")

from seamless.core import context, cell, transformer, macro_mode_on
with macro_mode_on():
    ctx = context(toplevel=True)
    ctx.module_storage = cell("text")
    ctx.module_form = cell("json")
    ctx.module = cell("mixed",
Ejemplo n.º 2
0
    ("r", np.int64),
], align=True)
dt = np.dtype([
    ("a", int),
    ("b", object),
    ("c", object),
    ("d", object),
    ("e", dt0),
], align=True)
data = np.zeros(1,dtype=dt)[0]
data["a"] = 10
data["b"] = embedded_data
data["c"] = [1,2,{"a":3, "b":4},5,[6,7]]
data["d"] = np.arange(-6, 0)

storage, form = get_form(data)
print(form, storage); print()
print("stream")
stream = to_stream(data, storage, form)
#print(stream)
newdata = from_stream(stream, storage, form)
print(newdata["a"] == data["a"])
print(newdata["b"]["arr"].tobytes() == data["b"]["arr"].tobytes())
print(newdata["b"]["arr2"].tobytes() == data["b"]["arr2"].tobytes())
print(newdata["b"]["v"].tobytes() == data["b"]["v"].tobytes())
print(newdata["b"]["z"] == data["b"]["z"])
print(newdata["c"] == data["c"])
print(newdata["d"].tobytes() == data["d"].tobytes())
print(newdata["e"] == data["e"])
print(newdata.dtype == data.dtype)
Ejemplo n.º 3
0
dt = np.dtype([
    ("a", int),
    ("b", object),
    ("c", object),
    ("d", object),
    ("e", dt0),
],
              align=True)
data = np.zeros(1, dtype=dt)[0]
data["a"] = 10
data["b"] = embedded_data
data["c"] = [1, 2, {"a": 3, "b": 4}, 5, [6, 7]]
data["d"] = np.arange(-6, 0)

storage, form = get_form(data)
print(form, storage)
print()
print("stream")
stream = to_stream(data, storage, form)
#print(stream)
newdata = from_stream(stream, storage, form)
print(newdata["a"] == data["a"])
print(newdata["b"]["arr"].tobytes() == data["b"]["arr"].tobytes())
print(newdata["b"]["arr2"].tobytes() == data["b"]["arr2"].tobytes())
print(newdata["b"]["v"].tobytes() == data["b"]["v"].tobytes())
print(newdata["b"]["z"] == data["b"]["z"])
print(newdata["c"] == data["c"])
print(newdata["d"].tobytes() == data["d"].tobytes())
print(newdata["e"] == data["e"])
print(newdata.dtype == data.dtype)
Ejemplo n.º 4
0
module_name = build_extension_cffi(binary_module, compiler_verbose=compiler_verbose)
import sys
testmodule = sys.modules[module_name].lib
print(testmodule.add(2,3))

######################################################################
# 4: test the mixed serialization protocol on the binary module
######################################################################

from seamless.mixed.get_form import get_form
from seamless.mixed.io import to_stream, from_stream
from seamless.mixed.io.util import is_identical_debug

storage, form = get_form(binary_module)
x = to_stream(binary_module, storage, form)
binary_module2 = from_stream(x, storage, form)

assert (is_identical_debug(binary_module, binary_module2))

######################################################################
# 5: test it in a context
######################################################################

from seamless.core import context, cell, transformer, macro_mode_on
with macro_mode_on():
    ctx = context(toplevel=True)
    ctx.module_storage = cell("text")
    ctx.module_form = cell("json")
    ctx.module = cell("mixed", form_cell=ctx.module_form, storage_cell=ctx.module_storage)
    ctx.module.set(binary_module, auto_form=True)
    tf = ctx.tf = transformer({
Ejemplo n.º 5
0
assert dt1.isalignedstruct
assert dt2.isalignedstruct
assert dt1["c"].subdtype

d1 = np.zeros(1, dt1)[0]
d2 = np.zeros(1, dt2)[0]
d2["c"] = np.zeros(3, float)

d1["a"] = d2["a"] = 10
d1["b"] = d2["b"] = 20
d1["c"][:] = d2["c"][:] = range(100,103)

storage1, form1 = get_form(d1)
storage2, form2 = get_form(d2)

print(storage1, form1)
print(storage2, form2)

stream1 = to_stream(d1, storage1, form1)
#print(stream1)
stream2 = to_stream(d2, storage2, form2)
#print(stream2)

newd1 = from_stream(stream1, storage1, form1)
print(newd1.tobytes() == d1.tobytes())
newd2 = from_stream(stream2, storage2, form2)
print(newd2["a"] == d2["a"])
print(newd2["b"] == d2["b"])
print(newd2["c"].tobytes() == d2["c"].tobytes())