mirror of
https://github.com/pytorch/pytorch.git
synced 2026-11-20 09:04:25 +08:00
Support for NamedTuple (#21428)
Summary: Resolves https://github.com/pytorch/lockdown/issues/18 This implements NamedTuple by taking advantage of the existing `names` field in `TupleType`. TODO: This currently doesn't retain the NamedTuple-ness through serialization. Discussed with suo offline, we can probably make a way to define an anonymous NamedTuple in script (e.g. `NamedTuple('Foo', [('a', int), ('b', float), ('c', List[float])])` and serialize that TODO: implement support for calling the constructor with kwargs Pull Request resolved: https://github.com/pytorch/pytorch/pull/21428 Differential Revision: D15741564 Pulled By: jamesr66a fbshipit-source-id: c077cbcea1880675ca6deb340a9ec78f824a136c
This commit is contained in:
committed by
Facebook Github Bot
parent
ac8d1a1f76
commit
4bcc72fe95
@@ -106,7 +106,7 @@ TEST(TorchScriptTest, TestTupleArgMatching) {
|
||||
)JIT");
|
||||
|
||||
std::vector<int64_t> int_list = {1};
|
||||
auto tuple_generic_list = c10::ivalue::TuplePtr::create({ int_list });
|
||||
auto tuple_generic_list = c10::ivalue::Tuple::create({ int_list });
|
||||
|
||||
// doesn't fail on arg matching
|
||||
module->run_method("tuple_op", tuple_generic_list);
|
||||
@@ -122,7 +122,7 @@ TEST(TorchScriptTest, TestOptionalArgMatching) {
|
||||
return a[0]
|
||||
)JIT");
|
||||
|
||||
auto optional_tuple = c10::ivalue::TuplePtr::create({2, std::string("hi")});
|
||||
auto optional_tuple = c10::ivalue::Tuple::create({2, std::string("hi")});
|
||||
|
||||
ASSERT_EQ(2, module->run_method("optional_tuple_op", optional_tuple).toInt());
|
||||
ASSERT_EQ(
|
||||
|
||||
Reference in New Issue
Block a user