-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
【BUPT】【Paddle Tensor 第二期 API支持 0-size Tensor】paddle.matrix_norm 支持 0-size tensor #70186
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
} | ||
auto dim_x = x.dims(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用xdim即可
for (int i = 0; i < dim_x.size() - 2; ++i) { | ||
out_dims_vec[i] = dim_x[i]; | ||
} | ||
out->Resize(phi::make_ddim(out_dims_vec)); | ||
dev_ctx.template Alloc<int64_t>(out); | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
被删除的axis不一定是最后两个吧?
axis (list|tuple,可选) - 使用范数计算的轴。axis 为 [-2,-1],否则 axis 必须为长度为 2 的 list|tuple。
out_dims_vec[dim_x.size() - 2] = 1; | ||
out_dims_vec[dim_x.size() - 1] = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上,不一定是最后两个axis
x1 = paddle.full((0, 0), 1.0, dtype='float32') | ||
y1_p = paddle.linalg.matrix_norm(x1, p=1, axis=[0, -1]) | ||
self.assertRaises( | ||
ValueError, paddle.linalg.matrix_norm, x1, p=2, axis=[0, -1] | ||
) | ||
y1_fro_keepdimfalse = paddle.linalg.matrix_norm( | ||
x1, p='fro', axis=[0, -1], keepdim=False | ||
) | ||
y1_fro_keepdimtrue = paddle.linalg.matrix_norm( | ||
x1, p='fro', axis=[0, -1], keepdim=True | ||
) | ||
x2 = paddle.full((2, 2, 0), 1.0, dtype='float32') | ||
y2_fro_keepdimfalse = paddle.linalg.matrix_norm( | ||
x2, p='fro', keepdim=False | ||
) | ||
y2_fro_keepdimtrue = paddle.linalg.matrix_norm( | ||
x2, p='fro', keepdim=True | ||
) | ||
y2_p_keepdimfalse = paddle.linalg.matrix_norm( | ||
x2, p=1, axis=[0, -1], keepdim=False | ||
) | ||
y2_p_keepdimtrue = paddle.linalg.matrix_norm( | ||
x2, p=1, axis=[0, -1], keepdim=True | ||
) | ||
self.assertRaises( | ||
ValueError, paddle.linalg.matrix_norm, x2, p=2, axis=[0, -1] | ||
) | ||
self.assertEqual(y1_fro_keepdimfalse.shape, []) | ||
self.assertEqual(y1_fro_keepdimtrue.shape, [1, 1]) | ||
self.assertEqual(y2_fro_keepdimfalse.shape, x2.shape[:-2]) | ||
self.assertEqual(y2_fro_keepdimtrue.shape, [2, 1, 1]) | ||
self.assertEqual(y2_p_keepdimfalse.shape, []) | ||
self.assertEqual(y2_p_keepdimtrue.shape, [2, 1, 1]) | ||
self.assertEqual(y1_p.shape, []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以增加一个单测,[3,0,2,0], axis=[1,-1]
Sorry to inform you that a6845c9's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |
PR Category
User Experience
PR Types
Bug fixes
Description
解决存在matrix_norm 0 size tensor的报错