refactor: make AnyTensor a class#1552
Merged
Merged
Conversation
Signed-off-by: Mohammad Kalim Akram <kalim.akram@jina.ai>
Signed-off-by: Mohammad Kalim Akram <kalim.akram@jina.ai>
Signed-off-by: Mohammad Kalim Akram <kalim.akram@jina.ai>
Signed-off-by: Mohammad Kalim Akram <kalim.akram@jina.ai>
Signed-off-by: Mohammad Kalim Akram <kalim.akram@jina.ai>
Signed-off-by: Mohammad Kalim Akram <kalim.akram@jina.ai>
693f57a to
7465cd3
Compare
Signed-off-by: Mohammad Kalim Akram <kalim.akram@jina.ai>
Signed-off-by: Mohammad Kalim Akram <kalim.akram@jina.ai>
JohannesMessner
requested changes
May 24, 2023
Member
|
@makram93 could you pleas update the description of the PR? |
Signed-off-by: Mohammad Kalim Akram <kalim.akram@jina.ai>
Signed-off-by: Mohammad Kalim Akram <kalim.akram@jina.ai>
JohannesMessner
left a comment
Member
There was a problem hiding this comment.
Big picture looks good, I think this is the way we should solve this!! I will do a more thorough review when I have time (thursday, friday I am not so docarray focused)
samsja
reviewed
May 25, 2023
samsja
reviewed
May 25, 2023
samsja
reviewed
May 25, 2023
samsja
reviewed
May 25, 2023
samsja
left a comment
Member
There was a problem hiding this comment.
Looks good, nice trick ! I added minor comments
Signed-off-by: Mohammad Kalim Akram <kalim.akram@jina.ai>
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR solves #1439 .
As mentioned by @JohannesMessner, simply updating the
validate()method ofNdArrayto support type coercion from Torch/TensorFlow to NumPy produces unwanted side-effects withAnyTensor.AnyTensoris currently defined as:AnyTensor == Union[NdArray, TorchTensor, TensorFlowTensor].Unionvalidates the type from left to right, as such if we give torch tensors then it gets converted to NdArray. If we change the order asAnyTensor == Union[TorchTensor, TensorFlowTensor, NdArray]then the NumPy value gets converted to TorchTensor.In this PR:
AnyTensora class that inherits from theAbstractTensorsand implements theoverride()method only. This method basically checks the type of value and returns the class accordingly.Note:
AnyTensordoes not inherit[TorchTensor, TensorflowTensor, NdArray]neither does it implement any functions from the classesTYPE_CHECKINGso that mypy does not complain about the missing attribute.AnyEmbedding,AudioTensor,ImageTensor,VideoTensor.torch.Tensor,TorchTensor,tf.Tensor,TensorFlowTensor] to np inNdArray