| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| 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]) |
| 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 |
| 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 |
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.