[Zero-Dim] OpTest support shape check and fix previous case problem #54117
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR types
Function optimization
PR changes
OPs
Description
Pcard-66984
进一步增强完善0D Tensor基础设施。由于当前基类OpTest对shape的判断不严格、不规范,导致OP开发时可以轻松绕过0D的shape判断。为了拦截后续OP开发时的0D shape以及维度设置不合理等问题,因此增强基类OpTest对shape的检查功能,同时修复约40个存量单测的问题。
shape判断标准:由于
np.allclose
具有自动broadcast功能,所以无任何shape检查功能,例如[3]与[3, 3, 3]对比仍为True;np.testing.assert_allclose
虽具有一些shape检查功能,例如[3]与[3, 3, 3]会为False,但不具有0D shape的检查功能,例如[]与[1]仍为True。因此将此处的assert标准统一升级为:先硬性对比shape一致,再np.testing.assert_allclose
。