已合并
fix: 规范示例代码格式 #4464
zhang-song-rui创建于 15 天前
fix: 规范示例代码格式 #4464
已合并
zhang-song-rui创建于 15 天前
zhang-song-rui
zhang-song-rui成员
15 天前

描述

规范 math/ 目录下相关算子的示例代码格式,不涉及功能逻辑变更:

  • CHECK_RET(..., return ret;); 统一为 CHECK_RET(..., return ret);,涉及 24 个文件、29 处。
  • 将文档中的 while(0) 统一为 while (0),涉及 less、less_equal、gcd 共 5 个文件、10 处。
  • 为 not_equal 文档中三元运算符的冒号后补充空格,涉及 2 个文件、4 处。

关联的Issue

https://gitcode.com/cann/ops-math/issues/2527

测试

  • 使用全文检索确认修改范围内无上述格式问题残留。
  • 检查 Git diff,确认共修改 31 个文件、43 处,均为格式调整。
  • 推送时 Git Hooks 检查通过。
  • 本次仅修改示例及文档格式,未执行算子功能测试。

文档更新

更新了 less、less_equal、gcd、not_equal 算子的示例文档格式;同时规范了相关算子文档及 examples 中的 CHECK_RET 写法。

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 zhang-song-rui 的贡献)
zhang-song-ruizhang-song-rui成员
15 天前 创建了 pull request,commit 309c9278
atomgit-bot
atomgit-bot
15 天前 评论:

变更摘要

此 PR 统一修正了 math 模块下 29 个示例代码文件中 CHECK_RET 宏的调用格式,移除了宏第二个参数中 return ret 语句末尾多余的分号(;),使代码风格符合 CHECK_RET 宏的规范用法。

主要改动

  • 规范 CHECK_RET 宏调用格式:在 bitwise_andbitwise_orbitwise_xorgreatermodselecttanh_grad 等多个算子的示例代码中,将 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT(...); return ret;); 统一修正为 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT(...); return ret);,去除了 return ret 后多余的独立分号。
  • 涉及 29 个文件的一致性修改:所有受影响的文件均为各算子 examples/ 目录下的 test_aclnn_*.cpp 示例文件,改动模式完全相同,均为工作空间分配失败时的错误处理分支中的 CHECK_RET 调用。
likedislike
atomgit-bot
atomgit-bot
15 天前 评论:

代码审查

现在让我完成最后的梳理(Section X-pre),检查是否有遗漏的共址次要缺陷或其他问题……所有变更均已审核。while(0)while (0) 变更纯粹是格式调整,无语法影响。核心问题 — CHECK_RET 尾随分号移除 — 已报告。


审查总结

优先级 数量 说明
P0 1 CHECK_RET(...) 宏调用移除尾随分号,导致 do { ... } while (0) 语法错误,涉及 24 个文件

逐文件审查结果

