# thienannguyen-cv/smap architecture

> Architecture diagram of the GitHub repository thienannguyen-cv/smap, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thienannguyen-cv/smap
- Repository: https://github.com/thienannguyen-cv/smap

## Overview

1. **Repository purpose and shape**
   - This is a Python/PyTorch library, not a full application stack.
   - The repo is centered on a core package, `smap`, with supporting notebooks, tests, docs, and release automation.
   - The library’s main job is to transform 2D tensor representations using camera/geometry information to support the project’s “dynamic 3D inference” experiments.

2. **Core runtime boundary: `smap/`**
   - `smap` is the production package that consumers import.
   - The public entry points are exposed through `smap/__init__.py`, which the README shows as `SMap` and `SMap3x3`.
   - This package is the architectural center: everything else either supports it, validates it, or demonstrates it.

3. **Main computation layer**
   - `smap/smap.py` appears to hold the primary spatial-mapping implementation.
   - The README’s quick start shows the core data flow: a tensor shaped like `(N, C, H, W)` plus camera intrinsics/affine-style matrix information is passed into `SMap`, producing a mapped output tensor.
   - `smap/specials.py` likely contains special-case logic or optimized variants used by the main mapper.

4. **Geometric/rectification subsystem**
   - `smap/rectify.py` is a distinct support layer for geometric correction or coordinate adjustment.
   - This suggests the library separates “build the mapping” from “rectify/normalize the spatial relationship,” which is important when drawing the architecture: one branch for core mapping, another for geometry helpers.
   - `smap/utils.py` provides shared helpers used across these modules.

5. **Two operational modes: general and 3x3-specialized**
   - The README explicitly highlights both `SMap` and `SMap3x3`.
   - `SMap` is the general spatial-mapping path; `SMap3x3` is a constrained specialization for a 3-by-3 neighborhood of directional targets.
   - The existence of a dedicated `tests/test_vtest_data/smap3x3/` fixture set indicates the specialized mode is a first-class architectural branch, not just a minor parameter change.

6. **Data flow through the library**
   - Inputs are typically PyTorch tensors, while camera metadata and matrices are NumPy-based in the documented usage.
   - The core flow is: tensor input → mapping/rectification logic → transformed output tensor.
   - The repo also stores intermediate-style artifacts such as masks, expected outputs, and a `flow_info.pkl`, indicating that spatial flow/field information is part of the internal representation or validation path.

7. **Validation strategy: unit tests plus visual/regression tests**
   - `tests/utest_rectify.py`, `tests/utest_smap.py`, and `tests/utest_smap3x3.py` cover the main library surfaces.
   - `tests/vtest_data/` contains fixed `.npy` fixtures and expected outputs for regression-style verification, especially around spatial behavior.
   - This means correctness is checked not just by numeric function outputs, but by comparing stored spatial artifacts and expected mapped representations.

8. **Documentation and research context**
   - `docs/` contains repository documentation and a knowledge-graph-style description of the project’s theory.
   - The docs are tied to the research framing rather than product UX, which matches the repo’s role as an explainable scientific library.
   - `VERSIONING.md` and the README emphasize release/version discipline appropriate for a publishable package.

9. **Application layer: notebooks as consumers of the core library**
   - `applications/Camera Calibration/` and `applications/Depth Estimation/` are example projects built on top of the package.
   - They use Jupyter notebooks and dataset-specific assets, showing that the repo supports experimental workflows and demos rather than a single runtime app.
   - These notebooks are downstream consumers of `smap`, not part of the package’s internal runtime.

10. **External data dependencies**
   - The applications reference external datasets: `Sky-dataset` for camera calibration and `Lamp-dataset` for depth estimation.
   - Dataset artifacts and model checkpoints live alongside the notebooks, reinforcing that these are research experiments with local assets rather than service endpoints.
   - The `applications/Depth Estimation/model_0_0.pth` and CSV histories show training/evaluation artifacts for a learned component within the demo workflow.

