matrix-utils 0.4.2__tar.gz → 0.5__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_utils-0.4.2 → matrix_utils-0.5}/CHANGELOG.md +8 -0
- {matrix_utils-0.4.2 → matrix_utils-0.5}/PKG-INFO +3 -3
- {matrix_utils-0.4.2 → matrix_utils-0.5}/matrix_utils/__init__.py +1 -1
- {matrix_utils-0.4.2 → matrix_utils-0.5}/matrix_utils/indexers.py +10 -2
- {matrix_utils-0.4.2 → matrix_utils-0.5}/matrix_utils/mapped_matrix.py +8 -2
- {matrix_utils-0.4.2 → matrix_utils-0.5}/matrix_utils/mapped_matrix_dict.py +4 -2
- {matrix_utils-0.4.2 → matrix_utils-0.5}/matrix_utils/resource_group.py +3 -1
- {matrix_utils-0.4.2 → matrix_utils-0.5}/matrix_utils.egg-info/PKG-INFO +3 -3
- matrix_utils-0.5/matrix_utils.egg-info/SOURCES.txt +20 -0
- {matrix_utils-0.4.2 → matrix_utils-0.5}/matrix_utils.egg-info/requires.txt +2 -2
- {matrix_utils-0.4.2 → matrix_utils-0.5}/pyproject.toml +2 -2
- matrix_utils-0.4.2/.gitignore +0 -104
- matrix_utils-0.4.2/.pre-commit-config.yaml +0 -53
- matrix_utils-0.4.2/binder/Brightway 2.5 demonstration.ipynb +0 -615
- matrix_utils-0.4.2/binder/environment.yml +0 -33
- matrix_utils-0.4.2/dev/Brightway 2.5 - Linking with IAMs.ipynb +0 -741
- matrix_utils-0.4.2/dev/Brightway 2.5 demonstration.ipynb +0 -648
- matrix_utils-0.4.2/dev/Graph traversal with modification.ipynb +0 -893
- matrix_utils-0.4.2/dev/Indexing speed tests.ipynb +0 -235
- matrix_utils-0.4.2/dev/Interfaces which produce results for multiple matrices.ipynb +0 -506
- matrix_utils-0.4.2/dev/Mapping speed tests.ipynb +0 -312
- matrix_utils-0.4.2/dev/Multifunctionality with Brightway 2.5.ipynb +0 -555
- matrix_utils-0.4.2/dev/Real-time modification of hybrid databases.ipynb +0 -543
- matrix_utils-0.4.2/dev/Supply chain modification.ipynb +0 -562
- matrix_utils-0.4.2/dev/Untitled.ipynb +0 -32
- matrix_utils-0.4.2/dev/profiling/bw2.prof +0 -0
- matrix_utils-0.4.2/dev/profiling/bw2.svg +0 -9638
- matrix_utils-0.4.2/dev/profiling/bw25.prof +0 -0
- matrix_utils-0.4.2/dev/profiling/bw25.svg +0 -9948
- matrix_utils-0.4.2/dev/profiling/bw25_profile.txt +0 -6310
- matrix_utils-0.4.2/dev/profiling/bw25_profiling.py +0 -12
- matrix_utils-0.4.2/dev/profiling/bw2_profile.txt +0 -5014
- matrix_utils-0.4.2/dev/profiling/bw2_profiling.py +0 -10
- matrix_utils-0.4.2/dev/profiling/profiling-versus-bw2.py +0 -55
- matrix_utils-0.4.2/dev/speed_test_unique_indices.py +0 -7
- matrix_utils-0.4.2/dev/speed_tests.py +0 -113
- matrix_utils-0.4.2/docs/Makefile +0 -20
- matrix_utils-0.4.2/docs/conf.py +0 -57
- matrix_utils-0.4.2/docs/index.rst +0 -19
- matrix_utils-0.4.2/docs/loading.rst +0 -4
- matrix_utils-0.4.2/docs/make.bat +0 -35
- matrix_utils-0.4.2/docs/saving.rst +0 -11
- matrix_utils-0.4.2/docs/utilities.rst +0 -35
- matrix_utils-0.4.2/matrix_utils.egg-info/SOURCES.txt +0 -68
- matrix_utils-0.4.2/tests/array_mapper.py +0 -72
- matrix_utils-0.4.2/tests/fixtures/__init__.py +0 -1
- matrix_utils-0.4.2/tests/fixtures/a-first.zip +0 -0
- matrix_utils-0.4.2/tests/fixtures/b-second.zip +0 -0
- matrix_utils-0.4.2/tests/fixtures/basic.py +0 -65
- matrix_utils-0.4.2/tests/fixtures/create_static_fixtures.py +0 -192
- matrix_utils-0.4.2/tests/fixtures/sa-1.zip +0 -0
- matrix_utils-0.4.2/tests/fixtures/sa-2.zip +0 -0
- matrix_utils-0.4.2/tests/indexers.py +0 -115
- matrix_utils-0.4.2/tests/integration.py +0 -166
- matrix_utils-0.4.2/tests/interfaces.py +0 -16
- matrix_utils-0.4.2/tests/mapped_matrix.py +0 -837
- matrix_utils-0.4.2/tests/masking.py +0 -271
- matrix_utils-0.4.2/tests/monte_carlo.py +0 -245
- matrix_utils-0.4.2/tests/ordering.py +0 -32
- matrix_utils-0.4.2/tests/utils.py +0 -105
- {matrix_utils-0.4.2 → matrix_utils-0.5}/CODE_OF_CONDUCT.md +0 -0
- {matrix_utils-0.4.2 → matrix_utils-0.5}/LICENSE +0 -0
- {matrix_utils-0.4.2 → matrix_utils-0.5}/MANIFEST.in +0 -0
- {matrix_utils-0.4.2 → matrix_utils-0.5}/README.md +0 -0
- {matrix_utils-0.4.2 → matrix_utils-0.5}/matrix_utils/aggregation.py +0 -0
- {matrix_utils-0.4.2 → matrix_utils-0.5}/matrix_utils/array_mapper.py +0 -0
- {matrix_utils-0.4.2 → matrix_utils-0.5}/matrix_utils/errors.py +0 -0
- {matrix_utils-0.4.2 → matrix_utils-0.5}/matrix_utils/utils.py +0 -0
- {matrix_utils-0.4.2 → matrix_utils-0.5}/matrix_utils.egg-info/dependency_links.txt +0 -0
- {matrix_utils-0.4.2 → matrix_utils-0.5}/matrix_utils.egg-info/top_level.txt +0 -0
- {matrix_utils-0.4.2 → matrix_utils-0.5}/setup.cfg +0 -0
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
### [0.5] - 2024-08-20
|
|
4
|
+
|
|
5
|
+
* Default is not 64 bit integers for indexing; compatible with `bw_processing` 1.0
|
|
6
|
+
|
|
7
|
+
### [0.4.3] - 2024-06-04
|
|
8
|
+
|
|
9
|
+
* Allow `MappedMatrixDict` to take extra `kwargs` for compatiblity with custom matrix classes
|
|
10
|
+
|
|
3
11
|
### [0.4.2] - 2024-06-04
|
|
4
12
|
|
|
5
13
|
* Fix diagonal `MappedMatrixDict` - `col_mapper` is not required
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: matrix_utils
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5
|
|
4
4
|
Summary: Tools to create matrices from data packages
|
|
5
5
|
Author-email: Chris Mutel <cmutel@gmail.com>
|
|
6
6
|
Maintainer-email: Chris Mutel <cmutel@gmail.com>
|
|
@@ -26,9 +26,9 @@ Requires-Python: >=3.9
|
|
|
26
26
|
Description-Content-Type: text/markdown
|
|
27
27
|
License-File: LICENSE
|
|
28
28
|
Requires-Dist: numpy
|
|
29
|
-
Requires-Dist: scipy
|
|
29
|
+
Requires-Dist: scipy>=1.10
|
|
30
30
|
Requires-Dist: pandas
|
|
31
|
-
Requires-Dist: bw_processing
|
|
31
|
+
Requires-Dist: bw_processing>=1.0
|
|
32
32
|
Requires-Dist: stats_arrays
|
|
33
33
|
Provides-Extra: testing
|
|
34
34
|
Requires-Dist: matrix_utils; extra == "testing"
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
from itertools import product
|
|
2
2
|
from typing import List, Union
|
|
3
3
|
|
|
4
|
+
from numpy import int32, int64
|
|
4
5
|
from numpy.random import PCG64, Generator
|
|
5
6
|
|
|
6
7
|
# Max signed 32 bit integer, compatible with Windows
|
|
7
8
|
MAX_SIGNED_32BIT_INT = 2147483647
|
|
9
|
+
MAX_SIGNED_64BIT_INT = 9223372036854775807
|
|
8
10
|
|
|
9
11
|
|
|
10
12
|
class Indexer:
|
|
@@ -18,15 +20,21 @@ class RandomIndexer(Generator, Indexer):
|
|
|
18
20
|
|
|
19
21
|
Returns indices for a sample array.
|
|
20
22
|
|
|
23
|
+
Because we are creating Python indices, and Python starts indices with zero, the value
|
|
24
|
+
`max_value` is never reached - the maximum generated index is `max_value - 1`.
|
|
25
|
+
|
|
21
26
|
max_value: Number of columns in the array for which a column index is returned.
|
|
22
27
|
seed: Seed for RNG. Optional."""
|
|
23
28
|
|
|
24
|
-
def __init__(self, seed: Union[int, None] = None):
|
|
29
|
+
def __init__(self, seed: Union[int, None] = None, max_value: int = MAX_SIGNED_64BIT_INT):
|
|
25
30
|
self.seed = seed
|
|
31
|
+
self.max_value = max_value
|
|
26
32
|
self.reset()
|
|
27
33
|
|
|
28
34
|
def __next__(self):
|
|
29
|
-
self.index = self.integers(
|
|
35
|
+
self.index = self.integers(
|
|
36
|
+
0, self.max_value, dtype=int32 if self.max_value == MAX_SIGNED_32BIT_INT else int64
|
|
37
|
+
)
|
|
30
38
|
return self.index
|
|
31
39
|
|
|
32
40
|
def reset(self):
|
|
@@ -178,6 +178,9 @@ class MappedMatrix:
|
|
|
178
178
|
self.rebuild_matrix()
|
|
179
179
|
|
|
180
180
|
def rebuild_matrix(self) -> None:
|
|
181
|
+
# In theory, setting this to zero instead of multiplying it would
|
|
182
|
+
# save some nanoseconds, but it led to weird Numpy dtype errors and
|
|
183
|
+
# wasn't worth thinking about too much for very little gain.
|
|
181
184
|
self.matrix.data *= 0
|
|
182
185
|
for group in self.groups:
|
|
183
186
|
row, col, data = group.calculate()
|
|
@@ -211,7 +214,10 @@ class MappedMatrix:
|
|
|
211
214
|
for obj in resources:
|
|
212
215
|
obj.add_indexer(indexer=package.indexer)
|
|
213
216
|
else:
|
|
214
|
-
package.indexer = RandomIndexer(
|
|
217
|
+
package.indexer = RandomIndexer(
|
|
218
|
+
seed=seed_override or package.metadata["seed"],
|
|
219
|
+
max_value=package.get_max_index_value(),
|
|
220
|
+
)
|
|
215
221
|
for obj in resources:
|
|
216
222
|
obj.add_indexer(indexer=package.indexer)
|
|
217
223
|
|
|
@@ -270,7 +276,7 @@ class MappedMatrix:
|
|
|
270
276
|
|
|
271
277
|
array = np.zeros(len(given), dtype=UNCERTAINTY_DTYPE)
|
|
272
278
|
for field in FIELDS:
|
|
273
|
-
array[field] = np.
|
|
279
|
+
array[field] = np.nan
|
|
274
280
|
array["loc"] = given
|
|
275
281
|
array["uncertainty_type"] = uncertainty_type
|
|
276
282
|
return array
|
|
@@ -26,7 +26,7 @@ class SparseMatrixDict(dict):
|
|
|
26
26
|
return SparseMatrixDict(
|
|
27
27
|
{unroll(a, b): c @ d.matrix for a, c in self.items() for b, d in other.items()}
|
|
28
28
|
)
|
|
29
|
-
elif sparse.
|
|
29
|
+
elif sparse.issparse(other):
|
|
30
30
|
return SparseMatrixDict({a: b @ other for a, b in self.items()})
|
|
31
31
|
else:
|
|
32
32
|
raise TypeError(f"Can't understand matrix multiplication for type {type(other)}")
|
|
@@ -51,6 +51,7 @@ class MappedMatrixDict(Mapping):
|
|
|
51
51
|
empty_ok: bool = False,
|
|
52
52
|
sequential: bool = False,
|
|
53
53
|
matrix_class: Type[MappedMatrix] = MappedMatrix,
|
|
54
|
+
**kwargs,
|
|
54
55
|
):
|
|
55
56
|
"""A thin wrapper around a dict of `MappedMatrix` objects. See its docstring
|
|
56
57
|
for details on `custom_filter` and `indexer_override`.
|
|
@@ -143,6 +144,7 @@ class MappedMatrixDict(Mapping):
|
|
|
143
144
|
transpose=transpose,
|
|
144
145
|
custom_filter=custom_filter,
|
|
145
146
|
empty_ok=empty_ok,
|
|
147
|
+
**kwargs,
|
|
146
148
|
)
|
|
147
149
|
for key, packages in packages.items()
|
|
148
150
|
}
|
|
@@ -178,7 +180,7 @@ class MappedMatrixDict(Mapping):
|
|
|
178
180
|
|
|
179
181
|
Note that the mapped matrix dict must come first, i.e. `MappedMatrixDict @ other`.
|
|
180
182
|
"""
|
|
181
|
-
if sparse.
|
|
183
|
+
if sparse.issparse(other):
|
|
182
184
|
return SparseMatrixDict(
|
|
183
185
|
[(key, value.matrix @ other) for key, value in self.matrices.items()]
|
|
184
186
|
)
|
|
@@ -120,7 +120,9 @@ class ResourceGroup:
|
|
|
120
120
|
"""The source data for the indices array."""
|
|
121
121
|
indices = self.get_resource_by_suffix("indices")
|
|
122
122
|
if self.transpose:
|
|
123
|
-
indices = indices.astype(
|
|
123
|
+
indices = indices.astype(
|
|
124
|
+
[("col", indices.dtype[0]), ("row", indices.dtype[0])], copy=False
|
|
125
|
+
)
|
|
124
126
|
return indices
|
|
125
127
|
|
|
126
128
|
def get_resource_by_suffix(self, suffix: str) -> Any:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: matrix_utils
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5
|
|
4
4
|
Summary: Tools to create matrices from data packages
|
|
5
5
|
Author-email: Chris Mutel <cmutel@gmail.com>
|
|
6
6
|
Maintainer-email: Chris Mutel <cmutel@gmail.com>
|
|
@@ -26,9 +26,9 @@ Requires-Python: >=3.9
|
|
|
26
26
|
Description-Content-Type: text/markdown
|
|
27
27
|
License-File: LICENSE
|
|
28
28
|
Requires-Dist: numpy
|
|
29
|
-
Requires-Dist: scipy
|
|
29
|
+
Requires-Dist: scipy>=1.10
|
|
30
30
|
Requires-Dist: pandas
|
|
31
|
-
Requires-Dist: bw_processing
|
|
31
|
+
Requires-Dist: bw_processing>=1.0
|
|
32
32
|
Requires-Dist: stats_arrays
|
|
33
33
|
Provides-Extra: testing
|
|
34
34
|
Requires-Dist: matrix_utils; extra == "testing"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
CHANGELOG.md
|
|
2
|
+
CODE_OF_CONDUCT.md
|
|
3
|
+
LICENSE
|
|
4
|
+
MANIFEST.in
|
|
5
|
+
README.md
|
|
6
|
+
pyproject.toml
|
|
7
|
+
matrix_utils/__init__.py
|
|
8
|
+
matrix_utils/aggregation.py
|
|
9
|
+
matrix_utils/array_mapper.py
|
|
10
|
+
matrix_utils/errors.py
|
|
11
|
+
matrix_utils/indexers.py
|
|
12
|
+
matrix_utils/mapped_matrix.py
|
|
13
|
+
matrix_utils/mapped_matrix_dict.py
|
|
14
|
+
matrix_utils/resource_group.py
|
|
15
|
+
matrix_utils/utils.py
|
|
16
|
+
matrix_utils.egg-info/PKG-INFO
|
|
17
|
+
matrix_utils.egg-info/SOURCES.txt
|
|
18
|
+
matrix_utils.egg-info/dependency_links.txt
|
|
19
|
+
matrix_utils.egg-info/requires.txt
|
|
20
|
+
matrix_utils.egg-info/top_level.txt
|
matrix_utils-0.4.2/.gitignore
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
# Byte-compiled / optimized / DLL files
|
|
2
|
-
__pycache__/
|
|
3
|
-
*.py[cod]
|
|
4
|
-
*$py.class
|
|
5
|
-
|
|
6
|
-
# C extensions
|
|
7
|
-
*.so
|
|
8
|
-
|
|
9
|
-
# Distribution / packaging
|
|
10
|
-
.Python
|
|
11
|
-
build/
|
|
12
|
-
develop-eggs/
|
|
13
|
-
dist/
|
|
14
|
-
downloads/
|
|
15
|
-
eggs/
|
|
16
|
-
.eggs/
|
|
17
|
-
lib/
|
|
18
|
-
lib64/
|
|
19
|
-
parts/
|
|
20
|
-
sdist/
|
|
21
|
-
var/
|
|
22
|
-
wheels/
|
|
23
|
-
*.egg-info/
|
|
24
|
-
.installed.cfg
|
|
25
|
-
*.egg
|
|
26
|
-
MANIFEST
|
|
27
|
-
|
|
28
|
-
# PyInstaller
|
|
29
|
-
# Usually these files are written by a python script from a template
|
|
30
|
-
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
31
|
-
*.manifest
|
|
32
|
-
*.spec
|
|
33
|
-
|
|
34
|
-
# Installer logs
|
|
35
|
-
pip-log.txt
|
|
36
|
-
pip-delete-this-directory.txt
|
|
37
|
-
|
|
38
|
-
# Unit test / coverage reports
|
|
39
|
-
htmlcov/
|
|
40
|
-
.tox/
|
|
41
|
-
.coverage
|
|
42
|
-
.coverage.*
|
|
43
|
-
.cache
|
|
44
|
-
nosetests.xml
|
|
45
|
-
coverage.xml
|
|
46
|
-
*.cover
|
|
47
|
-
.hypothesis/
|
|
48
|
-
.pytest_cache/
|
|
49
|
-
|
|
50
|
-
# Translations
|
|
51
|
-
*.mo
|
|
52
|
-
*.pot
|
|
53
|
-
|
|
54
|
-
# Django stuff:
|
|
55
|
-
*.log
|
|
56
|
-
local_settings.py
|
|
57
|
-
db.sqlite3
|
|
58
|
-
|
|
59
|
-
# Flask stuff:
|
|
60
|
-
instance/
|
|
61
|
-
.webassets-cache
|
|
62
|
-
|
|
63
|
-
# Scrapy stuff:
|
|
64
|
-
.scrapy
|
|
65
|
-
|
|
66
|
-
# Sphinx documentation
|
|
67
|
-
docs/_build/
|
|
68
|
-
|
|
69
|
-
# PyBuilder
|
|
70
|
-
target/
|
|
71
|
-
|
|
72
|
-
# Jupyter Notebook
|
|
73
|
-
.ipynb_checkpoints
|
|
74
|
-
|
|
75
|
-
# pyenv
|
|
76
|
-
.python-version
|
|
77
|
-
|
|
78
|
-
# celery beat schedule file
|
|
79
|
-
celerybeat-schedule
|
|
80
|
-
|
|
81
|
-
# SageMath parsed files
|
|
82
|
-
*.sage.py
|
|
83
|
-
|
|
84
|
-
# Environments
|
|
85
|
-
.env
|
|
86
|
-
.venv
|
|
87
|
-
env/
|
|
88
|
-
venv/
|
|
89
|
-
ENV/
|
|
90
|
-
env.bak/
|
|
91
|
-
venv.bak/
|
|
92
|
-
|
|
93
|
-
# Spyder project settings
|
|
94
|
-
.spyderproject
|
|
95
|
-
.spyproject
|
|
96
|
-
|
|
97
|
-
# Rope project settings
|
|
98
|
-
.ropeproject
|
|
99
|
-
|
|
100
|
-
# mkdocs documentation
|
|
101
|
-
/site
|
|
102
|
-
|
|
103
|
-
# mypy
|
|
104
|
-
.mypy_cache/
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
exclude: '^docs/conf.py'
|
|
2
|
-
|
|
3
|
-
repos:
|
|
4
|
-
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
5
|
-
rev: v4.4.0
|
|
6
|
-
hooks:
|
|
7
|
-
- id: trailing-whitespace
|
|
8
|
-
- id: check-added-large-files
|
|
9
|
-
- id: check-ast
|
|
10
|
-
- id: check-json
|
|
11
|
-
- id: check-merge-conflict
|
|
12
|
-
- id: check-xml
|
|
13
|
-
- id: check-yaml
|
|
14
|
-
- id: debug-statements
|
|
15
|
-
- id: end-of-file-fixer
|
|
16
|
-
- id: requirements-txt-fixer
|
|
17
|
-
- id: mixed-line-ending
|
|
18
|
-
args: ['--fix=auto'] # replace 'auto' with 'lf' to enforce Linux/Mac line endings or 'crlf' for Windows
|
|
19
|
-
|
|
20
|
-
## If you want to avoid flake8 errors due to unused vars or imports:
|
|
21
|
-
# - repo: https://github.com/myint/autoflake
|
|
22
|
-
# rev: v1.4
|
|
23
|
-
# hooks:
|
|
24
|
-
# - id: autoflake
|
|
25
|
-
# args: [
|
|
26
|
-
# --in-place,
|
|
27
|
-
# --remove-all-unused-imports,
|
|
28
|
-
# --remove-unused-variables,
|
|
29
|
-
# ]
|
|
30
|
-
|
|
31
|
-
- repo: https://github.com/pycqa/isort
|
|
32
|
-
rev: 5.11.5
|
|
33
|
-
hooks:
|
|
34
|
-
- id: isort
|
|
35
|
-
args: [--settings-path=pyproject.toml]
|
|
36
|
-
|
|
37
|
-
- repo: https://github.com/psf/black
|
|
38
|
-
rev: 23.10.0
|
|
39
|
-
hooks:
|
|
40
|
-
- id: black
|
|
41
|
-
args: [--config=pyproject.toml]
|
|
42
|
-
|
|
43
|
-
# - repo: https://github.com/adamchainz/blacken-docs
|
|
44
|
-
# rev: 1.16.0
|
|
45
|
-
# hooks:
|
|
46
|
-
# - id: blacken-docs
|
|
47
|
-
# additional_dependencies: [black]
|
|
48
|
-
|
|
49
|
-
- repo: https://github.com/PyCQA/flake8
|
|
50
|
-
rev: 6.0.0
|
|
51
|
-
hooks:
|
|
52
|
-
- id: flake8
|
|
53
|
-
additional_dependencies: [Flake8-pyproject]
|