Metadata-Version: 2.5
Name: grassmann-ot
Version: 0.3.0
Summary: Cell-to-cell anchoring via Grassmann subspace distance and Optimal Transport, with fast selectable backends.
Project-URL: Homepage, https://github.com/ZengFLab/grassmann-ot
Project-URL: Issues, https://github.com/ZengFLab/grassmann-ot/issues
Author-email: Your Name <you@example.com>
License: 404: Not Found
License-File: LICENSE
Keywords: anchors,grassmann,optimal-transport,single-cell
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Requires-Python: >=3.8
Requires-Dist: numpy>=1.20
Requires-Dist: pot>=0.8
Requires-Dist: scikit-learn>=1.0
Requires-Dist: scipy>=1.6
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: scanpy; extra == 'dev'
Provides-Extra: faiss
Requires-Dist: faiss-cpu; extra == 'faiss'
Provides-Extra: full
Requires-Dist: faiss-gpu; extra == 'full'
Requires-Dist: pytest>=7.0; extra == 'full'
Requires-Dist: scanpy; extra == 'full'
Requires-Dist: torch; extra == 'full'
Provides-Extra: gpu
Requires-Dist: faiss-gpu; extra == 'gpu'
Requires-Dist: torch; extra == 'gpu'
Provides-Extra: test
Requires-Dist: pytest>=7.0; extra == 'test'
Provides-Extra: torch
Requires-Dist: torch; extra == 'torch'
Description-Content-Type: text/markdown

# grassmann-ot

Cell-to-cell anchoring via **Grassmann subspace distance + Optimal Transport**,
now with **fast, selectable construction backends** for large `n`.

## Install

```bash
pip install grassmann-ot
```

For the GPU backends:

```bash
pip install torch faiss-gpu   # or faiss-cpu
```

## Quick start

```python
import numpy as np
from grassmann_ot import GrassmannOT

# H_X, H_Y come from any external tool (NMF, scVI, Harmony, ...)
# shape: (n_gene_programs, n_cells)
H_X, H_Y = np.random.rand(20, 300), np.random.rand(20, 250)

ot = GrassmannOT(k=30, p=3, reg=0.1, backend="batched")
gamma   = ot.fit(H_X, H_Y)        # soft coupling, shape (n_X, n_Y)
matches = ot.get_hard_anchors()   # one-to-one anchors, shape (K, 2)
```

## Backends (new in 0.3.0)

`cells_to_grassmann` and `GrassmannOT` now accept a `backend` parameter:

| Backend         | Requirements      | Use when                          |
|-----------------|-------------------|-----------------------------------|
| `loop`          | numpy             | Baseline / debugging              |
| `batched`       | torch             | **Default; medium datasets**      |
| `pca`           | scipy, numpy      | Want 10-20x speed, accept small precision loss |
| `subsampling`   | sklearn, scipy    | Very large n, tolerate interpolation |
| `faiss`         | faiss + torch     | Largest datasets, GPU available   |

```python
from grassmann_ot import cells_to_grassmann

U = cells_to_grassmann(H_X, k=30, p=3, backend="pca")
V = cells_to_grassmann(H_Y, k=30, p=3, backend="pca")
```

Extra options: `batch_size`, `subsample_rate`, `inner_backend`, `device`.

You can also skip construction and feed precomputed points directly:

```python
ot = GrassmannOT(k=30, p=3, reg=0.1)
gamma = ot.fit_points(U_list, V_list)
```

## Parameters

| Parameter         | Default | Meaning                                  |
|-------------------|---------|------------------------------------------|
| `k`               | 30      | Neighborhood size                        |
| `p`               | 3       | Subspace dimension                       |
| `metric`          | cosine  | Neighbor metric                          |
| `reg`             | 0.1     | Sinkhorn entropic regularization         |
| `backend`         | batched | Grassmann construction strategy          |
| `batch_size`      | 512     | Batch size for torch SVD                 |
| `subsample_rate`  | 0.1     | Fraction exact-computed in `subsampling` |
| `inner_backend`   | pca     | Backend for seed cells in `subsampling`  |
| `a`, `b`          | None    | Source / target marginals (uniform)      |

## Benchmark

```bash
python examples/benchmark_backends.py
```

## Changelog

### 0.3.0
- New module `grassmann_ot._grassmann_fast` with five backends.
- `GrassmannOT` exposes `backend`, `batch_size`, `subsample_rate`,
  `inner_backend`, `device`.
- New `fit_points()` to use precomputed Grassmann point lists.
- Fixed `linear_sum_assignment` result unpacking.
