Skip to content

add some compat API tests#40

Open
youge325 wants to merge 1 commit intoPFCCLab:masterfrom
youge325:cLast
Open

add some compat API tests#40
youge325 wants to merge 1 commit intoPFCCLab:masterfrom
youge325:cLast

Conversation

@youge325
Copy link
Contributor

@youge325 youge325 commented Feb 27, 2026

新增 sum、t、t_、transpose_、view_as、coalesce、is_variable、item 接口测试
image

Copilot AI review requested due to automatic review settings February 27, 2026 03:44
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

该 PR 为 ATen/compat 接口补充了一批 C++ 侧的 gtest 用例,通过将关键结果写入 /tmp/paddle_cpp_api_test/<exe>.txt 来做 Paddle/Torch 对齐验证。

Changes:

  • 新增 view_astranspose/transpose_t/t_toitemeyecoalesce 等接口的测试用例文件。
  • 扩展 SumTest.cpp,新增 Tensor::sum(...) 成员函数形式的覆盖。

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/ops/ViewAsTest.cpp 新增 view_as 形状变换与共享存储语义测试
test/ops/TransposeTest.cpp 新增 transpose/transpose_(含负维、原地)测试
test/ops/ToTest.cpp 新增 to(...) 多重载/可选参数覆盖测试
test/ops/TTest.cpp 新增 t/t_transpose 等价性测试
test/ops/SumTest.cpp 增加 Tensor::sum(...) 成员函数形式的测试覆盖
test/ops/ItemTest.cpp 新增 item() / item<T>() 标量提取测试
test/ops/EyeTest.cpp 新增 eye 不同形状/不同 dtype 的测试
test/ops/CoalesceTest.cpp 新增稀疏 COO coalesce/_nnz/_values/is_coalesced 测试

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

Comment on lines +176 to +179
at::Tensor result = test_tensor.sum(at::IntArrayRef{0, 1},
/*keepdim=*/false,
std::make_optional(at::kDouble));
file << std::to_string(result.dim()) << " ";
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

这里使用了 std::make_optional(at::kDouble),但当前文件没有包含 ,可能导致编译失败(make_optional 未声明)。建议在头部补充 #include (或改为显式构造 std::optional)。

Copilot uses AI. Check for mistakes.
Comment on lines +109 to +117
// 测试 contiguous 之后 transpose_ 数据是否正确
TEST_F(TransposeTest, TransposeInplaceData) {
auto file_name = g_custom_param.get();
FileManerger file(file_name);
file.createFile();

at::Tensor t = tensor2d.clone();
t.transpose_(0, 1);
// t[i][j] 应等于原 tensor2d[j][i]
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

注释写的是“contiguous 之后 transpose_ 数据是否正确”,但代码里并没有调用 contiguous()(只是 clone() 后直接 transpose_)。建议要么调整注释描述(例如说明 clone 得到 contiguous 再 transpose_),要么按注释预期补充 contiguous() 的调用,避免测试意图与实现不一致。

Copilot uses AI. Check for mistakes.
Comment on lines +130 to +134
float* data = v.data_ptr<float>();
float sum = 0.f;
for (int i = 0; i < v.numel(); ++i) sum += data[i];
file << std::to_string(sum) << " "; // 1 + 12 = 13
file.saveFile();
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

这里的循环变量用 int,而 v.numel() 返回 int64_t;在 -Wall 下可能触发 signed/unsigned 或窄化相关告警。建议把 i 改为 int64_t(或 auto i = int64_t{0})并与 numel() 保持同类型。

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.

2 participants