How to use test_apply method in pyshould

Best Python code snippet using pyshould_python

test_topi_math.py

Source:test_topi_math.py Github

copy

Full Screen

...11 m = tvm.var('m')12 l = tvm.var('l')13 A = tvm.placeholder((m, l), name='A')14 shape = (20, 3)15 def test_apply(func, name, f_numpy, low, high):16 B = func(A)17 assert tuple(B.shape) == tuple(A.shape)18 assert B.op.body[0].name == name19 a_np = np.random.uniform(low=low, high=high, size=shape).astype(A.dtype) * 1020 b_np = f_numpy(a_np)21 def check_device(device):22 ctx = tvm.context(device, 0)23 if not ctx.exist:24 print("Skip because %s is not enabled" % device)25 return26 print("Running on target: %s" % device)27 with tvm.target.create(device):28 s = topi.generic.schedule_injective(B)29 foo = tvm.build(s, [A, B], device, name=name)30 a = tvm.nd.array(a_np, ctx)31 b = tvm.nd.array(np.zeros_like(b_np), ctx)32 foo(a, b)33 np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5, atol=1e-5)34 for device in ['cuda', 'opencl', 'metal', 'rocm', 'vulkan', 'llvm', 'nvptx', 'sdaccel',35 'aocl_sw_emu']:36 check_device(device)37 test_apply(topi.floor, "floor", np.floor, -100, 100)38 test_apply(topi.ceil, "ceil", np.ceil, -100, 100)39 test_apply(topi.trunc, "trunc", np.trunc, -100, 100)40 test_apply(topi.abs, "fabs", np.abs, -100, 100)41 test_apply(topi.round, "round", np.round, -100, 100)42 test_apply(topi.exp, "exp", np.exp, -1, 1)43 test_apply(topi.tanh, "tanh", np.tanh, -10, 10)44 test_apply(topi.sigmoid, "sigmoid", lambda x:1/(1+np.exp(-x)), -1, 1)45 test_apply(topi.log, "log", np.log, 0, 100)46 test_apply(topi.sqrt, "sqrt", np.sqrt, 0, 100)47if __name__ == "__main__":48 test_util()...

Full Screen

Full Screen

test_topi_basic.py

Source:test_topi_basic.py Github

copy

Full Screen

...25def test_ewise():26 m = te.var('m')27 l = te.var('l')28 A = te.placeholder((m, l), name='A')29 def test_apply(func, name):30 B = func(A)31 assert tuple(B.shape) == tuple(A.shape)32 assert B.op.body[0].op.name == "tir." + name33 test_apply(topi.exp, "exp")34 test_apply(topi.erf, "erf")35 test_apply(topi.tanh, "tanh")36 test_apply(topi.sigmoid, "sigmoid")37 test_apply(topi.log, "log")38 test_apply(topi.sqrt, "sqrt")39 test_apply(topi.rsqrt, "rsqrt")40 test_apply(topi.sin, "sin")41 test_apply(topi.cos, "cos")42 test_apply(topi.tan, "tan")43 test_apply(topi.atan, "atan")44if __name__ == "__main__":45 test_util()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyshould automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful