mirror of
https://github.com/pytorch/pytorch.git
synced 2026-11-20 09:04:25 +08:00
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:
committed by
Facebook Github Bot
parent
93d5503f34
commit
d5b7138a2c
@@ -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>());
|
||||
|
||||
Reference in New Issue
Block a user