Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

add `KORNIA_CHECK_SAME_DEVICES` (#1788)

Anton Shevtsov363c01845c1d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5397043a0..5cfeab10d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added antialiasing option to Resize augmentation (#1687)
- Use nearest neighbour interpolation for masks (#1630)
- grayscale to rgb for `torch.uint8` (#1705)
+- Add `KORNIA_CHECK_SAME_DEVICES` (#1775)
## :rocket: [0.6.4] - 2022-03-19
### :new: New Features
diff --git a/kornia/testing/__init__.py b/kornia/testing/__init__.py
index c99967cbd..a3fa82343 100644
--- a/kornia/testing/__init__.py
+++ b/kornia/testing/__init__.py
@@ -219,6 +219,12 @@ def KORNIA_CHECK_IS_TENSOR(x, msg: Optional[str] = None):
raise TypeError(f"Not a Tensor type. Got: {type(x)}.\n{msg}")
+def KORNIA_CHECK_SAME_DEVICES(tensors: List[Tensor], msg: Optional[str] = None):
+ KORNIA_CHECK(isinstance(tensors, list) and len(tensors) >= 1, "Expected a list with at least one element")
+ if not all(tensors[0].device == x.device for x in tensors):
+ raise Exception(f"Not same device for tensors. Got: {[x.device for x in tensors]}.\n{msg}")
+
+
def KORNIA_CHECK_IS_COLOR(x: Tensor, msg: Optional[str] = None):
if len(x.shape) < 3 or x.shape[-3] != 3:
raise TypeError(f"Not a color tensor. Got: {type(x)}.\n{msg}")