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