文件 结论
math/bitwise_and/docs/aclnnBitwiseAndTensor.md ⚠️ P0 — CHECK_RET 尾随分号移除
math/bitwise_and/docs/aclnnBitwiseAndTensorOut&aclnnInplaceBitwiseAndTensorOut.md ⚠️ P0 — 同上
math/bitwise_and/docs/aclnnInplaceBitwiseAndScalar.md ⚠️ P0 — 同上
math/bitwise_and/docs/aclnnInplaceBitwiseAndTensor.md ⚠️ P0 — 同上
math/bitwise_and/examples/test_aclnn_bitwise_and_tensor.cpp ⚠️ P0 — 同上(锚定文件)
math/bitwise_or/docs/aclnnBitwiseOrTensor&aclnnInplaceBitwiseOrTensor.md ⚠️ P0 — 同上
math/bitwise_or/examples/test_aclnn_bitwise_or_tensor.cpp ⚠️ P0 — 同上
math/bitwise_or/examples/test_aclnn_inplace_bitwise_or_tensor.cpp ⚠️ P0 — 同上
math/bitwise_xor/docs/aclnnBitwiseXorTensor&aclnnInplaceBitwiseXorTensor.md ⚠️ P0 — 同上
math/bitwise_xor/examples/test_aclnn_bitwise_xor_tensor.cpp ⚠️ P0 — 同上
math/bitwise_xor/examples/test_aclnn_inplace_bitwise_xor_tensor.cpp ⚠️ P0 — 同上
math/gcd/docs/aclnnGcd.md ✅ 无问题(仅 while(0)while (0) 格式调整)
math/greater/docs/aclnnGtTensor&aclnnInplaceGtTensor.md ⚠️ P0 — CHECK_RET 尾随分号移除
math/greater/examples/test_aclnn_gt_tensor.cpp ⚠️ P0 — 同上
math/greater/examples/test_aclnn_inplace_gt_tensor.cpp ⚠️ P0 — 同上
math/greater_equal/docs/aclnnGeTensor&aclnnInplaceGeTensor.md ⚠️ P0 — 同上
math/less/docs/aclnnLtScalar&aclnnInplaceLtScalar.md ✅ 无问题(仅 while(0)while (0) 格式调整)
math/less/docs/aclnnLtTensor&aclnnInplaceLtTensor.md ✅ 无问题(仅 while(0)while (0) 格式调整)
math/less_equal/docs/aclnnLeScalar&aclnnInplaceLeScalar.md ✅ 无问题(仅 while(0)while (0) 格式调整)
math/less_equal/docs/aclnnLeTensor&aclnnInplaceLeTensor.md ✅ 无问题(仅 while(0)while (0) 格式调整)
math/mod/docs/aclnnFmodScalar&aclnnInplaceFmodScalar.md ⚠️ P0 — CHECK_RET 尾随分号移除
math/mod/docs/aclnnFmodTensor&aclnnInplaceFmodTensor.md ⚠️ P0 — 同上
math/mod/examples/test_aclnn_fmod_scalar.cpp ⚠️ P0 — 同上
math/mod/examples/test_aclnn_fmod_tensor.cpp ⚠️ P0 — 同上
math/select/docs/aclnnSWhere.md ⚠️ P0 — 同上
math/select/examples/test_aclnn_s_where.cpp ⚠️ P0 — 同上
math/sub/docs/aclnnRsub.md ⚠️ P0 — 同上
math/tanh_grad/docs/aclnnTanhBackward.md ⚠️ P0 — 同上
math/tanh_grad/examples/test_aclnn_tanh_backward.cpp ⚠️ P0 — 同上

整体风险评估

高风险。 此 DIFF 在 24 个文件中移除了 CHECK_RET(...) 宏调用的尾随分号。由于 CHECK_RET 展开为 do { ... } while (0) 惯用法,缺少尾随分号会导致 C/C++ 语法错误,直接影响 .cpp 测试文件的编译以及 .md 文档中示例代码的正确性。建议回退所有移除尾随分号的更改,或改用正确的修复方式(移除宏参数 return ret; 中的分号,保留宏调用末尾的分号)。while(0)while (0) 的 5 个文件为纯粹的空白格式调整,无风险。

类型 数量
🔴 阻塞 1
🟡 建议 0

⛔ 需要修改

likedislike
CANN-robotCANN-robot成员
15 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
15 天前 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here
You can get sig-info at here


PR Approval Progress

Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
*/*/docs/acl*.md 陈娇, wangrui_, 张磊 (3/2) 陈娇 (1/1)
math/bitwise_and 宋恺, wangrui_, 张磊, 王林木 (4/2) 王林木, 宋恺, wangrui_, 张磊 (4/1)
math/bitwise_or 宋恺, wangrui_, 张磊, 王林木 (4/2) 宋恺, wangrui_, 张磊, 王林木 (4/1)
math/bitwise_xor 王林木, 宋恺, wangrui_, 张磊 (4/2) 王林木, 宋恺, wangrui_, 张磊 (4/1)
math/greater 宋恺, wangrui_, 张磊, 王林木 (4/2) 王林木, 宋恺, wangrui_, 张磊 (4/1)
math/mod 宋恺, wangrui_, 张磊, 王林木 (4/2) 王林木, 宋恺, wangrui_, 张磊 (4/1)
math/select 张磊, 王林木, 宋恺, wangrui_ (4/2) 张磊, 王林木, 宋恺, wangrui_ (4/1)
math/tanh_grad wangrui_, 张磊, 王林木, 宋恺 (4/2) wangrui_, 张磊, 王林木, 宋恺 (4/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

zhang-song-rui, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
此处折叠了51条消息 查看更多
llimwang成员
14 天前 评论:

/approve

likedislike
chenjiao成员
14 天前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
14 天前 添加了label:approved
CANN-robotCANN-robot成员
14 天前 关闭了关联的issue
CANN-robotCANN-robot成员
14 天前 合入了pull request