imops 0.8.2__cp36-cp36m-win32.whl → 0.8.3__cp36-cp36m-win32.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.

Potentially problematic release.


This version of imops might be problematic. Click here for more details.

imops/src/_numeric.pyx CHANGED
@@ -8,10 +8,19 @@
8
8
  import numpy as np
9
9
 
10
10
  cimport numpy as np
11
+ from libc.stdint cimport uint16_t
11
12
 
12
13
  from cython.parallel import prange
13
14
 
14
15
 
16
+ # https://stackoverflow.com/questions/47421443/using-half-precision-numpy-floats-in-cython
17
+ cdef extern from "numpy/halffloat.h":
18
+ ctypedef uint16_t npy_half
19
+
20
+ float npy_half_to_float(npy_half h) nogil
21
+ npy_half npy_float_to_half(float f) nogil
22
+
23
+
15
24
  ctypedef fused NUM:
16
25
  short
17
26
  int
@@ -20,45 +29,214 @@ ctypedef fused NUM:
20
29
  double
21
30
 
22
31
 
23
- def _parallel_sum(NUM[:] nums, Py_ssize_t num_threads) -> NUM:
24
- cdef NUM res = 0
25
- cdef Py_ssize_t i, len_nums = len(nums)
32
+ ctypedef fused NUM_AND_NPY_HALF:
33
+ NUM
34
+ npy_half
26
35
 
27
- for i in prange(len_nums, num_threads=num_threads, nogil=True):
28
- res += nums[i]
29
36
 
