fastremap 1.15.1__tar.gz → 1.15.2__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.
Files changed (35) hide show
  1. {fastremap-1.15.1 → fastremap-1.15.2}/.github/workflows/build_wheel.yml +7 -3
  2. {fastremap-1.15.1 → fastremap-1.15.2}/.github/workflows/test.yml +2 -2
  3. {fastremap-1.15.1 → fastremap-1.15.2}/ChangeLog +10 -0
  4. fastremap-1.15.2/PKG-INFO +229 -0
  5. fastremap-1.15.2/fastremap.egg-info/PKG-INFO +229 -0
  6. fastremap-1.15.2/fastremap.egg-info/pbr.json +1 -0
  7. {fastremap-1.15.1 → fastremap-1.15.2}/setup.py +1 -1
  8. {fastremap-1.15.1 → fastremap-1.15.2}/src/fastremap.pyx +1 -1
  9. fastremap-1.15.1/PKG-INFO +0 -218
  10. fastremap-1.15.1/fastremap.egg-info/PKG-INFO +0 -218
  11. fastremap-1.15.1/fastremap.egg-info/pbr.json +0 -1
  12. {fastremap-1.15.1 → fastremap-1.15.2}/.dockerignore +0 -0
  13. {fastremap-1.15.1 → fastremap-1.15.2}/AUTHORS +0 -0
  14. {fastremap-1.15.1 → fastremap-1.15.2}/LICENSE +0 -0
  15. {fastremap-1.15.1 → fastremap-1.15.2}/MANIFEST.in +0 -0
  16. {fastremap-1.15.1 → fastremap-1.15.2}/README.md +0 -0
  17. {fastremap-1.15.1 → fastremap-1.15.2}/automated_test.py +0 -0
  18. {fastremap-1.15.1 → fastremap-1.15.2}/build_linux.sh +0 -0
  19. {fastremap-1.15.1 → fastremap-1.15.2}/fastremap.egg-info/SOURCES.txt +0 -0
  20. {fastremap-1.15.1 → fastremap-1.15.2}/fastremap.egg-info/dependency_links.txt +0 -0
  21. {fastremap-1.15.1 → fastremap-1.15.2}/fastremap.egg-info/not-zip-safe +0 -0
  22. {fastremap-1.15.1 → fastremap-1.15.2}/fastremap.egg-info/requires.txt +0 -0
  23. {fastremap-1.15.1 → fastremap-1.15.2}/fastremap.egg-info/top_level.txt +0 -0
  24. {fastremap-1.15.1 → fastremap-1.15.2}/manylinux1.Dockerfile +0 -0
  25. {fastremap-1.15.1 → fastremap-1.15.2}/manylinux2010.Dockerfile +0 -0
  26. {fastremap-1.15.1 → fastremap-1.15.2}/manylinux2014.Dockerfile +0 -0
  27. {fastremap-1.15.1 → fastremap-1.15.2}/pyproject.toml +0 -0
  28. {fastremap-1.15.1 → fastremap-1.15.2}/requirements.txt +0 -0
  29. {fastremap-1.15.1 → fastremap-1.15.2}/requirements_dev.txt +0 -0
  30. {fastremap-1.15.1 → fastremap-1.15.2}/setup.cfg +0 -0
  31. {fastremap-1.15.1 → fastremap-1.15.2}/src/fastremap.pxd +0 -0
  32. {fastremap-1.15.1 → fastremap-1.15.2}/src/ipt.hpp +0 -0
  33. {fastremap-1.15.1 → fastremap-1.15.2}/src/ska_flat_hash_map.hpp +0 -0
  34. {fastremap-1.15.1 → fastremap-1.15.2}/test.py +0 -0
  35. {fastremap-1.15.1 → fastremap-1.15.2}/tox.ini +0 -0
@@ -6,7 +6,7 @@ on:
6
6
  tags:
7
7
  - '*'
8
8
  env:
9
- CIBW_SKIP: cp27-* cp33-* cp34-* cp35-* cp36-* cp37-* pp* *-musllinux* cp312-manylinux_i686
9
+ CIBW_SKIP: cp27-* cp33-* cp34-* cp35-* cp36-* cp37-* cp38* pp* *-musllinux* cp312-manylinux_i686
10
10
 
11
11
  jobs:
12
12
  build_wheels:
@@ -35,6 +35,10 @@ jobs:
35
35
  CIBW_BEFORE_BUILD: pip install numpy setuptools wheel cython
36
36
  CIBW_ARCHS_MACOS: "x86_64 arm64"
37
37
 
38
- - uses: actions/upload-artifact@v3
38
+
39
+ - name: Upload built wheels
40
+ uses: actions/upload-artifact@v4
39
41
  with:
40
- path: ./wheelhouse/*.whl
42
+ name: built-wheels-${{ matrix.os }}-${{ matrix.arch }}
43
+ path: ./wheelhouse/*.whl
44
+ if-no-files-found: warn
@@ -14,8 +14,8 @@ jobs:
14
14
  runs-on: ${{ matrix.os }}
15
15
  strategy:
16
16
  matrix:
17
- os: [ubuntu-20.04, macos-latest, windows-2019]
18
- python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
17
+ os: [ubuntu-latest, macos-latest, windows-latest]
18
+ python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
19
19
 
20
20
  steps:
21
21
  - name: Set up Python ${{ matrix.python-version }}
@@ -1,6 +1,16 @@
1
1
  CHANGES
2
2
  =======
3
3
 
4
+ 1.15.2
5
+ ------
6
+
7
+ * install: restrict to py39+
8
+ * ci: exclude py38 from build
9
+ * ci: remove py38 as it is EOL
10
+ * ci: update runners
11
+ * test: add python3.13
12
+ * ci: upgrade to upload-artifact v4
13
+
4
14
  1.15.1
5
15
  ------
6
16
 
@@ -0,0 +1,229 @@
1
+ Metadata-Version: 2.4
2
+ Name: fastremap
3
+ Version: 1.15.2
4
+ Summary: Remap, mask, renumber, unique, and in-place transposition of 3D labeled images. Point cloud too.
5
+ Home-page: https://github.com/seung-lab/fastremap/
6
+ Author: William Silversmith
7
+ Author-email: ws9@princeton.edu
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
11
+ Classifier: Programming Language :: Python
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.7
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Topic :: Utilities
19
+ Requires-Python: >=3.9,<4.0
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ License-File: AUTHORS
23
+ Requires-Dist: numpy
24
+ Dynamic: author
25
+ Dynamic: author-email
26
+ Dynamic: classifier
27
+ Dynamic: description
28
+ Dynamic: description-content-type
29
+ Dynamic: home-page
30
+ Dynamic: license-file
31
+ Dynamic: requires-dist
32
+ Dynamic: requires-python
33
+ Dynamic: summary
34
+
35
+ [![PyPI version](https://badge.fury.io/py/fastremap.svg)](https://badge.fury.io/py/fastremap)
36
+
37
+ # fastremap
38
+
39
+ Renumber and relabel Numpy arrays at C++ speed and physically convert rectangular Numpy arrays between C and Fortran order using an in-place transposition.
40
+
41
+ ```python
42
+ import fastremap
43
+
44
+ uniq, cts = fastremap.unique(labels, return_counts=True) # may be much faster than np.unique
45
+ labels, remapping = fastremap.renumber(labels, in_place=True) # relabel values from 1 and refit data type
46
+ ptc = fastremap.point_cloud(labels) # dict of coordinates by label
47
+
48
+ labels = fastremap.refit(labels) # resize the data type of the array to fit extrema
49
+ labels = fastremap.refit(labels, value=-35) # resize the data type to fit the value provided
50
+
51
+ # remap all occurances of 1 -> 2
52
+ labels = fastremap.remap(labels, { 1: 2 }, preserve_missing_labels=True, in_place=True)
53
+
54
+ labels = fastremap.mask(labels, [1,5,13]) # set all occurances of 1,5,13 to 0
55
+ labels = fastremap.mask_except(labels, [1,5,13]) # set all labels except 1,5,13 to 0
56
+
57
+ mapping = fastremap.component_map([ 1, 2, 3, 4 ], [ 5, 5, 6, 7 ]) # { 1: 5, 2: 5, 3: 6, 4: 7 }
58
+ mapping = fastremap.inverse_component_map([ 1, 2, 1, 3 ], [ 4, 4, 5, 6 ]) # { 1: [ 4, 5 ], 2: [ 4 ], 3: [ 6 ] }
59
+
60
+ fastremap.transpose(labels) # physically transpose labels in-place
61
+ fastremap.ascontiguousarray(labels) # try to perform a physical in-place transposition to C order
62
+ fastremap.asfortranarray(labels) # try to perform a physical in-place transposition to F order
63
+
64
+ minval, maxval = fastremap.minmax(labels) # faster version of (np.min(labels), np.max(labels))
65
+
66
+ # computes number of matching adjacent pixel pairs in an image
67
+ num_pairs = fastremap.pixel_pairs(labels)
68
+ n_foreground = fastremap.foreground(labels) # number of nonzero voxels
69
+
70
+ # computes the cutout.tobytes(order) of each chunk and returns
71
+ # the binaries indexed by fortran order in the order specified (C or F)
72
+ # If the input image is F contiguous and F is requested, or C and C order,
73
+ # and the image is larger than a single chunk, this will be significantly
74
+ # faster than iterating and using tobytes.
75
+ binaries = fastremap.tobytes(labels, (64,64,64), order="F")
76
+ ```
77
+
78
+ ## All Available Functions
79
+ - **unique:** Faster implementation of `np.unique`.
80
+ - **renumber:** Relabel array from 1 to N which can often use smaller datatypes.
81
+ - **remap:** Custom relabeling of values in an array from a dictionary.
82
+ - **refit:** Resize the data type of an array to the smallest that can contain the most extreme values in it.
83
+ - **mask:** Zero out labels in an array specified by a given list.
84
+ - **mask_except**: Zero out all labels except those specified in a given list.
85
+ - **component_map**: Extract an int-to-int dictionary mapping of labels from one image containing component labels to another parent labels.
86
+ - **inverse_component_map**: Extract an int-to-list-of-ints dictionary mapping from an image containing groups of components to an image containing the components.
87
+ - **remap_from_array:** Same as remap, but the map is an array where the key is the array index and the value is the value.
88
+ - **remap_from_array_kv:** Same as remap, but the map consists of two equal sized arrays, the first containing keys, the second containing values.
89
+ - **asfortranarray:** Perform an in-place matrix transposition for rectangular arrays if memory is contiguous, standard numpy otherwise.
90
+ - **ascontiguousarray:** Perform an in-place matrix transposition for rectangular arrays if memory is contiguous, standard numpy algorithm otherwise.
91
+ - **minmax:** Compute the min and max of an array in one pass.
92
+ - **pixel_pairs:** Computes the number of adjacent matching memory locations in an image. A quick heuristic for understanding if the image statistics are roughly similar to a connectomics segmentation.
93
+ - **foreground:** Count the number of non-zero voxels rapidly.
94
+ - **point_cloud:** Get the X,Y,Z locations of each foreground voxel grouped by label.
95
+ - **tobytes**: Compute the tobytes of an image divided into a grid and return the resultant binaries indexed by their gridpoint in fortran order with the binary in the order requested (C or F).
96
+
97
+ ## `pip` Installation
98
+
99
+ ```bash
100
+ pip install fastremap
101
+ ```
102
+
103
+ *If not, a C++ compiler is required.*
104
+
105
+ ```bash
106
+ pip install numpy
107
+ pip install fastremap --no-binary :all:
108
+ ```
109
+
110
+ ## Manual Installation
111
+
112
+ *A C++ compiler is required.*
113
+
114
+ ```bash
115
+ sudo apt-get install g++ python3-dev
116
+ mkvirtualenv -p python3 fastremap
117
+ pip install numpy
118
+
119
+ # Choose one:
120
+ python setup.py develop
121
+ python setup.py install
122
+ ```
123
+
124
+ ## The Problem of Remapping
125
+
126
+ Python loops are slow, so Numpy is often used to perform remapping on large arrays (hundreds of megabytes or gigabytes). In order to efficiently remap an array in Numpy you need a key-value array where the index is the key and the value is the contents of that index.
127
+
128
+ ```python
129
+ import numpy as np
130
+
131
+ original = np.array([ 1, 3, 5, 5, 10 ])
132
+ remap = np.array([ 0, -5, 0, 6, 0, 0, 2, 0, 0, 0, -100 ])
133
+ # Keys: 0 1 2 3 4 5 6 7 8 9 10
134
+
135
+ remapped = remap[ original ]
136
+ >>> [ -5, 6, 2, 2, -100 ]
137
+ ```
138
+
139
+ If there are 32 or 64 bit labels in the array, this becomes impractical as the size of the array can grow larger than RAM. Therefore, it would be helpful to be able to perform this mapping using a C speed loop. Numba can be used for this in some circumstances. However, this library provides an alternative.
140
+
141
+ ```python
142
+ import numpy as np
143
+ import fastremap
144
+
145
+ mappings = {
146
+ 1: 100,
147
+ 2: 200,
148
+ -3: 7,
149
+ }
150
+
151
+ arr = np.array([5, 1, 2, -5, -3, 10, 6])
152
+ # Custom remapping of -3, 5, and 6 leaving the rest alone
153
+ arr = fastremap.remap(arr, mappings, preserve_missing_labels=True)
154
+ # result: [ 5, 100, 200, -5, 7, 10, 6 ]
155
+ ```
156
+
157
+ ## The Problem of Renumbering
158
+
159
+ Sometimes a 64-bit array contains values that could be represented by an 8-bit array. However, similarly to the remapping problem, Python loops can be too slow to do this. Numpy doesn't provide a convenient way to do it either. Therefore this library provides an alternative solution.
160
+
161
+ ```python
162
+ import fastremap
163
+ import numpy as np
164
+
165
+ arr = np.array([ 283732875, 439238823, 283732875, 182812404, 0 ], dtype=np.int64)
166
+
167
+ arr, remapping = fastremap.renumber(arr, preserve_zero=True) # Returns uint8 array
168
+ >>> arr = [ 1, 2, 1, 3, 0 ]
169
+ >>> remapping = { 0: 0, 283732875: 1, 439238823: 2, 182812404: 3 }
170
+
171
+ arr, remapping = fastremap.renumber(arr, preserve_zero=False) # Returns uint8 array
172
+ >>> arr = [ 1, 2, 1, 3, 4 ]
173
+ >>> remapping = { 0: 4, 283732875: 1, 439238823: 2, 182812404: 3 }
174
+
175
+ arr, remapping = fastremap.renumber(arr, preserve_zero=False, in_place=True) # Mutate arr to use less memory
176
+ >>> arr = [ 1, 2, 1, 3, 4 ]
177
+ >>> remapping = { 0: 4, 283732875: 1, 439238823: 2, 182812404: 3 }
178
+ ```
179
+
180
+ ## The Problem of In-Place Transposition
181
+
182
+ When transitioning between different media, e.g. CPU to GPU, CPU to Network, CPU to disk, it's often necessary to physically transpose multi-dimensional arrays to reformat as C or Fortran order. Tranposing matrices is also a common action in linear algebra, but often you can get away with just changing the strides.
183
+
184
+ An out-of-place transposition is easy to write, and often faster, but it will spike peak memory consumption. This library grants the user the option of performing an in-place transposition which trades CPU time for peak memory usage. In the special case of square or cubic arrays, the in-place transpisition is both lower memory and faster.
185
+
186
+ - **fastremap.asfortranarray:** Same as np.asfortranarray but will perform the transposition in-place for 1, 2, 3, and 4D arrays. 2D and 3D square matrices are faster to process than with Numpy.
187
+ - **fastremap.ascontiguousarray:** Same as np.ascontiguousarray but will perform the transposition in-place for 1, 2, 3, and 4D arrays. 2D and 3D square matrices are faster to process than with Numpy.
188
+
189
+ ```python
190
+ import fastremap
191
+ import numpy as np
192
+
193
+ arr = np.ones((512,512,512), dtype=np.float32)
194
+ arr = fastremap.asfortranarray(x)
195
+
196
+ arr = np.ones((512,512,512), dtype=np.float32, order='F')
197
+ arr = fastremap.ascontiguousarray(x)
198
+ ```
199
+
200
+ ## C++ Usage
201
+
202
+ The in-place matrix transposition is implemented in ipt.hpp. If you're working in C++, you can also use it directly like so:
203
+
204
+ ```cpp
205
+ #include "ipt.hpp"
206
+
207
+ int main() {
208
+
209
+ int sx = 128;
210
+ int sy = 124;
211
+ int sz = 103;
212
+ int sw = 3;
213
+
214
+ auto* arr = ....;
215
+
216
+ // All primitive number types supported
217
+ // The array will be modified in place,
218
+ // so these functions are void type.
219
+ ipt::ipt<int>(arr, sx, sy); // 2D
220
+ ipt::ipt<float>(arr, sx, sy, sz); // 3D
221
+ ipt::ipt<double>(arr, sx, sy, sz, sw); // 4D
222
+
223
+ return 0;
224
+ }
225
+ ```
226
+
227
+ --
228
+ Made with <3
229
+
@@ -0,0 +1,229 @@
1
+ Metadata-Version: 2.4
2
+ Name: fastremap
3
+ Version: 1.15.2
4
+ Summary: Remap, mask, renumber, unique, and in-place transposition of 3D labeled images. Point cloud too.
5
+ Home-page: https://github.com/seung-lab/fastremap/
6
+ Author: William Silversmith
7
+ Author-email: ws9@princeton.edu
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
11
+ Classifier: Programming Language :: Python
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.7
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Topic :: Utilities
19
+ Requires-Python: >=3.9,<4.0
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ License-File: AUTHORS
23
+ Requires-Dist: numpy
24
+ Dynamic: author
25
+ Dynamic: author-email
26
+ Dynamic: classifier
27
+ Dynamic: description
28
+ Dynamic: description-content-type
29
+ Dynamic: home-page
30
+ Dynamic: license-file
31
+ Dynamic: requires-dist
32
+ Dynamic: requires-python
33
+ Dynamic: summary
34
+
35
+ [![PyPI version](https://badge.fury.io/py/fastremap.svg)](https://badge.fury.io/py/fastremap)
36
+
37
+ # fastremap
38
+
39
+ Renumber and relabel Numpy arrays at C++ speed and physically convert rectangular Numpy arrays between C and Fortran order using an in-place transposition.
40
+
41
+ ```python
42
+ import fastremap
43
+
44
+ uniq, cts = fastremap.unique(labels, return_counts=True) # may be much faster than np.unique
45
+ labels, remapping = fastremap.renumber(labels, in_place=True) # relabel values from 1 and refit data type
46
+ ptc = fastremap.point_cloud(labels) # dict of coordinates by label
47
+
48
+ labels = fastremap.refit(labels) # resize the data type of the array to fit extrema
49
+ labels = fastremap.refit(labels, value=-35) # resize the data type to fit the value provided
50
+
51
+ # remap all occurances of 1 -> 2
52
+ labels = fastremap.remap(labels, { 1: 2 }, preserve_missing_labels=True, in_place=True)
53
+
54
+ labels = fastremap.mask(labels, [1,5,13]) # set all occurances of 1,5,13 to 0
55
+ labels = fastremap.mask_except(labels, [1,5,13]) # set all labels except 1,5,13 to 0
56
+
57
+ mapping = fastremap.component_map([ 1, 2, 3, 4 ], [ 5, 5, 6, 7 ]) # { 1: 5, 2: 5, 3: 6, 4: 7 }
58
+ mapping = fastremap.inverse_component_map([ 1, 2, 1, 3 ], [ 4, 4, 5, 6 ]) # { 1: [ 4, 5 ], 2: [ 4 ], 3: [ 6 ] }
59
+
60
+ fastremap.transpose(labels) # physically transpose labels in-place
61
+ fastremap.ascontiguousarray(labels) # try to perform a physical in-place transposition to C order
62
+ fastremap.asfortranarray(labels) # try to perform a physical in-place transposition to F order
63
+
64
+ minval, maxval = fastremap.minmax(labels) # faster version of (np.min(labels), np.max(labels))
65
+
66
+ # computes number of matching adjacent pixel pairs in an image
67
+ num_pairs = fastremap.pixel_pairs(labels)
68
+ n_foreground = fastremap.foreground(labels) # number of nonzero voxels
69
+
70
+ # computes the cutout.tobytes(order) of each chunk and returns
71
+ # the binaries indexed by fortran order in the order specified (C or F)
72
+ # If the input image is F contiguous and F is requested, or C and C order,
73
+ # and the image is larger than a single chunk, this will be significantly
74
+ # faster than iterating and using tobytes.
75
+ binaries = fastremap.tobytes(labels, (64,64,64), order="F")
76
+ ```
77
+
78
+ ## All Available Functions
79
+ - **unique:** Faster implementation of `np.unique`.
80
+ - **renumber:** Relabel array from 1 to N which can often use smaller datatypes.
81
+ - **remap:** Custom relabeling of values in an array from a dictionary.
82
+ - **refit:** Resize the data type of an array to the smallest that can contain the most extreme values in it.
83
+ - **mask:** Zero out labels in an array specified by a given list.
84
+ - **mask_except**: Zero out all labels except those specified in a given list.
85
+ - **component_map**: Extract an int-to-int dictionary mapping of labels from one image containing component labels to another parent labels.
86
+ - **inverse_component_map**: Extract an int-to-list-of-ints dictionary mapping from an image containing groups of components to an image containing the components.
87
+ - **remap_from_array:** Same as remap, but the map is an array where the key is the array index and the value is the value.
88
+ - **remap_from_array_kv:** Same as remap, but the map consists of two equal sized arrays, the first containing keys, the second containing values.
89
+ - **asfortranarray:** Perform an in-place matrix transposition for rectangular arrays if memory is contiguous, standard numpy otherwise.
90
+ - **ascontiguousarray:** Perform an in-place matrix transposition for rectangular arrays if memory is contiguous, standard numpy algorithm otherwise.
91
+ - **minmax:** Compute the min and max of an array in one pass.
92
+ - **pixel_pairs:** Computes the number of adjacent matching memory locations in an image. A quick heuristic for understanding if the image statistics are roughly similar to a connectomics segmentation.
93
+ - **foreground:** Count the number of non-zero voxels rapidly.
94
+ - **point_cloud:** Get the X,Y,Z locations of each foreground voxel grouped by label.
95
+ - **tobytes**: Compute the tobytes of an image divided into a grid and return the resultant binaries indexed by their gridpoint in fortran order with the binary in the order requested (C or F).
96
+
97
+ ## `pip` Installation
98
+
99
+ ```bash
100
+ pip install fastremap
101
+ ```
102
+
103
+ *If not, a C++ compiler is required.*
104
+
105
+ ```bash
106
+ pip install numpy
107
+ pip install fastremap --no-binary :all:
108
+ ```
109
+
110
+ ## Manual Installation
111
+
112
+ *A C++ compiler is required.*
113
+
114
+ ```bash
115
+ sudo apt-get install g++ python3-dev
116
+ mkvirtualenv -p python3 fastremap
117
+ pip install numpy
118
+
119
+ # Choose one:
120
+ python setup.py develop
121
+ python setup.py install
122
+ ```
123
+
124
+ ## The Problem of Remapping
125
+
126
+ Python loops are slow, so Numpy is often used to perform remapping on large arrays (hundreds of megabytes or gigabytes). In order to efficiently remap an array in Numpy you need a key-value array where the index is the key and the value is the contents of that index.
127
+
128
+ ```python
129
+ import numpy as np
130
+
131
+ original = np.array([ 1, 3, 5, 5, 10 ])
132
+ remap = np.array([ 0, -5, 0, 6, 0, 0, 2, 0, 0, 0, -100 ])
133
+ # Keys: 0 1 2 3 4 5 6 7 8 9 10
134
+
135
+ remapped = remap[ original ]
136
+ >>> [ -5, 6, 2, 2, -100 ]
137
+ ```
138
+
139
+ If there are 32 or 64 bit labels in the array, this becomes impractical as the size of the array can grow larger than RAM. Therefore, it would be helpful to be able to perform this mapping using a C speed loop. Numba can be used for this in some circumstances. However, this library provides an alternative.
140
+
141
+ ```python
142
+ import numpy as np
143
+ import fastremap
144
+
145
+ mappings = {
146
+ 1: 100,
147
+ 2: 200,
148
+ -3: 7,
149
+ }
150
+
151
+ arr = np.array([5, 1, 2, -5, -3, 10, 6])
152
+ # Custom remapping of -3, 5, and 6 leaving the rest alone
153
+ arr = fastremap.remap(arr, mappings, preserve_missing_labels=True)
154
+ # result: [ 5, 100, 200, -5, 7, 10, 6 ]
155
+ ```
156
+
157
+ ## The Problem of Renumbering
158
+
159
+ Sometimes a 64-bit array contains values that could be represented by an 8-bit array. However, similarly to the remapping problem, Python loops can be too slow to do this. Numpy doesn't provide a convenient way to do it either. Therefore this library provides an alternative solution.
160
+
161
+ ```python
162
+ import fastremap
163
+ import numpy as np
164
+
165
+ arr = np.array([ 283732875, 439238823, 283732875, 182812404, 0 ], dtype=np.int64)
166
+
167
+ arr, remapping = fastremap.renumber(arr, preserve_zero=True) # Returns uint8 array
168
+ >>> arr = [ 1, 2, 1, 3, 0 ]
169
+ >>> remapping = { 0: 0, 283732875: 1, 439238823: 2, 182812404: 3 }
170
+
171
+ arr, remapping = fastremap.renumber(arr, preserve_zero=False) # Returns uint8 array
172
+ >>> arr = [ 1, 2, 1, 3, 4 ]
173
+ >>> remapping = { 0: 4, 283732875: 1, 439238823: 2, 182812404: 3 }
174
+
175
+ arr, remapping = fastremap.renumber(arr, preserve_zero=False, in_place=True) # Mutate arr to use less memory
176
+ >>> arr = [ 1, 2, 1, 3, 4 ]
177
+ >>> remapping = { 0: 4, 283732875: 1, 439238823: 2, 182812404: 3 }
178
+ ```
179
+
180
+ ## The Problem of In-Place Transposition
181
+
182
+ When transitioning between different media, e.g. CPU to GPU, CPU to Network, CPU to disk, it's often necessary to physically transpose multi-dimensional arrays to reformat as C or Fortran order. Tranposing matrices is also a common action in linear algebra, but often you can get away with just changing the strides.
183
+
184
+ An out-of-place transposition is easy to write, and often faster, but it will spike peak memory consumption. This library grants the user the option of performing an in-place transposition which trades CPU time for peak memory usage. In the special case of square or cubic arrays, the in-place transpisition is both lower memory and faster.
185
+
186
+ - **fastremap.asfortranarray:** Same as np.asfortranarray but will perform the transposition in-place for 1, 2, 3, and 4D arrays. 2D and 3D square matrices are faster to process than with Numpy.
187
+ - **fastremap.ascontiguousarray:** Same as np.ascontiguousarray but will perform the transposition in-place for 1, 2, 3, and 4D arrays. 2D and 3D square matrices are faster to process than with Numpy.
188
+
189
+ ```python
190
+ import fastremap
191
+ import numpy as np
192
+
193
+ arr = np.ones((512,512,512), dtype=np.float32)
194
+ arr = fastremap.asfortranarray(x)
195
+
196
+ arr = np.ones((512,512,512), dtype=np.float32, order='F')
197
+ arr = fastremap.ascontiguousarray(x)
198
+ ```
199
+
200
+ ## C++ Usage
201
+
202
+ The in-place matrix transposition is implemented in ipt.hpp. If you're working in C++, you can also use it directly like so:
203
+
204
+ ```cpp
205
+ #include "ipt.hpp"
206
+
207
+ int main() {
208
+
209
+ int sx = 128;
210
+ int sy = 124;
211
+ int sz = 103;
212
+ int sw = 3;
213
+
214
+ auto* arr = ....;
215
+
216
+ // All primitive number types supported
217
+ // The array will be modified in place,
218
+ // so these functions are void type.
219
+ ipt::ipt<int>(arr, sx, sy); // 2D
220
+ ipt::ipt<float>(arr, sx, sy, sz); // 3D
221
+ ipt::ipt<double>(arr, sx, sy, sz, sw); // 4D
222
+
223
+ return 0;
224
+ }
225
+ ```
226
+
227
+ --
228
+ Made with <3
229
+
@@ -0,0 +1 @@
1
+ {"git_version": "b766561", "is_release": true}
@@ -23,7 +23,7 @@ if sys.platform == 'darwin':
23
23
 
24
24
  setuptools.setup(
25
25
  setup_requires=['pbr', 'cython', 'numpy'],
26
- python_requires=">=3.8,<4.0",
26
+ python_requires=">=3.9,<4.0",
27
27
  pbr=True,
28
28
  ext_modules=[
29
29
  setuptools.Extension(
@@ -897,7 +897,7 @@ def unique_via_sort(cnp.ndarray[ALLINT, ndim=1] labels):
897
897
 
898
898
  del labels
899
899
 
900
- return np.array(uniq, dtype=labels.dtype), np.array(counts)
900
+ return np.array(uniq), np.array(counts)
901
901
 
902
902
  @cython.boundscheck(False)
903
903
  @cython.wraparound(False) # turn off negative index wrapping for entire function
fastremap-1.15.1/PKG-INFO DELETED
@@ -1,218 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: fastremap
3
- Version: 1.15.1
4
- Summary: Remap, mask, renumber, unique, and in-place transposition of 3D labeled images. Point cloud too.
5
- Home-page: https://github.com/seung-lab/fastremap/
6
- Author: William Silversmith
7
- Author-email: ws9@princeton.edu
8
- License: UNKNOWN
9
- Description: [![PyPI version](https://badge.fury.io/py/fastremap.svg)](https://badge.fury.io/py/fastremap)
10
-
11
- # fastremap
12
-
13
- Renumber and relabel Numpy arrays at C++ speed and physically convert rectangular Numpy arrays between C and Fortran order using an in-place transposition.
14
-
15
- ```python
16
- import fastremap
17
-
18
- uniq, cts = fastremap.unique(labels, return_counts=True) # may be much faster than np.unique
19
- labels, remapping = fastremap.renumber(labels, in_place=True) # relabel values from 1 and refit data type
20
- ptc = fastremap.point_cloud(labels) # dict of coordinates by label
21
-
22
- labels = fastremap.refit(labels) # resize the data type of the array to fit extrema
23
- labels = fastremap.refit(labels, value=-35) # resize the data type to fit the value provided
24
-
25
- # remap all occurances of 1 -> 2
26
- labels = fastremap.remap(labels, { 1: 2 }, preserve_missing_labels=True, in_place=True)
27
-
28
- labels = fastremap.mask(labels, [1,5,13]) # set all occurances of 1,5,13 to 0
29
- labels = fastremap.mask_except(labels, [1,5,13]) # set all labels except 1,5,13 to 0
30
-
31
- mapping = fastremap.component_map([ 1, 2, 3, 4 ], [ 5, 5, 6, 7 ]) # { 1: 5, 2: 5, 3: 6, 4: 7 }
32
- mapping = fastremap.inverse_component_map([ 1, 2, 1, 3 ], [ 4, 4, 5, 6 ]) # { 1: [ 4, 5 ], 2: [ 4 ], 3: [ 6 ] }
33
-
34
- fastremap.transpose(labels) # physically transpose labels in-place
35
- fastremap.ascontiguousarray(labels) # try to perform a physical in-place transposition to C order
36
- fastremap.asfortranarray(labels) # try to perform a physical in-place transposition to F order
37
-
38
- minval, maxval = fastremap.minmax(labels) # faster version of (np.min(labels), np.max(labels))
39
-
40
- # computes number of matching adjacent pixel pairs in an image
41
- num_pairs = fastremap.pixel_pairs(labels)
42
- n_foreground = fastremap.foreground(labels) # number of nonzero voxels
43
-
44
- # computes the cutout.tobytes(order) of each chunk and returns
45
- # the binaries indexed by fortran order in the order specified (C or F)
46
- # If the input image is F contiguous and F is requested, or C and C order,
47
- # and the image is larger than a single chunk, this will be significantly
48
- # faster than iterating and using tobytes.
49
- binaries = fastremap.tobytes(labels, (64,64,64), order="F")
50
- ```
51
-
52
- ## All Available Functions
53
- - **unique:** Faster implementation of `np.unique`.
54
- - **renumber:** Relabel array from 1 to N which can often use smaller datatypes.
55
- - **remap:** Custom relabeling of values in an array from a dictionary.
56
- - **refit:** Resize the data type of an array to the smallest that can contain the most extreme values in it.
57
- - **mask:** Zero out labels in an array specified by a given list.
58
- - **mask_except**: Zero out all labels except those specified in a given list.
59
- - **component_map**: Extract an int-to-int dictionary mapping of labels from one image containing component labels to another parent labels.
60
- - **inverse_component_map**: Extract an int-to-list-of-ints dictionary mapping from an image containing groups of components to an image containing the components.
61
- - **remap_from_array:** Same as remap, but the map is an array where the key is the array index and the value is the value.
62
- - **remap_from_array_kv:** Same as remap, but the map consists of two equal sized arrays, the first containing keys, the second containing values.
63
- - **asfortranarray:** Perform an in-place matrix transposition for rectangular arrays if memory is contiguous, standard numpy otherwise.
64
- - **ascontiguousarray:** Perform an in-place matrix transposition for rectangular arrays if memory is contiguous, standard numpy algorithm otherwise.
65
- - **minmax:** Compute the min and max of an array in one pass.
66
- - **pixel_pairs:** Computes the number of adjacent matching memory locations in an image. A quick heuristic for understanding if the image statistics are roughly similar to a connectomics segmentation.
67
- - **foreground:** Count the number of non-zero voxels rapidly.
68
- - **point_cloud:** Get the X,Y,Z locations of each foreground voxel grouped by label.
69
- - **tobytes**: Compute the tobytes of an image divided into a grid and return the resultant binaries indexed by their gridpoint in fortran order with the binary in the order requested (C or F).
70
-
71
- ## `pip` Installation
72
-
73
- ```bash
74
- pip install fastremap
75
- ```
76
-
77
- *If not, a C++ compiler is required.*
78
-
79
- ```bash
80
- pip install numpy
81
- pip install fastremap --no-binary :all:
82
- ```
83
-
84
- ## Manual Installation
85
-
86
- *A C++ compiler is required.*
87
-
88
- ```bash
89
- sudo apt-get install g++ python3-dev
90
- mkvirtualenv -p python3 fastremap
91
- pip install numpy
92
-
93
- # Choose one:
94
- python setup.py develop
95
- python setup.py install
96
- ```
97
-
98
- ## The Problem of Remapping
99
-
100
- Python loops are slow, so Numpy is often used to perform remapping on large arrays (hundreds of megabytes or gigabytes). In order to efficiently remap an array in Numpy you need a key-value array where the index is the key and the value is the contents of that index.
101
-
102
- ```python
103
- import numpy as np
104
-
105
- original = np.array([ 1, 3, 5, 5, 10 ])
106
- remap = np.array([ 0, -5, 0, 6, 0, 0, 2, 0, 0, 0, -100 ])
107
- # Keys: 0 1 2 3 4 5 6 7 8 9 10
108
-
109
- remapped = remap[ original ]
110
- >>> [ -5, 6, 2, 2, -100 ]
111
- ```
112
-
113
- If there are 32 or 64 bit labels in the array, this becomes impractical as the size of the array can grow larger than RAM. Therefore, it would be helpful to be able to perform this mapping using a C speed loop. Numba can be used for this in some circumstances. However, this library provides an alternative.
114
-
115
- ```python
116
- import numpy as np
117
- import fastremap
118
-
119
- mappings = {
120
- 1: 100,
121
- 2: 200,
122
- -3: 7,
123
- }
124
-
125
- arr = np.array([5, 1, 2, -5, -3, 10, 6])
126
- # Custom remapping of -3, 5, and 6 leaving the rest alone
127
- arr = fastremap.remap(arr, mappings, preserve_missing_labels=True)
128
- # result: [ 5, 100, 200, -5, 7, 10, 6 ]
129
- ```
130
-
131
- ## The Problem of Renumbering
132
-
133
- Sometimes a 64-bit array contains values that could be represented by an 8-bit array. However, similarly to the remapping problem, Python loops can be too slow to do this. Numpy doesn't provide a convenient way to do it either. Therefore this library provides an alternative solution.
134
-
135
- ```python
136
- import fastremap
137
- import numpy as np
138
-
139
- arr = np.array([ 283732875, 439238823, 283732875, 182812404, 0 ], dtype=np.int64)
140
-
141
- arr, remapping = fastremap.renumber(arr, preserve_zero=True) # Returns uint8 array
142
- >>> arr = [ 1, 2, 1, 3, 0 ]
143
- >>> remapping = { 0: 0, 283732875: 1, 439238823: 2, 182812404: 3 }
144
-
145
- arr, remapping = fastremap.renumber(arr, preserve_zero=False) # Returns uint8 array
146
- >>> arr = [ 1, 2, 1, 3, 4 ]
147
- >>> remapping = { 0: 4, 283732875: 1, 439238823: 2, 182812404: 3 }
148
-
149
- arr, remapping = fastremap.renumber(arr, preserve_zero=False, in_place=True) # Mutate arr to use less memory
150
- >>> arr = [ 1, 2, 1, 3, 4 ]
151
- >>> remapping = { 0: 4, 283732875: 1, 439238823: 2, 182812404: 3 }
152
- ```
153
-
154
- ## The Problem of In-Place Transposition
155
-
156
- When transitioning between different media, e.g. CPU to GPU, CPU to Network, CPU to disk, it's often necessary to physically transpose multi-dimensional arrays to reformat as C or Fortran order. Tranposing matrices is also a common action in linear algebra, but often you can get away with just changing the strides.
157
-
158
- An out-of-place transposition is easy to write, and often faster, but it will spike peak memory consumption. This library grants the user the option of performing an in-place transposition which trades CPU time for peak memory usage. In the special case of square or cubic arrays, the in-place transpisition is both lower memory and faster.
159
-
160
- - **fastremap.asfortranarray:** Same as np.asfortranarray but will perform the transposition in-place for 1, 2, 3, and 4D arrays. 2D and 3D square matrices are faster to process than with Numpy.
161
- - **fastremap.ascontiguousarray:** Same as np.ascontiguousarray but will perform the transposition in-place for 1, 2, 3, and 4D arrays. 2D and 3D square matrices are faster to process than with Numpy.
162
-
163
- ```python
164
- import fastremap
165
- import numpy as np
166
-
167
- arr = np.ones((512,512,512), dtype=np.float32)
168
- arr = fastremap.asfortranarray(x)
169
-
170
- arr = np.ones((512,512,512), dtype=np.float32, order='F')
171
- arr = fastremap.ascontiguousarray(x)
172
- ```
173
-
174
- ## C++ Usage
175
-
176
- The in-place matrix transposition is implemented in ipt.hpp. If you're working in C++, you can also use it directly like so:
177
-
178
- ```cpp
179
- #include "ipt.hpp"
180
-
181
- int main() {
182
-
183
- int sx = 128;
184
- int sy = 124;
185
- int sz = 103;
186
- int sw = 3;
187
-
188
- auto* arr = ....;
189
-
190
- // All primitive number types supported
191
- // The array will be modified in place,
192
- // so these functions are void type.
193
- ipt::ipt<int>(arr, sx, sy); // 2D
194
- ipt::ipt<float>(arr, sx, sy, sz); // 3D
195
- ipt::ipt<double>(arr, sx, sy, sz, sw); // 4D
196
-
197
- return 0;
198
- }
199
- ```
200
-
201
- --
202
- Made with <3
203
-
204
-
205
- Platform: UNKNOWN
206
- Classifier: Intended Audience :: Developers
207
- Classifier: Development Status :: 5 - Production/Stable
208
- Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
209
- Classifier: Programming Language :: Python
210
- Classifier: Programming Language :: Python :: 3
211
- Classifier: Programming Language :: Python :: 3.7
212
- Classifier: Programming Language :: Python :: 3.8
213
- Classifier: Programming Language :: Python :: 3.9
214
- Classifier: Programming Language :: Python :: 3.10
215
- Classifier: Programming Language :: Python :: 3.11
216
- Classifier: Topic :: Utilities
217
- Requires-Python: >=3.8,<4.0
218
- Description-Content-Type: text/markdown
@@ -1,218 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: fastremap
3
- Version: 1.15.1
4
- Summary: Remap, mask, renumber, unique, and in-place transposition of 3D labeled images. Point cloud too.
5
- Home-page: https://github.com/seung-lab/fastremap/
6
- Author: William Silversmith
7
- Author-email: ws9@princeton.edu
8
- License: UNKNOWN
9
- Description: [![PyPI version](https://badge.fury.io/py/fastremap.svg)](https://badge.fury.io/py/fastremap)
10
-
11
- # fastremap
12
-
13
- Renumber and relabel Numpy arrays at C++ speed and physically convert rectangular Numpy arrays between C and Fortran order using an in-place transposition.
14
-
15
- ```python
16
- import fastremap
17
-
18
- uniq, cts = fastremap.unique(labels, return_counts=True) # may be much faster than np.unique
19
- labels, remapping = fastremap.renumber(labels, in_place=True) # relabel values from 1 and refit data type
20
- ptc = fastremap.point_cloud(labels) # dict of coordinates by label
21
-
22
- labels = fastremap.refit(labels) # resize the data type of the array to fit extrema
23
- labels = fastremap.refit(labels, value=-35) # resize the data type to fit the value provided
24
-
25
- # remap all occurances of 1 -> 2
26
- labels = fastremap.remap(labels, { 1: 2 }, preserve_missing_labels=True, in_place=True)
27
-
28
- labels = fastremap.mask(labels, [1,5,13]) # set all occurances of 1,5,13 to 0
29
- labels = fastremap.mask_except(labels, [1,5,13]) # set all labels except 1,5,13 to 0
30
-
31
- mapping = fastremap.component_map([ 1, 2, 3, 4 ], [ 5, 5, 6, 7 ]) # { 1: 5, 2: 5, 3: 6, 4: 7 }
32
- mapping = fastremap.inverse_component_map([ 1, 2, 1, 3 ], [ 4, 4, 5, 6 ]) # { 1: [ 4, 5 ], 2: [ 4 ], 3: [ 6 ] }
33
-
34
- fastremap.transpose(labels) # physically transpose labels in-place
35
- fastremap.ascontiguousarray(labels) # try to perform a physical in-place transposition to C order
36
- fastremap.asfortranarray(labels) # try to perform a physical in-place transposition to F order
37
-
38
- minval, maxval = fastremap.minmax(labels) # faster version of (np.min(labels), np.max(labels))
39
-
40
- # computes number of matching adjacent pixel pairs in an image
41
- num_pairs = fastremap.pixel_pairs(labels)
42
- n_foreground = fastremap.foreground(labels) # number of nonzero voxels
43
-
44
- # computes the cutout.tobytes(order) of each chunk and returns
45
- # the binaries indexed by fortran order in the order specified (C or F)
46
- # If the input image is F contiguous and F is requested, or C and C order,
47
- # and the image is larger than a single chunk, this will be significantly
48
- # faster than iterating and using tobytes.
49
- binaries = fastremap.tobytes(labels, (64,64,64), order="F")
50
- ```
51
-
52
- ## All Available Functions
53
- - **unique:** Faster implementation of `np.unique`.
54
- - **renumber:** Relabel array from 1 to N which can often use smaller datatypes.
55
- - **remap:** Custom relabeling of values in an array from a dictionary.
56
- - **refit:** Resize the data type of an array to the smallest that can contain the most extreme values in it.
57
- - **mask:** Zero out labels in an array specified by a given list.
58
- - **mask_except**: Zero out all labels except those specified in a given list.
59
- - **component_map**: Extract an int-to-int dictionary mapping of labels from one image containing component labels to another parent labels.
60
- - **inverse_component_map**: Extract an int-to-list-of-ints dictionary mapping from an image containing groups of components to an image containing the components.
61
- - **remap_from_array:** Same as remap, but the map is an array where the key is the array index and the value is the value.
62
- - **remap_from_array_kv:** Same as remap, but the map consists of two equal sized arrays, the first containing keys, the second containing values.
63
- - **asfortranarray:** Perform an in-place matrix transposition for rectangular arrays if memory is contiguous, standard numpy otherwise.
64
- - **ascontiguousarray:** Perform an in-place matrix transposition for rectangular arrays if memory is contiguous, standard numpy algorithm otherwise.
65
- - **minmax:** Compute the min and max of an array in one pass.
66
- - **pixel_pairs:** Computes the number of adjacent matching memory locations in an image. A quick heuristic for understanding if the image statistics are roughly similar to a connectomics segmentation.
67
- - **foreground:** Count the number of non-zero voxels rapidly.
68
- - **point_cloud:** Get the X,Y,Z locations of each foreground voxel grouped by label.
69
- - **tobytes**: Compute the tobytes of an image divided into a grid and return the resultant binaries indexed by their gridpoint in fortran order with the binary in the order requested (C or F).
70
-
71
- ## `pip` Installation
72
-
73
- ```bash
74
- pip install fastremap
75
- ```
76
-
77
- *If not, a C++ compiler is required.*
78
-
79
- ```bash
80
- pip install numpy
81
- pip install fastremap --no-binary :all:
82
- ```
83
-
84
- ## Manual Installation
85
-
86
- *A C++ compiler is required.*
87
-
88
- ```bash
89
- sudo apt-get install g++ python3-dev
90
- mkvirtualenv -p python3 fastremap
91
- pip install numpy
92
-
93
- # Choose one:
94
- python setup.py develop
95
- python setup.py install
96
- ```
97
-
98
- ## The Problem of Remapping
99
-
100
- Python loops are slow, so Numpy is often used to perform remapping on large arrays (hundreds of megabytes or gigabytes). In order to efficiently remap an array in Numpy you need a key-value array where the index is the key and the value is the contents of that index.
101
-
102
- ```python
103
- import numpy as np
104
-
105
- original = np.array([ 1, 3, 5, 5, 10 ])
106
- remap = np.array([ 0, -5, 0, 6, 0, 0, 2, 0, 0, 0, -100 ])
107
- # Keys: 0 1 2 3 4 5 6 7 8 9 10
108
-
109
- remapped = remap[ original ]
110
- >>> [ -5, 6, 2, 2, -100 ]
111
- ```
112
-
113
- If there are 32 or 64 bit labels in the array, this becomes impractical as the size of the array can grow larger than RAM. Therefore, it would be helpful to be able to perform this mapping using a C speed loop. Numba can be used for this in some circumstances. However, this library provides an alternative.
114
-
115
- ```python
116
- import numpy as np
117
- import fastremap
118
-
119
- mappings = {
120
- 1: 100,
121
- 2: 200,
122
- -3: 7,
123
- }
124
-
125
- arr = np.array([5, 1, 2, -5, -3, 10, 6])
126
- # Custom remapping of -3, 5, and 6 leaving the rest alone
127
- arr = fastremap.remap(arr, mappings, preserve_missing_labels=True)
128
- # result: [ 5, 100, 200, -5, 7, 10, 6 ]
129
- ```
130
-
131
- ## The Problem of Renumbering
132
-
133
- Sometimes a 64-bit array contains values that could be represented by an 8-bit array. However, similarly to the remapping problem, Python loops can be too slow to do this. Numpy doesn't provide a convenient way to do it either. Therefore this library provides an alternative solution.
134
-
135
- ```python
136
- import fastremap
137
- import numpy as np
138
-
139
- arr = np.array([ 283732875, 439238823, 283732875, 182812404, 0 ], dtype=np.int64)
140
-
141
- arr, remapping = fastremap.renumber(arr, preserve_zero=True) # Returns uint8 array
142
- >>> arr = [ 1, 2, 1, 3, 0 ]
143
- >>> remapping = { 0: 0, 283732875: 1, 439238823: 2, 182812404: 3 }
144
-
145
- arr, remapping = fastremap.renumber(arr, preserve_zero=False) # Returns uint8 array
146
- >>> arr = [ 1, 2, 1, 3, 4 ]
147
- >>> remapping = { 0: 4, 283732875: 1, 439238823: 2, 182812404: 3 }
148
-
149
- arr, remapping = fastremap.renumber(arr, preserve_zero=False, in_place=True) # Mutate arr to use less memory
150
- >>> arr = [ 1, 2, 1, 3, 4 ]
151
- >>> remapping = { 0: 4, 283732875: 1, 439238823: 2, 182812404: 3 }
152
- ```
153
-
154
- ## The Problem of In-Place Transposition
155
-
156
- When transitioning between different media, e.g. CPU to GPU, CPU to Network, CPU to disk, it's often necessary to physically transpose multi-dimensional arrays to reformat as C or Fortran order. Tranposing matrices is also a common action in linear algebra, but often you can get away with just changing the strides.
157
-
158
- An out-of-place transposition is easy to write, and often faster, but it will spike peak memory consumption. This library grants the user the option of performing an in-place transposition which trades CPU time for peak memory usage. In the special case of square or cubic arrays, the in-place transpisition is both lower memory and faster.
159
-
160
- - **fastremap.asfortranarray:** Same as np.asfortranarray but will perform the transposition in-place for 1, 2, 3, and 4D arrays. 2D and 3D square matrices are faster to process than with Numpy.
161
- - **fastremap.ascontiguousarray:** Same as np.ascontiguousarray but will perform the transposition in-place for 1, 2, 3, and 4D arrays. 2D and 3D square matrices are faster to process than with Numpy.
162
-
163
- ```python
164
- import fastremap
165
- import numpy as np
166
-
167
- arr = np.ones((512,512,512), dtype=np.float32)
168
- arr = fastremap.asfortranarray(x)
169
-
170
- arr = np.ones((512,512,512), dtype=np.float32, order='F')
171
- arr = fastremap.ascontiguousarray(x)
172
- ```
173
-
174
- ## C++ Usage
175
-
176
- The in-place matrix transposition is implemented in ipt.hpp. If you're working in C++, you can also use it directly like so:
177
-
178
- ```cpp
179
- #include "ipt.hpp"
180
-
181
- int main() {
182
-
183
- int sx = 128;
184
- int sy = 124;
185
- int sz = 103;
186
- int sw = 3;
187
-
188
- auto* arr = ....;
189
-
190
- // All primitive number types supported
191
- // The array will be modified in place,
192
- // so these functions are void type.
193
- ipt::ipt<int>(arr, sx, sy); // 2D
194
- ipt::ipt<float>(arr, sx, sy, sz); // 3D
195
- ipt::ipt<double>(arr, sx, sy, sz, sw); // 4D
196
-
197
- return 0;
198
- }
199
- ```
200
-
201
- --
202
- Made with <3
203
-
204
-
205
- Platform: UNKNOWN
206
- Classifier: Intended Audience :: Developers
207
- Classifier: Development Status :: 5 - Production/Stable
208
- Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
209
- Classifier: Programming Language :: Python
210
- Classifier: Programming Language :: Python :: 3
211
- Classifier: Programming Language :: Python :: 3.7
212
- Classifier: Programming Language :: Python :: 3.8
213
- Classifier: Programming Language :: Python :: 3.9
214
- Classifier: Programming Language :: Python :: 3.10
215
- Classifier: Programming Language :: Python :: 3.11
216
- Classifier: Topic :: Utilities
217
- Requires-Python: >=3.8,<4.0
218
- Description-Content-Type: text/markdown
@@ -1 +0,0 @@
1
- {"git_version": "0ea7a0b", "is_release": true}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes