Skip to content
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

[Cpp Extension] Support optional types #50764

Merged
merged 2 commits into from
Feb 23, 2023

Conversation

jiahy0825
Copy link
Contributor

PR types

New features

PR changes

Others

Describe

Cpp Extension supports optional types, Extension might return None or Tensor when C++ outputs optional<Tensor>

Comment on lines +109 to +127
def _test_nullable_tensor(self):
x = custom_cpp_extension.nullable_tensor(True)
assert x is None, "Return None when input parameter return_none = True"
x = custom_cpp_extension.nullable_tensor(False).numpy()
x_np = np.ones(shape=[2, 2])
np.testing.assert_array_equal(
x,
x_np,
err_msg='extension out: {},\n numpy out: {}'.format(x, x_np),
)

def _test_optional_tensor(self):
x = custom_cpp_extension.optional_tensor(True)
assert (
x is None
), "Return None when input parameter return_option = True"
x = custom_cpp_extension.optional_tensor(False).numpy()
x_np = np.ones(shape=[2, 2])
np.testing.assert_array_equal(
Copy link
Contributor

Choose a reason for hiding this comment

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

optional_tensor和nullable_tensor在功能上有什么区别吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这两个分别测不同的功能,nullable_tensor 测试的是 未初始化 Tensor 返回值为 None,optional_tensor 测试的是 Extension 支持 optional 的机制

These two unit tests have different goals: nullable_tensor tests un-initialized Tensor returns None, optional_tensor tests Extension supports optional mechanism.

@jiahy0825 jiahy0825 closed this Feb 23, 2023
@jiahy0825 jiahy0825 reopened this Feb 23, 2023
@jiahy0825 jiahy0825 merged commit ff4ec23 into PaddlePaddle:develop Feb 23, 2023
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