-
Notifications
You must be signed in to change notification settings - Fork 243
refactor: instances of parametrized tensors are no longer parametrized #1026
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ea06783
test: add tensor ops tests
Jackmin801 ce6d712
feat: instances of parametrized types are not parametrized anymore
Jackmin801 efef75d
test: fix test that have been changed by this feature
Jackmin801 8c5e3f0
refactor: change class name and add comments
Jackmin801 5251394
test: add tests to make sure isinstance does not do coercion
Jackmin801 57107fd
fix: parametrized isinstance check should not perform coercion
Jackmin801 bdd2966
Merge branch 'feat-rewrite-v2' into feat-994-dropshape
Jackmin801 46497a4
test: add more tests to parametrized class name tests
Jackmin801 5816234
Merge branch 'feat-rewrite-v2' into feat-994-dropshape
Jackmin801 61b31ad
Merge branch 'feat-rewrite-v2' into feat-994-dropshape
Jackmin801 a44feda
style: small black fix
Jackmin801 39fa8f4
Merge branch 'feat-rewrite-v2' into feat-994-dropshape
Jackmin801 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import numpy as np | ||
| from pydantic import parse_obj_as | ||
|
|
||
| from docarray.typing import NdArray, TorchTensor | ||
|
|
||
|
|
||
| def test_coercion_behavior(): | ||
| t_np = parse_obj_as(NdArray[128], np.zeros(128)) | ||
| t_th = parse_obj_as(TorchTensor[128], np.zeros(128)) | ||
|
|
||
| assert isinstance(t_np, NdArray[128]) | ||
| assert not isinstance(t_np, TorchTensor[128]) | ||
| assert isinstance(t_th, TorchTensor[128]) | ||
| assert not isinstance(t_th, NdArray[128]) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import numpy as np | ||
|
|
||
| from docarray import BaseDocument | ||
| from docarray.typing import NdArray | ||
|
|
||
|
|
||
| def test_tensor_ops(): | ||
| class A(BaseDocument): | ||
| tensor: NdArray[3, 224, 224] | ||
|
|
||
| class B(BaseDocument): | ||
| tensor: NdArray[3, 112, 224] | ||
|
|
||
| tensor = A(tensor=np.ones((3, 224, 224))).tensor | ||
| tensord = A(tensor=np.ones((3, 224, 224))).tensor | ||
| tensorn = np.zeros((3, 224, 224)) | ||
| tensorhalf = B(tensor=np.ones((3, 112, 224))).tensor | ||
| tensorfull = np.concatenate([tensorhalf, tensorhalf], axis=1) | ||
|
|
||
| assert type(tensor) == NdArray | ||
| assert type(tensor + tensord) == NdArray | ||
| assert type(tensor + tensorn) == NdArray | ||
| assert type(tensor + tensorfull) == NdArray |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import torch | ||
|
|
||
| from docarray import BaseDocument | ||
| from docarray.typing import TorchTensor | ||
|
|
||
|
|
||
| def test_tensor_ops(): | ||
| class A(BaseDocument): | ||
| tensor: TorchTensor[3, 224, 224] | ||
|
|
||
| class B(BaseDocument): | ||
| tensor: TorchTensor[3, 112, 224] | ||
|
|
||
| tensor = A(tensor=torch.ones(3, 224, 224)).tensor | ||
| tensord = A(tensor=torch.ones(3, 224, 224)).tensor | ||
| tensorn = torch.zeros(3, 224, 224) | ||
| tensorhalf = B(tensor=torch.ones(3, 112, 224)).tensor | ||
| tensorfull = torch.cat([tensorhalf, tensorhalf], dim=1) | ||
|
|
||
| assert type(tensor) == TorchTensor | ||
| assert type(tensor + tensord) == TorchTensor | ||
| assert type(tensor + tensorn) == TorchTensor | ||
| assert type(tensor + tensorfull) == TorchTensor |
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
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.
Uh oh!
There was an error while loading. Please reload this page.