30
- return res
31
-
32
-
33
- def _parallel_pointwise_mul(
37
+ # TODO: Generalize code below to n-d
38
+ def _pointwise_add_array_3d(
34
39
  NUM[:, :, :] nums1,
35
40
  NUM[:, :, :] nums2,
36
- Py_ssize_t[:] res_shape,
37
- Py_ssize_t num_threads
41
+ NUM[:, :, :] out,
42
+ Py_ssize_t num_threads,
38
43
  ) -> np.ndarray:
39
- cdef NUM[:, :, ::1] contiguous_nums1 = np.ascontiguousarray(nums1), contiguous_nums2 = np.ascontiguousarray(nums2)
40
- cdef Py_ssize_t rows = res_shape[0], cols = res_shape[1], dims = res_shape[2]
44
+ cdef Py_ssize_t rows = out.shape[0], cols = out.shape[1], dims = out.shape[2]
45
+ cdef Py_ssize_t i, j, k
46
+
47
+ for i in prange(rows, nogil=True, num_threads=num_threads):
48
+ for j in prange(cols):
49
+ for k in prange(dims):
50
+ out[i, j, k] = nums1[i, j, k] + nums2[i, j, k]
51
+
52
+ return np.asarray(out)
41
53
 
42
- cdef char[:] broadcast_mask1 = np.array([x == y for x, y in zip(res_shape, nums1.shape)], dtype=np.int8)
43
- cdef char[:] broadcast_mask2 = np.array([x == y for x, y in zip(res_shape, nums2.shape)], dtype=np.int8)
44
54
 
45
- cdef NUM[:, :, ::1] mul = np.empty_like(nums1, shape=res_shape)
55
+ def _pointwise_add_array_4d(
56
+ NUM[:, :, :, :] nums1,
57
+ NUM[:, :, :, :] nums2,
58
+ NUM[:, :, :, :] out,
59
+ Py_ssize_t num_threads,
60
+ ) -> np.ndarray:
61
+ cdef Py_ssize_t dim1 = out.shape[0], dim2 = out.shape[1], dim3 = out.shape[2], dim4 = out.shape[3]
62
+ cdef Py_ssize_t i1, i2, i3, i4
63
+
64
+ for i1 in prange(dim1, nogil=True, num_threads=num_threads):
65
+ for i2 in prange(dim2):
66
+ for i3 in prange(dim3):
67
+ for i4 in prange(dim4):
68
+ out[i1, i2, i3, i4] = nums1[i1, i2, i3, i4] + nums2[i1, i2, i3, i4]
69
+
70
+ return np.asarray(out)
71
+
72
+
73
+ def _pointwise_add_value_3d(
74
+ NUM[:, :, :] nums,
75
+ NUM value,
76
+ NUM[:, :, :] out,
77
+ Py_ssize_t num_threads,
78
+ ) -> np.ndarray:
79
+ cdef Py_ssize_t rows = out.shape[0], cols = out.shape[1], dims = out.shape[2]
46
80
  cdef Py_ssize_t i, j, k
47
81
 
48
82
  for i in prange(rows, nogil=True, num_threads=num_threads):
49
83
  for j in prange(cols):
50
84
  for k in prange(dims):
51
- mul[i, j, k] = (
52
- contiguous_nums1[
53
- i * broadcast_mask1[0],
54
- j * broadcast_mask1[1],
55
- k * broadcast_mask1[2]
56
- ] *
57
- contiguous_nums2[
58
- i * broadcast_mask2[0],
59
- j * broadcast_mask2[1],
60
- k * broadcast_mask2[2]
61
- ]
62
- )
63
-
64
- return np.asarray(mul)
85
+ out[i, j, k] = nums[i, j, k] + value
86
+
87
+ return np.asarray(out)
88
+
89
+
90
+ def _pointwise_add_value_4d(
91
+ NUM[:, :, :, :] nums,
92
+ NUM value,
93
+ NUM[:, :, :, :] out,
94
+ Py_ssize_t num_threads,
95
+ ) -> np.ndarray:
96
+ cdef Py_ssize_t dim1 = out.shape[0], dim2 = out.shape[1], dim3 = out.shape[2], dim4 = out.shape[3]
97
+ cdef Py_ssize_t i1, i2, i3, i4
98
+
99
+ for i1 in prange(dim1, nogil=True, num_threads=num_threads):
100
+ for i2 in prange(dim2):
101
+ for i3 in prange(dim3):
102
+ for i4 in prange(dim4):
103
+ out[i1, i2, i3, i4] = nums[i1, i2, i3, i4] + value
104
+
105
+ return np.asarray(out)
106
+
107
+
108
+ def _pointwise_add_array_3d_fp16(
109
+ npy_half[:, :, :] nums1,
110
+ npy_half[:, :, :] nums2,
111
+ npy_half[:, :, :] out,
112
+ Py_ssize_t num_threads,
113
+ ) -> np.ndarray:
114
+ cdef Py_ssize_t rows = out.shape[0], cols = out.shape[1], dims = out.shape[2]
115
+ cdef Py_ssize_t i, j, k
116
+
117
+ for i in prange(rows, nogil=True, num_threads=num_threads):
118
+ for j in prange(cols):
119
+ for k in prange(dims):
120
+ out[i, j, k] = (npy_float_to_half(npy_half_to_float(nums1[i, j, k]) +
121
+ npy_half_to_float(nums2[i, j, k])))
122
+
123
+ return np.asarray(out)
124
+
125
+
126
+ def _pointwise_add_array_4d_fp16(
127
+ npy_half[:, :, :, :] nums1,
128
+ npy_half[:, :, :, :] nums2,
129
+ npy_half[:, :, :, :] out,
130
+ Py_ssize_t num_threads,
131
+ ) -> np.ndarray:
132
+ cdef Py_ssize_t dim1 = out.shape[0], dim2 = out.shape[1], dim3 = out.shape[2], dim4 = out.shape[3]
133
+ cdef Py_ssize_t i1, i2, i3, i4
134
+
135
+ for i1 in prange(dim1, nogil=True, num_threads=num_threads):
136
+ for i2 in prange(dim2):
137
+ for i3 in prange(dim3):
138
+ for i4 in prange(dim4):
139
+ out[i1, i2, i3, i4] = (npy_float_to_half(npy_half_to_float(nums1[i1, i2, i3, i4]) +
140
+ npy_half_to_float(nums2[i1, i2, i3, i4])))
141
+
142
+ return np.asarray(out)
143
+
144
+
145
+ def _pointwise_add_value_3d_fp16(
146
+ npy_half[:, :, :] nums,
147
+ npy_half value,
148
+ npy_half[:, :, :] out,
149
+ Py_ssize_t num_threads,
150
+ ) -> np.ndarray:
151
+ cdef Py_ssize_t rows = out.shape[0], cols = out.shape[1], dims = out.shape[2]
152
+ cdef Py_ssize_t i, j, k
153
+
154
+ for i in prange(rows, nogil=True, num_threads=num_threads):
155
+ for j in prange(cols):
156
+ for k in prange(dims):
157
+ out[i, j, k] = npy_float_to_half(npy_half_to_float(nums[i, j, k]) + npy_half_to_float(value))
158
+
159
+ return np.asarray(out)
160
+
161
+
162
+ def _pointwise_add_value_4d_fp16(
163
+ npy_half[:, :, :, :] nums,
164
+ npy_half value,
165
+ npy_half[:, :, :, :] out,
166
+ Py_ssize_t num_threads,
167
+ ) -> np.ndarray:
168
+ cdef Py_ssize_t dim1 = out.shape[0], dim2 = out.shape[1], dim3 = out.shape[2], dim4 = out.shape[3]
169
+ cdef Py_ssize_t i1, i2, i3, i4
170
+
171
+ for i1 in prange(dim1, nogil=True, num_threads=num_threads):
172
+ for i2 in prange(dim2):
173
+ for i3 in prange(dim3):
174
+ for i4 in prange(dim4):
175
+ out[i1, i2, i3, i4] = (npy_float_to_half(npy_half_to_float(nums[i1, i2, i3, i4]) +
176
+ npy_half_to_float(value)))
177
+
178
+ return np.asarray(out)
179
+
180
+
181
+ def _fill_3d(NUM_AND_NPY_HALF[:, :, :] nums, NUM_AND_NPY_HALF value, Py_ssize_t num_threads) -> None:
182
+ cdef Py_ssize_t rows = nums.shape[0], cols = nums.shape[1], dims = nums.shape[2]
183
+ cdef Py_ssize_t i, j, k
184
+
185
+ for i in prange(rows, nogil=True, num_threads=num_threads):
186
+ for j in prange(cols):
187
+ for k in prange(dims):
188
+ nums[i, j, k] = value
189
+
190
+
191
+ def _fill_4d(NUM_AND_NPY_HALF[:, :, :, :] nums, NUM_AND_NPY_HALF value, Py_ssize_t num_threads) -> None:
192
+ cdef Py_ssize_t dim1 = nums.shape[0], dim2 = nums.shape[1], dim3 = nums.shape[2], dim4 = nums.shape[3]
193
+ cdef Py_ssize_t i1, i2, i3, i4
194
+
195
+ for i1 in prange(dim1, nogil=True, num_threads=num_threads):
196
+ for i2 in prange(dim2):
197
+ for i3 in prange(dim3):
198
+ for i4 in prange(dim4):
199
+ nums[i1, i2, i3, i4] = value
200
+
201
+
202
+ # FIXME: somehow `const NUM_AND_NPY_HALF` is not working
203
+ cpdef void _copy_3d(const NUM[:, :, :] nums1, NUM[:, :, :] nums2, Py_ssize_t num_threads):
204
+ cdef Py_ssize_t rows = nums1.shape[0], cols = nums1.shape[1], dims = nums1.shape[2]
205
+ cdef Py_ssize_t i, j, k
206
+
207
+ for i in prange(rows, nogil=True, num_threads=num_threads):
208
+ for j in prange(cols):
209
+ for k in prange(dims):
210
+ nums2[i, j, k] = nums1[i, j, k]
211
+
212
+
213
+ cpdef void _copy_4d(const NUM[:, :, :, :] nums1, NUM[:, :, :, :] nums2, Py_ssize_t num_threads):
214
+ cdef Py_ssize_t dim1 = nums1.shape[0], dim2 = nums1.shape[1], dim3 = nums1.shape[2], dim4 = nums1.shape[3]
215
+ cdef Py_ssize_t i1, i2, i3, i4
216
+
217
+ for i1 in prange(dim1, nogil=True, num_threads=num_threads):
218
+ for i2 in prange(dim2):
219
+ for i3 in prange(dim3):
220
+ for i4 in prange(dim4):
221
+ nums2[i1, i2, i3, i4] = nums1[i1, i2, i3, i4]
222
+
223
+
224
+ cpdef void _copy_3d_fp16(const npy_half[:, :, :] nums1, npy_half[:, :, :] nums2, Py_ssize_t num_threads):
225
+ cdef Py_ssize_t rows = nums1.shape[0], cols = nums1.shape[1], dims = nums1.shape[2]
226
+ cdef Py_ssize_t i, j, k
227
+
228
+ for i in prange(rows, nogil=True, num_threads=num_threads):
229
+ for j in prange(cols):
230
+ for k in prange(dims):
231
+ nums2[i, j, k] = nums1[i, j, k]
232
+
233
+
234
+ cpdef void _copy_4d_fp16(const npy_half[:, :, :, :] nums1, npy_half[:, :, :, :] nums2, Py_ssize_t num_threads):
235
+ cdef Py_ssize_t dim1 = nums1.shape[0], dim2 = nums1.shape[1], dim3 = nums1.shape[2], dim4 = nums1.shape[3]
236
+ cdef Py_ssize_t i1, i2, i3, i4
237
+
238
+ for i1 in prange(dim1, nogil=True, num_threads=num_threads):
239
+ for i2 in prange(dim2):
240
+ for i3 in prange(dim3):
241
+ for i4 in prange(dim4):
242
+ nums2[i1, i2, i3, i4] = nums1[i1, i2, i3, i4]
Binary file
Binary file
imops/utils.py CHANGED
@@ -1,39 +1,92 @@
1
1
  import os
2
+ from contextlib import contextmanager
2
3
  from itertools import permutations
3
4
  from typing import Callable, Optional, Sequence, Tuple, Union
4
5
  from warnings import warn
5
6
 
6
7
  import numpy as np
7
8
 
8
- from .backend import BACKEND2NUM_THREADS_VAR_NAME, SINGLE_THREADED_BACKENDS, Backend
9
+ from .backend import BACKEND_NAME2ENV_NUM_THREADS_VAR_NAME, SINGLE_THREADED_BACKENDS, Backend
9
10
 
10
11
 
11
12
  AxesLike = Union[int, Sequence[int]]
12
13
  AxesParams = Union[float, Sequence[float]]
13
14
 
14
15
  ZOOM_SRC_DIM = 4
16
+ # TODO: define imops-specific environment variable like `OMP_NUM_THREADS`?
17
+ IMOPS_NUM_THREADS = None
15
18
 
16
19
 
17
- def normalize_num_threads(num_threads: int, backend: Backend):
20
+ def set_num_threads(num_threads: int) -> int:
21
+ assert isinstance(num_threads, int) or num_threads is None, 'Number of threads must be int value or None.'
22
+ global IMOPS_NUM_THREADS
23
+ current = IMOPS_NUM_THREADS
24
+ IMOPS_NUM_THREADS = num_threads
25
+ return current
26
+
27
+
28
+ @contextmanager
29
+ def imops_num_threads(num_threads: int):
30
+ previous = set_num_threads(num_threads)
31
+ try:
32
+ yield
33
+ finally:
34
+ set_num_threads(previous)
35
+
36
+
37
+ def normalize_num_threads(num_threads: int, backend: Backend, warn_stacklevel: int = 1) -> int:
38
+ """Calculate the effective number of threads"""
39
+
40
+ global IMOPS_NUM_THREADS
18
41
  if backend.name in SINGLE_THREADED_BACKENDS:
19
42
  if num_threads != -1:
20
- warn(f'"{backend.name}" backend is single-threaded. Setting `num_threads` has no effect.')
43
+ warn(
44
+ f'"{backend.name}" backend is single-threaded. Setting `num_threads` has no effect.',
45
+ stacklevel=warn_stacklevel,
46
+ )
21
47
  return 1
48
+
49
+ env_num_threads_var_name = BACKEND_NAME2ENV_NUM_THREADS_VAR_NAME[backend.name]
50
+ # here we also handle the case `env_num_threads_var_name`=" " gracefully
51
+ env_num_threads = os.environ.get(env_num_threads_var_name, '').strip()
52
+ env_num_threads = int(env_num_threads) if env_num_threads else None
53
+ # TODO: maybe let user set the absolute maximum number of threads?
54
+ num_available_cpus = len(os.sched_getaffinity(0))
55
+
56
+ max_num_threads = min(filter(bool, [IMOPS_NUM_THREADS, env_num_threads, num_available_cpus]))
57
+
22
58
  if num_threads >= 0:
23
59
  # FIXME
24
60
  if backend.name == 'Numba':
25
61
  warn(
26
62
  'Setting `num_threads` has no effect with "Numba" backend. '
27
- 'Use `NUMBA_NUM_THREADS` environment variable.'
63
+ 'Use `NUMBA_NUM_THREADS` environment variable.',
64
+ stacklevel=warn_stacklevel,
28
65
  )
29
- return num_threads
30
-
31
- num_threads_var_name = BACKEND2NUM_THREADS_VAR_NAME[backend.name]
32
- # here we also handle the case `num_threads_var`=" " gracefully
33
- env_num_threads = os.environ.get(num_threads_var_name, '').strip()
34
- max_threads = int(env_num_threads) if env_num_threads else len(os.sched_getaffinity(0))
35
-
36
- return max_threads + num_threads + 1
66
+ return num_threads
67
+
68
+ if num_threads > max_num_threads:
69
+ if max_num_threads == IMOPS_NUM_THREADS:
70
+ warn(
71
+ f'Required number of threads ({num_threads}) is greater than `IMOPS_NUM_THREADS` '
72
+ f'({IMOPS_NUM_THREADS}). Using {IMOPS_NUM_THREADS} threads.',
73
+ stacklevel=warn_stacklevel,
74
+ )
75
+ elif max_num_threads == env_num_threads:
76
+ warn(
77
+ f'Required number of threads ({num_threads}) is greater than `{env_num_threads_var_name}` '
78
+ f'({env_num_threads}). Using {env_num_threads} threads.',
79
+ stacklevel=warn_stacklevel,
80
+ )
81
+ else:
82
+ warn(
83
+ f'Required number of threads ({num_threads}) is greater than number of available CPU-s '
84
+ f'({num_available_cpus}). Using {num_available_cpus} threads.',
85
+ stacklevel=warn_stacklevel,
86
+ )
87
+ return min(num_threads, max_num_threads)
88
+
89
+ return max_num_threads + num_threads + 1
37
90
 
38
91
 
39
92
  def get_c_contiguous_permutaion(array: np.ndarray) -> Optional[np.ndarray]:
imops/zoom.py CHANGED
@@ -208,7 +208,7 @@ def _zoom(
208
208
 
209
209
  See `https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.zoom.html`
210
210
  """
211
- backend = resolve_backend(backend)
211
+ backend = resolve_backend(backend, warn_stacklevel=4)
212
212
  if backend.name not in ('Scipy', 'Numba', 'Cython'):
213
213
  raise ValueError(f'Unsupported backend "{backend.name}".')
214
214
 
@@ -216,7 +216,7 @@ def _zoom(
216
216
  dtype = input.dtype
217
217
  cval = np.dtype(dtype).type(cval)
218
218
  zoom = fill_by_indices(np.ones(input.ndim, 'float64'), zoom, range(input.ndim))
219
- num_threads = normalize_num_threads(num_threads, backend)
219
+ num_threads = normalize_num_threads(num_threads, backend, warn_stacklevel=4)
220
220
 
221
221
  if backend.name == 'Scipy':
222
222
  return scipy_zoom(
@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: imops
3
- Version: 0.8.2
3
+ Version: 0.8.3
4
4
  Summary: Efficient parallelizable algorithms for multidimensional arrays to speed up your data pipelines
5
5
  Home-page: https://github.com/neuro-ml/imops
6
6
  Author: maxme1, vovaf709, talgat
7
7
  Author-email: maxs987@gmail.com, vovaf709@yandex.ru, saparov2130@gmail.com
8
8
  License: MIT
9
- Download-URL: https://github.com/neuro-ml/imops/archive/v0.8.2.tar.gz
9
+ Download-URL: https://github.com/neuro-ml/imops/archive/v0.8.3.tar.gz
10
10
  Keywords: image processing,fast,ndarray,data pipelines
11
11
  Platform: UNKNOWN
12
12
  Classifier: Development Status :: 5 - Production/Stable
@@ -21,6 +21,7 @@ Requires-Python: >=3.6
21
21
  Description-Content-Type: text/markdown
22
22
  License-File: LICENSE
23
23
  Requires-Dist: scipy (<2.0.0,>=1.0)
24
+ Requires-Dist: scikit-image
24
25
  Requires-Dist: connected-components-3d
25
26
  Requires-Dist: fastremap
26
27
  Requires-Dist: dataclasses ; python_version < "3.7"
@@ -0,0 +1,46 @@
1
+ imops/__init__.py,sha256=QAqK6FnQnOjdDwSXzhnJNB2ur3cGUNbP3ZdLc_VoIEY,514
2
+ imops/__version__.py,sha256=lPOlZg8rjdgN8DyBl7I1rkzxiXOhafW_7RzlMGnvNo8,23
3
+ imops/_configs.py,sha256=6hBY2O4YSaQC_avvqI-dmhZkPMl4p39KQIPtqx5MAh0,734
4
+ imops/backend.py,sha256=8x6Zq9hetOt9_RDcytNNBJZBLNXgQd7ob2dh4WQuuqM,2598
5
+ imops/box.py,sha256=NbYsPKQ8fCGxSm5up0TyqERJ-5iWmnzHLo4Smv9eesk,1865
6
+ imops/crop.py,sha256=hCgwxDgNdIo9m0gleMB3oOUNA7tQurhYNhE5S39tMlE,4055
7
+ imops/interp1d.py,sha256=CSPJ77isqGOJTN-_C--iyz-3qJhpL4dE9i5VdJgSFDE,8400
8
+ imops/measure.py,sha256=YJ5hBDH6iW1hgqm6fi6FIURBKmeZjVfr7LSINOHgFrM,8657
9
+ imops/morphology.py,sha256=KG3RCCicsX7WHsBj4mH6iaJ0dy6tW9cGJJvD4fDisBQ,12723
10
+ imops/numeric.py,sha256=yiSjPTUD2w177LOBD_39_BHh9n8uKbSsHJDchNVsKRY,13650
11
+ imops/pad.py,sha256=OXy_r4X7hOPBU4NSH3B-8ZpxfcY1t6FFMgMSopULpv8,9314
12
+ imops/radon.py,sha256=TWsgZvWRapBbU7MVr1fRdpVXCvi6-kt8fxroyQc44ek,9211
13
+ imops/testing.py,sha256=Qiy_Qn7bd7MIXoaZr4T_6r0jQWVRJFwR2z12c_Zwt30,1708
14
+ imops/utils.py,sha256=nfrMUU0OhPgK5UapD9GNC1StPxX3cKbob54kiuf4_qs,6890
15
+ imops/zoom.py,sha256=wl8wt7yoX5V4Mn7sMefV1Fy9KEetqMEdRHLdhT90o6o,9955
16
+ imops/src/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
+ imops/src/_backprojection.cp36-win32.pyd,sha256=A6LH7d8sIvVJvWTlH2nLrJr3j97GcZzNxtFK9REinbI,155136
18
+ imops/src/_backprojection.pyx,sha256=xngEJtJ6czjoBRBKL6tu5S7nt6ZgcsE82xDGdCIfagE,2724
19
+ imops/src/_fast_backprojection.cp36-win32.pyd,sha256=_Ob4--N7IZW3kkI9RX75NbkTVI6FC6H08D1k9WwWd1U,155136
20
+ imops/src/_fast_backprojection.pyx,sha256=xngEJtJ6czjoBRBKL6tu5S7nt6ZgcsE82xDGdCIfagE,2724
21
+ imops/src/_fast_measure.cp36-win32.pyd,sha256=VfXOkRGYwmZpKbXbHtwOME631bxgbWcjAEitWnXMdNg,220672
22
+ imops/src/_fast_measure.pyx,sha256=JzZ26PptkVT08OemSFaJakc4jf7xYocPqV8jfrYi_wA,2737
23
+ imops/src/_fast_morphology.cp36-win32.pyd,sha256=zplrVcEH2uNgUD7f5iXuw4ctYrMcTiWbWesFovOUhIY,129536
24
+ imops/src/_fast_morphology.pyx,sha256=QwFrPQ6M-bJDVQNCCtKK7FR3KOr5cZSx_CBvxh9THXM,9538
25
+ imops/src/_fast_numeric.cp36-win32.pyd,sha256=h9BS_ygwyPFP0m9fSELRCwjbgLDbi5FHZsovZlKqnoQ,326144
26
+ imops/src/_fast_numeric.pyx,sha256=c8q3KlL8mDe0wsz72ooeqhffk1iqvA0Org7NWW5RbYo,8221
27
+ imops/src/_fast_radon.cp36-win32.pyd,sha256=bUb0OKw3YP18Tc0uh79bx9U_Ql1QesnlJ4NlLyep8Xw,202752
28
+ imops/src/_fast_radon.pyx,sha256=pu8EZplCjIDz9HqBcAit8nj2lDgXpmdhU61_4CfdGWI,2987
29
+ imops/src/_fast_zoom.cp36-win32.pyd,sha256=ZR7ExxrXxn07L3rK7tBgo8nGzLaxRvsADTv8lfXUUws,333312
30
+ imops/src/_fast_zoom.pyx,sha256=Dd5MDelALAh4-3QhnzfzKTB5Gmi2lVERrbyYj-q8kVQ,23091
31
+ imops/src/_measure.cp36-win32.pyd,sha256=bmsMA49jfJh4M5E9kSNgc4Q94U-aNsJkzQhdxovPm44,220160
32
+ imops/src/_measure.pyx,sha256=JzZ26PptkVT08OemSFaJakc4jf7xYocPqV8jfrYi_wA,2737
33
+ imops/src/_morphology.cp36-win32.pyd,sha256=JjwzaXLa30gxKIezYbX10zuj1fcfTtwXif7fVoiT_5w,129536
34
+ imops/src/_morphology.pyx,sha256=QwFrPQ6M-bJDVQNCCtKK7FR3KOr5cZSx_CBvxh9THXM,9538
35
+ imops/src/_numba_zoom.py,sha256=OmMj7mCFkV2P0FaWVXFuYpfzMBQ3Ks60YiHQURes5wQ,16857
36
+ imops/src/_numeric.cp36-win32.pyd,sha256=PkrARdgAlTZ9byV3z80f45_XtwhGdeo5WJL6yEieNWc,325120
37
+ imops/src/_numeric.pyx,sha256=c8q3KlL8mDe0wsz72ooeqhffk1iqvA0Org7NWW5RbYo,8221
38
+ imops/src/_radon.cp36-win32.pyd,sha256=6XLWRXNN1bGFOsy98ddqxFjU_cWKy31dvdq2mrYG2VY,202752
39
+ imops/src/_radon.pyx,sha256=pu8EZplCjIDz9HqBcAit8nj2lDgXpmdhU61_4CfdGWI,2987
40
+ imops/src/_zoom.cp36-win32.pyd,sha256=0--K2pLZ7ctBXJdmlUgXPsn5xoKvnYfY_qKCz0VC8Ls,333312
41
+ imops/src/_zoom.pyx,sha256=Dd5MDelALAh4-3QhnzfzKTB5Gmi2lVERrbyYj-q8kVQ,23091
42
+ imops-0.8.3.dist-info/LICENSE,sha256=x7oyYZPKDTt8KoTitcNJLBWhueke5YEOopdr0XjyvBc,1085
43
+ imops-0.8.3.dist-info/METADATA,sha256=NdA1fnC5rCLIg-kvfInPxqlWIckur-inz1uUF89mft0,7391
44
+ imops-0.8.3.dist-info/WHEEL,sha256=ZX-iFFGFiHZRWPwXowAnONYwAL2TBxDHVbhC1HaSV9Q,97
45
+ imops-0.8.3.dist-info/top_level.txt,sha256=kEVHvrc8A4lkLQP8xew2pWdYcyQAMvAwqnlZXtoWwnc,6
46
+ imops-0.8.3.dist-info/RECORD,,
imops/_numeric.py DELETED
@@ -1,124 +0,0 @@
1
- from warnings import warn
2
-
3
- import numpy as np
4
-
5
- from .backend import BackendLike, resolve_backend
6
- from .src._fast_numeric import (
7
- _parallel_pointwise_mul as cython_fast_parallel_pointwise_mul,
8
- _parallel_sum as cython_fast_parallel_sum,
9
- )
10
- from .src._numeric import _parallel_pointwise_mul as cython_parallel_pointwise_mul, _parallel_sum as cython_parallel_sum
11
- from .utils import normalize_num_threads
12
-
13
-
14
- def _sum(nums: np.ndarray, num_threads: int = -1, backend: BackendLike = None) -> float:
15
- """
16
- Parallel sum of flat numpy array
17
-
18
- Parameters
19
- ----------
20
- nums: np.ndarray
21
- 1-dimensional array
22
- num_threads: int
23
- the number of threads to use for computation. Default = the cpu count. If negative value passed
24
- cpu count + num_threads + 1 threads will be used
25
- backend: BackendLike
26
- which backend to use. `cython` and `scipy` (primarly for benchmarking) are available,
27
- `cython` is used by default
28
-
29
- Returns
30
- -------
31
- sum: float
32
-
33
- Examples
34
- --------
35
- >>> s = _sum(x, num_threads=1)
36
- >>> s = _sum(x, num_threads=8, backend=Cython(fast=True)) # ffast-math compiled version
37
- """
38
- ndim = nums.ndim
39
-
40
- if ndim != 1:
41
- raise ValueError(f'Input must be 1-dimensional instead of {ndim}-dimensional.')
42
-
43
- backend = resolve_backend(backend)
44
- if backend.name not in ('Cython', 'Scipy'):
45
- raise ValueError(f'Unsupported backend "{backend.name}"')
46
-
47
- num_threads = normalize_num_threads(num_threads, backend)
48
-
49
- if backend.name == 'Scipy':
50
- return nums.sum()
51
-
52
- if backend.name == 'Cython':
53
- src_parallel_sum = cython_fast_parallel_sum if backend.fast else cython_parallel_sum
54
-
55
- return src_parallel_sum(nums, num_threads)
56
-
57
-
58
- def _mul(nums1: np.ndarray, nums2: np.ndarray, num_threads: int = -1, backend: BackendLike = None) -> np.ndarray:
59
- """
60
- Parallel pointwise multiplication of 2 numpy arrays (aka x * y). Works faster only for ndim <= 3.
61
-
62
- Parameters
63
- ----------
64
- nums1: np.ndarray
65
- nums2: np.ndarray
66
- num_threads: int
67
- the number of threads to use for computation. Default = the cpu count. If negative value passed
68
- cpu count + num_threads + 1 threads will be used
69
- backend: BackendLike
70
- which backend to use. `cython` and `scipy` (primarly for benchmarking) are available,
71
- `cython` is used by default
72
-
73
- Returns
74
- -------
75
- multiplied: np.ndarray
76
- result of nums1 * nums2
77
-
78
- Examples
79
- --------
80
- >>> mul = _mul(nums1, nums2, num_threads=8)
81
- >>> mul = _mul(np.ones((2, 3)), np.ones((1, 3))) # broadcasting, mul.shape == (2, 3)
82
- >>> mul = _mul(nums1, nums2, backend=Cython(fast=True)) # ffast-math compiled version
83
- """
84
- if not nums1.size and not nums2.size:
85
- return np.array([], dtype=nums1.dtype)
86
- if bool(nums1.size) ^ bool(nums2.size):
87
- raise ValueError('One of the arrays is empty, hence pointwise multiplication cannot be performed.')
88
- if len(nums1.shape) != len(nums2.shape):
89
- raise ValueError('Both arrays must have the same number of dimensions for pointwise multiplication.')
90
- for dim1, dim2 in zip(nums1.shape, nums2.shape):
91
- if dim1 != dim2 and dim1 != 1 and dim2 != 1:
92
- raise ValueError(f'Arrays of shapes {nums1.shape} and {nums2.shape} are not broadcastable.')
93
-
94
- if nums1.ndim > 3:
95
- warn('Parallel pointwise multiplication is only supported for ndim<=3. Falling back to naive x * y.')
96
-
97
- return nums1 * nums2
98
-
99
- backend = resolve_backend(backend)
100
- if backend.name not in ('Cython', 'Scipy'):
101
- raise ValueError(f'Unsupported backend "{backend.name}"')
102
-
103
- num_threads = normalize_num_threads(num_threads, backend)
104
-
105
- if backend.name == 'Scipy':
106
- return nums1 * nums2
107
-
108
- if backend.name == 'Cython':
109
- src_parallel_pointwise_mul = (
110
- cython_fast_parallel_pointwise_mul if backend.fast else cython_parallel_pointwise_mul
111
- )
112
-
113
- n_dummy = 3 - nums1.ndim
114
-
115
- if n_dummy:
116
- nums1 = nums1[(None,) * n_dummy]
117
- nums2 = nums2[(None,) * n_dummy]
118
-
119
- out = src_parallel_pointwise_mul(nums1, nums2, np.maximum(nums1.shape, nums2.shape), num_threads)
120
-
121
- if n_dummy:
122
- out = out[(0,) * n_dummy]
123
-
124
- return out
@@ -1,46 +0,0 @@
1
- imops/__init__.py,sha256=DH8Dp0MIEq8j_taTwUMXKqoY3WjdVdBbMnNdKHx_qes,459
2
- imops/__version__.py,sha256=XhFj_ipJJJgnq-LMeWY_tqb7jCV62Abi98yRdQ0le8U,23
3
- imops/_configs.py,sha256=6hBY2O4YSaQC_avvqI-dmhZkPMl4p39KQIPtqx5MAh0,734
4
- imops/_numeric.py,sha256=XfKU5mNGRAAoEKtJ9xrYTxpxNFZv0abHvoolEUVeVdo,4383
5
- imops/backend.py,sha256=lt3BrosqmxFh7BA-rYwYAer3XMdBTPS-pBIR5hHDNa0,2368
6
- imops/box.py,sha256=NbYsPKQ8fCGxSm5up0TyqERJ-5iWmnzHLo4Smv9eesk,1865
7
- imops/crop.py,sha256=hDrPNVFU3vV758KTwZmZxHzm4XgUkLQLSqJOYQHG4P0,3446
8
- imops/interp1d.py,sha256=55NFTGgYUDlcndRvPqKLLPpFe6U0K8B-so8yUgBbK3c,8183
9
- imops/measure.py,sha256=NqCsj2yxuUEfpPmGmOL-YSvI_2rrYUWJyzaSCPoOe90,8575
10
- imops/morphology.py,sha256=GDVnLjGjTZJgcGNyFXPn3BMM7WHZZQeg-i24ci6uCdQ,12625
11
- imops/pad.py,sha256=SAPJQwnuKosPoiCU26YPE4cyRPNrskwfzNOrT3KqSuk,7447
12
- imops/radon.py,sha256=C643fB9tzqK0_RyhH9EzQBfHAeEqjbnbGKDT485k5pk,9008
13
- imops/testing.py,sha256=Qiy_Qn7bd7MIXoaZr4T_6r0jQWVRJFwR2z12c_Zwt30,1708
14
- imops/utils.py,sha256=9XoA8qywuuSTluGDf1aEa_zP2Ixu2pNYQnBbWhy92T4,4720
15
- imops/zoom.py,sha256=g7lgv8Z51tNCYfAyQnLlA187QgDzyQHxckEY9Uu9EKY,9917
16
- imops/src/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
- imops/src/_backprojection.cp36-win32.pyd,sha256=tEJrvPUW9F1WYW8jHcrdUGPyvjQLD7GFV0A5BV6xRU0,153600
18
- imops/src/_backprojection.pyx,sha256=xngEJtJ6czjoBRBKL6tu5S7nt6ZgcsE82xDGdCIfagE,2724
19
- imops/src/_fast_backprojection.cp36-win32.pyd,sha256=hrm_VudsN4KrzJ9YQ4sRyQlnbKCrce5zuJx_QsS_-Ks,154112
20
- imops/src/_fast_backprojection.pyx,sha256=xngEJtJ6czjoBRBKL6tu5S7nt6ZgcsE82xDGdCIfagE,2724
21
- imops/src/_fast_measure.cp36-win32.pyd,sha256=O15wuxD58QyycWg_DN1KICRlqwh_GN16SmpzJl9kOKo,219648
22
- imops/src/_fast_measure.pyx,sha256=JzZ26PptkVT08OemSFaJakc4jf7xYocPqV8jfrYi_wA,2737
23
- imops/src/_fast_morphology.cp36-win32.pyd,sha256=699Q1QmRTM7mNlv33EOmnEsG6PGHOk1SC6AwDtjzi5k,129024
24
- imops/src/_fast_morphology.pyx,sha256=QwFrPQ6M-bJDVQNCCtKK7FR3KOr5cZSx_CBvxh9THXM,9538
25
- imops/src/_fast_numeric.cp36-win32.pyd,sha256=6MK-dQ9elgfHJiOUFc-IWdIo596an2KuQ53vg_z0Ft4,209920
26
- imops/src/_fast_numeric.pyx,sha256=bXv4qBx_k6B6INNR0r49HU2a8UNnpt-mCS19TczcU38,1919
27
- imops/src/_fast_radon.cp36-win32.pyd,sha256=9RPxYgYAYktiNNscPk7meGuCkg7pwMiJ4kG-g2lvnEo,195584
28
- imops/src/_fast_radon.pyx,sha256=pu8EZplCjIDz9HqBcAit8nj2lDgXpmdhU61_4CfdGWI,2987
29
- imops/src/_fast_zoom.cp36-win32.pyd,sha256=A25ZjipbwrrAO_IhGAtlVOPWErzNyEf0Bdd1bsu4IJY,312832
30
- imops/src/_fast_zoom.pyx,sha256=Dd5MDelALAh4-3QhnzfzKTB5Gmi2lVERrbyYj-q8kVQ,23091
31
- imops/src/_measure.cp36-win32.pyd,sha256=y6waCfQlPCSOlYEj87cvFE7ntls8QFlrTq63WyluacU,219136
32
- imops/src/_measure.pyx,sha256=JzZ26PptkVT08OemSFaJakc4jf7xYocPqV8jfrYi_wA,2737
33
- imops/src/_morphology.cp36-win32.pyd,sha256=fP3kYsa6PAlXOzhXyV8vMGum0jrweX-3yDyr-DMCuTM,129024
34
- imops/src/_morphology.pyx,sha256=QwFrPQ6M-bJDVQNCCtKK7FR3KOr5cZSx_CBvxh9THXM,9538
35
- imops/src/_numba_zoom.py,sha256=OmMj7mCFkV2P0FaWVXFuYpfzMBQ3Ks60YiHQURes5wQ,16857
36
- imops/src/_numeric.cp36-win32.pyd,sha256=LTRV7_kGgzEd04XsHd9S3xOLBziizQ7G9d4Agr6PcBE,209920
37
- imops/src/_numeric.pyx,sha256=bXv4qBx_k6B6INNR0r49HU2a8UNnpt-mCS19TczcU38,1919
38
- imops/src/_radon.cp36-win32.pyd,sha256=0sBYbxT9lToKTYrYSyrnBfy0ctY6sE4hBbxwLKBxYx0,195584
39
- imops/src/_radon.pyx,sha256=pu8EZplCjIDz9HqBcAit8nj2lDgXpmdhU61_4CfdGWI,2987
40
- imops/src/_zoom.cp36-win32.pyd,sha256=1jLv5ImsyMs-fvLGz1W0cVjMUPRoqZm0Tu6sbuSKVo8,312320
41
- imops/src/_zoom.pyx,sha256=Dd5MDelALAh4-3QhnzfzKTB5Gmi2lVERrbyYj-q8kVQ,23091
42
- imops-0.8.2.dist-info/LICENSE,sha256=x7oyYZPKDTt8KoTitcNJLBWhueke5YEOopdr0XjyvBc,1085
43
- imops-0.8.2.dist-info/METADATA,sha256=B9oMqoxEC0eeetqk0bQqDGbKTN8qxq3vGrp0sXIq9tg,7363
44
- imops-0.8.2.dist-info/WHEEL,sha256=ZX-iFFGFiHZRWPwXowAnONYwAL2TBxDHVbhC1HaSV9Q,97
45
- imops-0.8.2.dist-info/top_level.txt,sha256=kEVHvrc8A4lkLQP8xew2pWdYcyQAMvAwqnlZXtoWwnc,6
46
- imops-0.8.2.dist-info/RECORD,,
File without changes
File without changes