Co-authored-by: zhoupeng<zp2165064878@163.com> # message auto-generated for no-merge-commit merge: !42607 merge clang-format-1 into master [master][Fix] Fix static check errors detected by clang-format Created-by: thickhair Commit-by: zhoupeng Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/3340 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 修复clang-format错误 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!42607
33 lines
962 B
C++
33 lines
962 B
C++
#include <gtest/gtest.h>
|
|
#include <c10/util/irange.h>
|
|
|
|
#include <torch/torch.h>
|
|
#include "torch_npu/csrc/libs/torch_npu.h"
|
|
|
|
namespace F = torch::nn::functional;
|
|
using namespace torch::nn;
|
|
|
|
auto device = at::Device("npu:0");
|
|
|
|
TEST(FunctionalTest, Conv1d) {
|
|
torch_npu::init_npu(device);
|
|
auto x = torch::arange(30, torch::dtype(torch::kFloat16).requires_grad(true))
|
|
.reshape({2, 3, 5})
|
|
.to(device);
|
|
auto weight =
|
|
torch::arange(18, torch::dtype(torch::kFloat16).requires_grad(true))
|
|
.reshape({2, 3, 3})
|
|
.to(device);
|
|
|
|
auto y = F::conv1d(x, weight, F::Conv1dFuncOptions().stride(1));
|
|
auto expected = torch::tensor(
|
|
{{{312., 348., 384.}, {798., 915., 1032.}},
|
|
|
|
{{852., 888., 924.}, {2552., 2670., 2788.}}},
|
|
torch::kFloat16)
|
|
.to(device);
|
|
|
|
ASSERT_TRUE(torch::allclose(y, expected));
|
|
torch_npu::finalize_npu();
|
|
}
|