Skip to content

Commit e06d4bb

Browse files
committed
Added interpolate C++ API tests for nearest-exact and anti-alias options
1 parent 6a0b746 commit e06d4bb

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

test/cpp/api/functional.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,6 +2117,33 @@ TEST_F(FunctionalTest, Interpolate) {
21172117
"align_corners option can only be set with the "
21182118
"interpolating modes: linear | bilinear | bicubic | trilinear");
21192119
}
2120+
{
2121+
auto tensor = torch::rand({2, 3, 32, 32});
2122+
std::vector<int64_t> osize = {8, 10};
2123+
auto expected = at::native::_upsample_nearest_exact2d(tensor, osize, torch::nullopt);
2124+
2125+
auto options = F::InterpolateFuncOptions()
2126+
.size(osize)
2127+
.mode(torch::kNearestExact)
2128+
.align_corners(false);
2129+
auto output = F::interpolate(tensor, options);
2130+
2131+
ASSERT_TRUE(output.allclose(expected));
2132+
}
2133+
{
2134+
auto tensor = torch::rand({2, 3, 32, 32});
2135+
std::vector<int64_t> osize = {8, 10};
2136+
auto expected = at::native::_upsample_bilinear2d_aa(tensor, osize, false, torch::nullopt);
2137+
2138+
auto options = F::InterpolateFuncOptions()
2139+
.size(osize)
2140+
.mode(torch::kBilinear)
2141+
.align_corners(false)
2142+
.antialias(true);
2143+
auto output = F::interpolate(tensor, options);
2144+
ASSERT_TRUE(output.allclose(expected));
2145+
2146+
}
21202147
}
21212148

21222149
TEST_F(FunctionalTest, Pad) {

0 commit comments

Comments
 (0)