pytme 0.2.0b0__cp311-cp311-macosx_14_0_arm64.whl → 0.2.2__cp311-cp311-macosx_14_0_arm64.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.
- pytme-0.2.2.data/scripts/match_template.py +1187 -0
- {pytme-0.2.0b0.data → pytme-0.2.2.data}/scripts/postprocess.py +170 -71
- {pytme-0.2.0b0.data → pytme-0.2.2.data}/scripts/preprocessor_gui.py +179 -86
- pytme-0.2.2.dist-info/METADATA +91 -0
- pytme-0.2.2.dist-info/RECORD +74 -0
- {pytme-0.2.0b0.dist-info → pytme-0.2.2.dist-info}/WHEEL +1 -1
- scripts/extract_candidates.py +126 -87
- scripts/match_template.py +596 -209
- scripts/match_template_filters.py +571 -223
- scripts/postprocess.py +170 -71
- scripts/preprocessor_gui.py +179 -86
- scripts/refine_matches.py +567 -159
- tme/__init__.py +0 -1
- tme/__version__.py +1 -1
- tme/analyzer.py +627 -855
- tme/backends/__init__.py +41 -11
- tme/backends/_jax_utils.py +185 -0
- tme/backends/cupy_backend.py +120 -225
- tme/backends/jax_backend.py +282 -0
- tme/backends/matching_backend.py +464 -388
- tme/backends/mlx_backend.py +45 -68
- tme/backends/npfftw_backend.py +256 -514
- tme/backends/pytorch_backend.py +41 -154
- tme/density.py +312 -421
- tme/extensions.cpython-311-darwin.so +0 -0
- tme/matching_data.py +366 -303
- tme/matching_exhaustive.py +279 -1521
- tme/matching_optimization.py +234 -129
- tme/matching_scores.py +884 -0
- tme/matching_utils.py +281 -387
- tme/memory.py +377 -0
- tme/orientations.py +226 -66
- tme/parser.py +3 -4
- tme/preprocessing/__init__.py +2 -0
- tme/preprocessing/_utils.py +217 -0
- tme/preprocessing/composable_filter.py +31 -0
- tme/preprocessing/compose.py +55 -0
- tme/preprocessing/frequency_filters.py +388 -0
- tme/preprocessing/tilt_series.py +1011 -0
- tme/preprocessor.py +574 -530
- tme/structure.py +495 -189
- tme/types.py +5 -3
- pytme-0.2.0b0.data/scripts/match_template.py +0 -800
- pytme-0.2.0b0.dist-info/METADATA +0 -73
- pytme-0.2.0b0.dist-info/RECORD +0 -66
- tme/helpers.py +0 -881
- tme/matching_constrained.py +0 -195
- {pytme-0.2.0b0.data → pytme-0.2.2.data}/scripts/estimate_ram_usage.py +0 -0
- {pytme-0.2.0b0.data → pytme-0.2.2.data}/scripts/preprocess.py +0 -0
- {pytme-0.2.0b0.dist-info → pytme-0.2.2.dist-info}/LICENSE +0 -0
- {pytme-0.2.0b0.dist-info → pytme-0.2.2.dist-info}/entry_points.txt +0 -0
- {pytme-0.2.0b0.dist-info → pytme-0.2.2.dist-info}/top_level.txt +0 -0
tme/backends/matching_backend.py
CHANGED
@@ -6,11 +6,22 @@
|
|
6
6
|
"""
|
7
7
|
|
8
8
|
from abc import ABC, abstractmethod
|
9
|
-
from typing import Tuple, Callable, List
|
10
9
|
from multiprocessing import shared_memory
|
10
|
+
from typing import Tuple, Callable, List, Any, Union, Optional, Generator
|
11
11
|
|
12
|
-
from
|
13
|
-
|
12
|
+
from ..types import BackendArray, NDArray, Scalar, shm_type
|
13
|
+
|
14
|
+
|
15
|
+
def _create_metafunction(func_name: str) -> Callable:
|
16
|
+
"""
|
17
|
+
Returns a wrapper of ``self._array_backend.func_name``.
|
18
|
+
"""
|
19
|
+
|
20
|
+
def metafunction(self, *args, **kwargs) -> Any:
|
21
|
+
backend_func = getattr(self._array_backend, func_name)
|
22
|
+
return backend_func(*args, **kwargs)
|
23
|
+
|
24
|
+
return metafunction
|
14
25
|
|
15
26
|
|
16
27
|
class MatchingBackend(ABC):
|
@@ -29,54 +40,69 @@ class MatchingBackend(ABC):
|
|
29
40
|
----------
|
30
41
|
array_backend : object
|
31
42
|
The backend object providing array functionalities.
|
32
|
-
|
33
|
-
Data type of
|
43
|
+
float_dtype : type
|
44
|
+
Data type of float array instances, e.g. np.float32.
|
34
45
|
complex_dtype : type
|
35
46
|
Data type of complex array instances, e.g. np.complex64.
|
36
|
-
|
47
|
+
int_dtype : type
|
37
48
|
Data type of integer array instances, e.g. np.int32.
|
49
|
+
overflow_safe_dtype : type
|
50
|
+
Data type than can be used in reduction operations to avoid overflows.
|
38
51
|
|
39
52
|
Attributes
|
40
53
|
----------
|
41
54
|
_array_backend : object
|
42
|
-
The backend object
|
43
|
-
|
44
|
-
Data type of
|
55
|
+
The backend object providing array functionalities.
|
56
|
+
_float_dtype : type
|
57
|
+
Data type of float array instances, e.g. np.float32.
|
45
58
|
_complex_dtype : type
|
46
59
|
Data type of complex array instances, e.g. np.complex64.
|
47
|
-
|
60
|
+
_int_dtype : type
|
48
61
|
Data type of integer array instances, e.g. np.int32.
|
62
|
+
_overflow_safe_dtype : type
|
63
|
+
Data type than can be used in reduction operations to avoid overflows.
|
64
|
+
_fundamental_dtypes : Dict
|
65
|
+
Maps int, float and cmoplex python types to backend specific data types.
|
49
66
|
|
50
67
|
Examples
|
51
68
|
--------
|
52
69
|
>>> import numpy as np
|
53
|
-
>>>
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
70
|
+
>>> from tme.backends import NumpyFFTWBackend
|
71
|
+
>>> backend = NumpyFFTWBackend(
|
72
|
+
>>> array_backend=np,
|
73
|
+
>>> float_dtype=np.float32,
|
74
|
+
>>> complex_dtype=np.complex64,
|
75
|
+
>>> int_dtype=np.int32
|
76
|
+
>>> )
|
59
77
|
>>> arr = backend.array([1, 2, 3])
|
60
78
|
>>> print(arr)
|
61
79
|
[1 2 3]
|
62
80
|
|
63
81
|
Notes
|
64
82
|
-----
|
65
|
-
|
66
|
-
|
83
|
+
Developers should be aware of potential naming conflicts between methods and
|
84
|
+
attributes of this class and those of the provided backend.
|
67
85
|
"""
|
68
86
|
|
69
87
|
def __init__(
|
70
88
|
self,
|
71
89
|
array_backend,
|
72
|
-
|
90
|
+
float_dtype: type,
|
73
91
|
complex_dtype: type,
|
74
|
-
|
92
|
+
int_dtype: type,
|
93
|
+
overflow_safe_dtype: type,
|
75
94
|
):
|
76
95
|
self._array_backend = array_backend
|
77
|
-
self.
|
96
|
+
self._float_dtype = float_dtype
|
78
97
|
self._complex_dtype = complex_dtype
|
79
|
-
self.
|
98
|
+
self._int_dtype = int_dtype
|
99
|
+
self._overflow_safe_dtype = overflow_safe_dtype
|
100
|
+
|
101
|
+
self._fundamental_dtypes = {
|
102
|
+
int: self._int_dtype,
|
103
|
+
float: self._float_dtype,
|
104
|
+
complex: self._complex_dtype,
|
105
|
+
}
|
80
106
|
|
81
107
|
def __getattr__(self, name: str):
|
82
108
|
"""
|
@@ -115,27 +141,8 @@ class MatchingBackend(ABC):
|
|
115
141
|
base_attributes.extend(dir(self._array_backend))
|
116
142
|
return sorted(base_attributes)
|
117
143
|
|
118
|
-
@staticmethod
|
119
|
-
def free_sharedarr(link: shared_memory.SharedMemory):
|
120
|
-
"""
|
121
|
-
Free shared array at link.
|
122
|
-
|
123
|
-
Parameters
|
124
|
-
----------
|
125
|
-
link : shared_memory.SharedMemory
|
126
|
-
The shared memory link to be freed.
|
127
|
-
"""
|
128
|
-
if type(link) is not shared_memory.SharedMemory:
|
129
|
-
return None
|
130
|
-
try:
|
131
|
-
link.close()
|
132
|
-
link.unlink()
|
133
|
-
# Shared memory has been freed already
|
134
|
-
except FileNotFoundError:
|
135
|
-
pass
|
136
|
-
|
137
144
|
@abstractmethod
|
138
|
-
def to_backend_array(self, arr: NDArray) ->
|
145
|
+
def to_backend_array(self, arr: NDArray) -> BackendArray:
|
139
146
|
"""
|
140
147
|
Convert a numpy array instance to backend array type.
|
141
148
|
|
@@ -146,7 +153,7 @@ class MatchingBackend(ABC):
|
|
146
153
|
|
147
154
|
Returns
|
148
155
|
-------
|
149
|
-
|
156
|
+
BackendArray
|
150
157
|
An array of the specified backend.
|
151
158
|
|
152
159
|
See Also
|
@@ -156,13 +163,13 @@ class MatchingBackend(ABC):
|
|
156
163
|
"""
|
157
164
|
|
158
165
|
@abstractmethod
|
159
|
-
def to_numpy_array(self, arr:
|
166
|
+
def to_numpy_array(self, arr: BackendArray) -> NDArray:
|
160
167
|
"""
|
161
168
|
Convert an array of given backend to a numpy array.
|
162
169
|
|
163
170
|
Parameters
|
164
171
|
----------
|
165
|
-
arr :
|
172
|
+
arr : BackendArray
|
166
173
|
The array instance to be converted.
|
167
174
|
|
168
175
|
Returns
|
@@ -177,19 +184,19 @@ class MatchingBackend(ABC):
|
|
177
184
|
"""
|
178
185
|
|
179
186
|
@abstractmethod
|
180
|
-
def to_cpu_array(self, arr:
|
187
|
+
def to_cpu_array(self, arr: BackendArray) -> BackendArray:
|
181
188
|
"""
|
182
189
|
Convert an array of a given backend to a CPU array of that backend.
|
183
190
|
|
184
191
|
Parameters
|
185
192
|
----------
|
186
|
-
arr :
|
193
|
+
arr : BackendArray
|
187
194
|
The array instance to be converted.
|
188
195
|
|
189
196
|
Returns
|
190
197
|
-------
|
191
|
-
|
192
|
-
The
|
198
|
+
BackendArray
|
199
|
+
The CPU array equivalent of arr.
|
193
200
|
|
194
201
|
See Also
|
195
202
|
--------
|
@@ -197,6 +204,22 @@ class MatchingBackend(ABC):
|
|
197
204
|
:py:meth:`MatchingBackend.to_backend_array`
|
198
205
|
"""
|
199
206
|
|
207
|
+
def get_fundamental_dtype(self, arr: BackendArray) -> type:
|
208
|
+
"""
|
209
|
+
Given an array instance, returns the corresponding fundamental python type,
|
210
|
+
i.e., int, float or complex.
|
211
|
+
|
212
|
+
Parameters
|
213
|
+
----------
|
214
|
+
arr : BackendArray
|
215
|
+
Input data.
|
216
|
+
|
217
|
+
Returns
|
218
|
+
-------
|
219
|
+
type
|
220
|
+
Data type.
|
221
|
+
"""
|
222
|
+
|
200
223
|
@abstractmethod
|
201
224
|
def free_cache(self):
|
202
225
|
"""
|
@@ -204,428 +227,457 @@ class MatchingBackend(ABC):
|
|
204
227
|
"""
|
205
228
|
|
206
229
|
@abstractmethod
|
207
|
-
def add(
|
230
|
+
def add(
|
231
|
+
self, arr1: BackendArray, arr2: BackendArray, out: BackendArray = None
|
232
|
+
) -> BackendArray:
|
208
233
|
"""
|
209
|
-
|
234
|
+
Element-wise addition of arrays.
|
210
235
|
|
211
236
|
Parameters
|
212
237
|
----------
|
213
|
-
arr1 :
|
238
|
+
arr1 : BackendArray
|
214
239
|
Input array.
|
215
|
-
arr2 :
|
240
|
+
arr2 : BackendArray
|
216
241
|
Input array.
|
217
|
-
out :
|
218
|
-
|
219
|
-
that the inputs broadcast to.
|
242
|
+
out : BackendArray, optional
|
243
|
+
Output array to write the result to. Returns a new array by default.
|
220
244
|
|
221
245
|
Returns
|
222
246
|
-------
|
223
|
-
|
247
|
+
BackendArray
|
224
248
|
Element-wise sum of the input arrays.
|
225
249
|
"""
|
226
250
|
|
227
251
|
@abstractmethod
|
228
252
|
def subtract(
|
229
|
-
self, arr1:
|
230
|
-
) ->
|
253
|
+
self, arr1: BackendArray, arr2: BackendArray, out: BackendArray = None
|
254
|
+
) -> BackendArray:
|
231
255
|
"""
|
232
|
-
|
256
|
+
Element-wise subtraction of arrays.
|
233
257
|
|
234
258
|
Parameters
|
235
259
|
----------
|
236
|
-
arr1 :
|
260
|
+
arr1 : BackendArray
|
237
261
|
The minuend array.
|
238
|
-
arr2 :
|
262
|
+
arr2 : BackendArray
|
239
263
|
The subtrahend array.
|
240
|
-
out :
|
241
|
-
|
242
|
-
that the inputs broadcast to.
|
264
|
+
out : BackendArray, optional
|
265
|
+
Output array to write the result to. Returns a new array by default.
|
243
266
|
|
244
267
|
Returns
|
245
268
|
-------
|
246
|
-
|
269
|
+
BackendArray
|
247
270
|
Element-wise difference of the input arrays.
|
248
271
|
"""
|
249
272
|
|
250
273
|
@abstractmethod
|
251
274
|
def multiply(
|
252
|
-
self, arr1:
|
253
|
-
) ->
|
275
|
+
self, arr1: BackendArray, arr2: BackendArray, out: BackendArray = None
|
276
|
+
) -> BackendArray:
|
254
277
|
"""
|
255
|
-
|
278
|
+
Element-wise multiplication of arrays.
|
256
279
|
|
257
280
|
Parameters
|
258
281
|
----------
|
259
|
-
arr1 :
|
282
|
+
arr1 : BackendArray
|
260
283
|
Input array.
|
261
|
-
arr2 :
|
284
|
+
arr2 : BackendArray
|
262
285
|
Input array.
|
263
|
-
out :
|
264
|
-
|
265
|
-
that the inputs broadcast to.
|
286
|
+
out : BackendArray, optional
|
287
|
+
Output array to write the result to. Returns a new array by default.
|
266
288
|
|
267
289
|
Returns
|
268
290
|
-------
|
269
|
-
|
291
|
+
BackendArray
|
270
292
|
Element-wise product of the input arrays.
|
271
293
|
"""
|
272
294
|
|
273
295
|
@abstractmethod
|
274
296
|
def divide(
|
275
|
-
self, arr1:
|
276
|
-
) ->
|
297
|
+
self, arr1: BackendArray, arr2: BackendArray, out: BackendArray = None
|
298
|
+
) -> BackendArray:
|
277
299
|
"""
|
278
|
-
|
300
|
+
Element-wise division of arrays.
|
279
301
|
|
280
302
|
Parameters
|
281
303
|
----------
|
282
|
-
arr1 :
|
283
|
-
The
|
284
|
-
arr2 :
|
285
|
-
The
|
286
|
-
out :
|
287
|
-
|
288
|
-
that the inputs broadcast to.
|
304
|
+
arr1 : BackendArray
|
305
|
+
The dividend array.
|
306
|
+
arr2 : BackendArray
|
307
|
+
The divisor array.
|
308
|
+
out : BackendArray, optional
|
309
|
+
Output array to write the result to. Returns a new array by default.
|
289
310
|
|
290
311
|
Returns
|
291
312
|
-------
|
292
|
-
|
313
|
+
BackendArray
|
293
314
|
Element-wise quotient of the input arrays.
|
294
315
|
"""
|
295
316
|
|
296
317
|
@abstractmethod
|
297
|
-
def mod(
|
318
|
+
def mod(
|
319
|
+
self, arr1: BackendArray, arr2: BackendArray, out: BackendArray = None
|
320
|
+
) -> BackendArray:
|
298
321
|
"""
|
299
|
-
|
322
|
+
Element-wise modulus of arrays.
|
300
323
|
|
301
324
|
Parameters
|
302
325
|
----------
|
303
|
-
arr1 :
|
304
|
-
The
|
305
|
-
arr2 :
|
306
|
-
The
|
307
|
-
out :
|
308
|
-
|
309
|
-
that the inputs broadcast to.
|
326
|
+
arr1 : BackendArray
|
327
|
+
The dividend array.
|
328
|
+
arr2 : BackendArray
|
329
|
+
The divisor array.
|
330
|
+
out : BackendArray, optional
|
331
|
+
Output array to write the result to. Returns a new array by default.
|
310
332
|
|
311
333
|
Returns
|
312
334
|
-------
|
313
|
-
|
335
|
+
BackendArray
|
314
336
|
Element-wise modulus of the input arrays.
|
315
337
|
"""
|
316
338
|
|
317
339
|
@abstractmethod
|
318
|
-
def
|
340
|
+
def einsum(
|
341
|
+
self, arr1: BackendArray, arr2: BackendArray, out: BackendArray = None
|
342
|
+
) -> BackendArray:
|
319
343
|
"""
|
320
|
-
Compute the
|
344
|
+
Compute the einstein notation based summation.
|
321
345
|
|
322
346
|
Parameters
|
323
347
|
----------
|
324
|
-
|
325
|
-
|
348
|
+
subscripts : str
|
349
|
+
Specifies the subscripts for summation (see :obj:`numpy.einsum`).
|
350
|
+
arr1, arr2 : BackendArray
|
351
|
+
Input data.
|
352
|
+
out : BackendArray, optional
|
353
|
+
Output array to write the result to. Returns a new array by default.
|
326
354
|
|
327
355
|
Returns
|
328
356
|
-------
|
329
|
-
|
330
|
-
|
357
|
+
BackendArray
|
358
|
+
Einsum of input arrays.
|
331
359
|
"""
|
332
360
|
|
333
361
|
@abstractmethod
|
334
|
-
def
|
335
|
-
self,
|
336
|
-
) ->
|
362
|
+
def sum(
|
363
|
+
self, arr: BackendArray, axis: Tuple[int] = None
|
364
|
+
) -> Union[BackendArray, Scalar]:
|
337
365
|
"""
|
338
|
-
|
366
|
+
Compute the sum of array elements.
|
339
367
|
|
340
368
|
Parameters
|
341
369
|
----------
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
Input array.
|
347
|
-
arr2 : ArrayLike
|
348
|
-
Input array.
|
349
|
-
out : ArrayLike, optional
|
350
|
-
Optional output array to store the result. If provided, it must have a shape
|
351
|
-
that the inputs broadcast to.
|
370
|
+
arr : BackendArray
|
371
|
+
Input data.
|
372
|
+
axis : int or tuple of ints, optional
|
373
|
+
Axis or axes to perform the operation on. Default is all.
|
352
374
|
|
353
375
|
Returns
|
354
376
|
-------
|
355
|
-
|
356
|
-
|
377
|
+
Union[BackendArray, Scalar]
|
378
|
+
Sum of ``arr``.
|
357
379
|
"""
|
358
380
|
|
359
381
|
@abstractmethod
|
360
|
-
def mean(
|
382
|
+
def mean(
|
383
|
+
self, arr: BackendArray, axis: Tuple[int] = None
|
384
|
+
) -> Union[BackendArray, Scalar]:
|
361
385
|
"""
|
362
386
|
Compute the mean of array elements.
|
363
387
|
|
364
388
|
Parameters
|
365
389
|
----------
|
366
|
-
arr :
|
367
|
-
|
390
|
+
arr : BackendArray
|
391
|
+
Input data.
|
392
|
+
axis : int or tuple of ints, optional
|
393
|
+
Axis or axes to perform the operation on. Default is all.
|
368
394
|
|
369
395
|
Returns
|
370
396
|
-------
|
371
|
-
Scalar
|
372
|
-
Mean
|
397
|
+
Union[BackendArray, Scalar]
|
398
|
+
Mean of ``arr``.
|
373
399
|
"""
|
374
400
|
|
375
401
|
@abstractmethod
|
376
|
-
def std(
|
402
|
+
def std(
|
403
|
+
self, arr: BackendArray, axis: Tuple[int] = None
|
404
|
+
) -> Union[BackendArray, Scalar]:
|
377
405
|
"""
|
378
406
|
Compute the standad deviation of array elements.
|
379
407
|
|
380
408
|
Parameters
|
381
409
|
----------
|
382
|
-
arr :
|
383
|
-
|
384
|
-
axis :
|
385
|
-
Axis to perform the operation on.
|
410
|
+
arr : BackendArray
|
411
|
+
Input data.
|
412
|
+
axis : int or tuple of ints, optional
|
413
|
+
Axis or axes to perform the operation on. Default is all.
|
386
414
|
|
387
415
|
Returns
|
388
416
|
-------
|
389
|
-
Scalar
|
390
|
-
|
417
|
+
Union[BackendArray, Scalar]
|
418
|
+
Standard deviation of ``arr``.
|
391
419
|
"""
|
392
420
|
|
393
421
|
@abstractmethod
|
394
|
-
def max(
|
422
|
+
def max(
|
423
|
+
self, arr: BackendArray, axis: Tuple[int] = None
|
424
|
+
) -> Union[BackendArray, Scalar]:
|
395
425
|
"""
|
396
426
|
Compute the maximum of array elements.
|
397
427
|
|
398
428
|
Parameters
|
399
429
|
----------
|
400
|
-
arr :
|
401
|
-
|
430
|
+
arr : BackendArray
|
431
|
+
Input data.
|
432
|
+
axis : int or tuple of ints, optional
|
433
|
+
Axis or axes to perform the operation on. Default is all.
|
402
434
|
|
403
435
|
Returns
|
404
436
|
-------
|
405
|
-
Scalar
|
406
|
-
|
437
|
+
Union[BackendArray, Scalar]
|
438
|
+
Maximum of ``arr``.
|
407
439
|
"""
|
408
440
|
|
409
441
|
@abstractmethod
|
410
|
-
def min(
|
442
|
+
def min(
|
443
|
+
self, arr: BackendArray, axis: Tuple[int] = None
|
444
|
+
) -> Union[BackendArray, Scalar]:
|
411
445
|
"""
|
412
446
|
Compute the minimum of array elements.
|
413
447
|
|
414
448
|
Parameters
|
415
449
|
----------
|
416
|
-
arr :
|
417
|
-
|
450
|
+
arr : BackendArray
|
451
|
+
Input data.
|
452
|
+
axis : int or tuple of ints, optional
|
453
|
+
Axis or axes to perform the operation on. Default is all.
|
418
454
|
|
419
455
|
Returns
|
420
456
|
-------
|
421
|
-
Scalar
|
422
|
-
|
457
|
+
Union[BackendArray, Scalar]
|
458
|
+
Minimum of ``arr``.
|
423
459
|
"""
|
424
460
|
|
425
461
|
@abstractmethod
|
426
462
|
def maximum(
|
427
|
-
self, arr1:
|
428
|
-
) ->
|
463
|
+
self, arr1: BackendArray, arr2: BackendArray, out: BackendArray = None
|
464
|
+
) -> BackendArray:
|
429
465
|
"""
|
430
466
|
Compute the element wise maximum of arr1 and arr2.
|
431
467
|
|
432
468
|
Parameters
|
433
469
|
----------
|
434
|
-
arr1, arr2 :
|
435
|
-
|
436
|
-
out :
|
437
|
-
Output array.
|
470
|
+
arr1, arr2 : BackendArray
|
471
|
+
Input data.
|
472
|
+
out : BackendArray, optional
|
473
|
+
Output array to write the result to. Returns a new array by default.
|
438
474
|
|
439
475
|
Returns
|
440
476
|
-------
|
441
|
-
|
442
|
-
Element wise maximum of arr1 and arr2
|
477
|
+
BackendArray
|
478
|
+
Element wise maximum of ``arr1`` and ``arr2``.
|
443
479
|
"""
|
444
480
|
|
445
481
|
@abstractmethod
|
446
482
|
def minimum(
|
447
|
-
self, arr1:
|
448
|
-
) ->
|
483
|
+
self, arr1: BackendArray, arr2: BackendArray, out: BackendArray = None
|
484
|
+
) -> BackendArray:
|
449
485
|
"""
|
450
486
|
Compute the element wise minimum of arr1 and arr2.
|
451
487
|
|
452
488
|
Parameters
|
453
489
|
----------
|
454
|
-
arr1, arr2 :
|
455
|
-
|
456
|
-
out :
|
457
|
-
Output array.
|
490
|
+
arr1, arr2 : BackendArray
|
491
|
+
Input data.
|
492
|
+
out : BackendArray, optional
|
493
|
+
Output array to write the result to. Returns a new array by default.
|
458
494
|
|
459
495
|
Returns
|
460
496
|
-------
|
461
|
-
|
497
|
+
BackendArray
|
462
498
|
Element wise minimum of arr1 and arr2.
|
463
499
|
"""
|
464
500
|
|
465
501
|
@abstractmethod
|
466
|
-
def sqrt(self, arr:
|
502
|
+
def sqrt(self, arr: BackendArray, out: BackendArray = None) -> BackendArray:
|
467
503
|
"""
|
468
504
|
Compute the square root of array elements.
|
469
505
|
|
470
506
|
Parameters
|
471
507
|
----------
|
472
|
-
arr :
|
473
|
-
|
508
|
+
arr : BackendArray
|
509
|
+
Input data.
|
510
|
+
out : BackendArray, optional
|
511
|
+
Output array to write the result to. Returns a new array by default.
|
474
512
|
|
475
513
|
Returns
|
476
514
|
-------
|
477
|
-
|
478
|
-
|
515
|
+
BackendArray
|
516
|
+
Square root of ``arr``.
|
479
517
|
"""
|
480
518
|
|
481
519
|
@abstractmethod
|
482
|
-
def square(self, arr:
|
520
|
+
def square(self, arr: BackendArray, out: BackendArray = None) -> BackendArray:
|
483
521
|
"""
|
484
522
|
Compute the square of array elements.
|
485
523
|
|
486
524
|
Parameters
|
487
525
|
----------
|
488
|
-
arr :
|
489
|
-
|
526
|
+
arr : BackendArray
|
527
|
+
Input data.
|
528
|
+
out : BackendArray, optional
|
529
|
+
Output array to write the result to. Returns a new array by default.
|
490
530
|
|
491
531
|
Returns
|
492
532
|
-------
|
493
|
-
|
494
|
-
|
533
|
+
BackendArray
|
534
|
+
Square of ``arr``.
|
495
535
|
"""
|
496
536
|
|
497
537
|
@abstractmethod
|
498
|
-
def abs(self, arr:
|
538
|
+
def abs(self, arr: BackendArray, out: BackendArray = None) -> BackendArray:
|
499
539
|
"""
|
500
540
|
Compute the absolute of array elements.
|
501
541
|
|
502
542
|
Parameters
|
503
543
|
----------
|
504
|
-
arr :
|
505
|
-
|
544
|
+
arr : BackendArray
|
545
|
+
Input data.
|
546
|
+
out : BackendArray, optional
|
547
|
+
Output array to write the result to. Returns a new array by default.
|
506
548
|
|
507
549
|
Returns
|
508
550
|
-------
|
509
|
-
|
510
|
-
|
551
|
+
BackendArray
|
552
|
+
Absolute value of ``arr``.
|
511
553
|
"""
|
512
554
|
|
513
555
|
@abstractmethod
|
514
|
-
def transpose(self, arr:
|
556
|
+
def transpose(self, arr: BackendArray) -> BackendArray:
|
515
557
|
"""
|
516
558
|
Compute the transpose of arr.
|
517
559
|
|
518
560
|
Parameters
|
519
561
|
----------
|
520
|
-
arr :
|
521
|
-
Input
|
562
|
+
arr : BackendArray
|
563
|
+
Input data.
|
522
564
|
|
523
565
|
Returns
|
524
566
|
-------
|
525
|
-
|
526
|
-
|
567
|
+
BackendArray
|
568
|
+
Transpose of ``arr``.
|
527
569
|
"""
|
528
570
|
|
529
|
-
def power(
|
571
|
+
def power(
|
572
|
+
self,
|
573
|
+
arr: BackendArray = None,
|
574
|
+
power: BackendArray = None,
|
575
|
+
out: BackendArray = None,
|
576
|
+
*args,
|
577
|
+
**kwargs,
|
578
|
+
) -> BackendArray:
|
530
579
|
"""
|
531
580
|
Compute the n-th power of an array.
|
532
581
|
|
582
|
+
Parameters
|
583
|
+
----------
|
584
|
+
arr : BackendArray
|
585
|
+
Input data.
|
586
|
+
power : BackendArray
|
587
|
+
Power to raise ``arr`` to.
|
588
|
+
arr : BackendArray
|
589
|
+
Output array to write the result to. Returns a new array by default.
|
590
|
+
|
533
591
|
Returns
|
534
592
|
-------
|
535
|
-
|
536
|
-
|
593
|
+
BackendArray
|
594
|
+
N-th power of ``arr``.
|
537
595
|
"""
|
538
596
|
|
539
|
-
def tobytes(self, arr:
|
597
|
+
def tobytes(self, arr: BackendArray) -> str:
|
540
598
|
"""
|
541
599
|
Compute the bytestring representation of arr.
|
542
600
|
|
543
601
|
Parameters
|
544
602
|
----------
|
545
|
-
arr :
|
546
|
-
Input
|
603
|
+
arr : BackendArray
|
604
|
+
Input data.
|
547
605
|
|
548
606
|
Returns
|
549
607
|
-------
|
550
608
|
str
|
551
|
-
Bytestring representation of arr
|
609
|
+
Bytestring representation of ``arr``.
|
552
610
|
"""
|
553
611
|
|
554
612
|
@abstractmethod
|
555
|
-
def size(self, arr:
|
613
|
+
def size(self, arr: BackendArray) -> int:
|
556
614
|
"""
|
557
615
|
Compute the number of elements of arr.
|
558
616
|
|
559
617
|
Parameters
|
560
618
|
----------
|
561
|
-
arr :
|
562
|
-
Input
|
619
|
+
arr : BackendArray
|
620
|
+
Input data.
|
563
621
|
|
564
622
|
Returns
|
565
623
|
-------
|
566
624
|
int
|
567
|
-
|
625
|
+
Number of elements in ``arr``.
|
568
626
|
"""
|
569
627
|
|
570
628
|
@abstractmethod
|
571
|
-
def fill(self, arr:
|
629
|
+
def fill(self, arr: BackendArray, value: Scalar) -> None:
|
572
630
|
"""
|
573
|
-
|
631
|
+
Fills ``arr`` in-place with a given value.
|
574
632
|
|
575
633
|
Parameters
|
576
634
|
----------
|
577
|
-
arr :
|
578
|
-
|
579
|
-
value :
|
580
|
-
The value
|
581
|
-
|
582
|
-
Returns
|
583
|
-
-------
|
584
|
-
ArrayLike
|
585
|
-
The array filled with the given value.
|
635
|
+
arr : BackendArray
|
636
|
+
Input data.
|
637
|
+
value : Scalar
|
638
|
+
The value to fill the array with.
|
586
639
|
"""
|
587
640
|
|
588
641
|
@abstractmethod
|
589
|
-
def zeros(self, shape: Tuple[int], dtype: type) ->
|
642
|
+
def zeros(self, shape: Tuple[int], dtype: type) -> BackendArray:
|
590
643
|
"""
|
591
644
|
Returns an aligned array of zeros with specified shape and dtype.
|
592
645
|
|
593
646
|
Parameters
|
594
647
|
----------
|
595
|
-
shape :
|
648
|
+
shape : tuple of ints.
|
596
649
|
Desired shape for the array.
|
597
650
|
dtype : type
|
598
651
|
Desired data type for the array.
|
599
652
|
|
600
653
|
Returns
|
601
654
|
-------
|
602
|
-
|
655
|
+
BackendArray
|
603
656
|
Byte-aligned array of zeros with specified shape and dtype.
|
604
657
|
"""
|
605
658
|
|
606
659
|
@abstractmethod
|
607
|
-
def full(self, shape: Tuple[int], dtype: type, fill_value: Scalar) ->
|
660
|
+
def full(self, shape: Tuple[int], dtype: type, fill_value: Scalar) -> BackendArray:
|
608
661
|
"""
|
609
|
-
Returns an
|
662
|
+
Returns an array filled with fill_value of specified shape and dtype.
|
610
663
|
|
611
664
|
Parameters
|
612
665
|
----------
|
613
|
-
shape :
|
666
|
+
shape : tuple of ints.
|
614
667
|
Desired shape for the array.
|
615
668
|
dtype : type
|
616
669
|
Desired data type for the array.
|
617
670
|
|
618
671
|
Returns
|
619
672
|
-------
|
620
|
-
|
673
|
+
BackendArray
|
621
674
|
Byte-aligned array of zeros with specified shape and dtype.
|
622
675
|
"""
|
623
676
|
|
624
677
|
@abstractmethod
|
625
678
|
def eps(self, dtype: type) -> Scalar:
|
626
679
|
"""
|
627
|
-
Returns the
|
628
|
-
representable floating point value larger than 1.0.
|
680
|
+
Returns the minimal difference representable by dtype.
|
629
681
|
|
630
682
|
Parameters
|
631
683
|
----------
|
@@ -635,7 +687,7 @@ class MatchingBackend(ABC):
|
|
635
687
|
Returns
|
636
688
|
-------
|
637
689
|
Scalar
|
638
|
-
The eps for the given data type
|
690
|
+
The eps for the given data type.
|
639
691
|
"""
|
640
692
|
|
641
693
|
@abstractmethod
|
@@ -646,325 +698,311 @@ class MatchingBackend(ABC):
|
|
646
698
|
Parameters
|
647
699
|
----------
|
648
700
|
dtype : type
|
649
|
-
|
650
|
-
This is typically a data type like `np.float32` or `np.int64`.
|
701
|
+
Data type to determine the bytesize of.
|
651
702
|
|
652
703
|
Returns
|
653
704
|
-------
|
654
705
|
int
|
655
706
|
Number of bytes occupied by the datatype.
|
656
|
-
|
657
|
-
Examples
|
658
|
-
--------
|
659
|
-
>>> MatchingBackend.datatype_bytes(np.float32)
|
660
|
-
4
|
661
707
|
"""
|
662
708
|
|
663
709
|
@abstractmethod
|
664
710
|
def clip(
|
665
|
-
self, arr:
|
666
|
-
) ->
|
711
|
+
self, arr: BackendArray, a_min: Scalar, a_max: Scalar, out: BackendArray = None
|
712
|
+
) -> BackendArray:
|
667
713
|
"""
|
668
714
|
Clip elements of arr.
|
669
715
|
|
670
716
|
Parameters
|
671
717
|
----------
|
672
|
-
arr :
|
673
|
-
Input
|
718
|
+
arr : BackendArray
|
719
|
+
Input data.
|
674
720
|
a_min : Scalar
|
675
721
|
Lower bound.
|
676
722
|
a_max : Scalar
|
677
723
|
Upper bound.
|
678
|
-
out :
|
679
|
-
Output array.
|
724
|
+
out : BackendArray, optional
|
725
|
+
Output array to write the result to. Returns a new array by default.
|
680
726
|
|
681
727
|
Returns
|
682
728
|
-------
|
683
|
-
|
684
|
-
Clipped arr
|
729
|
+
BackendArray
|
730
|
+
Clipped ``arr``.
|
685
731
|
"""
|
686
732
|
|
687
733
|
@abstractmethod
|
688
|
-
def
|
689
|
-
self, arr: ArrayLike, a_min: Scalar, a_max: Scalar, out: ArrayLike = None
|
690
|
-
) -> ArrayLike:
|
691
|
-
"""
|
692
|
-
Flip the elements of arr.
|
693
|
-
|
694
|
-
Parameters
|
695
|
-
----------
|
696
|
-
arr : ArrayLike
|
697
|
-
Input array.
|
698
|
-
|
699
|
-
Returns
|
700
|
-
-------
|
701
|
-
ArrayLike
|
702
|
-
Flipped version of arr.
|
703
|
-
"""
|
704
|
-
|
705
|
-
@abstractmethod
|
706
|
-
def astype(arr: ArrayLike, dtype: type) -> ArrayLike:
|
734
|
+
def astype(arr: BackendArray, dtype: type) -> BackendArray:
|
707
735
|
"""
|
708
736
|
Change the datatype of arr.
|
709
737
|
|
710
738
|
Parameters
|
711
739
|
----------
|
712
|
-
arr :
|
713
|
-
Input
|
740
|
+
arr : BackendArray
|
741
|
+
Input data.
|
714
742
|
dtype : type
|
715
743
|
Target data type.
|
716
744
|
|
717
745
|
Returns
|
718
746
|
-------
|
719
|
-
|
720
|
-
|
747
|
+
BackendArray
|
748
|
+
Freshly allocated array containing the data of ``arr`` in ``dtype``.
|
721
749
|
"""
|
722
750
|
|
723
751
|
@abstractmethod
|
724
|
-
def arange(
|
752
|
+
def arange(
|
753
|
+
self, stop: Scalar, start: Scalar = 0, step: Scalar = 1, *args, **kwargs
|
754
|
+
) -> BackendArray:
|
725
755
|
"""
|
726
|
-
Arange values in
|
756
|
+
Arange values in evenly spaced interval.
|
727
757
|
|
728
758
|
Parameters
|
729
759
|
----------
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
760
|
+
stop : Scalar
|
761
|
+
End of the interval.
|
762
|
+
start : Scalar
|
763
|
+
Start of the interval, zero by default.
|
764
|
+
step : Scalar
|
765
|
+
Interval step size, one by default.
|
734
766
|
|
735
767
|
Returns
|
736
768
|
-------
|
737
|
-
|
738
|
-
|
769
|
+
BackendArray
|
770
|
+
Array of evenly spaced values in specified interval.
|
739
771
|
"""
|
740
772
|
|
741
|
-
def stack(self, *args, **kwargs) ->
|
773
|
+
def stack(self, *args, **kwargs) -> BackendArray:
|
742
774
|
"""
|
743
|
-
Join a sequence of
|
775
|
+
Join a sequence of objects along a new axis.
|
776
|
+
|
777
|
+
Parameters
|
778
|
+
----------
|
779
|
+
arr : BackendArray
|
780
|
+
Sequence of arrays.
|
781
|
+
axis : int, optional
|
782
|
+
Axis along which to stack the input arrays.
|
744
783
|
|
745
784
|
Returns
|
746
785
|
-------
|
747
|
-
|
748
|
-
|
786
|
+
BackendArray
|
787
|
+
Stacked input data.
|
749
788
|
"""
|
750
789
|
|
751
790
|
@abstractmethod
|
752
|
-
def concatenate(self, *args, **kwargs) ->
|
791
|
+
def concatenate(self, *args, **kwargs) -> BackendArray:
|
753
792
|
"""
|
754
|
-
|
793
|
+
Join a sequence of objects along an existing axis.
|
755
794
|
|
756
795
|
Parameters
|
757
796
|
----------
|
758
|
-
arr
|
759
|
-
|
797
|
+
arr : BackendArray
|
798
|
+
Sequence of arrays.
|
799
|
+
axis : int
|
800
|
+
Axis along which to stack the input arrays.
|
760
801
|
|
761
802
|
Returns
|
762
803
|
-------
|
763
|
-
|
764
|
-
Concatenated input
|
804
|
+
BackendArray
|
805
|
+
Concatenated input data.
|
765
806
|
"""
|
766
807
|
|
767
808
|
@abstractmethod
|
768
|
-
def repeat(self, *args, **kwargs) ->
|
809
|
+
def repeat(self, *args, **kwargs) -> BackendArray:
|
769
810
|
"""
|
770
|
-
Repeat each array
|
811
|
+
Repeat each array element a specified number of times.
|
771
812
|
|
772
813
|
Parameters
|
773
814
|
----------
|
774
|
-
arr :
|
775
|
-
Input
|
815
|
+
arr : BackendArray
|
816
|
+
Input data.
|
817
|
+
repeats : int or tuple of ints
|
818
|
+
Number of each repetitions along axis.
|
776
819
|
|
777
820
|
Returns
|
778
821
|
-------
|
779
|
-
|
780
|
-
Repeated
|
822
|
+
BackendArray
|
823
|
+
Repeated ``arr``.
|
781
824
|
"""
|
782
825
|
|
783
826
|
@abstractmethod
|
784
|
-
def topk_indices(self, arr: NDArray, k: int) ->
|
827
|
+
def topk_indices(self, arr: NDArray, k: int) -> BackendArray:
|
785
828
|
"""
|
786
|
-
|
829
|
+
Determinces the indices of largest elements.
|
787
830
|
|
788
831
|
Parameters
|
789
832
|
----------
|
790
|
-
arr :
|
791
|
-
Input
|
792
|
-
|
793
|
-
|
833
|
+
arr : BackendArray
|
834
|
+
Input data.
|
835
|
+
k : int
|
836
|
+
Number of maxima to determine.
|
794
837
|
|
795
838
|
Returns
|
796
839
|
-------
|
797
|
-
|
798
|
-
|
840
|
+
BackendArray
|
841
|
+
Indices of ``k`` largest elements in ``arr``.
|
799
842
|
"""
|
800
843
|
|
801
|
-
def indices(self, *args, **kwargs) ->
|
844
|
+
def indices(self, *args, **kwargs) -> BackendArray:
|
802
845
|
"""
|
803
846
|
Creates an array representing the index grid of an input.
|
804
847
|
|
805
848
|
Returns
|
806
849
|
-------
|
807
|
-
|
850
|
+
BackendArray
|
808
851
|
The index grid.
|
809
852
|
"""
|
810
853
|
|
811
854
|
@abstractmethod
|
812
|
-
def roll(self, *args, **kwargs) ->
|
855
|
+
def roll(self, *args, **kwargs) -> BackendArray:
|
813
856
|
"""
|
814
857
|
Roll array elements along a specified axis.
|
815
858
|
|
816
859
|
Parameters
|
817
860
|
----------
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
861
|
+
a : BackendArray
|
862
|
+
Input data.
|
863
|
+
shift : int or tuple of ints, optional
|
864
|
+
Shift along each axis.
|
822
865
|
|
823
866
|
Returns
|
824
867
|
-------
|
825
|
-
|
868
|
+
BackendArray
|
826
869
|
Array with elements rolled.
|
870
|
+
"""
|
827
871
|
|
828
|
-
|
829
|
-
|
830
|
-
|
872
|
+
@abstractmethod
|
873
|
+
def where(condition, *args) -> BackendArray:
|
874
|
+
"""
|
875
|
+
Return elements from input depending on ``condition``.
|
831
876
|
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
877
|
+
Parameters
|
878
|
+
----------
|
879
|
+
condition : BackendArray
|
880
|
+
Binary condition array.
|
881
|
+
*args : BackendArray
|
882
|
+
Values to choose from.
|
883
|
+
|
884
|
+
Returns
|
885
|
+
-------
|
886
|
+
BackendArray
|
887
|
+
Array of elements according to ``condition``.
|
838
888
|
"""
|
839
889
|
|
840
890
|
@abstractmethod
|
841
|
-
def unique(
|
891
|
+
def unique(
|
892
|
+
self,
|
893
|
+
arr: BackendArray,
|
894
|
+
return_index: bool = False,
|
895
|
+
return_inverse: bool = False,
|
896
|
+
return_counts: bool = False,
|
897
|
+
axis: Tuple[int] = None,
|
898
|
+
*args,
|
899
|
+
**kwargs,
|
900
|
+
) -> Tuple[BackendArray]:
|
842
901
|
"""
|
843
902
|
Find the unique elements of an array.
|
844
903
|
|
845
904
|
Parameters
|
846
905
|
----------
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
906
|
+
arr : BackendArray
|
907
|
+
Input data.
|
908
|
+
return_index : bool, optional
|
909
|
+
Return indices that resulted in unique array, False by default.
|
910
|
+
return_inverse : bool, optional
|
911
|
+
Return indices to reconstruct the input, False by default.
|
912
|
+
return_counts : bool, optional
|
913
|
+
Return number of occurences of each unique element, False by default.
|
914
|
+
axis : int or tuple of ints, optional
|
915
|
+
Axis or axes to perform the operation on. Default is all.
|
851
916
|
|
852
917
|
Returns
|
853
918
|
-------
|
854
|
-
|
919
|
+
BackendArray or tuple of BackendArray
|
855
920
|
If `return_index`, `return_inverse`, and `return_counts` keyword
|
856
|
-
arguments are all False (the default), this will be an
|
921
|
+
arguments are all False (the default), this will be an BackendArray object
|
857
922
|
of the sorted unique values. Otherwise, it's a tuple with one
|
858
923
|
or more arrays as specified by those keyword arguments.
|
859
|
-
|
860
|
-
See Also
|
861
|
-
--------
|
862
|
-
numpy.unique : For more detailed documentation on arguments and behavior.
|
863
|
-
|
864
|
-
Examples
|
865
|
-
--------
|
866
|
-
>>> import numpy as np
|
867
|
-
>>> x = np.array([1, 2, 3, 2, 3, 4])
|
868
|
-
>>> np.unique(x)
|
869
|
-
array([1, 2, 3, 4])
|
870
924
|
"""
|
871
925
|
|
872
926
|
@abstractmethod
|
873
|
-
def argsort(self, *args, **kwargs) ->
|
927
|
+
def argsort(self, *args, **kwargs) -> BackendArray:
|
874
928
|
"""
|
875
|
-
|
929
|
+
Compute the indices to sort a given input array.
|
876
930
|
|
877
931
|
Parameters
|
878
932
|
----------
|
879
|
-
arr :
|
933
|
+
arr : BackendArray
|
880
934
|
Input array.
|
881
935
|
dtype : type
|
882
936
|
Target data type.
|
883
937
|
|
884
938
|
Returns
|
885
939
|
-------
|
886
|
-
|
887
|
-
|
940
|
+
BackendArray
|
941
|
+
Indices that would sort the input data.
|
888
942
|
"""
|
889
943
|
|
890
944
|
@abstractmethod
|
891
|
-
def unravel_index(
|
945
|
+
def unravel_index(
|
946
|
+
self, indices: BackendArray, shape: Tuple[int]
|
947
|
+
) -> Tuple[BackendArray]:
|
892
948
|
"""
|
893
949
|
Convert flat index to array indices.
|
894
950
|
|
895
951
|
Parameters
|
896
952
|
----------
|
897
|
-
|
898
|
-
Input
|
899
|
-
|
900
|
-
|
953
|
+
indices : BackendArray
|
954
|
+
Input data.
|
955
|
+
shape : tuple of ints
|
956
|
+
Shape of the array used for unraveling.
|
901
957
|
|
902
958
|
Returns
|
903
959
|
-------
|
904
|
-
|
905
|
-
|
960
|
+
BackendArray
|
961
|
+
Array indices.
|
906
962
|
"""
|
907
963
|
|
908
964
|
@abstractmethod
|
909
|
-
def tril_indices(self, *args, **kwargs) ->
|
965
|
+
def tril_indices(self, *args, **kwargs) -> BackendArray:
|
910
966
|
"""
|
911
967
|
Compute indices of upper triangular matrix
|
912
968
|
|
913
969
|
Parameters
|
914
970
|
----------
|
915
|
-
arr :
|
971
|
+
arr : BackendArray
|
916
972
|
Input array.
|
917
973
|
dtype : type
|
918
974
|
Target data type.
|
919
975
|
|
920
976
|
Returns
|
921
977
|
-------
|
922
|
-
|
978
|
+
BackendArray
|
923
979
|
Flipped version of arr.
|
924
980
|
"""
|
925
981
|
|
926
982
|
@abstractmethod
|
927
983
|
def max_filter_coordinates(
|
928
|
-
self, score_space:
|
929
|
-
) ->
|
984
|
+
self, score_space: BackendArray, min_distance: Tuple[int]
|
985
|
+
) -> BackendArray:
|
930
986
|
"""
|
931
987
|
Identifies local maxima in score_space separated by min_distance.
|
932
988
|
|
933
989
|
Parameters
|
934
990
|
----------
|
935
|
-
score_space :
|
991
|
+
score_space : BackendArray
|
936
992
|
Input score space.
|
937
993
|
min_distance : tuple of ints
|
938
994
|
Minimum distance along each array axis.
|
939
995
|
|
940
996
|
Returns
|
941
997
|
-------
|
942
|
-
|
998
|
+
BackendArray
|
943
999
|
Identified local maxima.
|
944
1000
|
"""
|
945
1001
|
|
946
1002
|
@abstractmethod
|
947
|
-
def
|
948
|
-
"""
|
949
|
-
Returns an aligned array of zeros with specified shape and dtype.
|
950
|
-
|
951
|
-
Parameters
|
952
|
-
----------
|
953
|
-
shape : Tuple[int]
|
954
|
-
Desired shape for the array.
|
955
|
-
dtype : type
|
956
|
-
Desired data type for the array.
|
957
|
-
|
958
|
-
Returns
|
959
|
-
-------
|
960
|
-
ArrayLike
|
961
|
-
Byte-aligned array of zeros with specified shape and dtype.
|
962
|
-
"""
|
963
|
-
|
964
|
-
@abstractmethod
|
965
|
-
def sharedarr_to_arr(
|
1003
|
+
def from_sharedarr(
|
966
1004
|
self, shape: Tuple[int], dtype: str, shm: shared_memory.SharedMemory
|
967
|
-
) ->
|
1005
|
+
) -> BackendArray:
|
968
1006
|
"""
|
969
1007
|
Returns an array of given shape and dtype from shared memory location.
|
970
1008
|
|
@@ -979,41 +1017,41 @@ class MatchingBackend(ABC):
|
|
979
1017
|
|
980
1018
|
Returns
|
981
1019
|
-------
|
982
|
-
|
1020
|
+
BackendArray
|
983
1021
|
Array of the specified shape and dtype from the shared memory location.
|
984
1022
|
"""
|
985
1023
|
|
986
1024
|
@abstractmethod
|
987
|
-
def
|
988
|
-
self, arr: type, shared_memory_handler: type = None
|
989
|
-
) -> shared_memory.SharedMemory:
|
1025
|
+
def to_sharedarr(self, arr: type, shared_memory_handler: type = None) -> shm_type:
|
990
1026
|
"""
|
991
|
-
Converts an array to an object shared in memory.
|
1027
|
+
Converts an array to an object shared in memory. The output of this function
|
1028
|
+
will only be passed to :py:meth:`from_sharedarr`, hence the return values can
|
1029
|
+
be modified in particular backends to match the expected input data.
|
992
1030
|
|
993
1031
|
Parameters
|
994
1032
|
----------
|
995
|
-
arr :
|
1033
|
+
arr : BackendArray
|
996
1034
|
Numpy array to convert.
|
997
1035
|
shared_memory_handler : type, optional
|
998
1036
|
The type of shared memory handler. Default is None.
|
999
1037
|
|
1000
1038
|
Returns
|
1001
1039
|
-------
|
1002
|
-
shared_memory.SharedMemory
|
1003
|
-
The shared memory object containing the numpy array.
|
1040
|
+
Tuple[shared_memory.SharedMemory, tuple of ints, dtype]
|
1041
|
+
The shared memory object containing the numpy array, its shape and dtype.
|
1004
1042
|
"""
|
1005
1043
|
|
1006
1044
|
@abstractmethod
|
1007
1045
|
def topleft_pad(
|
1008
|
-
self, arr:
|
1009
|
-
) ->
|
1046
|
+
self, arr: BackendArray, shape: Tuple[int], padval: int = 0
|
1047
|
+
) -> BackendArray:
|
1010
1048
|
"""
|
1011
1049
|
Returns an array that has been padded to a specified shape with a padding
|
1012
1050
|
value at the top-left corner.
|
1013
1051
|
|
1014
1052
|
Parameters
|
1015
1053
|
----------
|
1016
|
-
arr :
|
1054
|
+
arr : BackendArray
|
1017
1055
|
Input array to be padded.
|
1018
1056
|
shape : Tuple[int]
|
1019
1057
|
Desired shape for the output array.
|
@@ -1022,7 +1060,7 @@ class MatchingBackend(ABC):
|
|
1022
1060
|
|
1023
1061
|
Returns
|
1024
1062
|
-------
|
1025
|
-
|
1063
|
+
BackendArray
|
1026
1064
|
Array that has been padded to the specified shape.
|
1027
1065
|
"""
|
1028
1066
|
|
@@ -1036,7 +1074,11 @@ class MatchingBackend(ABC):
|
|
1036
1074
|
**kwargs,
|
1037
1075
|
) -> Tuple[Callable, Callable]:
|
1038
1076
|
"""
|
1039
|
-
Build forward and inverse real fourier transform functions.
|
1077
|
+
Build forward and inverse real fourier transform functions. The returned
|
1078
|
+
callables have two parameters ``arr`` and ``out`` which correspond to the
|
1079
|
+
input and output of the Fourier transform. The methods return the output
|
1080
|
+
of the respective function call, regardless of ``out`` being provided or not,
|
1081
|
+
analogous to most numpy functions.
|
1040
1082
|
|
1041
1083
|
Parameters
|
1042
1084
|
----------
|
@@ -1050,35 +1092,36 @@ class MatchingBackend(ABC):
|
|
1050
1092
|
Numpy dtype of the inverse fourier transform.
|
1051
1093
|
complex_dtype : dtype
|
1052
1094
|
Numpy dtype of the fourier transform.
|
1095
|
+
inverse_fast_shape : tuple, optional
|
1096
|
+
Output shape of the inverse Fourier transform. By default fast_shape.
|
1053
1097
|
fftargs : dict, optional
|
1054
1098
|
Dictionary passed to pyFFTW builders.
|
1055
|
-
temp_real :
|
1099
|
+
temp_real : NDArray, optional
|
1056
1100
|
Temporary real numpy array, by default None.
|
1057
|
-
temp_fft :
|
1101
|
+
temp_fft : NDArray, optional
|
1058
1102
|
Temporary fft numpy array, by default None.
|
1059
1103
|
|
1060
1104
|
Returns
|
1061
1105
|
-------
|
1062
1106
|
tuple
|
1063
|
-
Tuple
|
1064
|
-
fourier transform
|
1107
|
+
Tuple of callables for forward and inverse real Fourier transform.
|
1065
1108
|
"""
|
1066
1109
|
|
1067
|
-
def extract_center(self, arr:
|
1110
|
+
def extract_center(self, arr: BackendArray, newshape: Tuple[int]) -> BackendArray:
|
1068
1111
|
"""
|
1069
1112
|
Extract the centered portion of an array based on a new shape.
|
1070
1113
|
|
1071
1114
|
Parameters
|
1072
1115
|
----------
|
1073
|
-
arr :
|
1074
|
-
Input
|
1116
|
+
arr : BackendArray
|
1117
|
+
Input data.
|
1075
1118
|
newshape : tuple
|
1076
1119
|
Desired shape for the central portion.
|
1077
1120
|
|
1078
1121
|
Returns
|
1079
1122
|
-------
|
1080
|
-
|
1081
|
-
Central portion of the array with shape
|
1123
|
+
BackendArray
|
1124
|
+
Central portion of the array with shape ``newshape``.
|
1082
1125
|
"""
|
1083
1126
|
|
1084
1127
|
@abstractmethod
|
@@ -1104,19 +1147,42 @@ class MatchingBackend(ABC):
|
|
1104
1147
|
"""
|
1105
1148
|
|
1106
1149
|
@abstractmethod
|
1107
|
-
def
|
1150
|
+
def rigid_transform(
|
1151
|
+
self,
|
1152
|
+
arr: BackendArray,
|
1153
|
+
rotation_matrix: BackendArray,
|
1154
|
+
arr_mask: Optional[BackendArray] = None,
|
1155
|
+
translation: Optional[BackendArray] = None,
|
1156
|
+
use_geometric_center: bool = True,
|
1157
|
+
out: Optional[BackendArray] = None,
|
1158
|
+
out_mask: Optional[BackendArray] = None,
|
1159
|
+
order: int = 3,
|
1160
|
+
**kwargs,
|
1161
|
+
) -> Tuple[BackendArray, Optional[BackendArray]]:
|
1108
1162
|
"""
|
1109
|
-
|
1163
|
+
Performs a rigid transformation.
|
1110
1164
|
|
1111
1165
|
Parameters
|
1112
1166
|
----------
|
1113
|
-
arr :
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1167
|
+
arr : BackendArray
|
1168
|
+
The input array to be rotated.
|
1169
|
+
arr_mask : BackendArray, optional
|
1170
|
+
The mask of `arr` that will be equivalently rotated.
|
1171
|
+
rotation_matrix : BackendArray
|
1172
|
+
The rotation matrix to apply (d, d).
|
1173
|
+
translation : BackendArray
|
1174
|
+
The translation to apply (d,).
|
1175
|
+
use_geometric_center : bool, optional
|
1176
|
+
Whether rotation should be performed over the center of mass.
|
1177
|
+
out : BackendArray, optional
|
1178
|
+
Location into which the rotation of ``arr`` is written.
|
1179
|
+
out_mask : BackendArray, optional
|
1180
|
+
Location into which the rotation of ``arr_mask`` is written.
|
1181
|
+
order : int, optional
|
1182
|
+
Interpolation order, one is linear and three is cubic. Specific
|
1183
|
+
meaning depends on backend.
|
1184
|
+
kwargs : dict, optional
|
1185
|
+
Keyword arguments relevant to particular backend implementations.
|
1120
1186
|
"""
|
1121
1187
|
|
1122
1188
|
@abstractmethod
|
@@ -1128,29 +1194,39 @@ class MatchingBackend(ABC):
|
|
1128
1194
|
"""
|
1129
1195
|
|
1130
1196
|
@abstractmethod
|
1131
|
-
def reverse(arr:
|
1197
|
+
def reverse(arr: BackendArray) -> BackendArray:
|
1132
1198
|
"""
|
1133
1199
|
Reverse the order of elements in an array along all its axes.
|
1134
1200
|
|
1135
1201
|
Parameters
|
1136
1202
|
----------
|
1137
|
-
arr :
|
1203
|
+
arr : BackendArray
|
1138
1204
|
Input array.
|
1139
1205
|
|
1140
1206
|
Returns
|
1141
1207
|
-------
|
1142
|
-
|
1208
|
+
BackendArray
|
1143
1209
|
Reversed array.
|
1144
1210
|
"""
|
1145
1211
|
|
1146
1212
|
@abstractmethod
|
1147
|
-
def set_device(device_index: int):
|
1213
|
+
def set_device(device_index: int) -> Generator:
|
1148
1214
|
"""
|
1149
|
-
|
1215
|
+
Context manager that sets active compute device device for operations.
|
1216
|
+
|
1217
|
+
Parameters
|
1218
|
+
----------
|
1219
|
+
device_index : int
|
1220
|
+
Index of the device to be set as active.
|
1150
1221
|
"""
|
1151
1222
|
|
1152
1223
|
@abstractmethod
|
1153
1224
|
def device_count() -> int:
|
1154
1225
|
"""
|
1155
|
-
Return the number of available compute devices.
|
1226
|
+
Return the number of available compute devices considered by the backend.
|
1227
|
+
|
1228
|
+
Returns
|
1229
|
+
-------
|
1230
|
+
int
|
1231
|
+
Number of available devices.
|
1156
1232
|
"""
|