Beispiel #1
0
 def f(x):
     nonlocal buf
     neg = ops.Elemwise(Elemwise.Mode.NEGATE)
     (x, ) = apply(neg, x)
     buf = x.numpy()
     (x, ) = apply(neg, x)
     return x
Beispiel #2
0
 def f(x):
     nonlocal buf
     neg = ops.Elemwise(mode="negate")
     (x, ) = apply(neg, x)
     buf = x.numpy()
     (x, ) = apply(neg, x)
     return x
Beispiel #3
0
 def f(x):
     neg = ops.Elemwise(Elemwise.Mode.NEGATE)
     (x, ) = apply(neg, x)
     with exclude_from_trace():
         if i % 2:
             (x, ) = apply(neg, x)
     (x, ) = apply(neg, x)
     return x
Beispiel #4
0
 def f(x):
     neg = ops.Elemwise(mode="negate")
     (x, ) = apply(neg, x)
     with exclude_from_trace():
         if i % 2:
             (x, ) = apply(neg, x)
     (x, ) = apply(neg, x)
     return x
def test_raw_tensor():
    from megengine.core.ops.builtin import Elemwise
    from megengine.core.tensor.raw_tensor import as_raw_tensor

    x = np.random.rand(10).astype("float32")
    xx = as_raw_tensor(x)
    (yy,) = apply(Elemwise(Elemwise.Mode.MUL), xx, xx)
    np.testing.assert_allclose(x * x, yy.numpy())
    (yy,) = apply(Elemwise(Elemwise.Mode.MUL), xx, xx)
    np.testing.assert_allclose(x * x, yy.numpy())
def invoke_op(op, inputs_, cvt_inputs=canonize_inputs):
    inputs = cvt_inputs(
        inputs_, config=megengine.core._imperative_rt.OperatorNodeConfig())
    return apply(op, *inputs)
Beispiel #7
0
 def f(a, b):
     op = ops.Elemwise(Elemwise.Mode.ADD)
     (y, ) = apply(op, a, b)
     return y
Beispiel #8
0
 def f(x):
     op = ops.Elemwise(Elemwise.Mode.NEGATE)
     (y, ) = apply(op, x)
     return y
Beispiel #9
0
 def f():
     (b, ) = apply(ops.Broadcast(), a, tensor([1, 10], dtype=np.int32))
     return b
Beispiel #10
0
 def f(x):
     op = ops.Elemwise(Elemwise.Mode.MUL)
     (y, ) = apply(op, x, p)
     return y
 def assert_equal(expect, real, **kwargs):
     op = builtin.AssertEqual(**kwargs)
     (res, ) = apply(op, expect, real)
     return res
Beispiel #12
0
 def f(a, b):
     op = ops.Elemwise(mode="add")
     (y, ) = apply(op, a, b)
     return y
Beispiel #13
0
 def f(x):
     op = ops.Elemwise(mode="negate")
     (y, ) = apply(op, x)
     return y
Beispiel #14
0
 def f(x):
     op = ops.Elemwise(mode="mul")
     (y, ) = apply(op, x, p)
     return y
Beispiel #15
0
 def typecvt(x, dt=None):
     (y,) = apply(ops.TypeCvt(param=dt), x)
     return y