vsparse 0.4.0__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vsparse
3
- Version: 0.4.0
3
+ Version: 0.5.0
4
4
  Summary: Value-Compressed Sparse Column/Row (VCSC/VCSR) arrays, with optional AnnData integration
5
5
  Keywords: anndata,single-cell,sparse,compression
6
6
  Author: Aaron Meyer
@@ -11,11 +11,14 @@ Classifier: Intended Audience :: Science/Research
11
11
  Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
12
12
  Classifier: Programming Language :: Python :: 3.12
13
13
  Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
14
15
  Requires-Dist: numpy>=2.0
15
16
  Requires-Dist: scipy>=1.12
16
17
  Requires-Dist: numba>=0.60
17
18
  Requires-Dist: anndata>=0.13
18
19
  Requires-Dist: hdf5plugin>=4.0
20
+ Requires-Dist: numcodecs>=0.13
21
+ Requires-Dist: cupy-cuda13x[ctk]>=13.0,<15.0 ; extra == 'cuda'
19
22
  Requires-Dist: sphinx>=7.0 ; extra == 'docs'
20
23
  Requires-Dist: furo>=2024.1.29 ; extra == 'docs'
21
24
  Requires-Dist: myst-parser>=3.0 ; extra == 'docs'
@@ -25,6 +28,7 @@ Project-URL: Homepage, https://meyer-lab.github.io/vsparse/
25
28
  Project-URL: Repository, https://github.com/meyer-lab/vsparse
26
29
  Project-URL: Documentation, https://meyer-lab.github.io/vsparse/
27
30
  Project-URL: Issues, https://github.com/meyer-lab/vsparse/issues
31
+ Provides-Extra: cuda
28
32
  Provides-Extra: docs
29
33
  Description-Content-Type: text/markdown
30
34
 
@@ -55,6 +59,14 @@ pip install vsparse
55
59
  uv add vsparse
56
60
  ```
57
61
 
62
+ For the CUDA support described below (needs an NVIDIA GPU; pulls in CuPy):
63
+
64
+ ```sh
65
+ pip install "vsparse[cuda]"
66
+ # or with uv
67
+ uv add "vsparse[cuda]"
68
+ ```
69
+
58
70
  From source:
59
71
 
60
72
  ```sh
@@ -130,7 +142,8 @@ va = vsparse.VCSCAnnData.from_anndata(adata) # Compresses X and raw.X
130
142
  va.X # VCSCArray
131
143
  va.raw_X # VCSCArray (separate from anndata's .raw)
132
144
 
133
- # Persist to HDF5 (.h5ad) or Zarr with default Blosc2+LZ4 compression
145
+ # Persist to HDF5 (.h5ad) or Zarr with default zstd compression
146
+ # (stored as IVCSC/IVCSR, see below)
134
147
  va.write_h5ad("compressed.h5ad") # Read back with VCSCAnnData.read_h5ad
135
148
  va2 = vsparse.VCSCAnnData.read_h5ad("compressed.h5ad")
136
149
 
@@ -143,41 +156,63 @@ plain = va.to_anndata()
143
156
 
144
157
  ### Byte-Packed On-Disk Format (IVCSC / IVCSR)
145
158
 
