summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Messmer <messmer@fb.com>2019-04-23 12:43:23 -0700
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>2019-04-23 12:58:32 -0700
commitfddd763ec13a4ca941e821509eafee17f5144177 (patch)
tree627b1c9918e966f0ec9425b72d78ca428c7e8914
parentfc8834df4b9c129fb40ea26641ac8aaeeb702428 (diff)
downloadpytorch-fddd763ec13a4ca941e821509eafee17f5144177.tar.gz
pytorch-fddd763ec13a4ca941e821509eafee17f5144177.tar.bz2
pytorch-fddd763ec13a4ca941e821509eafee17f5144177.zip
Add test cases for optional of list (#19592)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/19592 This is already supported but wasn't tested yet Reviewed By: ezyang Differential Revision: D15039888 fbshipit-source-id: dc8ea724c76dd1719b1d4810a20c8f958e5beecc
-rw-r--r--aten/src/ATen/core/op_registration/op_registration_test.cpp27
1 files changed, 26 insertions, 1 deletions
diff --git a/aten/src/ATen/core/op_registration/op_registration_test.cpp b/aten/src/ATen/core/op_registration/op_registration_test.cpp
index cef5c2ab79..aabea77e14 100644
--- a/aten/src/ATen/core/op_registration/op_registration_test.cpp
+++ b/aten/src/ATen/core/op_registration/op_registration_test.cpp
@@ -483,7 +483,32 @@ TEST(OperatorRegistrationTest, testAvailableArgTypes) {
},
"(Tensor[] a) -> Tensor[]");
- // TODO We support optional of list. Add test cases for it.
+ // Test optional of list (with nullopt)
+ ArgTypeTestKernel<c10::optional<c10::ArrayRef<int64_t>>, c10::optional<std::vector<int64_t>>>::test(
+ c10::optional<c10::ArrayRef<int64_t>>(c10::nullopt), [] (c10::optional<c10::ArrayRef<int64_t>> v) {EXPECT_FALSE(v.has_value());},
+ c10::optional<std::vector<int64_t>>(c10::nullopt), [] (const IValue& v) {EXPECT_TRUE(v.isNone());});
+ ArgTypeTestKernel<c10::optional<c10::ArrayRef<int64_t>>, c10::optional<std::vector<int64_t>>>::test(
+ c10::optional<c10::ArrayRef<int64_t>>(c10::nullopt), [] (c10::optional<c10::ArrayRef<int64_t>> v) {EXPECT_FALSE(v.has_value());},
+ c10::optional<std::vector<int64_t>>(c10::nullopt), [] (const IValue& v) {EXPECT_TRUE(v.isNone());},
+ "(int[]? a) -> int[]?");
+
+ // Test optional of list (with empty list)
+ ArgTypeTestKernel<c10::optional<c10::ArrayRef<int64_t>>, c10::optional<std::vector<int64_t>>>::test(
+ c10::optional<c10::ArrayRef<int64_t>>(c10::ArrayRef<int64_t>{}), [] (c10::optional<c10::ArrayRef<int64_t>> v) {EXPECT_EQ(0, v.value().size());},
+ c10::optional<std::vector<int64_t>>(std::vector<int64_t>{}), [] (const IValue& v) {EXPECT_EQ(0, v.toIntListRef().size());});
+ ArgTypeTestKernel<c10::optional<c10::ArrayRef<int64_t>>, c10::optional<std::vector<int64_t>>>::test(
+ c10::optional<c10::ArrayRef<int64_t>>(c10::ArrayRef<int64_t>{}), [] (c10::optional<c10::ArrayRef<int64_t>> v) {EXPECT_EQ(0, v.value().size());},
+ c10::optional<std::vector<int64_t>>(std::vector<int64_t>{}), [] (const IValue& v) {EXPECT_EQ(0, v.toIntListRef().size());},
+ "(int[]? a) -> int[]?");
+
+ // Test optional of list (with values)
+ ArgTypeTestKernel<c10::optional<c10::ArrayRef<int64_t>>, c10::optional<std::vector<int64_t>>>::test(
+ c10::optional<c10::ArrayRef<int64_t>>({1, 2}), [] (c10::optional<c10::ArrayRef<int64_t>> v) {EXPECT_EQ(c10::ArrayRef<int64_t>({1, 2}), v.value());},
+ c10::optional<std::vector<int64_t>>({3, 4}), [] (const IValue& v) {EXPECT_EQ(std::vector<int64_t>({3, 4}), v.toIntListRef());});
+ ArgTypeTestKernel<c10::optional<c10::ArrayRef<int64_t>>, c10::optional<std::vector<int64_t>>>::test(
+ c10::optional<c10::ArrayRef<int64_t>>({1, 2}), [] (c10::optional<c10::ArrayRef<int64_t>> v) {EXPECT_EQ(c10::ArrayRef<int64_t>({1, 2}), v.value());},
+ c10::optional<std::vector<int64_t>>({3, 4}), [] (const IValue& v) {EXPECT_EQ(std::vector<int64_t>({3, 4}), v.toIntListRef());},
+ "(int[]? a) -> int[]?");
// TODO Do we want to support list of optional ?