11. **Tooling and test harnesses**
   - `tools/testing/` contains additional infrastructure for validation, including a separate `vtest` harness and an `hdvo` execution environment.
   - This suggests the repo has a layered test story: standard pytest-style unit tests plus a more specialized visual/interactive test runner for notebook-derived workflows.
   - These tools are auxiliary and do not affect the library’s public API, but they matter for understanding how the project is verified.

12. **Packaging and release pipeline**
   - `setup.py`, `requirements.txt`, and `environment.yml` define the installable Python package and its reproducible environment.
   - GitHub Actions workflows (`ci.yml`, `cd.yml`, `pypi-publish.yml`) indicate automated testing and publishing to PyPI.
   - Architecturally, this repo is built to ship as a reusable library artifact, with notebooks and docs as companion layers.

13. **How to draw the architecture**
   - Put `smap` at the center.
   - Show `applications/` as downstream notebook-based consumers that call into `SMap`/`SMap3x3`.
   - Show `tests/` and `tools/testing/` as validation and regression layers around the core.
   - Show docs and CI/CD as supporting infrastructure around the package lifecycle, not part of runtime execution.

Main entry points: [`smap/__init__.py`](https://github.com/thienannguyen-cv/smap/blob/main/smap/__init__.py) (Public API), [`smap/smap.py`](https://github.com/thienannguyen-cv/smap/blob/main/smap/smap.py) (SMap), [`smap/specials.py`](https://github.com/thienannguyen-cv/smap/blob/main/smap/specials.py) (SMap3x3), [`smap/rectify.py`](https://github.com/thienannguyen-cv/smap/blob/main/smap/rectify.py) (Rectify)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core package"]
  node_smap_init["Public API<br/>package entry<br/>[__init__.py]"]
  node_smap_core["SMap<br/>mapper<br/>[smap.py]"]
  node_smap_3x3["SMap3x3<br/>specialized mapper<br/>[specials.py]"]
  node_rectify["Rectify<br/>geometry<br/>[rectify.py]"]
  node_utils["Utils<br/>helpers<br/>[utils.py]"]
end

subgraph group_validation["Validation"]
  node_ut_rectify["Rectify tests<br/>unit tests<br/>[utest_rectify.py]"]
  node_ut_smap["SMap tests<br/>unit tests<br/>[utest_smap.py]"]
  node_ut_smap3x3["3x3 tests<br/>unit tests<br/>[utest_smap3x3.py]"]
  node_vtest_data[("VTest fixtures<br/>regression data")]
  node_flow_info["Flow info<br/>fixture<br/>[test_flow_info.pkl]"]
  node_vtest_harness["VTest harness"]
  node_hdvo_env["HDVO env<br/>execution env"]
end

subgraph group_consumers["Applications"]
  node_camera_app["Camera calib<br/>notebook app"]
  node_depth_app["Depth est.<br/>notebook app"]
end

subgraph group_support["Support"]
  node_docs["Docs<br/>documentation"]
  node_packaging["Packaging<br/>build config<br/>[setup.py]"]
  node_release["Release CI<br/>automation<br/>[workflows]"]
end

node_smap_init -->|"exports"| node_smap_core
node_smap_init -->|"exports"| node_smap_3x3
node_smap_core -->|"uses"| node_rectify
node_smap_core -->|"uses"| node_utils
node_smap_3x3 -->|"uses"| node_rectify
node_smap_3x3 -->|"uses"| node_utils
node_ut_rectify -->|"validates"| node_rectify
node_ut_smap -->|"validates"| node_smap_core
node_ut_smap3x3 -->|"validates"| node_smap_3x3
node_vtest_data -->|"fixtures for"| node_ut_smap3x3
node_flow_info -->|"fixtures for"| node_ut_smap
node_vtest_harness -->|"drives"| node_vtest_data
node_hdvo_env -->|"supports"| node_vtest_harness
node_camera_app -->|"consumes"| node_smap_init
node_depth_app -->|"consumes"| node_smap_init
node_docs -->|"describes"| node_smap_init
node_packaging -->|"packages"| node_smap_init
node_release -->|"publishes"| node_packaging

click node_smap_init "https://github.com/thienannguyen-cv/smap/blob/main/smap/__init__.py"
click node_smap_core "https://github.com/thienannguyen-cv/smap/blob/main/smap/smap.py"
click node_smap_3x3 "https://github.com/thienannguyen-cv/smap/blob/main/smap/specials.py"
click node_rectify "https://github.com/thienannguyen-cv/smap/blob/main/smap/rectify.py"
click node_utils "https://github.com/thienannguyen-cv/smap/blob/main/smap/utils.py"
click node_ut_rectify "https://github.com/thienannguyen-cv/smap/blob/main/tests/utest_rectify.py"
click node_ut_smap "https://github.com/thienannguyen-cv/smap/blob/main/tests/utest_smap.py"
click node_ut_smap3x3 "https://github.com/thienannguyen-cv/smap/blob/main/tests/utest_smap3x3.py"
click node_vtest_data "https://github.com/thienannguyen-cv/smap/tree/main/tests/vtest_data"
click node_flow_info "https://github.com/thienannguyen-cv/smap/blob/main/tests/test_flow_info.pkl"
click node_vtest_harness "https://github.com/thienannguyen-cv/smap/tree/main/tools/testing/vtest"
click node_hdvo_env "https://github.com/thienannguyen-cv/smap/tree/main/tools/testing/hdvo"
click node_camera_app "https://github.com/thienannguyen-cv/smap/blob/main/applications/Camera Calibration/camera-calibration.ipynb"
click node_depth_app "https://github.com/thienannguyen-cv/smap/blob/main/applications/Depth Estimation/depth-estimation.ipynb"
click node_docs "https://github.com/thienannguyen-cv/smap/tree/main/docs"
click node_packaging "https://github.com/thienannguyen-cv/smap/blob/main/setup.py"
click node_release "https://github.com/thienannguyen-cv/smap/blob/main/.github/workflows"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_smap_init,node_smap_core,node_smap_3x3,node_rectify,node_utils toneBlue
class node_ut_rectify,node_ut_smap,node_ut_smap3x3,node_vtest_data,node_flow_info,node_vtest_harness,node_hdvo_env toneAmber
class node_camera_app,node_depth_app toneMint
class node_docs,node_packaging,node_release toneRose
```

## Components

### Core package

Installable Python package that implements the spatial mapping runtime.

- [Public API](https://github.com/thienannguyen-cv/smap/blob/main/smap/__init__.py): package entry · Exports the library’s main classes for consumers. · `smap/__init__.py`
- [SMap](https://github.com/thienannguyen-cv/smap/blob/main/smap/smap.py): mapper · Primary spatial mapping implementation for tensor-to-tensor transformation. · `smap/smap.py`
- [SMap3x3](https://github.com/thienannguyen-cv/smap/blob/main/smap/specials.py): specialized mapper · Constrained 3x3 mapping variant used as a first-class operational mode. · `smap/specials.py`
- [Rectify](https://github.com/thienannguyen-cv/smap/blob/main/smap/rectify.py): geometry · Geometric correction and coordinate adjustment layer. · `smap/rectify.py`
- [Utils](https://github.com/thienannguyen-cv/smap/blob/main/smap/utils.py): helpers · Shared helpers used by the core mapping and geometry modules. · `smap/utils.py`

### Validation

Unit tests, regression fixtures, and specialized test harnesses.

- [Rectify tests](https://github.com/thienannguyen-cv/smap/blob/main/tests/utest_rectify.py): unit tests · Covers geometric correction behavior. · `tests/utest_rectify.py`
- [SMap tests](https://github.com/thienannguyen-cv/smap/blob/main/tests/utest_smap.py): unit tests · Covers the general spatial mapping path. · `tests/utest_smap.py`
- [3x3 tests](https://github.com/thienannguyen-cv/smap/blob/main/tests/utest_smap3x3.py): unit tests · Covers the specialized 3x3 mapping path. · `tests/utest_smap3x3.py`
- [VTest fixtures](https://github.com/thienannguyen-cv/smap/tree/main/tests/vtest_data): regression data · Stored tensors, masks, and expected outputs for spatial regression checks. · `tests/vtest_data`
- [Flow info](https://github.com/thienannguyen-cv/smap/blob/main/tests/test_flow_info.pkl): fixture · Serialized flow/field metadata used by tests and validation. · `tests/test_flow_info.pkl`
- [VTest harness](https://github.com/thienannguyen-cv/smap/tree/main/tools/testing/vtest): test harness · Notebook-driven visual/regression test environment. · `tools/testing/vtest`
- [HDVO env](https://github.com/thienannguyen-cv/smap/tree/main/tools/testing/hdvo): execution env · Specialized execution environment supporting visual testing workflows. · `tools/testing/hdvo`

### Applications

Notebook-based downstream experiments that consume the library.

- [Camera calib](https://github.com/thienannguyen-cv/smap/blob/HEAD/applications/Camera%20Calibration/camera-calibration.ipynb): notebook app · Notebook experiment for camera calibration built on the library. · `applications/Camera Calibration/camera-calibration.ipynb`
- [Depth est.](https://github.com/thienannguyen-cv/smap/blob/HEAD/applications/Depth%20Estimation/depth-estimation.ipynb): notebook app · Notebook experiment for depth estimation built on the library. · `applications/Depth Estimation/depth-estimation.ipynb`

### Support

Docs, packaging, and release automation around the package lifecycle.

- [Docs](https://github.com/thienannguyen-cv/smap/tree/main/docs): documentation · Project theory, usage notes, and architecture-oriented documentation. · `docs`
- [Packaging](https://github.com/thienannguyen-cv/smap/blob/main/setup.py): build config · Package metadata and environment definition for installation and reproducibility. · `setup.py`
- [Release CI](https://github.com/thienannguyen-cv/smap/blob/main/.github/workflows): automation · Continuous integration, deployment, and PyPI publishing workflows. · `.github/workflows`

## Connections

- Public API → SMap: exports · Public entry point exposes the primary mapper.
- Public API → SMap3x3: exports · Public entry point exposes the specialized mapper.
- SMap → Rectify: uses · General mapping relies on geometric correction.
- SMap → Utils: uses · Shares helpers for core runtime logic.
- SMap3x3 → Rectify: uses · Specialized mapping also depends on rectification/geometry.
- SMap3x3 → Utils: uses · Shares helper routines with the core package.
- Rectify tests → Rectify: validates · Unit tests exercise geometric correction behavior.
- SMap tests → SMap: validates · Unit tests cover the main mapping path.
- 3x3 tests → SMap3x3: validates · Unit tests cover the 3x3 specialization.
- VTest fixtures → 3x3 tests: fixtures for · Regression artifacts support the specialized visual tests.
- Flow info → SMap tests: fixtures for · Serialized flow data supports validation of mapping behavior.
- VTest harness → VTest fixtures: drives · Harness consumes stored representations and expected outputs.
- HDVO env → VTest harness: supports · Execution environment runs the visual test workflow.
- Camera calib → Public API: consumes · Notebook experiment calls into the public API.
- Depth est. → Public API: consumes · Notebook experiment calls into the public API.
- Docs → Public API: describes · Documentation explains the package and its theory.
- Packaging → Public API: packages · Build metadata turns the core library into an installable distribution.
- Release CI → Packaging: publishes · CI/CD workflows test and publish release artifacts.
