π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
docs(api): declare DataKey and four helpers public (#6332)
Omkar Kabde84be6a27acca
diff --git a/changelog.d/6332.added.md b/changelog.d/6332.added.mdnew file mode 100644index 000000000..60b5283c2--- /dev/null+++ b/changelog.d/6332.added.md@@ -0,0 +1,3 @@+`DataKey`, `is_powerof_two`, `find_next_powerof_two`, `KORNIA_CHECK_SAME_SHAPE` and+`KORNIA_CHECK_IS_COLOR_OR_GRAY` are declared public: they are in their modules' `__all__` and in the API+reference. They were already importable and used downstream.diff --git a/docs/source/augmentation.container.rst b/docs/source/augmentation.container.rstindex 94d5409a1..424803ded 100644--- a/docs/source/augmentation.container.rst+++ b/docs/source/augmentation.container.rst@@ -156,3 +156,16 @@ data formats... autoclass:: VideoSequential.. automethod:: forward+++Data keys+---------++.. currentmodule:: kornia.constants++``data_keys`` of :class:`~kornia.augmentation.container.AugmentationSequential` accepts a :class:`DataKey` member or+its name, for example ``DataKey.INPUT`` or ``"input"``.++.. autoclass:: DataKey+ :members:+ :undoc-members:diff --git a/docs/source/core.rst b/docs/source/core.rstindex 2b497e2eb..8bba0e502 100644--- a/docs/source/core.rst+++ b/docs/source/core.rst@@ -66,6 +66,8 @@ when the check fails. Any other message that formats a tensor size or an ``int``.. autofunction:: KORNIA_CHECK_SIZES+.. autofunction:: KORNIA_CHECK_IS_COLOR_OR_GRAY+Exceptions----------diff --git a/docs/source/geometry.transform.rst b/docs/source/geometry.transform.rstindex 29a338526..5bd4fa2b9 100644--- a/docs/source/geometry.transform.rst+++ b/docs/source/geometry.transform.rst@@ -42,6 +42,8 @@ Image 2D transforms.. autofunction:: pyrup.. autofunction:: build_pyramid.. autofunction:: build_laplacian_pyramid+.. autofunction:: is_powerof_two+.. autofunction:: find_next_powerof_twoImage 3D transforms-------------------diff --git a/kornia/constants.py b/kornia/constants.pyindex d6ff6e54e..656655154 100644--- a/kornia/constants.py+++ b/kornia/constants.py@@ -20,7 +20,7 @@ from typing import Iterator, Type, TypeVar, Unionimport torch-__all__ = ["BorderType", "DType", "Resample", "SamplePadding", "TKEnum", "pi"]+__all__ = ["BorderType", "DType", "DataKey", "Resample", "SamplePadding", "TKEnum", "pi"]pi = torch.tensor(3.14159265358979323846)diff --git a/kornia/core/check.py b/kornia/core/check.pyindex 1f94e06f3..140fad9d0 100644--- a/kornia/core/check.py+++ b/kornia/core/check.py@@ -41,6 +41,7 @@ __all__ = ["KORNIA_CHECK","KORNIA_CHECK_DM_DESC","KORNIA_CHECK_IS_COLOR",+ "KORNIA_CHECK_IS_COLOR_OR_GRAY","KORNIA_CHECK_IS_GRAY","KORNIA_CHECK_IS_IMAGE","KORNIA_CHECK_IS_LIST_OF_TENSOR",@@ -48,6 +49,7 @@ __all__ = ["KORNIA_CHECK_LAF","KORNIA_CHECK_SAME_DEVICE","KORNIA_CHECK_SAME_DEVICES",+ "KORNIA_CHECK_SAME_SHAPE","KORNIA_CHECK_SAME_SIZE","KORNIA_CHECK_SHAPE","KORNIA_CHECK_SIZES",diff --git a/kornia/geometry/transform/pyramid.py b/kornia/geometry/transform/pyramid.pyindex 5177ce005..4b501d1b4 100644--- a/kornia/geometry/transform/pyramid.py+++ b/kornia/geometry/transform/pyramid.py@@ -27,7 +27,17 @@ from kornia.core.check import KORNIA_CHECK, KORNIA_CHECK_SHAPEfrom kornia.filters import filter2d, gaussian_blur2dfrom kornia.filters.gaussian import _gaussian_blur2d_cpu, _gaussian_blur2d_cpu_eligible-__all__ = ["PyrDown", "PyrUp", "ScalePyramid", "build_laplacian_pyramid", "build_pyramid", "pyrdown", "pyrup"]+__all__ = [+ "PyrDown",+ "PyrUp",+ "ScalePyramid",+ "build_laplacian_pyramid",+ "build_pyramid",+ "find_next_powerof_two",+ "is_powerof_two",+ "pyrdown",+ "pyrup",+]def _get_pyramid_gaussian_kernel() -> torch.Tensor:@@ -556,11 +566,40 @@ def build_pyramid(def is_powerof_two(x: int) -> bool:- # check if number x is a power of two+ r"""Check whether a number is a power of two.++ Args:+ x: the integer to check.++ Returns:+ ``True`` if ``x`` is a positive power of two, ``False`` otherwise (including for ``0``).++ Example:+ >>> is_powerof_two(64)+ True+ >>> is_powerof_two(100)+ False++ """return bool(x) and (not (x & (x - 1)))def find_next_powerof_two(x: int) -> int:+ r"""Find the smallest power of two that is greater than or equal to a number.++ Args:+ x: a positive integer.++ Returns:+ the smallest power of two not below ``x``.++ Example:+ >>> find_next_powerof_two(100)+ 128+ >>> find_next_powerof_two(64)+ 64++ """return 1 << (x - 1).bit_length()diff --git a/tests/api_surface.json b/tests/api_surface.jsonindex facfcca87..9b0dc81e3 100644--- a/tests/api_surface.json+++ b/tests/api_surface.json@@ -227,6 +227,15 @@"yuv422_to_rgb","yuv_to_rgb"],+ "kornia.constants": [+ "BorderType",+ "DType",+ "DataKey",+ "Resample",+ "SamplePadding",+ "TKEnum",+ "pi"+ ],"kornia.core": ["ImageModule","ImageModuleMixIn",@@ -253,6 +262,7 @@"KORNIA_CHECK","KORNIA_CHECK_DM_DESC","KORNIA_CHECK_IS_COLOR",+ "KORNIA_CHECK_IS_COLOR_OR_GRAY","KORNIA_CHECK_IS_GRAY","KORNIA_CHECK_IS_IMAGE","KORNIA_CHECK_IS_LIST_OF_TENSOR",@@ -260,6 +270,7 @@"KORNIA_CHECK_LAF","KORNIA_CHECK_SAME_DEVICE","KORNIA_CHECK_SAME_DEVICES",+ "KORNIA_CHECK_SAME_SHAPE","KORNIA_CHECK_SAME_SIZE","KORNIA_CHECK_SHAPE","KORNIA_CHECK_SIZES",@@ -573,6 +584,7 @@"find_homography_dlt_iterated","find_homography_lines_dlt","find_homography_lines_dlt_iterated",+ "find_next_powerof_two","fit_line","fit_plane","flips",@@ -604,6 +616,7 @@"intrinsics_like","inverse_transformation","invert_affine_transform",+ "is_powerof_two","iterative_quad_interp3d","keypoints","left_to_right_epipolar_distance",@@ -1046,6 +1059,8 @@"ScalePyramid","build_laplacian_pyramid","build_pyramid",+ "find_next_powerof_two",+ "is_powerof_two","pyrdown","pyrup"],diff --git a/tests/test_api_surface.py b/tests/test_api_surface.pyindex 513286e8c..bfab04b52 100644--- a/tests/test_api_surface.py+++ b/tests/test_api_surface.py@@ -396,6 +396,23 @@ def test_public_names_resolve(module_name):)+ ("module_name", "names"),+ [+ ("kornia.constants", ["DataKey"]),+ ("kornia.core.check", ["KORNIA_CHECK_SAME_SHAPE", "KORNIA_CHECK_IS_COLOR_OR_GRAY"]),+ ("kornia.geometry.transform.pyramid", ["is_powerof_two", "find_next_powerof_two"]),+ ],+)+def test_published_names_are_star_exported_4026(module_name, names):+ mod = importlib.import_module(module_name)+ namespace: dict = {}+ exec(f"from {module_name} import *", namespace) # noqa: S102+ for name in names:+ assert name in mod.__all__+ assert namespace[name] is getattr(mod, name)++if __name__ == "__main__":regenerate()print(f"regenerated {INVENTORY}")