MCPcopy Index your code
hub / github.com/apache/tvm / FunctionTest

Class FunctionTest

jvm/core/src/test/java/org/apache/tvm/FunctionTest.java:25–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23import org.junit.Test;
24
25public class FunctionTest {
26 @Test
27 public void test_reg_sum_number() {
28 Function.register("sum_number", new Function.Callback() {
29 @Override
30 public Object invoke(TVMValue... args) {
31 long res = 0L;
32 for (TVMValue arg : args) {
33 res += arg.asLong();
34 }
35 return res;
36 }
37 });
38 Function func = Function.getFunction("sum_number");
39 TVMValue res = func.pushArg(10).pushArg(20).invoke();
40 assertEquals(30, res.asLong());
41 res.release();
42 func.release();
43 }
44
45 @Test
46 public void test_add_string() {
47 System.err.println("[TEST] test_add_string");
48
49 Function func = Function.convertFunc(new Function.Callback() {
50 @Override
51 public Object invoke(TVMValue... args) {
52 String res = "";
53 for (TVMValue arg : args) {
54 res += arg.asString();
55 }
56 return res;
57 }
58 });
59 TVMValue res = func.pushArg("Hello").pushArg(" ").pushArg("World!").invoke();
60 assertEquals("Hello World!", res.asString());
61 res.release();
62 func.release();
63 }
64
65 @Test
66 public void test_sum_first_byte() {
67 Function func = Function.convertFunc(new Function.Callback() {
68 @Override
69 public Object invoke(TVMValue... args) {
70 byte[] bt = new byte[1];
71 for (TVMValue arg : args) {
72 bt[0] += arg.asBytes()[0];
73 }
74 return bt;
75 }
76 });
77 TVMValue res = func.pushArg(new byte[] {1}).pushArg(new byte[] {2, 3}).invoke();
78 assertArrayEquals(new byte[] {3}, res.asBytes());
79 res.release();
80 func.release();
81 }
82

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…