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

fix: docvec equality if tensors are involved #1663

Merged
merged 10 commits into from
Jun 20, 2023
Merged

Conversation

JohannesMessner
Copy link
Member

@JohannesMessner JohannesMessner commented Jun 20, 2023

Before this, DocVec equality checks that involved a tensor would fail by raising and Exception:

    class Text(BaseDoc):
        tens: TorchTensor

    da = DocVec[Text](
        [Text(tens=[1, 2, 3, 4]) for _ in range(10)], tensor_type=TorchTensor
    )
    da2 = DocVec[Text](
        [Text(tens=[1, 2, 3, 4]) for _ in range(10)], tensor_type=TorchTensor
    )
    assert da == da2  # would raise
RuntimeError: Boolean value of Tensor with more than one value is ambiguous

This is because checks of the form tens1 == tens2 return a boolean tensor, not a single bool, which breaks an assumption in the previous implementation.

This PR solved that by introducing a helper function that let's us compare tensors and get a single bool as output.

Signed-off-by: Johannes Messner <messnerjo@gmail.com>
Signed-off-by: Johannes Messner <messnerjo@gmail.com>
Signed-off-by: Johannes Messner <messnerjo@gmail.com>
Signed-off-by: Johannes Messner <messnerjo@gmail.com>
Signed-off-by: Johannes Messner <messnerjo@gmail.com>
Signed-off-by: Johannes Messner <messnerjo@gmail.com>
@github-actions github-actions bot added size/m and removed size/s labels Jun 20, 2023
Signed-off-by: Johannes Messner <messnerjo@gmail.com>
Signed-off-by: Johannes Messner <messnerjo@gmail.com>
@JohannesMessner JohannesMessner marked this pull request as ready for review June 20, 2023 09:46
docarray/helper.py Outdated Show resolved Hide resolved
Signed-off-by: Johannes Messner <messnerjo@gmail.com>
Signed-off-by: Johannes Messner <messnerjo@gmail.com>
@github-actions
Copy link

📝 Docs are deployed on https://ft-fix-docvec-equality--jina-docs.netlify.app 🎉

@JohannesMessner JohannesMessner merged commit c3c8061 into main Jun 20, 2023
21 checks passed
@JohannesMessner JohannesMessner deleted the fix-docvec-equality branch June 20, 2023 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants