3 #include "test/cpp/jit/test_base.h" 4 #include "test/cpp/jit/test_utils.h" 10 void testAttributes() {
12 auto one = attr::alpha;
13 auto two = attr::device;
14 auto three = attr::end;
15 auto four = attr::perm;
16 Node* n = g.create(Symbol::fromQualString(
"foo::bar"));
18 attr.f_(one, 3.4)->i_(two, 5)->s_(three,
"what");
19 ASSERT_EQ(attr.f(one), 3.4);
20 ASSERT_EQ(attr.s(three),
"what");
21 ASSERT_EQ(attr.i(two), 5);
23 ASSERT_EQ(attr.s(one),
"no");
24 ASSERT_TRUE(attr.hasAttribute(three));
25 ASSERT_TRUE(!attr.hasAttribute(four));
26 attr.ss_(two, {
"hi",
"now"});
27 ASSERT_EQ(attr.ss(two).at(1),
"now");
29 Node* n2 = g.create(Symbol::fromQualString(
"foo::baz"));
31 attr2.copyAttributes(attr);
32 ASSERT_EQ(attr2.s(one),
"no");
34 ASSERT_EQ(attr.s(one),
"no");
35 ASSERT_EQ(attr2.f(one), 5);
38 void testBlocks(std::ostream& out = std::cout) {
39 auto g = std::make_shared<Graph>();
41 auto a = Var::asNewInput(*g,
"a");
42 auto b = Var::asNewInput(*g,
"b");
45 g->appendNode(g->create(prim::If, {Var::asNewInput(*g,
"c").value()}));
46 auto then_block = r->addBlock();
47 auto else_block = r->addBlock();
49 WithInsertPoint guard(then_block);
51 then_block->registerOutput(t.value());
54 WithInsertPoint guard(else_block);
57 else_block->registerOutput(e.value());
59 g->registerOutput((Var(r->output()) + c).value());
67 ->check_count(
"aten::add", 3)