fastremap 1.15.1__cp313-cp313-win_amd64.whl

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.
@@ -0,0 +1 @@
1
+ William Silversmith <william.silversmith@gmail.com>
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -0,0 +1,219 @@
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
+ 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.8,<4.0
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ License-File: AUTHORS
23
+ Requires-Dist: numpy
24
+
25
+ [![PyPI version](https://badge.fury.io/py/fastremap.svg)](https://badge.fury.io/py/fastremap)
26
+
27
+ # fastremap
28
+
29
+ Renumber and relabel Numpy arrays at C++ speed and physically convert rectangular Numpy arrays between C and Fortran order using an in-place transposition.
30
+
31
+ ```python
32
+ import fastremap
33
+
34
+ uniq, cts = fastremap.unique(labels, return_counts=True) # may be much faster than np.unique
35
+ labels, remapping = fastremap.renumber(labels, in_place=True) # relabel values from 1 and refit data type
36
+ ptc = fastremap.point_cloud(labels) # dict of coordinates by label
37
+
38
+ labels = fastremap.refit(labels) # resize the data type of the array to fit extrema
39
+ labels = fastremap.refit(labels, value=-35) # resize the data type to fit the value provided
40
+
41
+ # remap all occurances of 1 -> 2
42
+ labels = fastremap.remap(labels, { 1: 2 }, preserve_missing_labels=True, in_place=True)
43
+
44
+ labels = fastremap.mask(labels, [1,5,13]) # set all occurances of 1,5,13 to 0
45
+ labels = fastremap.mask_except(labels, [1,5,13]) # set all labels except 1,5,13 to 0
46
+
47
+ mapping = fastremap.component_map([ 1, 2, 3, 4 ], [ 5, 5, 6, 7 ]) # { 1: 5, 2: 5, 3: 6, 4: 7 }
48
+ mapping = fastremap.inverse_component_map([ 1, 2, 1, 3 ], [ 4, 4, 5, 6 ]) # { 1: [ 4, 5 ], 2: [ 4 ], 3: [ 6 ] }
49
+
50
+ fastremap.transpose(labels) # physically transpose labels in-place
51
+ fastremap.ascontiguousarray(labels) # try to perform a physical in-place transposition to C order
52
+ fastremap.asfortranarray(labels) # try to perform a physical in-place transposition to F order
53
+
54
+ minval, maxval = fastremap.minmax(labels) # faster version of (np.min(labels), np.max(labels))
55
+
56
+ # computes number of matching adjacent pixel pairs in an image
57
+ num_pairs = fastremap.pixel_pairs(labels)
58
+ n_foreground = fastremap.foreground(labels) # number of nonzero voxels
59
+
60
+ # computes the cutout.tobytes(order) of each chunk and returns
61
+ # the binaries indexed by fortran order in the order specified (C or F)
62
+ # If the input image is F contiguous and F is requested, or C and C order,
63
+ # and the image is larger than a single chunk, this will be significantly
64
+ # faster than iterating and using tobytes.
65
+ binaries = fastremap.tobytes(labels, (64,64,64), order="F")
66
+ ```
67
+
68
+ ## All Available Functions
69
+ - **unique:** Faster implementation of `np.unique`.
70
+ - **renumber:** Relabel array from 1 to N which can often use smaller datatypes.
71
+ - **remap:** Custom relabeling of values in an array from a dictionary.
72
+ - **refit:** Resize the data type of an array to the smallest that can contain the most extreme values in it.
73
+ - **mask:** Zero out labels in an array specified by a given list.
74
+ - **mask_except**: Zero out all labels except those specified in a given list.
75
+ - **component_map**: Extract an int-to-int dictionary mapping of labels from one image containing component labels to another parent labels.
76
+ - **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.
77
+ - **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.
78
+ - **remap_from_array_kv:** Same as remap, but the map consists of two equal sized arrays, the first containing keys, the second containing values.
79
+ - **asfortranarray:** Perform an in-place matrix transposition for rectangular arrays if memory is contiguous, standard numpy otherwise.
80
+ - **ascontiguousarray:** Perform an in-place matrix transposition for rectangular arrays if memory is contiguous, standard numpy algorithm otherwise.
81
+ - **minmax:** Compute the min and max of an array in one pass.
82
+ - **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.
83
+ - **foreground:** Count the number of non-zero voxels rapidly.
84
+ - **point_cloud:** Get the X,Y,Z locations of each foreground voxel grouped by label.
85
+ - **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).
86
+
87
+ ## `pip` Installation
88
+
89
+ ```bash
90
+ pip install fastremap
91
+ ```
92
+
93
+ *If not, a C++ compiler is required.*
94
+
95
+ ```bash
96
+ pip install numpy
97
+ pip install fastremap --no-binary :all:
98
+ ```
99
+
100
+ ## Manual Installation
101
+
102
+ *A C++ compiler is required.*
103
+
104
+ ```bash
105
+ sudo apt-get install g++ python3-dev
106
+ mkvirtualenv -p python3 fastremap
107
+ pip install numpy
108
+
109
+ # Choose one:
110
+ python setup.py develop
111
+ python setup.py install
112
+ ```
113
+
114
+ ## The Problem of Remapping
115
+
116
+ 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.
117
+
118
+ ```python
119
+ import numpy as np
120
+
121
+ original = np.array([ 1, 3, 5, 5, 10 ])
122
+ remap = np.array([ 0, -5, 0, 6, 0, 0, 2, 0, 0, 0, -100 ])
123
+ # Keys: 0 1 2 3 4 5 6 7 8 9 10
124
+
125
+ remapped = remap[ original ]
126
+ >>> [ -5, 6, 2, 2, -100 ]
127
+ ```
128
+
129
+ 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.
130
+
131
+ ```python
132
+ import numpy as np
133
+ import fastremap
134
+
135
+ mappings = {
136
+ 1: 100,
137
+ 2: 200,
138
+ -3: 7,
139
+ }
140
+
141
+ arr = np.array([5, 1, 2, -5, -3, 10, 6])
142
+ # Custom remapping of -3, 5, and 6 leaving the rest alone
143
+ arr = fastremap.remap(arr, mappings, preserve_missing_labels=True)
144
+ # result: [ 5, 100, 200, -5, 7, 10, 6 ]
145
+ ```
146
+
147
+ ## The Problem of Renumbering
148
+
149
+ 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.
150
+
151
+ ```python
152
+ import fastremap
153
+ import numpy as np
154
+
155
+ arr = np.array([ 283732875, 439238823, 283732875, 182812404, 0 ], dtype=np.int64)
156
+
157
+ arr, remapping = fastremap.renumber(arr, preserve_zero=True) # Returns uint8 array
158
+ >>> arr = [ 1, 2, 1, 3, 0 ]
159
+ >>> remapping = { 0: 0, 283732875: 1, 439238823: 2, 182812404: 3 }
160
+
161
+ arr, remapping = fastremap.renumber(arr, preserve_zero=False) # Returns uint8 array
162
+ >>> arr = [ 1, 2, 1, 3, 4 ]
163
+ >>> remapping = { 0: 4, 283732875: 1, 439238823: 2, 182812404: 3 }
164
+
165
+ arr, remapping = fastremap.renumber(arr, preserve_zero=False, in_place=True) # Mutate arr to use less memory
166
+ >>> arr = [ 1, 2, 1, 3, 4 ]
167
+ >>> remapping = { 0: 4, 283732875: 1, 439238823: 2, 182812404: 3 }
168
+ ```
169
+
170
+ ## The Problem of In-Place Transposition
171
+
172
+ 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.
173
+
174
+ 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.
175
+
176
+ - **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.
177
+ - **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.
178
+
179
+ ```python
180
+ import fastremap
181
+ import numpy as np
182
+
183
+ arr = np.ones((512,512,512), dtype=np.float32)
184
+ arr = fastremap.asfortranarray(x)
185
+
186
+ arr = np.ones((512,512,512), dtype=np.float32, order='F')
187
+ arr = fastremap.ascontiguousarray(x)
188
+ ```
189
+
190
+ ## C++ Usage
191
+
192
+ The in-place matrix transposition is implemented in ipt.hpp. If you're working in C++, you can also use it directly like so:
193
+
194
+ ```cpp
195
+ #include "ipt.hpp"
196
+
197
+ int main() {
198
+
199
+ int sx = 128;
200
+ int sy = 124;
201
+ int sz = 103;
202
+ int sw = 3;
203
+
204
+ auto* arr = ....;
205
+
206
+ // All primitive number types supported
207
+ // The array will be modified in place,
208
+ // so these functions are void type.
209
+ ipt::ipt<int>(arr, sx, sy); // 2D
210
+ ipt::ipt<float>(arr, sx, sy, sz); // 3D
211
+ ipt::ipt<double>(arr, sx, sy, sz, sw); // 4D
212
+
213
+ return 0;
214
+ }
215
+ ```
216
+
217
+ --
218
+ Made with <3
219
+
@@ -0,0 +1,8 @@
1
+ fastremap.cp313-win_amd64.pyd,sha256=cPpkTdSXK5Db0O2GYtgiNWKEPP6S2bNPNJv9doFC43g,2019328
2
+ fastremap-1.15.1.dist-info/AUTHORS,sha256=Aa4H7O3dtmfq0lF_eATudy11i8K6QAI8LykzASr9bL0,52
3
+ fastremap-1.15.1.dist-info/LICENSE,sha256=fTqV5eBpeAZO0_jit8j4Ref9ikBSlHJ8xwj5TLg7gFk,7817
4
+ fastremap-1.15.1.dist-info/METADATA,sha256=DvzvncVVaEkyycdFVxxnfkLui-Nv4EwJ8MzhTjvwIr0,9780
5
+ fastremap-1.15.1.dist-info/WHEEL,sha256=4-iQBlRoDdX1wfPofc7KLWa5Cys4eZSgXs6GVU8fKlQ,101
6
+ fastremap-1.15.1.dist-info/pbr.json,sha256=b77m2uoyXaN-c7-BVxEmFd75JW-Qj02KkOHiAhpnJgk,47
7
+ fastremap-1.15.1.dist-info/top_level.txt,sha256=D-q4-YJbbk7QpuU8fxH9rFQEjV_W6wpdruzTTDV4N5s,10
8
+ fastremap-1.15.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.6.0)
3
+ Root-Is-Purelib: false
4
+ Tag: cp313-cp313-win_amd64
5
+
@@ -0,0 +1 @@
1
+ {"git_version": "0ea7a0b", "is_release": false}
@@ -0,0 +1 @@
1
+ fastremap
Binary file