vsparse 0.3.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.
- {vsparse-0.3.0 → vsparse-0.5.0}/PKG-INFO +70 -35
- vsparse-0.5.0/README.md +184 -0
- {vsparse-0.3.0 → vsparse-0.5.0}/pyproject.toml +29 -3
- {vsparse-0.3.0 → vsparse-0.5.0}/pyproject.toml.orig +28 -2
- {vsparse-0.3.0 → vsparse-0.5.0}/src/vsparse/__init__.py +5 -3
- {vsparse-0.3.0 → vsparse-0.5.0}/src/vsparse/_anndata_class.py +156 -81
- {vsparse-0.3.0 → vsparse-0.5.0}/src/vsparse/_base.py +1 -19
- vsparse-0.5.0/src/vsparse/_compression.py +308 -0
- vsparse-0.5.0/src/vsparse/_cuda.py +592 -0
- {vsparse-0.3.0 → vsparse-0.5.0}/src/vsparse/_io.py +7 -6
- {vsparse-0.3.0 → vsparse-0.5.0}/src/vsparse/_ivcsc.py +18 -19
- vsparse-0.5.0/src/vsparse/_norm_common.py +1190 -0
- {vsparse-0.3.0 → vsparse-0.5.0}/src/vsparse/_ops.py +153 -5
- vsparse-0.5.0/src/vsparse/_rapid_load.py +49 -0
- vsparse-0.5.0/src/vsparse/_vcs_matmul.py +328 -0
- {vsparse-0.3.0 → vsparse-0.5.0}/src/vsparse/_vcs_norm.py +4 -21
- vsparse-0.3.0/README.md +0 -153
- vsparse-0.3.0/src/vsparse/_compression.py +0 -168
- vsparse-0.3.0/src/vsparse/_norm_common.py +0 -729
- vsparse-0.3.0/src/vsparse/_rapid_load.py +0 -556
- vsparse-0.3.0/src/vsparse/_vcs_matmul.py +0 -277
- {vsparse-0.3.0 → vsparse-0.5.0}/src/vsparse/_anndata.py +0 -0
- {vsparse-0.3.0 → vsparse-0.5.0}/src/vsparse/_construct.py +0 -0
- {vsparse-0.3.0 → vsparse-0.5.0}/src/vsparse/_indexutils.py +0 -0
- {vsparse-0.3.0 → vsparse-0.5.0}/src/vsparse/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: vsparse
|
|
3
|
-
Version: 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
|
|
@@ -89,31 +101,31 @@ v = vsparse.VCSCArray.from_scipy(csc)
|
|
|
89
101
|
|
|
90
102
|
# Or build from an AnnData object or SciPy sparse array
|
|
91
103
|
adata = ... # an AnnData object
|
|
92
|
-
v = vsparse.from_anndata(adata)
|
|
93
|
-
vr = vsparse.from_anndata(adata, format="csr")
|
|
104
|
+
v = vsparse.from_anndata(adata) # VCSCArray (column-compressed) from adata.X
|
|
105
|
+
vr = vsparse.from_anndata(adata, format="csr") # VCSRArray (row-compressed)
|
|
94
106
|
|
|
95
107
|
# Transposition is zero-copy (swaps major/minor axes and shares buffers)
|
|
96
|
-
vr = v.T
|
|
108
|
+
vr = v.T # VCSRArray
|
|
97
109
|
|
|
98
110
|
# Scalar arithmetic & math
|
|
99
|
-
v2 = v * 2.0
|
|
100
|
-
v_div = v / 2.0
|
|
101
|
-
v_neg = -v
|
|
102
|
-
v_log = v.log1p()
|
|
111
|
+
v2 = v * 2.0 # Scalar multiplication
|
|
112
|
+
v_div = v / 2.0 # Scalar division
|
|
113
|
+
v_neg = -v # Negation
|
|
114
|
+
v_log = v.log1p() # Elementwise log1p
|
|
103
115
|
|
|
104
116
|
# Matrix & vector products (Numba-parallelized)
|
|
105
|
-
y = v @ x
|
|
106
|
-
y_left = x @ v
|
|
107
|
-
Y = v @ B
|
|
108
|
-
Y_left = B @ v
|
|
117
|
+
y = v @ x # Matrix-vector: (n_rows, n_cols) @ (n_cols,) -> (n_rows,)
|
|
118
|
+
y_left = x @ v # Vector-matrix: (n_rows,) @ (n_rows, n_cols) -> (n_cols,)
|
|
119
|
+
Y = v @ B # Matrix-matrix: (n_rows, n_cols) @ (n_cols, k) -> (n_rows, k)
|
|
120
|
+
Y_left = B @ v # Matrix-matrix: (k, n_rows) @ (n_rows, n_cols) -> (k, n_cols)
|
|
109
121
|
|
|
110
122
|
# Slicing
|
|
111
|
-
col_slice = v[:, [1, 3, 5]]
|
|
112
|
-
sub = v[0:10, 0:10]
|
|
123
|
+
col_slice = v[:, [1, 3, 5]] # Fast major-axis slicing (returns VCSCArray)
|
|
124
|
+
sub = v[0:10, 0:10] # 2D slicing (falls back to scipy)
|
|
113
125
|
|
|
114
126
|
# Conversion & layers
|
|
115
|
-
sp_csc = v.to_scipy()
|
|
116
|
-
dense = v.toarray()
|
|
127
|
+
sp_csc = v.to_scipy() # -> scipy.sparse.csc_array (or to_csr())
|
|
128
|
+
dense = v.toarray() # -> numpy.ndarray
|
|
117
129
|
vsparse.to_layer(adata, v, key="counts_vcsc") # Attach to AnnData layer
|
|
118
130
|
```
|
|
119
131
|
|
|
@@ -126,15 +138,16 @@ is an `AnnData` subclass whose `X` (and optionally `raw_X`) is backed directly b
|
|
|
126
138
|
```python
|
|
127
139
|
import vsparse
|
|
128
140
|
|
|
129
|
-
va = vsparse.VCSCAnnData.from_anndata(adata)
|
|
130
|
-
va.X
|
|
131
|
-
va.raw_X
|
|
141
|
+
va = vsparse.VCSCAnnData.from_anndata(adata) # Compresses X and raw.X
|
|
142
|
+
va.X # VCSCArray
|
|
143
|
+
va.raw_X # VCSCArray (separate from anndata's .raw)
|
|
132
144
|
|
|
133
|
-
# Persist to HDF5 (.h5ad) or Zarr with default
|
|
134
|
-
|
|
145
|
+
# Persist to HDF5 (.h5ad) or Zarr with default zstd compression
|
|
146
|
+
# (stored as IVCSC/IVCSR, see below)
|
|
147
|
+
va.write_h5ad("compressed.h5ad") # Read back with VCSCAnnData.read_h5ad
|
|
135
148
|
va2 = vsparse.VCSCAnnData.read_h5ad("compressed.h5ad")
|
|
136
149
|
|
|
137
|
-
va.write_zarr("compressed.zarr")
|
|
150
|
+
va.write_zarr("compressed.zarr") # Read back with VCSCAnnData.read_zarr
|
|
138
151
|
va3 = vsparse.VCSCAnnData.read_zarr("compressed.zarr")
|
|
139
152
|
|
|
140
153
|
# Escape hatch back to standard AnnData
|
|
@@ -143,41 +156,63 @@ plain = va.to_anndata()
|
|
|
143
156
|
|
|
144
157
|
### Byte-Packed On-Disk Format (IVCSC / IVCSR)
|
|
145
158
|
|
|
146
|
-
|
|
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
|
-
#
|
|
152
|
-
va.write_h5ad("archived.h5ad"
|
|
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
|
-
###
|
|
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
|
-
|
|
180
|
+
### CUDA (`to_gpu`)
|
|
161
181
|
|
|
162
|
-
|
|
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
|
-
|
|
167
|
-
|
|
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
|
+
```
|
vsparse-0.5.0/README.md
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# vsparse
|
|
2
|
+
|
|
3
|
+
`vsparse` provides `VCSCArray`/`VCSRArray`: Value-Compressed Sparse Column/Row (VCSC/VCSR)
|
|
4
|
+
array types, implemented in NumPy and accelerated with [Numba](https://numba.pydata.org/). The
|
|
5
|
+
array types are standalone -- they can be built from and converted to SciPy sparse arrays and
|
|
6
|
+
used entirely without [AnnData](https://anndata.readthedocs.io). `vsparse` also ships an
|
|
7
|
+
optional AnnData integration (`from_anndata`, `to_layer`, and the `VCSCAnnData` subclass) for
|
|
8
|
+
projects that want compressed arrays backed directly into an `AnnData` object.
|
|
9
|
+
|
|
10
|
+
VCSC/VCSR are compressed-sparse layouts inspired by
|
|
11
|
+
[IVSparse's VCSC](https://github.com/Seth-Wolfgang/IVSparse). In addition to the usual
|
|
12
|
+
compressed-sparse pointer/index arrays, nonzero values within each major-axis slice
|
|
13
|
+
(columns for VCSC, rows for VCSR) are deduplicated: each unique value is stored once,
|
|
14
|
+
alongside the list of minor-axis positions that share it. This is a strict memory win
|
|
15
|
+
whenever values repeat heavily within a slice — as is typical for integer count
|
|
16
|
+
matrices, e.g. single-cell RNA-seq counts.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
Install from PyPI:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
pip install vsparse
|
|
24
|
+
# or with uv
|
|
25
|
+
uv add vsparse
|
|
26
|
+
```
|
|
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
|
+
|
|
36
|
+
From source:
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
pip install git+https://github.com/meyer-lab/vsparse.git
|
|
40
|
+
# or with uv
|
|
41
|
+
uv add git+https://github.com/meyer-lab/vsparse.git
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
For local development:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
git clone https://github.com/meyer-lab/vsparse.git
|
|
48
|
+
cd vsparse
|
|
49
|
+
uv sync --all-extras --dev
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Quickstart
|
|
53
|
+
|
|
54
|
+
### Working with VCSC / VCSR arrays
|
|
55
|
+
|
|
56
|
+
`VCSCArray`/`VCSRArray` are standalone array types -- they only need a SciPy sparse array
|
|
57
|
+
(or an AnnData object, if you have one) to be built, and none of the operations below require
|
|
58
|
+
AnnData at all:
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
import vsparse
|
|
62
|
+
import scipy.sparse as sp
|
|
63
|
+
|
|
64
|
+
# Build directly from a SciPy sparse array -- no AnnData involved
|
|
65
|
+
csc = sp.random(1000, 500, density=0.1, format="csc")
|
|
66
|
+
v = vsparse.VCSCArray.from_scipy(csc)
|
|
67
|
+
|
|
68
|
+
# Or build from an AnnData object or SciPy sparse array
|
|
69
|
+
adata = ... # an AnnData object
|
|
70
|
+
v = vsparse.from_anndata(adata) # VCSCArray (column-compressed) from adata.X
|
|
71
|
+
vr = vsparse.from_anndata(adata, format="csr") # VCSRArray (row-compressed)
|
|
72
|
+
|
|
73
|
+
# Transposition is zero-copy (swaps major/minor axes and shares buffers)
|
|
74
|
+
vr = v.T # VCSRArray
|
|
75
|
+
|
|
76
|
+
# Scalar arithmetic & math
|
|
77
|
+
v2 = v * 2.0 # Scalar multiplication
|
|
78
|
+
v_div = v / 2.0 # Scalar division
|
|
79
|
+
v_neg = -v # Negation
|
|
80
|
+
v_log = v.log1p() # Elementwise log1p
|
|
81
|
+
|
|
82
|
+
# Matrix & vector products (Numba-parallelized)
|
|
83
|
+
y = v @ x # Matrix-vector: (n_rows, n_cols) @ (n_cols,) -> (n_rows,)
|
|
84
|
+
y_left = x @ v # Vector-matrix: (n_rows,) @ (n_rows, n_cols) -> (n_cols,)
|
|
85
|
+
Y = v @ B # Matrix-matrix: (n_rows, n_cols) @ (n_cols, k) -> (n_rows, k)
|
|
86
|
+
Y_left = B @ v # Matrix-matrix: (k, n_rows) @ (n_rows, n_cols) -> (k, n_cols)
|
|
87
|
+
|
|
88
|
+
# Slicing
|
|
89
|
+
col_slice = v[:, [1, 3, 5]] # Fast major-axis slicing (returns VCSCArray)
|
|
90
|
+
sub = v[0:10, 0:10] # 2D slicing (falls back to scipy)
|
|
91
|
+
|
|
92
|
+
# Conversion & layers
|
|
93
|
+
sp_csc = v.to_scipy() # -> scipy.sparse.csc_array (or to_csr())
|
|
94
|
+
dense = v.toarray() # -> numpy.ndarray
|
|
95
|
+
vsparse.to_layer(adata, v, key="counts_vcsc") # Attach to AnnData layer
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### `VCSCAnnData`: AnnData with direct VCSC/VCSR backing
|
|
99
|
+
|
|
100
|
+
For projects that want the compressed array wired directly into AnnData, `vsparse.VCSCAnnData`
|
|
101
|
+
is an `AnnData` subclass whose `X` (and optionally `raw_X`) is backed directly by a
|
|
102
|
+
`VCSCArray` or `VCSRArray`:
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
import vsparse
|
|
106
|
+
|
|
107
|
+
va = vsparse.VCSCAnnData.from_anndata(adata) # Compresses X and raw.X
|
|
108
|
+
va.X # VCSCArray
|
|
109
|
+
va.raw_X # VCSCArray (separate from anndata's .raw)
|
|
110
|
+
|
|
111
|
+
# Persist to HDF5 (.h5ad) or Zarr with default zstd compression
|
|
112
|
+
# (stored as IVCSC/IVCSR, see below)
|
|
113
|
+
va.write_h5ad("compressed.h5ad") # Read back with VCSCAnnData.read_h5ad
|
|
114
|
+
va2 = vsparse.VCSCAnnData.read_h5ad("compressed.h5ad")
|
|
115
|
+
|
|
116
|
+
va.write_zarr("compressed.zarr") # Read back with VCSCAnnData.read_zarr
|
|
117
|
+
va3 = vsparse.VCSCAnnData.read_zarr("compressed.zarr")
|
|
118
|
+
|
|
119
|
+
# Escape hatch back to standard AnnData
|
|
120
|
+
plain = va.to_anndata()
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Byte-Packed On-Disk Format (IVCSC / IVCSR)
|
|
124
|
+
|
|
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)).
|
|
126
|
+
|
|
127
|
+
It is purely an archival storage format: `read_h5ad` / `read_zarr` decompress the indices on load and return a standard `VCSCArray`/`VCSRArray`.
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
# Writes delta+varint byte-packed indices
|
|
131
|
+
va.write_h5ad("archived.h5ad")
|
|
132
|
+
|
|
133
|
+
# Reads back directly as an ordinary VCSCAnnData
|
|
134
|
+
va_loaded = vsparse.VCSCAnnData.read_h5ad("archived.h5ad")
|
|
135
|
+
```
|
|
136
|
+
|
|
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
|
+
```
|
|
145
|
+
|
|
146
|
+
### CUDA (`to_gpu`)
|
|
147
|
+
|
|
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.
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
gpu = vsparse.VCSRArray.from_scipy(counts).normalized("parafac2").to_gpu()
|
|
152
|
+
out = gpu @ B # float32 CuPy array; B @ gpu likewise
|
|
153
|
+
```
|
|
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
|
+
|
|
166
|
+
See `docs/` for full usage guides and API documentation.
|
|
167
|
+
|
|
168
|
+
## Development
|
|
169
|
+
|
|
170
|
+
```sh
|
|
171
|
+
uv sync --all-extras --dev # add --no-extra cuda to skip the ~1 GB CuPy wheel
|
|
172
|
+
uv run pytest
|
|
173
|
+
uv run ruff check .
|
|
174
|
+
uv run ty check
|
|
175
|
+
uv run sphinx-build -b html docs docs/_build/html
|
|
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.
|
|
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",
|
|
@@ -50,6 +53,12 @@ dev = [
|
|
|
50
53
|
"pytest-cov>=5.0",
|
|
51
54
|
"ruff>=0.6",
|
|
52
55
|
"ty>=0.0.1a1",
|
|
56
|
+
"hypothesis>=6.100",
|
|
57
|
+
"codespell>=2.3",
|
|
58
|
+
"pytest-memray>=1.11.0",
|
|
59
|
+
"vulture>=2.16",
|
|
60
|
+
"radon>=6.0.1",
|
|
61
|
+
"xenon>=0.9.3",
|
|
53
62
|
]
|
|
54
63
|
|
|
55
64
|
[build-system]
|
|
@@ -64,10 +73,16 @@ target-version = "py312"
|
|
|
64
73
|
select = [
|
|
65
74
|
"E",
|
|
66
75
|
"F",
|
|
67
|
-
"I",
|
|
68
|
-
"UP",
|
|
69
76
|
"B",
|
|
70
77
|
"NPY",
|
|
78
|
+
"PD",
|
|
79
|
+
"SIM",
|
|
80
|
+
"RET",
|
|
81
|
+
"PIE",
|
|
82
|
+
"ERA",
|
|
83
|
+
"PERF",
|
|
84
|
+
"UP",
|
|
85
|
+
"C4",
|
|
71
86
|
"RUF",
|
|
72
87
|
]
|
|
73
88
|
ignore = ["E501"]
|
|
@@ -75,12 +90,23 @@ ignore = ["E501"]
|
|
|
75
90
|
[tool.ruff.lint.isort]
|
|
76
91
|
known-first-party = ["vsparse"]
|
|
77
92
|
|
|
93
|
+
[tool.codespell]
|
|
94
|
+
skip = "*.lock,uv.lock,.venv,docs/_build,benchmarks/baselines.json"
|
|
95
|
+
ignore-words-list = "coo"
|
|
96
|
+
|
|
78
97
|
[tool.ty.environment]
|
|
79
98
|
python-version = "3.12"
|
|
80
99
|
|
|
100
|
+
[tool.ty.analysis]
|
|
101
|
+
allowed-unresolved-imports = [
|
|
102
|
+
"cupy",
|
|
103
|
+
"cupyx.**",
|
|
104
|
+
]
|
|
105
|
+
|
|
81
106
|
[tool.pytest.ini_options]
|
|
82
107
|
testpaths = ["tests"]
|
|
83
108
|
addopts = "-ra"
|
|
109
|
+
markers = ["cuda: requires CuPy and an NVIDIA GPU"]
|
|
84
110
|
|
|
85
111
|
[tool.coverage.run]
|
|
86
112
|
source = ["src/vsparse"]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "vsparse"
|
|
3
|
-
version = "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",
|
|
@@ -44,6 +51,12 @@ dev = [
|
|
|
44
51
|
"pytest-cov>=5.0",
|
|
45
52
|
"ruff>=0.6",
|
|
46
53
|
"ty>=0.0.1a1",
|
|
54
|
+
"hypothesis>=6.100",
|
|
55
|
+
"codespell>=2.3",
|
|
56
|
+
"pytest-memray>=1.11.0",
|
|
57
|
+
"vulture>=2.16",
|
|
58
|
+
"radon>=6.0.1",
|
|
59
|
+
"xenon>=0.9.3",
|
|
47
60
|
]
|
|
48
61
|
|
|
49
62
|
[build-system]
|
|
@@ -55,18 +68,31 @@ line-length = 100
|
|
|
55
68
|
target-version = "py312"
|
|
56
69
|
|
|
57
70
|
[tool.ruff.lint]
|
|
58
|
-
select = ["E", "F", "
|
|
71
|
+
select = ["E", "F", "B", "NPY", "PD", "SIM", "RET", "PIE", "ERA", "PERF", "UP", "C4", "RUF"]
|
|
59
72
|
ignore = ["E501"]
|
|
60
73
|
|
|
61
74
|
[tool.ruff.lint.isort]
|
|
62
75
|
known-first-party = ["vsparse"]
|
|
63
76
|
|
|
77
|
+
[tool.codespell]
|
|
78
|
+
skip = "*.lock,uv.lock,.venv,docs/_build,benchmarks/baselines.json"
|
|
79
|
+
ignore-words-list = "coo"
|
|
80
|
+
|
|
64
81
|
[tool.ty.environment]
|
|
65
82
|
python-version = "3.12"
|
|
66
83
|
|
|
84
|
+
[tool.ty.analysis]
|
|
85
|
+
# CuPy is an optional extra; the lint job syncs without it.
|
|
86
|
+
allowed-unresolved-imports = ["cupy", "cupyx.**"]
|
|
87
|
+
|
|
67
88
|
[tool.pytest.ini_options]
|
|
68
89
|
testpaths = ["tests"]
|
|
69
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
|
+
]
|
|
70
96
|
|
|
71
97
|
[tool.coverage.run]
|
|
72
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
|
|
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.
|
|
32
|
+
__version__ = "0.5.0"
|