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