Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

docs: add CLAUDE.md with dev environment and architecture guide

Dmytro Mishkinbcd6a3807071
diff --git a/CLAUDE.md b/CLAUDE.md
new file mode 100644
index 000000000..d11ab140a
--- /dev/null
+++ b/CLAUDE.md
@@ -0,0 +1,107 @@
+# CLAUDE.md
+
+This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
+
+## About Kornia
+
+Kornia is a differentiable computer vision library built on PyTorch. It provides differentiable image processing, geometric vision algorithms, augmentation pipelines, and pre-trained AI models (feature detection/matching, segmentation, etc.).
+
+## Development Environment
+
+The project uses [pixi](https://pixi.sh) for environment management and `uv` for Python package management.
+
+```bash
+# Set up development environment (Python 3.11 default)
+pixi install
+
+# For specific Python versions
+pixi install -e py312
+pixi install -e py313
+
+# For CUDA development
+pixi run -e cuda install
+```
+
+## Common Commands
+
+```bash
+# Run all tests
+pixi run test
+
+# Run a specific test file
+pixi run test tests/test_geometry_transform.py
+
+# Run tests with pytest options (dtype: bfloat16, float16, float32, float64, all; device: cpu, cuda, mps, tpu, all)
+pixi run test tests/test_geometry_transform.py --dtype=float32,float64 --device=all
+
+# Run quick tests (excludes jit, grad, nn)
+pixi run test-quick
+
+# Linting (ruff via pre-commit)
+pixi run lint
+
+# Type checking (uses `ty`)
+pixi run typecheck
+
+# Doctests
+pixi run doctest
+
+# Build documentation
+pixi run build-docs
+
+# Run tests with specific device/dtype via env vars
+KORNIA_TEST_DEVICE=cuda KORNIA_TEST_DTYPE=float32 pixi run test
+KORNIA_TEST_RUNSLOW=true pixi run test-slow
+```
+
+## Code Architecture
+
+The library is structured as submodules under `kornia/`:
+
+- **`kornia/filters/`** β€” Image filtering (Gaussian, Sobel, Median, Canny, etc.). Imported first in `__init__.py` as it's core.
+- **`kornia/geometry/`** β€” Geometric transformations (affine, homography, camera models, stereo, 3D). Also core, imported first.
+- **`kornia/augmentation/`** β€” Augmentation pipeline (`AugmentationSequential`, `RandomAffine`, etc.)
+- **`kornia/color/`** β€” Color space conversions (RGB, HSV, grayscale, etc.)
+- **`kornia/feature/`** β€” Feature detection and description (SIFT, HardNet, DISK, DeDoDe, LoFTR, LightGlue, etc.)
+- **`kornia/enhance/`** β€” Image enhancement (histogram equalization, CLAHE, gamma correction)
+- **`kornia/losses/`** β€” Loss functions (SSIM, PSNR, Dice, Hausdorff, etc.)
+- **`kornia/models/`** β€” Pre-trained AI models (YuNet face detection, SAM segmentation, etc.)
+- **`kornia/morphology/`** β€” Morphological operations (dilation, erosion, etc.)
+- **`kornia/onnx/`** β€” ONNX export and inference (`ONNXSequential`)
+- **`kornia/contrib/`** β€” Experimental/contributed modules
+- **`kornia/core/`** β€” Base classes (`ImageModule`, `ImageSequential`, `TensorWrapper`, ONNX mixins)
+- **`kornia/transpiler/`** β€” Multi-framework support via ivy (JAX, TensorFlow, NumPy backends)
+- **`testing/`** β€” Test utilities (not tests). `testing/base.py` contains `BaseTester` and `assert_close`.
+
+**Import order matters**: `filters` and `geometry` must be imported before other modules to avoid circular dependencies (see `kornia/__init__.py`).
+
+## Testing Patterns
+
+All tests should inherit from `BaseTester` (from `testing.base`):
+
+```python
+from testing.base import BaseTester
+
+class TestMyFunction(BaseTester):
+ def test_smoke(self, device, dtype): ... # Basic run with all arg combinations
+ def test_exception(self, device, dtype): ... # Exception cases
+ def test_cardinality(self, device, dtype): ... # Output shapes
+ def test_gradcheck(self, device): ... # Gradient checking via self.gradcheck()
+ def test_dynamo(self, device, dtype, torch_optimizer): ... # torch.compile compat
+```
+
+The `device` and `dtype` fixtures are injected automatically. Use `self.assert_close()` for tensor comparisons. Test configurations are driven by env vars `KORNIA_TEST_DEVICE` and `KORNIA_TEST_DTYPE`, or by `--device`/`--dtype` pytest args.
+
+## Coding Standards
+
+- **Python >= 3.11** with `from __future__ import annotations` for non-JIT modules
+- **Line length**: 120 characters (ruff enforced)
+- **Type hints required** on all function inputs and outputs; use `torch.Tensor` directly (not string annotations for tensor types in JIT-compatible code)
+- **Only PyTorch** as a third-party dependency β€” no other libraries
+- **Use existing `kornia` utilities** rather than reimplementing with raw PyTorch
+- **Docstrings**: Follow existing codebase style; all public APIs need docstrings
+- Every source file must start with the Apache 2.0 license header (managed by `add-license-header`)
+
+## Pre-commit Hooks
+
+Install hooks with `pre-commit install`. CI enforces ruff formatting, linting, and docformatter.