vsparse 0.5.0__tar.gz → 0.7.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.5.0 → vsparse-0.7.0}/PKG-INFO +26 -1
- {vsparse-0.5.0 → vsparse-0.7.0}/README.md +25 -0
- {vsparse-0.5.0 → vsparse-0.7.0}/pyproject.toml +2 -1
- {vsparse-0.5.0 → vsparse-0.7.0}/pyproject.toml.orig +3 -3
- {vsparse-0.5.0 → vsparse-0.7.0}/src/vsparse/__init__.py +14 -4
- {vsparse-0.5.0 → vsparse-0.7.0}/src/vsparse/_anndata_class.py +29 -14
- {vsparse-0.5.0 → vsparse-0.7.0}/src/vsparse/_base.py +333 -62
- {vsparse-0.5.0 → vsparse-0.7.0}/src/vsparse/_compression.py +80 -48
- {vsparse-0.5.0 → vsparse-0.7.0}/src/vsparse/_construct.py +76 -40
- vsparse-0.7.0/src/vsparse/_cuda.py +1466 -0
- vsparse-0.7.0/src/vsparse/_gds.py +698 -0
- vsparse-0.7.0/src/vsparse/_grouped.py +183 -0
- vsparse-0.7.0/src/vsparse/_huffman.py +684 -0
- vsparse-0.7.0/src/vsparse/_indexutils.py +77 -0
- vsparse-0.7.0/src/vsparse/_io.py +294 -0
- {vsparse-0.5.0 → vsparse-0.7.0}/src/vsparse/_ivcsc.py +226 -20
- {vsparse-0.5.0 → vsparse-0.7.0}/src/vsparse/_norm_common.py +201 -123
- {vsparse-0.5.0 → vsparse-0.7.0}/src/vsparse/_ops.py +209 -64
- vsparse-0.7.0/src/vsparse/_rapid_load.py +108 -0
- vsparse-0.7.0/src/vsparse/_stats.py +212 -0
- {vsparse-0.5.0 → vsparse-0.7.0}/src/vsparse/_vcs_matmul.py +130 -49
- vsparse-0.5.0/src/vsparse/_cuda.py +0 -592
- vsparse-0.5.0/src/vsparse/_indexutils.py +0 -43
- vsparse-0.5.0/src/vsparse/_io.py +0 -144
- vsparse-0.5.0/src/vsparse/_rapid_load.py +0 -49
- vsparse-0.5.0/src/vsparse/_vcs_norm.py +0 -51
- {vsparse-0.5.0 → vsparse-0.7.0}/src/vsparse/_anndata.py +0 -0
- {vsparse-0.5.0 → vsparse-0.7.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.7.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
|
|
@@ -119,6 +119,12 @@ y_left = x @ v # Vector-matrix: (n_rows,) @ (n_rows, n_cols) -> (n_cols,)
|
|
|
119
119
|
Y = v @ B # Matrix-matrix: (n_rows, n_cols) @ (n_cols, k) -> (n_rows, k)
|
|
120
120
|
Y_left = B @ v # Matrix-matrix: (k, n_rows) @ (n_rows, n_cols) -> (k, n_cols)
|
|
121
121
|
|
|
122
|
+
# Reductions, whole-matrix and per group of rows/columns
|
|
123
|
+
col_totals = v.sum(axis=0) # also mean/max/min/getnnz
|
|
124
|
+
cond_sums = v.group_sum(condition_idxs, n_cond) # (n_cond, n_cols) per-condition sums
|
|
125
|
+
cond_depth = v.group_sum(condition_idxs, n_cond, total=True) # (n_cond,) totals
|
|
126
|
+
cond_means = v.group_mean(condition_idxs, n_cond) # also group_nnz
|
|
127
|
+
|
|
122
128
|
# Slicing
|
|
123
129
|
col_slice = v[:, [1, 3, 5]] # Fast major-axis slicing (returns VCSCArray)
|
|
124
130
|
sub = v[0:10, 0:10] # 2D slicing (falls back to scipy)
|
|
@@ -177,6 +183,25 @@ va = vsparse.load_packed("archived.h5ad")
|
|
|
177
183
|
norm = va.X.normalized("parafac2") # lazy view; norm @ B works without densifying
|
|
178
184
|
```
|
|
179
185
|
|
|
186
|
+
`load_packed` can also subset as it decodes: `obs_idx`/`var_idx` take a boolean mask, an array of integer positions, or a slice, and give the same result as indexing a full load, without ever building the full matrix. With IVCSR, only the selected cells are decoded and unselected genes are dropped in the same pass (IVCSC is the same with the axes swapped). Every packed byte is still read, so reading the stream sets the floor: on a 1.26M-cell file, a 1% cell subset decodes `X` in 0.21 s against 0.50 s for all of it.
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
import anndata, h5py
|
|
190
|
+
|
|
191
|
+
with h5py.File("archived.h5ad") as f: # read only obs to build the mask
|
|
192
|
+
obs = anndata.io.read_elem(f["obs"])
|
|
193
|
+
va_blood = vsparse.load_packed("archived.h5ad", obs_idx=obs["tissue"] == "blood")
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Statistics sidecar
|
|
197
|
+
|
|
198
|
+
Every `VCSCArray`/`VCSRArray` carries per-row and per-column summary statistics as `arr.stats` (a `vsparse.VCSStats`): `row_sums`/`col_sums` (total counts), `row_nnz`/`col_nnz` (n-genes/n-cells by counts), and `col_depth_sums` (per-gene sums of depth-normalized counts). They are computed on first access and written next to `X`/`raw_X` by `write_h5ad`/`write_zarr` whether or not they were ever computed or a normalized view was ever made, so a file read back has them without touching the data. Every recipe's per-cell and per-gene scales (`a`/`b`) are derived from them, so only centering/scaling recipes still need a pass over the data. Files without a usable sidecar (older versions, other tools) load as before, and the statistics are recomputed when first needed.
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
va = vsparse.VCSCAnnData.read_h5ad("archived.h5ad")
|
|
202
|
+
keep = va.X.stats.row_sums >= 500 # QC filter from the sidecar alone
|
|
203
|
+
```
|
|
204
|
+
|
|
180
205
|
### CUDA (`to_gpu`)
|
|
181
206
|
|
|
182
207
|
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.
|
|
@@ -85,6 +85,12 @@ y_left = x @ v # Vector-matrix: (n_rows,) @ (n_rows, n_cols) -> (n_cols,)
|
|
|
85
85
|
Y = v @ B # Matrix-matrix: (n_rows, n_cols) @ (n_cols, k) -> (n_rows, k)
|
|
86
86
|
Y_left = B @ v # Matrix-matrix: (k, n_rows) @ (n_rows, n_cols) -> (k, n_cols)
|
|
87
87
|
|
|
88
|
+
# Reductions, whole-matrix and per group of rows/columns
|
|
89
|
+
col_totals = v.sum(axis=0) # also mean/max/min/getnnz
|
|
90
|
+
cond_sums = v.group_sum(condition_idxs, n_cond) # (n_cond, n_cols) per-condition sums
|
|
91
|
+
cond_depth = v.group_sum(condition_idxs, n_cond, total=True) # (n_cond,) totals
|
|
92
|
+
cond_means = v.group_mean(condition_idxs, n_cond) # also group_nnz
|
|
93
|
+
|
|
88
94
|
# Slicing
|
|
89
95
|
col_slice = v[:, [1, 3, 5]] # Fast major-axis slicing (returns VCSCArray)
|
|
90
96
|
sub = v[0:10, 0:10] # 2D slicing (falls back to scipy)
|
|
@@ -143,6 +149,25 @@ va = vsparse.load_packed("archived.h5ad")
|
|
|
143
149
|
norm = va.X.normalized("parafac2") # lazy view; norm @ B works without densifying
|
|
144
150
|
```
|
|
145
151
|
|
|
152
|
+
`load_packed` can also subset as it decodes: `obs_idx`/`var_idx` take a boolean mask, an array of integer positions, or a slice, and give the same result as indexing a full load, without ever building the full matrix. With IVCSR, only the selected cells are decoded and unselected genes are dropped in the same pass (IVCSC is the same with the axes swapped). Every packed byte is still read, so reading the stream sets the floor: on a 1.26M-cell file, a 1% cell subset decodes `X` in 0.21 s against 0.50 s for all of it.
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
import anndata, h5py
|
|
156
|
+
|
|
157
|
+
with h5py.File("archived.h5ad") as f: # read only obs to build the mask
|
|
158
|
+
obs = anndata.io.read_elem(f["obs"])
|
|
159
|
+
va_blood = vsparse.load_packed("archived.h5ad", obs_idx=obs["tissue"] == "blood")
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Statistics sidecar
|
|
163
|
+
|
|
164
|
+
Every `VCSCArray`/`VCSRArray` carries per-row and per-column summary statistics as `arr.stats` (a `vsparse.VCSStats`): `row_sums`/`col_sums` (total counts), `row_nnz`/`col_nnz` (n-genes/n-cells by counts), and `col_depth_sums` (per-gene sums of depth-normalized counts). They are computed on first access and written next to `X`/`raw_X` by `write_h5ad`/`write_zarr` whether or not they were ever computed or a normalized view was ever made, so a file read back has them without touching the data. Every recipe's per-cell and per-gene scales (`a`/`b`) are derived from them, so only centering/scaling recipes still need a pass over the data. Files without a usable sidecar (older versions, other tools) load as before, and the statistics are recomputed when first needed.
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
va = vsparse.VCSCAnnData.read_h5ad("archived.h5ad")
|
|
168
|
+
keep = va.X.stats.row_sums >= 500 # QC filter from the sidecar alone
|
|
169
|
+
```
|
|
170
|
+
|
|
146
171
|
### CUDA (`to_gpu`)
|
|
147
172
|
|
|
148
173
|
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.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "vsparse"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.7.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"
|
|
@@ -101,6 +101,7 @@ python-version = "3.12"
|
|
|
101
101
|
allowed-unresolved-imports = [
|
|
102
102
|
"cupy",
|
|
103
103
|
"cupyx.**",
|
|
104
|
+
"kvikio",
|
|
104
105
|
]
|
|
105
106
|
|
|
106
107
|
[tool.pytest.ini_options]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "vsparse"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.7.0"
|
|
4
4
|
description = "Value-Compressed Sparse Column/Row (VCSC/VCSR) arrays, with optional AnnData integration"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [
|
|
@@ -82,8 +82,8 @@ ignore-words-list = "coo"
|
|
|
82
82
|
python-version = "3.12"
|
|
83
83
|
|
|
84
84
|
[tool.ty.analysis]
|
|
85
|
-
# CuPy
|
|
86
|
-
allowed-unresolved-imports = ["cupy", "cupyx.**"]
|
|
85
|
+
# CuPy and kvikio are optional CUDA extras; the lint job syncs without them.
|
|
86
|
+
allowed-unresolved-imports = ["cupy", "cupyx.**", "kvikio"]
|
|
87
87
|
|
|
88
88
|
[tool.pytest.ini_options]
|
|
89
89
|
testpaths = ["tests"]
|
|
@@ -8,25 +8,35 @@ AnnData subclass that holds a VCSC/VCSR array as ``X`` directly.
|
|
|
8
8
|
|
|
9
9
|
from vsparse._anndata import from_anndata, to_layer
|
|
10
10
|
from vsparse._anndata_class import VCSCAnnData
|
|
11
|
-
from vsparse._base import VCSCArray, VCSRArray
|
|
11
|
+
from vsparse._base import VCSCArray, VCSRArray, sampled_dot
|
|
12
12
|
from vsparse._cuda import CudaNormalizedView, cuda_is_available
|
|
13
|
-
from vsparse.
|
|
13
|
+
from vsparse._gds import CudaStreamedView, open_gpu_stream
|
|
14
|
+
from vsparse._norm_common import (
|
|
15
|
+
RECIPES,
|
|
16
|
+
Recipe,
|
|
17
|
+
VCSCArrayNormalized,
|
|
18
|
+
VCSRArrayNormalized,
|
|
19
|
+
)
|
|
14
20
|
from vsparse._rapid_load import load_packed
|
|
15
|
-
from vsparse.
|
|
21
|
+
from vsparse._stats import VCSStats
|
|
16
22
|
|
|
17
23
|
__all__ = [
|
|
18
24
|
"RECIPES",
|
|
19
25
|
"CudaNormalizedView",
|
|
26
|
+
"CudaStreamedView",
|
|
20
27
|
"Recipe",
|
|
21
28
|
"VCSCAnnData",
|
|
22
29
|
"VCSCArray",
|
|
23
30
|
"VCSCArrayNormalized",
|
|
24
31
|
"VCSRArray",
|
|
25
32
|
"VCSRArrayNormalized",
|
|
33
|
+
"VCSStats",
|
|
26
34
|
"cuda_is_available",
|
|
27
35
|
"from_anndata",
|
|
28
36
|
"load_packed",
|
|
37
|
+
"open_gpu_stream",
|
|
38
|
+
"sampled_dot",
|
|
29
39
|
"to_layer",
|
|
30
40
|
]
|
|
31
41
|
|
|
32
|
-
__version__ = "0.
|
|
42
|
+
__version__ = "0.7.0"
|
|
@@ -13,8 +13,14 @@ import scipy.sparse as sp
|
|
|
13
13
|
|
|
14
14
|
from vsparse import _compression, _io
|
|
15
15
|
from vsparse._base import VCSCArray, VCSRArray, _VCSBase
|
|
16
|
-
from vsparse._norm_common import
|
|
17
|
-
|
|
16
|
+
from vsparse._norm_common import (
|
|
17
|
+
DEFAULT_RECIPE,
|
|
18
|
+
Recipe,
|
|
19
|
+
VCSCArrayNormalized,
|
|
20
|
+
VCSRArrayNormalized,
|
|
21
|
+
_NormCache,
|
|
22
|
+
resolve_recipe,
|
|
23
|
+
)
|
|
18
24
|
|
|
19
25
|
if TYPE_CHECKING:
|
|
20
26
|
from collections.abc import Mapping
|
|
@@ -212,7 +218,18 @@ class VCSCAnnData(ad.AnnData):
|
|
|
212
218
|
oidx, vidx = self._normalize_indices(index)
|
|
213
219
|
oidx = _as_slice_index(oidx, self.n_obs)
|
|
214
220
|
vidx = _as_slice_index(vidx, self.n_vars)
|
|
221
|
+
return type(self)(
|
|
222
|
+
X=_subset_2d(self._vcs_X, oidx, vidx),
|
|
223
|
+
raw_X=_subset_2d(self._vcs_raw_X, oidx, vidx),
|
|
224
|
+
**self._subset_fields(oidx, vidx),
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
def _subset_fields(self, oidx: Any, vidx: Any) -> dict[str, Any]:
|
|
228
|
+
"""Every field but ``X``/``raw_X``, subset to positions ``oidx``/``vidx``.
|
|
215
229
|
|
|
230
|
+
Shared by :meth:`__getitem__` and :func:`~vsparse.load_packed`'s
|
|
231
|
+
``obs_idx``/``var_idx``, which decodes ``X`` already subset.
|
|
232
|
+
"""
|
|
216
233
|
obs = cast(pd.DataFrame, self.obs).iloc[oidx].copy()
|
|
217
234
|
var = cast(pd.DataFrame, self.var).iloc[vidx].copy()
|
|
218
235
|
|
|
@@ -229,18 +246,16 @@ class VCSCAnnData(ad.AnnData):
|
|
|
229
246
|
if _VSPARSE_UNS_KEY in uns:
|
|
230
247
|
uns = {**uns, _VSPARSE_UNS_KEY: {**uns[_VSPARSE_UNS_KEY], "stale": True}}
|
|
231
248
|
|
|
232
|
-
return
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
layers=_map_subset_2d(self.layers, oidx, vidx),
|
|
243
|
-
)
|
|
249
|
+
return {
|
|
250
|
+
"obs": obs,
|
|
251
|
+
"var": var,
|
|
252
|
+
"uns": uns,
|
|
253
|
+
"obsm": _map_subset_1d(self.obsm, oidx),
|
|
254
|
+
"varm": _map_subset_1d(self.varm, vidx),
|
|
255
|
+
"obsp": _map_subset_2d(self.obsp, oidx, oidx),
|
|
256
|
+
"varp": _map_subset_2d(self.varp, vidx, vidx),
|
|
257
|
+
"layers": _map_subset_2d(self.layers, oidx, vidx),
|
|
258
|
+
}
|
|
244
259
|
|
|
245
260
|
def copy(self) -> VCSCAnnData: # ty: ignore[invalid-method-override]
|
|
246
261
|
"""A deep copy, preserving the VCSC/VCSR-backed ``X``/``raw_X``.
|