146
- For smaller files, pass `format="ivcsc"` (or `"ivcsr"`) on write. This byte-packs the minor-axis indices with delta + varint encoding (inspired by [IVSparse's IVCSC](https://github.com/Seth-Wolfgang/IVSparse)).
159
+ `write_h5ad` / `write_zarr` always store `X`/`raw_X` as IVCSC (from VCSC) or IVCSR (from VCSR). This byte-packs the minor-axis indices with delta + varint encoding (inspired by [IVSparse's IVCSC](https://github.com/Seth-Wolfgang/IVSparse)).
147
160
 
148
161
  It is purely an archival storage format: `read_h5ad` / `read_zarr` decompress the indices on load and return a standard `VCSCArray`/`VCSRArray`.
149
162
 
150
163
  ```python
151
- # Write delta+varint byte-packed indices
152
- va.write_h5ad("archived.h5ad", format="ivcsc")
164
+ # Writes delta+varint byte-packed indices
165
+ va.write_h5ad("archived.h5ad")
153
166
 
154
167
  # Reads back directly as an ordinary VCSCAnnData
155
168
  va_loaded = vsparse.VCSCAnnData.read_h5ad("archived.h5ad")
156
169
  ```
157
170
 
158
- ### Fast Filtering & Depth Normalization (`load_and_normalize`)
171
+ ### Loading, subsetting, and normalizing
172
+
173
+ Loading, subsetting, and normalization are separate steps, so they can be mixed and matched. `vsparse.load_packed` decodes an IVCSR/IVCSC-stored `.h5ad` into a `VCSCAnnData`; normalization is then a view over the stored array (`.normalized("parafac2")` reproduces `parafac2.normalize.prepare_dataset`'s depth normalization and log10 transform) that is never materialized.
174
+
175
+ ```python
176
+ va = vsparse.load_packed("archived.h5ad")
177
+ norm = va.X.normalized("parafac2") # lazy view; norm @ B works without densifying
178
+ ```
159
179
 
160
- For IVCSR-backed datasets, `vsparse.load_and_normalize` bypasses full array decompression for rapid preprocessing, reproducing the filtering and depth normalization from `parafac2.normalize.prepare_dataset`:
180
+ ### CUDA (`to_gpu`)
161
181
 
162
- - **Cell filtering without decoding**: Computes cell totals in $O(n_{\text{unique}})$ time directly from group sizes without unpacking varint indices.
163
- - **Fused filter & normalization**: Performs gene filtering, cell/gene depth-scaling, and $\log_{10}(1000x + 1)$ transform in parallel passes over the compact CSR representation.
182
+ A normalized view moves onto an NVIDIA GPU with `.to_gpu()`, keeping its value-compressed layout there rather than expanding to one float per nonzero — so a matrix that only fits in device memory compressed still fits. Everything floating-point on the device is float32.
164
183
 
165
184
  ```python
166
- adata_norm = vsparse.load_and_normalize(
167
- "archived.h5ad",
168
- min_cell_counts=10.0, # Filter cells with counts <= 10
169
- gene_threshold=0.05, # Filter genes with counts <= 0.05 * n_cells
170
- )
185
+ gpu = vsparse.VCSRArray.from_scipy(counts).normalized("parafac2").to_gpu()
186
+ out = gpu @ B # float32 CuPy array; B @ gpu likewise
171
187
  ```
172
188
 
189
+ cuSPARSE reads only CSR/CSC, so walking the VCS layout on the device needs custom kernels; `vsparse._cuda` supplies four, one per (format, direction). Against the alternative — expanding to a sorted CuPy CSR and calling cuSPARSE — they measured (RTX 5080, 60k x 2k, 6M nonzeros, width 16):
190
+
191
+ | direction | kernel / cuSPARSE | device bytes vs CSR |
192
+ | --- | --- | --- |
193
+ | `VCSR @ B` | 0.71x–0.86x | 0.62x |
194
+ | `VCSC @ B` | 0.83x | 0.51x |
195
+ | `B @ VCSC` | 0.32x | 0.51x |
196
+ | `B @ VCSR` | 0.23x | 0.62x |
197
+
198
+ `CudaNormalizedView.to_cupy_sparse()` builds that CSR baseline if you want it.
199
+
173
200
  See `docs/` for full usage guides and API documentation.
174
201
 
175
202
  ## Development
176
203
 
177
204
  ```sh
178
- uv sync --all-extras --dev
205
+ uv sync --all-extras --dev # add --no-extra cuda to skip the ~1 GB CuPy wheel
179
206
  uv run pytest
180
207
  uv run ruff check .
181
208
  uv run ty check
182
209
  uv run sphinx-build -b html docs docs/_build/html
183
210
  ```
211
+
212
+ The CUDA tests and benchmarks need an NVIDIA GPU; without one `tests/test_cuda.py`
213
+ skips itself. On a GPU machine:
214
+
215
+ ```sh
216
+ uv run pytest -m cuda
217
+ uv run python -m benchmarks.run --set cuda
218
+ ```
@@ -25,6 +25,14 @@ pip install vsparse
25
25
  uv add vsparse
26
26
  ```
27
27
 
28
+ For the CUDA support described below (needs an NVIDIA GPU; pulls in CuPy):
29
+
30
+ ```sh
31
+ pip install "vsparse[cuda]"
32
+ # or with uv
33
+ uv add "vsparse[cuda]"
34
+ ```
35
+
28
36
  From source:
29
37
 
30
38
  ```sh
@@ -100,7 +108,8 @@ va = vsparse.VCSCAnnData.from_anndata(adata) # Compresses X and raw.X
100
108
  va.X # VCSCArray
101
109
  va.raw_X # VCSCArray (separate from anndata's .raw)
102
110
 
103
- # Persist to HDF5 (.h5ad) or Zarr with default Blosc2+LZ4 compression
111
+ # Persist to HDF5 (.h5ad) or Zarr with default zstd compression
112
+ # (stored as IVCSC/IVCSR, see below)
104
113
  va.write_h5ad("compressed.h5ad") # Read back with VCSCAnnData.read_h5ad
105
114
  va2 = vsparse.VCSCAnnData.read_h5ad("compressed.h5ad")
106
115
 
@@ -113,41 +122,63 @@ plain = va.to_anndata()
113
122
 
114
123
  ### Byte-Packed On-Disk Format (IVCSC / IVCSR)
115
124
 
116
- For smaller files, pass `format="ivcsc"` (or `"ivcsr"`) on write. This byte-packs the minor-axis indices with delta + varint encoding (inspired by [IVSparse's IVCSC](https://github.com/Seth-Wolfgang/IVSparse)).
125
+ `write_h5ad` / `write_zarr` always store `X`/`raw_X` as IVCSC (from VCSC) or IVCSR (from VCSR). This byte-packs the minor-axis indices with delta + varint encoding (inspired by [IVSparse's IVCSC](https://github.com/Seth-Wolfgang/IVSparse)).
117
126
 
118
127
  It is purely an archival storage format: `read_h5ad` / `read_zarr` decompress the indices on load and return a standard `VCSCArray`/`VCSRArray`.
119
128
 
120
129
  ```python
121
- # Write delta+varint byte-packed indices
122
- va.write_h5ad("archived.h5ad", format="ivcsc")
130
+ # Writes delta+varint byte-packed indices
131
+ va.write_h5ad("archived.h5ad")
123
132
 
124
133
  # Reads back directly as an ordinary VCSCAnnData
125
134
  va_loaded = vsparse.VCSCAnnData.read_h5ad("archived.h5ad")
126
135
  ```
127
136
 
128
- ### Fast Filtering & Depth Normalization (`load_and_normalize`)
137
+ ### Loading, subsetting, and normalizing
138
+
139
+ Loading, subsetting, and normalization are separate steps, so they can be mixed and matched. `vsparse.load_packed` decodes an IVCSR/IVCSC-stored `.h5ad` into a `VCSCAnnData`; normalization is then a view over the stored array (`.normalized("parafac2")` reproduces `parafac2.normalize.prepare_dataset`'s depth normalization and log10 transform) that is never materialized.
140
+
141
+ ```python
142
+ va = vsparse.load_packed("archived.h5ad")
143
+ norm = va.X.normalized("parafac2") # lazy view; norm @ B works without densifying
144
+ ```
129
145
 
130
- For IVCSR-backed datasets, `vsparse.load_and_normalize` bypasses full array decompression for rapid preprocessing, reproducing the filtering and depth normalization from `parafac2.normalize.prepare_dataset`:
146
+ ### CUDA (`to_gpu`)
131
147
 
132
- - **Cell filtering without decoding**: Computes cell totals in $O(n_{\text{unique}})$ time directly from group sizes without unpacking varint indices.
133
- - **Fused filter & normalization**: Performs gene filtering, cell/gene depth-scaling, and $\log_{10}(1000x + 1)$ transform in parallel passes over the compact CSR representation.
148
+ A normalized view moves onto an NVIDIA GPU with `.to_gpu()`, keeping its value-compressed layout there rather than expanding to one float per nonzero — so a matrix that only fits in device memory compressed still fits. Everything floating-point on the device is float32.
134
149
 
135
150
  ```python
136
- adata_norm = vsparse.load_and_normalize(
137
- "archived.h5ad",
138
- min_cell_counts=10.0, # Filter cells with counts <= 10
139
- gene_threshold=0.05, # Filter genes with counts <= 0.05 * n_cells
140
- )
151
+ gpu = vsparse.VCSRArray.from_scipy(counts).normalized("parafac2").to_gpu()
152
+ out = gpu @ B # float32 CuPy array; B @ gpu likewise
141
153
  ```
142
154
 
155
+ cuSPARSE reads only CSR/CSC, so walking the VCS layout on the device needs custom kernels; `vsparse._cuda` supplies four, one per (format, direction). Against the alternative — expanding to a sorted CuPy CSR and calling cuSPARSE — they measured (RTX 5080, 60k x 2k, 6M nonzeros, width 16):
156
+
157
+ | direction | kernel / cuSPARSE | device bytes vs CSR |
158
+ | --- | --- | --- |
159
+ | `VCSR @ B` | 0.71x–0.86x | 0.62x |
160
+ | `VCSC @ B` | 0.83x | 0.51x |
161
+ | `B @ VCSC` | 0.32x | 0.51x |
162
+ | `B @ VCSR` | 0.23x | 0.62x |
163
+
164
+ `CudaNormalizedView.to_cupy_sparse()` builds that CSR baseline if you want it.
165
+
143
166
  See `docs/` for full usage guides and API documentation.
144
167
 
145
168
  ## Development
146
169
 
147
170
  ```sh
148
- uv sync --all-extras --dev
171
+ uv sync --all-extras --dev # add --no-extra cuda to skip the ~1 GB CuPy wheel
149
172
  uv run pytest
150
173
  uv run ruff check .
151
174
  uv run ty check
152
175
  uv run sphinx-build -b html docs docs/_build/html
153
176
  ```
177
+
178
+ The CUDA tests and benchmarks need an NVIDIA GPU; without one `tests/test_cuda.py`
179
+ skips itself. On a GPU machine:
180
+
181
+ ```sh
182
+ uv run pytest -m cuda
183
+ uv run python -m benchmarks.run --set cuda
184
+ ```
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "vsparse"
3
- version = "0.4.0"
3
+ version = "0.5.0"
4
4
  description = "Value-Compressed Sparse Column/Row (VCSC/VCSR) arrays, with optional AnnData integration"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -17,6 +17,7 @@ classifiers = [
17
17
  "Topic :: Scientific/Engineering :: Bio-Informatics",
18
18
  "Programming Language :: Python :: 3.12",
19
19
  "Programming Language :: Python :: 3.13",
20
+ "Programming Language :: Python :: 3.14",
20
21
  ]
21
22
  dependencies = [
22
23
  "numpy>=2.0",
@@ -24,6 +25,7 @@ dependencies = [
24
25
  "numba>=0.60",
25
26
  "anndata>=0.13",
26
27
  "hdf5plugin>=4.0",
28
+ "numcodecs>=0.13",
27
29
  ]
28
30
 
29
31
  [[project.authors]]
@@ -37,6 +39,7 @@ Documentation = "https://meyer-lab.github.io/vsparse/"
37
39
  Issues = "https://github.com/meyer-lab/vsparse/issues"
38
40
 
39
41
  [project.optional-dependencies]
42
+ cuda = ["cupy-cuda13x[ctk]>=13.0, <15.0"]
40
43
  docs = [
41
44
  "sphinx>=7.0",
42
45
  "furo>=2024.1.29",
@@ -52,6 +55,10 @@ dev = [
52
55
  "ty>=0.0.1a1",
53
56
  "hypothesis>=6.100",
54
57
  "codespell>=2.3",
58
+ "pytest-memray>=1.11.0",
59
+ "vulture>=2.16",
60
+ "radon>=6.0.1",
61
+ "xenon>=0.9.3",
55
62
  ]
56
63
 
57
64
  [build-system]
@@ -90,9 +97,16 @@ ignore-words-list = "coo"
90
97
  [tool.ty.environment]
91
98
  python-version = "3.12"
92
99
 
100
+ [tool.ty.analysis]
101
+ allowed-unresolved-imports = [
102
+ "cupy",
103
+ "cupyx.**",
104
+ ]
105
+
93
106
  [tool.pytest.ini_options]
94
107
  testpaths = ["tests"]
95
108
  addopts = "-ra"
109
+ markers = ["cuda: requires CuPy and an NVIDIA GPU"]
96
110
 
97
111
  [tool.coverage.run]
98
112
  source = ["src/vsparse"]
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "vsparse"
3
- version = "0.4.0"
3
+ version = "0.5.0"
4
4
  description = "Value-Compressed Sparse Column/Row (VCSC/VCSR) arrays, with optional AnnData integration"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -15,6 +15,7 @@ classifiers = [
15
15
  "Topic :: Scientific/Engineering :: Bio-Informatics",
16
16
  "Programming Language :: Python :: 3.12",
17
17
  "Programming Language :: Python :: 3.13",
18
+ "Programming Language :: Python :: 3.14",
18
19
  ]
19
20
  dependencies = [
20
21
  "numpy>=2.0",
@@ -22,6 +23,7 @@ dependencies = [
22
23
  "numba>=0.60",
23
24
  "anndata>=0.13",
24
25
  "hdf5plugin>=4.0",
26
+ "numcodecs>=0.13",
25
27
  ]
26
28
 
27
29
  [project.urls]
@@ -31,6 +33,11 @@ Documentation = "https://meyer-lab.github.io/vsparse/"
31
33
  Issues = "https://github.com/meyer-lab/vsparse/issues"
32
34
 
33
35
  [project.optional-dependencies]
36
+ # CUDA support (`vsparse._cuda`). Kept an opt-in extra because the wheel is
37
+ # ~1 GB and useless without an NVIDIA GPU; CI's CPU jobs pass `--no-extra cuda`.
38
+ cuda = [
39
+ "cupy-cuda13x[ctk]>=13.0, <15.0",
40
+ ]
34
41
  docs = [
35
42
  "sphinx>=7.0",
36
43
  "furo>=2024.1.29",
@@ -46,6 +53,10 @@ dev = [
46
53
  "ty>=0.0.1a1",
47
54
  "hypothesis>=6.100",
48
55
  "codespell>=2.3",
56
+ "pytest-memray>=1.11.0",
57
+ "vulture>=2.16",
58
+ "radon>=6.0.1",
59
+ "xenon>=0.9.3",
49
60
  ]
50
61
 
51
62
  [build-system]
@@ -70,9 +81,18 @@ ignore-words-list = "coo"
70
81
  [tool.ty.environment]
71
82
  python-version = "3.12"
72
83
 
84
+ [tool.ty.analysis]
85
+ # CuPy is an optional extra; the lint job syncs without it.
86
+ allowed-unresolved-imports = ["cupy", "cupyx.**"]
87
+
73
88
  [tool.pytest.ini_options]
74
89
  testpaths = ["tests"]
75
90
  addopts = "-ra"
91
+ markers = [
92
+ # tests/test_cuda.py skips itself without a device, so the marker is for
93
+ # selecting (`-m cuda`) or excluding (`-m 'not cuda'`) the GPU suite.
94
+ "cuda: requires CuPy and an NVIDIA GPU",
95
+ ]
76
96
 
77
97
  [tool.coverage.run]
78
98
  source = ["src/vsparse"]
@@ -9,22 +9,24 @@ AnnData subclass that holds a VCSC/VCSR array as ``X`` directly.
9
9
  from vsparse._anndata import from_anndata, to_layer
10
10
  from vsparse._anndata_class import VCSCAnnData
11
11
  from vsparse._base import VCSCArray, VCSRArray
12
+ from vsparse._cuda import CudaNormalizedView, cuda_is_available
12
13
  from vsparse._norm_common import RECIPES, Recipe
13
- from vsparse._rapid_load import load_and_normalize, load_packed
14
+ from vsparse._rapid_load import load_packed
14
15
  from vsparse._vcs_norm import VCSCArrayNormalized, VCSRArrayNormalized
15
16
 
16
17
  __all__ = [
17
18
  "RECIPES",
19
+ "CudaNormalizedView",
18
20
  "Recipe",
19
21
  "VCSCAnnData",
20
22
  "VCSCArray",
21
23
  "VCSCArrayNormalized",
22
24
  "VCSRArray",
23
25
  "VCSRArrayNormalized",
26
+ "cuda_is_available",
24
27
  "from_anndata",
25
- "load_and_normalize",
26
28
  "load_packed",
27
29
  "to_layer",
28
30
  ]
29
31
 
30
- __version__ = "0.4.0"
32
+ __version__ = "0.5.0"