matrix-toolkit 0.0.1__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.
- matrix_toolkit-0.0.1/LICENSE +21 -0
- matrix_toolkit-0.0.1/PKG-INFO +303 -0
- matrix_toolkit-0.0.1/README.md +247 -0
- matrix_toolkit-0.0.1/matrix_toolkit/__init__.py +24 -0
- matrix_toolkit-0.0.1/matrix_toolkit/anymatrix/__init__.py +21 -0
- matrix_toolkit-0.0.1/matrix_toolkit/anymatrix/groups/__init__.py +3 -0
- matrix_toolkit-0.0.1/matrix_toolkit/anymatrix/groups/core.py +445 -0
- matrix_toolkit-0.0.1/matrix_toolkit/anymatrix/groups/core_extended.py +830 -0
- matrix_toolkit-0.0.1/matrix_toolkit/anymatrix/groups/gallery.py +169 -0
- matrix_toolkit-0.0.1/matrix_toolkit/anymatrix/groups/hadamard.py +71 -0
- matrix_toolkit-0.0.1/matrix_toolkit/anymatrix/groups/matlab.py +330 -0
- matrix_toolkit-0.0.1/matrix_toolkit/anymatrix/groups/registry.py +249 -0
- matrix_toolkit-0.0.1/matrix_toolkit/anymatrix/groups/regtools.py +246 -0
- matrix_toolkit-0.0.1/matrix_toolkit/anymatrix/properties.py +470 -0
- matrix_toolkit-0.0.1/matrix_toolkit/anymatrix/registry.py +249 -0
- matrix_toolkit-0.0.1/matrix_toolkit/anymatrix/testing/__init__.py +6 -0
- matrix_toolkit-0.0.1/matrix_toolkit/anymatrix/testing/property_checker.py +72 -0
- matrix_toolkit-0.0.1/matrix_toolkit/anymatrix/testing/test_anymatrix.py +180 -0
- matrix_toolkit-0.0.1/matrix_toolkit/anymatrix/testing/test_runner.py +317 -0
- matrix_toolkit-0.0.1/matrix_toolkit/cli/__init__.py +5 -0
- matrix_toolkit-0.0.1/matrix_toolkit/cli/main.py +227 -0
- matrix_toolkit-0.0.1/matrix_toolkit/converters/__init__.py +15 -0
- matrix_toolkit-0.0.1/matrix_toolkit/converters/base.py +67 -0
- matrix_toolkit-0.0.1/matrix_toolkit/converters/cupy_converter.py +72 -0
- matrix_toolkit-0.0.1/matrix_toolkit/converters/jax_converter.py +75 -0
- matrix_toolkit-0.0.1/matrix_toolkit/converters/numpy_converter.py +52 -0
- matrix_toolkit-0.0.1/matrix_toolkit/converters/scipy_converter.py +90 -0
- matrix_toolkit-0.0.1/matrix_toolkit/converters/torch_converter.py +88 -0
- matrix_toolkit-0.0.1/matrix_toolkit/core/__init__.py +8 -0
- matrix_toolkit-0.0.1/matrix_toolkit/core/cache.py +128 -0
- matrix_toolkit-0.0.1/matrix_toolkit/core/config.py +94 -0
- matrix_toolkit-0.0.1/matrix_toolkit/core/fetcher.py +381 -0
- matrix_toolkit-0.0.1/matrix_toolkit/core/search.py +202 -0
- matrix_toolkit-0.0.1/matrix_toolkit/datasets/__init__.py +15 -0
- matrix_toolkit-0.0.1/matrix_toolkit/datasets/dataset.py +197 -0
- matrix_toolkit-0.0.1/matrix_toolkit/datasets/samplers.py +223 -0
- matrix_toolkit-0.0.1/matrix_toolkit/generators/__init__.py +11 -0
- matrix_toolkit-0.0.1/matrix_toolkit/generators/base.py +65 -0
- matrix_toolkit-0.0.1/matrix_toolkit/generators/properties.py +325 -0
- matrix_toolkit-0.0.1/matrix_toolkit/integrations/__init__.py +10 -0
- matrix_toolkit-0.0.1/matrix_toolkit/integrations/pytorch.py +107 -0
- matrix_toolkit-0.0.1/matrix_toolkit/integrations/sklearn.py +142 -0
- matrix_toolkit-0.0.1/matrix_toolkit/storage/__init__.py +6 -0
- matrix_toolkit-0.0.1/matrix_toolkit/storage/loader.py +212 -0
- matrix_toolkit-0.0.1/matrix_toolkit/storage/saver.py +197 -0
- matrix_toolkit-0.0.1/matrix_toolkit/unified.py +260 -0
- matrix_toolkit-0.0.1/matrix_toolkit/utils/__init__.py +11 -0
- matrix_toolkit-0.0.1/matrix_toolkit/utils/metadata.py +124 -0
- matrix_toolkit-0.0.1/matrix_toolkit/utils/validation.py +207 -0
- matrix_toolkit-0.0.1/matrix_toolkit/utils/visualization.py +246 -0
- matrix_toolkit-0.0.1/matrix_toolkit.egg-info/PKG-INFO +303 -0
- matrix_toolkit-0.0.1/matrix_toolkit.egg-info/SOURCES.txt +66 -0
- matrix_toolkit-0.0.1/matrix_toolkit.egg-info/dependency_links.txt +1 -0
- matrix_toolkit-0.0.1/matrix_toolkit.egg-info/entry_points.txt +3 -0
- matrix_toolkit-0.0.1/matrix_toolkit.egg-info/requires.txt +34 -0
- matrix_toolkit-0.0.1/matrix_toolkit.egg-info/top_level.txt +1 -0
- matrix_toolkit-0.0.1/pyproject.toml +96 -0
- matrix_toolkit-0.0.1/setup.cfg +82 -0
- matrix_toolkit-0.0.1/tests/test_anymatrix_complete.py +283 -0
- matrix_toolkit-0.0.1/tests/test_converters.py +46 -0
- matrix_toolkit-0.0.1/tests/test_dataset.py +51 -0
- matrix_toolkit-0.0.1/tests/test_fetcher.py +66 -0
- matrix_toolkit-0.0.1/tests/test_integrations.py +52 -0
- matrix_toolkit-0.0.1/tests/test_metadata.py +77 -0
- matrix_toolkit-0.0.1/tests/test_samplers.py +74 -0
- matrix_toolkit-0.0.1/tests/test_storage.py +67 -0
- matrix_toolkit-0.0.1/tests/test_validation.py +67 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 inEXASCALE
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: matrix-toolkit
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A comprehensive toolkit for sparse matrix management and test matrix generation
|
|
5
|
+
Author: PAPA
|
|
6
|
+
Author-email: Xinye Chen <xinyechenai@gmail.com>
|
|
7
|
+
License: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/yourusername/matrix-toolkit
|
|
9
|
+
Project-URL: Documentation, https://matrix-toolkit.readthedocs.io
|
|
10
|
+
Project-URL: Repository, https://github.com/yourusername/matrix-toolkit
|
|
11
|
+
Project-URL: Issues, https://github.com/yourusername/matrix-toolkit/issues
|
|
12
|
+
Keywords: sparse-matrix,suitesparse,anymatrix,test-matrices,scientific-computing,numerical-analysis
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
23
|
+
Requires-Python: >=3.8
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: numpy>=1.20.0
|
|
27
|
+
Requires-Dist: scipy>=1.7.0
|
|
28
|
+
Requires-Dist: requests>=2.25.0
|
|
29
|
+
Requires-Dist: tqdm>=4.60.0
|
|
30
|
+
Requires-Dist: pyyaml>=5.4.0
|
|
31
|
+
Requires-Dist: pandas>=1.3.0
|
|
32
|
+
Requires-Dist: matplotlib>=3.3.0
|
|
33
|
+
Requires-Dist: click>=8.0.0
|
|
34
|
+
Requires-Dist: joblib>=1.0.0
|
|
35
|
+
Requires-Dist: h5py>=3.0.0
|
|
36
|
+
Provides-Extra: cupy
|
|
37
|
+
Requires-Dist: cupy>=10.0.0; extra == "cupy"
|
|
38
|
+
Provides-Extra: jax
|
|
39
|
+
Requires-Dist: jax>=0.3.0; extra == "jax"
|
|
40
|
+
Requires-Dist: jaxlib>=0.3.0; extra == "jax"
|
|
41
|
+
Provides-Extra: torch
|
|
42
|
+
Requires-Dist: torch>=1.9.0; extra == "torch"
|
|
43
|
+
Provides-Extra: all
|
|
44
|
+
Requires-Dist: cupy>=10.0.0; extra == "all"
|
|
45
|
+
Requires-Dist: jax>=0.3.0; extra == "all"
|
|
46
|
+
Requires-Dist: jaxlib>=0.3.0; extra == "all"
|
|
47
|
+
Requires-Dist: torch>=1.9.0; extra == "all"
|
|
48
|
+
Provides-Extra: dev
|
|
49
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
50
|
+
Requires-Dist: pytest-cov>=3.0.0; extra == "dev"
|
|
51
|
+
Requires-Dist: black>=22.0.0; extra == "dev"
|
|
52
|
+
Requires-Dist: flake8>=4.0.0; extra == "dev"
|
|
53
|
+
Requires-Dist: mypy>=0.950; extra == "dev"
|
|
54
|
+
Requires-Dist: sphinx>=4.5.0; extra == "dev"
|
|
55
|
+
Dynamic: license-file
|
|
56
|
+
|
|
57
|
+
# matrix-toolkit
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
A comprehensive Python toolkit for fetching, managing, and converting sparse matrices from the SuiteSparse Matrix Collection, plus programmatic generation of test matrices inspired by MATLAB's anymatrix.
|
|
62
|
+
|
|
63
|
+
## Features
|
|
64
|
+
|
|
65
|
+
### SuiteSparse Integration
|
|
66
|
+
- **Smart Search & Filter**: Search matrices by size, sparsity, symmetry, domain, and more
|
|
67
|
+
- **Multi-Backend Support**: Automatic conversion to SciPy, CuPy, JAX, PyTorch formats
|
|
68
|
+
- **Flexible Storage**: Save and load matrix collections with multiple formats (NPZ, HDF5, MAT)
|
|
69
|
+
- **Dataset Management**: Create reproducible matrix datasets with train/val/test splits
|
|
70
|
+
- **Parallel Processing**: Multi-threaded downloading and processing
|
|
71
|
+
- **CLI Tools**: Command-line interface for quick operations
|
|
72
|
+
|
|
73
|
+
### Anymatrix Integration
|
|
74
|
+
- **Test Matrix Generation**: Programmatic generation of 40+ well-defined test matrices
|
|
75
|
+
- **Property Verification**: Automatic checking of mathematical properties
|
|
76
|
+
- **Comprehensive Testing**: Built-in test suite for all generated matrices
|
|
77
|
+
- **Multiple Groups**: Core, gallery, and custom matrix collections
|
|
78
|
+
- **Unified Interface**: Single API for both SuiteSparse and generated matrices
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
## Installation
|
|
82
|
+
|
|
83
|
+
### Basic Installation
|
|
84
|
+
```bash
|
|
85
|
+
pip install matrix-toolkit
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### With Optional Dependencies
|
|
89
|
+
```bash
|
|
90
|
+
# For CuPy support
|
|
91
|
+
pip install matrix-toolkit[cupy]
|
|
92
|
+
|
|
93
|
+
# For JAX support
|
|
94
|
+
pip install matrix-toolkit[jax]
|
|
95
|
+
|
|
96
|
+
# For PyTorch support
|
|
97
|
+
pip install matrix-toolkit[torch]
|
|
98
|
+
|
|
99
|
+
# Install all optional dependencies
|
|
100
|
+
pip install matrix-toolkit[all]
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Development Installation
|
|
104
|
+
```bash
|
|
105
|
+
git clone https://github.com/inEXASCALE/matrix-toolkit.git
|
|
106
|
+
cd matrix-toolkit
|
|
107
|
+
pip install -e ".[dev]"
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Quick Start
|
|
111
|
+
|
|
112
|
+
### Basic Usage
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from matrix_toolkit import MatrixFetcher
|
|
116
|
+
|
|
117
|
+
# Initialize fetcher
|
|
118
|
+
fetcher = MatrixFetcher()
|
|
119
|
+
|
|
120
|
+
# Search for matrices
|
|
121
|
+
matrices = fetcher.search(
|
|
122
|
+
rows=(1000, 50000),
|
|
123
|
+
sparsity=(0.8, 0.99),
|
|
124
|
+
symmetry='symmetric'
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
# Fetch a specific matrix
|
|
128
|
+
matrix = fetcher.get_matrix(
|
|
129
|
+
'HB/494_bus',
|
|
130
|
+
backend='scipy',
|
|
131
|
+
format='csr'
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
# Random sampling
|
|
135
|
+
sample = fetcher.fetch(
|
|
136
|
+
n=10,
|
|
137
|
+
mode='random',
|
|
138
|
+
filters={'domain': 'physics'}
|
|
139
|
+
)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Dataset Creation
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
# Create a standardized dataset
|
|
146
|
+
dataset = fetcher.create_dataset(
|
|
147
|
+
name='my_dataset',
|
|
148
|
+
filters={
|
|
149
|
+
'rows': (5000, 20000),
|
|
150
|
+
'sparsity': (0.9, 0.99),
|
|
151
|
+
},
|
|
152
|
+
size=100,
|
|
153
|
+
split={'train': 0.7, 'val': 0.15, 'test': 0.15}
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
# Save dataset
|
|
157
|
+
dataset.save('my_dataset')
|
|
158
|
+
|
|
159
|
+
# Load dataset
|
|
160
|
+
from matrix_toolkit.datasets import MatrixDataset
|
|
161
|
+
dataset = MatrixDataset.load('my_dataset')
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Storage Management
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
# Save collection
|
|
168
|
+
fetcher.save_collection(
|
|
169
|
+
matrices,
|
|
170
|
+
path='/data/my_matrices',
|
|
171
|
+
format='npz',
|
|
172
|
+
compression=True
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
# Load collection
|
|
176
|
+
loaded = fetcher.load_collection('/data/my_matrices')
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## CLI Usage
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
# Search matrices
|
|
183
|
+
matrix-toolkit search --rows 1000:50000 --sparsity 0.9:0.99
|
|
184
|
+
|
|
185
|
+
# Fetch a matrix
|
|
186
|
+
matrix-toolkit fetch --name HB/494_bus --format csr --backend scipy
|
|
187
|
+
|
|
188
|
+
# List matrices by domain
|
|
189
|
+
matrix-toolkit list --domain physics
|
|
190
|
+
|
|
191
|
+
# Clear cache
|
|
192
|
+
matrix-toolkit cache --clear
|
|
193
|
+
|
|
194
|
+
# Create dataset
|
|
195
|
+
matrix-toolkit dataset create --config dataset.yaml
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Anymatrix Test Matrices
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
from matrix_toolkit.anymatrix import AnyMatrix, MatrixProperties
|
|
202
|
+
|
|
203
|
+
# Initialize anymatrix
|
|
204
|
+
am = AnyMatrix()
|
|
205
|
+
|
|
206
|
+
# List available matrices
|
|
207
|
+
groups = am.groups() # ['core', 'gallery']
|
|
208
|
+
matrices = am.list('core') # List matrices in core group
|
|
209
|
+
|
|
210
|
+
# Generate a matrix
|
|
211
|
+
beta_matrix = am.generate('core/beta', 10)
|
|
212
|
+
|
|
213
|
+
# Check properties
|
|
214
|
+
assert MatrixProperties.is_symmetric(beta_matrix)
|
|
215
|
+
assert MatrixProperties.is_positive_definite(beta_matrix)
|
|
216
|
+
|
|
217
|
+
# Search for matrices with specific properties
|
|
218
|
+
symmetric_matrices = am.search(['symmetric', 'positive definite'])
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Unified Interface
|
|
222
|
+
|
|
223
|
+
```python
|
|
224
|
+
from matrix_toolkit import UnifiedMatrixCollection
|
|
225
|
+
|
|
226
|
+
mc = UnifiedMatrixCollection()
|
|
227
|
+
|
|
228
|
+
# Get from anymatrix
|
|
229
|
+
A = mc.get('anymatrix/core/beta', 10)
|
|
230
|
+
|
|
231
|
+
# Get from SuiteSparse
|
|
232
|
+
B = mc.get('suitesparse/HB/494_bus', backend='scipy')
|
|
233
|
+
|
|
234
|
+
# Search both collections
|
|
235
|
+
results = mc.search(properties=['symmetric'])
|
|
236
|
+
|
|
237
|
+
# Verify properties automatically
|
|
238
|
+
mc.verify_properties('anymatrix/core/beta', 10, verbose=True)
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Available Anymatrix Collections
|
|
242
|
+
|
|
243
|
+
### Core Group
|
|
244
|
+
- `beta` - Symmetric positive definite matrix
|
|
245
|
+
- `fourier` - Discrete Fourier transform matrix (unitary)
|
|
246
|
+
- `nilpot_triang` - Nilpotent upper triangular
|
|
247
|
+
- `nilpot_tridiag` - Nilpotent tridiagonal
|
|
248
|
+
- `vand` - Vandermonde matrix
|
|
249
|
+
- `circul_binom` - Circulant with binomial coefficients
|
|
250
|
+
- `stoch_cesaro` - Stochastic Cesaro matrix
|
|
251
|
+
- `tournament` - Random tournament matrix
|
|
252
|
+
- `perfect_shuffle` - Perfect shuffle permutation
|
|
253
|
+
- `collatz` - Collatz conjecture matrix
|
|
254
|
+
- And more...
|
|
255
|
+
|
|
256
|
+
### Gallery Group
|
|
257
|
+
- `lehmer` - Lehmer matrix (symmetric positive definite)
|
|
258
|
+
- `minij` - MIN(i,j) matrix
|
|
259
|
+
- `moler` - Moler matrix
|
|
260
|
+
- `pei` - Pei matrix
|
|
261
|
+
- `clement` - Clement tridiagonal
|
|
262
|
+
- `kms` - Kac-Murdock-Szego Toeplitz matrix
|
|
263
|
+
|
|
264
|
+
## Running Tests
|
|
265
|
+
|
|
266
|
+
### Test all anymatrix matrices
|
|
267
|
+
```bash
|
|
268
|
+
python examples/run_anymatrix_tests.py --verbose --report test_report.txt
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Test specific groups
|
|
272
|
+
```bash
|
|
273
|
+
python examples/run_anymatrix_tests.py --groups core gallery
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Python API
|
|
277
|
+
```python
|
|
278
|
+
from matrix_toolkit.anymatrix.testing import run_all_tests
|
|
279
|
+
|
|
280
|
+
results = run_all_tests(verbose=True, generate_report=True)
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
## Contributing
|
|
285
|
+
|
|
286
|
+
Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
287
|
+
|
|
288
|
+
## License
|
|
289
|
+
|
|
290
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
291
|
+
|
|
292
|
+
## Citation
|
|
293
|
+
|
|
294
|
+
If you use this toolkit in your research, please cite:
|
|
295
|
+
|
|
296
|
+
```bibtex
|
|
297
|
+
@software{matrix_toolkit,
|
|
298
|
+
title={Matrix Toolkit: A Python Package for Sparse Matrix Management},
|
|
299
|
+
author={Xinye Chen},
|
|
300
|
+
year={2024},
|
|
301
|
+
url={https://github.com/chenxinye/matrix-toolkit}
|
|
302
|
+
}
|
|
303
|
+
```
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# matrix-toolkit
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
A comprehensive Python toolkit for fetching, managing, and converting sparse matrices from the SuiteSparse Matrix Collection, plus programmatic generation of test matrices inspired by MATLAB's anymatrix.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
### SuiteSparse Integration
|
|
10
|
+
- **Smart Search & Filter**: Search matrices by size, sparsity, symmetry, domain, and more
|
|
11
|
+
- **Multi-Backend Support**: Automatic conversion to SciPy, CuPy, JAX, PyTorch formats
|
|
12
|
+
- **Flexible Storage**: Save and load matrix collections with multiple formats (NPZ, HDF5, MAT)
|
|
13
|
+
- **Dataset Management**: Create reproducible matrix datasets with train/val/test splits
|
|
14
|
+
- **Parallel Processing**: Multi-threaded downloading and processing
|
|
15
|
+
- **CLI Tools**: Command-line interface for quick operations
|
|
16
|
+
|
|
17
|
+
### Anymatrix Integration
|
|
18
|
+
- **Test Matrix Generation**: Programmatic generation of 40+ well-defined test matrices
|
|
19
|
+
- **Property Verification**: Automatic checking of mathematical properties
|
|
20
|
+
- **Comprehensive Testing**: Built-in test suite for all generated matrices
|
|
21
|
+
- **Multiple Groups**: Core, gallery, and custom matrix collections
|
|
22
|
+
- **Unified Interface**: Single API for both SuiteSparse and generated matrices
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
### Basic Installation
|
|
28
|
+
```bash
|
|
29
|
+
pip install matrix-toolkit
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### With Optional Dependencies
|
|
33
|
+
```bash
|
|
34
|
+
# For CuPy support
|
|
35
|
+
pip install matrix-toolkit[cupy]
|
|
36
|
+
|
|
37
|
+
# For JAX support
|
|
38
|
+
pip install matrix-toolkit[jax]
|
|
39
|
+
|
|
40
|
+
# For PyTorch support
|
|
41
|
+
pip install matrix-toolkit[torch]
|
|
42
|
+
|
|
43
|
+
# Install all optional dependencies
|
|
44
|
+
pip install matrix-toolkit[all]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Development Installation
|
|
48
|
+
```bash
|
|
49
|
+
git clone https://github.com/inEXASCALE/matrix-toolkit.git
|
|
50
|
+
cd matrix-toolkit
|
|
51
|
+
pip install -e ".[dev]"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Quick Start
|
|
55
|
+
|
|
56
|
+
### Basic Usage
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from matrix_toolkit import MatrixFetcher
|
|
60
|
+
|
|
61
|
+
# Initialize fetcher
|
|
62
|
+
fetcher = MatrixFetcher()
|
|
63
|
+
|
|
64
|
+
# Search for matrices
|
|
65
|
+
matrices = fetcher.search(
|
|
66
|
+
rows=(1000, 50000),
|
|
67
|
+
sparsity=(0.8, 0.99),
|
|
68
|
+
symmetry='symmetric'
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
# Fetch a specific matrix
|
|
72
|
+
matrix = fetcher.get_matrix(
|
|
73
|
+
'HB/494_bus',
|
|
74
|
+
backend='scipy',
|
|
75
|
+
format='csr'
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
# Random sampling
|
|
79
|
+
sample = fetcher.fetch(
|
|
80
|
+
n=10,
|
|
81
|
+
mode='random',
|
|
82
|
+
filters={'domain': 'physics'}
|
|
83
|
+
)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Dataset Creation
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
# Create a standardized dataset
|
|
90
|
+
dataset = fetcher.create_dataset(
|
|
91
|
+
name='my_dataset',
|
|
92
|
+
filters={
|
|
93
|
+
'rows': (5000, 20000),
|
|
94
|
+
'sparsity': (0.9, 0.99),
|
|
95
|
+
},
|
|
96
|
+
size=100,
|
|
97
|
+
split={'train': 0.7, 'val': 0.15, 'test': 0.15}
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
# Save dataset
|
|
101
|
+
dataset.save('my_dataset')
|
|
102
|
+
|
|
103
|
+
# Load dataset
|
|
104
|
+
from matrix_toolkit.datasets import MatrixDataset
|
|
105
|
+
dataset = MatrixDataset.load('my_dataset')
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Storage Management
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
# Save collection
|
|
112
|
+
fetcher.save_collection(
|
|
113
|
+
matrices,
|
|
114
|
+
path='/data/my_matrices',
|
|
115
|
+
format='npz',
|
|
116
|
+
compression=True
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
# Load collection
|
|
120
|
+
loaded = fetcher.load_collection('/data/my_matrices')
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## CLI Usage
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# Search matrices
|
|
127
|
+
matrix-toolkit search --rows 1000:50000 --sparsity 0.9:0.99
|
|
128
|
+
|
|
129
|
+
# Fetch a matrix
|
|
130
|
+
matrix-toolkit fetch --name HB/494_bus --format csr --backend scipy
|
|
131
|
+
|
|
132
|
+
# List matrices by domain
|
|
133
|
+
matrix-toolkit list --domain physics
|
|
134
|
+
|
|
135
|
+
# Clear cache
|
|
136
|
+
matrix-toolkit cache --clear
|
|
137
|
+
|
|
138
|
+
# Create dataset
|
|
139
|
+
matrix-toolkit dataset create --config dataset.yaml
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Anymatrix Test Matrices
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
from matrix_toolkit.anymatrix import AnyMatrix, MatrixProperties
|
|
146
|
+
|
|
147
|
+
# Initialize anymatrix
|
|
148
|
+
am = AnyMatrix()
|
|
149
|
+
|
|
150
|
+
# List available matrices
|
|
151
|
+
groups = am.groups() # ['core', 'gallery']
|
|
152
|
+
matrices = am.list('core') # List matrices in core group
|
|
153
|
+
|
|
154
|
+
# Generate a matrix
|
|
155
|
+
beta_matrix = am.generate('core/beta', 10)
|
|
156
|
+
|
|
157
|
+
# Check properties
|
|
158
|
+
assert MatrixProperties.is_symmetric(beta_matrix)
|
|
159
|
+
assert MatrixProperties.is_positive_definite(beta_matrix)
|
|
160
|
+
|
|
161
|
+
# Search for matrices with specific properties
|
|
162
|
+
symmetric_matrices = am.search(['symmetric', 'positive definite'])
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Unified Interface
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
from matrix_toolkit import UnifiedMatrixCollection
|
|
169
|
+
|
|
170
|
+
mc = UnifiedMatrixCollection()
|
|
171
|
+
|
|
172
|
+
# Get from anymatrix
|
|
173
|
+
A = mc.get('anymatrix/core/beta', 10)
|
|
174
|
+
|
|
175
|
+
# Get from SuiteSparse
|
|
176
|
+
B = mc.get('suitesparse/HB/494_bus', backend='scipy')
|
|
177
|
+
|
|
178
|
+
# Search both collections
|
|
179
|
+
results = mc.search(properties=['symmetric'])
|
|
180
|
+
|
|
181
|
+
# Verify properties automatically
|
|
182
|
+
mc.verify_properties('anymatrix/core/beta', 10, verbose=True)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Available Anymatrix Collections
|
|
186
|
+
|
|
187
|
+
### Core Group
|
|
188
|
+
- `beta` - Symmetric positive definite matrix
|
|
189
|
+
- `fourier` - Discrete Fourier transform matrix (unitary)
|
|
190
|
+
- `nilpot_triang` - Nilpotent upper triangular
|
|
191
|
+
- `nilpot_tridiag` - Nilpotent tridiagonal
|
|
192
|
+
- `vand` - Vandermonde matrix
|
|
193
|
+
- `circul_binom` - Circulant with binomial coefficients
|
|
194
|
+
- `stoch_cesaro` - Stochastic Cesaro matrix
|
|
195
|
+
- `tournament` - Random tournament matrix
|
|
196
|
+
- `perfect_shuffle` - Perfect shuffle permutation
|
|
197
|
+
- `collatz` - Collatz conjecture matrix
|
|
198
|
+
- And more...
|
|
199
|
+
|
|
200
|
+
### Gallery Group
|
|
201
|
+
- `lehmer` - Lehmer matrix (symmetric positive definite)
|
|
202
|
+
- `minij` - MIN(i,j) matrix
|
|
203
|
+
- `moler` - Moler matrix
|
|
204
|
+
- `pei` - Pei matrix
|
|
205
|
+
- `clement` - Clement tridiagonal
|
|
206
|
+
- `kms` - Kac-Murdock-Szego Toeplitz matrix
|
|
207
|
+
|
|
208
|
+
## Running Tests
|
|
209
|
+
|
|
210
|
+
### Test all anymatrix matrices
|
|
211
|
+
```bash
|
|
212
|
+
python examples/run_anymatrix_tests.py --verbose --report test_report.txt
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Test specific groups
|
|
216
|
+
```bash
|
|
217
|
+
python examples/run_anymatrix_tests.py --groups core gallery
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Python API
|
|
221
|
+
```python
|
|
222
|
+
from matrix_toolkit.anymatrix.testing import run_all_tests
|
|
223
|
+
|
|
224
|
+
results = run_all_tests(verbose=True, generate_report=True)
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
## Contributing
|
|
229
|
+
|
|
230
|
+
Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
231
|
+
|
|
232
|
+
## License
|
|
233
|
+
|
|
234
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
235
|
+
|
|
236
|
+
## Citation
|
|
237
|
+
|
|
238
|
+
If you use this toolkit in your research, please cite:
|
|
239
|
+
|
|
240
|
+
```bibtex
|
|
241
|
+
@software{matrix_toolkit,
|
|
242
|
+
title={Matrix Toolkit: A Python Package for Sparse Matrix Management},
|
|
243
|
+
author={Xinye Chen},
|
|
244
|
+
year={2024},
|
|
245
|
+
url={https://github.com/chenxinye/matrix-toolkit}
|
|
246
|
+
}
|
|
247
|
+
```
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Matrix Toolkit - A comprehensive toolkit for sparse matrix management
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
__version__ = "0.0.1"
|
|
6
|
+
__author__ = "Xinye Chen"
|
|
7
|
+
__email__ = "xinyechenai@gmail.com"
|
|
8
|
+
|
|
9
|
+
from matrix_toolkit.core.fetcher import MatrixFetcher
|
|
10
|
+
from matrix_toolkit.core.search import MatrixSearcher
|
|
11
|
+
from matrix_toolkit.datasets.dataset import MatrixDataset
|
|
12
|
+
from matrix_toolkit.core.config import Config
|
|
13
|
+
|
|
14
|
+
# Anymatrix integration
|
|
15
|
+
from matrix_toolkit.anymatrix import AnyMatrix, MatrixProperties
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"MatrixFetcher",
|
|
19
|
+
"MatrixSearcher",
|
|
20
|
+
"MatrixDataset",
|
|
21
|
+
"Config",
|
|
22
|
+
"AnyMatrix",
|
|
23
|
+
"MatrixProperties",
|
|
24
|
+
]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Anymatrix integration - A collection of test matrices inspired by the
|
|
3
|
+
MATLAB anymatrix toolbox by Higham and Mikaitis.
|
|
4
|
+
|
|
5
|
+
This module provides programmatic generation of various test matrices
|
|
6
|
+
with well-defined properties for numerical computing research.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from matrix_toolkit.anymatrix.registry import AnyMatrix
|
|
10
|
+
from matrix_toolkit.anymatrix.properties import MatrixProperties
|
|
11
|
+
|
|
12
|
+
__all__ = ["AnyMatrix", "MatrixProperties"]
|
|
13
|
+
|
|
14
|
+
# Version info
|
|
15
|
+
__version__ = "0.1.0"
|
|
16
|
+
__anymatrix_reference__ = """
|
|
17
|
+
Nicholas J. Higham and Mantas Mikaitis.
|
|
18
|
+
Anymatrix: An Extendable MATLAB Matrix Collection.
|
|
19
|
+
Numer. Algorithms, 90:3, 1175-1196, Dec. 2021.
|
|
20
|
+
DOI: 10.1007/s11075-021-01226-2
|
|
21
|
+
"""
|