@@ -303,6 +303,24 @@ TEST_F(TakeTest, TakeExceptionBelowNegativeNumel) {
303303 file.saveFile ();
304304}
305305
306+ TEST_F (TakeTest, TakeCudaNegativeIndex) {
307+ at::Tensor t = make_test_tensor (at::kFloat );
308+ at::Tensor index = make_index_tensor ({-1 });
309+
310+ auto file_name = g_custom_param.get ();
311+ FileManerger file (file_name);
312+ file.openAppend ();
313+ file << " TakeCudaNegativeIndex " ;
314+ try {
315+ at::Tensor result = at::take (t.cuda (), index.cuda ());
316+ write_result_to_file (&file, result.cpu ());
317+ } catch (const std::exception&) {
318+ file << " exception " ;
319+ }
320+ file << " \n " ;
321+ file.saveFile ();
322+ }
323+
306324TEST_F (TakeTest, TakeCudaExceptionAtNumel) {
307325 at::Tensor t = make_test_tensor (at::kFloat );
308326 at::Tensor index = make_index_tensor ({t.numel ()});
@@ -321,5 +339,23 @@ TEST_F(TakeTest, TakeCudaExceptionAtNumel) {
321339 file.saveFile ();
322340}
323341
342+ TEST_F (TakeTest, TakeCudaExceptionBelowNegativeNumel) {
343+ at::Tensor t = make_test_tensor (at::kFloat );
344+ at::Tensor index = make_index_tensor ({-t.numel () - 1 });
345+
346+ auto file_name = g_custom_param.get ();
347+ FileManerger file (file_name);
348+ file.openAppend ();
349+ file << " TakeCudaExceptionBelowNegativeNumel " ;
350+ try {
351+ at::Tensor result = at::take (t.cuda (), index.cuda ());
352+ write_result_to_file (&file, result.cpu ());
353+ } catch (const std::exception&) {
354+ file << " exception " ;
355+ }
356+ file << " \n " ;
357+ file.saveFile ();
358+ }
359+
324360} // namespace test
325361} // namespace at
0 commit comments