a_dict = {'a': torch.ones(1), 'b': torch.ones(1) + 1, 'c': torch.ones(1) + 2}
self.checkScript(fn, (a_dict, ('a', 'c')))
+ def test_tensor_import_export(self):
+ @torch.jit.script
+ def foo(x):
+ a = torch.tensor(1)
+ b = torch.tensor([1, 2])
+ c = [a, b]
+ return c
+
+ self.run_pass('constant_propagation', foo.graph)
+ m = torch.jit.ScriptModule()
+ m._create_method_from_graph("forward", foo.graph)
+ self.getExportImportCopy(m)
+
class MnistNet(nn.Module):
def __init__(self):
} else if (!values.empty()) {
elem_type = values.at(0)->type();
}
+
+ // Tensors are special because they have dymnamic properties. So any
+ // list containing tensors should be typed with the unified typeof all
+ // the elements.
+ if (elem_type->isSubtypeOf(TensorType::get())) {
+ for (const auto& value : values) {
+ elem_type = unifyTypes(elem_type, value->type()).value();
+ }
+ }
for (auto v : values) {
if (!v->type()->isSubtypeOf(elem_type)) {
throw ErrorReport(tree)