Skip to content
This repository was archived by the owner on Sep 9, 2026. It is now read-only.

fix: docvec equality if tensors are involved - #1663

Merged
JohannesMessner merged 10 commits into
mainfrom
fix-docvec-equality
Jun 20, 2023
Merged

JohannesMessner merged 10 commits into
mainfrom
fix-docvec-equality

Conversation

@JohannesMessner

@JohannesMessner JohannesMessner commented Jun 20, 2023 •

Copy link
Copy Markdown
Member

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
Comment thread docarray/helper.py Outdated
Signed-off-by: Johannes Messner <messnerjo@gmail.com>
Signed-off-by: Johannes Messner <messnerjo@gmail.com>
@JohannesMessner
JohannesMessner requested a review from samsja June 20, 2023 10:42
@github-actions

Copy link
Copy Markdown

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants