mirror of
https://github.com/pytorch/pytorch.git
synced 2026-11-20 09:04:25 +08:00
ENH Adds dtype to nn.functional.one_hot (#58090)
Summary: Fixes https://github.com/pytorch/pytorch/issues/33046 Related to https://github.com/pytorch/pytorch/issues/53785 Pull Request resolved: https://github.com/pytorch/pytorch/pull/58090 Reviewed By: zou3519 Differential Revision: D28640893 Pulled By: jbschlosser fbshipit-source-id: 3686579517ccc75beaa74f0f6d167f5e40a83fd2
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e4be80c1b8
commit
a7f4f80903
@@ -1061,6 +1061,17 @@ TEST_F(FunctionalTest, OneHot) {
|
||||
ASSERT_TRUE(torch::allclose(y, expected));
|
||||
ASSERT_EQ(y.sizes(), std::vector<int64_t>({3, 2, 3}));
|
||||
}
|
||||
|
||||
{ // Test #4
|
||||
auto x = torch::arange(0, 5, torch::kLong);
|
||||
auto y = F::one_hot(x % 3, 3, torch::kUInt8);
|
||||
auto expected = torch::tensor(
|
||||
{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {1, 0, 0}, {0, 1, 0}}, torch::kUInt8);
|
||||
|
||||
ASSERT_EQ(y.ndimension(), 2);
|
||||
ASSERT_TRUE(torch::allclose(y, expected));
|
||||
ASSERT_EQ(y.sizes(), std::vector<int64_t>({5, 3}));
|
||||
}
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
|
||||
Reference in New Issue
Block a user