Dict is a reference type (#20669)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/20669

Before, Dict was a value type, i.e. copying it did a deep copy.
Unfortunately, this doesn't work well with storing and passing Dicts around in IValues because IValues are reference types.
This diff changes Dict to be a reference type.

Reviewed By: dzhulgakov

Differential Revision: D15404911

fbshipit-source-id: dc990d3eb7cae044b74dd0253f8b704dde6a6c86
This commit is contained in:
Sebastian Messmer
2019-05-23 15:18:32 -07:00
committed by Facebook Github Bot
parent 93d5503f34
commit d5b7138a2c
19 changed files with 367 additions and 259 deletions
+1 -1
View File
@@ -93,7 +93,7 @@ TEST(TorchScriptTest, TestDictArgMatching) {
def dict_op(a: Dict[str, Tensor], b: str):
return a[b]
)JIT");
c10::impl::GenericDict dict;
c10::impl::GenericDictPtr dict = c10::impl::make_generic_dict();
dict.insert("hello", torch::ones({2}));
auto output = module->run_method("dict_op", dict, std::string("hello"));
ASSERT_EQ(1, output.toTensor()[0].item<int64_t>());