matrix-dict 1.0.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.
- matrix_dict-1.0.0/PKG-INFO +145 -0
- matrix_dict-1.0.0/README.md +117 -0
- matrix_dict-1.0.0/matrix_dict.egg-info/PKG-INFO +145 -0
- matrix_dict-1.0.0/matrix_dict.egg-info/SOURCES.txt +8 -0
- matrix_dict-1.0.0/matrix_dict.egg-info/dependency_links.txt +1 -0
- matrix_dict-1.0.0/matrix_dict.egg-info/requires.txt +5 -0
- matrix_dict-1.0.0/matrix_dict.egg-info/top_level.txt +1 -0
- matrix_dict-1.0.0/pyproject.toml +57 -0
- matrix_dict-1.0.0/setup.cfg +4 -0
- matrix_dict-1.0.0/tests/test_matrix_dict.py +171 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: matrix-dict
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A 100x100 dictionary-based matrix with 10,000 accessible indexes
|
|
5
|
+
Author-email: amphibiar <amphibiar@example.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/amphibiar/matrix-dict
|
|
8
|
+
Project-URL: Repository, https://github.com/amphibiar/matrix-dict
|
|
9
|
+
Project-URL: Issues, https://github.com/amphibiar/matrix-dict/issues
|
|
10
|
+
Keywords: matrix,dictionary,data-structure,100x100,grid
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
22
|
+
Requires-Python: >=3.8
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
26
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
27
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
28
|
+
|
|
29
|
+
# matrix-dict
|
|
30
|
+
|
|
31
|
+
A 100x100 dictionary-based matrix with 10,000 accessible indexes for Python.
|
|
32
|
+
|
|
33
|
+
## Features
|
|
34
|
+
|
|
35
|
+
- **Fixed 100x100 size** - Exactly 10,000 cells
|
|
36
|
+
- **Dictionary-like access** - Use `(row, col)` tuple keys
|
|
37
|
+
- **Default values** - Initialize all cells with a default
|
|
38
|
+
- **Bulk operations** - Set/get entire rows, columns, or submatrices
|
|
39
|
+
- **Iteration** - Iterate over all 10,000 positions efficiently
|
|
40
|
+
- **Slicing** - Extract rectangular submatrices
|
|
41
|
+
- **List conversion** - Convert to/from nested lists
|
|
42
|
+
- **Type hints** - Full typing support
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install matrix-dict
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Or from source:
|
|
51
|
+
```bash
|
|
52
|
+
git clone https://github.com/amphibiar/matrix-dict
|
|
53
|
+
cd matrix-dict
|
|
54
|
+
pip install -e .
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Quick Start
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from matrix_dict import create_matrix
|
|
61
|
+
|
|
62
|
+
# Create a 100x100 matrix with default value 0
|
|
63
|
+
matrix = create_matrix(default_value=0)
|
|
64
|
+
|
|
65
|
+
# Set individual cells
|
|
66
|
+
matrix[(0, 0)] = 100
|
|
67
|
+
matrix[(50, 50)] = 2500
|
|
68
|
+
|
|
69
|
+
# Access cells
|
|
70
|
+
value = matrix[(0, 0)] # 100
|
|
71
|
+
|
|
72
|
+
# Fill with a loop
|
|
73
|
+
for row in range(100):
|
|
74
|
+
for col in range(100):
|
|
75
|
+
matrix[(row, col)] = row * 100 + col
|
|
76
|
+
|
|
77
|
+
# Or iterate directly
|
|
78
|
+
for (row, col), _ in matrix:
|
|
79
|
+
matrix[(row, col)] = row * 100 + col
|
|
80
|
+
|
|
81
|
+
# Get entire row/column
|
|
82
|
+
row_5 = matrix.get_row(5) # [500, 501, ..., 599]
|
|
83
|
+
col_3 = matrix.get_col(3) # [3, 103, 203, ..., 9903]
|
|
84
|
+
|
|
85
|
+
# Set entire row/column
|
|
86
|
+
matrix.set_row(0, [i * 2 for i in range(100)])
|
|
87
|
+
matrix.set_col(5, [i * 3 for i in range(100)])
|
|
88
|
+
|
|
89
|
+
# Submatrix operations
|
|
90
|
+
sub = matrix.get_submatrix(0, 10, 0, 10) # 10x10 top-left
|
|
91
|
+
matrix.set_submatrix(20, 20, [[1, 2], [3, 4]])
|
|
92
|
+
|
|
93
|
+
# Check if explicitly set
|
|
94
|
+
if (50, 50) in matrix:
|
|
95
|
+
print("Cell was set")
|
|
96
|
+
|
|
97
|
+
# Convert to/from list
|
|
98
|
+
data = matrix.to_list() # 100x100 list of lists
|
|
99
|
+
new_matrix = MatrixDict.from_list(data)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## API Reference
|
|
103
|
+
|
|
104
|
+
### `create_matrix(default_value=None) -> MatrixDict`
|
|
105
|
+
Factory function to create a new matrix.
|
|
106
|
+
|
|
107
|
+
### `MatrixDict(default_value=None)`
|
|
108
|
+
Main class. Initialize with optional default value for all 10,000 cells.
|
|
109
|
+
|
|
110
|
+
#### Item Access
|
|
111
|
+
- `matrix[(row, col)] = value` - Set cell
|
|
112
|
+
- `value = matrix[(row, col)]` - Get cell (returns default if not set)
|
|
113
|
+
- `(row, col) in matrix` - Check if explicitly set
|
|
114
|
+
|
|
115
|
+
#### Bulk Operations
|
|
116
|
+
- `matrix.fill(value)` - Fill all 10,000 cells
|
|
117
|
+
- `matrix.clear()` - Clear all explicitly set values
|
|
118
|
+
- `matrix.set_row(row, values)` - Set row from list of 100
|
|
119
|
+
- `matrix.set_col(col, values)` - Set column from list of 100
|
|
120
|
+
- `matrix.get_row(row) -> List` - Get row as list
|
|
121
|
+
- `matrix.get_col(col) -> List` - Get column as list
|
|
122
|
+
|
|
123
|
+
#### Submatrix
|
|
124
|
+
- `matrix.get_submatrix(r_start, r_end, c_start, c_end) -> List[List]`
|
|
125
|
+
- `matrix.set_submatrix(row_start, col_start, values)`
|
|
126
|
+
|
|
127
|
+
#### Iteration
|
|
128
|
+
- `for (row, col), value in matrix:` - All 10,000 positions
|
|
129
|
+
- `matrix.iterate_row(row)` - Iterate (col, value) in row
|
|
130
|
+
- `matrix.iterate_col(col)` - Iterate (row, value) in column
|
|
131
|
+
- `matrix.items()` - Explicitly set (key, value) pairs
|
|
132
|
+
- `matrix.keys()` - Explicitly set keys
|
|
133
|
+
- `matrix.values()` - Explicitly set values
|
|
134
|
+
|
|
135
|
+
#### Conversion
|
|
136
|
+
- `matrix.to_list()` - Convert to 100x100 list of lists
|
|
137
|
+
- `MatrixDict.from_list(data, default_value)` - Create from list
|
|
138
|
+
|
|
139
|
+
## Requirements
|
|
140
|
+
|
|
141
|
+
- Python 3.8+
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
MIT
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# matrix-dict
|
|
2
|
+
|
|
3
|
+
A 100x100 dictionary-based matrix with 10,000 accessible indexes for Python.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Fixed 100x100 size** - Exactly 10,000 cells
|
|
8
|
+
- **Dictionary-like access** - Use `(row, col)` tuple keys
|
|
9
|
+
- **Default values** - Initialize all cells with a default
|
|
10
|
+
- **Bulk operations** - Set/get entire rows, columns, or submatrices
|
|
11
|
+
- **Iteration** - Iterate over all 10,000 positions efficiently
|
|
12
|
+
- **Slicing** - Extract rectangular submatrices
|
|
13
|
+
- **List conversion** - Convert to/from nested lists
|
|
14
|
+
- **Type hints** - Full typing support
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install matrix-dict
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or from source:
|
|
23
|
+
```bash
|
|
24
|
+
git clone https://github.com/amphibiar/matrix-dict
|
|
25
|
+
cd matrix-dict
|
|
26
|
+
pip install -e .
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from matrix_dict import create_matrix
|
|
33
|
+
|
|
34
|
+
# Create a 100x100 matrix with default value 0
|
|
35
|
+
matrix = create_matrix(default_value=0)
|
|
36
|
+
|
|
37
|
+
# Set individual cells
|
|
38
|
+
matrix[(0, 0)] = 100
|
|
39
|
+
matrix[(50, 50)] = 2500
|
|
40
|
+
|
|
41
|
+
# Access cells
|
|
42
|
+
value = matrix[(0, 0)] # 100
|
|
43
|
+
|
|
44
|
+
# Fill with a loop
|
|
45
|
+
for row in range(100):
|
|
46
|
+
for col in range(100):
|
|
47
|
+
matrix[(row, col)] = row * 100 + col
|
|
48
|
+
|
|
49
|
+
# Or iterate directly
|
|
50
|
+
for (row, col), _ in matrix:
|
|
51
|
+
matrix[(row, col)] = row * 100 + col
|
|
52
|
+
|
|
53
|
+
# Get entire row/column
|
|
54
|
+
row_5 = matrix.get_row(5) # [500, 501, ..., 599]
|
|
55
|
+
col_3 = matrix.get_col(3) # [3, 103, 203, ..., 9903]
|
|
56
|
+
|
|
57
|
+
# Set entire row/column
|
|
58
|
+
matrix.set_row(0, [i * 2 for i in range(100)])
|
|
59
|
+
matrix.set_col(5, [i * 3 for i in range(100)])
|
|
60
|
+
|
|
61
|
+
# Submatrix operations
|
|
62
|
+
sub = matrix.get_submatrix(0, 10, 0, 10) # 10x10 top-left
|
|
63
|
+
matrix.set_submatrix(20, 20, [[1, 2], [3, 4]])
|
|
64
|
+
|
|
65
|
+
# Check if explicitly set
|
|
66
|
+
if (50, 50) in matrix:
|
|
67
|
+
print("Cell was set")
|
|
68
|
+
|
|
69
|
+
# Convert to/from list
|
|
70
|
+
data = matrix.to_list() # 100x100 list of lists
|
|
71
|
+
new_matrix = MatrixDict.from_list(data)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## API Reference
|
|
75
|
+
|
|
76
|
+
### `create_matrix(default_value=None) -> MatrixDict`
|
|
77
|
+
Factory function to create a new matrix.
|
|
78
|
+
|
|
79
|
+
### `MatrixDict(default_value=None)`
|
|
80
|
+
Main class. Initialize with optional default value for all 10,000 cells.
|
|
81
|
+
|
|
82
|
+
#### Item Access
|
|
83
|
+
- `matrix[(row, col)] = value` - Set cell
|
|
84
|
+
- `value = matrix[(row, col)]` - Get cell (returns default if not set)
|
|
85
|
+
- `(row, col) in matrix` - Check if explicitly set
|
|
86
|
+
|
|
87
|
+
#### Bulk Operations
|
|
88
|
+
- `matrix.fill(value)` - Fill all 10,000 cells
|
|
89
|
+
- `matrix.clear()` - Clear all explicitly set values
|
|
90
|
+
- `matrix.set_row(row, values)` - Set row from list of 100
|
|
91
|
+
- `matrix.set_col(col, values)` - Set column from list of 100
|
|
92
|
+
- `matrix.get_row(row) -> List` - Get row as list
|
|
93
|
+
- `matrix.get_col(col) -> List` - Get column as list
|
|
94
|
+
|
|
95
|
+
#### Submatrix
|
|
96
|
+
- `matrix.get_submatrix(r_start, r_end, c_start, c_end) -> List[List]`
|
|
97
|
+
- `matrix.set_submatrix(row_start, col_start, values)`
|
|
98
|
+
|
|
99
|
+
#### Iteration
|
|
100
|
+
- `for (row, col), value in matrix:` - All 10,000 positions
|
|
101
|
+
- `matrix.iterate_row(row)` - Iterate (col, value) in row
|
|
102
|
+
- `matrix.iterate_col(col)` - Iterate (row, value) in column
|
|
103
|
+
- `matrix.items()` - Explicitly set (key, value) pairs
|
|
104
|
+
- `matrix.keys()` - Explicitly set keys
|
|
105
|
+
- `matrix.values()` - Explicitly set values
|
|
106
|
+
|
|
107
|
+
#### Conversion
|
|
108
|
+
- `matrix.to_list()` - Convert to 100x100 list of lists
|
|
109
|
+
- `MatrixDict.from_list(data, default_value)` - Create from list
|
|
110
|
+
|
|
111
|
+
## Requirements
|
|
112
|
+
|
|
113
|
+
- Python 3.8+
|
|
114
|
+
|
|
115
|
+
## License
|
|
116
|
+
|
|
117
|
+
MIT
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: matrix-dict
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A 100x100 dictionary-based matrix with 10,000 accessible indexes
|
|
5
|
+
Author-email: amphibiar <amphibiar@example.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/amphibiar/matrix-dict
|
|
8
|
+
Project-URL: Repository, https://github.com/amphibiar/matrix-dict
|
|
9
|
+
Project-URL: Issues, https://github.com/amphibiar/matrix-dict/issues
|
|
10
|
+
Keywords: matrix,dictionary,data-structure,100x100,grid
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
22
|
+
Requires-Python: >=3.8
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
26
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
27
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
28
|
+
|
|
29
|
+
# matrix-dict
|
|
30
|
+
|
|
31
|
+
A 100x100 dictionary-based matrix with 10,000 accessible indexes for Python.
|
|
32
|
+
|
|
33
|
+
## Features
|
|
34
|
+
|
|
35
|
+
- **Fixed 100x100 size** - Exactly 10,000 cells
|
|
36
|
+
- **Dictionary-like access** - Use `(row, col)` tuple keys
|
|
37
|
+
- **Default values** - Initialize all cells with a default
|
|
38
|
+
- **Bulk operations** - Set/get entire rows, columns, or submatrices
|
|
39
|
+
- **Iteration** - Iterate over all 10,000 positions efficiently
|
|
40
|
+
- **Slicing** - Extract rectangular submatrices
|
|
41
|
+
- **List conversion** - Convert to/from nested lists
|
|
42
|
+
- **Type hints** - Full typing support
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install matrix-dict
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Or from source:
|
|
51
|
+
```bash
|
|
52
|
+
git clone https://github.com/amphibiar/matrix-dict
|
|
53
|
+
cd matrix-dict
|
|
54
|
+
pip install -e .
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Quick Start
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from matrix_dict import create_matrix
|
|
61
|
+
|
|
62
|
+
# Create a 100x100 matrix with default value 0
|
|
63
|
+
matrix = create_matrix(default_value=0)
|
|
64
|
+
|
|
65
|
+
# Set individual cells
|
|
66
|
+
matrix[(0, 0)] = 100
|
|
67
|
+
matrix[(50, 50)] = 2500
|
|
68
|
+
|
|
69
|
+
# Access cells
|
|
70
|
+
value = matrix[(0, 0)] # 100
|
|
71
|
+
|
|
72
|
+
# Fill with a loop
|
|
73
|
+
for row in range(100):
|
|
74
|
+
for col in range(100):
|
|
75
|
+
matrix[(row, col)] = row * 100 + col
|
|
76
|
+
|
|
77
|
+
# Or iterate directly
|
|
78
|
+
for (row, col), _ in matrix:
|
|
79
|
+
matrix[(row, col)] = row * 100 + col
|
|
80
|
+
|
|
81
|
+
# Get entire row/column
|
|
82
|
+
row_5 = matrix.get_row(5) # [500, 501, ..., 599]
|
|
83
|
+
col_3 = matrix.get_col(3) # [3, 103, 203, ..., 9903]
|
|
84
|
+
|
|
85
|
+
# Set entire row/column
|
|
86
|
+
matrix.set_row(0, [i * 2 for i in range(100)])
|
|
87
|
+
matrix.set_col(5, [i * 3 for i in range(100)])
|
|
88
|
+
|
|
89
|
+
# Submatrix operations
|
|
90
|
+
sub = matrix.get_submatrix(0, 10, 0, 10) # 10x10 top-left
|
|
91
|
+
matrix.set_submatrix(20, 20, [[1, 2], [3, 4]])
|
|
92
|
+
|
|
93
|
+
# Check if explicitly set
|
|
94
|
+
if (50, 50) in matrix:
|
|
95
|
+
print("Cell was set")
|
|
96
|
+
|
|
97
|
+
# Convert to/from list
|
|
98
|
+
data = matrix.to_list() # 100x100 list of lists
|
|
99
|
+
new_matrix = MatrixDict.from_list(data)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## API Reference
|
|
103
|
+
|
|
104
|
+
### `create_matrix(default_value=None) -> MatrixDict`
|
|
105
|
+
Factory function to create a new matrix.
|
|
106
|
+
|
|
107
|
+
### `MatrixDict(default_value=None)`
|
|
108
|
+
Main class. Initialize with optional default value for all 10,000 cells.
|
|
109
|
+
|
|
110
|
+
#### Item Access
|
|
111
|
+
- `matrix[(row, col)] = value` - Set cell
|
|
112
|
+
- `value = matrix[(row, col)]` - Get cell (returns default if not set)
|
|
113
|
+
- `(row, col) in matrix` - Check if explicitly set
|
|
114
|
+
|
|
115
|
+
#### Bulk Operations
|
|
116
|
+
- `matrix.fill(value)` - Fill all 10,000 cells
|
|
117
|
+
- `matrix.clear()` - Clear all explicitly set values
|
|
118
|
+
- `matrix.set_row(row, values)` - Set row from list of 100
|
|
119
|
+
- `matrix.set_col(col, values)` - Set column from list of 100
|
|
120
|
+
- `matrix.get_row(row) -> List` - Get row as list
|
|
121
|
+
- `matrix.get_col(col) -> List` - Get column as list
|
|
122
|
+
|
|
123
|
+
#### Submatrix
|
|
124
|
+
- `matrix.get_submatrix(r_start, r_end, c_start, c_end) -> List[List]`
|
|
125
|
+
- `matrix.set_submatrix(row_start, col_start, values)`
|
|
126
|
+
|
|
127
|
+
#### Iteration
|
|
128
|
+
- `for (row, col), value in matrix:` - All 10,000 positions
|
|
129
|
+
- `matrix.iterate_row(row)` - Iterate (col, value) in row
|
|
130
|
+
- `matrix.iterate_col(col)` - Iterate (row, value) in column
|
|
131
|
+
- `matrix.items()` - Explicitly set (key, value) pairs
|
|
132
|
+
- `matrix.keys()` - Explicitly set keys
|
|
133
|
+
- `matrix.values()` - Explicitly set values
|
|
134
|
+
|
|
135
|
+
#### Conversion
|
|
136
|
+
- `matrix.to_list()` - Convert to 100x100 list of lists
|
|
137
|
+
- `MatrixDict.from_list(data, default_value)` - Create from list
|
|
138
|
+
|
|
139
|
+
## Requirements
|
|
140
|
+
|
|
141
|
+
- Python 3.8+
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "matrix-dict"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "A 100x100 dictionary-based matrix with 10,000 accessible indexes"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
requires-python = ">=3.8"
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "amphibiar", email = "amphibiar@example.com"}
|
|
14
|
+
]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.8",
|
|
21
|
+
"Programming Language :: Python :: 3.9",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Topic :: Software Development :: Libraries",
|
|
26
|
+
"Topic :: Scientific/Engineering :: Mathematics",
|
|
27
|
+
]
|
|
28
|
+
keywords = ["matrix", "dictionary", "data-structure", "100x100", "grid"]
|
|
29
|
+
|
|
30
|
+
[project.optional-dependencies]
|
|
31
|
+
dev = [
|
|
32
|
+
"pytest>=7.0",
|
|
33
|
+
"pytest-cov>=4.0",
|
|
34
|
+
"ruff>=0.1.0",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
Homepage = "https://github.com/amphibiar/matrix-dict"
|
|
39
|
+
Repository = "https://github.com/amphibiar/matrix-dict"
|
|
40
|
+
Issues = "https://github.com/amphibiar/matrix-dict/issues"
|
|
41
|
+
|
|
42
|
+
[tool.setuptools.packages.find]
|
|
43
|
+
where = ["."]
|
|
44
|
+
include = ["matrix_dict*"]
|
|
45
|
+
|
|
46
|
+
[tool.ruff]
|
|
47
|
+
line-length = 100
|
|
48
|
+
target-version = "py38"
|
|
49
|
+
|
|
50
|
+
[tool.ruff.lint]
|
|
51
|
+
select = ["E", "F", "I", "UP", "B", "C4", "SIM", "T20"]
|
|
52
|
+
ignore = []
|
|
53
|
+
|
|
54
|
+
[tool.pytest.ini_options]
|
|
55
|
+
testpaths = ["tests"]
|
|
56
|
+
python_files = ["test_*.py"]
|
|
57
|
+
python_functions = ["test_*"]
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"""Tests for matrix_dict module."""
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from matrix_dict import MatrixDict, create_matrix
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TestMatrixDict:
|
|
8
|
+
def test_create_empty(self):
|
|
9
|
+
m = create_matrix()
|
|
10
|
+
assert m._default is None
|
|
11
|
+
assert len(m) == 0
|
|
12
|
+
|
|
13
|
+
def test_create_with_default(self):
|
|
14
|
+
m = create_matrix(default_value=5)
|
|
15
|
+
assert m._default == 5
|
|
16
|
+
assert len(m) == 10000
|
|
17
|
+
assert m[(0, 0)] == 5
|
|
18
|
+
assert m[(99, 99)] == 5
|
|
19
|
+
|
|
20
|
+
def test_set_and_get(self):
|
|
21
|
+
m = create_matrix()
|
|
22
|
+
m[(10, 20)] = 42
|
|
23
|
+
assert m[(10, 20)] == 42
|
|
24
|
+
assert len(m) == 1
|
|
25
|
+
|
|
26
|
+
def test_get_default(self):
|
|
27
|
+
m = create_matrix(default_value=-1)
|
|
28
|
+
assert m[(50, 50)] == -1
|
|
29
|
+
|
|
30
|
+
def test_get_custom_default(self):
|
|
31
|
+
m = create_matrix() # No default, so cells are not set
|
|
32
|
+
assert m.get((10, 10), 999) == 999
|
|
33
|
+
|
|
34
|
+
def test_bounds_checking(self):
|
|
35
|
+
m = create_matrix()
|
|
36
|
+
with pytest.raises(IndexError):
|
|
37
|
+
m[(100, 0)]
|
|
38
|
+
with pytest.raises(IndexError):
|
|
39
|
+
m[(0, 100)]
|
|
40
|
+
with pytest.raises(IndexError):
|
|
41
|
+
m[(-1, 0)]
|
|
42
|
+
with pytest.raises(IndexError):
|
|
43
|
+
m[(0, -1)]
|
|
44
|
+
|
|
45
|
+
def test_type_checking(self):
|
|
46
|
+
m = create_matrix()
|
|
47
|
+
with pytest.raises(TypeError):
|
|
48
|
+
m["not a tuple"]
|
|
49
|
+
with pytest.raises(TypeError):
|
|
50
|
+
m[(1, 2, 3)]
|
|
51
|
+
with pytest.raises(TypeError):
|
|
52
|
+
m[(1.5, 2)]
|
|
53
|
+
|
|
54
|
+
def test_fill(self):
|
|
55
|
+
m = create_matrix()
|
|
56
|
+
m.fill(7)
|
|
57
|
+
assert len(m) == 10000
|
|
58
|
+
assert m[(0, 0)] == 7
|
|
59
|
+
assert m[(99, 99)] == 7
|
|
60
|
+
|
|
61
|
+
def test_clear(self):
|
|
62
|
+
m = create_matrix(default_value=1)
|
|
63
|
+
m.clear()
|
|
64
|
+
assert len(m) == 0
|
|
65
|
+
assert m[(0, 0)] == 1
|
|
66
|
+
|
|
67
|
+
def test_contains(self):
|
|
68
|
+
m = create_matrix() # No default, cells not set
|
|
69
|
+
assert (0, 0) not in m
|
|
70
|
+
m[(0, 0)] = 5
|
|
71
|
+
assert (0, 0) in m
|
|
72
|
+
|
|
73
|
+
def test_iteration(self):
|
|
74
|
+
m = create_matrix(default_value=0)
|
|
75
|
+
count = 0
|
|
76
|
+
for (r, c), v in m:
|
|
77
|
+
assert v == 0
|
|
78
|
+
count += 1
|
|
79
|
+
assert count == 10000
|
|
80
|
+
|
|
81
|
+
def test_set_row(self):
|
|
82
|
+
m = create_matrix()
|
|
83
|
+
values = list(range(100))
|
|
84
|
+
m.set_row(5, values)
|
|
85
|
+
assert m.get_row(5) == values
|
|
86
|
+
|
|
87
|
+
def test_set_row_wrong_length(self):
|
|
88
|
+
m = create_matrix()
|
|
89
|
+
with pytest.raises(ValueError):
|
|
90
|
+
m.set_row(0, [1, 2, 3])
|
|
91
|
+
|
|
92
|
+
def test_set_col(self):
|
|
93
|
+
m = create_matrix()
|
|
94
|
+
values = [i * 10 for i in range(100)]
|
|
95
|
+
m.set_col(3, values)
|
|
96
|
+
assert m.get_col(3) == values
|
|
97
|
+
|
|
98
|
+
def test_get_row(self):
|
|
99
|
+
m = create_matrix(default_value=1)
|
|
100
|
+
row = m.get_row(0)
|
|
101
|
+
assert len(row) == 100
|
|
102
|
+
assert all(v == 1 for v in row)
|
|
103
|
+
|
|
104
|
+
def test_get_col(self):
|
|
105
|
+
m = create_matrix(default_value=2)
|
|
106
|
+
col = m.get_col(5)
|
|
107
|
+
assert len(col) == 100
|
|
108
|
+
assert all(v == 2 for v in col)
|
|
109
|
+
|
|
110
|
+
def test_submatrix_get(self):
|
|
111
|
+
m = create_matrix(default_value=0)
|
|
112
|
+
for r in range(5):
|
|
113
|
+
for c in range(5):
|
|
114
|
+
m[(r, c)] = r * 5 + c
|
|
115
|
+
sub = m.get_submatrix(0, 3, 0, 3)
|
|
116
|
+
assert sub == [[0, 1, 2], [5, 6, 7], [10, 11, 12]]
|
|
117
|
+
|
|
118
|
+
def test_submatrix_set(self):
|
|
119
|
+
m = create_matrix(default_value=0)
|
|
120
|
+
m.set_submatrix(10, 10, [[1, 2], [3, 4]])
|
|
121
|
+
assert m[(10, 10)] == 1
|
|
122
|
+
assert m[(10, 11)] == 2
|
|
123
|
+
assert m[(11, 10)] == 3
|
|
124
|
+
assert m[(11, 11)] == 4
|
|
125
|
+
|
|
126
|
+
def test_submatrix_bounds(self):
|
|
127
|
+
m = create_matrix()
|
|
128
|
+
with pytest.raises(IndexError):
|
|
129
|
+
m.get_submatrix(0, 101, 0, 10)
|
|
130
|
+
with pytest.raises(IndexError):
|
|
131
|
+
m.get_submatrix(0, 10, 0, 101)
|
|
132
|
+
|
|
133
|
+
def test_iterate_row(self):
|
|
134
|
+
m = create_matrix(default_value=0)
|
|
135
|
+
m.set_row(7, list(range(100)))
|
|
136
|
+
vals = [v for _, v in m.iterate_row(7)]
|
|
137
|
+
assert vals == list(range(100))
|
|
138
|
+
|
|
139
|
+
def test_iterate_col(self):
|
|
140
|
+
m = create_matrix(default_value=0)
|
|
141
|
+
m.set_col(4, [i * 2 for i in range(100)])
|
|
142
|
+
vals = [v for _, v in m.iterate_col(4)]
|
|
143
|
+
assert vals == [i * 2 for i in range(100)]
|
|
144
|
+
|
|
145
|
+
def test_to_list(self):
|
|
146
|
+
m = create_matrix(default_value=9)
|
|
147
|
+
lst = m.to_list()
|
|
148
|
+
assert len(lst) == 100
|
|
149
|
+
assert len(lst[0]) == 100
|
|
150
|
+
assert all(all(v == 9 for v in row) for row in lst)
|
|
151
|
+
|
|
152
|
+
def test_from_list(self):
|
|
153
|
+
data = [[r * 100 + c for c in range(100)] for r in range(100)]
|
|
154
|
+
m = MatrixDict.from_list(data, default_value=0)
|
|
155
|
+
assert m[(0, 0)] == 0
|
|
156
|
+
assert m[(50, 50)] == 5050
|
|
157
|
+
assert m[(99, 99)] == 9999
|
|
158
|
+
|
|
159
|
+
def test_from_list_wrong_size(self):
|
|
160
|
+
data = [[1, 2], [3, 4]]
|
|
161
|
+
with pytest.raises(ValueError):
|
|
162
|
+
MatrixDict.from_list(data)
|
|
163
|
+
|
|
164
|
+
def test_repr(self):
|
|
165
|
+
m = create_matrix(default_value=0)
|
|
166
|
+
assert "MatrixDict" in repr(m)
|
|
167
|
+
assert "10000" in repr(m)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
if __name__ == "__main__":
|
|
171
|
+
pytest.main([__file__, "-v"])
|