mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 00:21:07 +01:00
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/67766 Test Plan: `build/bin/test_lazy` Reviewed By: wconstab Differential Revision: D32147676 Pulled By: desertfire fbshipit-source-id: 528b48c9cf789abc171235091c7146b2ab7a9c76
43 lines
1.5 KiB
C++
43 lines
1.5 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include <c10/util/Exception.h>
|
|
#include <torch/csrc/lazy/core/permutation_util.h>
|
|
|
|
namespace torch {
|
|
namespace lazy {
|
|
|
|
TEST(PermutationUtilTest, TestInversePermutation) {
|
|
EXPECT_EQ(InversePermutation({0}), std::vector<int64_t>({0}));
|
|
EXPECT_EQ(InversePermutation({0, 1, 2}), std::vector<int64_t>({0, 1, 2}));
|
|
EXPECT_EQ(
|
|
InversePermutation({1, 3, 2, 0}), std::vector<int64_t>({3, 0, 2, 1}));
|
|
// Not a valid permutation
|
|
EXPECT_THROW(InversePermutation({-1}), c10::Error);
|
|
EXPECT_THROW(InversePermutation({1, 1}), c10::Error);
|
|
}
|
|
|
|
TEST(PermutationUtilTest, TestIsPermutation) {
|
|
EXPECT_TRUE(IsPermutation({0}));
|
|
EXPECT_TRUE(IsPermutation({0, 1, 2, 3}));
|
|
EXPECT_FALSE(IsPermutation({-1}));
|
|
EXPECT_FALSE(IsPermutation({5, 3}));
|
|
EXPECT_FALSE(IsPermutation({1, 2, 3}));
|
|
}
|
|
|
|
TEST(PermutationUtilTest, TestPermute) {
|
|
EXPECT_EQ(
|
|
Permute({0}, std::vector<int64_t>({224})), std::vector<int64_t>({224}));
|
|
EXPECT_EQ(
|
|
Permute({1, 2, 0}, std::vector<int64_t>({3, 224, 224})),
|
|
std::vector<int64_t>({224, 224, 3}));
|
|
// Not a valid permutation
|
|
EXPECT_THROW(Permute({-1}, std::vector<int64_t>({244})), c10::Error);
|
|
EXPECT_THROW(Permute({3, 2}, std::vector<int64_t>({244})), c10::Error);
|
|
// Permutation size is different from the to-be-permuted vector size
|
|
EXPECT_THROW(Permute({0, 1}, std::vector<int64_t>({244})), c10::Error);
|
|
EXPECT_THROW(Permute({0}, std::vector<int64_t>({3, 244, 244})), c10::Error);
|
|
}
|
|
|
|
} // namespace lazy
|
|
} // namespace torch
|