Skip to content

Conversation

@youge325
Copy link
Contributor

@youge325 youge325 commented Feb 6, 2026

新增 reciprocal reciprocal_ detach detach_ select masked_select tensor_split split unsafe_split split_with_sizes unsafe_split_with_sizes hsplit vsplit dsplit 接口测试
image

Copilot AI review requested due to automatic review settings February 6, 2026 07:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive test coverage for various tensor operations in the ATen/PyTorch C++ API, specifically focusing on split, select, reciprocal, and detach operations.

Changes:

  • Added tests for multiple split-related operations (split, split_with_sizes, unsafe_split, unsafe_split_with_sizes, tensor_split, hsplit, vsplit, dsplit)
  • Added tests for tensor selection operations (select, select_symint)
  • Added tests for reciprocal operations (reciprocal, reciprocal_, global reciprocal function)
  • Added tests for tensor detach operations (detach, detach_)

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

File Description
test/ops/SplitTest.cpp Implements 16 test cases covering various split operations including basic split, split by sizes, unsafe split variants, tensor_split, and dimensional splits (hsplit, vsplit, dsplit)
test/ops/SelectTest.cpp Implements 10 test cases for tensor selection operations including dimension selection, negative indexing, chained selection, and SymInt variants
test/ops/ReciprocalTest.cpp Implements 5 test cases for reciprocal operations including basic reciprocal, in-place variant, various values, multi-dimensional tensors, and global function
test/ops/DetachTest.cpp Implements 5 test cases for tensor detach operations including basic detach, in-place variant, modification tests, and multi-dimensional tensors

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

FileManerger file(file_name);
file.createFile();

// 创建大小数组 tensor(Paddle要求总和等于维度大小8)
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misleading comment. The comment states "创建大小数组 tensor(Paddle要求总和等于维度大小8)" (Create size array tensor, Paddle requires sum to equal dimension size 8), but tensor_split with a tensor of indices splits at those index positions, not by sizes. The indices {2, 3, 3} will split at positions 2, 3, and 3, creating splits [0:2], [2:3], [3:3] (empty), [3:8]. If this is intentional testing behavior, the comment should clarify that these are split indices, not sizes.

Suggested change
// 创建大小数组 tensor(Paddle要求总和等于维度大小8
// 创建索引数组 tensor(Paddle 中常用于按大小切分且大小和为 8,这里在 PyTorch 中作为分割索引使用

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,221 @@
#include <ATen/ATen.h>
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description mentions adding tests for masked_select, but no test file for this function is included in the changes. Either the test file is missing, or the PR description should be updated to remove the mention of masked_select.

Copilot uses AI. Check for mistakes.
TEST_F(DetachTest, InplaceDetach) {
auto file_name = g_custom_param.get();
FileManerger file(file_name);
file.createFile();
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect file operation usage. This test uses createFile() which will overwrite the output from the previous test BasicDetach. This test should use openAppend() to append to the file, or each test should write to a completely independent file. Based on the pattern in AbsTest.cpp where only the first test uses createFile(), this should use openAppend() instead.

Suggested change
file.createFile();
file.openAppend();

Copilot uses AI. Check for mistakes.
#include <ATen/core/Tensor.h>
#include <ATen/ops/ones.h>
#include <gtest/gtest.h>
#include <torch/all.h>
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The include torch/all.h appears to be unused. This file only uses ATen APIs, and none of the code references torch namespace functions. Consider removing this unnecessary include to keep dependencies minimal.

Suggested change
#include <torch/all.h>

Copilot uses AI. Check for mistakes.
at::Tensor result = test_tensor.select(1, 2);
auto file_name = g_custom_param.get();
FileManerger file(file_name);
file.createFile();
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect file operation usage. This test uses createFile() which will overwrite the output from the previous test SelectDim0. This test should use openAppend() to append to the file, or each test should write to a completely independent file. Based on the pattern in AbsTest.cpp where only the first test uses createFile(), this should use openAppend() instead.

Suggested change
file.createFile();
file.openAppend();

Copilot uses AI. Check for mistakes.
FileManerger file(file_name);
file.createFile();

// 使用大小数组 [3, 5](总和为8,等于维度2的大小)
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misleading comment. The comment states "使用大小数组 [3, 5](总和为8,等于维度2的大小)" (Using size array [3, 5], sum is 8, equal to dimension 2 size), but dsplit with an array of integers splits at those index positions, not by sizes. dsplit({3, 5}) will split at indices 3 and 5, creating 3 splits: [:, :, 0:3], [:, :, 3:5], [:, :, 5:8]. The comment should clarify that these are split indices, not sizes.

Suggested change
// 使用大小数组 [3, 5](总和为8,等于维度2的大小)
// 在深度维度的索引 [3, 5] 处进行分割,得到三段:[0:3]、[3:5]、[5:8]

Copilot uses AI. Check for mistakes.
TEST_F(ReciprocalTest, InplaceReciprocal) {
auto file_name = g_custom_param.get();
FileManerger file(file_name);
file.createFile();
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect file operation usage. This test uses createFile() which will overwrite the output from the previous test BasicReciprocal. This test should use openAppend() to append to the file, or each test should write to a completely independent file. Based on the pattern in AbsTest.cpp where only the first test uses createFile(), this should use openAppend() instead.

Suggested change
file.createFile();
file.openAppend();

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant