def f(x): nonlocal buf neg = ops.Elemwise(Elemwise.Mode.NEGATE) (x, ) = apply(neg, x) buf = x.numpy() (x, ) = apply(neg, x) return x
def f(x): nonlocal buf neg = ops.Elemwise(mode="negate") (x, ) = apply(neg, x) buf = x.numpy() (x, ) = apply(neg, x) return x
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
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)
def f(a, b): op = ops.Elemwise(Elemwise.Mode.ADD) (y, ) = apply(op, a, b) return y
def f(x): op = ops.Elemwise(Elemwise.Mode.NEGATE) (y, ) = apply(op, x) return y
def f(): (b, ) = apply(ops.Broadcast(), a, tensor([1, 10], dtype=np.int32)) return b
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
def f(a, b): op = ops.Elemwise(mode="add") (y, ) = apply(op, a, b) return y
def f(x): op = ops.Elemwise(mode="negate") (y, ) = apply(op, x) return y
def f(x): op = ops.Elemwise(mode="mul") (y, ) = apply(op, x, p) return y
def typecvt(x, dt=None): (y,) = apply(ops.TypeCvt(param=dt), x) return y